#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 10000;
const int MAX_Q = 100;
int v[MAX_N], ind[MAX_N + 1], diag[MAX_N + 1], m[MAX_Q + 1], p[MAX_Q + 1];
int good[MAX_N][MAX_Q];
int main() {
int n, k;
cin >> n >> k;
for ( int i = 0; i < n; i++ )
cin >> v[i];
int q;
cin >> q;
for ( int i = 1; i <= q; i++ ) {
cin >> m[i];
ind[m[i]] = i;
}
for ( int i = n - 1; i >= 0; i-- ) {
if ( ind[i] == 0 )
ind[i] = ind[i + 1];
}
for ( int d = 1; d < n; d++ ) {
for ( int i = 0; i < n; i++ )
diag[i] = 0;
for ( int i = 0; i < n - d; i++ ) {
int j = i + d;
if ( v[i] == v[j] )
continue;
int l = min( k, i + 1 );
diag[i - l + 1]++;
diag[i + 1]--;
}
for ( int i = 1; i < n; i++ )
diag[i] += diag[i - 1];
for ( int i = 0; i < n - d; i++ ) {
int j = i + d;
if ( i <= n - k && j <= n - k ) {
good[i][ind[diag[i]]]++;
good[j][ind[diag[i]]]++;
}
}
}
for ( int i = 1; i <= q; i++ )
p[i] = i;
sort( p + 1, p + 1 + q, []( int i, int j ) {
if ( m[i] == m[j] )
return i > j;
return m[i] < m[j];
} );
for ( int i = 0; i < n; i++ ) {
for ( int j = 2; j <= q; j++ )
good[i][p[j]] += good[i][p[j - 1]];
}
for ( int i = 1; i <= q; i++ ) {
for ( int j = 0; j <= n - k; j++ )
cout << good[j][i] << " ";
cout << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
21 ms |
2808 KB |
Output is correct |
14 |
Correct |
22 ms |
2652 KB |
Output is correct |
15 |
Correct |
18 ms |
2652 KB |
Output is correct |
16 |
Correct |
19 ms |
2652 KB |
Output is correct |
17 |
Correct |
23 ms |
2652 KB |
Output is correct |
18 |
Correct |
19 ms |
2716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
656 ms |
4460 KB |
Output is correct |
2 |
Correct |
633 ms |
4456 KB |
Output is correct |
3 |
Correct |
486 ms |
4460 KB |
Output is correct |
4 |
Correct |
479 ms |
4460 KB |
Output is correct |
5 |
Correct |
370 ms |
2864 KB |
Output is correct |
6 |
Correct |
458 ms |
4268 KB |
Output is correct |
7 |
Correct |
338 ms |
2864 KB |
Output is correct |
8 |
Correct |
356 ms |
3368 KB |
Output is correct |
9 |
Correct |
471 ms |
4408 KB |
Output is correct |
10 |
Correct |
464 ms |
4460 KB |
Output is correct |
11 |
Correct |
34 ms |
2648 KB |
Output is correct |
12 |
Correct |
348 ms |
3344 KB |
Output is correct |
13 |
Correct |
393 ms |
2940 KB |
Output is correct |
14 |
Correct |
378 ms |
2936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
656 ms |
4460 KB |
Output is correct |
2 |
Correct |
633 ms |
4456 KB |
Output is correct |
3 |
Correct |
486 ms |
4460 KB |
Output is correct |
4 |
Correct |
479 ms |
4460 KB |
Output is correct |
5 |
Correct |
370 ms |
2864 KB |
Output is correct |
6 |
Correct |
458 ms |
4268 KB |
Output is correct |
7 |
Correct |
338 ms |
2864 KB |
Output is correct |
8 |
Correct |
356 ms |
3368 KB |
Output is correct |
9 |
Correct |
471 ms |
4408 KB |
Output is correct |
10 |
Correct |
464 ms |
4460 KB |
Output is correct |
11 |
Correct |
34 ms |
2648 KB |
Output is correct |
12 |
Correct |
348 ms |
3344 KB |
Output is correct |
13 |
Correct |
393 ms |
2940 KB |
Output is correct |
14 |
Correct |
378 ms |
2936 KB |
Output is correct |
15 |
Correct |
492 ms |
4336 KB |
Output is correct |
16 |
Correct |
426 ms |
4156 KB |
Output is correct |
17 |
Correct |
472 ms |
4696 KB |
Output is correct |
18 |
Correct |
463 ms |
4496 KB |
Output is correct |
19 |
Correct |
462 ms |
4492 KB |
Output is correct |
20 |
Correct |
476 ms |
4504 KB |
Output is correct |
21 |
Correct |
476 ms |
4504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
21 ms |
2808 KB |
Output is correct |
14 |
Correct |
22 ms |
2652 KB |
Output is correct |
15 |
Correct |
18 ms |
2652 KB |
Output is correct |
16 |
Correct |
19 ms |
2652 KB |
Output is correct |
17 |
Correct |
23 ms |
2652 KB |
Output is correct |
18 |
Correct |
19 ms |
2716 KB |
Output is correct |
19 |
Correct |
656 ms |
4460 KB |
Output is correct |
20 |
Correct |
633 ms |
4456 KB |
Output is correct |
21 |
Correct |
486 ms |
4460 KB |
Output is correct |
22 |
Correct |
479 ms |
4460 KB |
Output is correct |
23 |
Correct |
370 ms |
2864 KB |
Output is correct |
24 |
Correct |
458 ms |
4268 KB |
Output is correct |
25 |
Correct |
338 ms |
2864 KB |
Output is correct |
26 |
Correct |
356 ms |
3368 KB |
Output is correct |
27 |
Correct |
471 ms |
4408 KB |
Output is correct |
28 |
Correct |
464 ms |
4460 KB |
Output is correct |
29 |
Correct |
34 ms |
2648 KB |
Output is correct |
30 |
Correct |
348 ms |
3344 KB |
Output is correct |
31 |
Correct |
393 ms |
2940 KB |
Output is correct |
32 |
Correct |
378 ms |
2936 KB |
Output is correct |
33 |
Correct |
492 ms |
4336 KB |
Output is correct |
34 |
Correct |
426 ms |
4156 KB |
Output is correct |
35 |
Correct |
472 ms |
4696 KB |
Output is correct |
36 |
Correct |
463 ms |
4496 KB |
Output is correct |
37 |
Correct |
462 ms |
4492 KB |
Output is correct |
38 |
Correct |
476 ms |
4504 KB |
Output is correct |
39 |
Correct |
476 ms |
4504 KB |
Output is correct |
40 |
Correct |
672 ms |
5196 KB |
Output is correct |
41 |
Correct |
363 ms |
4396 KB |
Output is correct |
42 |
Correct |
473 ms |
5212 KB |
Output is correct |
43 |
Correct |
448 ms |
4876 KB |
Output is correct |
44 |
Correct |
470 ms |
4892 KB |
Output is correct |
45 |
Correct |
725 ms |
8264 KB |
Output is correct |
46 |
Incorrect |
377 ms |
4912 KB |
Output isn't correct |
47 |
Halted |
0 ms |
0 KB |
- |