Submission #503924

#TimeUsernameProblemLanguageResultExecution timeMemory
503924krit3379Lottery (CEOI18_lot)C++14
0 / 100
426 ms4416 KiB
#include<bits/stdc++.h> using namespace std; #define N 10005 int a[N],ans[105][N],tr[N],tq[N],que[N]; int main(){ int n,m,l,q,i,j,k,cnt,x,now; scanf("%d %d",&n,&l); for(i=1;i<=n;i++)scanf("%d",&a[i]); scanf("%d",&q); for(i=1;i<=q;i++){ scanf("%d",&que[i]); tq[i]=que[i]; } sort(tq+1,tq+q+1); tq[q+1]=2e9; now=1; for(i=0;i<=n;i++){ while(i>tq[now])now++; tr[i]=now; } m=n-l+1; for(k=1;k<m;k++){ cnt=0; for(i=1;i<=l;i++)cnt+=(a[i]!=a[i+k]); i=1; ans[tr[cnt]][i]++; ans[tr[cnt]][i+k]++; for(i=2;i+k+l-1<=n;i++){ cnt+=(a[i+l-1]!=a[i+k+l-1])-(a[i-1]!=a[i+k-1]); ans[tr[cnt]][i]++; ans[tr[cnt]][i+k]++; } } for(i=1;i<=m;i++)for(j=1;j<=105;j++)ans[j][i]+=ans[j-1][i]; for(i=1;i<=q;i++){ for(j=1;j<=m;j++)printf("%d ",ans[que[i]][j]); printf("\n"); } return 0; }

Compilation message (stderr)

lot.cpp: In function 'int main()':
lot.cpp:8:27: warning: unused variable 'x' [-Wunused-variable]
    8 |     int n,m,l,q,i,j,k,cnt,x,now;
      |                           ^
lot.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d %d",&n,&l);
      |     ~~~~~^~~~~~~~~~~~~~~
lot.cpp:10:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     for(i=1;i<=n;i++)scanf("%d",&a[i]);
      |                      ~~~~~^~~~~~~~~~~~
lot.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
lot.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         scanf("%d",&que[i]);
      |         ~~~~~^~~~~~~~~~~~~~
lot.cpp:36:50: warning: iteration 104 invokes undefined behavior [-Waggressive-loop-optimizations]
   36 |     for(i=1;i<=m;i++)for(j=1;j<=105;j++)ans[j][i]+=ans[j-1][i];
      |                                         ~~~~~~~~~^~~~~~~~~~~~~
lot.cpp:36:31: note: within this loop
   36 |     for(i=1;i<=m;i++)for(j=1;j<=105;j++)ans[j][i]+=ans[j-1][i];
      |                              ~^~~~~
#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...