Submission #260106

# Submission time Handle Problem Language Result Execution time Memory
260106 2020-08-09T10:37:08 Z islingr Street Lamps (APIO19_street_lamps) C++17
100 / 100
3842 ms 64632 KB
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)

const int N = 1 << 19;
struct { bool ask; int l, r, t, del; } a[3 * N], b[3 * N];
int q, ans[N];

void cdq2(int l, int r) {
	if (r - l == 1) return;
	int m = (l + r) >> 1;
	cdq2(l, m); cdq2(m, r);
	rep(i, l, r) b[i].r = i < m;
	inplace_merge(b + l, b + m, b + r, [&](const auto &a, const auto &b) { return a.t < b.t; });
	int s = 0;
	rep(i, l, r) {
		if (!b[i].ask && b[i].l && b[i].r) s += b[i].del * b[i].t;
		if (b[i].ask && !b[i].l && !b[i].r) ans[b[i].t] += s;
	}
}

void cdq1(int l, int r) {
	if (r - l == 1) return;
	int m = (l + r) >> 1;
	cdq1(l, m); cdq1(m, r);
	rep(i, l, r) a[i].l = i < m;
	merge(a + l, a + m, a + m, a + r, b + l, [&](const auto &a, const auto &b) { return pair(-a.r, a.ask) < pair(-b.r, b.ask); });
	rep(i, l, r) a[i] = b[i];
	cdq2(l, r);
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n, p = 0; cin >> n >> q; int pre = -1;
	set<int> z = {-1};
	rep(i, 0, n) {
		char c; cin >> c;
		if (c != '0') {
			if (p && a[p - 1].r == i) a[p - 1].r = i + 1;
			else a[p++] = {0, pre + 1, i + 1, -1, -1};
		} else z.insert(pre = i);
	}
	z.insert(n);

	rep(t, 0, q) {
		string s; cin >> s;
		if (s == "toggle") {
			int i; cin >> i; --i;
			auto [it, f] = z.insert(i);
			int d = f ? +1 : -1;
			a[p++] = {0, *prev(it) + 1, *next(it), t, +d};
			a[p++] = {0, *prev(it) + 1, i, t, -d};
			a[p++] = {0, i + 1, *next(it), t, -d};
			if (d < 0) z.erase(it);
			ans[t] = -1;
		} else {
			int l, r; cin >> l >> r; --l; --r;
			a[p++] = {1, l, r, t, 0};
			ans[t] = *z.lower_bound(l) < r ? 0 : t;
		}
	}

	sort(a, a + p, [&](const auto &a, const auto &b) { return pair(a.l, a.ask) < pair(b.l, b.ask); });
	cdq1(0, p);
	rep(t, 0, q) if (0 <= ans[t]) cout << ans[t] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2514 ms 37136 KB Output is correct
2 Correct 2607 ms 37452 KB Output is correct
3 Correct 2671 ms 38128 KB Output is correct
4 Correct 3097 ms 50076 KB Output is correct
5 Correct 3021 ms 45368 KB Output is correct
6 Correct 2977 ms 53244 KB Output is correct
7 Correct 1448 ms 36600 KB Output is correct
8 Correct 1188 ms 22808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3725 ms 63240 KB Output is correct
6 Correct 3273 ms 53700 KB Output is correct
7 Correct 2818 ms 43952 KB Output is correct
8 Correct 1437 ms 21528 KB Output is correct
9 Correct 805 ms 17328 KB Output is correct
10 Correct 876 ms 18884 KB Output is correct
11 Correct 840 ms 19048 KB Output is correct
12 Correct 1717 ms 35608 KB Output is correct
13 Correct 1438 ms 21524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 1838 ms 32916 KB Output is correct
6 Correct 2464 ms 42232 KB Output is correct
7 Correct 3023 ms 51944 KB Output is correct
8 Correct 3842 ms 64632 KB Output is correct
9 Correct 3127 ms 44732 KB Output is correct
10 Correct 3599 ms 52576 KB Output is correct
11 Correct 3065 ms 45008 KB Output is correct
12 Correct 3637 ms 52568 KB Output is correct
13 Correct 3110 ms 44968 KB Output is correct
14 Correct 3694 ms 52432 KB Output is correct
15 Correct 1813 ms 35728 KB Output is correct
16 Correct 1435 ms 21652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2514 ms 37136 KB Output is correct
9 Correct 2607 ms 37452 KB Output is correct
10 Correct 2671 ms 38128 KB Output is correct
11 Correct 3097 ms 50076 KB Output is correct
12 Correct 3021 ms 45368 KB Output is correct
13 Correct 2977 ms 53244 KB Output is correct
14 Correct 1448 ms 36600 KB Output is correct
15 Correct 1188 ms 22808 KB Output is correct
16 Correct 6 ms 512 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3725 ms 63240 KB Output is correct
21 Correct 3273 ms 53700 KB Output is correct
22 Correct 2818 ms 43952 KB Output is correct
23 Correct 1437 ms 21528 KB Output is correct
24 Correct 805 ms 17328 KB Output is correct
25 Correct 876 ms 18884 KB Output is correct
26 Correct 840 ms 19048 KB Output is correct
27 Correct 1717 ms 35608 KB Output is correct
28 Correct 1438 ms 21524 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 4 ms 512 KB Output is correct
31 Correct 5 ms 512 KB Output is correct
32 Correct 6 ms 512 KB Output is correct
33 Correct 1838 ms 32916 KB Output is correct
34 Correct 2464 ms 42232 KB Output is correct
35 Correct 3023 ms 51944 KB Output is correct
36 Correct 3842 ms 64632 KB Output is correct
37 Correct 3127 ms 44732 KB Output is correct
38 Correct 3599 ms 52576 KB Output is correct
39 Correct 3065 ms 45008 KB Output is correct
40 Correct 3637 ms 52568 KB Output is correct
41 Correct 3110 ms 44968 KB Output is correct
42 Correct 3694 ms 52432 KB Output is correct
43 Correct 1813 ms 35728 KB Output is correct
44 Correct 1435 ms 21652 KB Output is correct
45 Correct 1435 ms 24644 KB Output is correct
46 Correct 1608 ms 24908 KB Output is correct
47 Correct 1738 ms 29624 KB Output is correct
48 Correct 2987 ms 48920 KB Output is correct
49 Correct 1092 ms 21212 KB Output is correct
50 Correct 1051 ms 21252 KB Output is correct
51 Correct 1026 ms 21400 KB Output is correct
52 Correct 921 ms 21656 KB Output is correct
53 Correct 909 ms 21780 KB Output is correct
54 Correct 902 ms 21656 KB Output is correct