Submission #791720

# Submission time Handle Problem Language Result Execution time Memory
791720 2023-07-24T09:03:29 Z 이동현(#10049) Sličnost (COI23_slicnost) C++17
67 / 100
794 ms 440728 KB
#include <bits/stdc++.h>
#define mi(x, y) (x = min(x, y))
#define ma(x, y) (x = max(x, y))
using namespace std;

const int SZ = (int)10000000, NS = (int)1e5 + 4;
struct Data{
    int l, r, mx, lazy, cnt;
    Data(){
        l = r = mx = lazy = cnt = 0;
    }
};
Data tr[SZ];
int tn;
int n, k, q;
int yl[NS], yr[NS];
int a[NS], b[NS];
int rt[NS];
long long cntsum[NS];

void build(int x, int s, int e){
    if(s == e){
        tr[x].cnt = 1;
        return;
    }
    int m = s + e >> 1;
    tr[x].l = ++tn;
    build(tr[x].l, s, m);
    tr[x].r = ++tn;
    build(tr[x].r, m + 1, e);
    tr[x].cnt = e - s + 1;
}

void push(int pre, int now, int s, int e, int ps, int pe, int val){
    // cout << "PUSH " << pre << ' ' << now << ' ' << s << ' ' << e << ' ' << ps << ' ' << pe << ' ' << val << endl;

    if(ps <= s && e <= pe){
        tr[now].mx += val;
        tr[now].lazy += val;
        return;
    }

    int m = s + e >> 1;
    if(tr[now].lazy || ps <= m){
        tr[now].l = ++tn;
        tr[tn] = tr[tr[pre].l];
        tr[tn].mx += tr[now].lazy;
        tr[tn].lazy += tr[now].lazy;
    }
    if(tr[now].lazy || pe > m){
        tr[now].r = ++tn;
        tr[tn] = tr[tr[pre].r];
        tr[tn].mx += tr[now].lazy;
        tr[tn].lazy += tr[now].lazy;
    }
    tr[now].lazy = 0;
    if(ps <= m){
        push(tr[pre].l, tr[now].l, s, m, ps, pe, val);
    }
    if(pe > m){
        push(tr[pre].r, tr[now].r, m + 1, e, ps, pe, val);
    }

    tr[now].mx = max(tr[tr[now].l].mx, tr[tr[now].r].mx);
    tr[now].cnt = (tr[now].mx == tr[tr[now].l].mx ? tr[tr[now].l].cnt : 0) + (tr[now].mx == tr[tr[now].r].mx ? tr[tr[now].r].cnt : 0);
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> k >> q;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        --a[i];
    }
    for(int i = 0; i < n; ++i){
        cin >> b[i];
        --b[i];

        yl[b[i]] = max(0, i - k + 1);
        yr[b[i]] = min(i, n - k);
    }
    vector<vector<vector<int>>> add(n - k + 2);
    for(int i = 0; i < n; ++i){
        add[max(0, i - k + 1)].push_back({yl[a[i]], yr[a[i]], 1});
        add[min(i, n - k) + 1].push_back({yl[a[i]], yr[a[i]], -1});
    }

    ++tn;
    build(1, 0, n - k);
    int pre = 1;
    for(int i = 0; i <= n - k; ++i){
        for(auto&j:add[i]){
            // cout << i << ' ' << j[0] << ' ' << j[1] << ' ' << j[2] << endl;
            rt[i] = ++tn;
            tr[tn] = tr[pre];
            push(pre, rt[i], 0, n - k, j[0], j[1], j[2]);
            // cout << tr[rt[i]].mx << ' ' << tr[rt[i]].cnt << endl;
            pre = rt[i];
        }
    }

    multiset<int> st;
    for(int i = 0; i <= n - k; ++i){
        st.insert(tr[rt[i]].mx);
        cntsum[tr[rt[i]].mx] += tr[rt[i]].cnt;
    }

    auto output = [&](){
        int ans1 = *(--st.end());
        cout << ans1 << ' ' << cntsum[ans1] << '\n';
    };
    output();

    for(int i = 0; i < q; ++i){
        int x;
        cin >> x;
        --x;

        int lp = x - k + 1;
        int rp = x + 1;

        if(lp >= 0){
            st.erase(st.find(tr[rt[lp]].mx));
            cntsum[tr[rt[lp]].mx] -= tr[rt[lp]].cnt;

            int lst = rt[lp];
            tr[++tn] = tr[rt[lp]];
            push(lst, rt[lp] = tn, 0, n - k, yl[a[x]], yr[a[x]], -1);
            lst = rt[lp];
            tr[++tn] = tr[rt[lp]];
            push(lst, rt[lp] = tn, 0, n - k, yl[a[x + 1]], yr[a[x + 1]], 1);

            st.insert(tr[rt[lp]].mx);
            cntsum[tr[rt[lp]].mx] += tr[rt[lp]].cnt;
        }

        if(rp <= n - k){
            st.erase(st.find(tr[rt[rp]].mx));
            cntsum[tr[rt[rp]].mx] -= tr[rt[rp]].cnt;

            int lst = rt[rp];
            tr[++tn] = tr[rt[rp]];
            push(lst, rt[rp] = tn, 0, n - k, yl[a[x]], yr[a[x]], 1);
            lst = rt[rp];
            tr[++tn] = tr[rt[rp]];
            push(lst, rt[rp] = tn, 0, n - k, yl[a[x + 1]], yr[a[x + 1]], -1);

            st.insert(tr[rt[rp]].mx);
            cntsum[tr[rt[rp]].mx] += tr[rt[rp]].cnt;
        }

        swap(a[x], a[x + 1]);

        output();

        if(tn > SZ - 100000){
            tn -= SZ - 100000;
        }
    }
    
    return 0;
}

Compilation message

Main.cpp: In function 'void build(int, int, int)':
Main.cpp:26:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   26 |     int m = s + e >> 1;
      |             ~~^~~
Main.cpp: In function 'void push(int, int, int, int, int, int, int)':
Main.cpp:43:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   43 |     int m = s + e >> 1;
      |             ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 79 ms 196000 KB Output is correct
2 Correct 79 ms 196044 KB Output is correct
3 Correct 86 ms 196024 KB Output is correct
4 Correct 79 ms 195972 KB Output is correct
5 Correct 80 ms 196036 KB Output is correct
6 Correct 78 ms 195936 KB Output is correct
7 Correct 79 ms 196100 KB Output is correct
8 Correct 75 ms 195924 KB Output is correct
9 Correct 79 ms 196016 KB Output is correct
10 Correct 77 ms 195944 KB Output is correct
11 Correct 77 ms 196016 KB Output is correct
12 Correct 76 ms 195956 KB Output is correct
13 Correct 76 ms 196016 KB Output is correct
14 Correct 79 ms 196004 KB Output is correct
15 Correct 81 ms 195956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 196000 KB Output is correct
2 Correct 79 ms 196044 KB Output is correct
3 Correct 86 ms 196024 KB Output is correct
4 Correct 79 ms 195972 KB Output is correct
5 Correct 80 ms 196036 KB Output is correct
6 Correct 78 ms 195936 KB Output is correct
7 Correct 79 ms 196100 KB Output is correct
8 Correct 75 ms 195924 KB Output is correct
9 Correct 79 ms 196016 KB Output is correct
10 Correct 77 ms 195944 KB Output is correct
11 Correct 77 ms 196016 KB Output is correct
12 Correct 76 ms 195956 KB Output is correct
13 Correct 76 ms 196016 KB Output is correct
14 Correct 79 ms 196004 KB Output is correct
15 Correct 81 ms 195956 KB Output is correct
16 Correct 81 ms 196996 KB Output is correct
17 Correct 86 ms 197064 KB Output is correct
18 Correct 85 ms 196740 KB Output is correct
19 Correct 82 ms 196824 KB Output is correct
20 Correct 87 ms 197004 KB Output is correct
21 Correct 83 ms 196996 KB Output is correct
22 Correct 80 ms 196744 KB Output is correct
23 Correct 84 ms 196992 KB Output is correct
24 Correct 85 ms 197024 KB Output is correct
25 Correct 97 ms 196792 KB Output is correct
26 Correct 89 ms 196852 KB Output is correct
27 Correct 88 ms 196996 KB Output is correct
28 Correct 83 ms 196788 KB Output is correct
29 Correct 82 ms 196804 KB Output is correct
30 Correct 102 ms 196840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 196000 KB Output is correct
2 Correct 79 ms 196044 KB Output is correct
3 Correct 86 ms 196024 KB Output is correct
4 Correct 79 ms 195972 KB Output is correct
5 Correct 80 ms 196036 KB Output is correct
6 Correct 78 ms 195936 KB Output is correct
7 Correct 79 ms 196100 KB Output is correct
8 Correct 75 ms 195924 KB Output is correct
9 Correct 79 ms 196016 KB Output is correct
10 Correct 77 ms 195944 KB Output is correct
11 Correct 77 ms 196016 KB Output is correct
12 Correct 76 ms 195956 KB Output is correct
13 Correct 76 ms 196016 KB Output is correct
14 Correct 79 ms 196004 KB Output is correct
15 Correct 81 ms 195956 KB Output is correct
16 Correct 81 ms 196996 KB Output is correct
17 Correct 86 ms 197064 KB Output is correct
18 Correct 85 ms 196740 KB Output is correct
19 Correct 82 ms 196824 KB Output is correct
20 Correct 87 ms 197004 KB Output is correct
21 Correct 83 ms 196996 KB Output is correct
22 Correct 80 ms 196744 KB Output is correct
23 Correct 84 ms 196992 KB Output is correct
24 Correct 85 ms 197024 KB Output is correct
25 Correct 97 ms 196792 KB Output is correct
26 Correct 89 ms 196852 KB Output is correct
27 Correct 88 ms 196996 KB Output is correct
28 Correct 83 ms 196788 KB Output is correct
29 Correct 82 ms 196804 KB Output is correct
30 Correct 102 ms 196840 KB Output is correct
31 Correct 213 ms 217164 KB Output is correct
32 Correct 288 ms 216956 KB Output is correct
33 Correct 108 ms 208272 KB Output is correct
34 Correct 189 ms 212800 KB Output is correct
35 Correct 290 ms 217560 KB Output is correct
36 Correct 232 ms 216340 KB Output is correct
37 Correct 112 ms 209032 KB Output is correct
38 Correct 288 ms 216548 KB Output is correct
39 Correct 312 ms 217424 KB Output is correct
40 Correct 218 ms 213448 KB Output is correct
41 Correct 242 ms 214688 KB Output is correct
42 Correct 302 ms 216144 KB Output is correct
43 Correct 200 ms 212868 KB Output is correct
44 Correct 166 ms 212024 KB Output is correct
45 Correct 113 ms 209040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 196000 KB Output is correct
2 Correct 79 ms 196044 KB Output is correct
3 Correct 86 ms 196024 KB Output is correct
4 Correct 79 ms 195972 KB Output is correct
5 Correct 80 ms 196036 KB Output is correct
6 Correct 78 ms 195936 KB Output is correct
7 Correct 79 ms 196100 KB Output is correct
8 Correct 75 ms 195924 KB Output is correct
9 Correct 79 ms 196016 KB Output is correct
10 Correct 77 ms 195944 KB Output is correct
11 Correct 77 ms 196016 KB Output is correct
12 Correct 76 ms 195956 KB Output is correct
13 Correct 76 ms 196016 KB Output is correct
14 Correct 79 ms 196004 KB Output is correct
15 Correct 81 ms 195956 KB Output is correct
16 Correct 87 ms 196056 KB Output is correct
17 Correct 82 ms 196028 KB Output is correct
18 Correct 83 ms 195912 KB Output is correct
19 Correct 83 ms 195932 KB Output is correct
20 Correct 86 ms 195944 KB Output is correct
21 Correct 84 ms 195948 KB Output is correct
22 Correct 83 ms 195968 KB Output is correct
23 Correct 83 ms 196032 KB Output is correct
24 Correct 83 ms 195984 KB Output is correct
25 Correct 83 ms 195928 KB Output is correct
26 Correct 83 ms 196032 KB Output is correct
27 Correct 84 ms 196016 KB Output is correct
28 Correct 86 ms 195976 KB Output is correct
29 Correct 83 ms 195952 KB Output is correct
30 Correct 84 ms 196036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 196000 KB Output is correct
2 Correct 79 ms 196044 KB Output is correct
3 Correct 86 ms 196024 KB Output is correct
4 Correct 79 ms 195972 KB Output is correct
5 Correct 80 ms 196036 KB Output is correct
6 Correct 78 ms 195936 KB Output is correct
7 Correct 79 ms 196100 KB Output is correct
8 Correct 75 ms 195924 KB Output is correct
9 Correct 79 ms 196016 KB Output is correct
10 Correct 77 ms 195944 KB Output is correct
11 Correct 77 ms 196016 KB Output is correct
12 Correct 76 ms 195956 KB Output is correct
13 Correct 76 ms 196016 KB Output is correct
14 Correct 79 ms 196004 KB Output is correct
15 Correct 81 ms 195956 KB Output is correct
16 Correct 81 ms 196996 KB Output is correct
17 Correct 86 ms 197064 KB Output is correct
18 Correct 85 ms 196740 KB Output is correct
19 Correct 82 ms 196824 KB Output is correct
20 Correct 87 ms 197004 KB Output is correct
21 Correct 83 ms 196996 KB Output is correct
22 Correct 80 ms 196744 KB Output is correct
23 Correct 84 ms 196992 KB Output is correct
24 Correct 85 ms 197024 KB Output is correct
25 Correct 97 ms 196792 KB Output is correct
26 Correct 89 ms 196852 KB Output is correct
27 Correct 88 ms 196996 KB Output is correct
28 Correct 83 ms 196788 KB Output is correct
29 Correct 82 ms 196804 KB Output is correct
30 Correct 102 ms 196840 KB Output is correct
31 Correct 87 ms 196056 KB Output is correct
32 Correct 82 ms 196028 KB Output is correct
33 Correct 83 ms 195912 KB Output is correct
34 Correct 83 ms 195932 KB Output is correct
35 Correct 86 ms 195944 KB Output is correct
36 Correct 84 ms 195948 KB Output is correct
37 Correct 83 ms 195968 KB Output is correct
38 Correct 83 ms 196032 KB Output is correct
39 Correct 83 ms 195984 KB Output is correct
40 Correct 83 ms 195928 KB Output is correct
41 Correct 83 ms 196032 KB Output is correct
42 Correct 84 ms 196016 KB Output is correct
43 Correct 86 ms 195976 KB Output is correct
44 Correct 83 ms 195952 KB Output is correct
45 Correct 84 ms 196036 KB Output is correct
46 Correct 100 ms 197168 KB Output is correct
47 Correct 98 ms 197136 KB Output is correct
48 Correct 86 ms 196780 KB Output is correct
49 Correct 94 ms 196940 KB Output is correct
50 Correct 104 ms 197180 KB Output is correct
51 Correct 87 ms 196836 KB Output is correct
52 Correct 99 ms 197040 KB Output is correct
53 Correct 102 ms 197008 KB Output is correct
54 Correct 99 ms 197084 KB Output is correct
55 Correct 96 ms 196928 KB Output is correct
56 Correct 105 ms 197064 KB Output is correct
57 Correct 104 ms 197120 KB Output is correct
58 Correct 89 ms 196812 KB Output is correct
59 Correct 101 ms 197052 KB Output is correct
60 Correct 90 ms 196832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 196000 KB Output is correct
2 Correct 79 ms 196044 KB Output is correct
3 Correct 86 ms 196024 KB Output is correct
4 Correct 79 ms 195972 KB Output is correct
5 Correct 80 ms 196036 KB Output is correct
6 Correct 78 ms 195936 KB Output is correct
7 Correct 79 ms 196100 KB Output is correct
8 Correct 75 ms 195924 KB Output is correct
9 Correct 79 ms 196016 KB Output is correct
10 Correct 77 ms 195944 KB Output is correct
11 Correct 77 ms 196016 KB Output is correct
12 Correct 76 ms 195956 KB Output is correct
13 Correct 76 ms 196016 KB Output is correct
14 Correct 79 ms 196004 KB Output is correct
15 Correct 81 ms 195956 KB Output is correct
16 Correct 81 ms 196996 KB Output is correct
17 Correct 86 ms 197064 KB Output is correct
18 Correct 85 ms 196740 KB Output is correct
19 Correct 82 ms 196824 KB Output is correct
20 Correct 87 ms 197004 KB Output is correct
21 Correct 83 ms 196996 KB Output is correct
22 Correct 80 ms 196744 KB Output is correct
23 Correct 84 ms 196992 KB Output is correct
24 Correct 85 ms 197024 KB Output is correct
25 Correct 97 ms 196792 KB Output is correct
26 Correct 89 ms 196852 KB Output is correct
27 Correct 88 ms 196996 KB Output is correct
28 Correct 83 ms 196788 KB Output is correct
29 Correct 82 ms 196804 KB Output is correct
30 Correct 102 ms 196840 KB Output is correct
31 Correct 213 ms 217164 KB Output is correct
32 Correct 288 ms 216956 KB Output is correct
33 Correct 108 ms 208272 KB Output is correct
34 Correct 189 ms 212800 KB Output is correct
35 Correct 290 ms 217560 KB Output is correct
36 Correct 232 ms 216340 KB Output is correct
37 Correct 112 ms 209032 KB Output is correct
38 Correct 288 ms 216548 KB Output is correct
39 Correct 312 ms 217424 KB Output is correct
40 Correct 218 ms 213448 KB Output is correct
41 Correct 242 ms 214688 KB Output is correct
42 Correct 302 ms 216144 KB Output is correct
43 Correct 200 ms 212868 KB Output is correct
44 Correct 166 ms 212024 KB Output is correct
45 Correct 113 ms 209040 KB Output is correct
46 Correct 87 ms 196056 KB Output is correct
47 Correct 82 ms 196028 KB Output is correct
48 Correct 83 ms 195912 KB Output is correct
49 Correct 83 ms 195932 KB Output is correct
50 Correct 86 ms 195944 KB Output is correct
51 Correct 84 ms 195948 KB Output is correct
52 Correct 83 ms 195968 KB Output is correct
53 Correct 83 ms 196032 KB Output is correct
54 Correct 83 ms 195984 KB Output is correct
55 Correct 83 ms 195928 KB Output is correct
56 Correct 83 ms 196032 KB Output is correct
57 Correct 84 ms 196016 KB Output is correct
58 Correct 86 ms 195976 KB Output is correct
59 Correct 83 ms 195952 KB Output is correct
60 Correct 84 ms 196036 KB Output is correct
61 Correct 100 ms 197168 KB Output is correct
62 Correct 98 ms 197136 KB Output is correct
63 Correct 86 ms 196780 KB Output is correct
64 Correct 94 ms 196940 KB Output is correct
65 Correct 104 ms 197180 KB Output is correct
66 Correct 87 ms 196836 KB Output is correct
67 Correct 99 ms 197040 KB Output is correct
68 Correct 102 ms 197008 KB Output is correct
69 Correct 99 ms 197084 KB Output is correct
70 Correct 96 ms 196928 KB Output is correct
71 Correct 105 ms 197064 KB Output is correct
72 Correct 104 ms 197120 KB Output is correct
73 Correct 89 ms 196812 KB Output is correct
74 Correct 101 ms 197052 KB Output is correct
75 Correct 90 ms 196832 KB Output is correct
76 Runtime error 794 ms 440728 KB Execution killed with signal 6
77 Halted 0 ms 0 KB -