Submission #944109

# Submission time Handle Problem Language Result Execution time Memory
944109 2024-03-12T08:34:41 Z Warinchai Meteors (POI11_met) C++14
74 / 100
3351 ms 65536 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
int own[300005];
vector<int>states[300005];
int least[300005];
struct segtree{
    int info[1200005];
    int lz[1200005];
    void push(int st,int en,int i){
        if(lz[i]!=0){
            if(st==en)info[i]+=lz[i];
            else {
                lz[i*2+1]+=lz[i];
                lz[i*2]+=lz[i];
            }
            lz[i]=0;
        }
    }
    void upd(int st,int en,int i,int l,int r,int val){
        push(st,en,i);
        if(st>r||en<l)return;
        if(st>=l&&en<=r)return lz[i]+=val,push(st,en,i),void();
        int m=(st+en)/2;
        upd(st,m,i*2,l,r,val);
        upd(m+1,en,i*2+1,l,r,val);
    }
    int fval(int st,int en,int i,int pos){
        push(st,en,i);
        if(st==en)return info[i];
        int m=(st+en)/2;
        if(pos<=m)return fval(st,m,i*2,pos);
        else return fval(m+1,en,i*2+1,pos);
    }
    void clear(int st,int en,int i){
        lz[i]=0;
        if(st==en)return info[i]=0,void();
        int m=(st+en)/2;
        clear(st,m,i*2);
        clear(m+1,en,i*2+1);
    }
}tr;
int st[300005];
int en[300005];
struct meteor{
    int l,r,a;
    meteor(int x,int y,int z){
        l=x,r=y,a=z;
    }
};
vector<meteor>events;
vector<int>query[300005];
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,m;cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>own[i];
        states[own[i]].push_back(i);
    }
    for(int i=1;i<=n;i++){
        cin>>least[i];
    }
    int k;cin>>k;
    int a,b,c,md,cur,l,r,sum,x;
    for(int i=1;i<=k;i++){
        a,b,c;cin>>a>>b>>c;
        events.push_back(meteor(a,b,c));
    }
    for(int i=1;i<=n;i++){
        st[i]=1;en[i]=k+1;
        md=(st[i]+en[i])/2;
        query[md].push_back(i);
    }
    //cout<<"work\n";
    while(1){
        cur=0;
        for(auto x:events){
            cur++;
            //cout<<"EVENT:"<<cur<<"\n";
            l=x.l;
            r=x.r;
            if(l<=r)tr.upd(1,m,1,l,r,x.a);
            else tr.upd(1,m,1,l,m,x.a),tr.upd(1,m,1,1,r,x.a);
            for(auto y:query[cur]){
                //cerr<<"STATE:"<<y<<"\n";
                sum=0;
                for(auto z:states[y]){
                    //cerr<<"STATION:"<<z<<" "<<tr.fval(1,m,1,z)<<"\n";
                    sum+=tr.fval(1,m,1,z);
                }
                if(sum>=least[y]){
                    //cerr<<"ENOUGH\n";
                    en[y]=cur;
                }else{
                    //cerr<<"NOT ENOUGH\n";
                    st[y]=cur+1;
                }
            }
            query[cur].clear();
        }
        tr.clear(1,m,1);
        int check=1;
        for(int i=1;i<=n;i++){
            if(st[i]!=en[i]){
                check=0;
                md=(st[i]+en[i])/2;
                query[md].push_back(i);
            }
        }
        if(check)break;
    }
    for(int i=1;i<=n;i++){
        x=st[i];
        if(x==k+1)cout<<"NIE\n";
        else cout<<x<<"\n";
    }
}

Compilation message

met.cpp: In function 'int32_t main()':
met.cpp:67:9: warning: left operand of comma operator has no effect [-Wunused-value]
   67 |         a,b,c;cin>>a>>b>>c;
      |         ^
met.cpp:67:13: warning: right operand of comma operator has no effect [-Wunused-value]
   67 |         a,b,c;cin>>a>>b>>c;
      |             ^
met.cpp:67:14: warning: right operand of comma operator has no effect [-Wunused-value]
   67 |         a,b,c;cin>>a>>b>>c;
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 9 ms 25176 KB Output is correct
2 Correct 8 ms 25180 KB Output is correct
3 Correct 9 ms 25284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 25176 KB Output is correct
2 Correct 7 ms 25364 KB Output is correct
3 Correct 8 ms 25412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 335 ms 31688 KB Output is correct
2 Correct 391 ms 34544 KB Output is correct
3 Correct 387 ms 33896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 403 ms 32964 KB Output is correct
2 Correct 367 ms 32916 KB Output is correct
3 Correct 397 ms 34732 KB Output is correct
4 Correct 88 ms 31608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 161 ms 31940 KB Output is correct
2 Correct 210 ms 34764 KB Output is correct
3 Correct 190 ms 27088 KB Output is correct
4 Correct 368 ms 33992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 359 ms 31040 KB Output is correct
2 Correct 317 ms 32644 KB Output is correct
3 Correct 345 ms 31360 KB Output is correct
4 Correct 379 ms 35976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 2805 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3351 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -