답안 #954621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
954621 2024-03-28T08:41:03 Z becaido Sličnost (COI23_slicnost) C++17
67 / 100
1285 ms 513896 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

bool X;

const int SIZE = 1e5 + 5;
const int TSIZ = 2.6e7 + 5;

int n, k, q;
int a[SIZE];
map<int, ll> mp;
pair<int, int> seg[SIZE], ans[SIZE];

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[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();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 7 ms 7004 KB Output is correct
17 Correct 7 ms 9564 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 7 ms 11868 KB Output is correct
20 Correct 10 ms 12376 KB Output is correct
21 Correct 8 ms 12076 KB Output is correct
22 Correct 2 ms 2908 KB Output is correct
23 Correct 9 ms 12380 KB Output is correct
24 Correct 7 ms 12048 KB Output is correct
25 Correct 8 ms 12376 KB Output is correct
26 Correct 9 ms 16476 KB Output is correct
27 Correct 10 ms 16476 KB Output is correct
28 Correct 7 ms 12124 KB Output is correct
29 Correct 5 ms 9564 KB Output is correct
30 Correct 2 ms 3164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 7 ms 7004 KB Output is correct
17 Correct 7 ms 9564 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 7 ms 11868 KB Output is correct
20 Correct 10 ms 12376 KB Output is correct
21 Correct 8 ms 12076 KB Output is correct
22 Correct 2 ms 2908 KB Output is correct
23 Correct 9 ms 12380 KB Output is correct
24 Correct 7 ms 12048 KB Output is correct
25 Correct 8 ms 12376 KB Output is correct
26 Correct 9 ms 16476 KB Output is correct
27 Correct 10 ms 16476 KB Output is correct
28 Correct 7 ms 12124 KB Output is correct
29 Correct 5 ms 9564 KB Output is correct
30 Correct 2 ms 3164 KB Output is correct
31 Correct 118 ms 78640 KB Output is correct
32 Correct 130 ms 84568 KB Output is correct
33 Correct 14 ms 4696 KB Output is correct
34 Correct 179 ms 198228 KB Output is correct
35 Correct 301 ms 249944 KB Output is correct
36 Correct 220 ms 230108 KB Output is correct
37 Correct 20 ms 21072 KB Output is correct
38 Correct 300 ms 237808 KB Output is correct
39 Correct 169 ms 191820 KB Output is correct
40 Correct 251 ms 257876 KB Output is correct
41 Correct 303 ms 304208 KB Output is correct
42 Correct 396 ms 372560 KB Output is correct
43 Correct 219 ms 220756 KB Output is correct
44 Correct 128 ms 150864 KB Output is correct
45 Correct 27 ms 32340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2848 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2648 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 7 ms 7004 KB Output is correct
17 Correct 7 ms 9564 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 7 ms 11868 KB Output is correct
20 Correct 10 ms 12376 KB Output is correct
21 Correct 8 ms 12076 KB Output is correct
22 Correct 2 ms 2908 KB Output is correct
23 Correct 9 ms 12380 KB Output is correct
24 Correct 7 ms 12048 KB Output is correct
25 Correct 8 ms 12376 KB Output is correct
26 Correct 9 ms 16476 KB Output is correct
27 Correct 10 ms 16476 KB Output is correct
28 Correct 7 ms 12124 KB Output is correct
29 Correct 5 ms 9564 KB Output is correct
30 Correct 2 ms 3164 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2848 KB Output is correct
38 Correct 1 ms 2652 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2648 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 12 ms 12380 KB Output is correct
47 Correct 13 ms 12596 KB Output is correct
48 Correct 2 ms 2652 KB Output is correct
49 Correct 13 ms 18780 KB Output is correct
50 Correct 26 ms 26968 KB Output is correct
51 Correct 4 ms 4444 KB Output is correct
52 Correct 15 ms 22876 KB Output is correct
53 Correct 29 ms 26848 KB Output is correct
54 Correct 19 ms 22876 KB Output is correct
55 Correct 10 ms 16732 KB Output is correct
56 Correct 27 ms 29020 KB Output is correct
57 Correct 26 ms 26972 KB Output is correct
58 Correct 6 ms 9560 KB Output is correct
59 Correct 25 ms 31080 KB Output is correct
60 Correct 6 ms 9564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 7 ms 7004 KB Output is correct
17 Correct 7 ms 9564 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 7 ms 11868 KB Output is correct
20 Correct 10 ms 12376 KB Output is correct
21 Correct 8 ms 12076 KB Output is correct
22 Correct 2 ms 2908 KB Output is correct
23 Correct 9 ms 12380 KB Output is correct
24 Correct 7 ms 12048 KB Output is correct
25 Correct 8 ms 12376 KB Output is correct
26 Correct 9 ms 16476 KB Output is correct
27 Correct 10 ms 16476 KB Output is correct
28 Correct 7 ms 12124 KB Output is correct
29 Correct 5 ms 9564 KB Output is correct
30 Correct 2 ms 3164 KB Output is correct
31 Correct 118 ms 78640 KB Output is correct
32 Correct 130 ms 84568 KB Output is correct
33 Correct 14 ms 4696 KB Output is correct
34 Correct 179 ms 198228 KB Output is correct
35 Correct 301 ms 249944 KB Output is correct
36 Correct 220 ms 230108 KB Output is correct
37 Correct 20 ms 21072 KB Output is correct
38 Correct 300 ms 237808 KB Output is correct
39 Correct 169 ms 191820 KB Output is correct
40 Correct 251 ms 257876 KB Output is correct
41 Correct 303 ms 304208 KB Output is correct
42 Correct 396 ms 372560 KB Output is correct
43 Correct 219 ms 220756 KB Output is correct
44 Correct 128 ms 150864 KB Output is correct
45 Correct 27 ms 32340 KB Output is correct
46 Correct 1 ms 2392 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2652 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 1 ms 2848 KB Output is correct
53 Correct 1 ms 2652 KB Output is correct
54 Correct 1 ms 2652 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 1 ms 2648 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 1 ms 2396 KB Output is correct
59 Correct 1 ms 2652 KB Output is correct
60 Correct 1 ms 2396 KB Output is correct
61 Correct 12 ms 12380 KB Output is correct
62 Correct 13 ms 12596 KB Output is correct
63 Correct 2 ms 2652 KB Output is correct
64 Correct 13 ms 18780 KB Output is correct
65 Correct 26 ms 26968 KB Output is correct
66 Correct 4 ms 4444 KB Output is correct
67 Correct 15 ms 22876 KB Output is correct
68 Correct 29 ms 26848 KB Output is correct
69 Correct 19 ms 22876 KB Output is correct
70 Correct 10 ms 16732 KB Output is correct
71 Correct 27 ms 29020 KB Output is correct
72 Correct 26 ms 26972 KB Output is correct
73 Correct 6 ms 9560 KB Output is correct
74 Correct 25 ms 31080 KB Output is correct
75 Correct 6 ms 9564 KB Output is correct
76 Correct 544 ms 212232 KB Output is correct
77 Correct 603 ms 237092 KB Output is correct
78 Correct 32 ms 7260 KB Output is correct
79 Correct 569 ms 401372 KB Output is correct
80 Incorrect 1285 ms 513896 KB Output isn't correct
81 Halted 0 ms 0 KB -