Submission #482571

#TimeUsernameProblemLanguageResultExecution timeMemory
482571HazemLottery (CEOI18_lot)C++14
0 / 100
205 ms65540 KiB
#include <bits/stdc++.h> #define LL long long using namespace std; const int N = 1e4+1; int a[N],val[N][N]; map<int,int>mp; set<int>st; vector<int>vals[N]; int main(){ int n,l; scanf("%d%d",&n,&l); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); st.insert(a[i]); } int cnt = 1; for(auto x:st) mp[x] = cnt++; for(int i=1;i<=n;i++) a[i] = mp[a[i]]; for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++){ if(a[i]!=a[j])continue; int i1 = max(1,i-l+1); int j1 = j-(i-i1); if(j1>n-l+1)continue; vals[j1-i1].push_back(i+1); // val[i1][j1]++; // val[i+1][j+1]--; } // for(int i=1;i<=n;i++) // for(int j=1;j<=n;j++) // val[i][j] += val[i-1][j-1]; for(int i=1;i<=n;i++) sort(vals[i].begin(),vals[i].end()); int q; scanf("%d",&q); while(q--){ int k; scanf("%d",&k); for(int i=1;i<=n-l+1;i++){ int ans = 0; for(int j=1;j<=n-l+1;j++){ if(i==j)continue; int d = abs(i-j); int idx = upper_bound(vals[d].begin(),vals[d].end(),min(i,j))-vals[d].begin()-1; if(l-(vals[d].size()-idx-1)<=k)ans++; } printf("%d ",ans); } puts(""); } }

Compilation message (stderr)

lot.cpp: In function 'int main()':
lot.cpp:60:44: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   60 |                 if(l-(vals[d].size()-idx-1)<=k)ans++;
      |                    ~~~~~~~~~~~~~~~~~~~~~~~~^~~
lot.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf("%d%d",&n,&l);
      |     ~~~~~^~~~~~~~~~~~~~
lot.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
lot.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
lot.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         scanf("%d",&k);
      |         ~~~~~^~~~~~~~~
#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...