-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMFREQ.cpp
executable file
·53 lines (48 loc) · 1.21 KB
/
MFREQ.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<iostream>
using namespace std;
int main()
{
int n,m,cnt,k,i;
cin>>n>>m;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
while(m--)
{
int l,r,k,cnt=1,flag=0,ans=-1;
cin>>l>>r>>k;
for(int i=l-1;i<=r;)
{
if((i+k)<=n&&a[i]==a[i+k-1])
{
ans=a[i];
i=r+1;
}
else if(a[i]==a[i+1])
{
cnt++;
if(cnt>=k)
{
ans=a[i];
flag=1;
i=r+1;
}
i++;
}
else
{
if(cnt>=k)
{
ans=a[i];
flag=1;
i=r+1;
}
i+=cnt;
cnt=1;
}
}
cout<<ans<<endl;
}
}