#include <bits/stdc++.h>
using namespace std;
#define POPCOUNT(n) (__builtin_popcountll((n)))
#define CLZ(n) (__builtin_clzll((n)))
#define CTZ(n) (__builtin_ctzll((n)))
#define LOG(n) (63 - __builtin_clzll((n)))
#define BIT(n, i) (((n) >> (i)) & 1ll)
#define MASK(i) (1ll << (i))
#define FLIP(n, i) ((n) ^ (1ll << (i)))
#define ON(n, i) ((n) | MASK(i))
#define OFF(n, i) ((n) & ~MASK(i))
#define Int __int128
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long, long long>> vll;
typedef vector<pair<long long, int>> vli;
typedef vector<pair<int, long long>> vil;
template <class T1, class T2> bool maximize(T1 &x, T2 y) {
if (x < y) {
x = y;
return true;
}
return false;
}
template <class T1, class T2> bool minimize(T1 &x, T2 y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <class T> void remove_duplicate(vector<T> &ve) {
sort (ve.begin(), ve.end());
ve.resize(unique(ve.begin(), ve.end()) - ve.begin());
}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
long long random(long long l, long long r) {
return uniform_int_distribution<long long>(l, r)(rng);
}
unsigned long long random(unsigned long long l, unsigned long long r) {
return uniform_int_distribution<unsigned long long>(l, r)(rng);
}
template <class T> T random(T r) {
return rng() % r;
}
const int N = 25e4 + 5, LG = 19;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const long long INF = 1e18;
int n, m, q;
struct SegmentTree {
vector<ll> mi, ma, lazyAdd, lazySet;
int n;
SegmentTree(int _n) {
n = _n;
mi.assign(4 * n + 5, 0);
ma.assign(4 * n + 5, 0);
lazyAdd.assign(4 * n + 5, 0);
lazySet.assign(4 * n + 5, -INF);
}
void apply_set(int id, ll val) {
mi[id] = ma[id] = val;
lazySet[id] = val, lazyAdd[id] = 0;
}
void apply_add(int id, ll val) {
mi[id] += val, ma[id] += val;
if (lazySet[id] != -INF) lazySet[id] += val;
else lazyAdd[id] += val;
}
void push(int id) {
if (lazySet[id] != -INF) {
apply_set(id << 1, lazySet[id]);
apply_set(id << 1 | 1, lazySet[id]);
}
else {
apply_add(id << 1, lazyAdd[id]);
apply_add(id << 1 | 1, lazyAdd[id]);
}
lazySet[id] = -INF, lazyAdd[id] = 0;
}
void add(int id, int l, int r, int u, int v, int val) {
if (l > v || r < u) return;
if (u <= l && r <= v) {
if (mi[id] + val >= 0) {
apply_add(id, val);
return;
}
if (ma[id] + val < 0) {
apply_set(id, 0);
return;
}
}
push(id); int mid = (l + r) >> 1;
add(id << 1, l, mid, u, v, val);
add(id << 1 | 1, mid + 1, r, u, v, val);
mi[id] = min(mi[id << 1], mi[id << 1 | 1]);
ma[id] = max(ma[id << 1], ma[id << 1 | 1]);
}
void add(int u, int v, int val) {
add(1, 1, n, u, v, val);
}
ll get(int id, int l, int r, int p) {
if (l == r) return mi[id];
push(id); int mid = (l + r) >> 1;
if (p <= mid) return get(id << 1, l, mid, p);
return get(id << 1 | 1, mid + 1, r, p);
}
ll get(int p) {
return get(1, 1, n, p);
}
};
struct FenwickTree {
using T = long long;
vector<T> bit;
FenwickTree(int n) {
resize(n);
}
void resize(int n) {
bit.assign(n + 1, 0);
}
void update(int p, T val) {
for (; p < int(bit.size()); p += p & -p) bit[p] += val;
}
void update(int l, int r, T val) {
update(l, val), update(r + 1, -val);
}
T get(int p) {
T ans = 0;
for (; p > 0; p -= p & -p) ans += bit[p];
return ans;
}
};
// struct Node {
// int le, ri;
// ll sum;
// Node(ll value = 0) {
// le = ri = 0;
// sum = value;
// }
// } nodes[4 * N * LG];
// int numNode = 0;
// vector<int> version;
// struct PersistentIT {
// int n;
// PersistentIT(int _n = 0) {
// n = _n;
// }
// int update(int oldId, int l, int r, int p, int val) {
// if (l > p || r < p) return oldId;
// int id = ++numNode;
// if (l == r) {
// nodes[id] = nodes[oldId];
// nodes[id].sum += val;
// return id;
// }
// int mid = (l + r) >> 1;
// nodes[id].le = update(nodes[oldId].le, l, mid, p, val);
// nodes[id].ri = update(nodes[oldId].ri, mid + 1, r, p, val);
// nodes[id].sum = nodes[nodes[id].le].sum + nodes[nodes[id].ri].sum;
// return id;
// }
// int update(int root, int p, int val) {
// return update(root, 1, n, p, val);
// }
// int update(int root, int l, int r, int val) {
// root = update(root, l, val);
// return update(root, r + 1, -val);
// }
// ll get(int id, int l, int r, int u, int v) {
// if (l > v || r < u) return 0;
// if (u <= l && r <= v) return nodes[id].sum;
// int mid = (l + r) >> 1;
// return get(nodes[id].le, l, mid, u, v) + get(nodes[id].ri, mid + 1, r, u, v);
// }
// ll get(int root, int p) {
// return get(root, 1, n, 1, p);
// }
// };
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> n >> m >> q;
SegmentTree len(n);
// PersistentIT R(n);
FenwickTree R(n);
// version.emplace_back(0);
vector<int> colors = {0};
for (int i = 1; i <= q; ++i) {
int type; cin >> type;
if (type == 1) {
int l, r, c, k; cin >> l >> r >> c >> k;
// version.emplace_back(R.update(version.back(), l, r, k));
R.update(l, r, k);
len.add(l, r, k);
}
if (type == 2) {
int l, r, k; cin >> l >> r >> k;
len.add(l, r, -k);
// len.maximize(l, r);
}
if (type == 3) {
int x; ll k; cin >> x >> k;
ll rightId = R.get(x);
ll leftId = rightId - len.get(x);
// cerr << leftId << ' ' << rightId << '\n';
if (leftId + k > rightId) cout << "0\n";
else {
// cerr << "hihi " << i << '\n';
// int low = 1, high = version.size() - 1, p = -1;
// while (low <= high) {
// int mid = (low + high) >> 1;
// if (R.get(version[mid], x) >= leftId + k) high = (p = mid) - 1;
// else low = mid + 1;
// }
// assert(p != -1);
// cout << colors[p] << '\n';
cout << m << '\n';
}
}
// for (int j = 1; j <= n; ++j)
// cerr << len.get(j) << ' ';
// cerr << '\n';
}
return 0;
}
| # | 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... |