Submission #680155

# Submission time Handle Problem Language Result Execution time Memory
680155 2023-01-10T03:27:06 Z browntoad Meteors (POI11_met) C++14
87 / 100
1639 ms 57564 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
#define ll long long
// #define int ll
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i=(n)-1; i>=0; i--)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())
#define SQ(x) (x)*(x)
#define f first
#define s second
#define pii pair<int, int>
#define endl '\n'
#define pb push_back

const ll mod = 1e9+7;
const ll maxn = 3e5+5;
const ll inf = (1ll<<60);
const ll iinf = 2e9;

ll pw(ll x, ll p){
    ll ret=1;
    while(p>0){
        if (p&1){
            ret*=x;
            ret%=mod;
        }
        x*=x;
        x%=mod;
        p>>=1;
    }
    return ret;
}
ll inv(ll x){
    return pw(x, mod-2);
}
int n, m, k;
vector<int> need(maxn), own(maxn), ans(maxn);
vector<int> ids[maxn];
int bit[21][maxn];
void modify(int a, int val, int lay){
    while(a<=m){
        bit[lay][a]+=val;
        a+=(a&-a);
    }
}
int query(int a, int lay){
    int ret=0;
    while(a>0){
        ret+=bit[lay][a];
        a-=(a&-a);
    }
    return ret;
}
struct mods{
    int l, r;
    int w;
};
vector<mods> quer;
int tmpv=0;
void run(int L, int R, vector<int> &vals, int lay){
    if (L>R) return;
    if (lay==21){
        REP(i, SZ(vals)){
            if (L==k) ans[vals[i]]=-1;
            else ans[vals[i]]=L+1;
        }
        return;
    }
    if (L==k){
        run(L, R, vals, lay+1);
        return;
    }
    int mid = (L+R)>>1;
    FOR(i, L, mid+1){
        if (quer[i].l<=quer[i].r){
            modify(quer[i].l, quer[i].w, lay);
            modify(quer[i].r+1, -quer[i].w, lay);
        }
        else {
            modify(quer[i].l, quer[i].w, lay);
            modify(m+1, -quer[i].w, lay);
            modify(1, quer[i].w, lay);
            modify(quer[i].r+1, -quer[i].w, lay);
        }
    }
    vector<int> aL, aR;
    REP(i, SZ(vals)){
        int tmpv=0;
        REP(j, SZ(ids[vals[i]])){
            tmpv+=query(ids[vals[i]][j], lay);
            if (tmpv>=need[vals[i]]) break;
        }
        if (tmpv>=need[vals[i]]){
            aL.pb(vals[i]);
        }
        else{
            aR.pb(vals[i]);
        }
    }
    run(L, mid, aL, lay+1);
    run(mid+1, R, aR, lay+1);

    FOR(i, mid+1, R+1){
        if (i>=k) break;
        if (quer[i].l<=quer[i].r){
            modify(quer[i].l, quer[i].w, lay);
            modify(quer[i].r+1, -quer[i].w, lay);
        }
        else {
            modify(quer[i].l, quer[i].w, lay);
            modify(m+1, -quer[i].w, lay);
            modify(1, quer[i].w, lay);
            modify(quer[i].r+1, -quer[i].w, lay);
        }
    }

}
signed main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin>>n>>m;
    vector<int> tmp(n);
    REP(i, n){
        tmp[i]=i+1;
    }
    REP1(i, m){
        cin>>own[i];
        ids[own[i]].pb(i);
    }
    REP1(i, n){
        cin>>need[i];
    }
    cin>>k;
    REP(i, k){
        int x, y, z; cin>>x>>y>>z;
        quer.pb({x, y, z});
    }
    fill(ALL(ans), -1);
    run(0, k, tmp, 0);
    REP1(i, n){
        if (ans[i]==-1) cout<<"NIE"<<endl;
        else cout<<ans[i]<<endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11092 KB Output is correct
2 Correct 8 ms 11184 KB Output is correct
3 Correct 7 ms 11092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11180 KB Output is correct
2 Correct 8 ms 11220 KB Output is correct
3 Correct 7 ms 11092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 17296 KB Output is correct
2 Correct 120 ms 19376 KB Output is correct
3 Correct 105 ms 17488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 17428 KB Output is correct
2 Correct 113 ms 17432 KB Output is correct
3 Correct 137 ms 18700 KB Output is correct
4 Correct 34 ms 16652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 16996 KB Output is correct
2 Correct 98 ms 18808 KB Output is correct
3 Correct 54 ms 12368 KB Output is correct
4 Correct 113 ms 17820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 17148 KB Output is correct
2 Correct 102 ms 17500 KB Output is correct
3 Correct 85 ms 17092 KB Output is correct
4 Correct 126 ms 18428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1183 ms 56132 KB Output is correct
2 Correct 460 ms 48460 KB Output is correct
3 Correct 231 ms 16488 KB Output is correct
4 Correct 1639 ms 57564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1221 ms 54920 KB Output is correct
2 Correct 470 ms 47244 KB Output is correct
3 Incorrect 199 ms 17000 KB Output isn't correct
4 Halted 0 ms 0 KB -