# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
807510 | Valaki2 | Lottery (CEOI18_lot) | C++14 | 446 ms | 8256 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second
const int maxn = 10000; //!!!!!
const int maxq = 100;
int n, l, q;
int v[1 + maxn];
int conv[1 + maxn];
int dp[1 + maxn];
int ans[1 + maxn][1 + maxq];
int qry[1 + maxq];
void solve() {
cin >> n >> l;
for(int i = 1; i <= n; i++) {
cin >> v[i];
}
cin >> q;
for(int i = n; i >= 0; i--) {
conv[i] = q + 1;
}
for(int i = 1; i <= q; i++) {
cin >> qry[i];
conv[qry[i]] = i;
}
vector<pii> sorted;
for(int i = n; i >= 0; i--) {
if(conv[i] != q + 1) {
sorted.pb(mp(i, conv[i]));
}
}
sort(sorted.begin(), sorted.end());
for(int i = n - 1; i >= 0; i--) {
if(conv[i] == q + 1) {
conv[i] = conv[i + 1];
}
}
for(int offset = 1; offset <= n - l; offset++) {
for(int i = 1; i <= offset; i++) {
dp[i] = 0;
}
for(int i = 1 + offset; i <= n; i++) {
dp[i] = dp[i - 1];
if(v[i] != v[i - offset]) {
dp[i]++;
}
if(i - l + 1 - offset >= 1) {
#define a (i - l + 1)
#define b (i - l + 1 - offset)
#define dist (dp[i] - dp[i - l])
ans[a][conv[dist]]++;
ans[b][conv[dist]]++;
}
}
}
for(int i = 1; i <= n - l + 1; i++) {
for(int j = 1; j < sorted.size(); j++) {
if(sorted[j].fi != sorted[j - 1].fi) {
ans[i][sorted[j].se] += ans[i][sorted[j - 1].se];
}
}
}
for(int i = 1; i <= q; i++) {
for(int j = 1; j <= n - l + 1; j++) {
cout << ans[j][conv[qry[i]]] << " ";
}
cout << "\n";
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |