답안 #954623

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
954623 2024-03-28T08:48:03 Z becaido Sličnost (COI23_slicnost) C++17
67 / 100
1110 ms 524288 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 = 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, 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 2404 KB Output is correct
2 Correct 1 ms 2400 KB Output is correct
3 Correct 1 ms 2400 KB Output is correct
4 Correct 1 ms 2400 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 2400 KB Output is correct
8 Correct 1 ms 2400 KB Output is correct
9 Correct 1 ms 2400 KB Output is correct
10 Correct 1 ms 2400 KB Output is correct
11 Correct 1 ms 2400 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 2400 KB Output is correct
15 Correct 1 ms 2400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2404 KB Output is correct
2 Correct 1 ms 2400 KB Output is correct
3 Correct 1 ms 2400 KB Output is correct
4 Correct 1 ms 2400 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 2400 KB Output is correct
8 Correct 1 ms 2400 KB Output is correct
9 Correct 1 ms 2400 KB Output is correct
10 Correct 1 ms 2400 KB Output is correct
11 Correct 1 ms 2400 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 2400 KB Output is correct
15 Correct 1 ms 2400 KB Output is correct
16 Correct 5 ms 6492 KB Output is correct
17 Correct 5 ms 6752 KB Output is correct
18 Correct 1 ms 2656 KB Output is correct
19 Correct 8 ms 10080 KB Output is correct
20 Correct 10 ms 12604 KB Output is correct
21 Correct 7 ms 12384 KB Output is correct
22 Correct 2 ms 2908 KB Output is correct
23 Correct 9 ms 12384 KB Output is correct
24 Correct 7 ms 10076 KB Output is correct
25 Correct 8 ms 12632 KB Output is correct
26 Correct 9 ms 16736 KB Output is correct
27 Correct 12 ms 16732 KB Output is correct
28 Correct 7 ms 12380 KB Output is correct
29 Correct 5 ms 7256 KB Output is correct
30 Correct 3 ms 3416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2404 KB Output is correct
2 Correct 1 ms 2400 KB Output is correct
3 Correct 1 ms 2400 KB Output is correct
4 Correct 1 ms 2400 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 2400 KB Output is correct
8 Correct 1 ms 2400 KB Output is correct
9 Correct 1 ms 2400 KB Output is correct
10 Correct 1 ms 2400 KB Output is correct
11 Correct 1 ms 2400 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 2400 KB Output is correct
15 Correct 1 ms 2400 KB Output is correct
16 Correct 5 ms 6492 KB Output is correct
17 Correct 5 ms 6752 KB Output is correct
18 Correct 1 ms 2656 KB Output is correct
19 Correct 8 ms 10080 KB Output is correct
20 Correct 10 ms 12604 KB Output is correct
21 Correct 7 ms 12384 KB Output is correct
22 Correct 2 ms 2908 KB Output is correct
23 Correct 9 ms 12384 KB Output is correct
24 Correct 7 ms 10076 KB Output is correct
25 Correct 8 ms 12632 KB Output is correct
26 Correct 9 ms 16736 KB Output is correct
27 Correct 12 ms 16732 KB Output is correct
28 Correct 7 ms 12380 KB Output is correct
29 Correct 5 ms 7256 KB Output is correct
30 Correct 3 ms 3416 KB Output is correct
31 Correct 116 ms 78932 KB Output is correct
32 Correct 133 ms 83268 KB Output is correct
33 Correct 14 ms 6744 KB Output is correct
34 Correct 177 ms 198596 KB Output is correct
35 Correct 311 ms 249948 KB Output is correct
36 Correct 185 ms 230312 KB Output is correct
37 Correct 20 ms 19544 KB Output is correct
38 Correct 279 ms 239020 KB Output is correct
39 Correct 158 ms 192944 KB Output is correct
40 Correct 241 ms 259160 KB Output is correct
41 Correct 309 ms 304216 KB Output is correct
42 Correct 407 ms 372312 KB Output is correct
43 Correct 205 ms 220808 KB Output is correct
44 Correct 123 ms 150864 KB Output is correct
45 Correct 27 ms 30544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2404 KB Output is correct
2 Correct 1 ms 2400 KB Output is correct
3 Correct 1 ms 2400 KB Output is correct
4 Correct 1 ms 2400 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 2400 KB Output is correct
8 Correct 1 ms 2400 KB Output is correct
9 Correct 1 ms 2400 KB Output is correct
10 Correct 1 ms 2400 KB Output is correct
11 Correct 1 ms 2400 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 2400 KB Output is correct
15 Correct 1 ms 2400 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2652 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 2648 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 2652 KB Output is correct
27 Correct 1 ms 2652 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 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2404 KB Output is correct
2 Correct 1 ms 2400 KB Output is correct
3 Correct 1 ms 2400 KB Output is correct
4 Correct 1 ms 2400 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 2400 KB Output is correct
8 Correct 1 ms 2400 KB Output is correct
9 Correct 1 ms 2400 KB Output is correct
10 Correct 1 ms 2400 KB Output is correct
11 Correct 1 ms 2400 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 2400 KB Output is correct
15 Correct 1 ms 2400 KB Output is correct
16 Correct 5 ms 6492 KB Output is correct
17 Correct 5 ms 6752 KB Output is correct
18 Correct 1 ms 2656 KB Output is correct
19 Correct 8 ms 10080 KB Output is correct
20 Correct 10 ms 12604 KB Output is correct
21 Correct 7 ms 12384 KB Output is correct
22 Correct 2 ms 2908 KB Output is correct
23 Correct 9 ms 12384 KB Output is correct
24 Correct 7 ms 10076 KB Output is correct
25 Correct 8 ms 12632 KB Output is correct
26 Correct 9 ms 16736 KB Output is correct
27 Correct 12 ms 16732 KB Output is correct
28 Correct 7 ms 12380 KB Output is correct
29 Correct 5 ms 7256 KB Output is correct
30 Correct 3 ms 3416 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2652 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 2648 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 2652 KB Output is correct
42 Correct 1 ms 2652 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 2392 KB Output is correct
46 Correct 12 ms 12376 KB Output is correct
47 Correct 13 ms 14684 KB Output is correct
48 Correct 2 ms 2652 KB Output is correct
49 Correct 13 ms 19036 KB Output is correct
50 Correct 28 ms 29276 KB Output is correct
51 Correct 4 ms 6236 KB Output is correct
52 Correct 14 ms 21084 KB Output is correct
53 Correct 27 ms 27228 KB Output is correct
54 Correct 21 ms 25176 KB Output is correct
55 Correct 10 ms 16984 KB Output is correct
56 Correct 29 ms 29276 KB Output is correct
57 Correct 26 ms 29272 KB Output is correct
58 Correct 8 ms 7516 KB Output is correct
59 Correct 31 ms 29276 KB Output is correct
60 Correct 6 ms 7004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2404 KB Output is correct
2 Correct 1 ms 2400 KB Output is correct
3 Correct 1 ms 2400 KB Output is correct
4 Correct 1 ms 2400 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 2400 KB Output is correct
8 Correct 1 ms 2400 KB Output is correct
9 Correct 1 ms 2400 KB Output is correct
10 Correct 1 ms 2400 KB Output is correct
11 Correct 1 ms 2400 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 2400 KB Output is correct
15 Correct 1 ms 2400 KB Output is correct
16 Correct 5 ms 6492 KB Output is correct
17 Correct 5 ms 6752 KB Output is correct
18 Correct 1 ms 2656 KB Output is correct
19 Correct 8 ms 10080 KB Output is correct
20 Correct 10 ms 12604 KB Output is correct
21 Correct 7 ms 12384 KB Output is correct
22 Correct 2 ms 2908 KB Output is correct
23 Correct 9 ms 12384 KB Output is correct
24 Correct 7 ms 10076 KB Output is correct
25 Correct 8 ms 12632 KB Output is correct
26 Correct 9 ms 16736 KB Output is correct
27 Correct 12 ms 16732 KB Output is correct
28 Correct 7 ms 12380 KB Output is correct
29 Correct 5 ms 7256 KB Output is correct
30 Correct 3 ms 3416 KB Output is correct
31 Correct 116 ms 78932 KB Output is correct
32 Correct 133 ms 83268 KB Output is correct
33 Correct 14 ms 6744 KB Output is correct
34 Correct 177 ms 198596 KB Output is correct
35 Correct 311 ms 249948 KB Output is correct
36 Correct 185 ms 230312 KB Output is correct
37 Correct 20 ms 19544 KB Output is correct
38 Correct 279 ms 239020 KB Output is correct
39 Correct 158 ms 192944 KB Output is correct
40 Correct 241 ms 259160 KB Output is correct
41 Correct 309 ms 304216 KB Output is correct
42 Correct 407 ms 372312 KB Output is correct
43 Correct 205 ms 220808 KB Output is correct
44 Correct 123 ms 150864 KB Output is correct
45 Correct 27 ms 30544 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2652 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 1 ms 2652 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 2648 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 2652 KB Output is correct
57 Correct 1 ms 2652 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 2392 KB Output is correct
61 Correct 12 ms 12376 KB Output is correct
62 Correct 13 ms 14684 KB Output is correct
63 Correct 2 ms 2652 KB Output is correct
64 Correct 13 ms 19036 KB Output is correct
65 Correct 28 ms 29276 KB Output is correct
66 Correct 4 ms 6236 KB Output is correct
67 Correct 14 ms 21084 KB Output is correct
68 Correct 27 ms 27228 KB Output is correct
69 Correct 21 ms 25176 KB Output is correct
70 Correct 10 ms 16984 KB Output is correct
71 Correct 29 ms 29276 KB Output is correct
72 Correct 26 ms 29272 KB Output is correct
73 Correct 8 ms 7516 KB Output is correct
74 Correct 31 ms 29276 KB Output is correct
75 Correct 6 ms 7004 KB Output is correct
76 Correct 583 ms 211652 KB Output is correct
77 Correct 641 ms 236704 KB Output is correct
78 Correct 33 ms 8540 KB Output is correct
79 Correct 638 ms 401136 KB Output is correct
80 Runtime error 1110 ms 524288 KB Execution killed with signal 9
81 Halted 0 ms 0 KB -