Submission #568765

#TimeUsernameProblemLanguageResultExecution timeMemory
568765birthdaycakeStreet Lamps (APIO19_street_lamps)C++17
0 / 100
5048 ms14944 KiB
#include<bits/stdc++.h> #define int long long #define endl '\n' #define mod 1000000007 #define boost ios_base::sync_with_stdio(false), cin.tie(NULL); using namespace std; int pref[200001],sub[200001]; signed main() { int n,q; cin >> n >> q; string a; cin >> a; for(int i = 0; i < n; i++){ if(a[i] == '1') pref[i]++; if(i) pref[i] += pref[i - 1]; sub[i] = pref[i]; } vector<pair<string,pair<int,int>>>qw(q); for(int i = 0; i < q; i++){ cin >> qw[i].first >> qw[i].second.first; if(qw[i].first != "toggle") cin >> qw[i].second.second; else qw[i].second.second = 0; int a = qw[i].second.first - 1, b = qw[i].second.second - 1; if(qw[i].first == "query"){ int ans = 0; for(int j = 0; j <= i; j++){ if(qw[j].first == "query"){ if(sub[b - 1] - (a == 0 ? 0 : sub[a - 1]) == (b - a)) ans++; }else{ int c = qw[j].second.first - 1; if(sub[c] - (c == 0 ? 0 : sub[c - 1]) == 1){ for(int k = c; k < n; k++) sub[k]--; }else{ for(int k = c; k < n; k++) sub[k]++; } } } cout << ans << endl; for(int j = 0; j < n; j++){ sub[j] = pref[j]; } } } 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...