#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
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:29:16: warning: unused variable 'b' [-Wunused-variable]
29 | int a, b;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
353 ms |
4536 KB |
Output is correct |
2 |
Correct |
362 ms |
4896 KB |
Output is correct |
3 |
Correct |
392 ms |
8684 KB |
Output is correct |
4 |
Correct |
585 ms |
209596 KB |
Output is correct |
5 |
Correct |
652 ms |
210136 KB |
Output is correct |
6 |
Correct |
582 ms |
209432 KB |
Output is correct |
7 |
Correct |
783 ms |
210376 KB |
Output is correct |
8 |
Correct |
870 ms |
211656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |