#include "bits/stdc++.h"
using namespace std;
#define int long long
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define pii pair<int, int>
#define lb lower_bound
#define ub upper_bound
const int N = 105;
const int M = 3e5+5;
const int mod = 1e9+7;
int n, m, k, a[M];
vector<array<int, 3>> tree[4*N];
string s;
int rr = 0, cnt = 0;
void find(int a, int b, int lx = 1, int rx = n, int x = 1){
for(auto x : tree[x]){
if(x[0] <= b && b <= x[1]) rr += x[2], cnt++;
} int m = (lx + rx)>>1;
if(lx == rx) return;
if(a <= m) find(a, b, lx, m, x<<1);
else find(a, b, m+1, rx, x<<1|1);
}
void add(int l, int r, array<int, 3> v, int lx = 1, int rx = n, int x = 1){
if(lx > r || rx < l) return;
if(lx >= l && rx <= r) { tree[x].pb(v); return; }
int m = (lx + rx)>>1;
add(l, r, v, lx, m, x<<1);
add(l, r, v, m+1, rx, x<<1|1);
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n>>m>>s;
set<int> ss;
s = "$" + s;
for(int i=1;i<=n;i++) {
a[i] = s[i] - '0';
if(!a[i]) ss.insert(i);
}
for(int i=1;i<=n;i++){
if(!a[i]) continue;
int j = i;
while(j <= n && a[j] == a[i]) j++;
j--, add(i, j, {i, j, 0}), i = j;
}
for(int i=1;i<=m;i++){
cin>>s;
if(s == "query"){
int a, b; cin>>a>>b, b--; rr = 0, cnt = 0;
find(a, b);
if(cnt & 1) rr += i;
cout<<rr<<"\n";
} else {
int m; cin>>m;
if(a[m]){
auto lx = ss.lb(m);
auto rx = ss.ub(m);
int r = (lx == ss.end() ? n + 1 : *lx);
int l = (rx == ss.begin() ? 0 : *--rx);
add(l+1, m, {m, r-1, i}), ss.insert(m);
} else {
ss.erase(m);
auto lx = ss.lb(m);
auto rx = ss.ub(m);
int r = (lx == ss.end() ? n + 1 : *lx);
int l = (rx == ss.begin() ? 0 : *--rx);
add(l+1, m, {m, r-1, -i});
} a[m] ^= 1;
}
} return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
908 ms |
9148 KB |
Output is correct |
2 |
Runtime error |
2 ms |
460 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
588 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
908 ms |
9148 KB |
Output is correct |
9 |
Runtime error |
2 ms |
460 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |