#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// #include <ext/rope>
using namespace std;
// using namespace __gnu_cxx;
// using namespace __gnu_pbds;
void Hollwo_Pelw();
signed main(){
#ifndef hollwo_pelw_local
if (fopen(".inp", "r"))
assert(freopen(".inp", "r", stdin)), assert(freopen(".out", "w", stdout));
#else
using namespace chrono;
auto start = steady_clock::now();
#endif
cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
int testcases = 1;
// cin >> testcases;
for (int test = 1; test <= testcases; test++){
// cout << "Case #" << test << ": ";
Hollwo_Pelw();
}
#ifdef hollwo_pelw_local
auto end = steady_clock::now();
cout << "\nExcution time : " << duration_cast<milliseconds> (end - start).count() << "[ms]" << endl;
#endif
}
const int N = 6e5 + 5;
struct query_t {
int t, sx, ex, sy, ey, v;
};
vector<query_t> queries;
int n, q;
char s[N];
vector<int> bit[N], val[N];
void update_temp(int x, int y) {
for (int px = x; px <= n; px += px & -px)
val[px].push_back(y);
}
void update(int x, int y, int v) {
for (int px = x; px <= n; px += px & -px) {
int py = lower_bound(val[px].begin(), val[px].end(), y) - val[px].begin() + 1;
for (; py < (int) bit[px].size(); py += py & -py)
bit[px][py] += v;
}
}
int get(int x, int y) {
int r = 0;
for (int px = x; px > 0; px -= px & -px) {
int py = upper_bound(val[px].begin(), val[px].end(), y) - val[px].begin();
for (; py; py -= py & -py)
r += bit[px][py];
}
return r;
}
void update_temp(int sx, int ex, int sy, int ey, int v) {
queries.push_back({1, sx, ex, sy, ey, v});
update_temp(sx, sy);
update_temp(ex + 1, sy);
update_temp(sx, ey + 1);
update_temp(ex + 1, ey + 1);
}
void update(int sx, int ex, int sy, int ey, int v) {
update(sx, sy, v);
update(sx, ey + 1, -v);
update(ex + 1, sy, -v);
update(ex + 1, ey + 1, v);
}
void Hollwo_Pelw(){
cin >> n >> q >> (s + 1);
set<int> st;
for (int i = 1; i <= n; i++)
if (s[i] == '0') st.insert(i);
for (int i = 1, l, r, p; i <= q; i++) {
string tp; cin >> tp;
if (tp[0] == 't') {
cin >> p;
if (st.count(p)) {
auto it = st.find(p);
l = it == st.begin() ? 1 : *prev(it) + 1;
r = next(it) == st.end() ? n : *next(it) - 1;
st.erase(p);
update_temp(l, p, p, r, -i);
} else {
st.insert(p);
auto it = st.find(p);
l = it == st.begin() ? 1 : *prev(it) + 1;
r = next(it) == st.end() ? n : *next(it) - 1;
update_temp(l, p, p, r, +i);
}
}
if (tp[0] == 'q') {
cin >> l >> r, -- r;
auto it = st.lower_bound(l);
int v = it == st.end() || *it > r ? i : 0;
queries.push_back({0, l, l, r, r, v});
}
}
for (int i = 1; i <= n; i++) {
sort(val[i].begin(), val[i].end());
val[i].erase(unique(val[i].begin(), val[i].end()), val[i].end());
bit[i].resize(val[i].size() + 5);
}
for (auto [t, sx, ex, sy, ey, v] : queries) {
if (t) {
update(sx, ex, sy, ey, v);
} else {
cout << v + get(sx, sy) << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
28508 KB |
Output is correct |
2 |
Correct |
15 ms |
28504 KB |
Output is correct |
3 |
Correct |
15 ms |
28500 KB |
Output is correct |
4 |
Correct |
15 ms |
28508 KB |
Output is correct |
5 |
Correct |
14 ms |
28516 KB |
Output is correct |
6 |
Correct |
17 ms |
28500 KB |
Output is correct |
7 |
Correct |
15 ms |
28500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
279 ms |
51796 KB |
Output is correct |
2 |
Correct |
333 ms |
52008 KB |
Output is correct |
3 |
Correct |
583 ms |
57612 KB |
Output is correct |
4 |
Correct |
1487 ms |
99672 KB |
Output is correct |
5 |
Correct |
1254 ms |
84660 KB |
Output is correct |
6 |
Correct |
1613 ms |
108312 KB |
Output is correct |
7 |
Correct |
383 ms |
65940 KB |
Output is correct |
8 |
Correct |
150 ms |
53240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
28692 KB |
Output is correct |
2 |
Correct |
16 ms |
28672 KB |
Output is correct |
3 |
Correct |
15 ms |
28500 KB |
Output is correct |
4 |
Correct |
16 ms |
28500 KB |
Output is correct |
5 |
Correct |
2492 ms |
123352 KB |
Output is correct |
6 |
Correct |
1895 ms |
107540 KB |
Output is correct |
7 |
Correct |
1173 ms |
83848 KB |
Output is correct |
8 |
Correct |
147 ms |
53056 KB |
Output is correct |
9 |
Correct |
91 ms |
37972 KB |
Output is correct |
10 |
Correct |
97 ms |
43928 KB |
Output is correct |
11 |
Correct |
94 ms |
44092 KB |
Output is correct |
12 |
Correct |
407 ms |
65844 KB |
Output is correct |
13 |
Correct |
168 ms |
53120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
28472 KB |
Output is correct |
2 |
Correct |
14 ms |
28628 KB |
Output is correct |
3 |
Correct |
16 ms |
28640 KB |
Output is correct |
4 |
Correct |
16 ms |
28604 KB |
Output is correct |
5 |
Correct |
399 ms |
59956 KB |
Output is correct |
6 |
Correct |
1107 ms |
86044 KB |
Output is correct |
7 |
Correct |
1855 ms |
107648 KB |
Output is correct |
8 |
Correct |
2610 ms |
128016 KB |
Output is correct |
9 |
Correct |
451 ms |
67444 KB |
Output is correct |
10 |
Correct |
384 ms |
63832 KB |
Output is correct |
11 |
Correct |
468 ms |
67476 KB |
Output is correct |
12 |
Correct |
396 ms |
63580 KB |
Output is correct |
13 |
Correct |
433 ms |
67508 KB |
Output is correct |
14 |
Correct |
397 ms |
63864 KB |
Output is correct |
15 |
Correct |
470 ms |
65880 KB |
Output is correct |
16 |
Correct |
182 ms |
53304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
28508 KB |
Output is correct |
2 |
Correct |
15 ms |
28504 KB |
Output is correct |
3 |
Correct |
15 ms |
28500 KB |
Output is correct |
4 |
Correct |
15 ms |
28508 KB |
Output is correct |
5 |
Correct |
14 ms |
28516 KB |
Output is correct |
6 |
Correct |
17 ms |
28500 KB |
Output is correct |
7 |
Correct |
15 ms |
28500 KB |
Output is correct |
8 |
Correct |
279 ms |
51796 KB |
Output is correct |
9 |
Correct |
333 ms |
52008 KB |
Output is correct |
10 |
Correct |
583 ms |
57612 KB |
Output is correct |
11 |
Correct |
1487 ms |
99672 KB |
Output is correct |
12 |
Correct |
1254 ms |
84660 KB |
Output is correct |
13 |
Correct |
1613 ms |
108312 KB |
Output is correct |
14 |
Correct |
383 ms |
65940 KB |
Output is correct |
15 |
Correct |
150 ms |
53240 KB |
Output is correct |
16 |
Correct |
17 ms |
28692 KB |
Output is correct |
17 |
Correct |
16 ms |
28672 KB |
Output is correct |
18 |
Correct |
15 ms |
28500 KB |
Output is correct |
19 |
Correct |
16 ms |
28500 KB |
Output is correct |
20 |
Correct |
2492 ms |
123352 KB |
Output is correct |
21 |
Correct |
1895 ms |
107540 KB |
Output is correct |
22 |
Correct |
1173 ms |
83848 KB |
Output is correct |
23 |
Correct |
147 ms |
53056 KB |
Output is correct |
24 |
Correct |
91 ms |
37972 KB |
Output is correct |
25 |
Correct |
97 ms |
43928 KB |
Output is correct |
26 |
Correct |
94 ms |
44092 KB |
Output is correct |
27 |
Correct |
407 ms |
65844 KB |
Output is correct |
28 |
Correct |
168 ms |
53120 KB |
Output is correct |
29 |
Correct |
14 ms |
28472 KB |
Output is correct |
30 |
Correct |
14 ms |
28628 KB |
Output is correct |
31 |
Correct |
16 ms |
28640 KB |
Output is correct |
32 |
Correct |
16 ms |
28604 KB |
Output is correct |
33 |
Correct |
399 ms |
59956 KB |
Output is correct |
34 |
Correct |
1107 ms |
86044 KB |
Output is correct |
35 |
Correct |
1855 ms |
107648 KB |
Output is correct |
36 |
Correct |
2610 ms |
128016 KB |
Output is correct |
37 |
Correct |
451 ms |
67444 KB |
Output is correct |
38 |
Correct |
384 ms |
63832 KB |
Output is correct |
39 |
Correct |
468 ms |
67476 KB |
Output is correct |
40 |
Correct |
396 ms |
63580 KB |
Output is correct |
41 |
Correct |
433 ms |
67508 KB |
Output is correct |
42 |
Correct |
397 ms |
63864 KB |
Output is correct |
43 |
Correct |
470 ms |
65880 KB |
Output is correct |
44 |
Correct |
182 ms |
53304 KB |
Output is correct |
45 |
Correct |
125 ms |
41496 KB |
Output is correct |
46 |
Correct |
182 ms |
42232 KB |
Output is correct |
47 |
Correct |
843 ms |
64608 KB |
Output is correct |
48 |
Correct |
1612 ms |
99844 KB |
Output is correct |
49 |
Correct |
147 ms |
44076 KB |
Output is correct |
50 |
Correct |
108 ms |
44028 KB |
Output is correct |
51 |
Correct |
109 ms |
44212 KB |
Output is correct |
52 |
Correct |
111 ms |
44592 KB |
Output is correct |
53 |
Correct |
105 ms |
44600 KB |
Output is correct |
54 |
Correct |
107 ms |
44604 KB |
Output is correct |