#include <bits/stdc++.h>
using namespace std;
// Hi
int main(){
//ios::sync_with_stdio(0);cin.tie(0);
int n,q;
cin>>n>>q;
string s;
cin>>s;
vector<int> cnt,last_on(n+1,0);
for(auto i:s)cnt.push_back(i-'0');
vector<bool> on(cnt.begin(),cnt.end());
for(int i=0;i<n;i++){
if(on[i]){
last_on[i] = 0;
}else last_on[i] = 1e9+7;
}
for(int time=1;time<=q;time++){
string t;
cin>>t;
if(t == "toggle"){
int ind;
cin>>ind;
ind--;
if(!on[ind]){
on[ind] = 1;
last_on[ind] = time;
cnt[ind]++;
}else{
int pre = time-last_on[ind]-1;
cnt[ind] += (pre >= 0 ? pre : 0);
last_on[ind] = 1e9+7;
on[ind] = 0;
}
}else{
int a,b;
cin>>a>>b;
int pre = time-last_on[a-1]-1;
cout << cnt[a-1]+(pre >= 0 ? pre : 0) << '\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
434 ms |
1220 KB |
Output is correct |
2 |
Correct |
448 ms |
4700 KB |
Output is correct |
3 |
Correct |
474 ms |
5284 KB |
Output is correct |
4 |
Correct |
511 ms |
8916 KB |
Output is correct |
5 |
Correct |
573 ms |
9496 KB |
Output is correct |
6 |
Correct |
451 ms |
8788 KB |
Output is correct |
7 |
Correct |
791 ms |
9688 KB |
Output is correct |
8 |
Correct |
808 ms |
11100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |