Submission #1004767

#TimeUsernameProblemLanguageResultExecution timeMemory
1004767KryptonchkMeteors (POI11_met)C++17
74 / 100
838 ms16728 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") using namespace std; using LL = long long; template <typename T> struct Fenwick { int n; int bit_num; vector<T> a; Fenwick(int n_ = 0) { init(n_); } void init(int n_) { n = n_; bit_num = __lg(n_) + 1; a.assign((1 << bit_num) + 1, T{}); } void add(int x, const T &v) { for (int i = x; !(i >> bit_num); i += i & -i) { a[i] = a[i] + v; } } T sum(int x) { T ans{}; for (int i = x; i > 0; i -= i & -i) { ans = ans + a[i]; } return ans; } T rangeSum(int l, int r) { return sum(r) - sum(l); } int select(T k) { int x = 0; for (int i = bit_num - 1; i >= 0; i--) { if (a[x + (1 << i)] < k) { k -= a[x + (1 << i)]; x = x + (1 << i); } } return x + 1; } }; void O_o() { int n, m; cin >> n >> m; vector<vector<int>> p(n + 1); for (int i = 0; i < m; i++) { int pos; cin >> pos; p[pos].push_back(i + 1); } vector<int> need(n + 1); for (int i = 1; i <= n; i++) { cin >> need[i]; } int Q; cin >> Q; vector<int> l(Q + 1), r(Q + 1), val(Q + 1); for (int i = 1; i <= Q; i++) { cin >> l[i] >> r[i] >> val[i]; } queue<tuple<int, int, vector<int>>> q; { vector<int> id; for (int i = 0; i < n; i++) { id.push_back(i + 1); } q.emplace(1, Q + 1, id); } Fenwick<LL> f(m + 2); vector<int> res(n + 1); int ptr = 0; while (q.size()) { auto [L, R, id] = q.front(); q.pop(); int M = L + (R - L) / 2; if (R == L) { for (auto x : id) { res[x] = M; } continue; } while (M < ptr) { f.init(m + 1); ptr = 0; } while (ptr < M) { ptr++; f.add(l[ptr], val[ptr]); f.add(r[ptr] + 1, -val[ptr]); if (r[ptr] < l[ptr]) { f.add(1, val[ptr]); } } vector<int> ok, neg; for (auto x : id) { LL now = need[x]; for(auto pos : p[x]) { now -= f.sum(pos); } if (now <= 0) { ok.push_back(x); } else { neg.push_back(x); } } if (ok.size()) { q.emplace(L, M, ok); } if (neg.size()) { q.emplace(M + 1, R, neg); } } for (int i = 1; i <= n; i++) { if (res[i] > Q) { cout << "NIE\n"; } else { cout << res[i] << '\n'; } } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; while (t--) { O_o(); } 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...