Submission #926335

# Submission time Handle Problem Language Result Execution time Memory
926335 2024-02-12T19:38:48 Z VMaksimoski008 Meteors (POI11_met) C++14
74 / 100
341 ms 65536 KB
#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
 
using namespace std;
using ll = long long;
 
struct BIT {
    int n;
    vector<int> tree;
 
    void config(int _n) {
        n = _n + 2;
        tree.resize(_n+10);
    }
 
    void add(int p, int v) {
        for(p++; p<n; p+=p&-p) tree[p] += v;
    }
 
    ll query(int p) {
        ll ans = 0;
        for(p++; p>0; p-=p&-p) ans += tree[p];
        return ans;
    }
 
	ll sum(int l, int r) { return query(r) - query(l-1); }
    void clear() { for(auto &x : tree) x = 0; }
};
 
struct Query { int l, r, x; };
 
int main() {
    int n, m, it, i, k, elm, u;
    ll total = 0;
    cin >> n >> m;
 
    vector<int> owner[n+5];
    for(i=1; i<=m; i++) {
        cin >> elm;
        owner[elm].push_back(i);
    }
 
    int req[n+5];
    for(i=1; i<=n; i++) cin >> req[i];
 
    cin >> k;
    Query qus[k+5], q;
    for(i=1; i<=k; i++)
        cin >> qus[i].l >> qus[i].r >> qus[i].x;
 
    vector<int> L(n+5, 1), R(n+5, k+1);
    bool changed = true;
 
    BIT bit;
    bit.config(m+1);
    stack<int> to_check[k+2];

    while(changed) {
        changed = false;
 
        bit.clear();
 
        for(i=1; i<=n; i++)
            if(L[i] != R[i]) to_check[(L[i]+R[i])/2].push(i);
 
        for(it=1; it<=k; it++) {
            q = qus[it];
 
            if(q.l <= q.r) {
                bit.add(q.l, q.x);
                bit.add(q.r+1, -q.x);
            } else {
                bit.add(q.l, q.x);
                bit.add(m+1, -q.x);
 
                bit.add(1, q.x);
                bit.add(q.r+1, -q.x);
            }
 
            while(!to_check[it].empty()) {
                changed = true;
 
                u = to_check[it].top();
                to_check[it].pop();
 
                total = 0;
                for(int &x : owner[u]) {
                    total += bit.query(x);
                    if(total > req[u]) break;
                }
 
                if(total >= req[u]) R[u] = it;
                else L[u] = it + 1;
            }
        }
    }
 
    for(i=1; i<=n; i++) {
        if(L[i] <= k) cout << L[i] << '\n';
        else cout << "NIE\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 2 ms 1368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 860 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 2 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 35192 KB Output is correct
2 Correct 127 ms 36432 KB Output is correct
3 Correct 116 ms 35904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 35456 KB Output is correct
2 Correct 117 ms 35468 KB Output is correct
3 Correct 147 ms 36432 KB Output is correct
4 Correct 33 ms 5208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 35056 KB Output is correct
2 Correct 107 ms 36520 KB Output is correct
3 Correct 66 ms 34640 KB Output is correct
4 Correct 130 ms 36180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 35120 KB Output is correct
2 Correct 118 ms 35672 KB Output is correct
3 Correct 100 ms 35208 KB Output is correct
4 Correct 131 ms 36756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 339 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 341 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -