Submission #443084

# Submission time Handle Problem Language Result Execution time Memory
443084 2021-07-09T15:50:39 Z MladenP Meteors (POI11_met) C++17
100 / 100
2059 ms 65536 KB
#include <bits/stdc++.h>
#define MAXN 300010
#define lld long long
#define endl '\n'
#define PRINT(x) cerr<<flush<<#x<<'='<<x<<endl;
using namespace std;
int N, M, K, l[MAXN], r[MAXN], L[MAXN], R[MAXN], rez[MAXN];
lld bit[MAXN], p[MAXN], x[MAXN];
vector<int> sec[MAXN], q[MAXN];
void update(int idx, lld val) {
    while(idx < MAXN) {
        bit[idx] += val;
        idx += idx&-idx;
    }
}
lld query(int idx) {
    lld sum = 0;
    while(idx) {
        sum += bit[idx];
        idx -= idx&-idx;
    }
    return sum;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> N >> M;
    for(int i = 1; i <= M; i++) {
        int o; cin >> o;
        sec[o].push_back(i);
    }
    for(int i = 1; i <= N; i++) cin >> p[i];
    cin >> K;
    for(int i = 1; i <= K; i++) {
        cin >> l[i] >> r[i] >> x[i];
    }
    for(int i = 1; i <= N; i++) {
        L[i] = 1, R[i] = K, rez[i] = K+1;
    }
    bool changed = 1;
    while(changed) {
        changed = 0;
        fill(bit, bit+MAXN, 0LL);
        for(int i = 1; i <= K; i++) q[i].clear();

        for(int i = 1; i <= N; i++) {
            if(L[i] <= R[i]) {
                changed = 1;
                int mid = (L[i]+R[i])/2;
                q[mid].push_back(i);
            }
        }

        for(int i = 1; i <= K; i++) {
            if(l[i] <= r[i]) {
                update(l[i], x[i]);
                update(r[i]+1, -x[i]);
            } else {
                update(1, x[i]);
                update(r[i]+1, -x[i]);
                update(l[i], x[i]);
            }
            for(auto x : q[i]) {
                lld sum = 0;
                for(int s : sec[x]) {
                    sum += query(s);
                    if(sum >= p[x]) break;
                }
                if(sum >= p[x]) {
                    R[x] = i-1;
                    rez[x] = i;
                } else {
                    L[x] = i+1;
                }
            }
        }
    }
    for(int i = 1; i <= N; i++) {
        if(rez[i] == K+1) cout << "NIE" << endl;
        else cout << rez[i] << endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 16844 KB Output is correct
2 Correct 13 ms 16764 KB Output is correct
3 Correct 16 ms 16856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 16844 KB Output is correct
2 Correct 13 ms 16844 KB Output is correct
3 Correct 14 ms 16920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 18372 KB Output is correct
2 Correct 162 ms 20480 KB Output is correct
3 Correct 129 ms 20004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 19492 KB Output is correct
2 Correct 150 ms 19392 KB Output is correct
3 Correct 156 ms 20616 KB Output is correct
4 Correct 48 ms 18756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 18792 KB Output is correct
2 Correct 167 ms 21196 KB Output is correct
3 Correct 147 ms 17612 KB Output is correct
4 Correct 161 ms 20504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 18000 KB Output is correct
2 Correct 143 ms 19448 KB Output is correct
3 Correct 110 ms 18228 KB Output is correct
4 Correct 169 ms 21840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1102 ms 35732 KB Output is correct
2 Correct 695 ms 22824 KB Output is correct
3 Correct 876 ms 23356 KB Output is correct
4 Correct 1985 ms 64120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1110 ms 34388 KB Output is correct
2 Correct 708 ms 22788 KB Output is correct
3 Correct 668 ms 23492 KB Output is correct
4 Correct 2059 ms 65536 KB Output is correct