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 <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <utility>
#include <cmath>
#include <numeric>
#include <assert.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 10007;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int n, l, q, a[M], cnt[M][102], Q[M], qry[M], pref[M];
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> l;
for(int i = 1; i <= n; ++i) cin >> a[i];
cin >> q;
for(int i = 1; i <= q; ++i) cin >> qry[i], Q[i] = qry[i];
sort(Q + 1, Q + q + 1);
for(int j = 1; j < n; ++j){
for(int i = 1; i + j <= n; ++i) pref[i] = pref[i - 1] + (a[i] != a[i + j]);
for(int i = 1; i + j + l - 1 <= n; ++i){
int dist = pref[i + l - 1] - pref[i - 1];
++cnt[i][lower_bound(Q + 1, Q + q + 1, dist) - Q];
++cnt[i + j][lower_bound(Q + 1, Q + q + 1, dist) - Q];
}
}
for(int i = 1; i <= n - l + 1; ++i) for(int j = 1; j <= q; ++j) cnt[i][j] += cnt[i][j - 1];
for(int i = 1; i <= q; ++i){
for(int j = 1; j <= n - l + 1; ++j) cout << cnt[j][lower_bound(Q + 1, Q + q + 1, qry[i]) - Q] << " ";
cout << endl;
}
return 0;
}
# | 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... |