Submission #954622

# Submission time Handle Problem Language Result Execution time Memory
954622 2024-03-28T08:47:31 Z becaido Sličnost (COI23_slicnost) C++17
34 / 100
304 ms 250704 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;
    short 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();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 2 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 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 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 2 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 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 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 6 ms 6492 KB Output is correct
17 Correct 6 ms 6748 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 6 ms 10156 KB Output is correct
20 Correct 9 ms 12632 KB Output is correct
21 Correct 7 ms 12380 KB Output is correct
22 Correct 2 ms 2908 KB Output is correct
23 Correct 9 ms 12636 KB Output is correct
24 Correct 7 ms 10328 KB Output is correct
25 Correct 8 ms 12636 KB Output is correct
26 Correct 10 ms 16988 KB Output is correct
27 Correct 11 ms 16988 KB Output is correct
28 Correct 8 ms 12456 KB Output is correct
29 Correct 5 ms 7524 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 2 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 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 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 6 ms 6492 KB Output is correct
17 Correct 6 ms 6748 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 6 ms 10156 KB Output is correct
20 Correct 9 ms 12632 KB Output is correct
21 Correct 7 ms 12380 KB Output is correct
22 Correct 2 ms 2908 KB Output is correct
23 Correct 9 ms 12636 KB Output is correct
24 Correct 7 ms 10328 KB Output is correct
25 Correct 8 ms 12636 KB Output is correct
26 Correct 10 ms 16988 KB Output is correct
27 Correct 11 ms 16988 KB Output is correct
28 Correct 8 ms 12456 KB Output is correct
29 Correct 5 ms 7524 KB Output is correct
30 Correct 2 ms 3420 KB Output is correct
31 Correct 143 ms 79704 KB Output is correct
32 Correct 130 ms 84188 KB Output is correct
33 Correct 15 ms 7708 KB Output is correct
34 Correct 206 ms 199524 KB Output is correct
35 Correct 304 ms 250704 KB Output is correct
36 Correct 180 ms 231076 KB Output is correct
37 Incorrect 25 ms 20308 KB Output isn't correct
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 2 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 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 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 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 2652 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 2652 KB Output is correct
26 Correct 1 ms 2660 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 2544 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 2 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 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 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 6 ms 6492 KB Output is correct
17 Correct 6 ms 6748 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 6 ms 10156 KB Output is correct
20 Correct 9 ms 12632 KB Output is correct
21 Correct 7 ms 12380 KB Output is correct
22 Correct 2 ms 2908 KB Output is correct
23 Correct 9 ms 12636 KB Output is correct
24 Correct 7 ms 10328 KB Output is correct
25 Correct 8 ms 12636 KB Output is correct
26 Correct 10 ms 16988 KB Output is correct
27 Correct 11 ms 16988 KB Output is correct
28 Correct 8 ms 12456 KB Output is correct
29 Correct 5 ms 7524 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 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 2652 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 2652 KB Output is correct
41 Correct 1 ms 2660 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 2544 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 12 ms 12632 KB Output is correct
47 Correct 15 ms 14752 KB Output is correct
48 Correct 2 ms 2652 KB Output is correct
49 Correct 13 ms 19088 KB Output is correct
50 Correct 34 ms 29268 KB Output is correct
51 Correct 5 ms 6236 KB Output is correct
52 Correct 16 ms 21084 KB Output is correct
53 Correct 27 ms 27280 KB Output is correct
54 Correct 20 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 28 ms 29276 KB Output is correct
58 Correct 6 ms 7516 KB Output is correct
59 Correct 25 ms 29276 KB Output is correct
60 Correct 5 ms 7004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 2 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 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 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 6 ms 6492 KB Output is correct
17 Correct 6 ms 6748 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 6 ms 10156 KB Output is correct
20 Correct 9 ms 12632 KB Output is correct
21 Correct 7 ms 12380 KB Output is correct
22 Correct 2 ms 2908 KB Output is correct
23 Correct 9 ms 12636 KB Output is correct
24 Correct 7 ms 10328 KB Output is correct
25 Correct 8 ms 12636 KB Output is correct
26 Correct 10 ms 16988 KB Output is correct
27 Correct 11 ms 16988 KB Output is correct
28 Correct 8 ms 12456 KB Output is correct
29 Correct 5 ms 7524 KB Output is correct
30 Correct 2 ms 3420 KB Output is correct
31 Correct 143 ms 79704 KB Output is correct
32 Correct 130 ms 84188 KB Output is correct
33 Correct 15 ms 7708 KB Output is correct
34 Correct 206 ms 199524 KB Output is correct
35 Correct 304 ms 250704 KB Output is correct
36 Correct 180 ms 231076 KB Output is correct
37 Incorrect 25 ms 20308 KB Output isn't correct
38 Halted 0 ms 0 KB -