Submission #1130289

#TimeUsernameProblemLanguageResultExecution timeMemory
1130289gygSličnost (COI23_slicnost)C++20
50 / 100
145 ms8928 KiB
#include <bits/stdc++.h> using namespace std; #define arr array #define int long long #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 mrg(Nd x, Nd y) { if (x.mx < y.mx) swap(x, y); return {x.mx, x.nm + ((y.mx == x.mx) ? y.nm : 0), 0}; } arr<Nd, 4 * N> sg; void bld(int u = 1, int lw = 1, int hg = n - k + 1) { if (lw == hg) { sg[u] = {0, 1, 0}; return; } int md = (lw + hg) / 2; bld(2 * u, lw, md), bld(2 * u + 1, md + 1, hg); sg[u] = mrg(sg[2 * u], sg[2 * u + 1]); } void prp(int u) { for (int v : {2 * u, 2 * u + 1}) sg[v].mx += sg[u].lzy, sg[v].lzy += sg[u].lzy; sg[u].lzy = 0; } void upd(int l, int r, int x, int u = 1, int lw = 1, int hg = n - k + 1) { l = max(l, 1ll), r = min(r, n - k + 1); if (r < lw || hg < l) return; if (l <= lw && hg <= r) { sg[u].mx += x, sg[u].lzy += x; return; } prp(u); int md = (lw + hg) / 2; upd(l, r, x, 2 * u, lw, md), upd(l, r, x, 2 * u + 1, md + 1, hg); sg[u] = mrg(sg[2 * u], sg[2 * u + 1]); } } 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.bld(); for (int i = 1; i <= k; i++) { int id = ps[a[i]]; sg.upd(id - k + 1, id, +1); } cnt[sg.sg[1].mx] += sg.sg[1].nm; for (int i = 2; i <= n - k + 1; i++) { int lf_id = ps[a[i - 1]], rg_id = ps[a[i + k - 1]]; sg.upd(lf_id - k + 1, lf_id, -1); sg.upd(rg_id - k + 1, rg_id, +1); cnt[sg.sg[1].mx] += sg.sg[1].nm; } } 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...