/// Template path: /home/mohammed/.config/sublime-text-3/Packages/User
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
// typedef
typedef long long ll;
typedef long double ld;
typedef vector<int> vecint;
typedef vector<char> vecchar;
typedef vector<string> vecstr;
typedef vector<long long> vecll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// Marcos
#define endl ("\n")
#define int long long
#define mod 1000000007
#define pi (3.141592653589)
#define REP(i,a,b) for (int i = a; i < b; i++)
#define RREP(i,a,b) for (int i = a; i > b; i--)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
// Functions
long long squared(long long x) {return (x * x) % mod;}
int factorial(int n) {long long res = 1; for (int i = 1; i <= n; i++) {res = ((res * i) % mod + mod) % mod ;} return res;}
long long power(long long x, long long p) {if (p == 0) {return 1;} if (p % 2 == 1) {return (power(x, p - 1) * x) % mod;} return squared(power(x, p / 2));}
// cout << fixed;
// cout << setprecision(4);
// ---------(^_^)--------- //
void main_solve() {
int n, q; cin >> n >> q;
string s; cin >> s;
vector<int> last(n, -1);
vector<int> result(n);
for (int i = 0; i < n ; i ++) {
if (s[i] == '1') {
last[i] = 0;
}
}
int curr_time = 0;
while (q--) {
curr_time++;
string type; cin >> type;
if (type == "toggle") {
int x; cin >> x;
if (s[x - 1] == '0') {
s[x - 1] = '1';
last[x - 1] = curr_time;
} else {
s[x - 1] = '0';
result[x - 1] += curr_time - last[x - 1];
last[x - 1] = -1;
}
continue;
}
int a, b; cin >> a >> b;
int e = result[a - 1];
if (last[a - 1] != -1) {
e += (curr_time - last[a - 1]);
}
cout << e << endl;
}
}
int32_t main() {
fast;
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
// Just another problem (-_-)
int t;
t = 1;
// cin >> t;
while (t--) {
main_solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
1164 KB |
Output is correct |
2 |
Correct |
56 ms |
4692 KB |
Output is correct |
3 |
Correct |
59 ms |
5328 KB |
Output is correct |
4 |
Correct |
78 ms |
11360 KB |
Output is correct |
5 |
Correct |
78 ms |
11732 KB |
Output is correct |
6 |
Correct |
63 ms |
11000 KB |
Output is correct |
7 |
Correct |
78 ms |
11968 KB |
Output is correct |
8 |
Correct |
83 ms |
13320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |