Submission #863286

#TimeUsernameProblemLanguageResultExecution timeMemory
863286ibm2006Meteors (POI11_met)C++17
0 / 100
26 ms65536 KiB
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef __int128 lll; ll n,e,i,j,k,x,z,w,l,r,m,q,lazy[1100000],a[1100000],le[1100000],ri[1100000],s,ans[1100000],b[1100000],cc[1100000],ans2[1100000]; lll seg[1100000],y; vector<ll> v[1100000],u[1100000]; pair<ll,ll> p[1100000],pp[1100000]; pair<pair<ll,ll>,ll> upd[1100000]; void h(ll x,ll y,ll z) { if(lazy[z]==0) return; if(z>=524288) { seg[z]+=lazy[z]; lazy[z]=0; return; } seg[z]+=(y-x+1)*lazy[z]; lazy[z*2]+=lazy[z]; lazy[z*2+1]+=lazy[z]; lazy[z]=0; return; } void Clear() { ll i; for(i=0;i<1100000;i++) { seg[i]=0; lazy[i]=0; } } void f(ll x,ll y,ll z,ll w) { h(x,y,z); if(l>y||x>r) return; if(l<=x&&y<=r) { lazy[z]+=w; h(x,y,z); return; } f(x,(x+y)/2,z*2,w); f((x+y)/2+1,y,z*2+1,w); seg[z]=seg[z*2]+seg[z*2+1]; } ll g(ll x,ll y,ll z) { h(x,y,z); if(l>y||x>r) return 0; if(l<=x&&y<=r) { return seg[z]; } return g(x,(x+y)/2,z*2)+g((x+y)/2+1,y,z*2+1); } void timeout() { ll i; while(1) { i=129891028%123912; } } int main() { srand(time(NULL)); scanf("%lld %lld",&n,&m); //scanf("%lld",&q); //while(1) { for(i=1;i<=300000;i++) { v[i].clear(); u[i].clear(); } Clear(); for(i=1;i<=m;i++) { scanf("%lld",&x); //x=rand()%n+1; //printf("%lld ",x); cc[i]=x; v[x].push_back(i); } //printf("\n"); for(i=1;i<=n;i++) { scanf("%lld",&a[i]); //a[i]=rand()+1; //printf("%lld ",a[i]); } scanf("%lld",&q); for(i=1;i<=q;i++) { scanf("%lld %lld %lld",&x,&w,&z); //x=rand()%m+1; //w=rand()%m+1; //z=rand()%4+1; // printf("%lld %lld %lld\n",x,w,z); upd[i]={{x,w},z}; } for(i=1;i<=n;i++) { le[i]=1; ri[i]=q+1; p[i]={(le[i]+ri[i])/2,i}; if(p[i].first<=0||p[i].first>q+1) { //timeout(); } } for(e=0;e<40;e++) { //printf("!"); //for(i=1;i<=n;i++) // printf("(%lld,%lld)\n",le[i],ri[i]); Clear(); s=1; for(i=1;i<=n;i++) { if(p[i].first<=0||p[i].first>q+1) { if(e==0) assert(0); //timeout(); } } for(i=1;i<=q+1;i++) { u[i].clear(); } for(i=1;i<=n;i++) { if(p[i].first<=0||p[i].first>q+1) { if(e==0) return 0; //timeout(); } } for(i=1;i<=n;i++) { if(p[i].first<=0||p[i].first>q+1) { if(e==0) timeout(); } u[p[i].first].push_back(p[i].second); } for(i=1;i<=q+1;i++) { s+=u[i].size(); } if(s<n+1) { return 0; } s=1; for(i=1;i<=q+1;i++) { //printf("%lld\n",i); if(i<=q) {x=upd[i].first.first; y=upd[i].first.second; z=upd[i].second; if(x<=y) { l=x; r=y; f(1,524288,1,z); } else { l=x; r=m; f(1,524288,1,z); l=1; r=y; f(1,524288,1,z); } } //printf("?"); for(j=0;j<u[i].size();j++) { x=u[i][j]; y=0; for(k=0;k<v[x].size();k++) { l=v[x][k]; r=v[x][k]; y+=g(1,524288,1);} if(lll(a[x])<=y) { ri[x]=i; } else le[x]=i+1; le[x]=min(le[x],q+1); // printf("[%lld,%lld]\n",(le[x]+ri[x])/2,x); p[s]={(le[x]+ri[x])/2,x}; s++; } } if(e==0) { if(s<n+1) { return 0; for(i=1;1;i++) { x=12904127%1923081; } } } else assert(s==n+1); //swap(p,pp); } //return 0; for(i=1;i<=n;i++) { if(le[i]!=ri[i]) { return 0; for(i=1;1;i++) { x=12904127%1923081; } return 0; } ans[p[i].second]=p[i].first; } for(i=1;i<=n;i++) { if(ans[i]>=q+1) { printf("NIE\n"); } else printf("%lld\n",ans[i]); } return 0; for(i=1;i<=n;i++) { b[i]=0; ans2[i]=q+1; } for(i=1;i<=q;i++) { x=upd[i].first.first; y=upd[i].first.second; z=upd[i].second; for(j=x;j!=y;j=j%m+1) { b[cc[j]]+=z; } b[cc[y]]+=z; /*for(j=1;j<=n;j++) printf("%lld ",b[j]); printf("\n");*/ for(j=1;j<=n;j++) { if(b[j]>=a[j]) ans2[j]=min(ans2[j],i); } } x=0; for(i=1;i<=n;i++) { if(ans2[i]>=q+1) { printf("NIE\n"); } else printf("%lld\n",ans2[i]); if(ans[i]!=ans2[i]) { x=1; } } //printf("%lld\n",x); if(x==1) return 0; } }

Compilation message (stderr)

met.cpp: In function 'void timeout()':
met.cpp:63:8: warning: variable 'i' set but not used [-Wunused-but-set-variable]
   63 |     ll i;
      |        ^
met.cpp: In function 'int main()':
met.cpp:190:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  190 |             for(j=0;j<u[i].size();j++)
      |                     ~^~~~~~~~~~~~
met.cpp:194:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  194 |                 for(k=0;k<v[x].size();k++)
      |                         ~^~~~~~~~~~~~
met.cpp:203:17: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
  203 |                 else
      |                 ^~~~
met.cpp:205:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
  205 |                     le[x]=min(le[x],q+1);
      |                     ^~
met.cpp:282:9: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
  282 |         else
      |         ^~~~
met.cpp:284:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
  284 |             if(ans[i]!=ans2[i])
      |             ^~
met.cpp:72:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |     scanf("%lld %lld",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
met.cpp:85:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         scanf("%lld",&x);
      |         ~~~~~^~~~~~~~~~~
met.cpp:94:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |         scanf("%lld",&a[i]);
      |         ~~~~~^~~~~~~~~~~~~~
met.cpp:98:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |     scanf("%lld",&q);
      |     ~~~~~^~~~~~~~~~~
met.cpp:101:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |         scanf("%lld %lld %lld",&x,&w,&z);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...