This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
char opposite(char c) {
if(c=='0')
return '1';
return '0';
}
bool ok(string str, int a, int b) {
for(int i = a-1; i < b-1; i++) {
if(str[i]=='0')
return 0;
}
return 1;
}
int main() {
int n, q;
cin >> n >> q;
int prev[n];
queue<pair<int, int>> operations[n];
memset(prev, 0, sizeof prev);
string str;
cin >> str;
for(int i = 0; i < n; i++) {
if(str[i]=='1')
operations[i].push({1, 0});
}
for(int i = 1; i <= q; i++) {
string Str;
int a, b;
cin >> Str >> a;
a--;
if(Str=="toggle") {
if(str[a]=='0')
str[a] = '1';
else
str[a] = '0';
operations[a].push({str[a]-48, i});
} else {
int pos = 0;
if(str[a]=='1')
operations[a].push({0, i});
while(operations[a].size()) {
int x, b;
tie(x, b) = operations[a].front();
operations[a].pop();
if(x) {
pos = b;
} else {
prev[a]+=b-pos;
pos = i;
}
}
if(str[a]=='1')
operations[a].push({1, i});
cout << prev[a] << '\n';
cin >> a;
}
}
}
Compilation message (stderr)
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:29:16: warning: unused variable 'b' [-Wunused-variable]
29 | int a, b;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |