# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
883490 | 2023-12-05T10:59:58 Z | vjudge1 | Ants and Sugar (JOI22_sugar) | C++17 | 850 ms | 113192 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 344 KB | Output is correct |
4 | Correct | 1 ms | 344 KB | Output is correct |
5 | Correct | 1 ms | 344 KB | Output is correct |
6 | Correct | 2 ms | 604 KB | Output is correct |
7 | Correct | 2 ms | 604 KB | Output is correct |
8 | Correct | 1 ms | 344 KB | Output is correct |
9 | Correct | 2 ms | 348 KB | Output is correct |
10 | Correct | 3 ms | 856 KB | Output is correct |
11 | Correct | 3 ms | 856 KB | Output is correct |
12 | Correct | 3 ms | 860 KB | Output is correct |
13 | Correct | 3 ms | 728 KB | Output is correct |
14 | Correct | 2 ms | 348 KB | Output is correct |
15 | Correct | 2 ms | 472 KB | Output is correct |
16 | Correct | 3 ms | 1112 KB | Output is correct |
17 | Correct | 3 ms | 1112 KB | Output is correct |
18 | Correct | 2 ms | 1116 KB | Output is correct |
19 | Correct | 2 ms | 848 KB | Output is correct |
20 | Correct | 4 ms | 1116 KB | Output is correct |
21 | Correct | 3 ms | 860 KB | Output is correct |
22 | Correct | 3 ms | 1116 KB | Output is correct |
23 | Correct | 3 ms | 860 KB | Output is correct |
24 | Correct | 3 ms | 1116 KB | Output is correct |
25 | Correct | 3 ms | 860 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 344 KB | Output is correct |
4 | Correct | 462 ms | 37436 KB | Output is correct |
5 | Correct | 176 ms | 33420 KB | Output is correct |
6 | Correct | 510 ms | 43396 KB | Output is correct |
7 | Correct | 194 ms | 33740 KB | Output is correct |
8 | Correct | 666 ms | 51760 KB | Output is correct |
9 | Correct | 376 ms | 69204 KB | Output is correct |
10 | Correct | 639 ms | 51304 KB | Output is correct |
11 | Correct | 381 ms | 69164 KB | Output is correct |
12 | Correct | 172 ms | 29652 KB | Output is correct |
13 | Correct | 238 ms | 40700 KB | Output is correct |
14 | Correct | 396 ms | 66000 KB | Output is correct |
15 | Correct | 369 ms | 65620 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 161 ms | 29556 KB | Output is correct |
3 | Correct | 229 ms | 40648 KB | Output is correct |
4 | Correct | 369 ms | 65832 KB | Output is correct |
5 | Correct | 385 ms | 65996 KB | Output is correct |
6 | Correct | 463 ms | 46288 KB | Output is correct |
7 | Correct | 24 ms | 4444 KB | Output is correct |
8 | Correct | 213 ms | 25036 KB | Output is correct |
9 | Correct | 350 ms | 35984 KB | Output is correct |
10 | Correct | 647 ms | 66764 KB | Output is correct |
11 | Correct | 637 ms | 67020 KB | Output is correct |
12 | Correct | 663 ms | 64044 KB | Output is correct |
13 | Correct | 686 ms | 64016 KB | Output is correct |
14 | Correct | 662 ms | 63992 KB | Output is correct |
15 | Correct | 626 ms | 64020 KB | Output is correct |
16 | Correct | 647 ms | 64280 KB | Output is correct |
17 | Correct | 713 ms | 64216 KB | Output is correct |
18 | Correct | 794 ms | 64424 KB | Output is correct |
19 | Correct | 778 ms | 64068 KB | Output is correct |
20 | Correct | 746 ms | 63988 KB | Output is correct |
21 | Correct | 850 ms | 64104 KB | Output is correct |
22 | Correct | 793 ms | 64204 KB | Output is correct |
23 | Correct | 809 ms | 64000 KB | Output is correct |
24 | Correct | 514 ms | 64060 KB | Output is correct |
25 | Correct | 721 ms | 64164 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 344 KB | Output is correct |
4 | Correct | 1 ms | 344 KB | Output is correct |
5 | Correct | 1 ms | 344 KB | Output is correct |
6 | Correct | 2 ms | 604 KB | Output is correct |
7 | Correct | 2 ms | 604 KB | Output is correct |
8 | Correct | 1 ms | 344 KB | Output is correct |
9 | Correct | 2 ms | 348 KB | Output is correct |
10 | Correct | 3 ms | 856 KB | Output is correct |
11 | Correct | 3 ms | 856 KB | Output is correct |
12 | Correct | 3 ms | 860 KB | Output is correct |
13 | Correct | 3 ms | 728 KB | Output is correct |
14 | Correct | 2 ms | 348 KB | Output is correct |
15 | Correct | 2 ms | 472 KB | Output is correct |
16 | Correct | 3 ms | 1112 KB | Output is correct |
17 | Correct | 3 ms | 1112 KB | Output is correct |
18 | Correct | 2 ms | 1116 KB | Output is correct |
19 | Correct | 2 ms | 848 KB | Output is correct |
20 | Correct | 4 ms | 1116 KB | Output is correct |
21 | Correct | 3 ms | 860 KB | Output is correct |
22 | Correct | 3 ms | 1116 KB | Output is correct |
23 | Correct | 3 ms | 860 KB | Output is correct |
24 | Correct | 3 ms | 1116 KB | Output is correct |
25 | Correct | 3 ms | 860 KB | Output is correct |
26 | Correct | 1 ms | 348 KB | Output is correct |
27 | Correct | 0 ms | 348 KB | Output is correct |
28 | Correct | 1 ms | 344 KB | Output is correct |
29 | Correct | 462 ms | 37436 KB | Output is correct |
30 | Correct | 176 ms | 33420 KB | Output is correct |
31 | Correct | 510 ms | 43396 KB | Output is correct |
32 | Correct | 194 ms | 33740 KB | Output is correct |
33 | Correct | 666 ms | 51760 KB | Output is correct |
34 | Correct | 376 ms | 69204 KB | Output is correct |
35 | Correct | 639 ms | 51304 KB | Output is correct |
36 | Correct | 381 ms | 69164 KB | Output is correct |
37 | Correct | 172 ms | 29652 KB | Output is correct |
38 | Correct | 238 ms | 40700 KB | Output is correct |
39 | Correct | 396 ms | 66000 KB | Output is correct |
40 | Correct | 369 ms | 65620 KB | Output is correct |
41 | Correct | 0 ms | 344 KB | Output is correct |
42 | Correct | 161 ms | 29556 KB | Output is correct |
43 | Correct | 229 ms | 40648 KB | Output is correct |
44 | Correct | 369 ms | 65832 KB | Output is correct |
45 | Correct | 385 ms | 65996 KB | Output is correct |
46 | Correct | 463 ms | 46288 KB | Output is correct |
47 | Correct | 24 ms | 4444 KB | Output is correct |
48 | Correct | 213 ms | 25036 KB | Output is correct |
49 | Correct | 350 ms | 35984 KB | Output is correct |
50 | Correct | 647 ms | 66764 KB | Output is correct |
51 | Correct | 637 ms | 67020 KB | Output is correct |
52 | Correct | 663 ms | 64044 KB | Output is correct |
53 | Correct | 686 ms | 64016 KB | Output is correct |
54 | Correct | 662 ms | 63992 KB | Output is correct |
55 | Correct | 626 ms | 64020 KB | Output is correct |
56 | Correct | 647 ms | 64280 KB | Output is correct |
57 | Correct | 713 ms | 64216 KB | Output is correct |
58 | Correct | 794 ms | 64424 KB | Output is correct |
59 | Correct | 778 ms | 64068 KB | Output is correct |
60 | Correct | 746 ms | 63988 KB | Output is correct |
61 | Correct | 850 ms | 64104 KB | Output is correct |
62 | Correct | 793 ms | 64204 KB | Output is correct |
63 | Correct | 809 ms | 64000 KB | Output is correct |
64 | Correct | 514 ms | 64060 KB | Output is correct |
65 | Correct | 721 ms | 64164 KB | Output is correct |
66 | Correct | 315 ms | 34768 KB | Output is correct |
67 | Correct | 425 ms | 40716 KB | Output is correct |
68 | Correct | 495 ms | 47616 KB | Output is correct |
69 | Correct | 430 ms | 43360 KB | Output is correct |
70 | Correct | 676 ms | 66840 KB | Output is correct |
71 | Correct | 639 ms | 66864 KB | Output is correct |
72 | Correct | 705 ms | 66932 KB | Output is correct |
73 | Correct | 698 ms | 67104 KB | Output is correct |
74 | Correct | 121 ms | 12832 KB | Output is correct |
75 | Correct | 316 ms | 19396 KB | Output is correct |
76 | Correct | 764 ms | 113192 KB | Output is correct |
77 | Correct | 761 ms | 108620 KB | Output is correct |
78 | Correct | 774 ms | 108712 KB | Output is correct |
79 | Correct | 712 ms | 67312 KB | Output is correct |
80 | Correct | 767 ms | 103316 KB | Output is correct |
81 | Correct | 692 ms | 61636 KB | Output is correct |
82 | Correct | 773 ms | 103088 KB | Output is correct |
83 | Correct | 799 ms | 61828 KB | Output is correct |
84 | Correct | 822 ms | 103208 KB | Output is correct |
85 | Correct | 810 ms | 61900 KB | Output is correct |
86 | Correct | 805 ms | 103352 KB | Output is correct |
87 | Correct | 832 ms | 61772 KB | Output is correct |
88 | Correct | 759 ms | 103756 KB | Output is correct |
89 | Correct | 767 ms | 85448 KB | Output is correct |