제출 #1126377

#제출 시각아이디문제언어결과실행 시간메모리
1126377jor0715새로운 문제 (POI11_met)C++20
74 / 100
716 ms35832 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define MAXN 300010 #define endl '\n' #define lowbit(x) (x & -x) struct MET{ int l, r, a, i; }; class BIT{ ll a[MAXN]; void add(int pos, int val){ while(pos < MAXN){ a[pos] += val; pos += lowbit(pos); } } public: BIT(){ } void add(int l, int r, int val){ add(l, val); add(r+1, -1*val); } ll qry(int x){ ll ans = 0; while(x > 0){ ans += a[x]; x -= lowbit(x); } return ans; } void reset(int x){ ll diff = qry(x) - qry(x - 1); add(x, -diff); } }; int n, m, k; int target[MAXN], ans[MAXN]; vector<MET> meter; vector<int> country; vector<int> station[MAXN]; BIT bit; void init(){ cin >> n >> m; for(int i = 1; i <= n; ++i) country.push_back(i); for(int i = 1; i <= m; ++i){ int kk; cin >> kk; station[kk].push_back(i); } for(int i = 1; i <= n; ++i){ int x; cin >> x; target[i] = x; } cin >> k; for(int i = 1; i <= k; ++i){ int l, r, a; cin >> l >> r >> a; meter.push_back({l, r, a, i}); } } void solve(int cl, int cr, vector<int>& country, vector<MET>& meter){ if(cl == cr){ for(int x : country) ans[x] = cl; return; } if(country.empty()) return; int mid = (cl + cr) >> 1; vector<MET> lmeter, rmeter; for(MET& me : meter){ int l = me.l, r = me.r, a = me.a, i = me.i; if(i > mid) rmeter.push_back({l, r, a, i}); else{ if(l > r) bit.add(l, m, a), bit.add(1, r, a); else bit.add(l, r, a); lmeter.push_back({l, r, a, i}); } } vector<int> lcountry, rcountry; for(int x : country){ ll summ = 0; for(int y : station[x]) summ += bit.qry(y), summ = min(summ, (ll) target[x]); if(summ >= target[x]){ lcountry.push_back(x); }else{ rcountry.push_back(x); target[x] -= summ; } } for(MET& me : lmeter){ int l = me.l, r = me.r; if(l > r){ bit.reset(l); bit.reset(m+1); bit.reset(1); bit.reset(r+1); }else{ bit.reset(l); bit.reset(r+1); } } solve(cl, mid, lcountry, lmeter); solve(mid+1, cr, rcountry, rmeter); } int main(){ init(); solve(1, MAXN, country, meter); for(int i = 1; i <= n; ++i){ if(ans[i] <= k) cout << ans[i] << endl; else cout << "NIE\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...