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>
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define rrep(i,a,b) for(int i=int(a);i>int(b);i--)
#define all(v) v.begin(),v.end()
#define trav(a,v) for(auto&a:v)
#define sz(a) a.size()
using namespace std;
const long long inf = 1e15;
typedef long long ll;
int main() {
cin.sync_with_stdio(false);
ll n, l;
cin >> n >> l;
vector<ll> v(n);
rep(i, 0, n)cin >> v[i];
int Q;
cin >> Q;
vector<int> q(Q);
rep(i, 0, Q) {
cin >> q[i];
}
vector<vector<int>> res(Q, vector<int>(n - l + 1, -1));
vector<int> dist(n - l + 1);
rep(i, 0, n - l + 1) {
rep(j, 0, l) {
if (v[i + j] != v[j])dist[i]++;
}
}
rep(i, 0, Q) {
rep(j, 0, n - l + 1) {
res[i][0] += (dist[j] <= q[i]);
}
}
vector<int> dist2(n-l+1);
multiset<int> s;
rep(i, 1, n - l + 1) {
s.clear();
rrep(j, n - l, 0) {
dist[j] = dist[j - 1];
}
dist[0] = 0;
rep(j, 0, l) {
if (v[j] != v[i + j])dist[0]++;
}
s.insert(dist[0]);
rep(j, 0, n - l) {
dist[j + 1] -= (v[i - 1] != v[j]);
dist[j + 1] += (v[i + l - 1] != v[j + l]);
s.insert(dist[j+1]);
}
ll counter = 0;
trav(a, s) {
dist2[counter] = a;
counter++;
}
rep(o, 0, Q) {
ll l = 0, r = dist2.size();
while (l < r) {
ll mid = l + (r - l) / 2;
if (dist2[mid] > q[o])r = mid;
else l = mid + 1;
}
res[o][i] += r;
}
}
trav(vec, res) {
trav(a, vec)cout << a << " ";
cout << '\n';
}
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... |