#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);
u->lf = new Nd(u->lf->mx + u->lzy, u->lf->nm, u->lf->lzy + u->lzy, u->lf->lf, u->lf->rg);
u->rg = new Nd(u->rg->mx + u->lzy, u->rg->nm, u->rg->lzy + u->lzy, u->rg->lf, u->rg->rg);
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);
// cout << l << " " << r << " " << x << ": " << lw << " " << hg << ": " << u->mx << " " << u->nm << endl;
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();
for (int j = 1; j <= q; j++) {
int i; cin >> i;
int lf_id = ps[a[i]], rg_id = ps[a[i + 1]];
if (i - k + 1 >= 1) {
cnt[sg.rt[i - k + 1]->mx] -= sg.rt[i - k + 1]->nm;
if (cnt[sg.rt[i - k + 1]->mx] == 0) cnt.erase(sg.rt[i - k + 1]->mx);
sg.rt[i - k + 1] = sg.upd(lf_id - k + 1, lf_id, -1, sg.rt[i - k + 1]);
sg.rt[i - k + 1] = sg.upd(rg_id - k + 1, rg_id, +1, sg.rt[i - k + 1]);
cnt[sg.rt[i - k + 1]->mx] += sg.rt[i - k + 1]->nm;
}
if (i + 1 <= n - k + 1) {
cnt[sg.rt[i + 1]->mx] -= sg.rt[i + 1]->nm;
if (cnt[sg.rt[i + 1]->mx] == 0) cnt.erase(sg.rt[i + 1]->mx);
sg.rt[i + 1] = sg.upd(lf_id - k + 1, lf_id, +1, sg.rt[i + 1]);
sg.rt[i + 1] = sg.upd(rg_id - k + 1, rg_id, -1, sg.rt[i + 1]);
cnt[sg.rt[i + 1]->mx] += sg.rt[i + 1]->nm;
}
swap(a[i], a[i + 1]);
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();
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:96:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
96 | freopen("a.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
# | 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... |