#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
//#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tree<iii, null_type, greater<iii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
void read(int &v) {
v = 0;
char ch = getchar_unlocked();
for (; ch < '0' || ch > '9'; ch = getchar_unlocked());
for (; '0' <= ch && ch <= '9'; ch = getchar_unlocked())
v = (v << 3) + (v << 1) + (ch & 15);
}
void read(ll &v) {
v = 0;
char ch = getchar_unlocked();
for (; ch < '0' || ch > '9'; ch = getchar_unlocked());
for (; '0' <= ch && ch <= '9'; ch = getchar_unlocked())
v = (v << 3ll) + (v << 1ll) + (ch & 15ll);
}
int N, M, Q, T, L, R, C, K, A, curq, q1, out[100005];
ll B, ft[250005];
iiii vq1[250005];
struct node {
node *left, *right;
int S, E;
bool hasmx;
ll val, pv, pmx;
node(int _s, int _e) : S(_s), E(_e), hasmx(0), val(0), pv(0), pmx(-1e16) {
if (S == E) return;
int M = (S + E) >> 1;
left = new node(S, M);
right = new node(M + 1, E);
}
void add_prop(bool t, ll x) {
if (t == 0) {
pv += x;
if (hasmx) pmx += x;
} else {
pmx = max(pmx, x);
hasmx = 1;
}
}
void prop() {
if (S == E) return;
left->val += pv;
right->val += pv;
left->add_prop(0, pv);
right->add_prop(0, pv);
pv = 0;
if (hasmx) {
left->val = max(left->val, pmx);
right->val = max(right->val, pmx);
left->add_prop(1, pmx);
right->add_prop(1, pmx);
pmx = -1e16;
} else assert(pmx == -1e16);
hasmx = 0;
}
void add(int l, int r, ll v) {
if (l > E || r < S) return;
if (l <= S && E <= r) {
add_prop(0, v);
val += v;
return;
}
prop();
left->add(l, r, v);
right->add(l, r, v);
}
ll qry(int p) {
if (S == E) return val;
int M = (S + E) >> 1;
prop();
if (p <= M) return left->qry(p);
else return right->qry(p);
}
} *root;
inline int ls(int x) { return x & -x; }
void upd(int l, int r, int v) {
for (; l <= N; l += ls(l)) ft[l] += v;
for (r++; r <= N; r += ls(r)) ft[r] -= v;
}
int qry(int p) {
int r = 0;
for (; p; p -= ls(p)) r += ft[p];
return r;
}
struct node2 {
node2 *left, *right;
int S, E, pos;
ll pv;
vector<pair<ll, int> > val;
tuple<ll, int, int> mv;
node2(int _s, int _e) : S(_s), E(_e), pos(0), pv(0) {
mv = mt(1e16, -1, -1);
if (S == E) return;
int M = (S + E) >> 1;
left = new node2(S, M);
right = new node2(M + 1, E);
}
void prop() {
if (S == E || !pv) return;
g0(left->mv) += pv;
left->pv += pv;
g0(right->mv) += pv;
right->pv += pv;
pv = 0;
}
void upd(int p, ll a, int b) {
if (S == E) {
val.eb(a, b);
return;
}
int M = (S + E) >> 1;
prop();
if (p <= M) left->upd(p, a, b);
else right->upd(p, a, b);
mv = min(left->mv, right->mv);
}
void add(int l, int r, ll v) {
if (l > E || r < S) return;
if (l <= S && E <= r) {
g0(mv) += v;
pv += v;
return;
}
prop();
left->add(l, r, v);
right->add(l, r, v);
mv = min(left->mv, right->mv);
}
void sortall() {
if (S == E) {
sort(val.begin(), val.end());
if (!val.empty()) mv = mt(val[0].first, S, val[0].second);
return;
}
prop();
left->sortall();
right->sortall();
mv = min(left->mv, right->mv);
}
void del(int p) {
if (S == E) {
assert(pos < val.size());
pos++;
if (pos < val.size()) mv = mt(val[pos].first, S, val[pos].second);
else mv = mt(1e16, -1, -1);
return;
}
int M = (S + E) >> 1;
prop();
if (p <= M) left->del(p);
else right->del(p);
mv = min(left->mv, right->mv);
}
} *root2;
main() {
read(N);
read(M);
read(Q);
root = new node(1, N);
root2 = new node2(1, N);
for (int i = 1; i <= Q; i++) {
read(T);
if (T == 1) {
read(L);
read(R);
read(C);
read(K);
q1++;
vq1[q1] = mt(L, R, C, K);
root->add(L, R, K);
upd(L, R, K);
} else if (T == 2) {
read(L);
read(R);
read(K);
root->add(L, R, -K);
root->val = max(0ll, root->val);
root->add_prop(1, 0);
} else {
read(A);
read(B);
curq++;
ll sz = root->qry(A), tmp = qry(A);
if (sz >= B) root2->upd(A, tmp - (sz - B), curq);
}
}
root2->sortall();
for (int i = 1; i <= q1; i++) {
tie(L, R, C, K) = vq1[i];
root2->add(L, R, -K);
while (g0(root2->mv) <= 0) {
out[g2(root2->mv)] = C;
root2->del(g1(root2->mv));
}
}
for (int i = 1; i <= curq; i++) printf("%d\n", out[i]);
}
Compilation message
In file included from /usr/include/c++/10/ext/pb_ds/detail/pat_trie_/pat_trie_.hpp:45,
from /usr/include/c++/10/ext/pb_ds/detail/container_base_dispatch.hpp:90,
from /usr/include/c++/10/ext/pb_ds/assoc_container.hpp:48,
from foodcourt.cpp:2:
foodcourt.cpp: In member function 'void node2::del(int)':
foodcourt.cpp:174:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
174 | assert(pos < val.size());
| ~~~~^~~~~~~~~~~~
foodcourt.cpp:176:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
176 | if (pos < val.size()) mv = mt(val[pos].first, S, val[pos].second);
| ~~~~^~~~~~~~~~~~
foodcourt.cpp: At global scope:
foodcourt.cpp:188:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
188 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
21508 KB |
Output is correct |
2 |
Correct |
113 ms |
21728 KB |
Output is correct |
3 |
Incorrect |
99 ms |
21556 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
655 ms |
75424 KB |
Output is correct |
2 |
Correct |
516 ms |
65220 KB |
Output is correct |
3 |
Correct |
810 ms |
83964 KB |
Output is correct |
4 |
Correct |
638 ms |
82476 KB |
Output is correct |
5 |
Correct |
554 ms |
63104 KB |
Output is correct |
6 |
Correct |
777 ms |
84144 KB |
Output is correct |
7 |
Correct |
36 ms |
3128 KB |
Output is correct |
8 |
Correct |
50 ms |
3032 KB |
Output is correct |
9 |
Runtime error |
613 ms |
172028 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
127 ms |
21704 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |