# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
883489 | 2023-12-05T10:59:15 Z | vjudge1 | Ants and Sugar (JOI22_sugar) | C++17 | 903 ms | 118332 KB |
// https://oj.uz/problem/view/JOI22_sugar #include <bits/stdc++.h> using namespace std; /* Hall's theorem Answer = A - max(|S| - |NG(S)|) */ const int64_t inf = 1e18; class segtree_t { public: segtree_t *left, *right; int l, r, m; int64_t x[2][2], lazyx, lazy_mid, mid; segtree_t(int l, int r) : l(l), r(r), m(l + r >> 1), lazy_mid(0), lazyx(0), mid(0) { for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { x[i][j] = 0; } } if (l == r) return; left = new segtree_t(l, m); right = new segtree_t(m + 1, r); } void Update(int s, int t, int64_t val) { if (l > t || r < s) return; if (s <= l && r <= t) { for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { x[i][j] += val; } } lazyx += val; lazy_mid += val; mid += val; return; } Down(); if (s <= m && m < t) mid += val; left->Update(s, t, val); right->Update(s, t, val); Up(); } void Down() { for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { left->x[i][j] += lazyx; right->x[i][j] += lazyx; } } left->lazy_mid += lazy_mid; left->lazyx += lazyx; left->mid += lazy_mid; right->lazy_mid += lazy_mid; right->lazyx += lazyx; right->mid += lazy_mid; lazy_mid = lazyx = 0; } void Up() { for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { x[i][j] = -inf; for (int k = 0; k < 2; k++) { x[i][j] = max<int64_t>(x[i][j], left->x[i][k] + right->x[k][j] - 1ll * k * mid); } } } for (int i = 0; i < 2; i++) { x[i][0] = max(x[i][0], left->x[i][0]); x[0][i] = max(x[0][i], right->x[0][i]); } } }; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int q, L; cin >> q >> L; vector<int> t(q), a(q), x(q); for (int i = 0; i < q; i++) cin >> t[i] >> x[i] >> a[i]; vector<int> cord; for (int i = 0; i < q; i++) { if (t[i] == 1) cord.emplace_back(x[i]); } sort(cord.begin(), cord.end()); cord.resize(unique(cord.begin(), cord.end()) - cord.begin()); int N = cord.size(); segtree_t* tree = new segtree_t(0, N); int64_t A = 0; for (int i = 0; i < q; i++) { if (t[i] == 1) { A += a[i]; int y = lower_bound(cord.begin(), cord.end(), x[i]) - cord.begin(); tree->Update(y, y, +a[i]); } else { int u = lower_bound(cord.begin(), cord.end(), x[i] - L) - cord.begin(); int v = upper_bound(cord.begin(), cord.end(), x[i] + L) - cord.begin() - 1; tree->Update(u, v, -a[i]); } cout << A - max<int64_t>(0, tree->x[0][0]) << '\n'; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 2 ms | 604 KB | Output is correct |
7 | Correct | 1 ms | 464 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 2 ms | 860 KB | Output is correct |
11 | Correct | 2 ms | 856 KB | Output is correct |
12 | Correct | 2 ms | 860 KB | Output is correct |
13 | Correct | 2 ms | 860 KB | Output is correct |
14 | Correct | 1 ms | 548 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 3 ms | 980 KB | Output is correct |
17 | Correct | 3 ms | 1116 KB | Output is correct |
18 | Correct | 3 ms | 968 KB | Output is correct |
19 | Correct | 3 ms | 860 KB | Output is correct |
20 | Correct | 2 ms | 1116 KB | Output is correct |
21 | Correct | 2 ms | 812 KB | Output is correct |
22 | Correct | 3 ms | 1116 KB | Output is correct |
23 | Correct | 3 ms | 1112 KB | Output is correct |
24 | Correct | 2 ms | 976 KB | Output is correct |
25 | Correct | 3 ms | 856 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 396 ms | 32244 KB | Output is correct |
5 | Correct | 171 ms | 34160 KB | Output is correct |
6 | Correct | 492 ms | 45256 KB | Output is correct |
7 | Correct | 172 ms | 34456 KB | Output is correct |
8 | Correct | 602 ms | 53284 KB | Output is correct |
9 | Correct | 390 ms | 71356 KB | Output is correct |
10 | Correct | 599 ms | 53300 KB | Output is correct |
11 | Correct | 397 ms | 71084 KB | Output is correct |
12 | Correct | 161 ms | 30328 KB | Output is correct |
13 | Correct | 237 ms | 41932 KB | Output is correct |
14 | Correct | 391 ms | 68040 KB | Output is correct |
15 | Correct | 425 ms | 67880 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 175 ms | 26168 KB | Output is correct |
3 | Correct | 225 ms | 41676 KB | Output is correct |
4 | Correct | 414 ms | 67764 KB | Output is correct |
5 | Correct | 383 ms | 67740 KB | Output is correct |
6 | Correct | 497 ms | 47928 KB | Output is correct |
7 | Correct | 24 ms | 4444 KB | Output is correct |
8 | Correct | 200 ms | 25552 KB | Output is correct |
9 | Correct | 344 ms | 36864 KB | Output is correct |
10 | Correct | 676 ms | 69164 KB | Output is correct |
11 | Correct | 664 ms | 69168 KB | Output is correct |
12 | Correct | 662 ms | 69072 KB | Output is correct |
13 | Correct | 688 ms | 69084 KB | Output is correct |
14 | Correct | 668 ms | 69072 KB | Output is correct |
15 | Correct | 678 ms | 68900 KB | Output is correct |
16 | Correct | 667 ms | 69064 KB | Output is correct |
17 | Correct | 749 ms | 69084 KB | Output is correct |
18 | Correct | 840 ms | 69172 KB | Output is correct |
19 | Correct | 807 ms | 69128 KB | Output is correct |
20 | Correct | 772 ms | 69212 KB | Output is correct |
21 | Correct | 813 ms | 69048 KB | Output is correct |
22 | Correct | 838 ms | 69232 KB | Output is correct |
23 | Correct | 816 ms | 69108 KB | Output is correct |
24 | Correct | 534 ms | 69004 KB | Output is correct |
25 | Correct | 726 ms | 69192 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 2 ms | 604 KB | Output is correct |
7 | Correct | 1 ms | 464 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 2 ms | 860 KB | Output is correct |
11 | Correct | 2 ms | 856 KB | Output is correct |
12 | Correct | 2 ms | 860 KB | Output is correct |
13 | Correct | 2 ms | 860 KB | Output is correct |
14 | Correct | 1 ms | 548 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 3 ms | 980 KB | Output is correct |
17 | Correct | 3 ms | 1116 KB | Output is correct |
18 | Correct | 3 ms | 968 KB | Output is correct |
19 | Correct | 3 ms | 860 KB | Output is correct |
20 | Correct | 2 ms | 1116 KB | Output is correct |
21 | Correct | 2 ms | 812 KB | Output is correct |
22 | Correct | 3 ms | 1116 KB | Output is correct |
23 | Correct | 3 ms | 1112 KB | Output is correct |
24 | Correct | 2 ms | 976 KB | Output is correct |
25 | Correct | 3 ms | 856 KB | Output is correct |
26 | Correct | 0 ms | 348 KB | Output is correct |
27 | Correct | 0 ms | 348 KB | Output is correct |
28 | Correct | 0 ms | 348 KB | Output is correct |
29 | Correct | 396 ms | 32244 KB | Output is correct |
30 | Correct | 171 ms | 34160 KB | Output is correct |
31 | Correct | 492 ms | 45256 KB | Output is correct |
32 | Correct | 172 ms | 34456 KB | Output is correct |
33 | Correct | 602 ms | 53284 KB | Output is correct |
34 | Correct | 390 ms | 71356 KB | Output is correct |
35 | Correct | 599 ms | 53300 KB | Output is correct |
36 | Correct | 397 ms | 71084 KB | Output is correct |
37 | Correct | 161 ms | 30328 KB | Output is correct |
38 | Correct | 237 ms | 41932 KB | Output is correct |
39 | Correct | 391 ms | 68040 KB | Output is correct |
40 | Correct | 425 ms | 67880 KB | Output is correct |
41 | Correct | 0 ms | 348 KB | Output is correct |
42 | Correct | 175 ms | 26168 KB | Output is correct |
43 | Correct | 225 ms | 41676 KB | Output is correct |
44 | Correct | 414 ms | 67764 KB | Output is correct |
45 | Correct | 383 ms | 67740 KB | Output is correct |
46 | Correct | 497 ms | 47928 KB | Output is correct |
47 | Correct | 24 ms | 4444 KB | Output is correct |
48 | Correct | 200 ms | 25552 KB | Output is correct |
49 | Correct | 344 ms | 36864 KB | Output is correct |
50 | Correct | 676 ms | 69164 KB | Output is correct |
51 | Correct | 664 ms | 69168 KB | Output is correct |
52 | Correct | 662 ms | 69072 KB | Output is correct |
53 | Correct | 688 ms | 69084 KB | Output is correct |
54 | Correct | 668 ms | 69072 KB | Output is correct |
55 | Correct | 678 ms | 68900 KB | Output is correct |
56 | Correct | 667 ms | 69064 KB | Output is correct |
57 | Correct | 749 ms | 69084 KB | Output is correct |
58 | Correct | 840 ms | 69172 KB | Output is correct |
59 | Correct | 807 ms | 69128 KB | Output is correct |
60 | Correct | 772 ms | 69212 KB | Output is correct |
61 | Correct | 813 ms | 69048 KB | Output is correct |
62 | Correct | 838 ms | 69232 KB | Output is correct |
63 | Correct | 816 ms | 69108 KB | Output is correct |
64 | Correct | 534 ms | 69004 KB | Output is correct |
65 | Correct | 726 ms | 69192 KB | Output is correct |
66 | Correct | 318 ms | 37328 KB | Output is correct |
67 | Correct | 406 ms | 43648 KB | Output is correct |
68 | Correct | 503 ms | 51124 KB | Output is correct |
69 | Correct | 452 ms | 46840 KB | Output is correct |
70 | Correct | 662 ms | 72100 KB | Output is correct |
71 | Correct | 662 ms | 72112 KB | Output is correct |
72 | Correct | 666 ms | 71984 KB | Output is correct |
73 | Correct | 709 ms | 72368 KB | Output is correct |
74 | Correct | 121 ms | 17848 KB | Output is correct |
75 | Correct | 319 ms | 24492 KB | Output is correct |
76 | Correct | 761 ms | 118332 KB | Output is correct |
77 | Correct | 804 ms | 113880 KB | Output is correct |
78 | Correct | 783 ms | 113752 KB | Output is correct |
79 | Correct | 725 ms | 72128 KB | Output is correct |
80 | Correct | 856 ms | 113828 KB | Output is correct |
81 | Correct | 704 ms | 72104 KB | Output is correct |
82 | Correct | 849 ms | 113800 KB | Output is correct |
83 | Correct | 855 ms | 72488 KB | Output is correct |
84 | Correct | 832 ms | 113908 KB | Output is correct |
85 | Correct | 903 ms | 72564 KB | Output is correct |
86 | Correct | 833 ms | 113860 KB | Output is correct |
87 | Correct | 893 ms | 72464 KB | Output is correct |
88 | Correct | 785 ms | 113744 KB | Output is correct |
89 | Correct | 796 ms | 95776 KB | Output is correct |