#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;
vector<pii> sorted;
for(int i = 1; i <= q; i++) {
cin >> qry[i];
conv[qry[i]] = qry[i];
sorted.pb(mp(qry[i], i));
}
sort(sorted.begin(), sorted.end());
for(int i = n - 1; i >= 0; i--) {
if(conv[i] == 0) {
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 < q; j++) {
if(sorted[j].fi != sorted[j - 1].fi) {
ans[i][sorted[j].fi] += ans[i][sorted[j - 1].fi];
}
}
}
for(int i = 1; i <= q; i++) {
for(int j = 1; j <= n - l + 1; j++) {
cout << ans[j][qry[i]] << " ";
}
cout << "\n";
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
331 ms |
4392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
331 ms |
4392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |