#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) (x).begin(), (x).end()
const int mxn = 3e5 + 100;
struct Node {
ll sum = 0, suf = 0, total = 0;
} null;
struct SGT {
vector<Node> sgt;
SGT(int sz) {
sgt.resize(4 * sz);
}
void merge(Node &k, Node k1, Node k2) {
k.sum = k1.sum + k2.sum;
k.suf = max(k2.suf, k1.suf + k2.sum);
}
void fix(int k, int l, int r, int i, ll val) {
if (l > i || r < i) return;
if (l == r) {
sgt[k].sum = val;
sgt[k].suf = max(val, 0LL);
return;
}
int mid = (l + r) / 2;
fix(k * 2, l, mid, i, val);
fix(k * 2 + 1, mid + 1, r, i, val);
merge(sgt[k], sgt[k * 2], sgt[k * 2 + 1]);
}
void update(int k, int l, int r, int i, ll val) {
if (l > i || r < i) return;
if (l == r) {
sgt[k].total = val;
return;
}
int mid = (l + r) / 2;
update(k * 2, l, mid, i, val);
update(k * 2 + 1, mid + 1, r, i, val);
sgt[k].total = sgt[k * 2].total + sgt[k * 2 + 1].total;
}
Node mx(int k, int l, int r, int i, int j) {
if (l > j || r < i) return null;
if (i <= l && r <= j) return sgt[k];
int mid = (l + r) / 2;
Node ansL = mx(k * 2, l, mid, i, j), ansR = mx(k * 2 + 1, mid + 1, r, i, j);
Node ans;
merge(ans, ansL, ansR);
return ans;
}
ll get(int k, int l, int r, int i, int j) {
if (l > j || r < i) return 0;
if (i <= l && r <= j) return sgt[k].total;
int mid = (l + r) / 2;
return get(k * 2, l, mid, i, j) + get(k * 2 + 1, mid + 1, r, i, j);
}
int walk(int k, int l, int r, int i) {
if (l == r) return sgt[k].total > i ? l : l + 1;
int mid = (l + r) / 2;
if (sgt[k * 2].total > i) return walk(k * 2, l, mid, i);
return walk(k * 2 + 1, mid + 1, r, i - sgt[k * 2].total);
}
} sgt(mxn);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, q;
cin >> n >> m >> q;
vector<pair<int, int>> qs[n + 10], fs[n + 10], xs[n + 10];
int l[q + 10], r[q + 10], c[q + 10], k[q + 10], a[q + 10], b[q + 10];
for (int i = 0; i < q; i++) {
int type;
cin >> type;
if (type == 1) {
cin >> l[i] >> r[i] >> c[i] >> k[i];
qs[l[i]].push_back({i, k[i]});
qs[r[i] + 1].push_back({i, 0});
fs[l[i]].push_back({i, k[i]});
fs[r[i] + 1].push_back({i, 0});
}
if (type == 2) {
cin >> l[i] >> r[i] >> k[i];
qs[l[i]].push_back({i, -k[i]});
qs[r[i] + 1].push_back({i, 0});
}
if (type == 3) {
cin >> a[i] >> b[i];
xs[a[i]].push_back({i, b[i]});
}
}
ll ans[q + 10];
memset(ans, -1, sizeof(ans));
for (int i = 1; i <= n; i++) {
for (auto x : qs[i]) sgt.fix(1, 0, q - 1, x.first, x.second);
for (auto x : fs[i]) sgt.update(1, 0, q - 1, x.first, x.second);
for (auto x : xs[i]) {
Node val = sgt.mx(1, 0, q - 1, 0, x.first);
if (val.suf < x.second) {
ans[x.first] = 0;
continue;
}
ll ind = sgt.get(1, 0, q - 1, 0, x.first) - val.suf + x.second;
ans[x.first] = c[sgt.walk(1, 0, q - 1, ind - 1)];
}
}
for (int i = 0; i < q; i++) {
if (ans[i] != -1) cout << ans[i] << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
28908 KB |
Output is correct |
2 |
Correct |
13 ms |
28824 KB |
Output is correct |
3 |
Correct |
12 ms |
28764 KB |
Output is correct |
4 |
Correct |
14 ms |
28760 KB |
Output is correct |
5 |
Correct |
12 ms |
28724 KB |
Output is correct |
6 |
Correct |
13 ms |
28760 KB |
Output is correct |
7 |
Correct |
14 ms |
28764 KB |
Output is correct |
8 |
Correct |
14 ms |
28764 KB |
Output is correct |
9 |
Correct |
14 ms |
28996 KB |
Output is correct |
10 |
Correct |
16 ms |
28760 KB |
Output is correct |
11 |
Correct |
13 ms |
28764 KB |
Output is correct |
12 |
Correct |
12 ms |
28888 KB |
Output is correct |
13 |
Correct |
13 ms |
29016 KB |
Output is correct |
14 |
Correct |
16 ms |
28912 KB |
Output is correct |
15 |
Correct |
14 ms |
28760 KB |
Output is correct |
16 |
Correct |
13 ms |
28760 KB |
Output is correct |
17 |
Correct |
15 ms |
28764 KB |
Output is correct |
18 |
Correct |
13 ms |
28764 KB |
Output is correct |
19 |
Correct |
13 ms |
28764 KB |
Output is correct |
20 |
Correct |
13 ms |
29016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
28908 KB |
Output is correct |
2 |
Correct |
13 ms |
28824 KB |
Output is correct |
3 |
Correct |
12 ms |
28764 KB |
Output is correct |
4 |
Correct |
14 ms |
28760 KB |
Output is correct |
5 |
Correct |
12 ms |
28724 KB |
Output is correct |
6 |
Correct |
13 ms |
28760 KB |
Output is correct |
7 |
Correct |
14 ms |
28764 KB |
Output is correct |
8 |
Correct |
14 ms |
28764 KB |
Output is correct |
9 |
Correct |
14 ms |
28996 KB |
Output is correct |
10 |
Correct |
16 ms |
28760 KB |
Output is correct |
11 |
Correct |
13 ms |
28764 KB |
Output is correct |
12 |
Correct |
12 ms |
28888 KB |
Output is correct |
13 |
Correct |
13 ms |
29016 KB |
Output is correct |
14 |
Correct |
16 ms |
28912 KB |
Output is correct |
15 |
Correct |
14 ms |
28760 KB |
Output is correct |
16 |
Correct |
13 ms |
28760 KB |
Output is correct |
17 |
Correct |
15 ms |
28764 KB |
Output is correct |
18 |
Correct |
13 ms |
28764 KB |
Output is correct |
19 |
Correct |
13 ms |
28764 KB |
Output is correct |
20 |
Correct |
13 ms |
29016 KB |
Output is correct |
21 |
Incorrect |
12 ms |
28764 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
39760 KB |
Output is correct |
2 |
Correct |
73 ms |
40016 KB |
Output is correct |
3 |
Correct |
70 ms |
39692 KB |
Output is correct |
4 |
Correct |
63 ms |
39504 KB |
Output is correct |
5 |
Correct |
79 ms |
40136 KB |
Output is correct |
6 |
Correct |
69 ms |
40124 KB |
Output is correct |
7 |
Correct |
33 ms |
32444 KB |
Output is correct |
8 |
Correct |
34 ms |
32896 KB |
Output is correct |
9 |
Correct |
66 ms |
39864 KB |
Output is correct |
10 |
Correct |
66 ms |
39772 KB |
Output is correct |
11 |
Correct |
76 ms |
39876 KB |
Output is correct |
12 |
Correct |
68 ms |
39764 KB |
Output is correct |
13 |
Correct |
59 ms |
37460 KB |
Output is correct |
14 |
Correct |
72 ms |
39996 KB |
Output is correct |
15 |
Correct |
75 ms |
38836 KB |
Output is correct |
16 |
Correct |
78 ms |
40500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
53456 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
28908 KB |
Output is correct |
2 |
Correct |
13 ms |
28824 KB |
Output is correct |
3 |
Correct |
12 ms |
28764 KB |
Output is correct |
4 |
Correct |
14 ms |
28760 KB |
Output is correct |
5 |
Correct |
12 ms |
28724 KB |
Output is correct |
6 |
Correct |
13 ms |
28760 KB |
Output is correct |
7 |
Correct |
14 ms |
28764 KB |
Output is correct |
8 |
Correct |
14 ms |
28764 KB |
Output is correct |
9 |
Correct |
14 ms |
28996 KB |
Output is correct |
10 |
Correct |
16 ms |
28760 KB |
Output is correct |
11 |
Correct |
13 ms |
28764 KB |
Output is correct |
12 |
Correct |
12 ms |
28888 KB |
Output is correct |
13 |
Correct |
13 ms |
29016 KB |
Output is correct |
14 |
Correct |
16 ms |
28912 KB |
Output is correct |
15 |
Correct |
14 ms |
28760 KB |
Output is correct |
16 |
Correct |
13 ms |
28760 KB |
Output is correct |
17 |
Correct |
15 ms |
28764 KB |
Output is correct |
18 |
Correct |
13 ms |
28764 KB |
Output is correct |
19 |
Correct |
13 ms |
28764 KB |
Output is correct |
20 |
Correct |
13 ms |
29016 KB |
Output is correct |
21 |
Correct |
69 ms |
39760 KB |
Output is correct |
22 |
Correct |
73 ms |
40016 KB |
Output is correct |
23 |
Correct |
70 ms |
39692 KB |
Output is correct |
24 |
Correct |
63 ms |
39504 KB |
Output is correct |
25 |
Correct |
79 ms |
40136 KB |
Output is correct |
26 |
Correct |
69 ms |
40124 KB |
Output is correct |
27 |
Correct |
33 ms |
32444 KB |
Output is correct |
28 |
Correct |
34 ms |
32896 KB |
Output is correct |
29 |
Correct |
66 ms |
39864 KB |
Output is correct |
30 |
Correct |
66 ms |
39772 KB |
Output is correct |
31 |
Correct |
76 ms |
39876 KB |
Output is correct |
32 |
Correct |
68 ms |
39764 KB |
Output is correct |
33 |
Correct |
59 ms |
37460 KB |
Output is correct |
34 |
Correct |
72 ms |
39996 KB |
Output is correct |
35 |
Correct |
75 ms |
38836 KB |
Output is correct |
36 |
Correct |
78 ms |
40500 KB |
Output is correct |
37 |
Correct |
65 ms |
38480 KB |
Output is correct |
38 |
Correct |
61 ms |
38228 KB |
Output is correct |
39 |
Correct |
32 ms |
32048 KB |
Output is correct |
40 |
Correct |
36 ms |
32704 KB |
Output is correct |
41 |
Correct |
75 ms |
39672 KB |
Output is correct |
42 |
Correct |
70 ms |
39760 KB |
Output is correct |
43 |
Correct |
71 ms |
39508 KB |
Output is correct |
44 |
Correct |
69 ms |
39512 KB |
Output is correct |
45 |
Correct |
71 ms |
39760 KB |
Output is correct |
46 |
Correct |
74 ms |
39500 KB |
Output is correct |
47 |
Correct |
44 ms |
37956 KB |
Output is correct |
48 |
Correct |
60 ms |
38508 KB |
Output is correct |
49 |
Correct |
52 ms |
36432 KB |
Output is correct |
50 |
Correct |
59 ms |
38808 KB |
Output is correct |
51 |
Correct |
72 ms |
39724 KB |
Output is correct |
52 |
Correct |
71 ms |
39764 KB |
Output is correct |
53 |
Correct |
62 ms |
38368 KB |
Output is correct |
54 |
Correct |
98 ms |
40516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
35456 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
28908 KB |
Output is correct |
2 |
Correct |
13 ms |
28824 KB |
Output is correct |
3 |
Correct |
12 ms |
28764 KB |
Output is correct |
4 |
Correct |
14 ms |
28760 KB |
Output is correct |
5 |
Correct |
12 ms |
28724 KB |
Output is correct |
6 |
Correct |
13 ms |
28760 KB |
Output is correct |
7 |
Correct |
14 ms |
28764 KB |
Output is correct |
8 |
Correct |
14 ms |
28764 KB |
Output is correct |
9 |
Correct |
14 ms |
28996 KB |
Output is correct |
10 |
Correct |
16 ms |
28760 KB |
Output is correct |
11 |
Correct |
13 ms |
28764 KB |
Output is correct |
12 |
Correct |
12 ms |
28888 KB |
Output is correct |
13 |
Correct |
13 ms |
29016 KB |
Output is correct |
14 |
Correct |
16 ms |
28912 KB |
Output is correct |
15 |
Correct |
14 ms |
28760 KB |
Output is correct |
16 |
Correct |
13 ms |
28760 KB |
Output is correct |
17 |
Correct |
15 ms |
28764 KB |
Output is correct |
18 |
Correct |
13 ms |
28764 KB |
Output is correct |
19 |
Correct |
13 ms |
28764 KB |
Output is correct |
20 |
Correct |
13 ms |
29016 KB |
Output is correct |
21 |
Incorrect |
12 ms |
28764 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
28908 KB |
Output is correct |
2 |
Correct |
13 ms |
28824 KB |
Output is correct |
3 |
Correct |
12 ms |
28764 KB |
Output is correct |
4 |
Correct |
14 ms |
28760 KB |
Output is correct |
5 |
Correct |
12 ms |
28724 KB |
Output is correct |
6 |
Correct |
13 ms |
28760 KB |
Output is correct |
7 |
Correct |
14 ms |
28764 KB |
Output is correct |
8 |
Correct |
14 ms |
28764 KB |
Output is correct |
9 |
Correct |
14 ms |
28996 KB |
Output is correct |
10 |
Correct |
16 ms |
28760 KB |
Output is correct |
11 |
Correct |
13 ms |
28764 KB |
Output is correct |
12 |
Correct |
12 ms |
28888 KB |
Output is correct |
13 |
Correct |
13 ms |
29016 KB |
Output is correct |
14 |
Correct |
16 ms |
28912 KB |
Output is correct |
15 |
Correct |
14 ms |
28760 KB |
Output is correct |
16 |
Correct |
13 ms |
28760 KB |
Output is correct |
17 |
Correct |
15 ms |
28764 KB |
Output is correct |
18 |
Correct |
13 ms |
28764 KB |
Output is correct |
19 |
Correct |
13 ms |
28764 KB |
Output is correct |
20 |
Correct |
13 ms |
29016 KB |
Output is correct |
21 |
Incorrect |
12 ms |
28764 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |