답안 #389716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
389716 2021-04-14T12:05:01 Z qwerasdfzxcl Meteors (POI11_met) C++14
74 / 100
2078 ms 37068 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
struct Seg{
    ll tree[600600];
    int sz;
    void init(){
        for (int i=1;i<((sz)<<1);i++) tree[i] = 0;
    }
    void update_p(int i, int p){
        i += sz;
        for (tree[i]+=p;i>1;i>>=1) tree[i>>1] = tree[i]+tree[i^1];
    }
    void update(int l, int r, int p){
        update_p(l, p);
        if (r<sz-1) update_p(r+1, -p);
    }
    ll query(int l, int r){
        ll ret = 0;
        for (l += sz, r += sz;l<r;l>>=1, r>>=1){
            if (l&1) ret += tree[l++];
            if (r&1) ret += tree[--r];
        }
        return ret;
    }
    void debug(){
        for (int i=sz;i<(sz<<1);i++) printf("%lld ", tree[i]);
        printf("\n");
    }
}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;
    tree.sz = m+1;
    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<12);
        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();
        for (int i=0;i<tmp;i++){
            if (query[i].l<=query[i].r) tree.update(query[i].l, query[i].r, query[i].a);
            else{
                tree.update(1, query[i].r, query[i].a);
                tree.update(query[i].l, m, query[i].a);
            }
            for (auto &j:q[i]){
                ll tmp1 = 0;
                for (auto &x:ar[j]){
                    tmp1 += tree.query(1, x+1);
                }
                if (tmp1>=val[j]){
                    r[j] = i;
                    ans[j] = i+1;
                }
                else l[j] = i+1;
            }
            //tree.debug();
        }
    }
    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 10 ms 14412 KB Output is correct
2 Correct 10 ms 14448 KB Output is correct
3 Correct 10 ms 14412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14412 KB Output is correct
2 Correct 11 ms 14536 KB Output is correct
3 Correct 11 ms 14540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 16620 KB Output is correct
2 Correct 192 ms 18640 KB Output is correct
3 Correct 191 ms 18316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 171 ms 17672 KB Output is correct
2 Correct 179 ms 17664 KB Output is correct
3 Correct 192 ms 18824 KB Output is correct
4 Correct 71 ms 17124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 17084 KB Output is correct
2 Correct 153 ms 19284 KB Output is correct
3 Correct 48 ms 15076 KB Output is correct
4 Correct 172 ms 18692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 153 ms 16148 KB Output is correct
2 Correct 164 ms 17752 KB Output is correct
3 Correct 135 ms 16400 KB Output is correct
4 Correct 197 ms 20080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1996 ms 37068 KB Output is correct
2 Incorrect 821 ms 31812 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2078 ms 35532 KB Output is correct
2 Incorrect 709 ms 30336 KB Output isn't correct
3 Halted 0 ms 0 KB -