Submission #863277

#TimeUsernameProblemLanguageResultExecution timeMemory
863277ibm2006Meteors (POI11_met)C++17
0 / 100
136 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[330000],le[330000],ri[330000],s,ans[330000],b[330000],cc[330000],ans2[330000]; lll seg[1100000],y; vector<ll> v[330000],u[330000]; pair<ll,ll> p[330000],pp[330000]; pair<pair<ll,ll>,ll> upd[330000]; 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<=q+1;i++) { u[i].clear(); } for(i=1;i<=n;i++) { if(p[i].first<=0||p[i].first>q+1) { //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:170: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]
  170 |             for(j=0;j<u[i].size();j++)
      |                     ~^~~~~~~~~~~~
met.cpp:174: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]
  174 |                 for(k=0;k<v[x].size();k++)
      |                         ~^~~~~~~~~~~~
met.cpp:183:17: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
  183 |                 else
      |                 ^~~~
met.cpp:185:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
  185 |                     le[x]=min(le[x],q+1);
      |                     ^~
met.cpp:262:9: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
  262 |         else
      |         ^~~~
met.cpp:264:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
  264 |             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);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
met.cpp: In function 'void Clear()':
met.cpp:31:15: warning: iteration 1100000 invokes undefined behavior [-Waggressive-loop-optimizations]
   31 |         seg[i]=0;
      |         ~~~~~~^~
met.cpp:29:14: note: within this loop
   29 |     for(i=0;i<=1100000;i++)
      |             ~^~~~~~~~~
met.cpp:31:15: warning: 'void* __builtin_memset(void*, int, long unsigned int)' forming offset [17600000, 17600015] is out of the bounds [0, 17600000] of object 'seg' with type 'lll [1100000]' {aka '__int128 [1100000]'} [-Warray-bounds]
   31 |         seg[i]=0;
      |         ~~~~~~^~
met.cpp:6:5: note: 'seg' declared here
    6 | lll seg[1100000],y;
      |     ^~~
met.cpp:32:16: warning: 'void* __builtin_memset(void*, int, long unsigned int)' forming offset [8800000, 8800007] is out of the bounds [0, 8800000] of object 'lazy' with type 'll [1100000]' {aka 'long long int [1100000]'} [-Warray-bounds]
   32 |         lazy[i]=0;
      |         ~~~~~~~^~
met.cpp:5:28: note: 'lazy' declared here
    5 | ll n,e,i,j,k,x,z,w,l,r,m,q,lazy[1100000],a[330000],le[330000],ri[330000],s,ans[330000],b[330000],cc[330000],ans2[330000];
      |                            ^~~~
In function 'void Clear()',
    inlined from 'int main()' at met.cpp:82:14:
met.cpp:31:15: warning: 'void* __builtin_memset(void*, int, long unsigned int)' forming offset [17600000, 17600015] is out of the bounds [0, 17600000] of object 'seg' with type 'lll [1100000]' {aka '__int128 [1100000]'} [-Warray-bounds]
   31 |         seg[i]=0;
      |         ~~~~~~^~
met.cpp: In function 'int main()':
met.cpp:6:5: note: 'seg' declared here
    6 | lll seg[1100000],y;
      |     ^~~
In function 'void Clear()',
    inlined from 'int main()' at met.cpp:82:14:
met.cpp:32:16: warning: 'void* __builtin_memset(void*, int, long unsigned int)' forming offset [8800000, 8800007] is out of the bounds [0, 8800000] of object 'lazy' with type 'll [1100000]' {aka 'long long int [1100000]'} [-Warray-bounds]
   32 |         lazy[i]=0;
      |         ~~~~~~~^~
met.cpp: In function 'int main()':
met.cpp:5:28: note: 'lazy' declared here
    5 | ll n,e,i,j,k,x,z,w,l,r,m,q,lazy[1100000],a[330000],le[330000],ri[330000],s,ans[330000],b[330000],cc[330000],ans2[330000];
      |                            ^~~~
In function 'void Clear()',
    inlined from 'int main()' at met.cpp:124:14:
met.cpp:31:15: warning: 'void* __builtin_memset(void*, int, long unsigned int)' forming offset [17600000, 17600015] is out of the bounds [0, 17600000] of object 'seg' with type 'lll [1100000]' {aka '__int128 [1100000]'} [-Warray-bounds]
   31 |         seg[i]=0;
      |         ~~~~~~^~
met.cpp: In function 'int main()':
met.cpp:6:5: note: 'seg' declared here
    6 | lll seg[1100000],y;
      |     ^~~
In function 'void Clear()',
    inlined from 'int main()' at met.cpp:124:14:
met.cpp:32:16: warning: 'void* __builtin_memset(void*, int, long unsigned int)' forming offset [8800000, 8800007] is out of the bounds [0, 8800000] of object 'lazy' with type 'll [1100000]' {aka 'long long int [1100000]'} [-Warray-bounds]
   32 |         lazy[i]=0;
      |         ~~~~~~~^~
met.cpp: In function 'int main()':
met.cpp:5:28: note: 'lazy' declared here
    5 | ll n,e,i,j,k,x,z,w,l,r,m,q,lazy[1100000],a[330000],le[330000],ri[330000],s,ans[330000],b[330000],cc[330000],ans2[330000];
      |                            ^~~~
#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...