Submission #541584

#TimeUsernameProblemLanguageResultExecution timeMemory
541584UncoolAnonLottery (CEOI18_lot)C++14
0 / 100
3 ms596 KiB
#include <bits/stdc++.h> using namespace std; void print(vector<int> a){ for(int x:a) cout << x << " "; cout<<endl ; } int main(){ #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif ios_base::sync_with_stdio(0); cin.tie(nullptr); int n,l,q; cin>>n>>l; vector<int> a(n); for(int&x:a) cin>>x; cin>>q; vector<vector<int>> answer(q,vector<int>(n-l+1)); vector<int> m(q); for(int&x:m) cin>>x; vector<int> dif(n-l+1); for(int i=0;i+l-1<n;i++){ if(i==0){ for(int j=0;j+l-1<n;j++){ int d=0; for(int k=j;k<j+l;k++) d+=(a[k]!=a[i+k-j]); dif[j]=d; } } else{ for(int j=n-1;j>0;j--){ if(j+l-1<n){ dif[j]=dif[j-1]-(a[j-1]!=a[i-1]); dif[j]+=(a[j+l-1]!=a[i+l-1]); } } dif[0]=0; for(int j=0;j<l;j++) dif[0]+=(a[i+j]!=a[j]); } //cout << i << " :" ; print(dif); vector<int> prefix(n+1); for(int&x:dif) prefix[x]++; for(int i=1;i<=n;i++) prefix[i]+=prefix[i-1]; for(int query=0;query<q;query++) answer[query][i]=prefix[m[query]]-1; } for(auto x:answer){ for(int y:x) cout<<y<<" "; cout<<'\n'; } return 0; }

Compilation message (stderr)

lot.cpp: In function 'int main()':
lot.cpp:9:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |   freopen("in.txt","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~
lot.cpp:10:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |   freopen("out.txt","w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...