Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <cmath>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <map>
- #include <set>
- #define INF 19999999
- #define ll long long
- using namespace std;
- ll n,m,l1,k,a[100002],viz[100002],b[100002],mid,r,l;
- int dif(int l,int r){
- ll s=0;
- for (int i=l;i<=r;i++){
- if (b[i]>r) s++;
- }
- return s;
- }
- int main()
- {
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- cin>>n>>m;
- for (int i=1;i<=n;i++){
- cin>>a[i];
- }
- for (int i=n;i>=1;i--){
- if (viz[a[i]]==0) b[i]=INF;
- else
- b[i]=viz[a[i]];
- viz[a[i]]=i;
- }
- cin>>m; ll p=0;
- for (int i=1;i<=m;i++){
- cin>>l1>>k;
- l1=((l1+p)%n)+1;
- k=((k+p)%m)+1;
- l=l1; r=n;
- while(l<r){
- mid=(l+r)/2;
- if (dif(l1,mid)>=k) r=mid;
- else
- l=mid+1;
- }
- if (dif(l1,r)==k) p=r;
- else p=0;
- cout<<p<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment