#include<bits/stdc++.h>
using namespace std;
#define MAXN 10000
#define MAXQ 100
int n, l, a[MAXN + 3], q, mapToSortedUniqQuery[MAXN + 3];
int ans[MAXQ + 3][MAXN + 3];
vector<int> queries, sortedUniqQueries;
int main() {
cin >> n >> l;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
cin >> q;
for (int i = 0; i < q; i++) {
int num;
cin >> num;
queries.push_back(num);
sortedUniqQueries.push_back(num);
}
// Populate mapToSortedUniqQuery
sort(sortedUniqQueries.begin(), sortedUniqQueries.end());
sortedUniqQueries.erase(unique(sortedUniqQueries.begin(), sortedUniqQueries.end()), sortedUniqQueries.end());
for (int k = 1; k <= n; k++) {
mapToSortedUniqQuery[k] = lower_bound(sortedUniqQueries.begin(), sortedUniqQueries.end(), k) - sortedUniqQueries.begin() + 1;
}
memset(ans, 0, sizeof(ans));
for (int d = 1; (1 + d) + (l - 1) <= n; d++) {
int currentDiff = 0;
for (int i = 1; i < l; i++) {
currentDiff += (a[i] != a[i + d]);
}
int leftPtr = 1;
for (int i = l; i + d <= n; i++) {
currentDiff += (a[i] != a[i + d]);
while (i - leftPtr + 1 > l) {
currentDiff -= (a[leftPtr] != a[leftPtr + d]);
leftPtr += 1;
}
// cout << "currentDiff " << leftPtr << " " << d << " " << currentDiff << " " << mapToSortedUniqQuery[currentDiff] << endl;
ans[mapToSortedUniqQuery[currentDiff]][leftPtr] += 1;
ans[mapToSortedUniqQuery[currentDiff]][leftPtr + d] += 1;
}
}
// Apply the prefix sum
for (int idx = 1; idx <= n - l + 1; idx++) {
for (int qIndex = 1; qIndex <= sortedUniqQueries.size(); qIndex++) {
ans[qIndex][idx] += ans[qIndex - 1][idx];
}
}
for (int i = 0; i < q; i++) {
int queryIndex = mapToSortedUniqQuery[queries[i]];
for (int j = 1; j <= n - l + 1; j++) {
if (j > 1) {
cout << " ";
}
cout << ans[queryIndex][j];
}
cout << endl;
}
}
Compilation message
lot.cpp: In function 'int main()':
lot.cpp:57:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int qIndex = 1; qIndex <= sortedUniqQueries.size(); qIndex++) {
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4308 KB |
Output is correct |
2 |
Correct |
3 ms |
4264 KB |
Output is correct |
3 |
Correct |
2 ms |
4308 KB |
Output is correct |
4 |
Correct |
2 ms |
4276 KB |
Output is correct |
5 |
Correct |
2 ms |
4280 KB |
Output is correct |
6 |
Correct |
3 ms |
4276 KB |
Output is correct |
7 |
Correct |
2 ms |
4308 KB |
Output is correct |
8 |
Correct |
2 ms |
4276 KB |
Output is correct |
9 |
Correct |
3 ms |
4308 KB |
Output is correct |
10 |
Correct |
4 ms |
4336 KB |
Output is correct |
11 |
Correct |
4 ms |
4276 KB |
Output is correct |
12 |
Correct |
3 ms |
4308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4308 KB |
Output is correct |
2 |
Correct |
3 ms |
4264 KB |
Output is correct |
3 |
Correct |
2 ms |
4308 KB |
Output is correct |
4 |
Correct |
2 ms |
4276 KB |
Output is correct |
5 |
Correct |
2 ms |
4280 KB |
Output is correct |
6 |
Correct |
3 ms |
4276 KB |
Output is correct |
7 |
Correct |
2 ms |
4308 KB |
Output is correct |
8 |
Correct |
2 ms |
4276 KB |
Output is correct |
9 |
Correct |
3 ms |
4308 KB |
Output is correct |
10 |
Correct |
4 ms |
4336 KB |
Output is correct |
11 |
Correct |
4 ms |
4276 KB |
Output is correct |
12 |
Correct |
3 ms |
4308 KB |
Output is correct |
13 |
Correct |
19 ms |
4356 KB |
Output is correct |
14 |
Correct |
13 ms |
4416 KB |
Output is correct |
15 |
Correct |
12 ms |
4308 KB |
Output is correct |
16 |
Correct |
19 ms |
4436 KB |
Output is correct |
17 |
Correct |
17 ms |
4412 KB |
Output is correct |
18 |
Correct |
18 ms |
4436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
406 ms |
4420 KB |
Output is correct |
2 |
Correct |
404 ms |
4408 KB |
Output is correct |
3 |
Correct |
400 ms |
4408 KB |
Output is correct |
4 |
Correct |
403 ms |
4484 KB |
Output is correct |
5 |
Correct |
121 ms |
4488 KB |
Output is correct |
6 |
Correct |
351 ms |
4488 KB |
Output is correct |
7 |
Correct |
122 ms |
4492 KB |
Output is correct |
8 |
Correct |
210 ms |
4488 KB |
Output is correct |
9 |
Correct |
382 ms |
4556 KB |
Output is correct |
10 |
Correct |
377 ms |
4480 KB |
Output is correct |
11 |
Correct |
20 ms |
4308 KB |
Output is correct |
12 |
Correct |
215 ms |
4472 KB |
Output is correct |
13 |
Correct |
159 ms |
4488 KB |
Output is correct |
14 |
Correct |
155 ms |
4488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
406 ms |
4420 KB |
Output is correct |
2 |
Correct |
404 ms |
4408 KB |
Output is correct |
3 |
Correct |
400 ms |
4408 KB |
Output is correct |
4 |
Correct |
403 ms |
4484 KB |
Output is correct |
5 |
Correct |
121 ms |
4488 KB |
Output is correct |
6 |
Correct |
351 ms |
4488 KB |
Output is correct |
7 |
Correct |
122 ms |
4492 KB |
Output is correct |
8 |
Correct |
210 ms |
4488 KB |
Output is correct |
9 |
Correct |
382 ms |
4556 KB |
Output is correct |
10 |
Correct |
377 ms |
4480 KB |
Output is correct |
11 |
Correct |
20 ms |
4308 KB |
Output is correct |
12 |
Correct |
215 ms |
4472 KB |
Output is correct |
13 |
Correct |
159 ms |
4488 KB |
Output is correct |
14 |
Correct |
155 ms |
4488 KB |
Output is correct |
15 |
Correct |
365 ms |
4408 KB |
Output is correct |
16 |
Correct |
331 ms |
4488 KB |
Output is correct |
17 |
Correct |
374 ms |
4484 KB |
Output is correct |
18 |
Correct |
394 ms |
4436 KB |
Output is correct |
19 |
Correct |
390 ms |
4500 KB |
Output is correct |
20 |
Correct |
388 ms |
4484 KB |
Output is correct |
21 |
Correct |
390 ms |
4500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4308 KB |
Output is correct |
2 |
Correct |
3 ms |
4264 KB |
Output is correct |
3 |
Correct |
2 ms |
4308 KB |
Output is correct |
4 |
Correct |
2 ms |
4276 KB |
Output is correct |
5 |
Correct |
2 ms |
4280 KB |
Output is correct |
6 |
Correct |
3 ms |
4276 KB |
Output is correct |
7 |
Correct |
2 ms |
4308 KB |
Output is correct |
8 |
Correct |
2 ms |
4276 KB |
Output is correct |
9 |
Correct |
3 ms |
4308 KB |
Output is correct |
10 |
Correct |
4 ms |
4336 KB |
Output is correct |
11 |
Correct |
4 ms |
4276 KB |
Output is correct |
12 |
Correct |
3 ms |
4308 KB |
Output is correct |
13 |
Correct |
19 ms |
4356 KB |
Output is correct |
14 |
Correct |
13 ms |
4416 KB |
Output is correct |
15 |
Correct |
12 ms |
4308 KB |
Output is correct |
16 |
Correct |
19 ms |
4436 KB |
Output is correct |
17 |
Correct |
17 ms |
4412 KB |
Output is correct |
18 |
Correct |
18 ms |
4436 KB |
Output is correct |
19 |
Correct |
406 ms |
4420 KB |
Output is correct |
20 |
Correct |
404 ms |
4408 KB |
Output is correct |
21 |
Correct |
400 ms |
4408 KB |
Output is correct |
22 |
Correct |
403 ms |
4484 KB |
Output is correct |
23 |
Correct |
121 ms |
4488 KB |
Output is correct |
24 |
Correct |
351 ms |
4488 KB |
Output is correct |
25 |
Correct |
122 ms |
4492 KB |
Output is correct |
26 |
Correct |
210 ms |
4488 KB |
Output is correct |
27 |
Correct |
382 ms |
4556 KB |
Output is correct |
28 |
Correct |
377 ms |
4480 KB |
Output is correct |
29 |
Correct |
20 ms |
4308 KB |
Output is correct |
30 |
Correct |
215 ms |
4472 KB |
Output is correct |
31 |
Correct |
159 ms |
4488 KB |
Output is correct |
32 |
Correct |
155 ms |
4488 KB |
Output is correct |
33 |
Correct |
365 ms |
4408 KB |
Output is correct |
34 |
Correct |
331 ms |
4488 KB |
Output is correct |
35 |
Correct |
374 ms |
4484 KB |
Output is correct |
36 |
Correct |
394 ms |
4436 KB |
Output is correct |
37 |
Correct |
390 ms |
4500 KB |
Output is correct |
38 |
Correct |
388 ms |
4484 KB |
Output is correct |
39 |
Correct |
390 ms |
4500 KB |
Output is correct |
40 |
Correct |
415 ms |
5172 KB |
Output is correct |
41 |
Correct |
17 ms |
4564 KB |
Output is correct |
42 |
Correct |
407 ms |
5192 KB |
Output is correct |
43 |
Correct |
378 ms |
4868 KB |
Output is correct |
44 |
Correct |
462 ms |
5068 KB |
Output is correct |
45 |
Correct |
491 ms |
8252 KB |
Output is correct |
46 |
Correct |
24 ms |
4796 KB |
Output is correct |
47 |
Correct |
450 ms |
8392 KB |
Output is correct |
48 |
Correct |
436 ms |
6672 KB |
Output is correct |
49 |
Correct |
466 ms |
7244 KB |
Output is correct |