/* In the name of GOD */
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mk make_pair
typedef long long ll;
typedef long double ld;
typedef pair <long long, long long> pii;
const int N = 250012, SegN = (1 << 19);
const long long INF = 1e16 + 31;
pii lz[SegN];
ll slz[SegN];
ll t[N], l[N], r[N], c[N], x[N], ans[N];
ll k[N];
vector <pii> v[N];
vector <pii> s[N], e[N];
int LZ[SegN];
int MX[SegN];
void SHIFT (int v) {
if (!LZ[v])
return;
LZ[v << 1] += LZ[v];
LZ[v << 1 | 1] += LZ[v];
MX[v << 1] += LZ[v];
MX[v << 1 | 1] += LZ[v];
LZ[v] = 0;
}
void ADD (int l, int r, int x, int v = 1, int tl = 0, int tr = N - 1) {
if (tl > r || l > tr)
return;
if (l <= tl && tr <= r) {
LZ[v] += x;
MX[v] += x;
} else {
SHIFT(v);
int mid = (tl + tr) >> 1;
ADD (l, r, x, v << 1, tl, mid);
ADD (l, r, x, v << 1 | 1, mid + 1, tr);
MX[v] = max(MX[v << 1], MX[v << 1 | 1]);
}
}
int GET (int x, int v = 1, int tl = 0, int tr = N - 1) {
if (x == -1)
return 0;
if (tl == tr) {
return c[tl];
}
SHIFT(v);
int mid = (tl + tr) >> 1;
if (MX[v << 1] >= x) {
return GET (x, v << 1, tl, mid);
} else {
return GET (x, v << 1 | 1, mid + 1, tr);
}
}
void shift (int v) {
ll x = lz[v].F, y = lz[v].S;
lz[v << 1].F += x;
lz[v << 1].S += x;
lz[v << 1 | 1].F += x;
lz[v << 1 | 1].S += x;
lz[v << 1].S = max(lz[v << 1].S, y);
lz[v << 1 | 1].S = max(lz[v << 1 | 1].S, y);
slz[v << 1] += slz[v];
slz[v << 1 | 1] += slz[v];
lz[v] = mk(0, -INF);
slz[v] = 0;
}
void mx (int l, int r, ll x, int v = 1, int tl = 0, int tr = N - 1) {
if (tl > r || l > tr)
return;
if (l <= tl && tr <= r) {
lz[v].S = max(lz[v].S, x);
} else {
shift(v);
int mid = (tl + tr) >> 1;
mx (l, r, x, v << 1, tl, mid);
mx (l, r, x, v << 1 | 1, mid + 1, tr);
}
}
void add (int l, int r, ll x, int v = 1, int tl = 0, int tr = N - 1) {
// cout << l << ' ' << r << ' ' << x << ' ' << v << ' ' << tl << ' ' << tr << '\n';
if (tl > r || l > tr)
return;
if (l <= tl && tr <= r) {
//cout << "wef\n";
slz[v] += max(0LL, x);
lz[v].S += x;
lz[v].F += x;
//cout << lz[v].F << ' ' << lz[v].S << '\n';
} else {
shift(v);
int mid = (tl + tr) >> 1;
add (l, r, x, v << 1, tl, mid);
add (l, r, x, v << 1 | 1, mid + 1, tr);
}
}
pii get (int i, int v = 1, int tl = 0, int tr = N - 1) {
if (tl == tr)
return mk(slz[v], max(lz[v].F, lz[v].S));
shift(v);
int mid = (tl + tr) >> 1;
if (i <= mid)
return get (i, v << 1, tl, mid);
return get (i, v << 1 | 1, mid + 1, tr);
}
int32_t main () {
ios::sync_with_stdio(false);
cin.tie();
for (int v = 0; v < SegN; v++)
lz[v] = mk(0, -INF);
int n, m, q;
cin >> n >> m >> q;
for (int i = 0; i < q; i++) {
ans[i] = -1;
cin >> t[i];
if (t[i] == 1) {
cin >> l[i] >> r[i] >> c[i] >> k[i];
s[l[i]].push_back(mk(i, k[i]));
e[r[i]].push_back(mk(i, k[i]));
add (l[i], r[i], k[i]);
} else if (t[i] == 2) {
cin >> l[i] >> r[i] >> k[i];
add (l[i], r[i], -k[i]);
mx (l[i], r[i], 0);
} else {
cin >> l[i] >> k[i];
pii p = get (l[i]);
if (k[i] > p.S) {
x[i] = -1;
} else {
x[i] = p.F - p.S + k[i];
}
v[l[i]].push_back(mk(x[i], i));
}
}
// FFFFFFFFFFFFFFFINALY
for (int i = 1; i <= n; i++) {
for (auto [tt, kk] : s[i]) {
ADD (tt, N - 1, kk);
}
for (auto [j, ii] : v[i])
ans[ii] = GET (j);
for (auto [tt, kk] : e[i]) {
ADD (tt, N - 1, -kk);
}
}
for (int i = 0; i < q; i++) {
if (ans[i] >= 0)
cout << ans[i] << '\n';
}
}
Compilation message
foodcourt.cpp: In function 'int32_t main()':
foodcourt.cpp:151:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
151 | for (auto [tt, kk] : s[i]) {
| ^
foodcourt.cpp:154:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
154 | for (auto [j, ii] : v[i])
| ^
foodcourt.cpp:156:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
156 | for (auto [tt, kk] : e[i]) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
26452 KB |
Output is correct |
2 |
Correct |
14 ms |
26500 KB |
Output is correct |
3 |
Correct |
14 ms |
26468 KB |
Output is correct |
4 |
Correct |
14 ms |
26536 KB |
Output is correct |
5 |
Correct |
13 ms |
26472 KB |
Output is correct |
6 |
Correct |
15 ms |
26552 KB |
Output is correct |
7 |
Correct |
14 ms |
26552 KB |
Output is correct |
8 |
Correct |
15 ms |
26588 KB |
Output is correct |
9 |
Correct |
14 ms |
26552 KB |
Output is correct |
10 |
Correct |
14 ms |
26560 KB |
Output is correct |
11 |
Correct |
16 ms |
26552 KB |
Output is correct |
12 |
Correct |
15 ms |
26580 KB |
Output is correct |
13 |
Correct |
14 ms |
26452 KB |
Output is correct |
14 |
Correct |
15 ms |
26600 KB |
Output is correct |
15 |
Correct |
14 ms |
26452 KB |
Output is correct |
16 |
Correct |
15 ms |
26600 KB |
Output is correct |
17 |
Correct |
16 ms |
26452 KB |
Output is correct |
18 |
Correct |
14 ms |
26580 KB |
Output is correct |
19 |
Correct |
14 ms |
26500 KB |
Output is correct |
20 |
Correct |
14 ms |
26540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
26452 KB |
Output is correct |
2 |
Correct |
14 ms |
26500 KB |
Output is correct |
3 |
Correct |
14 ms |
26468 KB |
Output is correct |
4 |
Correct |
14 ms |
26536 KB |
Output is correct |
5 |
Correct |
13 ms |
26472 KB |
Output is correct |
6 |
Correct |
15 ms |
26552 KB |
Output is correct |
7 |
Correct |
14 ms |
26552 KB |
Output is correct |
8 |
Correct |
15 ms |
26588 KB |
Output is correct |
9 |
Correct |
14 ms |
26552 KB |
Output is correct |
10 |
Correct |
14 ms |
26560 KB |
Output is correct |
11 |
Correct |
16 ms |
26552 KB |
Output is correct |
12 |
Correct |
15 ms |
26580 KB |
Output is correct |
13 |
Correct |
14 ms |
26452 KB |
Output is correct |
14 |
Correct |
15 ms |
26600 KB |
Output is correct |
15 |
Correct |
14 ms |
26452 KB |
Output is correct |
16 |
Correct |
15 ms |
26600 KB |
Output is correct |
17 |
Correct |
16 ms |
26452 KB |
Output is correct |
18 |
Correct |
14 ms |
26580 KB |
Output is correct |
19 |
Correct |
14 ms |
26500 KB |
Output is correct |
20 |
Correct |
14 ms |
26540 KB |
Output is correct |
21 |
Incorrect |
14 ms |
26572 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
33904 KB |
Output is correct |
2 |
Correct |
105 ms |
35504 KB |
Output is correct |
3 |
Correct |
78 ms |
35012 KB |
Output is correct |
4 |
Correct |
76 ms |
34992 KB |
Output is correct |
5 |
Correct |
81 ms |
35532 KB |
Output is correct |
6 |
Correct |
81 ms |
35512 KB |
Output is correct |
7 |
Correct |
51 ms |
32704 KB |
Output is correct |
8 |
Correct |
53 ms |
32524 KB |
Output is correct |
9 |
Correct |
77 ms |
34632 KB |
Output is correct |
10 |
Correct |
81 ms |
35120 KB |
Output is correct |
11 |
Correct |
103 ms |
35172 KB |
Output is correct |
12 |
Correct |
83 ms |
35112 KB |
Output is correct |
13 |
Correct |
70 ms |
34380 KB |
Output is correct |
14 |
Correct |
80 ms |
35676 KB |
Output is correct |
15 |
Correct |
85 ms |
35892 KB |
Output is correct |
16 |
Correct |
123 ms |
36396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
356 ms |
53040 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
26452 KB |
Output is correct |
2 |
Correct |
14 ms |
26500 KB |
Output is correct |
3 |
Correct |
14 ms |
26468 KB |
Output is correct |
4 |
Correct |
14 ms |
26536 KB |
Output is correct |
5 |
Correct |
13 ms |
26472 KB |
Output is correct |
6 |
Correct |
15 ms |
26552 KB |
Output is correct |
7 |
Correct |
14 ms |
26552 KB |
Output is correct |
8 |
Correct |
15 ms |
26588 KB |
Output is correct |
9 |
Correct |
14 ms |
26552 KB |
Output is correct |
10 |
Correct |
14 ms |
26560 KB |
Output is correct |
11 |
Correct |
16 ms |
26552 KB |
Output is correct |
12 |
Correct |
15 ms |
26580 KB |
Output is correct |
13 |
Correct |
14 ms |
26452 KB |
Output is correct |
14 |
Correct |
15 ms |
26600 KB |
Output is correct |
15 |
Correct |
14 ms |
26452 KB |
Output is correct |
16 |
Correct |
15 ms |
26600 KB |
Output is correct |
17 |
Correct |
16 ms |
26452 KB |
Output is correct |
18 |
Correct |
14 ms |
26580 KB |
Output is correct |
19 |
Correct |
14 ms |
26500 KB |
Output is correct |
20 |
Correct |
14 ms |
26540 KB |
Output is correct |
21 |
Correct |
78 ms |
33904 KB |
Output is correct |
22 |
Correct |
105 ms |
35504 KB |
Output is correct |
23 |
Correct |
78 ms |
35012 KB |
Output is correct |
24 |
Correct |
76 ms |
34992 KB |
Output is correct |
25 |
Correct |
81 ms |
35532 KB |
Output is correct |
26 |
Correct |
81 ms |
35512 KB |
Output is correct |
27 |
Correct |
51 ms |
32704 KB |
Output is correct |
28 |
Correct |
53 ms |
32524 KB |
Output is correct |
29 |
Correct |
77 ms |
34632 KB |
Output is correct |
30 |
Correct |
81 ms |
35120 KB |
Output is correct |
31 |
Correct |
103 ms |
35172 KB |
Output is correct |
32 |
Correct |
83 ms |
35112 KB |
Output is correct |
33 |
Correct |
70 ms |
34380 KB |
Output is correct |
34 |
Correct |
80 ms |
35676 KB |
Output is correct |
35 |
Correct |
85 ms |
35892 KB |
Output is correct |
36 |
Correct |
123 ms |
36396 KB |
Output is correct |
37 |
Correct |
76 ms |
34068 KB |
Output is correct |
38 |
Correct |
81 ms |
33616 KB |
Output is correct |
39 |
Correct |
46 ms |
31596 KB |
Output is correct |
40 |
Correct |
52 ms |
32416 KB |
Output is correct |
41 |
Correct |
82 ms |
34160 KB |
Output is correct |
42 |
Correct |
84 ms |
34900 KB |
Output is correct |
43 |
Correct |
83 ms |
34868 KB |
Output is correct |
44 |
Correct |
96 ms |
34556 KB |
Output is correct |
45 |
Correct |
92 ms |
34856 KB |
Output is correct |
46 |
Correct |
87 ms |
34944 KB |
Output is correct |
47 |
Correct |
68 ms |
34216 KB |
Output is correct |
48 |
Correct |
74 ms |
34764 KB |
Output is correct |
49 |
Correct |
63 ms |
32348 KB |
Output is correct |
50 |
Correct |
78 ms |
33720 KB |
Output is correct |
51 |
Correct |
102 ms |
34964 KB |
Output is correct |
52 |
Correct |
89 ms |
34944 KB |
Output is correct |
53 |
Correct |
70 ms |
34380 KB |
Output is correct |
54 |
Correct |
93 ms |
36404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
80 ms |
34036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
26452 KB |
Output is correct |
2 |
Correct |
14 ms |
26500 KB |
Output is correct |
3 |
Correct |
14 ms |
26468 KB |
Output is correct |
4 |
Correct |
14 ms |
26536 KB |
Output is correct |
5 |
Correct |
13 ms |
26472 KB |
Output is correct |
6 |
Correct |
15 ms |
26552 KB |
Output is correct |
7 |
Correct |
14 ms |
26552 KB |
Output is correct |
8 |
Correct |
15 ms |
26588 KB |
Output is correct |
9 |
Correct |
14 ms |
26552 KB |
Output is correct |
10 |
Correct |
14 ms |
26560 KB |
Output is correct |
11 |
Correct |
16 ms |
26552 KB |
Output is correct |
12 |
Correct |
15 ms |
26580 KB |
Output is correct |
13 |
Correct |
14 ms |
26452 KB |
Output is correct |
14 |
Correct |
15 ms |
26600 KB |
Output is correct |
15 |
Correct |
14 ms |
26452 KB |
Output is correct |
16 |
Correct |
15 ms |
26600 KB |
Output is correct |
17 |
Correct |
16 ms |
26452 KB |
Output is correct |
18 |
Correct |
14 ms |
26580 KB |
Output is correct |
19 |
Correct |
14 ms |
26500 KB |
Output is correct |
20 |
Correct |
14 ms |
26540 KB |
Output is correct |
21 |
Incorrect |
14 ms |
26572 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
26452 KB |
Output is correct |
2 |
Correct |
14 ms |
26500 KB |
Output is correct |
3 |
Correct |
14 ms |
26468 KB |
Output is correct |
4 |
Correct |
14 ms |
26536 KB |
Output is correct |
5 |
Correct |
13 ms |
26472 KB |
Output is correct |
6 |
Correct |
15 ms |
26552 KB |
Output is correct |
7 |
Correct |
14 ms |
26552 KB |
Output is correct |
8 |
Correct |
15 ms |
26588 KB |
Output is correct |
9 |
Correct |
14 ms |
26552 KB |
Output is correct |
10 |
Correct |
14 ms |
26560 KB |
Output is correct |
11 |
Correct |
16 ms |
26552 KB |
Output is correct |
12 |
Correct |
15 ms |
26580 KB |
Output is correct |
13 |
Correct |
14 ms |
26452 KB |
Output is correct |
14 |
Correct |
15 ms |
26600 KB |
Output is correct |
15 |
Correct |
14 ms |
26452 KB |
Output is correct |
16 |
Correct |
15 ms |
26600 KB |
Output is correct |
17 |
Correct |
16 ms |
26452 KB |
Output is correct |
18 |
Correct |
14 ms |
26580 KB |
Output is correct |
19 |
Correct |
14 ms |
26500 KB |
Output is correct |
20 |
Correct |
14 ms |
26540 KB |
Output is correct |
21 |
Incorrect |
14 ms |
26572 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |