Submission #974716

#TimeUsernameProblemLanguageResultExecution timeMemory
974716AbitoStreet Lamps (APIO19_street_lamps)C++17
20 / 100
203 ms12624 KiB
#include <bits/stdc++.h> #define F first #define S second #define pb push_back #define ppb pop_back #define ep insert #define endl '\n' #define elif else if #define pow pwr #define sqrt sqrtt //#define int long long #define ll long long typedef unsigned long long ull; using namespace std; const int N=3e5+5; int n,q,seg[4*N+5]; bool a[N]; int build(int x,int l,int r){ if (l==r){ if (a[l]) seg[x]=0; else seg[x]=q+100; return seg[x]; } int mid=(l+r)/2; return seg[x]=max(build(x*2,l,mid),build(x*2+1,mid+1,r)); } void edit(int x,int l,int r,int idx,int val){ if (l==r){ seg[x]=val; return; }int mid=(l+r)/2; if (idx<=mid) edit(x*2,l,mid,idx,val); else edit(x*2+1,mid+1,r,idx,val); seg[x]=max(seg[x*2],seg[x*2+1]); return; } int query(int x,int l,int r,int lx,int rx){ if (l>=lx && r<=rx) return seg[x]; if (l>rx || r<lx) return INT_MIN; int mid=(l+r)/2; return max(query(x*2,l,mid,lx,rx),query(x*2+1,mid+1,r,lx,rx)); } int32_t main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); cin>>n>>q; for (int i=1;i<=n;i++){ char c;cin>>c; if (c=='1') a[i]=1; } build(1,1,n); for (int i=1;i<=q;i++){ string s;cin>>s; if (s=="toggle"){ int x;cin>>x; edit(1,1,n,x,i); } else{ int l,r;cin>>l>>r; cout<<max(0,i-query(1,1,n,l,r-1))<<endl; } } return 0; }
#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...