#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m";
void DBG() { cerr << "]" << _reset << endl; }
template<class H, class...T> void DBG(H h, T ...t) {
cerr << to_string(h);
if(sizeof ...(t)) cerr << ", ";
DBG(t...);
}
#ifdef CHEISSMART
#define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define debug(...)
#endif
const int INF = 1e9 + 7, N = 250005;
int n;
namespace seg {
struct node {
ll tot_lz, len_add, len_mx;
node() {
tot_lz = len_add = len_mx = 0;
}
} t[N * 4];
void apply_add_tot(int v, ll x) {
t[v].tot_lz += x;
}
void apply_upd_len(int v, ll add, ll mx) {
t[v].len_add += add;
t[v].len_mx += add;
t[v].len_mx = max(t[v].len_mx, mx);
}
void push(int v) {
apply_add_tot(v * 2, t[v].tot_lz);
apply_add_tot(v * 2 + 1, t[v].tot_lz);
t[v].tot_lz = 0;
apply_upd_len(v * 2, t[v].len_add, t[v].len_mx);
apply_upd_len(v * 2 + 1, t[v].len_add, t[v].len_mx);
t[v].len_add = t[v].len_mx = 0;
}
void add_tot(int l, int r, ll x, int v = 1, int tl = 0, int tr = n) {
if(l <= tl && tr <= r) {
apply_add_tot(v, x);
return;
}
push(v);
int tm = (tl + tr) / 2;
if(l < tm) add_tot(l, r, x, v * 2, tl, tm);
if(r > tm) add_tot(l, r, x, v * 2 + 1, tm, tr);
}
void upd_len(int l, int r, ll add, ll mx, int v = 1, int tl = 0, int tr = n) {
if(l <= tl && tr <= r) {
apply_upd_len(v, add, mx);
return;
}
push(v);
int tm = (tl + tr) / 2;
if(l < tm) upd_len(l, r, add, mx, v * 2, tl, tm);
if(r > tm) upd_len(l, r, add, mx, v * 2 + 1, tm, tr);
}
ll qry_tot(int pos, int v = 1, int tl = 0, int tr = n) {
if(tr - tl == 1)
return t[v].tot_lz;
push(v);
int tm = (tl + tr) / 2;
if(pos < tm) return qry_tot(pos, v * 2, tl, tm);
else return qry_tot(pos, v * 2 + 1, tm, tr);
}
ll qry_len(int pos, int v = 1, int tl = 0, int tr = n) {
if(tr - tl == 1)
return max(t[v].len_add, t[v].len_mx);
push(v);
int tm = (tl + tr) / 2;
if(pos < tm) return qry_len(pos, v * 2, tl, tm);
else return qry_len(pos, v * 2 + 1, tm, tr);
}
}
namespace seg2 {
ll t[N * 4];
void apply(int v, ll x) {
t[v] += x;
}
void push(int v) {
apply(v * 2, t[v]);
apply(v * 2 + 1, t[v]);
t[v] = 0;
}
void add(int l, int r, ll x, int v = 1, int tl = 0, int tr = n) {
if(l <= tl && tr <= r) {
apply(v, x);
return;
}
push(v);
int tm = (tl + tr) / 2;
if(l < tm) add(l, r, x, v * 2, tl, tm);
if(r > tm) add(l, r, x, v * 2 + 1, tm, tr);
}
ll qry(int pos, int v = 1, int tl = 0, int tr = n) {
if(tr - tl == 1)
return t[v];
push(v);
int tm = (tl + tr) / 2;
if(pos < tm) return qry(pos, v * 2, tl, tm);
else return qry(pos, v * 2 + 1, tm, tr);
}
}
signed main()
{
IO_OP;
int m, q;
cin >> n >> m >> q;
V<array<int, 4>> ev;
V<pair<int, ll>> qq;
for(int i = 0; i < q; i++) {
int t; cin >> t;
if(t == 1) {
int l, r, c, k;
cin >> l >> r >> c >> k, l--;
ev.PB({l, r, c, k});
seg::add_tot(l, r, k);
seg::upd_len(l, r, k, 0);
} else if(t == 2) {
int l, r, k;
cin >> l >> r >> k, l--;
seg::upd_len(l, r, -k, 0);
} else {
int a;
ll b;
cin >> a >> b, a--;
if(b > seg::qry_len(a)) {
qq.EB(a, -1);
} else {
qq.EB(a, seg::qry_tot(a) - seg::qry_len(a) + b);
}
}
}
vi ans(SZ(qq));
function<void(vi&, int, int)> solve = [&] (vi& todo, int l, int r) {
if(todo.empty()) return;
if(l == r) {
for(int i:todo) ans[i] = ev[l][2];
return;
}
int m = (l + r) / 2;
vi todo_l, todo_r;
for(int i = 0; i <= m; i++)
seg2::add(ev[i][0], ev[i][1], ev[i][3]);
for(int i:todo) {
if(seg2::qry(qq[i].F) >= qq[i].S) {
todo_l.PB(i);
} else {
todo_r.PB(i);
}
}
for(int i = 0; i <= m; i++)
seg2::add(ev[i][0], ev[i][1], -ev[i][3]);
solve(todo_l, l, m);
solve(todo_r, m + 1, r);
};
vi todo;
for(int i = 0; i < SZ(qq); i++)
if(qq[i].S != -1) {
debug(i);
todo.PB(i);
}
solve(todo, 0, SZ(ev) - 1);
for(int i = 0; i < SZ(qq); i++)
cout << ans[i] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
23824 KB |
Output is correct |
2 |
Correct |
86 ms |
23916 KB |
Output is correct |
3 |
Correct |
59 ms |
23884 KB |
Output is correct |
4 |
Correct |
129 ms |
23904 KB |
Output is correct |
5 |
Correct |
14 ms |
23764 KB |
Output is correct |
6 |
Correct |
17 ms |
23804 KB |
Output is correct |
7 |
Correct |
109 ms |
23896 KB |
Output is correct |
8 |
Correct |
104 ms |
23856 KB |
Output is correct |
9 |
Correct |
101 ms |
23892 KB |
Output is correct |
10 |
Correct |
109 ms |
23896 KB |
Output is correct |
11 |
Correct |
105 ms |
23864 KB |
Output is correct |
12 |
Correct |
91 ms |
23900 KB |
Output is correct |
13 |
Correct |
13 ms |
23892 KB |
Output is correct |
14 |
Correct |
14 ms |
23892 KB |
Output is correct |
15 |
Correct |
45 ms |
23868 KB |
Output is correct |
16 |
Correct |
80 ms |
23972 KB |
Output is correct |
17 |
Correct |
63 ms |
23884 KB |
Output is correct |
18 |
Correct |
92 ms |
23892 KB |
Output is correct |
19 |
Correct |
82 ms |
23980 KB |
Output is correct |
20 |
Correct |
98 ms |
23928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
23824 KB |
Output is correct |
2 |
Correct |
86 ms |
23916 KB |
Output is correct |
3 |
Correct |
59 ms |
23884 KB |
Output is correct |
4 |
Correct |
129 ms |
23904 KB |
Output is correct |
5 |
Correct |
14 ms |
23764 KB |
Output is correct |
6 |
Correct |
17 ms |
23804 KB |
Output is correct |
7 |
Correct |
109 ms |
23896 KB |
Output is correct |
8 |
Correct |
104 ms |
23856 KB |
Output is correct |
9 |
Correct |
101 ms |
23892 KB |
Output is correct |
10 |
Correct |
109 ms |
23896 KB |
Output is correct |
11 |
Correct |
105 ms |
23864 KB |
Output is correct |
12 |
Correct |
91 ms |
23900 KB |
Output is correct |
13 |
Correct |
13 ms |
23892 KB |
Output is correct |
14 |
Correct |
14 ms |
23892 KB |
Output is correct |
15 |
Correct |
45 ms |
23868 KB |
Output is correct |
16 |
Correct |
80 ms |
23972 KB |
Output is correct |
17 |
Correct |
63 ms |
23884 KB |
Output is correct |
18 |
Correct |
92 ms |
23892 KB |
Output is correct |
19 |
Correct |
82 ms |
23980 KB |
Output is correct |
20 |
Correct |
98 ms |
23928 KB |
Output is correct |
21 |
Correct |
72 ms |
23916 KB |
Output is correct |
22 |
Correct |
77 ms |
23892 KB |
Output is correct |
23 |
Correct |
97 ms |
23892 KB |
Output is correct |
24 |
Correct |
115 ms |
23916 KB |
Output is correct |
25 |
Correct |
13 ms |
23880 KB |
Output is correct |
26 |
Correct |
15 ms |
23764 KB |
Output is correct |
27 |
Correct |
99 ms |
23928 KB |
Output is correct |
28 |
Correct |
110 ms |
23912 KB |
Output is correct |
29 |
Correct |
89 ms |
23920 KB |
Output is correct |
30 |
Correct |
101 ms |
23916 KB |
Output is correct |
31 |
Correct |
90 ms |
23908 KB |
Output is correct |
32 |
Correct |
106 ms |
23892 KB |
Output is correct |
33 |
Correct |
14 ms |
23932 KB |
Output is correct |
34 |
Correct |
14 ms |
23948 KB |
Output is correct |
35 |
Correct |
62 ms |
23824 KB |
Output is correct |
36 |
Correct |
79 ms |
23916 KB |
Output is correct |
37 |
Correct |
55 ms |
23892 KB |
Output is correct |
38 |
Correct |
114 ms |
23924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
577 ms |
26832 KB |
Output is correct |
2 |
Correct |
837 ms |
27044 KB |
Output is correct |
3 |
Execution timed out |
1031 ms |
26924 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1078 ms |
36660 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
23824 KB |
Output is correct |
2 |
Correct |
86 ms |
23916 KB |
Output is correct |
3 |
Correct |
59 ms |
23884 KB |
Output is correct |
4 |
Correct |
129 ms |
23904 KB |
Output is correct |
5 |
Correct |
14 ms |
23764 KB |
Output is correct |
6 |
Correct |
17 ms |
23804 KB |
Output is correct |
7 |
Correct |
109 ms |
23896 KB |
Output is correct |
8 |
Correct |
104 ms |
23856 KB |
Output is correct |
9 |
Correct |
101 ms |
23892 KB |
Output is correct |
10 |
Correct |
109 ms |
23896 KB |
Output is correct |
11 |
Correct |
105 ms |
23864 KB |
Output is correct |
12 |
Correct |
91 ms |
23900 KB |
Output is correct |
13 |
Correct |
13 ms |
23892 KB |
Output is correct |
14 |
Correct |
14 ms |
23892 KB |
Output is correct |
15 |
Correct |
45 ms |
23868 KB |
Output is correct |
16 |
Correct |
80 ms |
23972 KB |
Output is correct |
17 |
Correct |
63 ms |
23884 KB |
Output is correct |
18 |
Correct |
92 ms |
23892 KB |
Output is correct |
19 |
Correct |
82 ms |
23980 KB |
Output is correct |
20 |
Correct |
98 ms |
23928 KB |
Output is correct |
21 |
Correct |
577 ms |
26832 KB |
Output is correct |
22 |
Correct |
837 ms |
27044 KB |
Output is correct |
23 |
Execution timed out |
1031 ms |
26924 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1089 ms |
27676 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
23824 KB |
Output is correct |
2 |
Correct |
86 ms |
23916 KB |
Output is correct |
3 |
Correct |
59 ms |
23884 KB |
Output is correct |
4 |
Correct |
129 ms |
23904 KB |
Output is correct |
5 |
Correct |
14 ms |
23764 KB |
Output is correct |
6 |
Correct |
17 ms |
23804 KB |
Output is correct |
7 |
Correct |
109 ms |
23896 KB |
Output is correct |
8 |
Correct |
104 ms |
23856 KB |
Output is correct |
9 |
Correct |
101 ms |
23892 KB |
Output is correct |
10 |
Correct |
109 ms |
23896 KB |
Output is correct |
11 |
Correct |
105 ms |
23864 KB |
Output is correct |
12 |
Correct |
91 ms |
23900 KB |
Output is correct |
13 |
Correct |
13 ms |
23892 KB |
Output is correct |
14 |
Correct |
14 ms |
23892 KB |
Output is correct |
15 |
Correct |
45 ms |
23868 KB |
Output is correct |
16 |
Correct |
80 ms |
23972 KB |
Output is correct |
17 |
Correct |
63 ms |
23884 KB |
Output is correct |
18 |
Correct |
92 ms |
23892 KB |
Output is correct |
19 |
Correct |
82 ms |
23980 KB |
Output is correct |
20 |
Correct |
98 ms |
23928 KB |
Output is correct |
21 |
Correct |
72 ms |
23916 KB |
Output is correct |
22 |
Correct |
77 ms |
23892 KB |
Output is correct |
23 |
Correct |
97 ms |
23892 KB |
Output is correct |
24 |
Correct |
115 ms |
23916 KB |
Output is correct |
25 |
Correct |
13 ms |
23880 KB |
Output is correct |
26 |
Correct |
15 ms |
23764 KB |
Output is correct |
27 |
Correct |
99 ms |
23928 KB |
Output is correct |
28 |
Correct |
110 ms |
23912 KB |
Output is correct |
29 |
Correct |
89 ms |
23920 KB |
Output is correct |
30 |
Correct |
101 ms |
23916 KB |
Output is correct |
31 |
Correct |
90 ms |
23908 KB |
Output is correct |
32 |
Correct |
106 ms |
23892 KB |
Output is correct |
33 |
Correct |
14 ms |
23932 KB |
Output is correct |
34 |
Correct |
14 ms |
23948 KB |
Output is correct |
35 |
Correct |
62 ms |
23824 KB |
Output is correct |
36 |
Correct |
79 ms |
23916 KB |
Output is correct |
37 |
Correct |
55 ms |
23892 KB |
Output is correct |
38 |
Correct |
114 ms |
23924 KB |
Output is correct |
39 |
Correct |
577 ms |
26832 KB |
Output is correct |
40 |
Correct |
837 ms |
27044 KB |
Output is correct |
41 |
Execution timed out |
1031 ms |
26924 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
23824 KB |
Output is correct |
2 |
Correct |
86 ms |
23916 KB |
Output is correct |
3 |
Correct |
59 ms |
23884 KB |
Output is correct |
4 |
Correct |
129 ms |
23904 KB |
Output is correct |
5 |
Correct |
14 ms |
23764 KB |
Output is correct |
6 |
Correct |
17 ms |
23804 KB |
Output is correct |
7 |
Correct |
109 ms |
23896 KB |
Output is correct |
8 |
Correct |
104 ms |
23856 KB |
Output is correct |
9 |
Correct |
101 ms |
23892 KB |
Output is correct |
10 |
Correct |
109 ms |
23896 KB |
Output is correct |
11 |
Correct |
105 ms |
23864 KB |
Output is correct |
12 |
Correct |
91 ms |
23900 KB |
Output is correct |
13 |
Correct |
13 ms |
23892 KB |
Output is correct |
14 |
Correct |
14 ms |
23892 KB |
Output is correct |
15 |
Correct |
45 ms |
23868 KB |
Output is correct |
16 |
Correct |
80 ms |
23972 KB |
Output is correct |
17 |
Correct |
63 ms |
23884 KB |
Output is correct |
18 |
Correct |
92 ms |
23892 KB |
Output is correct |
19 |
Correct |
82 ms |
23980 KB |
Output is correct |
20 |
Correct |
98 ms |
23928 KB |
Output is correct |
21 |
Correct |
72 ms |
23916 KB |
Output is correct |
22 |
Correct |
77 ms |
23892 KB |
Output is correct |
23 |
Correct |
97 ms |
23892 KB |
Output is correct |
24 |
Correct |
115 ms |
23916 KB |
Output is correct |
25 |
Correct |
13 ms |
23880 KB |
Output is correct |
26 |
Correct |
15 ms |
23764 KB |
Output is correct |
27 |
Correct |
99 ms |
23928 KB |
Output is correct |
28 |
Correct |
110 ms |
23912 KB |
Output is correct |
29 |
Correct |
89 ms |
23920 KB |
Output is correct |
30 |
Correct |
101 ms |
23916 KB |
Output is correct |
31 |
Correct |
90 ms |
23908 KB |
Output is correct |
32 |
Correct |
106 ms |
23892 KB |
Output is correct |
33 |
Correct |
14 ms |
23932 KB |
Output is correct |
34 |
Correct |
14 ms |
23948 KB |
Output is correct |
35 |
Correct |
62 ms |
23824 KB |
Output is correct |
36 |
Correct |
79 ms |
23916 KB |
Output is correct |
37 |
Correct |
55 ms |
23892 KB |
Output is correct |
38 |
Correct |
114 ms |
23924 KB |
Output is correct |
39 |
Correct |
577 ms |
26832 KB |
Output is correct |
40 |
Correct |
837 ms |
27044 KB |
Output is correct |
41 |
Execution timed out |
1031 ms |
26924 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |