Submission #1133843

#TimeUsernameProblemLanguageResultExecution timeMemory
1133843steveonalexFood Court (JOI21_foodcourt)C++20
100 / 100
234 ms42396 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define MASK(i) (1LL << (i)) #define GETBIT(mask, i) (((mask) >> (i)) & 1) #define ALL(v) (v).begin(), (v).end() ll max(ll a, ll b){return (a > b) ? a : b;} ll min(ll a, ll b){return (a < b) ? a : b;} ll gcd(ll a, ll b){return __gcd(a, b);} ll LASTBIT(ll mask){return (mask) & (-mask);} int pop_cnt(ll mask){return __builtin_popcountll(mask);} int ctz(ll mask){return __builtin_ctzll(mask);} int logOf(ll mask){return __lg(mask);} mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);} template <class T1, class T2> bool maximize(T1 &a, T2 b){ if (a < b) {a = b; return true;} return false; } template <class T1, class T2> bool minimize(T1 &a, T2 b){ if (a > b) {a = b; return true;} return false; } template <class T> void printArr(T& container, string separator = " ", string finish = "\n"){ for(auto item: container) cout << item << separator; cout << finish; } template <class T> void remove_dup(vector<T> &a){ sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin()); } struct FenwickTree{ int n; vector<ll> a; FenwickTree(int _n){ n = _n; a.resize(n+1); } void update(int i, ll v){ while(i <= n){ a[i] += v; i += LASTBIT(i); } } ll get(int i){ ll ans = 0; while(i > 0){ ans += a[i]; i -= LASTBIT(i); } return ans; } ll get(int l, int r){return get(r) - get(l-1);} int binary_lift(ll x){ int p = MASK(logOf(n)), idx =0; while(p > 0){ if (idx + p <= n && x > a[idx + p]){ idx += p; x -= a[idx]; } p >>= 1; } return idx + 1; } }; const ll INF = 1e18 + 69; struct SegmentTree{ ll n, h; vector<ll> t, d; SegmentTree(ll _n){ n = _n; h = logOf(n); t.resize(n * 2 + 2), d.resize(n * 2 + 2); for(ll i = 1; i <= n * 2 + 1; ++i) t[i] = d[i] = 0; } void apply(ll p, ll value) { t[p] += value; if (p < n) d[p] += value; } void build(ll p) { while (p > 1) p >>= 1, t[p] = min(t[p<<1], t[p<<1|1]) + d[p]; } void push(ll p) { for (ll s = h; s > 0; --s) { ll i = p >> s; if (d[i] != 0) { apply(i<<1, d[i]); apply(i<<1|1, d[i]); d[i] = 0; } } } void update(ll l, ll r, ll value) { l += n, r += n+1; ll l0 = l, r0 = r; for (; l < r; l >>= 1, r >>= 1) { if (l&1) apply(l++, value); if (r&1) apply(--r, value); } build(l0); build(r0 - 1); } ll get(ll l, ll r) { l += n, r += n+1; push(l); push(r - 1); ll res = INF; for (; l < r; l >>= 1, r >>= 1) { if (l&1) res = min(res, t[l++]); if (r&1) res = min(t[--r], res); } return res; } }; void solve(){ int n, m, q; cin >> n >> m >> q; vector<vector<pair<int,int>>> add_query(n+2); vector<vector<pair<int,int>>> del_query(n+2); vector<vector<pair<ll,ll>>> query(n+2); vector<ll> color(q+2); for(ll i = 2; i <= q + 1; ++i){ int type; cin >> type; if (type == 1){ ll l, r, c, k; cin >> l >> r >> c >> k; color[i] = c; add_query[l].push_back({k, i}); add_query[r+1].push_back({-k, i}); } if (type == 2){ ll l, r, k; cin >> l >> r >> k; del_query[l].push_back({k, i}); del_query[r+1].push_back({-k, i}); } if (type == 3){ ll a, b; cin >> a >> b; query[a].push_back({b, i}); } } vector<ll> ans(q+2, -1); FenwickTree bit(q+1); SegmentTree st(q+1); for(int i = 1; i <= n; ++i){ for(pair<int,int> j: add_query[i]){ st.update(j.second, q + 1, j.first); bit.update(j.second, j.first); } for(pair<int,int> j: del_query[i]){ st.update(j.second, q + 1, -j.first); } for(pair<ll, ll> j: query[i]){ ll cur = st.get(j.second, j.second) - st.get(1, j.second); if (cur < j.first) { ans[j.second] = 0; continue; } ll off_set = cur - j.first; int idx = bit.binary_lift(bit.get(j.second) - off_set); ans[j.second] = color[idx]; } } for(int i: ans) if (i != -1) cout << i << " "; cout << "\n"; } int main(void){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); clock_t start = clock(); solve(); cerr << "Time elapsed: " << clock() - start << "ms!\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...