Submission #389706

# Submission time Handle Problem Language Result Execution time Memory
389706 2021-04-14T11:46:04 Z qwerasdfzxcl Meteors (POI11_met) C++14
74 / 100
6000 ms 40352 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<50);
        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 14464 KB Output is correct
2 Correct 13 ms 14504 KB Output is correct
3 Correct 16 ms 14540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 14520 KB Output is correct
2 Correct 14 ms 14544 KB Output is correct
3 Correct 14 ms 14544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 566 ms 17424 KB Output is correct
2 Correct 639 ms 19268 KB Output is correct
3 Correct 737 ms 18992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 696 ms 18348 KB Output is correct
2 Correct 644 ms 18296 KB Output is correct
3 Correct 769 ms 19532 KB Output is correct
4 Correct 176 ms 17736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 378 ms 17756 KB Output is correct
2 Correct 549 ms 19996 KB Output is correct
3 Correct 246 ms 15192 KB Output is correct
4 Correct 660 ms 19312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 631 ms 16800 KB Output is correct
2 Correct 612 ms 18348 KB Output is correct
3 Correct 567 ms 17168 KB Output is correct
4 Correct 645 ms 20824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 6049 ms 40352 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6070 ms 39272 KB Time limit exceeded
2 Halted 0 ms 0 KB -