Submission #542293

# Submission time Handle Problem Language Result Execution time Memory
542293 2022-03-26T05:00:20 Z SirCovidThe19th Meteors (POI11_met) C++17
100 / 100
1556 ms 65536 KB
#include <bits/stdc++.h>
using namespace std; 
 
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define ll long long
 
const int mx = 3e5 + 5;
 
int n, m, q, targ[mx], ans[mx]; ll bit[mx]; vector<int> pos[mx]; array<int, 3> Q[mx]; 
 
void upd(int i, int val){
    for (; i < mx; i += i & (-i)) bit[i] += val;
}
void rupd(int l, int r, int val){
    if (l <= r) upd(l, val), upd(r + 1, -val);
    else rupd(l, m, val), rupd(1, r, val);
}
ll qry(int i){
    ll ret = 0;
    for (; i > 0; i -= i & (-i)) ret += bit[i], ret = min(ret, (ll)2e9); //avoid overflow
    return ret;
}
void pbs(int l, int r, vector<pair<int, ll>> states){
    if (l == r or states.empty()){
        for (auto [i, _] : states) ans[i] = l;
        return;
    }
    int mid = (l + r) / 2; vector<pair<int, ll>> L, R;
 
    FOR(i, l, mid + 1) rupd(Q[i][0], Q[i][1], Q[i][2]);
    for (auto [i, initVal] : states){
        ll sm = initVal;
        for (int p : pos[i]) sm += qry(p);
        (sm >= targ[i]) ? L.push_back({i, initVal}) : R.push_back({i, sm});
    }
    FOR(i, l, mid + 1) rupd(Q[i][0], Q[i][1], -Q[i][2]);
 
    pbs(l, mid, L); pbs(mid + 1, r, R);
}
 
int main(){
    cin >> n >> m;
    FOR(i, 1, m + 1){ int x; cin >> x; pos[x].push_back(i); }
    FOR(i, 1, n + 1) cin >> targ[i];
    cin >> q;
    FOR(i, 1, q + 1) cin >> Q[i][0] >> Q[i][1] >> Q[i][2];
 
    vector<pair<int, ll>> all;
    FOR(i, 1, n + 1) all.push_back({i, 0});
    pbs(1, q + 1, all);
    FOR(i, 1, n + 1) cout<<(ans[i] <= q ? to_string(ans[i]) : "NIE")<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7380 KB Output is correct
2 Correct 6 ms 7504 KB Output is correct
3 Correct 6 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7508 KB Output is correct
2 Correct 7 ms 7508 KB Output is correct
3 Correct 7 ms 7628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 12040 KB Output is correct
2 Correct 145 ms 23052 KB Output is correct
3 Correct 173 ms 11592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 144 ms 11016 KB Output is correct
2 Correct 137 ms 11016 KB Output is correct
3 Correct 117 ms 18088 KB Output is correct
4 Correct 48 ms 13228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 10584 KB Output is correct
2 Correct 164 ms 19728 KB Output is correct
3 Correct 71 ms 8652 KB Output is correct
4 Correct 172 ms 12368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 9708 KB Output is correct
2 Correct 151 ms 11448 KB Output is correct
3 Correct 90 ms 10060 KB Output is correct
4 Correct 175 ms 15452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 821 ms 65536 KB Output is correct
2 Correct 467 ms 19704 KB Output is correct
3 Correct 440 ms 12812 KB Output is correct
4 Correct 1397 ms 45424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 726 ms 51976 KB Output is correct
2 Correct 500 ms 20292 KB Output is correct
3 Correct 210 ms 13448 KB Output is correct
4 Correct 1556 ms 60232 KB Output is correct