Submission #335106

#TimeUsernameProblemLanguageResultExecution timeMemory
335106nicholaskStreet Lamps (APIO19_street_lamps)C++14
40 / 100
1008 ms11268 KiB
#include <bits/stdc++.h> using namespace std; int main(){ int n,q; cin>>n>>q; string st; cin>>st; if (n<=100&&q<=100){ vector <string> v; v.push_back(st); for (int z=1; z<=q; z++){ string s; cin>>s; if (s=="toggle"){ int u; cin>>u; u--; if (st[u]=='0') st[u]='1'; else st[u]='0'; } else { int t,u; cin>>t>>u; t--; u--; int cnt=0; for (auto&i:v){ bool ok=1; for (int j=t; j<u; j++){ if (i[j]!='1'){ ok=0; break; } } if (ok) cnt++; } cout<<cnt<<endl; } v.push_back(st); } } else { int cnt[n]={},on[n]={}; for (int i=0; i<n; i++){ if (st[i]=='1') on[i]=0; } for (int z=1; z<=q; z++){ string s; cin>>s; if (s=="toggle"){ int u; cin>>u; u--; if (st[u]=='0'){ st[u]='1'; on[u]=z; } else { st[u]='0'; cnt[u]+=z-on[u]; } } else { int u,dummy; cin>>u>>dummy; u--; if (st[u]=='0') cout<<cnt[u]<<endl; else cout<<cnt[u]+z-on[u]<<endl; } } } }
#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...