이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl '\n'
const int MXN = 10000, MXQ = 100;
int ans[MXQ+1][MXN+1], nums[MXN+1], match[MXN+1], freq[MXN+3];
ii qr[MXQ+1];
vi pos[MXN+1];
int main() {
#ifdef shiven
freopen("test.in", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, l; cin >> n >> l;
vector<ii> val(n);
for_(i, 0, n) {
cin >> nums[i];
val[i] = {nums[i], i};
}
sort(val.begin(), val.end());
int pt = -1;
for_(i, 0, n) {
if (i > 0 and val[i].first == val[i-1].first) nums[val[i].second] = pt;
else nums[val[i].second] = ++pt;
}
for_(i, 0, n) pos[nums[i]].push_back(i);
int q; cin >> q;
for_(i, 0, q) {
cin >> qr[i].first;
qr[i].second = i;
}
sort(qr, qr+q);
for_(i, 0, n-l+1) {
memset(match, 0, sizeof(match)); memset(freq, 0, sizeof(freq));
for_(j, 0, l) for (auto p: pos[nums[i+j]]) if (p >= j and p != i+j) match[p-j] += 1;
for_(j, 0, n-l+1) if (i != j) {
int pt = lower_bound(qr, qr+q, (ii) {l-match[j], -1})-qr;
if (pt != q) ans[pt][i] += 1;
}
}
for_(qq, 1, q) for_(i, 0, n-l+1) ans[qr[qq].second][i] += ans[qr[qq-1].second][i];
for_(i, 0, q) {
for_(j, 0, n-l+1) cout << ans[i][j] << " ";
cout << endl;
}
cout << endl;
return 0;
}
# | 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... |