Submission #248773

#TimeUsernameProblemLanguageResultExecution timeMemory
248773SortingLottery (CEOI18_lot)C++14
100 / 100
1219 ms25720 KiB
#include <bits/stdc++.h> using namespace std; const short k_N = 1e4 + 3; const short k_Q = 1e3 + 3; int n, l; int a[k_N]; short cnt[k_N][k_Q]; short prefix[k_N]; pair<short, short> queries[k_Q]; short ans[k_Q][k_N]; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> l; for(int i = 0; i < n; ++i) cin >> a[i]; int q; cin >> q; for(int i = 0; i < q; ++i){ cin >> queries[i].first; queries[i].second = i; } sort(queries, queries + q); for(int d = 1; d < n - l + 1; d++){ prefix[0] = (a[0] != a[d]); for(int i = 1; i < n - d; ++i) prefix[i] = (a[i] != a[i + d]) + prefix[i - 1]; for(int i = 0; i < n - l + 1 - d; ++i){ short sum = prefix[i + l - 1]; if(i) sum -= prefix[i - 1]; int idx = lower_bound(queries, queries + q, pair<short, short>{sum, -1}) - queries; cnt[i][idx]++; cnt[i + d][idx]++; } } for(int i = 0; i < n - l + 1; ++i) for(int j = 1; j < q; ++j) cnt[i][j] += cnt[i][j - 1]; for(int i = 0; i < q; ++i) for(int j = 0; j < n - l + 1; ++j) ans[queries[i].second][j] = cnt[j][i]; for(int i = 0; i < q; ++i){ for(int j = 0; j < n - l + 1; ++j) cout << ans[i][j] << " "; cout << "\n"; } }
#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...