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;
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define eb emplace_back
#define em emplace
#define pre(a) cout<<fixed; cout.precision(a)
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INF = 1e18;
const int inf = 1e9;
int n, l, q;
int a[10010];
int k[110];
int g[10010];
int ans[111][10010];
int main() {
fast;
cin >> n >> l;
for(int i=1; i<=n; i++) {
cin >> a[i];
}
cin >> q;
for(int i=1; i<=q; i++) {
cin >> k[i];
g[k[i]+1] = 1;
}
for(int i=1; i<=n; i++) {
g[i] += g[i-1];
}
for(int i=1; i+l<=n; i++) {
int cnt = 0;
for(int j=1; j<=l; j++) {
cnt += a[j] != a[j+i];
}
ans[g[cnt]][1]++;
ans[g[cnt]][i+1]++;
for(int j=1; j+l+i <= n; j++) {
cnt -= a[j+i] != a[j];
cnt += a[j+l+i] != a[j+l];
ans[g[cnt]][j+1]++;
ans[g[cnt]][j+i+1]++;
}
}
for(int i=1; i<q; i++) {
for(int j=1; j<=n-l+1; j++) {
ans[i][j] += ans[i-1][j];
}
}
for(int i=1; i<=q; i++) {
if(i > 1) cout << "\n";
for(int j=1; j<=n-l; j++)
cout << ans[g[k[i]]][j] << " ";
cout << ans[g[k[i]]][n-l+1];
}
}
# | 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... |