Submission #1291455

#TimeUsernameProblemLanguageResultExecution timeMemory
1291455IcelastLottery (CEOI18_lot)C++20
100 / 100
883 ms8612 KiB
#include <iostream> #include <bits/stdc++.h> #define ll long long using namespace std; const ll maxn = 2*1e5+5, INF = 4e18+9; void solve(){ int n, L; cin >> n >> L; vector<int> a(n*2+1, -1); for(int i = 1; i <= n; i++){ cin >> a[i+n]; } int Q; cin >> Q; vector<int> q(Q+1); for(int i = 1; i <= Q; i++){ cin >> q[i]; } vector<int> f(n*2+1, 0); vector<int> pf(n+1, 0); vector<vector<int>> ans(Q+1, vector<int>(n+1, 0)); for(int s = 1; s <= n-L+1; s++){ if(s == 1){ for(int i = 1; i <= n*2-L+1; i++){ for(int j = 1; j <= L; j++){ if(a[j+n] == a[i+j-1]){ f[i]++; } } } }else{ for(int i = 1; i <= n; i++){ if(a[i+n] == a[s-1+n]){ f[i+n]--; } } for(int i = 2*n; i >= 1; i--){ f[i] = f[i-1]; } for(int i = 1; i <= n; i++){ if(a[s+L-1 + n] == a[i+n]){ f[i-L+1 + n]++; } } } for(int i = 0; i <= n; i++){ pf[i] = 0; } for(int i = 1; i <= n-L+1; i++){ int g = L - f[i+n]; pf[g]++; } for(int i = 1; i <= n; i++){ pf[i] += pf[i-1]; } for(int i = 1; i <= Q; i++){ ans[i][s] = pf[q[i]]-1; } } for(int i = 1; i <= Q; i++){ for(int j = 1; j <= n-L+1; j++){ cout << ans[i][j] << " "; } cout << "\n"; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
#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...