#include <bits/stdc++.h>
using namespace std;
#define int long long
#define arr array
#define pii pair<int, int>
#define fir first
#define sec second
const int N = 5e3 + 5;
int n, k, q;
arr<int, N> a, b;
arr<int, N> frq;
void upd(pii &x, int y) {
if (y == x.fir) x.sec++;
if (y > x.fir) x = {y, 1};
}
void slv() {
pii ans = {-1, -1};
for (int i = 1; i <= n; i++) {
int j = (i + k - 1);
if (j > n) continue;
frq.fill(0);
for (int x = i; x <= j; x++) frq[a[x]]++;
for (int x = 1; x <= k; x++) frq[b[x]]++;
int cnt = 0;
for (int x = 1; x <= n; x++) cnt += (frq[x] == 2);
upd(ans, cnt);
for (int x = 1; x <= n; x++) {
int y = x + k;
if (y > n) continue;
cnt -= (frq[b[x]] == 2);
frq[b[x]]--, frq[b[y]]++;
cnt += (frq[b[y]] == 2);
upd(ans, cnt);
}
}
cout << ans.fir << " " << ans.sec << endl;
}
signed main() {
// freopen("a.in", "r", stdin);
cin >> n >> k >> q;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
slv();
for (int i = 1; i <= q; i++) {
int j; cin >> j;
swap(a[j], a[j + 1]);
slv();
}
}
# | 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... |