답안 #389703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
389703 2021-04-14T11:45:13 Z qwerasdfzxcl Meteors (POI11_met) C++14
74 / 100
6000 ms 39900 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<100);
        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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 14412 KB Output is correct
2 Correct 16 ms 14540 KB Output is correct
3 Correct 14 ms 14412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14480 KB Output is correct
2 Correct 14 ms 14548 KB Output is correct
3 Correct 14 ms 14540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 578 ms 17344 KB Output is correct
2 Correct 637 ms 19268 KB Output is correct
3 Correct 639 ms 18964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 587 ms 18376 KB Output is correct
2 Correct 607 ms 18444 KB Output is correct
3 Correct 715 ms 19448 KB Output is correct
4 Correct 181 ms 17732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 356 ms 17684 KB Output is correct
2 Correct 583 ms 20028 KB Output is correct
3 Correct 223 ms 15148 KB Output is correct
4 Correct 635 ms 19312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 626 ms 16792 KB Output is correct
2 Correct 567 ms 18372 KB Output is correct
3 Correct 594 ms 17112 KB Output is correct
4 Correct 661 ms 20692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6035 ms 39900 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6038 ms 38788 KB Time limit exceeded
2 Halted 0 ms 0 KB -