# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
381224 | 2021-03-24T19:09:46 Z | aryan12 | Meteors (POI11_met) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> #pragma GCC optimize "trapv" using namespace std; vector<unsigned long long> req; vector<vector<unsigned long long>> land; vector<array<unsigned long long, 3>> D; vector<unsigned long long> ans; unsigned long long n, m; struct BIT{ vector<unsigned long long> tree; unsigned long long n; void init(unsigned long long _n){ n = _n; tree.resize(n+1); } void upd(unsigned long long idx, unsigned long long val){ for(; idx <= n; idx += (idx&(-idx))) tree[idx] += val; } void upd(unsigned long long l, unsigned long long r, unsigned long long val){ upd(l, val); upd(r+1, -val); } unsigned long long query(unsigned long long idx){ unsigned long long sum = 0; for(; idx > 0; idx -= (idx&(-idx))) sum += tree[idx]; return sum; } }bit; void PBS(unsigned long long l, unsigned long long r, vector<unsigned long long> active){ if(active.size() == 0) return; if(r - l == 1){ for(unsigned long long i : active) ans[i] = l; return; } unsigned long long mid = (l + r) >> 1; for(unsigned long long i = l; i < mid; i++){ if(D[i][0] <= D[i][1]) bit.upd(D[i][0], D[i][1], unsigned long long(D[i][2])); else{ bit.upd(D[i][0], m, unsigned long long(D[i][2])); bit.upd(1, D[i][1], unsigned long long(D[i][2])); } } vector<unsigned long long> nq[2]; for(unsigned long long i : active){ unsigned long long sum = 0; for(unsigned long long v : land[i]) sum += bit.query(v); if(sum >= req[i]) nq[0].push_back(i); else{ req[i] -= sum; nq[1].push_back(i); } } for(unsigned long long i = l; i < mid; i++){ if(D[i][0] <= D[i][1]) bit.upd(D[i][0], D[i][1], unsigned long long(-D[i][2])); else{ bit.upd(D[i][0], m, unsigned long long(-D[i][2])); bit.upd(1, D[i][1], unsigned long long(-D[i][2])); } } PBS(l, mid, nq[0]); PBS(mid, r, nq[1]); } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; land.resize(n+1), req.resize(n+1); ans.resize(n+1); bit.init(m); for(unsigned long long i = 1; i <= m; i++){ unsigned long long x; cin >> x; land[x].push_back(i); } for(unsigned long long i = 1; i <= n; i++) cin >> req[i]; unsigned long long k; cin >> k; D.resize(k+1); for(unsigned long long i = 1; i <= k; i++){ auto& [l, r, upd] = D[i]; cin >> l >> r >> upd; } vector<unsigned long long> cur(n); iota(cur.begin(), cur.end(), 1); PBS(1, k+2, cur); for(unsigned long long i = 1; i <= n; i++) if(ans[i] == k+1) cout << "NIE\n"; else cout << ans[i] << '\n'; return 0; }