Submission #954643

#TimeUsernameProblemLanguageResultExecution timeMemory
954643becaidoSličnost (COI23_slicnost)C++17
100 / 100
529 ms29792 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 #define lpos pos*2 #define rpos pos*2+1 const int SIZE = 1e5 + 5; int n, k, q; int a[SIZE]; map<int, ll> mp; pair<int, int> seg[SIZE]; vector<pair<int, int>> add[SIZE]; vector<tuple<int, int, int>> op[SIZE]; struct segtree { struct Node { int mx, cnt, 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[SIZE << 2]; void build(int pos, int l, int r) { node[pos].cnt = r - l + 1; if (l < r) { int mid = (l + r) / 2; build(lpos, l, mid); build(rpos, 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) { node[lpos].lazy += node[pos].lazy; node[rpos].lazy += node[pos].lazy; } node[pos].lazy = 0; } void pull(int pos, int l, int r) { int mid = (l + r) / 2; push(lpos, l, mid); push(rpos, mid + 1, r); node[pos] = node[lpos] + node[rpos]; } void upd(int pos, int l, int r, int L, int R, int x) { if (l == L && r == R) { node[pos].lazy += x; push(pos, L, R); return; } int mid = (L + R) / 2; push(pos, L, R); if (r <= mid) upd(lpos, l, r, L, mid, x); else if (l > mid) upd(rpos, l, r, mid + 1, R, x); else { upd(lpos, l, mid, L, mid, x); upd(rpos, mid + 1, r, mid + 1, R, x); } pull(pos, L, R); } pair<int, int> que() { return {node[1].mx, node[1].cnt}; } } tree; 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)}; } FOR (i, 1, n) { op[i].pb(0, a[i], 1); if (i > k) op[i].pb(0, a[i - k], -1); } FOR (i, 1, q) { int p; cin >> p; if (p >= k) { op[p].pb(i, a[p], -1); op[p].pb(i, a[p + 1], 1); } if (p + k <= n) { op[p + k].pb(i, a[p + 1], -1); op[p + k].pb(i, a[p], 1); } swap(a[p], a[p + 1]); } tree.build(1, k, n); FOR (i, 1, n) { sort(op[i].begin(), op[i].end()); for (int j = 0; j < op[i].size(); j++) { auto [l, x, coef] = op[i][j]; tree.upd(1, seg[x].F, seg[x].S, k, n, coef); if (i < k) continue; int r = (j == op[i].size() - 1 ? q + 1 : get<0>(op[i][j + 1])) - 1; if (l <= r) { auto [x, c] = tree.que(); add[l].pb(x, c); add[r + 1].pb(x, -c); } } for (int j = 0; j < op[i].size(); j++) { auto [l, x, coef] = op[i][j]; if (l > 0) tree.upd(1, seg[x].F, seg[x].S, k, n, -coef); } } FOR (i, 0, q) { for (auto [x, c] : add[i]) mp[x] += c; while (prev(mp.end())->S == 0) mp.erase(prev(mp.end())); cout << prev(mp.end())->F << ' ' << prev(mp.end())->S << '\n'; } } int main() { Waimai; solve(); }

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:118:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |         for (int j = 0; j < op[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~
Main.cpp:122:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  122 |             int r = (j == op[i].size() - 1 ? q + 1 : get<0>(op[i][j + 1])) - 1;
      |                      ~~^~~~~~~~~~~~~~~~~~~
Main.cpp:129:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  129 |         for (int j = 0; j < op[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~
#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...