Submission #522302

#TimeUsernameProblemLanguageResultExecution timeMemory
522302LoboLottery (CEOI18_lot)C++17
100 / 100
984 ms8416 KiB
#include<bits/stdc++.h> using namespace std; const long long inf = (long long) 1e18 + 10; const int inf1 = (int) 1e9 + 10; // #define int long long #define dbl long double #define endl '\n' #define sc second #define fr first #define mp make_pair #define pb push_back #define all(x) x.begin(), x.end() #define maxn 10100 int n, l, a[maxn], ans1[maxn], ans[maxn], ant[maxn], qr[110], qtd[maxn], ansq[110][maxn]; void solve() { cin >> n >> l; for(int i = 1; i <= n; i++) { cin >> a[i]; } int q; cin >> q; for(int i = 1; i <= q; i++) { cin >> qr[i]; } for(int i = 1; i <= n-l+1; i++) { ans1[i] = l; for(int j = 0; j < l; j++) { if(a[1+j] == a[i+j]) { ans1[i]--; } } qtd[ans1[i]]++; } for(int j = 1; j <= l; j++) { qtd[j]+= qtd[j-1]; } for(int j = 1; j <= q; j++) { ansq[j][1] = qtd[qr[j]]; } for(int i = 1; i <= n-l+1; i++) { ant[i] = ans1[i]; } for(int i = 2; i <= n-l+1; i++) { ans[1] = ans1[i]; for(int j = 0; j <= l; j++) { qtd[j] = 0; } qtd[ans[1]]++; for(int j = 2; j <= n-l+1; j++) { ans[j] = ant[j-1]; if(a[j-1] == a[i-1]) ans[j]++; if(a[j+l-1] == a[i+l-1]) ans[j]--; qtd[ans[j]]++; } for(int j = 1; j <= l; j++) { qtd[j]+= qtd[j-1]; } for(int j = 1; j <= q; j++) { ansq[j][i] = qtd[qr[j]]; } for(int j = 1; j <= n-l+1; j++) { ant[j] = ans[j]; } } for(int i = 1; i <= q; i++) { for(int j = 1; j <= n-l+1; j++) { cout << ansq[i][j]-1 << " "; } cout << endl; } } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); // freopen("in.in", "r", stdin); //freopen("out.out", "w", stdout); int tt = 1; // cin >> tt; while(tt--) 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...