Submission #875061

#TimeUsernameProblemLanguageResultExecution timeMemory
875061tvladm2009Lottery (CEOI18_lot)C++17
25 / 100
40 ms65536 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e4 + 7; const int Q = 1e2 + 7; int n, l; int a[N]; bool b[N][N]; int dist[N][N]; int sum[N]; int ans[Q][N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> l; for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { b[i][j] = (a[i] != a[j]); } } vector<pair<int, int>> queries; int q; cin >> q; for (int i = 1; i <= q; ++i) { int k; cin >> k; queries.push_back({k, i}); } for (int i = 1; i <= n - l + 1; ++i) { memset(sum, 0, sizeof(sum)); if (i == 1) { for (int j = 1; j <= n - l + 1; ++j) { for (int k = 0; k < l; ++k) { dist[i][j] += b[i + k][j + k]; } sum[dist[i][j]]++; } } else { dist[i][1] = 0; for (int j = 0; j < l; ++j) { dist[i][1] += b[i + j][1 + j]; } sum[dist[i][1]]++; for (int j = 2; j <= n - l + 1; ++j) { dist[i][j] = dist[i - 1][j - 1] - b[i - 1][j - 1] + b[i + l - 1][j + l - 1]; sum[dist[i][j]]++; } } for (int j = 1; j <= l; ++j) { sum[j] += sum[j - 1]; } for (auto it : queries) { ans[it.second][i] = sum[it.first]; } } for (int i = 1; i <= q; ++i) { for (int j = 1; j <= n - l + 1; ++j) { cout << ans[i][j] - 1 << " "; } cout << "\n"; } return 0; }
#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...