Submission #762449

#TimeUsernameProblemLanguageResultExecution timeMemory
762449Chal1shkanMeteors (POI11_met)C++14
100 / 100
1685 ms61272 KiB
//Bismillahir-Rahmanir-Rahim # include <bits/stdc++.h> # define pb push_back # define ff first # define ss second # define nl "\n" # define sz(x) ((int)(x).size()) # define deb(x) cerr << #x << " = " << x << endl; # define pll pair <ll, ll> # define pii pair <int, int> typedef long long ll; typedef unsigned long long ull; typedef long double ld; const ll maxn = 3e5 + 25; const ll inf = 2e18 + 0; const ll mod = 1e9 + 7; const ll dx[] = {-1, 1, 0, 0}; const ll dy[] = {0, 0, -1, 1}; const ll P = 67; using namespace std; int n, m, q, tl[maxn], tr[maxn]; vector <int> boss[maxn]; int need[maxn], ans[maxn]; int l[maxn], r[maxn]; ll a[maxn]; vector <int> check[maxn]; struct fenwick { ll t[maxn]; void clear () { for (int i = 1; i <= m; ++i) { t[i] = 0; } } void update (int id, ll x) { for (; id < maxn; id += (id & (-id))) { t[id] += x; } } ll get (int id) { ll res = 0; for (; id >= 1; id -= (id & (-id))) { res += t[id]; } return res; } } t; void ma1n (/* SABR */) { cin >> n >> m; for (int i = 1; i <= m; ++i) { int owner; cin >> owner; boss[owner].pb(i); } for (int i = 1; i <= n; ++i) { cin >> need[i]; } cin >> q; for (int i = 1; i <= q; ++i) { cin >> l[i] >> r[i] >> a[i]; } for (int i = 1; i <= n; ++i) { tl[i] = 1, tr[i] = q, ans[i] = -1; } bool boo = 1; while (boo) { boo = 0; t.clear(); for (int i = 1; i <= n; ++i) { if (tl[i] <= tr[i]) { check[(tl[i] + tr[i]) >> 1].pb(i); } // cout << tl[i] << ' ' << tr[i] << nl; } for (int i = 1; i <= q; ++i) { if (l[i] <= r[i]) { t.update(l[i], a[i]); t.update(r[i] + 1, -a[i]); } else { t.update(1, a[i]); t.update(r[i] + 1, -a[i]); t.update(l[i], a[i]); } while (!check[i].empty()) { boo = 1; int id = check[i].back(); check[i].pop_back(); ll sum = 0; for (int x : boss[id]) { sum += t.get(x); if (sum >= need[id]) break; } if (sum >= need[id]) { tr[id] = i - 1; ans[id] = i; } else { tl[id] = i + 1; } } } } for (int i = 1; i <= n; ++i) { if (ans[i] == -1) { cout << "NIE" << nl; } else { cout << ans[i] << nl; } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("file.in", "r", stdin); // freopen("file.out", "w", stdout); int ttt = 1; // cin >> ttt; for (int test = 1; test <= ttt; ++test) { // cout << "Case " << test << ":" << '\n'; ma1n(); } return 0; } // 998batrr | BbIWEJI 3A TObOU!!! // tourist | BbIWEJI 3A TObOU!!!
#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...