Submission #1288819

#TimeUsernameProblemLanguageResultExecution timeMemory
1288819thieunguyenhuyFood Court (JOI21_foodcourt)C++20
0 / 100
1104 ms182244 KiB
#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 { struct Node { ll mi, ma; ll lazyAdd, lazySet; Node() { mi = ma = 0; lazyAdd = 0, lazySet = -INF; } Node operator+ (const Node &other) { Node res; res.mi = min(mi, other.mi); res.ma = max(ma, other.ma); return res; } }; vector<Node> nodes; int n; SegmentTree(int _n) { n = _n; nodes.assign(4 * n + 5, Node()); } void apply_set(int id, ll val) { nodes[id].mi = nodes[id].ma = val; nodes[id].lazySet = val, nodes[id].lazyAdd = 0; } void apply_add(int id, ll val) { nodes[id].mi += val, nodes[id].ma += val; if (nodes[id].lazySet != -INF) nodes[id].lazySet += val; else nodes[id].lazyAdd += val; } void push(int id) { if (nodes[id].lazySet != -INF) { apply_set(id << 1, nodes[id].lazySet); apply_set(id << 1 | 1, nodes[id].lazySet); } else { apply_add(id << 1, nodes[id].lazyAdd); apply_add(id << 1 | 1, nodes[id].lazyAdd); } nodes[id].lazySet = -INF, nodes[id].lazyAdd = 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 (nodes[id].mi + val >= 0) { apply_add(id, val); return; } if (nodes[id].ma + 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); nodes[id] = nodes[id << 1] + nodes[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 nodes[id].mi; 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 Node { int le, ri; ll sum; Node(ll value = 0) { le = ri = 0; sum = value; } } nodes[2 * 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); 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)); colors.emplace_back(c); 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(version.back(), 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...