#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <bitset>
#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int nmax = 15001;
int ans[nmax];
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
int l; cin >> l;
int a[n + 1];
int b[n + 1];
fill(b, b + n + 1, 0);
for(int i = 1; i <= n; i++){
cin >> a[i];
}
int q; cin >> q;
int cnt[n + 1][q];
vector <int> vec;
int k[q + 1];
for(int i = 1; i <= q; i++){
int x; cin >> x;
k[i] = x;
vec.pb(x);
}
sort(vec.begin(), vec.end());
vec.erase(unique(vec.begin(), vec.end()), vec.end());
for(int i = 1; i <= n; i++){
for(int j =0; j < q; j++)
cnt[i][j] = 0;
}
for(int d = 1; d <= n; d++){
fill(b, b + n + 1, 0);
for(int j = 1; j <= n - d; j++){
b[j] = (a[j] != a[j + d]);
b[j] += b[j - 1];
}
for(int i = 1; i <= n - l - d + 1; i++){
int val = b[i + l - 1] - b[i - 1];
int x= lower_bound(vec.begin(), vec.end(), val) - vec.begin();
cnt[i][x]++;
}
}
for(int d = 1; d <= n; d++){
fill(b, b + n + 1, 0);
for(int j = d + 1; j <= n; j++){
b[j] = (a[j] != a[j - d]);
b[j] += b[j - 1];
}
for(int i = d + 1; i <= n - l + 1; i++){
int val = b[i + l - 1] - b[i - 1];
int x= lower_bound(vec.begin(), vec.end(), val) - vec.begin();
cnt[i][x]++;
}
}
for(int j = 1; j < q; j++){
for(int i = 1; i <= n; i++)
cnt[i][j] += cnt[i][j - 1];
}
for(int j = 1; j <= q; j++){
int ind = 0;
for(int i = 0; i < q; i++)
if(k[j] == vec[i]) ind = i;
for(int i = 1; i <= n - l + 1; i++){
cout << cnt[i][ind] << ' ';
}
cout << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
671 ms |
436 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
671 ms |
436 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |