Submission #762608

#TimeUsernameProblemLanguageResultExecution timeMemory
762608IssaMeteors (POI11_met)C++17
100 / 100
1006 ms64176 KiB
#include <algorithm> #include <iostream> #include <iomanip> #include <bitset> #include <cmath> #include <queue> #include <map> #include <set> // #pragma GCC optimize("O3,unroll-loops") // #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt") using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define ent "\n" const int maxn = 3e5 + 100; const ll INF = (ll)2e18; const int inf = (ll)2e9; const int maxl = 26; const int MOD = 1e9 + 7; int n, m, q; vector<int> g[maxn]; int a[maxn]; int ans[maxn]; ll t[maxn]; int l[maxn]; int r[maxn]; int x[maxn]; vector<int> cl; void upd(int i, int x){ for(; i <= m; i |= (i + 1)) t[i] += x, cl.push_back(i); } void upd(int l, int r, int x){ if(l <= r){ upd(l, x); upd(r + 1, -x); } else{ upd(1, x); upd(r + 1, -x); upd(l, x); } } ll get(int i){ ll res = 0; for(; i > 0; i = (i & (i + 1)) - 1) res += t[i]; return res; } void f(int tl, int tr, vector<int> &v){ if(tl > tr) return; int mid = (tl + tr) >> 1; vector<int> L, R; for(int i = tl; i <= mid; i++){ upd(l[i], r[i], x[i]); } for(int x: v){ ll sum = 0; for(int i: g[x]){ sum = min((ll)1e18, 1ll * get(i) + sum); } if(a[x] > sum) a[x] -= sum, R.push_back(x); else ans[x] = mid, L.push_back(x); } for(int x: cl) t[x] = 0; cl.clear(); f(tl, mid - 1, L); f(mid + 1, tr, R); } void test(){ cin >> n >> m; for(int i = 1; i <= m; i++){ int x; cin >> x; g[x].push_back(i); } vector<int> v; for(int i = 1; i <= n; i++){ cin >> a[i]; v.push_back(i); ans[i] = -1; } cin >> q; for(int i = 1; i <= q; i++){ cin >> l[i] >> r[i] >> x[i]; } f(1, q, v); for(int i = 1; i <= n; i++){ if(ans[i] == -1) cout << "NIE\n"; else cout << ans[i] << ent; } } int main(){ // freopen("cows.in", "r", stdin); // freopen("cows.out", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int t; t = 1; while(t--) test(); }
#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...