#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 = 1e5 + 5;
int n, k, q;
arr<int, N> a, b;
struct Sg {
struct Nd {
int mx, nm, lzy;
Nd *lf, *rg;
Nd(int x, int y, int z = 0, Nd *l = nullptr, Nd *r = nullptr) {
mx = x, nm = y, lzy = z, lf = l, rg = r;
}
Nd(Nd *l, Nd *r) {
mx = max(l->mx, r->mx);
nm = ((l->mx == mx) ? l->nm : 0) + ((r->mx == mx) ? r->nm : 0);
lzy = 0, lf = l, rg = r;
}
};
arr<Nd*, N> rt;
void prp(Nd *u, int lw, int hg) {
int md = (lw + hg) / 2;
if (!u->lf)
u->lf = new Nd(0, md - lw + 1), u->rg = new Nd(0, hg - md);
for (Nd *v : {u->lf, u->rg})
v->mx += u->lzy, v->lzy += u->lzy;
u->lzy = 0;
}
Nd* upd(int l, int r, int x, Nd *u, int lw = 1, int hg = n - k + 1) {
l = max(l, 1ll), r = min(r, n - k + 1);
assert(l <= r);
if (r < lw || hg < l) return u;
if (l <= lw && hg <= r) return new Nd(u->mx + x, u->nm, u->lzy + x, u->lf, u->rg);
prp(u, lw, hg);
int md = (lw + hg) / 2;
return new Nd(upd(l, r, x, u->lf, lw, md), upd(l, r, x, u->rg, md + 1, hg));
}
} sg;
arr<int, N> ps;
map<int, int> cnt;
void prnt() { cout << cnt.rbegin()->fir << " " << cnt.rbegin()->sec << endl; }
void prcmp() {
for (int i = 1; i <= n; i++)
ps[b[i]] = i;
sg.rt[1] = new Sg::Nd(0, n - k + 1);
for (int i = 1; i <= k; i++) {
int id = ps[a[i]];
sg.rt[1] = sg.upd(id - k + 1, id, +1, sg.rt[1]);
}
for (int i = 2; i <= n - k + 1; i++) {
int lf_id = ps[a[i - 1]], rg_id = ps[a[i + k - 1]];
sg.rt[i] = sg.upd(lf_id - k + 1, lf_id, -1, sg.rt[i - 1]);
sg.rt[i] = sg.upd(rg_id - k + 1, rg_id, +1, sg.rt[i]);
}
for (int i = 1; i <= n - k + 1; i++)
cnt[sg.rt[i]->mx] += sg.rt[i]->nm;
// for (int i = 1; i <= n - k + 1; i++) {
// cout << i << ": " << sg.rt[i]->mx << " " << sg.rt[i]->nm << endl;
// }
}
void cmp() {
prnt();
}
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];
prcmp(), cmp();
}
# | 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... |