#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;
#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())
struct state {
deque<int> vec, freq;
state (int n, int sz) : vec(n), freq(sz + 1) { freq[0] = n; }
void change (int pos, int val) {
if (0 <= pos && pos < vec.size())
freq[vec[pos]]--, vec[pos] += val, freq[vec[pos]]++;
}
void shift (int val) {
vec.push_front(val);
freq[val]++, freq[vec.back()]--;
vec.pop_back();
}
};
const int mn = 1e4 + 4;
vector<int> pos[mn], cmp;
int a[mn], ans[100][mn];
int calc (int u, int v, int k) {
int ans = 0;
for (int i = u, j = v, cnt = 0; cnt < k; i++, j++, cnt++)
if (a[i] == a[j]) ans++;
return ans;
}
int getID (int targ) {
return lower_bound(all(cmp), targ) - cmp.begin();
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, k; cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
cmp.push_back(a[i]);
}
sort(all(cmp)); filter(cmp);
for (int i = 0; i < n; i++) {
a[i] = getID(a[i]);
pos[a[i]].push_back(i);
}
int q; cin >> q;
vector<pii> qry(q);
for (int i = 0; i < q; i++) {
int dl; cin >> dl;
qry[i] = {dl, i};
}
sort(all(qry));
state helper(n - k + 1, k);
for (int i = 0; i < k; i++)
for (int p : pos[a[i]]) helper.change(p - i, 1);
for (int i = 0; i + k - 1 < n; i++) {
int iter = k + 1, cur = 0;
for (pii it : qry) {
int dl, id; tie(dl, id) = it;
int minSame = k - dl;
while (iter > minSame)
cur += helper.freq[--iter];
ans[id][i] = cur;
}
for (int p : pos[a[i]]) helper.change(p, -1);
if (i + k < n) {
for (int p : pos[a[i + k]]) helper.change(p - k, 1);
helper.shift(calc(0, i + 1, k));
}
}
for (int i = 0; i < q; i++) {
for (int j = 0; j + k - 1 < n; j++) cout << ans[i][j] - 1 << " ";
cout << "\n";
}
return 0;
}
Compilation message
lot.cpp: In member function 'void state::change(int, int)':
lot.cpp:18:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | if (0 <= pos && pos < vec.size())
| ~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2744 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2744 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
2652 KB |
Output is correct |
13 |
Correct |
8 ms |
604 KB |
Output is correct |
14 |
Correct |
4 ms |
2760 KB |
Output is correct |
15 |
Correct |
5 ms |
2908 KB |
Output is correct |
16 |
Correct |
4 ms |
2824 KB |
Output is correct |
17 |
Correct |
4 ms |
2904 KB |
Output is correct |
18 |
Correct |
5 ms |
2916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
544 ms |
860 KB |
Output is correct |
2 |
Correct |
506 ms |
920 KB |
Output is correct |
3 |
Correct |
116 ms |
912 KB |
Output is correct |
4 |
Correct |
12 ms |
1032 KB |
Output is correct |
5 |
Correct |
294 ms |
972 KB |
Output is correct |
6 |
Correct |
10 ms |
856 KB |
Output is correct |
7 |
Correct |
537 ms |
860 KB |
Output is correct |
8 |
Correct |
791 ms |
972 KB |
Output is correct |
9 |
Correct |
73 ms |
996 KB |
Output is correct |
10 |
Correct |
47 ms |
856 KB |
Output is correct |
11 |
Correct |
28 ms |
796 KB |
Output is correct |
12 |
Correct |
152 ms |
1052 KB |
Output is correct |
13 |
Correct |
121 ms |
860 KB |
Output is correct |
14 |
Correct |
194 ms |
1008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
544 ms |
860 KB |
Output is correct |
2 |
Correct |
506 ms |
920 KB |
Output is correct |
3 |
Correct |
116 ms |
912 KB |
Output is correct |
4 |
Correct |
12 ms |
1032 KB |
Output is correct |
5 |
Correct |
294 ms |
972 KB |
Output is correct |
6 |
Correct |
10 ms |
856 KB |
Output is correct |
7 |
Correct |
537 ms |
860 KB |
Output is correct |
8 |
Correct |
791 ms |
972 KB |
Output is correct |
9 |
Correct |
73 ms |
996 KB |
Output is correct |
10 |
Correct |
47 ms |
856 KB |
Output is correct |
11 |
Correct |
28 ms |
796 KB |
Output is correct |
12 |
Correct |
152 ms |
1052 KB |
Output is correct |
13 |
Correct |
121 ms |
860 KB |
Output is correct |
14 |
Correct |
194 ms |
1008 KB |
Output is correct |
15 |
Correct |
107 ms |
948 KB |
Output is correct |
16 |
Correct |
34 ms |
1000 KB |
Output is correct |
17 |
Correct |
77 ms |
1036 KB |
Output is correct |
18 |
Correct |
5 ms |
860 KB |
Output is correct |
19 |
Correct |
5 ms |
1056 KB |
Output is correct |
20 |
Correct |
5 ms |
860 KB |
Output is correct |
21 |
Correct |
5 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2744 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
2652 KB |
Output is correct |
13 |
Correct |
8 ms |
604 KB |
Output is correct |
14 |
Correct |
4 ms |
2760 KB |
Output is correct |
15 |
Correct |
5 ms |
2908 KB |
Output is correct |
16 |
Correct |
4 ms |
2824 KB |
Output is correct |
17 |
Correct |
4 ms |
2904 KB |
Output is correct |
18 |
Correct |
5 ms |
2916 KB |
Output is correct |
19 |
Correct |
544 ms |
860 KB |
Output is correct |
20 |
Correct |
506 ms |
920 KB |
Output is correct |
21 |
Correct |
116 ms |
912 KB |
Output is correct |
22 |
Correct |
12 ms |
1032 KB |
Output is correct |
23 |
Correct |
294 ms |
972 KB |
Output is correct |
24 |
Correct |
10 ms |
856 KB |
Output is correct |
25 |
Correct |
537 ms |
860 KB |
Output is correct |
26 |
Correct |
791 ms |
972 KB |
Output is correct |
27 |
Correct |
73 ms |
996 KB |
Output is correct |
28 |
Correct |
47 ms |
856 KB |
Output is correct |
29 |
Correct |
28 ms |
796 KB |
Output is correct |
30 |
Correct |
152 ms |
1052 KB |
Output is correct |
31 |
Correct |
121 ms |
860 KB |
Output is correct |
32 |
Correct |
194 ms |
1008 KB |
Output is correct |
33 |
Correct |
107 ms |
948 KB |
Output is correct |
34 |
Correct |
34 ms |
1000 KB |
Output is correct |
35 |
Correct |
77 ms |
1036 KB |
Output is correct |
36 |
Correct |
5 ms |
860 KB |
Output is correct |
37 |
Correct |
5 ms |
1056 KB |
Output is correct |
38 |
Correct |
5 ms |
860 KB |
Output is correct |
39 |
Correct |
5 ms |
860 KB |
Output is correct |
40 |
Correct |
563 ms |
3924 KB |
Output is correct |
41 |
Correct |
31 ms |
2904 KB |
Output is correct |
42 |
Correct |
106 ms |
3924 KB |
Output is correct |
43 |
Correct |
20 ms |
3676 KB |
Output is correct |
44 |
Correct |
20 ms |
3676 KB |
Output is correct |
45 |
Correct |
549 ms |
8532 KB |
Output is correct |
46 |
Correct |
39 ms |
3668 KB |
Output is correct |
47 |
Correct |
117 ms |
8532 KB |
Output is correct |
48 |
Correct |
54 ms |
6992 KB |
Output is correct |
49 |
Correct |
59 ms |
7620 KB |
Output is correct |