Submission #993405

#TimeUsernameProblemLanguageResultExecution timeMemory
993405Kryptonchk새로운 문제 (POI11_met)C++17
100 / 100
1129 ms44096 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") using namespace std; //#include <atcoder/all> //using namespace atcoder; 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 clear() { fill(a.begin(), a.end(), 0); } 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(m + 1); for(int i = 1; i <= m; i++) { int pos; cin >> pos; p[pos].push_back(i); } vector<int> tar(n + 1); for(int i = 1; i <= n; i++) { cin >> tar[i]; } int t; cin >> t; vector<int> l(t + 1), r(t + 1), val(t + 1); for(int i = 1; i <= t; i++){ cin >> l[i] >> r[i] >> val[i]; } queue<tuple<int, int, vector<int>>> q; vector<int> ids; for(int i = 1; i <= n; i++){ ids.push_back(i); } q.emplace(1, t + 1, ids); Fenwick<int64_t> f(m); vector<int> res(n + 1); int ptr = 0; while(q.size()) { auto [ll, rr, id] = q.front(); q.pop(); if(ll == rr) { for(auto x : id) { res[x] = ll; } continue; } int mm = ll + (rr - ll) / 2; if(ptr > mm){ ptr = 0; f.clear(); } while(ptr < mm){ ptr++; f.add(l[ptr], val[ptr]); f.add(r[ptr] + 1, -val[ptr]); if(l[ptr] > r[ptr]) { f.add(1, val[ptr]); } } vector<int> to_left, to_right; for(auto x : id) { int64_t cur = tar[x]; for(auto y : p[x]) { cur -= f.sum(y); if(cur <= 0) { break; } } if(cur <= 0) { to_left.push_back(x); }else { to_right.push_back(x); } } if(to_left.size()) { q.emplace(ll, mm, to_left); } if(to_right.size()) { q.emplace(mm + 1, rr, to_right); } } for(int i = 1; i <= n; i++){ if(res[i] > t) { cout << "NIE" << '\n'; continue; } cout << res[i] << '\n'; } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; while(t--){ O_O(); } }
#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...