Submission #389707

# Submission time Handle Problem Language Result Execution time Memory
389707 2021-04-14T11:47:38 Z qwerasdfzxcl Meteors (POI11_met) C++14
74 / 100
6000 ms 39908 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
struct Seg{
    ll a[300300], lazy[(1<<20)+1];
    void init(int i, int l, int r){
        lazy[i] = 0;
        if (l==r){
            a[l] = 0; return;
        }
        int m = (l+r)>>1;
        init(i<<1, l, m); init(i<<1|1, m+1, r);
    }
    void propagate(int i, int l, int r){
        if (l==r) a[l] += lazy[i];
        else lazy[i<<1] += lazy[i], lazy[i<<1|1] += lazy[i];
        lazy[i] = 0;
    }
    void update(int i, int l, int r, int s, int e, int val){
        propagate(i, l, r);
        if (r<s || e<l) return;
        if (s<=l && r<=e){
            lazy[i] += val; propagate(i, l, r);
            return;
        }
        int m = (l+r)>>1;
        update(i<<1, l, m, s, e, val); update(i<<1|1, m+1, r, s, e, val);
    }
    ll query(int i, int l, int r, int p){
        propagate(i, l, r);
        if (r<p || p<l) return 0;
        if (p==l && p==r) return a[l];
        int m = (l+r)>>1;
        return query(i<<1, l, m, p)+query(i<<1|1, m+1, r, p);
    }
}tree;
struct Query{
    int l, r, a;
}query[300300];
vector<int> ar[300300], q[300300];
int l[300300], r[300300], ans[300300];
ll val[300300];

int main(){
    int n, m;
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    for (int i=1;i<=m;i++){
        int x;
        cin >> x;
        ar[x-1].push_back(i);
    }
    for (int i=0;i<n;i++) cin >> val[i];
    int tmp;
    cin >> tmp;
    for (int i=0;i<tmp;i++){
        cin >> query[i].l >> query[i].r >> query[i].a;
    }
    for (int i=0;i<n;i++) l[i] = 0, r[i] = tmp;
    int c=0;
    while(1){
        c++;
        assert(c<25);
        bool chk=0;
        for (int i=0;i<=tmp;i++) q[i].clear();
        for (int i=0;i<n;i++) if (l[i]!=r[i]){
            q[(l[i]+r[i])>>1].push_back(i);
            chk=1;
        }
        if (!chk) break;
        tree.init(1, 1, m);
        for (int i=0;i<tmp;i++){
            if (query[i].l<=query[i].r) tree.update(1, 1, m, query[i].l, query[i].r, query[i].a);
            else{
                tree.update(1, 1, m, 1, query[i].r, query[i].a);
                tree.update(1, 1, m, query[i].l, m, query[i].a);
            }
            for (auto &j:q[i]){
                ll tmp1 = 0;
                for (auto &x:ar[j]){
                    tmp1 += tree.query(1, 1, m, x);
                }
                if (tmp1>=val[j]){
                    r[j] = i;
                    ans[j] = i+1;
                }
                else l[j] = i+1;
            }
        }
    }
    for (int i=0;i<n;i++){
        if (l[i] == tmp) cout << "NIE\n";
        else cout << ans[i] << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 14412 KB Output is correct
2 Correct 15 ms 14552 KB Output is correct
3 Correct 14 ms 14540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 14528 KB Output is correct
2 Correct 14 ms 14540 KB Output is correct
3 Correct 14 ms 14572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 611 ms 17236 KB Output is correct
2 Correct 692 ms 19260 KB Output is correct
3 Correct 728 ms 18972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 615 ms 18376 KB Output is correct
2 Correct 670 ms 18288 KB Output is correct
3 Correct 710 ms 19532 KB Output is correct
4 Correct 211 ms 17752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 371 ms 17728 KB Output is correct
2 Correct 536 ms 20024 KB Output is correct
3 Correct 240 ms 15188 KB Output is correct
4 Correct 645 ms 19384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 602 ms 16788 KB Output is correct
2 Correct 622 ms 18340 KB Output is correct
3 Correct 652 ms 17036 KB Output is correct
4 Correct 685 ms 20744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 6044 ms 39908 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6043 ms 39204 KB Time limit exceeded
2 Halted 0 ms 0 KB -