Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

feb. long challenge 2017

$
0
0

Just saw video tutorial and tried to implement MFREQ question... can anyone tell me what am I missing at? here is my code:

include <bits stdc++.h="">

using namespace std;

int main() {

int n,m;
cin>>n>>m;
long long a[n],left[n],right[n];
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<m;i++){
    int l,r,k;
    cin>>l>>r>>k;

    left[0]=0;
    for(int i=1;i<n;i++)
    {
        if(a[i]==a[i-1])
        left[i]=i-1;
        else
        left[i]=i;
    }
    right[n-1]=n-1;
    for(int i=n-2;i>=0;i--)
    {
        if(a[i]==a[i+1])
        right[i]=i+1;
        else
        right[i]=i;
    }
    for(int i=0;i<n;i++)
    cout<<left[i]<<" ";    //left array
    cout<<endl;
     for(int i=0;i<n;i++)
    cout<<right[i]<<" ";   //right array
    int  mid=(l+r)/2;

   if((right[mid]-left[mid])>=k)    // not getting this condition
    cout<<a[mid]<<endl;
   else
   cout<<-1<<endl;
}

}

Please help me...


Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>