#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, nq, a[N], pre;
set <int> s;
vector <int> vt[N], bit[N];
struct ngu {
int a, b, c, d, e, f, g;
};
vector <ngu> task;
void upd(int x, int _y, int last, int i) {
while (x) {
int y = lower_bound(vt[x].begin(), vt[x].end(), _y) - vt[x].begin();
while (y < vt[x].size()) {
bit[x][y] += (i ? last : -last);
y += (y & -y);
}
x -= (x & -x);
}
}
void up(int x, int y, int u, int v, int last, int i) {
upd(x, y, last, i);
upd(x, v + 1, last, 1 - i);
upd(u - 1, y, last, 1 - i);
upd(u - 1, v + 1, last, i);
}
void fake_up(int x, int y, int u, int v, int last, int i) {
task.push_back({0, x, y, u, v, last, i});
while (x) {
vt[x].push_back(y);
vt[x].push_back(v + 1);
x -= (x & -x);
}
x = u - 1;
while (x ) {
vt[x].push_back(y);
vt[x].push_back(v + 1);
x -= (x & -x);
}
}
int get(int x, int _y) {
int ret = 0;
while (x <= n) {
int y = lower_bound(vt[x].begin(), vt[x].end(), _y) - vt[x].begin();
while (y) {
ret += bit[x][y];
y -= (y & -y);
}
x += (x & -x);
}
return ret;
}
main () {
cin.tie(0)->sync_with_stdio(0);
if(fopen("task.inp", "r")) {
freopen("task.inp", "r", stdin);
freopen("wa.out", "w", stdout);
}
cin >> n >> nq; n++;
for(int i = 1; i < n; i++) {
char ch; cin >> ch;
a[i] = ch - '0';
if(!a[i]) {
s.insert(i);
up(n, pre + 1, i + 1, i, 0, 0);
pre = i;
}
}
s.insert(0); s.insert(n);
for(int t = 1; t <= nq; t++) {
string str; cin >> str;
if(str == "query") {
int u, v; cin >> u >> v;
if(u < v) swap(u, v);
int tmp = t;
if(*s.lower_bound(v) < u) tmp = 0;
task.push_back({1, tmp, u, v, 0, 0, 0});
while (u <= n) {
vt[u].push_back(v);
u += (u & -u);
}
}
else {
int i; cin >> i;
a[i] = 1 - a[i];
if(!a[i]) s.insert(i);
else s.erase(i);
int j = *(--(s.lower_bound(i)));
int k = *s.upper_bound(i);
fake_up(k, j + 1, i + 1, i, t, a[i]);
}
}
for(int i = 1; i <= n; i++) {
vt[i].push_back(-1);
sort(vt[i].begin(), vt[i].end());
vt[i].resize(unique(vt[i].begin(), vt[i].end()) - vt[i].begin());
bit[i].resize(vt[i].size());
}
for(auto [type, x, y, u, v, last, i] : task) {
// cout << type << " " << x << " " << y << " " << u << " " << v << " " << last << " " << i << "\n";
if(type) cout << x - get(y, u) << "\n";
else up(x, y, u, v, last, i);
}
return 0;
}
Compilation message
street_lamps.cpp: In function 'void upd(int, int, int, int)':
street_lamps.cpp:16:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | while (y < vt[x].size()) {
| ~~^~~~~~~~~~~~~~
street_lamps.cpp: At global scope:
street_lamps.cpp:59:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
59 | main () {
| ^~~~
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | freopen("task.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | freopen("wa.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14320 KB |
Output is correct |
3 |
Correct |
8 ms |
14420 KB |
Output is correct |
4 |
Correct |
8 ms |
14420 KB |
Output is correct |
5 |
Correct |
8 ms |
14424 KB |
Output is correct |
6 |
Correct |
7 ms |
14420 KB |
Output is correct |
7 |
Correct |
8 ms |
14428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
266 ms |
41616 KB |
Output is correct |
2 |
Correct |
341 ms |
45508 KB |
Output is correct |
3 |
Correct |
630 ms |
53144 KB |
Output is correct |
4 |
Correct |
1734 ms |
93844 KB |
Output is correct |
5 |
Correct |
1589 ms |
84724 KB |
Output is correct |
6 |
Correct |
1751 ms |
96332 KB |
Output is correct |
7 |
Correct |
1455 ms |
76260 KB |
Output is correct |
8 |
Correct |
1014 ms |
63816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
14548 KB |
Output is correct |
2 |
Correct |
10 ms |
14540 KB |
Output is correct |
3 |
Correct |
10 ms |
14560 KB |
Output is correct |
4 |
Correct |
10 ms |
14548 KB |
Output is correct |
5 |
Correct |
2364 ms |
102988 KB |
Output is correct |
6 |
Correct |
1918 ms |
92684 KB |
Output is correct |
7 |
Correct |
1579 ms |
82588 KB |
Output is correct |
8 |
Correct |
925 ms |
66180 KB |
Output is correct |
9 |
Correct |
120 ms |
27400 KB |
Output is correct |
10 |
Correct |
126 ms |
34644 KB |
Output is correct |
11 |
Correct |
145 ms |
35468 KB |
Output is correct |
12 |
Correct |
1273 ms |
78808 KB |
Output is correct |
13 |
Correct |
956 ms |
66172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14548 KB |
Output is correct |
2 |
Correct |
9 ms |
14560 KB |
Output is correct |
3 |
Correct |
10 ms |
14548 KB |
Output is correct |
4 |
Correct |
10 ms |
14676 KB |
Output is correct |
5 |
Correct |
1161 ms |
76552 KB |
Output is correct |
6 |
Correct |
1434 ms |
89156 KB |
Output is correct |
7 |
Correct |
1750 ms |
99992 KB |
Output is correct |
8 |
Correct |
2277 ms |
111812 KB |
Output is correct |
9 |
Correct |
423 ms |
53576 KB |
Output is correct |
10 |
Correct |
327 ms |
49544 KB |
Output is correct |
11 |
Correct |
416 ms |
53580 KB |
Output is correct |
12 |
Correct |
370 ms |
49604 KB |
Output is correct |
13 |
Correct |
419 ms |
53808 KB |
Output is correct |
14 |
Correct |
335 ms |
49248 KB |
Output is correct |
15 |
Correct |
1228 ms |
83236 KB |
Output is correct |
16 |
Correct |
948 ms |
70464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14320 KB |
Output is correct |
3 |
Correct |
8 ms |
14420 KB |
Output is correct |
4 |
Correct |
8 ms |
14420 KB |
Output is correct |
5 |
Correct |
8 ms |
14424 KB |
Output is correct |
6 |
Correct |
7 ms |
14420 KB |
Output is correct |
7 |
Correct |
8 ms |
14428 KB |
Output is correct |
8 |
Correct |
266 ms |
41616 KB |
Output is correct |
9 |
Correct |
341 ms |
45508 KB |
Output is correct |
10 |
Correct |
630 ms |
53144 KB |
Output is correct |
11 |
Correct |
1734 ms |
93844 KB |
Output is correct |
12 |
Correct |
1589 ms |
84724 KB |
Output is correct |
13 |
Correct |
1751 ms |
96332 KB |
Output is correct |
14 |
Correct |
1455 ms |
76260 KB |
Output is correct |
15 |
Correct |
1014 ms |
63816 KB |
Output is correct |
16 |
Correct |
13 ms |
14548 KB |
Output is correct |
17 |
Correct |
10 ms |
14540 KB |
Output is correct |
18 |
Correct |
10 ms |
14560 KB |
Output is correct |
19 |
Correct |
10 ms |
14548 KB |
Output is correct |
20 |
Correct |
2364 ms |
102988 KB |
Output is correct |
21 |
Correct |
1918 ms |
92684 KB |
Output is correct |
22 |
Correct |
1579 ms |
82588 KB |
Output is correct |
23 |
Correct |
925 ms |
66180 KB |
Output is correct |
24 |
Correct |
120 ms |
27400 KB |
Output is correct |
25 |
Correct |
126 ms |
34644 KB |
Output is correct |
26 |
Correct |
145 ms |
35468 KB |
Output is correct |
27 |
Correct |
1273 ms |
78808 KB |
Output is correct |
28 |
Correct |
956 ms |
66172 KB |
Output is correct |
29 |
Correct |
10 ms |
14548 KB |
Output is correct |
30 |
Correct |
9 ms |
14560 KB |
Output is correct |
31 |
Correct |
10 ms |
14548 KB |
Output is correct |
32 |
Correct |
10 ms |
14676 KB |
Output is correct |
33 |
Correct |
1161 ms |
76552 KB |
Output is correct |
34 |
Correct |
1434 ms |
89156 KB |
Output is correct |
35 |
Correct |
1750 ms |
99992 KB |
Output is correct |
36 |
Correct |
2277 ms |
111812 KB |
Output is correct |
37 |
Correct |
423 ms |
53576 KB |
Output is correct |
38 |
Correct |
327 ms |
49544 KB |
Output is correct |
39 |
Correct |
416 ms |
53580 KB |
Output is correct |
40 |
Correct |
370 ms |
49604 KB |
Output is correct |
41 |
Correct |
419 ms |
53808 KB |
Output is correct |
42 |
Correct |
335 ms |
49248 KB |
Output is correct |
43 |
Correct |
1228 ms |
83236 KB |
Output is correct |
44 |
Correct |
948 ms |
70464 KB |
Output is correct |
45 |
Correct |
108 ms |
27272 KB |
Output is correct |
46 |
Correct |
216 ms |
31540 KB |
Output is correct |
47 |
Correct |
859 ms |
57596 KB |
Output is correct |
48 |
Correct |
1742 ms |
97080 KB |
Output is correct |
49 |
Correct |
148 ms |
36848 KB |
Output is correct |
50 |
Correct |
141 ms |
36224 KB |
Output is correct |
51 |
Correct |
170 ms |
36988 KB |
Output is correct |
52 |
Correct |
170 ms |
37924 KB |
Output is correct |
53 |
Correct |
209 ms |
38096 KB |
Output is correct |
54 |
Correct |
173 ms |
38084 KB |
Output is correct |