#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 SegmentTreeBeats
{
struct Node
{
ll cap, add;
Node() : cap(0), add(0) {};
};
vector<Node> st;
int n;
SegmentTreeBeats(int n) : n(n) { st.resize(4 * n + 1); }
void apply(int head, ll c, ll a)
{
st[head].cap = min(st[head].cap + a, c);
st[head].add += a;
}
void pass(int head)
{
apply(head << 1, st[head].cap, st[head].add);
apply(head << 1 | 1, st[head].cap, st[head].add);
st[head].cap = INF;
st[head].add = 0;
}
void update(int head, int l, int r, int u, int v, ll val)
{
if (l > v || r < u) return;
if (u <= l && r <= v)
{
apply(head, INF, val);
return;
}
pass(head);
int mid = l + r >> 1;
update(head << 1, l, mid, u, v, val);
update(head << 1 | 1, mid + 1, r, u, v, val);
}
void update(int u, int v, ll val)
{
update(1, 1, n, u, v, val);
apply(1, 0, 0);
}
ll query(int head, int l, int r, int pos)
{
if (pos < l || r < pos) return -INF;
if (l == r) return st[head].cap;
pass(head);
int mid = l + r >> 1;
return max(query(head << 1, l, mid, pos), query(head << 1 | 1, mid + 1, r, pos));
}
ll query(int pos) { return query(1, 1, n, pos); }
};
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;
SegmentTreeBeats 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.update(l, r, -k);
}
if (type == 2) {
int l, r, k; cin >> l >> r >> k;
len.update(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.query(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... |