Submission #479175

# Submission time Handle Problem Language Result Execution time Memory
479175 2021-10-10T14:07:03 Z Bogdan1110 Meteors (POI11_met) C++14
100 / 100
2143 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++) { // za svaki query
        
            if(l[i] <= r[i]) { // procesovanje range querry-ja
                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(int 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 11 ms 16844 KB Output is correct
2 Correct 11 ms 16856 KB Output is correct
3 Correct 13 ms 16844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 16844 KB Output is correct
2 Correct 11 ms 16852 KB Output is correct
3 Correct 13 ms 16864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 18380 KB Output is correct
2 Correct 168 ms 20496 KB Output is correct
3 Correct 129 ms 19988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 145 ms 19488 KB Output is correct
2 Correct 137 ms 19464 KB Output is correct
3 Correct 155 ms 20644 KB Output is correct
4 Correct 39 ms 18740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 18756 KB Output is correct
2 Correct 199 ms 21224 KB Output is correct
3 Correct 133 ms 17736 KB Output is correct
4 Correct 129 ms 20468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 148 ms 17824 KB Output is correct
2 Correct 163 ms 19492 KB Output is correct
3 Correct 92 ms 18144 KB Output is correct
4 Correct 151 ms 21860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1094 ms 35772 KB Output is correct
2 Correct 677 ms 22908 KB Output is correct
3 Correct 778 ms 23120 KB Output is correct
4 Correct 1909 ms 64076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1215 ms 34416 KB Output is correct
2 Correct 751 ms 22780 KB Output is correct
3 Correct 637 ms 23380 KB Output is correct
4 Correct 2143 ms 65536 KB Output is correct