제출 #142656

#제출 시각아이디문제언어결과실행 시간메모리
142656Bodo171Street Lamps (APIO19_street_lamps)C++14
0 / 100
1833 ms4420 KiB
#include <iostream> #include <fstream> #include <set> using namespace std; const int nmax=1005; struct pct { int x,y,val; }nl; int n,i,q,j,poz,a,b; string ini; bool operator <(pct unu,pct doi) { return unu.x<doi.x; } bool operator !=(pct unu,pct doi) { return (unu.x!=doi.x||unu.y!=doi.y||unu.val!=doi.val); } set<pct> s; set<pct>::iterator it; string tip; struct aint { pct a[4*nmax]; int nr; void update(int nod,int l,int r,int x,int y,int val) { ++nr; a[nr].x=x,a[nr].y=y,a[nr].val=val; } int ret; void query(int nod,int l,int r,int x,int y) { for(int idx=1;idx<=nr;idx++) if(a[idx].x<=x&&a[idx].y>=y) ret+=a[idx].val; } int Q(int x,int y) { ret=0; query(1,1,n,x,y); return ret; } }A; void ins(int poz) { pct st=nl,dr=nl,act; it=s.lower_bound({poz,0,0}); if((*it).x==poz+1) dr=(*it); if(it!=s.begin()) { it--; if((*it).y==poz-1) st=(*it); } act.val=i;act.x=act.y=poz; if(st!=nl) { A.update(1,1,n,st.x,st.y,i-st.val); act.x=st.x; s.erase(st); } if(dr!=nl) { A.update(1,1,n,dr.x,dr.y,i-dr.val); act.y=dr.y; s.erase(dr); } s.insert(act); return; } void del(int poz) { pct st=nl,dr=nl,act; it=s.lower_bound({poz+1,0,0}); it--;//mereu se poate act=(*it); A.update(1,1,n,act.x,act.y,i-act.val); s.erase(act); if(poz>act.x) { st={act.x,poz-1,i}; s.insert(st); } if(poz<act.y) { dr={poz+1,act.y,i}; s.insert(dr); } } int main() { //freopen("data.in","r",stdin); ios_base::sync_with_stdio(false); cin>>n>>q; cin>>ini; for(i=0;i<ini.size();i++) { if(ini[i]=='1') { j=i; while(j<ini.size()&&ini[j]=='1') j++; j--; s.insert({i+1,j+1,0}); i=j; } } for(i=1;i<=q;i++) { cin>>tip; if(tip=="toggle") { cin>>poz; if(ini[poz]=='1') { ini[poz]='0'; del(poz); } else { ini[poz]='1'; ins(poz); } } else { int ans; cin>>a>>b; it=s.lower_bound({b,0,0}); it--; if((*it).x<=a&&(*it).y>=b-1) ans=i-(*it).val; else ans=0; ans+=A.Q(a,b-1); cout<<ans<<'\n'; } } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

street_lamps.cpp: In function 'int main()':
street_lamps.cpp:100:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<ini.size();i++)
             ~^~~~~~~~~~~
street_lamps.cpp:105:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while(j<ini.size()&&ini[j]=='1')
                   ~^~~~~~~~~~~
#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...