이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;
vi t;
vector<vi> sol;
void sredi(int a, int b, int d){
auto it = lower_bound(t.begin(), t.end(), d);
if (it == t.end()) return;
int ind = it - t.begin();
sol[ind][a]++;
sol[ind][b]++;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
int n, x;
cin >> n >> x;
vi a(n);
for (auto& i : a)
cin >> i;
int m;
cin >> m;
vi q(m);
set<int> st;
for (auto& i : q){
cin >> i;
st.insert(i);
}
for (auto& i : st)
t.push_back(i);
int sz = t.size();
sol = vector<vi>(sz + 2, vi(n + 2, 0));
vi con(x + 1, 0);
for (int i = 0; i < sz; ++i){
con[t[i]] = i;
}
for (int dist = 1; dist <= n - x; ++dist){
int l = 0, r = x - 1, dif = 0;
for (int i = l; i <= r; ++i){
dif += (a[i] != a[i + dist]);
}
sredi(l, l + dist, dif);
while(1){
if (r + dist + 1 >= n) break;
dif -= (a[l] != a[l + dist]);
dif += (a[r + 1] != a[r + dist + 1]);
++r;
++l;
sredi(l, l + dist, dif);
}
}
vector<vi> p(sz + 2, vi(n + 2, 0));
for (int i = 0; i < n; ++i){
p[0][i] = sol[0][i];
for (int j = 1; j < sz; ++j){
p[j][i] = p[j - 1][i] + sol[j][i];
}
}
for (int i = 0; i < m; ++i){
int ind = con[q[i]];
for (int j = 0; j < n-x+1; ++j){
cout << p[ind][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... |