// In the name of God
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
#define int ll
const int N = 25e4 + 5;
int n, m, q;
vector<pair<int, int> > A[N], B[N];
vector<pair<int, int> > vec[N];
int INX[N];
vector<pair<pair<int, int>, int> > Q[N];
int col[N], ans[N];
int seg[N << 2], lz[N << 2], fen[N];
void updFen(int inx, int val) {
for (inx; inx <= m; inx += inx & -inx)
fen[inx] += val;
}
int queryFen(int inx) {
int res = 0;
for (inx; inx > 0; inx -= inx & -inx)
res += fen[inx];
return res;
}
void shift(int v, int tl, int tr) {
seg[v] += lz[v];
if (tl < tr) {
lz[v << 1] += lz[v];
lz[v << 1 | 1] += lz[v];
}
lz[v] = 0;
}
void upd(int l, int r, int val, int v = 1, int tl = 0, int tr = q) {
shift(v, tl, tr);
if (tl > r || tr < l)
return;
if (tl >= l && tr <= r) {
lz[v] += val;
shift(v, tl, tr);
return;
}
int mid = (tl + tr) >> 1;
upd(l, r, val, v << 1, tl, mid);
upd(l, r, val, v << 1 | 1, mid + 1, tr);
seg[v] = min(seg[v << 1], seg[v << 1 | 1]);
}
int query(int l, int r, int v = 1, int tl = 0, int tr = q) {
shift(v, tl, tr);
if (l > tr || r < tl)
return 1e9 + 10;
if (tl >= l && tr <= r)
return seg[v];
int mid = (tl + tr) >> 1;
return min(query(l, r, v << 1, tl, mid), query(l, r, v << 1 | 1, mid + 1, tr));
}
void solve() {
cin >> n >> m >> q;
int inx = 0;
for (int i = 0; i < q; i++) {
int t; cin >> t;
if (t == 1) {
int l, r, c, k; cin >> l >> r >> c >> k;
for (int j = l; j <= r; j++) {
vec[j].pb(mp(k, c));
}
}
else if (t == 2) {
int l, r, k; cin >> l >> r >> k;
int kp = k;
for (int j = l; j <= r; j++) {
k = kp;
if (n <= 2000 && q <= 2000) {
while (INX[j] < vec[j].size() && k) {
int tmp = min(k, vec[j][INX[j]].fi);
k -= tmp;
vec[j][INX[j]].fi -= tmp;
if (!vec[j][INX[j]].fi)
INX[j]++;
}
}
else {
INX[j] = min((int)vec[j].size(), INX[j] + k);
}
}
}
else {
int a, b; cin >> a >> b;
if (n <= 2000 && q <= 2000) {
int sum = 0, j;
for (j = 0; j < vec[a].size() && sum < b; j++) {
sum += vec[a][j].fi;
}
if (sum >= b)
cout << vec[a][--j].se << '\n';
else
cout << 0 << '\n';
}
else {
if (vec[a].size() - INX[a] < b) {
cout << 0 << '\n';
}
else {
cout << vec[a][INX[a] + b - 1].se << '\n';
}
}
continue;
int sum = 0, j;
for (j = 0; j < vec[a].size() && sum < b; j++) {
sum += vec[a][j].fi;
}
if (sum >= b)
cout << vec[a][--j].se << '\n';
else
cout << 0 << '\n';
ans[i] = 0;
Q[a].pb(mp(mp(inx, i), b));
}
}
/*for (int i = 1; i <= n; i++) {
for (auto [l, k] : A[i]) {
upd(l, q, k);
}
for (auto tmp : Q[i]) {
int j = tmp.fi.fi, qi = tmp.fi.se, b = tmp.se;
int l = -1, r = j + 1;
while (r - l > 1) {
int mid = (l + r) >> 1;
if (query(mid, j) < b)
l = mid;
else
r = mid;
}
if (query(j + 1, j + 1) >= b) {
ans[qi] = col[l];
}
}
}
for (int i = 0; i < q; i++)
if (ans[i] != -1)
cout << ans[i] << '\n';*/
}
int32_t main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
solve();
return 0;
}
Compilation message
foodcourt.cpp: In function 'void updFen(ll, ll)':
foodcourt.cpp:20:10: warning: statement has no effect [-Wunused-value]
20 | for (inx; inx <= m; inx += inx & -inx)
| ^~~
foodcourt.cpp: In function 'll queryFen(ll)':
foodcourt.cpp:25:10: warning: statement has no effect [-Wunused-value]
25 | for (inx; inx > 0; inx -= inx & -inx)
| ^~~
foodcourt.cpp: In function 'void solve()':
foodcourt.cpp:82:35: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | while (INX[j] < vec[j].size() && k) {
| ~~~~~~~^~~~~~~~~~~~~~~
foodcourt.cpp:100:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | for (j = 0; j < vec[a].size() && sum < b; j++) {
| ~~^~~~~~~~~~~~~~~
foodcourt.cpp:109:32: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'll' {aka 'long long int'} [-Wsign-compare]
109 | if (vec[a].size() - INX[a] < b) {
| ~~~~~~~~~~~~~~~~~~~~~~~^~~
foodcourt.cpp:118:27: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
118 | for (j = 0; j < vec[a].size() && sum < b; j++) {
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
29596 KB |
Output is correct |
2 |
Correct |
25 ms |
35216 KB |
Output is correct |
3 |
Correct |
27 ms |
37144 KB |
Output is correct |
4 |
Correct |
41 ms |
47756 KB |
Output is correct |
5 |
Correct |
13 ms |
23824 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
37 ms |
41304 KB |
Output is correct |
8 |
Correct |
35 ms |
40716 KB |
Output is correct |
9 |
Correct |
35 ms |
40728 KB |
Output is correct |
10 |
Correct |
39 ms |
41800 KB |
Output is correct |
11 |
Correct |
37 ms |
42272 KB |
Output is correct |
12 |
Correct |
35 ms |
41356 KB |
Output is correct |
13 |
Correct |
42 ms |
49604 KB |
Output is correct |
14 |
Correct |
52 ms |
54712 KB |
Output is correct |
15 |
Correct |
36 ms |
39320 KB |
Output is correct |
16 |
Correct |
52 ms |
54512 KB |
Output is correct |
17 |
Correct |
25 ms |
32820 KB |
Output is correct |
18 |
Correct |
30 ms |
37688 KB |
Output is correct |
19 |
Correct |
16 ms |
24020 KB |
Output is correct |
20 |
Correct |
13 ms |
24152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
29596 KB |
Output is correct |
2 |
Correct |
25 ms |
35216 KB |
Output is correct |
3 |
Correct |
27 ms |
37144 KB |
Output is correct |
4 |
Correct |
41 ms |
47756 KB |
Output is correct |
5 |
Correct |
13 ms |
23824 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
37 ms |
41304 KB |
Output is correct |
8 |
Correct |
35 ms |
40716 KB |
Output is correct |
9 |
Correct |
35 ms |
40728 KB |
Output is correct |
10 |
Correct |
39 ms |
41800 KB |
Output is correct |
11 |
Correct |
37 ms |
42272 KB |
Output is correct |
12 |
Correct |
35 ms |
41356 KB |
Output is correct |
13 |
Correct |
42 ms |
49604 KB |
Output is correct |
14 |
Correct |
52 ms |
54712 KB |
Output is correct |
15 |
Correct |
36 ms |
39320 KB |
Output is correct |
16 |
Correct |
52 ms |
54512 KB |
Output is correct |
17 |
Correct |
25 ms |
32820 KB |
Output is correct |
18 |
Correct |
30 ms |
37688 KB |
Output is correct |
19 |
Correct |
16 ms |
24020 KB |
Output is correct |
20 |
Correct |
13 ms |
24152 KB |
Output is correct |
21 |
Correct |
25 ms |
34124 KB |
Output is correct |
22 |
Correct |
28 ms |
35352 KB |
Output is correct |
23 |
Correct |
29 ms |
39464 KB |
Output is correct |
24 |
Correct |
39 ms |
47780 KB |
Output is correct |
25 |
Correct |
13 ms |
23872 KB |
Output is correct |
26 |
Correct |
13 ms |
23860 KB |
Output is correct |
27 |
Correct |
39 ms |
38672 KB |
Output is correct |
28 |
Correct |
43 ms |
41676 KB |
Output is correct |
29 |
Correct |
41 ms |
41612 KB |
Output is correct |
30 |
Correct |
40 ms |
41100 KB |
Output is correct |
31 |
Correct |
37 ms |
38228 KB |
Output is correct |
32 |
Correct |
34 ms |
37916 KB |
Output is correct |
33 |
Correct |
49 ms |
48076 KB |
Output is correct |
34 |
Correct |
57 ms |
54604 KB |
Output is correct |
35 |
Correct |
43 ms |
46472 KB |
Output is correct |
36 |
Correct |
56 ms |
54160 KB |
Output is correct |
37 |
Correct |
13 ms |
24048 KB |
Output is correct |
38 |
Correct |
14 ms |
24148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
637 ms |
28792 KB |
Output is correct |
2 |
Correct |
477 ms |
30552 KB |
Output is correct |
3 |
Correct |
652 ms |
31632 KB |
Output is correct |
4 |
Correct |
610 ms |
31564 KB |
Output is correct |
5 |
Correct |
485 ms |
34572 KB |
Output is correct |
6 |
Correct |
492 ms |
34664 KB |
Output is correct |
7 |
Correct |
28 ms |
25168 KB |
Output is correct |
8 |
Correct |
28 ms |
25472 KB |
Output is correct |
9 |
Execution timed out |
1042 ms |
29312 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
718 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
29596 KB |
Output is correct |
2 |
Correct |
25 ms |
35216 KB |
Output is correct |
3 |
Correct |
27 ms |
37144 KB |
Output is correct |
4 |
Correct |
41 ms |
47756 KB |
Output is correct |
5 |
Correct |
13 ms |
23824 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
37 ms |
41304 KB |
Output is correct |
8 |
Correct |
35 ms |
40716 KB |
Output is correct |
9 |
Correct |
35 ms |
40728 KB |
Output is correct |
10 |
Correct |
39 ms |
41800 KB |
Output is correct |
11 |
Correct |
37 ms |
42272 KB |
Output is correct |
12 |
Correct |
35 ms |
41356 KB |
Output is correct |
13 |
Correct |
42 ms |
49604 KB |
Output is correct |
14 |
Correct |
52 ms |
54712 KB |
Output is correct |
15 |
Correct |
36 ms |
39320 KB |
Output is correct |
16 |
Correct |
52 ms |
54512 KB |
Output is correct |
17 |
Correct |
25 ms |
32820 KB |
Output is correct |
18 |
Correct |
30 ms |
37688 KB |
Output is correct |
19 |
Correct |
16 ms |
24020 KB |
Output is correct |
20 |
Correct |
13 ms |
24152 KB |
Output is correct |
21 |
Correct |
637 ms |
28792 KB |
Output is correct |
22 |
Correct |
477 ms |
30552 KB |
Output is correct |
23 |
Correct |
652 ms |
31632 KB |
Output is correct |
24 |
Correct |
610 ms |
31564 KB |
Output is correct |
25 |
Correct |
485 ms |
34572 KB |
Output is correct |
26 |
Correct |
492 ms |
34664 KB |
Output is correct |
27 |
Correct |
28 ms |
25168 KB |
Output is correct |
28 |
Correct |
28 ms |
25472 KB |
Output is correct |
29 |
Execution timed out |
1042 ms |
29312 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
657 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
29596 KB |
Output is correct |
2 |
Correct |
25 ms |
35216 KB |
Output is correct |
3 |
Correct |
27 ms |
37144 KB |
Output is correct |
4 |
Correct |
41 ms |
47756 KB |
Output is correct |
5 |
Correct |
13 ms |
23824 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
37 ms |
41304 KB |
Output is correct |
8 |
Correct |
35 ms |
40716 KB |
Output is correct |
9 |
Correct |
35 ms |
40728 KB |
Output is correct |
10 |
Correct |
39 ms |
41800 KB |
Output is correct |
11 |
Correct |
37 ms |
42272 KB |
Output is correct |
12 |
Correct |
35 ms |
41356 KB |
Output is correct |
13 |
Correct |
42 ms |
49604 KB |
Output is correct |
14 |
Correct |
52 ms |
54712 KB |
Output is correct |
15 |
Correct |
36 ms |
39320 KB |
Output is correct |
16 |
Correct |
52 ms |
54512 KB |
Output is correct |
17 |
Correct |
25 ms |
32820 KB |
Output is correct |
18 |
Correct |
30 ms |
37688 KB |
Output is correct |
19 |
Correct |
16 ms |
24020 KB |
Output is correct |
20 |
Correct |
13 ms |
24152 KB |
Output is correct |
21 |
Correct |
25 ms |
34124 KB |
Output is correct |
22 |
Correct |
28 ms |
35352 KB |
Output is correct |
23 |
Correct |
29 ms |
39464 KB |
Output is correct |
24 |
Correct |
39 ms |
47780 KB |
Output is correct |
25 |
Correct |
13 ms |
23872 KB |
Output is correct |
26 |
Correct |
13 ms |
23860 KB |
Output is correct |
27 |
Correct |
39 ms |
38672 KB |
Output is correct |
28 |
Correct |
43 ms |
41676 KB |
Output is correct |
29 |
Correct |
41 ms |
41612 KB |
Output is correct |
30 |
Correct |
40 ms |
41100 KB |
Output is correct |
31 |
Correct |
37 ms |
38228 KB |
Output is correct |
32 |
Correct |
34 ms |
37916 KB |
Output is correct |
33 |
Correct |
49 ms |
48076 KB |
Output is correct |
34 |
Correct |
57 ms |
54604 KB |
Output is correct |
35 |
Correct |
43 ms |
46472 KB |
Output is correct |
36 |
Correct |
56 ms |
54160 KB |
Output is correct |
37 |
Correct |
13 ms |
24048 KB |
Output is correct |
38 |
Correct |
14 ms |
24148 KB |
Output is correct |
39 |
Correct |
637 ms |
28792 KB |
Output is correct |
40 |
Correct |
477 ms |
30552 KB |
Output is correct |
41 |
Correct |
652 ms |
31632 KB |
Output is correct |
42 |
Correct |
610 ms |
31564 KB |
Output is correct |
43 |
Correct |
485 ms |
34572 KB |
Output is correct |
44 |
Correct |
492 ms |
34664 KB |
Output is correct |
45 |
Correct |
28 ms |
25168 KB |
Output is correct |
46 |
Correct |
28 ms |
25472 KB |
Output is correct |
47 |
Execution timed out |
1042 ms |
29312 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
29596 KB |
Output is correct |
2 |
Correct |
25 ms |
35216 KB |
Output is correct |
3 |
Correct |
27 ms |
37144 KB |
Output is correct |
4 |
Correct |
41 ms |
47756 KB |
Output is correct |
5 |
Correct |
13 ms |
23824 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
37 ms |
41304 KB |
Output is correct |
8 |
Correct |
35 ms |
40716 KB |
Output is correct |
9 |
Correct |
35 ms |
40728 KB |
Output is correct |
10 |
Correct |
39 ms |
41800 KB |
Output is correct |
11 |
Correct |
37 ms |
42272 KB |
Output is correct |
12 |
Correct |
35 ms |
41356 KB |
Output is correct |
13 |
Correct |
42 ms |
49604 KB |
Output is correct |
14 |
Correct |
52 ms |
54712 KB |
Output is correct |
15 |
Correct |
36 ms |
39320 KB |
Output is correct |
16 |
Correct |
52 ms |
54512 KB |
Output is correct |
17 |
Correct |
25 ms |
32820 KB |
Output is correct |
18 |
Correct |
30 ms |
37688 KB |
Output is correct |
19 |
Correct |
16 ms |
24020 KB |
Output is correct |
20 |
Correct |
13 ms |
24152 KB |
Output is correct |
21 |
Correct |
25 ms |
34124 KB |
Output is correct |
22 |
Correct |
28 ms |
35352 KB |
Output is correct |
23 |
Correct |
29 ms |
39464 KB |
Output is correct |
24 |
Correct |
39 ms |
47780 KB |
Output is correct |
25 |
Correct |
13 ms |
23872 KB |
Output is correct |
26 |
Correct |
13 ms |
23860 KB |
Output is correct |
27 |
Correct |
39 ms |
38672 KB |
Output is correct |
28 |
Correct |
43 ms |
41676 KB |
Output is correct |
29 |
Correct |
41 ms |
41612 KB |
Output is correct |
30 |
Correct |
40 ms |
41100 KB |
Output is correct |
31 |
Correct |
37 ms |
38228 KB |
Output is correct |
32 |
Correct |
34 ms |
37916 KB |
Output is correct |
33 |
Correct |
49 ms |
48076 KB |
Output is correct |
34 |
Correct |
57 ms |
54604 KB |
Output is correct |
35 |
Correct |
43 ms |
46472 KB |
Output is correct |
36 |
Correct |
56 ms |
54160 KB |
Output is correct |
37 |
Correct |
13 ms |
24048 KB |
Output is correct |
38 |
Correct |
14 ms |
24148 KB |
Output is correct |
39 |
Correct |
637 ms |
28792 KB |
Output is correct |
40 |
Correct |
477 ms |
30552 KB |
Output is correct |
41 |
Correct |
652 ms |
31632 KB |
Output is correct |
42 |
Correct |
610 ms |
31564 KB |
Output is correct |
43 |
Correct |
485 ms |
34572 KB |
Output is correct |
44 |
Correct |
492 ms |
34664 KB |
Output is correct |
45 |
Correct |
28 ms |
25168 KB |
Output is correct |
46 |
Correct |
28 ms |
25472 KB |
Output is correct |
47 |
Execution timed out |
1042 ms |
29312 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |