Submission #560722

#TimeUsernameProblemLanguageResultExecution timeMemory
560722jeqchoStreet Lamps (APIO19_street_lamps)C++17
0 / 100
5082 ms8344 KiB
#include <bits/stdc++.h> using namespace std; typedef long double ld; typedef long long ll; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<pair<int,int>> vpi; #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define trav(a,x) for (auto& a: x) #define pb push_back #define rsz resize #define sz(x) int(x.size()) #define all(x) begin(x), end(x) #define fi first #define se second int const Q=3e5+3; int sum[Q]; int state[Q]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,q; cin>>n>>q; string s; cin>>s; vector<bool>c(n); F0R(i,n)c[i]=s[i]-'0'; vpi qs; F0R(j,q) { string t; cin>>t; if(t=="toggle") { int i; cin>>i; --i; qs.pb({i,-1}); } else { int a,b; cin>>a>>b; --a;--b; qs.pb({a,b}); } } F0R(j,q) { if(qs[j].se==-1)continue; state[j]=accumulate(c.begin()+qs[j].fi,c.begin()+qs[j].se,(int)0); } fill(sum,sum+q,0); F0R(i,q) { if(qs[i].se==-1) { c[qs[i].fi]=!c[qs[i].fi]; FOR(j,i+1,q) { if(qs[j].se==-1)continue; if(qs[i].fi<qs[j].fi || qs[i].fi>=qs[j].se)continue; if(c[qs[i].fi])++state[j]; else --state[j]; if(state[j]==qs[j].se-qs[j].fi) { sum[j]-=i+1; } else if(state[j]+1==qs[j].se-qs[j].fi) { sum[j]+=i+1; } } } else { if(state[i]==qs[i].se-qs[i].fi)sum[i]+=i+1; cout<<sum[i]<<'\n'; } } 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...