답안 #954643

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
954643 2024-03-28T09:25:48 Z becaido Sličnost (COI23_slicnost) C++17
100 / 100
529 ms 29792 KB
#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

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++) {
      |                         ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6628 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6588 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6488 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6628 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6588 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6488 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 5 ms 9052 KB Output is correct
17 Correct 5 ms 9052 KB Output is correct
18 Correct 3 ms 6660 KB Output is correct
19 Correct 5 ms 6884 KB Output is correct
20 Correct 7 ms 9052 KB Output is correct
21 Correct 6 ms 9052 KB Output is correct
22 Correct 3 ms 6736 KB Output is correct
23 Correct 6 ms 9052 KB Output is correct
24 Correct 5 ms 9048 KB Output is correct
25 Correct 5 ms 6748 KB Output is correct
26 Correct 6 ms 6748 KB Output is correct
27 Correct 7 ms 8936 KB Output is correct
28 Correct 5 ms 6888 KB Output is correct
29 Correct 4 ms 6748 KB Output is correct
30 Correct 3 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6628 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6588 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6488 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 5 ms 9052 KB Output is correct
17 Correct 5 ms 9052 KB Output is correct
18 Correct 3 ms 6660 KB Output is correct
19 Correct 5 ms 6884 KB Output is correct
20 Correct 7 ms 9052 KB Output is correct
21 Correct 6 ms 9052 KB Output is correct
22 Correct 3 ms 6736 KB Output is correct
23 Correct 6 ms 9052 KB Output is correct
24 Correct 5 ms 9048 KB Output is correct
25 Correct 5 ms 6748 KB Output is correct
26 Correct 6 ms 6748 KB Output is correct
27 Correct 7 ms 8936 KB Output is correct
28 Correct 5 ms 6888 KB Output is correct
29 Correct 4 ms 6748 KB Output is correct
30 Correct 3 ms 6748 KB Output is correct
31 Correct 65 ms 16964 KB Output is correct
32 Correct 66 ms 16580 KB Output is correct
33 Correct 19 ms 10576 KB Output is correct
34 Correct 70 ms 13792 KB Output is correct
35 Correct 123 ms 16768 KB Output is correct
36 Correct 82 ms 16584 KB Output is correct
37 Correct 23 ms 12976 KB Output is correct
38 Correct 116 ms 16756 KB Output is correct
39 Correct 87 ms 16788 KB Output is correct
40 Correct 86 ms 13944 KB Output is correct
41 Correct 102 ms 16900 KB Output is correct
42 Correct 131 ms 16832 KB Output is correct
43 Correct 75 ms 13776 KB Output is correct
44 Correct 56 ms 13800 KB Output is correct
45 Correct 28 ms 13056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6628 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6588 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6488 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 3 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 3 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6488 KB Output is correct
23 Correct 2 ms 6620 KB Output is correct
24 Correct 2 ms 6492 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
26 Correct 2 ms 6616 KB Output is correct
27 Correct 2 ms 6492 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 2 ms 6492 KB Output is correct
30 Correct 3 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6628 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6588 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6488 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 5 ms 9052 KB Output is correct
17 Correct 5 ms 9052 KB Output is correct
18 Correct 3 ms 6660 KB Output is correct
19 Correct 5 ms 6884 KB Output is correct
20 Correct 7 ms 9052 KB Output is correct
21 Correct 6 ms 9052 KB Output is correct
22 Correct 3 ms 6736 KB Output is correct
23 Correct 6 ms 9052 KB Output is correct
24 Correct 5 ms 9048 KB Output is correct
25 Correct 5 ms 6748 KB Output is correct
26 Correct 6 ms 6748 KB Output is correct
27 Correct 7 ms 8936 KB Output is correct
28 Correct 5 ms 6888 KB Output is correct
29 Correct 4 ms 6748 KB Output is correct
30 Correct 3 ms 6748 KB Output is correct
31 Correct 2 ms 6492 KB Output is correct
32 Correct 3 ms 6492 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 2 ms 6492 KB Output is correct
35 Correct 3 ms 6492 KB Output is correct
36 Correct 2 ms 6492 KB Output is correct
37 Correct 2 ms 6488 KB Output is correct
38 Correct 2 ms 6620 KB Output is correct
39 Correct 2 ms 6492 KB Output is correct
40 Correct 2 ms 6492 KB Output is correct
41 Correct 2 ms 6616 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 2 ms 6492 KB Output is correct
44 Correct 2 ms 6492 KB Output is correct
45 Correct 3 ms 6492 KB Output is correct
46 Correct 12 ms 9564 KB Output is correct
47 Correct 13 ms 9764 KB Output is correct
48 Correct 3 ms 6748 KB Output is correct
49 Correct 11 ms 7256 KB Output is correct
50 Correct 20 ms 9564 KB Output is correct
51 Correct 5 ms 7000 KB Output is correct
52 Correct 12 ms 7256 KB Output is correct
53 Correct 18 ms 9564 KB Output is correct
54 Correct 16 ms 9560 KB Output is correct
55 Correct 8 ms 7200 KB Output is correct
56 Correct 19 ms 9652 KB Output is correct
57 Correct 19 ms 9564 KB Output is correct
58 Correct 6 ms 7000 KB Output is correct
59 Correct 17 ms 7256 KB Output is correct
60 Correct 6 ms 7004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6628 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6588 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6488 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 5 ms 9052 KB Output is correct
17 Correct 5 ms 9052 KB Output is correct
18 Correct 3 ms 6660 KB Output is correct
19 Correct 5 ms 6884 KB Output is correct
20 Correct 7 ms 9052 KB Output is correct
21 Correct 6 ms 9052 KB Output is correct
22 Correct 3 ms 6736 KB Output is correct
23 Correct 6 ms 9052 KB Output is correct
24 Correct 5 ms 9048 KB Output is correct
25 Correct 5 ms 6748 KB Output is correct
26 Correct 6 ms 6748 KB Output is correct
27 Correct 7 ms 8936 KB Output is correct
28 Correct 5 ms 6888 KB Output is correct
29 Correct 4 ms 6748 KB Output is correct
30 Correct 3 ms 6748 KB Output is correct
31 Correct 65 ms 16964 KB Output is correct
32 Correct 66 ms 16580 KB Output is correct
33 Correct 19 ms 10576 KB Output is correct
34 Correct 70 ms 13792 KB Output is correct
35 Correct 123 ms 16768 KB Output is correct
36 Correct 82 ms 16584 KB Output is correct
37 Correct 23 ms 12976 KB Output is correct
38 Correct 116 ms 16756 KB Output is correct
39 Correct 87 ms 16788 KB Output is correct
40 Correct 86 ms 13944 KB Output is correct
41 Correct 102 ms 16900 KB Output is correct
42 Correct 131 ms 16832 KB Output is correct
43 Correct 75 ms 13776 KB Output is correct
44 Correct 56 ms 13800 KB Output is correct
45 Correct 28 ms 13056 KB Output is correct
46 Correct 2 ms 6492 KB Output is correct
47 Correct 3 ms 6492 KB Output is correct
48 Correct 2 ms 6492 KB Output is correct
49 Correct 2 ms 6492 KB Output is correct
50 Correct 3 ms 6492 KB Output is correct
51 Correct 2 ms 6492 KB Output is correct
52 Correct 2 ms 6488 KB Output is correct
53 Correct 2 ms 6620 KB Output is correct
54 Correct 2 ms 6492 KB Output is correct
55 Correct 2 ms 6492 KB Output is correct
56 Correct 2 ms 6616 KB Output is correct
57 Correct 2 ms 6492 KB Output is correct
58 Correct 2 ms 6492 KB Output is correct
59 Correct 2 ms 6492 KB Output is correct
60 Correct 3 ms 6492 KB Output is correct
61 Correct 12 ms 9564 KB Output is correct
62 Correct 13 ms 9764 KB Output is correct
63 Correct 3 ms 6748 KB Output is correct
64 Correct 11 ms 7256 KB Output is correct
65 Correct 20 ms 9564 KB Output is correct
66 Correct 5 ms 7000 KB Output is correct
67 Correct 12 ms 7256 KB Output is correct
68 Correct 18 ms 9564 KB Output is correct
69 Correct 16 ms 9560 KB Output is correct
70 Correct 8 ms 7200 KB Output is correct
71 Correct 19 ms 9652 KB Output is correct
72 Correct 19 ms 9564 KB Output is correct
73 Correct 6 ms 7000 KB Output is correct
74 Correct 17 ms 7256 KB Output is correct
75 Correct 6 ms 7004 KB Output is correct
76 Correct 277 ms 29120 KB Output is correct
77 Correct 331 ms 29108 KB Output is correct
78 Correct 36 ms 11600 KB Output is correct
79 Correct 278 ms 21188 KB Output is correct
80 Correct 486 ms 29568 KB Output is correct
81 Correct 65 ms 16468 KB Output is correct
82 Correct 273 ms 26320 KB Output is correct
83 Correct 474 ms 29020 KB Output is correct
84 Correct 409 ms 29792 KB Output is correct
85 Correct 148 ms 20664 KB Output is correct
86 Correct 529 ms 29252 KB Output is correct
87 Correct 524 ms 29036 KB Output is correct
88 Correct 99 ms 18248 KB Output is correct
89 Correct 416 ms 26740 KB Output is correct
90 Correct 89 ms 17736 KB Output is correct