#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n, l, a[20010], dp[110][10010], pos[10010], b[110];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin >> n >> l;
for (int i = 1; i <= n; i++){
cin >> a[i];
a[i+n] = a[i];
}
int q;
cin >> q;
for (int i = 1; i <= q; i++){
cin >> b[i];
pos[b[i]] = i;
}
for (int i = n; i >= 0; i--){
if (pos[i] == 0)
pos[i] = pos[i+1];
}
for (int sz = 1; sz <= n; sz++){
int curans = 0;
if (l+sz > n)
break;
for (int i = 1; i < l; i++){
if (a[i] != a[i+sz])
++curans;
}
for (int i = 1; i <= n; i++){
if (i+l-1+sz > n)
break;
if (i != 1 && a[i-1] != a[i+sz-1])
--curans;
if (a[i+l-1] != a[i+l-1+sz])
++curans;
//cout << sz << ' ' << i << ' ' << curans << endl;
++dp[pos[curans]][i];
++dp[pos[curans]][i+sz];
}
/*curans = 0;
for (int i = n-l+1; i <= n; i++){
if (a[i-sz] != a[i])
++curans;
}
++dp[pos[curans]][n-l+1];
++dp[pos[curans]][n-l+1-sz];
for (int i = n-1; i >= 1; i--){
if (i-l+1-sz <= 0)
break;
if (a[i+1] != a[i-sz+1])
--curans;
if (a[i-l+1-sz] != a[i-l+1])
++curans;
++dp[pos[curans]][i-l+1];
++dp[pos[curans]][i-l+1-sz];
}*/
}
for (int i = 1; i <= 100; i++){
for (int j = 1; j <= n; j++)
dp[i][j] += dp[i-1][j];
}
for (int i = 1; i <= q; i++){
for (int j = 1; j <= n-l+1; j++){
cout << dp[pos[b[i]]][j] << ' ';
}
cout << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
764 KB |
Output is correct |
2 |
Incorrect |
3 ms |
892 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
764 KB |
Output is correct |
2 |
Incorrect |
3 ms |
892 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
465 ms |
4520 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
465 ms |
4520 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
764 KB |
Output is correct |
2 |
Incorrect |
3 ms |
892 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |