#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define pb push_back
#define sz(v) ((int)v.size())
const ll inf = 1e16;
const int N = 10000;
int n, l, q;
vector<int> nm, v, ks;
vector<array<int,100>> ans;
int j[N], lst[N], e[N], prec[N+1];
int bs(int x) {
int l, r, m;
l = 0;
r = sz(nm);
while (l < r) {
m = (l+r)/2;
if (nm[m] <= x)
l = m+1;
else
r = m;
}
return l - 1;
}
int bs2(int x) {
int l, r, m;
l = 0;
r = sz(ks);
while (l < r) {
m = (l+r)/2;
if (ks[m] <= x)
l = m+1;
else
r = m;
}
return l;
}
void _add(int x) {
if (j[x] == 0) return;
int d = x;
do {
d -= j[d];
++e[x-d];
} while (j[d]);
}
void _rem(int x) {
if (j[x] == 0) return;
int d = x;
do {
d -= j[d];
--e[x-d];
} while (j[d]);
}
void solve() {
for (int i = 0; i < n; ++i) {
j[i] = 0; lst[i] = -1; e[i] = 0;
}
for (int i = 0; i < n; ++i) {
if (lst[v[i]] != -1)
j[i] = i - lst[v[i]];
lst[v[i]] = i;
}
for (int i = 0; i < l; ++i)
_add(i);
for (int i = 1; i + l - 1 < n; ++i) {
_add(i+l-1); _rem(i-1);
for (int j = 1; j <= i; ++j) {
if (prec[e[j]]) ans[i][prec[e[j]]-1]++;
}
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> l;
v.assign(n, 0);
ans.resize(n-l+1);
for (int i = 0; i < n; ++i) cin >> v[i];
for (int i = 0; i < n - l + 1; ++i)
for (int j = 0; j < 100; ++j) ans[i][j] = 0;
nm = v; sort(nm.begin(), nm.end()); nm.erase(unique(nm.begin(), nm.end()), nm.end());
for (int i = 0; i < n; ++i) v[i] = bs(v[i]);
cin >> q;
vector<int> qq(q);
for (int i = 0; i < q; ++i)
cin>>qq[i];
for (int i = 0; i < q; ++i)
ks.pb(l - qq[i]);
sort(ks.begin(), ks.end()); ks.erase(unique(ks.begin(), ks.end()), ks.end());
for (int i = 0; i <= n; ++i)
prec[i] = bs2(i);
solve();
reverse(v.begin(), v.end());
reverse(ans.begin(), ans.end());
solve();
reverse(ans.begin(), ans.end());
for (int i = sz(ks)-1; i >= 0; --i)
for (int j = 0; j < n - l + 1; ++j)
ans[j][i] += ans[j][i+1];
for (int i = 0; i < q; ++i) {
for (int j = 0; j < n - l + 1; ++j)
cout << ans[j][bs2(l-qq[i])-1] << (j == n-l ? '\n' : ' ');
}
}
# |
Verdict |
Execution time |
Memory |
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 |
0 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 |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 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 |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
10 ms |
1108 KB |
Output is correct |
14 |
Correct |
6 ms |
980 KB |
Output is correct |
15 |
Correct |
3 ms |
852 KB |
Output is correct |
16 |
Correct |
6 ms |
1108 KB |
Output is correct |
17 |
Correct |
5 ms |
1108 KB |
Output is correct |
18 |
Correct |
5 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
398 ms |
4460 KB |
Output is correct |
2 |
Correct |
330 ms |
4480 KB |
Output is correct |
3 |
Correct |
118 ms |
4456 KB |
Output is correct |
4 |
Correct |
69 ms |
4388 KB |
Output is correct |
5 |
Correct |
166 ms |
2516 KB |
Output is correct |
6 |
Correct |
60 ms |
4200 KB |
Output is correct |
7 |
Correct |
348 ms |
2516 KB |
Output is correct |
8 |
Correct |
461 ms |
3292 KB |
Output is correct |
9 |
Correct |
90 ms |
4332 KB |
Output is correct |
10 |
Correct |
88 ms |
4404 KB |
Output is correct |
11 |
Correct |
17 ms |
1196 KB |
Output is correct |
12 |
Correct |
93 ms |
3284 KB |
Output is correct |
13 |
Correct |
75 ms |
2772 KB |
Output is correct |
14 |
Correct |
106 ms |
2772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
398 ms |
4460 KB |
Output is correct |
2 |
Correct |
330 ms |
4480 KB |
Output is correct |
3 |
Correct |
118 ms |
4456 KB |
Output is correct |
4 |
Correct |
69 ms |
4388 KB |
Output is correct |
5 |
Correct |
166 ms |
2516 KB |
Output is correct |
6 |
Correct |
60 ms |
4200 KB |
Output is correct |
7 |
Correct |
348 ms |
2516 KB |
Output is correct |
8 |
Correct |
461 ms |
3292 KB |
Output is correct |
9 |
Correct |
90 ms |
4332 KB |
Output is correct |
10 |
Correct |
88 ms |
4404 KB |
Output is correct |
11 |
Correct |
17 ms |
1196 KB |
Output is correct |
12 |
Correct |
93 ms |
3284 KB |
Output is correct |
13 |
Correct |
75 ms |
2772 KB |
Output is correct |
14 |
Correct |
106 ms |
2772 KB |
Output is correct |
15 |
Correct |
458 ms |
4332 KB |
Output is correct |
16 |
Correct |
64 ms |
4076 KB |
Output is correct |
17 |
Correct |
118 ms |
4472 KB |
Output is correct |
18 |
Correct |
65 ms |
4412 KB |
Output is correct |
19 |
Correct |
66 ms |
4416 KB |
Output is correct |
20 |
Correct |
66 ms |
4440 KB |
Output is correct |
21 |
Correct |
67 ms |
4436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 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 |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
10 ms |
1108 KB |
Output is correct |
14 |
Correct |
6 ms |
980 KB |
Output is correct |
15 |
Correct |
3 ms |
852 KB |
Output is correct |
16 |
Correct |
6 ms |
1108 KB |
Output is correct |
17 |
Correct |
5 ms |
1108 KB |
Output is correct |
18 |
Correct |
5 ms |
1108 KB |
Output is correct |
19 |
Correct |
398 ms |
4460 KB |
Output is correct |
20 |
Correct |
330 ms |
4480 KB |
Output is correct |
21 |
Correct |
118 ms |
4456 KB |
Output is correct |
22 |
Correct |
69 ms |
4388 KB |
Output is correct |
23 |
Correct |
166 ms |
2516 KB |
Output is correct |
24 |
Correct |
60 ms |
4200 KB |
Output is correct |
25 |
Correct |
348 ms |
2516 KB |
Output is correct |
26 |
Correct |
461 ms |
3292 KB |
Output is correct |
27 |
Correct |
90 ms |
4332 KB |
Output is correct |
28 |
Correct |
88 ms |
4404 KB |
Output is correct |
29 |
Correct |
17 ms |
1196 KB |
Output is correct |
30 |
Correct |
93 ms |
3284 KB |
Output is correct |
31 |
Correct |
75 ms |
2772 KB |
Output is correct |
32 |
Correct |
106 ms |
2772 KB |
Output is correct |
33 |
Correct |
458 ms |
4332 KB |
Output is correct |
34 |
Correct |
64 ms |
4076 KB |
Output is correct |
35 |
Correct |
118 ms |
4472 KB |
Output is correct |
36 |
Correct |
65 ms |
4412 KB |
Output is correct |
37 |
Correct |
66 ms |
4416 KB |
Output is correct |
38 |
Correct |
66 ms |
4440 KB |
Output is correct |
39 |
Correct |
67 ms |
4436 KB |
Output is correct |
40 |
Correct |
347 ms |
5192 KB |
Output is correct |
41 |
Correct |
27 ms |
972 KB |
Output is correct |
42 |
Correct |
121 ms |
5184 KB |
Output is correct |
43 |
Correct |
73 ms |
4688 KB |
Output is correct |
44 |
Correct |
78 ms |
4808 KB |
Output is correct |
45 |
Correct |
385 ms |
8264 KB |
Output is correct |
46 |
Correct |
33 ms |
1228 KB |
Output is correct |
47 |
Incorrect |
295 ms |
9292 KB |
Output isn't correct |
48 |
Halted |
0 ms |
0 KB |
- |