#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
const int N = 2e3 + 10;
ll hashes[10010];
ll P = 1e9 + 7, Q = 1403072387;
ll binpow(ll a, ll x) {
if (x == 0) return 1;
if (x % 2 == 0) {
ll u = binpow(a, x / 2);
return (u * u) % Q;
}
return (a * binpow(a, x - 1)) % Q;
}
int a[10010];
short dp[N][N];
vector <short> v[N];
int n, l;
int ans(int left, int right) {
return dp[left][right] - dp[left + l][right + l];
}
int main() {
cin >> n >> l;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
if (n <= 2000) {
for (int i = n; i >= 1; i--) {
for (int j = i + 1; j <= n; j++) {
dp[i][j] = dp[i + 1][j + 1] + (a[i] != a[j]);
}
}
for (int i = 1; i <= n - l + 1; i++) {
for (int j = i - 1; j >= 1; j--) {
v[i].push_back(ans(j, i));
}
for (int j = i + 1; j + l <= n + 1; j++) {
v[i].push_back(ans(i, j));
}
sort(v[i].begin(), v[i].end());
}
int q;
cin >> q;
while (q--) {
int x;
cin >> x;
for (int i = 1; i <= n - l + 1; i++) {
cout << upper_bound(v[i].begin(), v[i].end(), x) - v[i].begin() << " ";
}
cout << "\n";
}
return 0;
}
int q;
cin >> q;
int val;
cin >> val;
ll hash = 0;
map <ll, int> mp;
for (int i = 1; i <= l; i++) {
hash += binpow(P, i) * a[i];
hash %= Q;
}
hashes[1] = hash;
mp[hash]++;
for (int i = l + 1; i <= n; i++) {
ll u = (binpow(P, 1) * a[i - l]) % Q;
hash = (hash + Q - u) % Q;
hash = (hash * binpow(P, Q - 2)) % Q;
hash = (hash + binpow(P, l) * a[i]) % Q;
hashes[i - l + 1] = hash;
mp[hash]++;
}
for (int i = 1; i <= n - l + 1; i++) {
cout << mp[hashes[i]] - 1 << " ";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
2 ms |
1620 KB |
Output is correct |
9 |
Correct |
1 ms |
1620 KB |
Output is correct |
10 |
Correct |
2 ms |
1748 KB |
Output is correct |
11 |
Correct |
2 ms |
1748 KB |
Output is correct |
12 |
Correct |
2 ms |
1748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
2 ms |
1620 KB |
Output is correct |
9 |
Correct |
1 ms |
1620 KB |
Output is correct |
10 |
Correct |
2 ms |
1748 KB |
Output is correct |
11 |
Correct |
2 ms |
1748 KB |
Output is correct |
12 |
Correct |
2 ms |
1748 KB |
Output is correct |
13 |
Correct |
76 ms |
16284 KB |
Output is correct |
14 |
Correct |
33 ms |
13728 KB |
Output is correct |
15 |
Correct |
28 ms |
13552 KB |
Output is correct |
16 |
Correct |
48 ms |
15428 KB |
Output is correct |
17 |
Correct |
39 ms |
14900 KB |
Output is correct |
18 |
Correct |
39 ms |
14956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
468 KB |
Output is correct |
2 |
Correct |
8 ms |
436 KB |
Output is correct |
3 |
Correct |
8 ms |
492 KB |
Output is correct |
4 |
Correct |
10 ms |
628 KB |
Output is correct |
5 |
Correct |
8 ms |
748 KB |
Output is correct |
6 |
Correct |
11 ms |
980 KB |
Output is correct |
7 |
Correct |
8 ms |
560 KB |
Output is correct |
8 |
Correct |
8 ms |
468 KB |
Output is correct |
9 |
Correct |
10 ms |
628 KB |
Output is correct |
10 |
Correct |
9 ms |
624 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
9 ms |
880 KB |
Output is correct |
13 |
Correct |
9 ms |
872 KB |
Output is correct |
14 |
Correct |
9 ms |
872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
468 KB |
Output is correct |
2 |
Correct |
8 ms |
436 KB |
Output is correct |
3 |
Correct |
8 ms |
492 KB |
Output is correct |
4 |
Correct |
10 ms |
628 KB |
Output is correct |
5 |
Correct |
8 ms |
748 KB |
Output is correct |
6 |
Correct |
11 ms |
980 KB |
Output is correct |
7 |
Correct |
8 ms |
560 KB |
Output is correct |
8 |
Correct |
8 ms |
468 KB |
Output is correct |
9 |
Correct |
10 ms |
628 KB |
Output is correct |
10 |
Correct |
9 ms |
624 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
9 ms |
880 KB |
Output is correct |
13 |
Correct |
9 ms |
872 KB |
Output is correct |
14 |
Correct |
9 ms |
872 KB |
Output is correct |
15 |
Incorrect |
10 ms |
1108 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
2 ms |
1620 KB |
Output is correct |
9 |
Correct |
1 ms |
1620 KB |
Output is correct |
10 |
Correct |
2 ms |
1748 KB |
Output is correct |
11 |
Correct |
2 ms |
1748 KB |
Output is correct |
12 |
Correct |
2 ms |
1748 KB |
Output is correct |
13 |
Correct |
76 ms |
16284 KB |
Output is correct |
14 |
Correct |
33 ms |
13728 KB |
Output is correct |
15 |
Correct |
28 ms |
13552 KB |
Output is correct |
16 |
Correct |
48 ms |
15428 KB |
Output is correct |
17 |
Correct |
39 ms |
14900 KB |
Output is correct |
18 |
Correct |
39 ms |
14956 KB |
Output is correct |
19 |
Correct |
7 ms |
468 KB |
Output is correct |
20 |
Correct |
8 ms |
436 KB |
Output is correct |
21 |
Correct |
8 ms |
492 KB |
Output is correct |
22 |
Correct |
10 ms |
628 KB |
Output is correct |
23 |
Correct |
8 ms |
748 KB |
Output is correct |
24 |
Correct |
11 ms |
980 KB |
Output is correct |
25 |
Correct |
8 ms |
560 KB |
Output is correct |
26 |
Correct |
8 ms |
468 KB |
Output is correct |
27 |
Correct |
10 ms |
628 KB |
Output is correct |
28 |
Correct |
9 ms |
624 KB |
Output is correct |
29 |
Correct |
2 ms |
468 KB |
Output is correct |
30 |
Correct |
9 ms |
880 KB |
Output is correct |
31 |
Correct |
9 ms |
872 KB |
Output is correct |
32 |
Correct |
9 ms |
872 KB |
Output is correct |
33 |
Incorrect |
10 ms |
1108 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |