Submission #568879

#TimeUsernameProblemLanguageResultExecution timeMemory
568879birthdaycakeStreet Lamps (APIO19_street_lamps)C++17
20 / 100
385 ms1168 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[300001],sub[300001],ans[300001],l[300001]; signed main() { int n,q; cin >> n >> q; string a; cin >> a; if(n <= 100 && q <= 100){ 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{ if(sub[b - 1] - (a == 0 ? 0 : sub[a - 1]) == (b - a)) ans++; 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; } for(int i = 0; i < q; i++){ string t; cin >> t; if(t == "toggle"){ int x; cin >> x; x--; if(a[x] == '0'){ a[x] = '1'; l[x] = i; }else{ ans[x] += (i - l[x] + 1); a[x] = '0'; } }else{ int x,y; cin >> x >> y; x--; if(a[x] == '1'){ ans[x] += (i - l[x] + 1); l[x] = i; } cout << ans[x] << endl; } } 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...