Submission #954620

# Submission time Handle Problem Language Result Execution time Memory
954620 2024-03-28T08:38:50 Z becaido Sličnost (COI23_slicnost) C++17
34 / 100
2798 ms 524292 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

const int SIZE = 1e5 + 5;
const int TSIZ = SIZE * (__lg(SIZE) + 2) * 8;

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();
    }
}

int main() {
    Waimai;
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 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 2392 KB Output is correct
7 Correct 2 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 2400 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 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 2392 KB Output is correct
7 Correct 2 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 2400 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 5 ms 5212 KB Output is correct
17 Correct 5 ms 5468 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 8 ms 10844 KB Output is correct
20 Correct 9 ms 13148 KB Output is correct
21 Correct 7 ms 12892 KB Output is correct
22 Correct 2 ms 3160 KB Output is correct
23 Correct 9 ms 13148 KB Output is correct
24 Correct 7 ms 12892 KB Output is correct
25 Correct 8 ms 13152 KB Output is correct
26 Correct 9 ms 15452 KB Output is correct
27 Correct 11 ms 17504 KB Output is correct
28 Correct 7 ms 12900 KB Output is correct
29 Correct 5 ms 10340 KB Output is correct
30 Correct 2 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 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 2392 KB Output is correct
7 Correct 2 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 2400 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 5 ms 5212 KB Output is correct
17 Correct 5 ms 5468 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 8 ms 10844 KB Output is correct
20 Correct 9 ms 13148 KB Output is correct
21 Correct 7 ms 12892 KB Output is correct
22 Correct 2 ms 3160 KB Output is correct
23 Correct 9 ms 13148 KB Output is correct
24 Correct 7 ms 12892 KB Output is correct
25 Correct 8 ms 13152 KB Output is correct
26 Correct 9 ms 15452 KB Output is correct
27 Correct 11 ms 17504 KB Output is correct
28 Correct 7 ms 12900 KB Output is correct
29 Correct 5 ms 10340 KB Output is correct
30 Correct 2 ms 3420 KB Output is correct
31 Correct 139 ms 79188 KB Output is correct
32 Correct 130 ms 85328 KB Output is correct
33 Correct 15 ms 6728 KB Output is correct
34 Correct 202 ms 200208 KB Output is correct
35 Correct 303 ms 251580 KB Output is correct
36 Correct 185 ms 231764 KB Output is correct
37 Correct 21 ms 21588 KB Output is correct
38 Correct 285 ms 239696 KB Output is correct
39 Correct 161 ms 193616 KB Output is correct
40 Correct 253 ms 259732 KB Output is correct
41 Runtime error 2798 ms 524292 KB Execution killed with signal 9
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 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 2392 KB Output is correct
7 Correct 2 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 2400 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 2396 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 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2604 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 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2648 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 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 2392 KB Output is correct
7 Correct 2 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 2400 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 5 ms 5212 KB Output is correct
17 Correct 5 ms 5468 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 8 ms 10844 KB Output is correct
20 Correct 9 ms 13148 KB Output is correct
21 Correct 7 ms 12892 KB Output is correct
22 Correct 2 ms 3160 KB Output is correct
23 Correct 9 ms 13148 KB Output is correct
24 Correct 7 ms 12892 KB Output is correct
25 Correct 8 ms 13152 KB Output is correct
26 Correct 9 ms 15452 KB Output is correct
27 Correct 11 ms 17504 KB Output is correct
28 Correct 7 ms 12900 KB Output is correct
29 Correct 5 ms 10340 KB Output is correct
30 Correct 2 ms 3420 KB Output is correct
31 Correct 1 ms 2396 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 2652 KB Output is correct
38 Correct 1 ms 2652 KB Output is correct
39 Correct 1 ms 2604 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 2396 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2648 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 12 ms 13148 KB Output is correct
47 Correct 14 ms 13460 KB Output is correct
48 Correct 3 ms 2648 KB Output is correct
49 Correct 16 ms 17600 KB Output is correct
50 Correct 26 ms 27736 KB Output is correct
51 Correct 5 ms 4700 KB Output is correct
52 Correct 15 ms 21596 KB Output is correct
53 Correct 25 ms 27736 KB Output is correct
54 Correct 23 ms 24100 KB Output is correct
55 Correct 10 ms 17496 KB Output is correct
56 Correct 33 ms 27728 KB Output is correct
57 Correct 27 ms 27728 KB Output is correct
58 Correct 7 ms 10588 KB Output is correct
59 Correct 29 ms 29884 KB Output is correct
60 Correct 6 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 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 2392 KB Output is correct
7 Correct 2 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 2400 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 5 ms 5212 KB Output is correct
17 Correct 5 ms 5468 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 8 ms 10844 KB Output is correct
20 Correct 9 ms 13148 KB Output is correct
21 Correct 7 ms 12892 KB Output is correct
22 Correct 2 ms 3160 KB Output is correct
23 Correct 9 ms 13148 KB Output is correct
24 Correct 7 ms 12892 KB Output is correct
25 Correct 8 ms 13152 KB Output is correct
26 Correct 9 ms 15452 KB Output is correct
27 Correct 11 ms 17504 KB Output is correct
28 Correct 7 ms 12900 KB Output is correct
29 Correct 5 ms 10340 KB Output is correct
30 Correct 2 ms 3420 KB Output is correct
31 Correct 139 ms 79188 KB Output is correct
32 Correct 130 ms 85328 KB Output is correct
33 Correct 15 ms 6728 KB Output is correct
34 Correct 202 ms 200208 KB Output is correct
35 Correct 303 ms 251580 KB Output is correct
36 Correct 185 ms 231764 KB Output is correct
37 Correct 21 ms 21588 KB Output is correct
38 Correct 285 ms 239696 KB Output is correct
39 Correct 161 ms 193616 KB Output is correct
40 Correct 253 ms 259732 KB Output is correct
41 Runtime error 2798 ms 524292 KB Execution killed with signal 9
42 Halted 0 ms 0 KB -