Submission #201218

#TimeUsernameProblemLanguageResultExecution timeMemory
201218brcodeNekameleoni (COCI15_nekameleoni)C++14
140 / 140
1903 ms494200 KiB
#include <iostream> #include <bits/stdc++.h> #define INF 1e9 using namespace std; const int MAXN = 1e5; int n,k,q; int v[MAXN+2]; struct node{ int len; pair<long long,int> suff[52],pref[52]; int ans; }; node seg[3*MAXN + 2]; bool check(long long a,long long b){ return (a&b) == a; } void upd(int a,int b){ a+=(1LL<<17); seg[a].len = 1; seg[a].pref[0] = make_pair(1LL<<b,a-(1LL<<17)); seg[a].suff[0] = seg[a].pref[0]; seg[a].ans = INF; for(a/=2;a;a>>=1){ int lp,r1; lp = 0; //setting prefixes to child prefixes for(int i=0;i<seg[a*2].len;i++){ seg[a].pref[lp++] = seg[a*2].pref[i]; } for(int i=0;i<seg[a*2+1].len;i++){ if(lp==0||!check(seg[a*2+1].pref[i].first,seg[a].pref[lp-1].first)){ seg[a].pref[lp] =seg[a*2 + 1].pref[i]; if(lp>0){ seg[a].pref[lp].first|=seg[a].pref[lp-1].first; } lp++; } } //setting suffixes to child suffixes r1 = 0; for(int i=0;i<seg[a*2+1].len;i++){ seg[a].suff[r1++] = seg[a*2 + 1].suff[i]; } for(int i=0;i<seg[a*2].len;i++){ if(r1 == 0||!check(seg[a*2].suff[i].first,seg[a].suff[r1-1].first)){ seg[a].suff[r1] = seg[a*2].suff[i]; if(r1){ seg[a].suff[r1].first|=seg[a].suff[r1-1].first; } r1++; } } seg[a].len = lp; seg[a].ans = INF; int prefpos = 0; //set the whole suffix to be the answer at the start, then decrease the suffix and accordingly increase the prefix for(int suffpos = seg[a*2].len-1;suffpos>=0;suffpos--){ while(prefpos<seg[a*2+1].len && (seg[a*2].suff[suffpos].first|seg[a*2+1].pref[prefpos].first)!=(1LL<<k)-1){ prefpos++; } if(prefpos<seg[a*2 + 1].len){ long long currmask = (seg[a*2].suff[suffpos].first|seg[a*2+1].pref[prefpos].first); if(currmask==(1LL<<k)-1){ seg[a].ans = min(seg[a].ans,seg[a*2+1].pref[prefpos].second -seg[a*2].suff[suffpos].second+1); } } seg[a].ans = min(seg[a].ans,min(seg[2*a].ans,seg[a*2+1].ans)); } } } int main() { cin>>n>>k>>q; for(int i=0;i<=280000;i++){ seg[i].ans = INF; } for(int i=0;i<n;i++){ cin>>v[i]; upd(i,v[i]-1); } while(q--){ int type; cin>>type; if(type == 2){ if(seg[1].ans == INF){ cout<<-1LL<<endl; }else{ cout<<seg[1].ans<<endl; } }else{ int a,b; cin>>a>>b; a--; b--; upd(a,b); } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...