#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int)size(x))
#define all(x) begin(x), end(x)
#define trace(x) cout << #x << ": " << (x) << endl;
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }
const int N = 10000, Q = 101;
const ll infL = 3e18;
int a[N], n, l, ans[N][Q];
int count(int i, int j) {
if (i == j) return 0;
int aans = 0;
for (int id = 0; id < l; ++id) {
aans += (a[i + id] != a[j + id]);
}
return aans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> l;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int q;
cin >> q;
vector<pair<int, int>> k(q);
vector<int> ord(q);
for (int i = 0; i < q; ++i) {
cin >> k[i].first;
k[i].second = i;
}
sort(all(k));
for (int i = 0; i < q; ++i)
ord[k[i].second] = i;
k.emplace_back(N + 2, -1);
for (int i = n - l - 1; i > -1; --i) {
int ct = count(i, n - l);
int pnt = lower_bound(all(k), make_pair(ct, -1)) - begin(k);
ans[i][pnt] += 1;
ans[n - l][pnt] += 1;
for (int j = 1; j <= i; ++j) {
ct = ct + (a[i - j] != a[n - l - j]) - (a[i - j + l] != a[n - j]);
while (k[pnt].first < ct)
++pnt;
while (pnt && k[pnt - 1].first >= ct)
--pnt;
ans[i - j][pnt] += 1;
ans[n - l - j][pnt] += 1;
}
}
for (int i = 0; i <= n - l; ++i) {
for (int j = 1; j < q; ++j)
ans[i][j] += ans[i][j - 1];
}
for (int i = 0; i < q; ++i) {
for (int j = 0; j <= n - l; ++j) {
cout << ans[j][ord[i]] << " ";
}
cout << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
16 ms |
1140 KB |
Output is correct |
14 |
Correct |
9 ms |
852 KB |
Output is correct |
15 |
Correct |
6 ms |
852 KB |
Output is correct |
16 |
Correct |
10 ms |
1056 KB |
Output is correct |
17 |
Correct |
8 ms |
980 KB |
Output is correct |
18 |
Correct |
9 ms |
1128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
320 ms |
4304 KB |
Output is correct |
2 |
Correct |
258 ms |
4308 KB |
Output is correct |
3 |
Correct |
214 ms |
4308 KB |
Output is correct |
4 |
Correct |
251 ms |
4224 KB |
Output is correct |
5 |
Correct |
66 ms |
2344 KB |
Output is correct |
6 |
Correct |
198 ms |
4044 KB |
Output is correct |
7 |
Correct |
69 ms |
2348 KB |
Output is correct |
8 |
Correct |
124 ms |
3148 KB |
Output is correct |
9 |
Correct |
219 ms |
4180 KB |
Output is correct |
10 |
Correct |
208 ms |
4224 KB |
Output is correct |
11 |
Correct |
10 ms |
1108 KB |
Output is correct |
12 |
Correct |
137 ms |
3108 KB |
Output is correct |
13 |
Correct |
91 ms |
2684 KB |
Output is correct |
14 |
Correct |
87 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
320 ms |
4304 KB |
Output is correct |
2 |
Correct |
258 ms |
4308 KB |
Output is correct |
3 |
Correct |
214 ms |
4308 KB |
Output is correct |
4 |
Correct |
251 ms |
4224 KB |
Output is correct |
5 |
Correct |
66 ms |
2344 KB |
Output is correct |
6 |
Correct |
198 ms |
4044 KB |
Output is correct |
7 |
Correct |
69 ms |
2348 KB |
Output is correct |
8 |
Correct |
124 ms |
3148 KB |
Output is correct |
9 |
Correct |
219 ms |
4180 KB |
Output is correct |
10 |
Correct |
208 ms |
4224 KB |
Output is correct |
11 |
Correct |
10 ms |
1108 KB |
Output is correct |
12 |
Correct |
137 ms |
3108 KB |
Output is correct |
13 |
Correct |
91 ms |
2684 KB |
Output is correct |
14 |
Correct |
87 ms |
2688 KB |
Output is correct |
15 |
Correct |
219 ms |
4180 KB |
Output is correct |
16 |
Correct |
212 ms |
3924 KB |
Output is correct |
17 |
Correct |
249 ms |
4300 KB |
Output is correct |
18 |
Correct |
208 ms |
4260 KB |
Output is correct |
19 |
Correct |
268 ms |
4276 KB |
Output is correct |
20 |
Correct |
249 ms |
4276 KB |
Output is correct |
21 |
Correct |
238 ms |
4260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
16 ms |
1140 KB |
Output is correct |
14 |
Correct |
9 ms |
852 KB |
Output is correct |
15 |
Correct |
6 ms |
852 KB |
Output is correct |
16 |
Correct |
10 ms |
1056 KB |
Output is correct |
17 |
Correct |
8 ms |
980 KB |
Output is correct |
18 |
Correct |
9 ms |
1128 KB |
Output is correct |
19 |
Correct |
320 ms |
4304 KB |
Output is correct |
20 |
Correct |
258 ms |
4308 KB |
Output is correct |
21 |
Correct |
214 ms |
4308 KB |
Output is correct |
22 |
Correct |
251 ms |
4224 KB |
Output is correct |
23 |
Correct |
66 ms |
2344 KB |
Output is correct |
24 |
Correct |
198 ms |
4044 KB |
Output is correct |
25 |
Correct |
69 ms |
2348 KB |
Output is correct |
26 |
Correct |
124 ms |
3148 KB |
Output is correct |
27 |
Correct |
219 ms |
4180 KB |
Output is correct |
28 |
Correct |
208 ms |
4224 KB |
Output is correct |
29 |
Correct |
10 ms |
1108 KB |
Output is correct |
30 |
Correct |
137 ms |
3108 KB |
Output is correct |
31 |
Correct |
91 ms |
2684 KB |
Output is correct |
32 |
Correct |
87 ms |
2688 KB |
Output is correct |
33 |
Correct |
219 ms |
4180 KB |
Output is correct |
34 |
Correct |
212 ms |
3924 KB |
Output is correct |
35 |
Correct |
249 ms |
4300 KB |
Output is correct |
36 |
Correct |
208 ms |
4260 KB |
Output is correct |
37 |
Correct |
268 ms |
4276 KB |
Output is correct |
38 |
Correct |
249 ms |
4276 KB |
Output is correct |
39 |
Correct |
238 ms |
4260 KB |
Output is correct |
40 |
Correct |
362 ms |
5032 KB |
Output is correct |
41 |
Correct |
11 ms |
852 KB |
Output is correct |
42 |
Correct |
240 ms |
5060 KB |
Output is correct |
43 |
Correct |
221 ms |
4612 KB |
Output is correct |
44 |
Correct |
254 ms |
4736 KB |
Output is correct |
45 |
Correct |
636 ms |
8020 KB |
Output is correct |
46 |
Correct |
16 ms |
1136 KB |
Output is correct |
47 |
Correct |
286 ms |
8260 KB |
Output is correct |
48 |
Correct |
290 ms |
6284 KB |
Output is correct |
49 |
Correct |
259 ms |
6980 KB |
Output is correct |