This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5, M = 1e2 + 5;
int n, m, l, a[N], b[N], c[N], pos[N];
int pref[M][N];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> l;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
cin >> m;
for(int i = 1; i <= m; i++){
cin >> b[i];
c[i] = b[i];
}
sort(c + 1, c + m + 1);
for(int i = 1; i <= m; i++){
pos[c[i]] = i;
}
pos[n + 1] = m + 1;
for(int i = n; i >= 0; i--){
if(pos[i] == 0){
pos[i] = pos[i + 1];
}
}
for(int shift = 1; l + shift <= n; shift++){
int ans = 0;
for(int i = 1; i < l; i++){
if(a[i] != a[i + shift]){
ans += 1;
}
}
for(int i = 1; i + l - 1 + shift <= n; i++){
if(i != 1 && a[i - 1] != a[i - 1 + shift]){
ans -= 1;
}
if(a[i + l - 1] != a[i + l - 1 + shift]){
ans += 1;
}
pref[pos[ans]][i] += 1;
pref[pos[ans]][i + shift] += 1;
}
}
for(int j = 1; j <= n; j++){
for(int i = 1; i <= m; i++){
pref[i][j] += pref[i - 1][j];
}
}
for(int i = 1; i <= m; i++){
for(int j = 1; j + l - 1 <= n; j++){
cout << pref[pos[b[i]]][j] << " ";
}
cout << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |