This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |