이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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];
short Q;
cin >> Q;
vector<short> q(Q);
rep(i, 0, Q) {
cin >> q[i];
}
vector<vector<short>> res(Q, vector<short>(n - l + 1, -1));
vector<short> 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]);
}
}
rep(i, 1, n - l + 1) {
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]++;
}
rep(j, 0, n - l) {
dist[j + 1] -= (v[i - 1] != v[j]);
dist[j + 1] += (v[i + l - 1] != v[j + l]);
}
vector<short> dist2 = dist;
sort(all(dist2));
rep(o, 0, Q) {
res[o][i] += upper_bound(all(dist2), q[o]) - dist2.begin();
}
}
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... |