제출 #736457

#제출 시각아이디문제언어결과실행 시간메모리
736457Dan4Life가로등 (APIO19_street_lamps)C++17
20 / 100
256 ms10996 KiB
#include <bits/stdc++.h> using namespace std; const int mxN = (int)3e5+10; string s; int n, q, segTree[2*mxN]; void upd(int x, int v, int p=0, int l=1, int r=n){ if(l==r){ segTree[p]=v; return; } int mid = (l+r)>>1; int rp = p+2*(mid-l+1); if(x<=mid) upd(x,v,p+1,l,mid); else upd(x,v,rp,mid+1,r); segTree[p] = max(segTree[p+1],segTree[rp]); } int query(int i, int j, int p=0, int l=1, int r=n){ if(i>r or j<l or i>j) return 0; if(i<=l and r<=j) return segTree[p]; int mid = (l+r)>>1; int rp = p+2*(mid-l+1); return max(query(i,j,p+1,l,mid),query(i,j,rp,mid+1,r)); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> q >> s; fill(segTree,segTree+mxN*2,mxN); for(int i = 0; i < n; i++) upd(i+1,(s[i]=='1')?0:mxN); for(int i = 1; i <= q; i++){ int x, y; cin >> s >> x; if(s[0]=='t') upd(x,i); else cin >> y, y--, cout << (query(x,y)!=mxN)*(i-query(x,y)) << "\n"; } }
#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...