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;
int main()
{
cin.tie(0)->sync_with_stdio(0);
int n, K, q;
cin >> n >> K >> q;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++)
{
cin >> a[i];
a[i]--;
}
for (int i = 0; i < n; i++)
{
cin >> b[i];
b[i]--;
}
vector<int> aa(n), bb(n);
for (int i = 0; i < n; i++)
{
aa[a[i]] = i;
bb[b[i]] = i;
}
vector<vector<int>> add(n + 1), del(n + 1);
for (int i = 0; i < n; i++)
{
add[max(0, aa[i] - (K - 1)) + (K - 1)].push_back(i);
del[min(n, aa[i] + K)].push_back(i);
}
long long ans = 0, cnt = 0;
vector<long long> dd(n);
for (int t = 0; t <= n; t++)
{
for (int id : add[t])
{
int l = max(0, bb[id] - (K - 1)) + (K - 1), r = min(n, bb[id] + K);
for (int i = l; i < r; i++)
{
dd[i]++;
}
}
for (int id : del[t])
{
int l = max(0, bb[id] - (K - 1)) + (K - 1), r = min(n, bb[id] + K);
for (int i = l; i < r; i++)
{
dd[i]--;
}
}
long long res = 0, cc = 0;
for (int i = K - 1; i < n; i++)
{
if (res < dd[i])
{
res = dd[i];
cc = 1;
}
else if (res == dd[i])
{
cc++;
}
}
if (res > ans)
{
ans = res;
cnt = cc;
}
else if (res == ans)
{
cnt += cc;
}
}
cout << ans << ' ' << cnt << '\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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |