This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;
#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout (T t, U...u) {cout << t << (sizeof... (u) ? ", " : ""), dout (u...);}
#else
#define debug(...) 7122
#endif
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
#define lpos pos*2
#define rpos pos*2+1
// Merge(d1, a1), (d2, a2) => (d1 + max(d2-a1, 0), a2 + max(a1-d2, 0))
const int SIZE = 2.5e5 + 5;
int n, m, q;
int ans[SIZE];
vector<pair<ll, int>> ask[SIZE]; // ask[p] : (x, id)
vector<tuple<int, int, int>> add[SIZE]; // add[p] : (c, k, id)
vector<pair<int, int>> del[SIZE]; // del[p] : (k, id)
struct Segtree1 {
struct Node {
ll d, a;
Node operator + (const Node& rhs) const {
Node re;
re.d = d + max(rhs.d - a, 0ll);
re.a = rhs.a + max(a - rhs.d, 0ll);
return re;
}
} node[4 * SIZE];
void upd(int pos, int l, int r, int p, int ty, int x) {
if (l == r) {
if (ty == 1) node[pos].a += x;
if (ty == 2) node[pos].d += x;
return;
}
int mid = (l + r) / 2;
if (p <= mid) upd(lpos, l, mid, p, ty, x);
else upd(rpos, mid + 1, r, p, ty, x);
node[pos] = node[lpos] + node[rpos];
}
Node que(int pos, int l, int r, int L, int R) {
if (l == L && r == R) return node[pos];
int mid = (L + R) / 2;
if (r <= mid) return que(lpos, l, r, L, mid);
if (l > mid) return que(rpos, l, r, mid + 1, R);
return que(lpos, l, mid, L, mid) + que(rpos, mid + 1, r, mid + 1, R);
}
} sgt1;
struct Segtree2 {
int g[SIZE];
ll sum[4 * SIZE];
void upd(int pos, int l, int r, int p, int c, int x) {
if (l == r) {
g[p] = c;
sum[pos] += x;
return;
}
int mid = (l + r) / 2;
if (p <= mid) upd(lpos, l, mid, p, c, x);
else upd(rpos, mid + 1, r, p, c, x);
sum[pos] = sum[lpos] + sum[rpos];
}
ll que(int pos, int l, int r, int L, int R) {
if (l == L && r == R) return sum[pos];
int mid = (L + R) / 2;
if (r <= mid) return que(lpos, l, r, L, mid);
if (l > mid) return que(rpos, l, r, mid + 1, R);
return que(lpos, l, mid, L, mid) + que(rpos, mid + 1, r, mid + 1, R);
}
int sch(int pos, int l, int r, ll x) {
if (l == r) return g[l];
int mid = (l + r) / 2;
if (sum[lpos] >= x) return sch(lpos, l, mid, x);
else return sch(rpos, mid + 1, r, x - sum[lpos]);
}
} sgt2;
void solve() {
cin >> n >> m >> q;
FOR (i, 1, q) {
ans[i] = -1;
int t, l, r, c, k;
cin >> t;
if (t == 1) {
cin >> l >> r >> c >> k;
add[l].pb(c, k, i);
add[r + 1].pb(0, -k, i);
}
if (t == 2) {
cin >> l >> r >> k;
del[l].pb(k, i);
del[r + 1].pb(-k, i);
}
if (t == 3) {
int p;
ll x;
cin >> p >> x;
ask[p].pb(x, i);
}
}
FOR (i, 1, n) {
for (auto [c, k, id] : add[i]) {
sgt1.upd(1, 1, q, id, 1, k);
sgt2.upd(1, 1, q, id, c, k);
}
for (auto [k, id] : del[i]) {
sgt1.upd(1, 1, q, id, 2, k);
}
for (auto [p, id] : ask[i]) {
ll tot = sgt2.que(1, 1, id, 1, q);
ll cur = sgt1.que(1, 1, id, 1, q).a;
if (p > cur) ans[id] = 0;
else ans[id] = sgt2.sch(1, 1, q, tot - cur + p);
}
}
FOR (i, 1, q) if (ans[i] != -1) cout << ans[i] << '\n';
}
int main() {
Waimai;
solve();
}
# | 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... |