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;
int n, q, last[300005], ct[300005];
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin>>n>>q;
string s;
cin>>s;
for(int i=0;i<n;i++) {
if(s[i]-'0'==1) last[i] = 0;
else last[i] = -1;
}
for(int i=1;i<=q;i++) {
cin>>s;
if(s[0]=='q') {
int a, b;
cin>>a>>b;
a--; b--;
cout<<ct[a]+(last[a]==-1 ? 0:i-last[a])<<'\n';
} else {
int a;
cin>>a;
a--;
if(last[a]==-1) {
last[a] = i;
} else {
ct[a] += (last[a]==-1 ? 0:i-last[a]);
last[a] = -1;
}
}
}
}
/*
5 7
11011
query 1 2
query 1 2
query 1 6
query 3 4
toggle 3
query 3 4
query 1 6
*/
# | 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... |