#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
using ull=unsigned long long;
using ll=long long;
using pii=pair<int,int>;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
const int mod=1e9+7;
#define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n";
template <typename T> istream& operator>>(istream& is, vector<T> &a) {
copy_n(istream_iterator<T>(is), a.size(), a.begin()); return is;}
#ifdef IOI
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#else
#define dbg(...) 1337;
#endif
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
int q;
cin>>q;
string s;
cin>>s;
vector<vector<int>> queries;
int ans[n];memset(ans,0,sizeof(ans));
int lst[n];memset(lst,-1,sizeof(lst));
for(int i = 0;i<n;i++){
if(s[i]=='1'){
lst[i] = 0;
}else lst[i] = -1;
}
for(int j =1;j<=q;j++){
string a;
cin>>a;
if(a[0]=='t'){
int i;
cin>>i;
i--;
int x = s[i]-'0';
x^=1;
dbg(i,x,lst[i])
if(x==1){
lst[i] = j;
}else{
int r = j-lst[i];
ans[i] += r;
}
s[i] = char(x+'0');
}else{
int a,b;
cin>>a>>b;
a--;
if(s[a]=='1'){
dbg(j,a)
int r = j-lst[a];
ans[a]+=r;
lst[a] = j;
}
cout<<ans[a]<<endl;
}
}
}
# | 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... |