Submission #202982

#TimeUsernameProblemLanguageResultExecution timeMemory
202982MKopchevMeteors (POI11_met)C++14
100 / 100
1521 ms39720 KiB
#include<bits/stdc++.h> using namespace std; const int nmax=3e5+42; int states; int n,inp[nmax]; vector<int> seen[nmax]; int want[nmax]; int samples; struct sample { int l,r,add; }; sample all[nmax]; int output[nmax]; long long fenwick[nmax]; void update(int pos,int add) { while(pos<=n) { fenwick[pos]+=add; pos=pos+(pos&(-pos)); } } void on(int l,int r,int add) { update(l,add); update(r+1,-add); } void note(int id,int mult) { int add=mult*all[id].add; if(all[id].l<=all[id].r)on(all[id].l,all[id].r,add); else {on(1,all[id].r,add);on(all[id].l,n,add);} } long long query(int pos) { long long ret=0; while(pos) { ret=ret+fenwick[pos]; pos=pos-(pos&(-pos)); } return ret; } bool proper(int id) { long long now=0; for(auto k:seen[id]) { now=now+query(k); if(now>=want[id])return 1; } return 0; } void solve(vector<int> active,int l,int r) { if(l>r)return; //everything in [1, l-1] is added /* cout<<l<<" "<<r<<" "<<(l+r)/2<<endl; cout<<"query: "; for(int i=1;i<=n;i++) cout<<query(i)<<" ";cout<<endl; */ int av=(l+r)/2; for(int i=l;i<=av;i++) note(i,1); vector<int> satisfied={},unsatisfied={}; for(auto k:active) { if(proper(k)){satisfied.push_back(k);output[k]=av;} else unsatisfied.push_back(k); } solve(unsatisfied,av+1,r); for(int i=l;i<=av;i++) note(i,-1); solve(satisfied,l,av-1); } int main() { scanf("%i%i",&states,&n); for(int i=1;i<=n;i++) { scanf("%i",&inp[i]); seen[inp[i]].push_back(i); } for(int i=1;i<=states;i++)scanf("%i",&want[i]); scanf("%i",&samples); for(int i=1;i<=samples;i++) scanf("%i%i%i",&all[i].l,&all[i].r,&all[i].add); for(int i=1;i<=states;i++)output[i]=samples+1; vector<int> active={}; for(int i=1;i<=states;i++)active.push_back(i); solve(active,1,samples); for(int i=1;i<=states;i++) if(output[i]>samples)printf("NIE\n"); else printf("%i\n",output[i]); return 0; }

Compilation message (stderr)

met.cpp: In function 'int main()':
met.cpp:89:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i%i",&states,&n);
     ~~~~~^~~~~~~~~~~~~~~~~~~
met.cpp:92:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&inp[i]);
         ~~~~~^~~~~~~~~~~~~~
met.cpp:96:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=states;i++)scanf("%i",&want[i]);
                               ~~~~~^~~~~~~~~~~~~~~
met.cpp:98:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i",&samples);
     ~~~~~^~~~~~~~~~~~~~~
met.cpp:100:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i%i%i",&all[i].l,&all[i].r,&all[i].add);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...