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;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
template<class T> inline bool chmin(T &a, T b){
if(a>b){a=b;return true;}
return false;
}
template<class T> inline bool chmax(T &a, T b){
if(a<b){a=b;return true;}
return false;
}
constexpr int mod = 1e9+7;
constexpr long long inf = 3e18;
int N,Q;
string S;
int ans[300005],now[300005];
signed main(){
cin>>N>>Q>>S;
rep(i,N)now[i]=-1;
rep(i,Q){
string s;cin>>s;
if(s=="query"){
int a,b;cin>>a>>b;a--;
int res=ans[a];
if(S[a]=='1')res+=i-now[a];
cout<<res<<endl;
}else {
int a;cin>>a;a--;
if(S[a]=='1'){
ans[a]+=i-now[a];
S[a]='0';
}else {
now[a]=i;
S[a]='1';
}
}
}
}
# | 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... |