Submission #1131674

#TimeUsernameProblemLanguageResultExecution timeMemory
1131674HectonitSličnost (COI23_slicnost)C++20
50 / 100
179 ms11944 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; struct SegTree { struct Node { ll ls = -1, rs = -1, cmx = 0, mx = 0, tp = 0; Node(int lb, int rb) { cmx = rb - lb; } }; vector<Node> t; SegTree(int n) { t.push_back(Node(0, n)); } void apply(int i, int tp) { t[i].mx += tp; t[i].tp += tp; } void push(int i, int l, int r) { if (t[i].ls == -1) { int m = (l + r) / 2; t[i].ls = t.size(); t.push_back(Node(l, m)); t[i].rs = t.size(); t.push_back(Node(m, r)); } if (t[i].tp) { apply(t[i].ls, t[i].tp); apply(t[i].rs, t[i].tp); t[i].tp = 0; } } void upd(int i, int l, int r, int ql, int qr, int x) { if (l >= qr || ql >= r) return; if (ql <= l && r <= qr) { t[i].mx += x; t[i].tp += x; return; } push(i, l, r); int m = (l + r) / 2; upd(t[i].ls, l, m, ql, qr, x); upd(t[i].rs, m, r, ql, qr, x); t[i].mx = max(t[t[i].ls].mx, t[t[i].rs].mx); t[i].cmx = 0; if (t[t[i].ls].mx == t[i].mx) { t[i].cmx += t[t[i].ls].cmx; } if (t[t[i].rs].mx == t[i].mx) { t[i].cmx += t[t[i].rs].cmx; } } }; void solve() { int n, k, m; cin >> n >> k >> m; vector<int> p(n), q(n); for (int i = 0; i < n; i++) { cin >> p[i]; p[i]--; } vector<int> pos(n); for (int i = 0; i < n; i++) { cin >> q[i]; q[i]--; pos[q[i]] = i; } SegTree t(n); for (int i = 0; i < k - 1; i++) { t.upd(0, 0, n, max(0, pos[p[i]] - k + 1), min(pos[p[i]], n - k) + 1, 1); } ll ans = -1, cans = 0; for (int i = 0; i < n - k + 1; i++) { t.upd(0, 0, n, max(0, pos[p[i + k - 1]] - k + 1), min(pos[p[i + k - 1]], n - k) + 1, 1); if (ans < t.t[0].mx) { ans = t.t[0].mx; cans = t.t[0].cmx; } else if (ans == t.t[0].mx) { cans += t.t[0].cmx; } t.upd(0, 0, n, max(0, pos[p[i]] - k + 1), min(pos[p[i]], n - k) + 1, -1); } cout << ans << ' ' << cans << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t = 1; //cin >> t; while (t--) { solve(); } }
#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...