Submission #964287

#TimeUsernameProblemLanguageResultExecution timeMemory
964287PekibanMeteors (POI11_met)C++17
0 / 100
305 ms26928 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mxN = 3e5+3; vector<int> a[mxN]; array<int, 3> e[mxN]; ll bit[mxN], p[mxN], ans[mxN], c = -1; void upd(int idx, int x) { while (idx < mxN) { bit[idx] += x; idx |= (idx + 1); } } ll sum(ll idx) { ll s = 0; while (idx >= 0) { s += bit[idx]; idx &= (idx + 1); --idx; } return s; } void upd(int l, int r, int x) { upd(l, x); upd(r+1, -x); } int n, m; void solve(int l, int r, vector<int> &b) { if (l == r) { for (auto u : b) { ans[u] = l; } return; } int mid = (l + r)/2; while (c < mid) { ++c; if (e[c][0] <= e[c][1]) { upd(e[c][0], e[c][1], e[c][2]); } else { upd(e[c][0], m-1, e[c][2]); upd(0, e[c][1], e[c][2]); } } while (c > mid) { if (e[c][0] <= e[c][1]) { upd(e[c][0], e[c][1], -e[c][2]); } else { upd(e[c][0], m-1, -e[c][2]); upd(0, e[c][1], -e[c][2]); } --c; } vector<int> L, R; for (auto x : b) { ll s = 0; for (auto i : a[x]) { s += sum(i); } if (s >= p[x]) { ans[x] = mid; L.push_back(x); } else { R.push_back(x); } } b.clear(); if (!L.empty() && l != mid) solve(l, mid-1, L); if (!R.empty()) solve(mid+1, r, R); } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 0; i < m; ++i) { int x; cin >> x; --x; a[x].push_back(i); } for (int i = 0; i < n; ++i) { cin >> p[i]; } int k; cin >> k; for (int i = 0; i < k; ++i) { cin >> e[i][0] >> e[i][1] >> e[i][2]; --e[i][0], --e[i][1]; } e[k] = {0, 0, 0}; vector<int> b(n); iota(b.begin(), b.end(), 0); solve(0, k, b); for (int i = 0; i < n; ++i) { cout << (ans[i] == k ? "NIE" : to_string(ans[i] + 1)) << '\n'; } }
#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...