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>
#define fast cin.tie(0)->sync_with_stdio(0);
#define int long long
#define inf ((int)1e18)
using namespace std;
int32_t main(){
fast
int n, q;
cin >> n >> q;
string s;
cin >> s;
vector <int> till(n, -1), ans(n); // till[ind] = 0 means closed
for(int i = 0; i < n; i++) {
if(s[i] == '1') till[i] = 0;
}
for(int i = 1; i <= q; i++) {
string type;
cin >> type;
if(type == "toggle") {
int ind;
cin >> ind;
ind--;
if(~till[ind]) {
ans[ind] += i - till[ind];
till[ind] = -1;
}
else {
till[ind] = i;
}
}
else {
int a, b;
cin >> a >> b;
a--, b-=2;
int tmp = (~till[a]) ? i - till[a] : 0;
cout << tmp + ans[a] << "\n";
}
}
}
# | 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... |