Submission #919456

# Submission time Handle Problem Language Result Execution time Memory
919456 2024-01-31T21:21:58 Z noyancanturk Meteors (POI11_met) C++17
74 / 100
940 ms 65536 KB
#ifndef Local
    #pragma GCC optimize("O3,unroll-loops")
    const int lim=3e5+100;
#else
    const int lim=1e3+100;
#endif
    
#include "bits/stdc++.h"
using namespace std;
    
#define int int64_t
#define pb push_back
    
const int mod=1e9+7;
using pii=pair<int,int>;

int tree[4*lim];
struct segtree{
    int n;
    segtree(int n):n(n){
        for(int i=1;i<=4*n;i++){
            tree[i]=0;
        }
    }
    int L,R,VAL;
    void update(int l,int r,int node){
        if(L<=l&&r<=R){
            tree[node]+=VAL;
            return;
        }
        if(r<L||R<l){
            return;
        }
        int mid=(l+r)>>1,child=node<<1;
        update(l,mid,child),update(mid+1,r,child|1);
    }
    void insert(int l,int r,int val){
        L=l,R=r,VAL=val;
        update(1,n,1);
    }
    int P;
    int query(int l,int r,int node){
        //cerr<<l<<" "<<r<<" "<<tree[node]<<"\n";
        if(l==r)return tree[node];
        int mid=(l+r)>>1,child=node<<1;
        if(P<=mid)return tree[node]+query(l,mid,child);
        return tree[node]+query(mid+1,r,child|1);
    }
    int query(int p){
        //cerr<<p<<"\n";
        P=p;
        return query(1,n,1);
    }
};

struct bs{
    int l,r,i;
    inline bs(){}
    inline bs(int l,int r,int i)
    :l(l),r(r),i(i){}
};

struct comp{
    inline bool operator()(bs&a,bs&b){
        return (a.l+a.r)/2<(b.l+b.r)/2;
    }
};

inline void solve(){
    int n,m;
    cin>>n>>m;
    vector<int>v[n+1];
    for(int i=1;i<=m;i++){
        int tem;
        cin>>tem;
        v[tem].pb(i);
    }
    int goal[n+1];
    for(int i=1;i<=n;i++){
        cin>>goal[i];
    }
    int k;
    cin>>k;
    bs all[k+1];
    for(int i=1;i<=k;i++){
        cin>>all[i].l>>all[i].r>>all[i].i;
    }
    vector<bs>qq[k+1];
    for(int i=1;i<=n;i++){
        qq[(1+k)>>1].pb(bs(1,k,i));
    }
    int ans[n+1];
    memset(ans,-1,sizeof(ans));
    bool ok=1;
    while(ok){
        ok=0;
        segtree st(m+10);
        for(int t=1;t<=k;t++){
            if(all[t].l<=all[t].r)st.insert(all[t].l,all[t].r,all[t].i);
            else {
                st.insert(all[t].l,m,all[t].i);
                st.insert(1,all[t].r,all[t].i);
            }
            while(qq[t].size()){
                bs now=qq[t].back();
                qq[t].pop_back();
                //cerr<<now.l<<" "<<now.r<<" "<<now.i<<"\n\n";
                int tot=0;
                for(int j:v[now.i]){
                    tot+=st.query(j);
                }
                //cerr<<mid<<" "<<tot<<"\n\n";
                int mid=(now.l+now.r)>>1;
                if(goal[now.i]<=tot){
                    ans[now.i]=mid;
                    if(now.l<=mid-1){
                        qq[(now.l+mid-1)>>1].pb(bs(now.l,mid-1,now.i));
                        ok=1;
                    }
                }else{
                    if(mid+1<=now.r){
                        qq[(mid+1+now.r)>>1].pb(bs(mid+1,now.r,now.i));
                        ok=1;
                    }
                }
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(ans[i]==-1)cout<<"NIE\n";
        else cout<<ans[i]<<"\n";
    }
}
    
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
#ifdef Local  
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#else

#endif
    int t=1;
    //cin>>t;
    while (t--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 600 KB Output is correct
2 Correct 3 ms 600 KB Output is correct
3 Correct 3 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 219 ms 8688 KB Output is correct
2 Correct 256 ms 18036 KB Output is correct
3 Correct 258 ms 13664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 236 ms 11848 KB Output is correct
2 Correct 238 ms 11600 KB Output is correct
3 Correct 301 ms 18576 KB Output is correct
4 Correct 53 ms 9944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 8980 KB Output is correct
2 Correct 153 ms 18308 KB Output is correct
3 Correct 98 ms 3664 KB Output is correct
4 Correct 239 ms 15308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 241 ms 6836 KB Output is correct
2 Correct 216 ms 12012 KB Output is correct
3 Correct 201 ms 7764 KB Output is correct
4 Correct 273 ms 20420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 696 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 940 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -