제출 #1155420

#제출 시각아이디문제언어결과실행 시간메모리
1155420rlx0090새로운 문제 (POI11_met)C++20
0 / 100
6090 ms63984 KiB
#include <iostream> #include <vector> #include <fstream> #include <cstring> #include <string> #include <queue> #include <algorithm> #include <cmath> #include <map> #include <set> #include <cfloat> #include <random> #include <complex> #include <assert.h> #include <tuple> using namespace std; int n, m; struct meteor{ int a, b, c; }; vector<meteor> meteors(300005); vector<vector<int> > pt(300005); vector<long long> seg, lazy, aim(300005); int l[300005], r[300005], ans[300005]; vector<vector<int> > g(300005); void updatelazy(int nl, int nr, int no) { if(lazy[no] != 0) { if(nl == nr) seg[no] += lazy[no]; if(nl != nr) { lazy[(no << 1)] += lazy[no]; lazy[(no << 1) + 1] += lazy[no]; } lazy[no] = 0; } } void update(int l, int r, long long x, int nl, int nr, int no) { updatelazy(nl, nr, no); if(l > nr || r < nl) return; if(l <= nl && nr <= r) { if(nl == nr) seg[no] += x; else { lazy[(no << 1)] += x; lazy[(no << 1) + 1] += x; } return; } int m = (nl + nr) / 2; update(l, r, x, nl, m, (no << 1)); update(l, r, x, m + 1, nr, (no << 1) + 1); } int query(int x, int nl, int nr, int no) { updatelazy(nl, nr, no); if(x < nl || x > nr) return 0; if(nl == nr) return seg[no]; int m = (nl + nr) / 2; return query(x, nl, m, (no << 1)) + query(x, m + 1, nr, (no << 1) + 1); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n >> m; for(int i = 1; i <= m; ++i) { int x; cin >> x; pt[x].push_back(i); } for(int i = 1; i <= n; ++i) cin >> aim[i]; int q; cin >> q; for(int i = 1; i <= q; ++i) { int a, b, c; cin >> a >> b >> c; meteors[i] = {a, b, c}; } for(int i = 1; i <= n; ++i) { l[i] = 1; r[i] = q; } while(1) { seg = lazy = vector<long long >(300005 * 4, 0); for(int i = 1; i <= n; ++i) g[i].clear(); bool chk = false; for(int i = 1; i <= n; ++i) { if(l[i] <= r[i]) { chk = true; g[(l[i] + r[i]) / 2].push_back(i); } } if(!chk) break; for(int i = 1; i <= q; ++i) { meteor e = meteors[i]; if(e.a > e.b) { update(1, e.b, e.c, 1, m, 1); update(e.a, m, e.c, 1, m, 1); } else update(e.a, e.b, e.c, 1, m, 1); for(int j : g[i]) { long long amt = 0; for(int k : pt[j]) amt += query(k, 1, m, 1); if(amt >= aim[j]) { ans[j] = i; r[j] = i - 1; } else l[j] = i + 1; } } } for(int i = 1; i <= n; ++i) { if(l[i] > q) cout << "NIE" << '\n'; else cout << ans[i] << '\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...