Submission #954622

#TimeUsernameProblemLanguageResultExecution timeMemory
954622becaidoSličnost (COI23_slicnost)C++17
34 / 100
304 ms250704 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx,popcnt,sse4,abm") #include <bits/stdc++.h> using namespace std; #ifdef WAIMAI #define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE) void dout() {cout << '\n';} template<typename T, typename...U> void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);} #else #define debug(...) 7122 #endif #define ll long long #define Waimai ios::sync_with_stdio(false), cin.tie(0) #define FOR(x,a,b) for (int x = a, I = b; x <= I; x++) #define pb emplace_back #define F first #define S second bool X; const int SIZE = 1e5 + 5; const int TSIZ = 3e7 + 5; int n, k, q; int a[SIZE]; map<int, ll> mp; pair<int, int> seg[SIZE], ans[SIZE]; struct Node { int mx, cnt; short lazy; Node operator + (const Node &o) const { Node re; re.mx = max(mx, o.mx); re.cnt = (mx == re.mx ? cnt : 0) + (o.mx == re.mx ? o.cnt : 0); re.lazy = 0; return re; } } node[TSIZ]; int sz, ls[TSIZ], rs[TSIZ], root[SIZE]; int newnode(int pos) { sz++; node[sz] = node[pos]; ls[sz] = ls[pos], rs[sz] = rs[pos]; return sz; } void build(int &pos, int l, int r) { pos = newnode(pos); node[pos].cnt = r - l + 1; if (l < r) { int mid = (l + r) / 2; build(ls[pos], l, mid); build(rs[pos], mid + 1, r); } } void push(int pos, int l, int r) { if (node[pos].lazy == 0) return; node[pos].mx += node[pos].lazy; if (l < r) { ls[pos] = newnode(ls[pos]); rs[pos] = newnode(rs[pos]); node[ls[pos]].lazy += node[pos].lazy; node[rs[pos]].lazy += node[pos].lazy; } node[pos].lazy = 0; } void pull(int pos, int l, int r) { int mid = (l + r) / 2; push(ls[pos], l, mid); push(rs[pos], mid + 1, r); node[pos] = node[ls[pos]] + node[rs[pos]]; } void upd(int &pos, int l, int r, int L, int R, int x) { pos = newnode(pos); if (l == L && r == R) { node[pos].lazy += x; return; } int mid = (L + R) / 2; push(pos, L, R); if (r <= mid) upd(ls[pos], l, r, L, mid, x); else if (l > mid) upd(rs[pos], l, r, mid + 1, R, x); else { upd(ls[pos], l, mid, L, mid, x); upd(rs[pos], mid + 1, r, mid + 1, R, x); } pull(pos, L, R); } pair<int, int> que(int pos) { push(pos, k, n); return {node[pos].mx, node[pos].cnt}; } void que() { while (mp.rbegin()->S == 0) mp.erase(prev(mp.end())); cout << mp.rbegin()->F << ' ' << mp.rbegin()->S << '\n'; } void solve() { cin >> n >> k >> q; FOR (i, 1, n) cin >> a[i]; FOR (i, 1, n) { int x; cin >> x; seg[x] = {max(i, k), min(n, i + k - 1)}; } build(root[0], k, n); FOR (i, 1, n) { auto [l, r] = seg[a[i]]; root[i] = root[i - 1]; upd(root[i], l, r, k, n, 1); if (i > k) { auto [l, r] = seg[a[i - k]]; upd(root[i], l, r, k, n, -1); } ans[i] = que(root[i]); if (i >= k) mp[ans[i].F] += ans[i].S; } que(); while (q--) { int p; cin >> p; if (p >= k) { mp[ans[p].F] -= ans[p].S; auto [l, r] = seg[a[p]]; upd(root[p], l, r, k, n, -1); tie(l, r) = seg[a[p + 1]]; upd(root[p], l, r, k, n, 1); ans[p] = que(root[p]); mp[ans[p].F] += ans[p].S; } if (p + k <= n) { mp[ans[p + k].F] -= ans[p + k].S; auto [l, r] = seg[a[p + 1]]; upd(root[p + k], l, r, k, n, -1); tie(l, r) = seg[a[p]]; upd(root[p + k], l, r, k, n, 1); ans[p + k] = que(root[p + k]); mp[ans[p + k].F] += ans[p + k].S; } swap(a[p], a[p + 1]); que(); } } bool Y; int main() { // cout << (&Y - &X) / 1048576.0 << '\n'; // return 0; Waimai; 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...