Submission #791586

# Submission time Handle Problem Language Result Execution time Memory
791586 2023-07-24T07:42:51 Z 반딧불(#10046) Sličnost (COI23_slicnost) C++17
67 / 100
1236 ms 524288 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct Update{
    int t, l, r, v;
    Update(){}
    Update(int t, int l, int r, int v): t(t), l(l), r(r), v(v){}

    bool operator<(const Update &nxt)const{
        return t<nxt.t;
    }
};

struct PST{
    struct Node{
        int lc, rc;
        int val, maxSum, maxCnt; /// �� ������ ���� +��, �� ���������� �ִ�

        Node(){
            lc = rc = 0;
            val = maxSum = 0, maxCnt = 1;
        }
        Node(int lc, int rc, int val, int maxSum, int maxCnt):
            lc(lc), rc(rc), val(val), maxSum(maxSum), maxCnt(maxCnt){}
    } nodes[18'000'000];
    int nodeCnt;

    void init(int i, int l, int r){
        if(l==r) return;
        int m = (l+r)>>1;
        nodes[i].lc = ++nodeCnt;
        init(nodes[i].lc, l, m);
        nodes[i].rc = ++nodeCnt;
        init(nodes[i].rc, m+1, r);
        nodes[i].maxCnt = nodes[nodes[i].lc].maxCnt + nodes[nodes[i].rc].maxCnt;
    }

    int update(int i, int l, int r, int s, int e, int v){
        if(s<=l && r<=e){
            int tmp = ++nodeCnt;
            nodes[tmp] = nodes[i];
            nodes[tmp].val += v;
            if(l==r) nodes[tmp].maxSum = nodes[tmp].val;
            else{
                nodes[tmp].maxSum = nodes[tmp].val + max(nodes[nodes[tmp].lc].maxSum, nodes[nodes[tmp].rc].maxSum);
                nodes[tmp].maxCnt = (nodes[nodes[tmp].lc].maxSum >= nodes[nodes[tmp].rc].maxSum ? nodes[nodes[tmp].lc].maxCnt : 0) +
                              (nodes[nodes[tmp].rc].maxSum >= nodes[nodes[tmp].lc].maxSum ? nodes[nodes[tmp].rc].maxCnt : 0);
            }
            return tmp;
        }
        int m = (l+r)>>1;
        int tmp = ++nodeCnt;
        nodes[tmp] = nodes[i];
        if(s<=m) nodes[tmp].lc = update(nodes[tmp].lc, l, m, s, e, v);
        if(m<e)  nodes[tmp].rc = update(nodes[tmp].rc, m+1, r, s, e, v);
        nodes[tmp].maxSum = nodes[tmp].val + max(nodes[nodes[tmp].lc].maxSum, nodes[nodes[tmp].rc].maxSum);
        nodes[tmp].maxCnt = (nodes[nodes[tmp].lc].maxSum >= nodes[nodes[tmp].rc].maxSum ? nodes[nodes[tmp].lc].maxCnt : 0) +
                      (nodes[nodes[tmp].rc].maxSum >= nodes[nodes[tmp].lc].maxSum ? nodes[nodes[tmp].rc].maxCnt : 0);
        return tmp;
    }

    int root[200002];
    int L;
    map<int, ll> mp;

    inline void mpAdd(int x, ll v){
        mp[x] += v;
    }

    inline void mpErase(int x, ll v){
        mp[x] -= v;
        if(!mp[x]) mp.erase(x);
    }

    void init(int _L, vector<Update> &vec){
        L = _L;
        root[0] = ++nodeCnt;
        init(root[0], 1, L);

        int pnt = 0;
        for(int t=1; t<=L*2; t++){
            root[t] = root[t-1];
            while(pnt < (int)vec.size() && vec[pnt].t == t){
                root[t] = update(root[t], 1, L, vec[pnt].l, vec[pnt].r, vec[pnt].v);
//                printf("Root %d: add %d %d %d\n", vec[pnt].t, vec[pnt].l, vec[pnt].r, vec[pnt].v);
                pnt++;
            }
            if(t%2) mpAdd(nodes[root[t]].maxSum, nodes[root[t]].maxCnt);
        }
    }

    void update(int t, Update p){
        if(t%2) mpErase(nodes[root[t]].maxSum, nodes[root[t]].maxCnt);
        root[t] = update(root[t], 1, L, p.l, p.r, p.v);
        if(t%2) mpAdd(nodes[root[t]].maxSum, nodes[root[t]].maxCnt);
    }

    void printAns(){
        printf("%d %lld\n", mp.rbegin()->first, mp.rbegin()->second);
    }
} tree;

int n, k, q;
int a[100002], idx[100002];
int in[100002], out[100002];

int main(){
    scanf("%d %d %d", &n, &k, &q);
    for(int i=1; i<=n; i++) scanf("%d", &a[i]);
    for(int i=1; i<=n; i++){
        int x;
        scanf("%d", &x);
        idx[x] = i;
    }

    /// �ʱ� ���� ���� �����
    vector<Update> updateVec;
    for(int i=1; i<=n; i++){
        in[i] = max(1, i-k+1);
        out[i] = min(i, n-k+1);
    }
    for(int i=1; i<=n; i++){
        updateVec.push_back(Update(in[i]*2-1, in[idx[a[i]]], out[idx[a[i]]], 1));
        updateVec.push_back(Update(out[i]*2, in[idx[a[i]]], out[idx[a[i]]], -1));
    }
    sort(updateVec.begin(), updateVec.end());
    tree.init(n-k+1, updateVec);
    tree.printAns();

    /// ���� ó���ϱ�
    while(q--){
        int x;
        scanf("%d", &x);
        /// x�� x+1�� ������ �۾�
        int in1 = in[x]*2-1, in2 = in[x+1]*2-1;
        int out1 = out[x]*2, out2 = out[x+1]*2;
        int ql = in[idx[a[x]]], qr = out[idx[a[x]]];

        for(int d=in1; d<in2; d++) tree.update(d, Update(d, ql, qr, -1));
        for(int d=out1+1; d<out2; d++) tree.update(d, Update(d, ql, qr, 1));

        /// x+1�� x�� ������ �۾�
        ql = in[idx[a[x+1]]], qr = out[idx[a[x+1]]];
        for(int d=in1; d<in2; d++) if(d&1) tree.update(d, Update(d, ql, qr, 1));
        for(int d=out1+1; d<out2; d++) if(d&1) tree.update(d, Update(d, ql, qr, -1));

        /// �� ��ȯ
        swap(a[x], a[x+1]);
        assert(tree.nodeCnt <= 17'000'000);
        tree.printAns();
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:111:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |     scanf("%d %d %d", &n, &k, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:112:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |     for(int i=1; i<=n; i++) scanf("%d", &a[i]);
      |                             ~~~~~^~~~~~~~~~~~~
Main.cpp:115:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  115 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
Main.cpp:136:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  136 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 146 ms 352548 KB Output is correct
2 Correct 132 ms 352460 KB Output is correct
3 Correct 128 ms 352496 KB Output is correct
4 Correct 142 ms 352528 KB Output is correct
5 Correct 130 ms 352520 KB Output is correct
6 Correct 135 ms 352588 KB Output is correct
7 Correct 129 ms 352556 KB Output is correct
8 Correct 127 ms 352452 KB Output is correct
9 Correct 135 ms 352528 KB Output is correct
10 Correct 134 ms 352540 KB Output is correct
11 Correct 128 ms 352548 KB Output is correct
12 Correct 133 ms 352564 KB Output is correct
13 Correct 130 ms 352500 KB Output is correct
14 Correct 129 ms 352552 KB Output is correct
15 Correct 133 ms 352564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 146 ms 352548 KB Output is correct
2 Correct 132 ms 352460 KB Output is correct
3 Correct 128 ms 352496 KB Output is correct
4 Correct 142 ms 352528 KB Output is correct
5 Correct 130 ms 352520 KB Output is correct
6 Correct 135 ms 352588 KB Output is correct
7 Correct 129 ms 352556 KB Output is correct
8 Correct 127 ms 352452 KB Output is correct
9 Correct 135 ms 352528 KB Output is correct
10 Correct 134 ms 352540 KB Output is correct
11 Correct 128 ms 352548 KB Output is correct
12 Correct 133 ms 352564 KB Output is correct
13 Correct 130 ms 352500 KB Output is correct
14 Correct 129 ms 352552 KB Output is correct
15 Correct 133 ms 352564 KB Output is correct
16 Correct 130 ms 352980 KB Output is correct
17 Correct 130 ms 352964 KB Output is correct
18 Correct 130 ms 352972 KB Output is correct
19 Correct 132 ms 352988 KB Output is correct
20 Correct 133 ms 352984 KB Output is correct
21 Correct 133 ms 352940 KB Output is correct
22 Correct 129 ms 352908 KB Output is correct
23 Correct 141 ms 352976 KB Output is correct
24 Correct 133 ms 352972 KB Output is correct
25 Correct 135 ms 352944 KB Output is correct
26 Correct 135 ms 352968 KB Output is correct
27 Correct 134 ms 352996 KB Output is correct
28 Correct 134 ms 352904 KB Output is correct
29 Correct 157 ms 352988 KB Output is correct
30 Correct 130 ms 352924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 146 ms 352548 KB Output is correct
2 Correct 132 ms 352460 KB Output is correct
3 Correct 128 ms 352496 KB Output is correct
4 Correct 142 ms 352528 KB Output is correct
5 Correct 130 ms 352520 KB Output is correct
6 Correct 135 ms 352588 KB Output is correct
7 Correct 129 ms 352556 KB Output is correct
8 Correct 127 ms 352452 KB Output is correct
9 Correct 135 ms 352528 KB Output is correct
10 Correct 134 ms 352540 KB Output is correct
11 Correct 128 ms 352548 KB Output is correct
12 Correct 133 ms 352564 KB Output is correct
13 Correct 130 ms 352500 KB Output is correct
14 Correct 129 ms 352552 KB Output is correct
15 Correct 133 ms 352564 KB Output is correct
16 Correct 130 ms 352980 KB Output is correct
17 Correct 130 ms 352964 KB Output is correct
18 Correct 130 ms 352972 KB Output is correct
19 Correct 132 ms 352988 KB Output is correct
20 Correct 133 ms 352984 KB Output is correct
21 Correct 133 ms 352940 KB Output is correct
22 Correct 129 ms 352908 KB Output is correct
23 Correct 141 ms 352976 KB Output is correct
24 Correct 133 ms 352972 KB Output is correct
25 Correct 135 ms 352944 KB Output is correct
26 Correct 135 ms 352968 KB Output is correct
27 Correct 134 ms 352996 KB Output is correct
28 Correct 134 ms 352904 KB Output is correct
29 Correct 157 ms 352988 KB Output is correct
30 Correct 130 ms 352924 KB Output is correct
31 Correct 218 ms 358332 KB Output is correct
32 Correct 214 ms 358280 KB Output is correct
33 Correct 150 ms 358276 KB Output is correct
34 Correct 279 ms 358332 KB Output is correct
35 Correct 312 ms 358268 KB Output is correct
36 Correct 233 ms 358272 KB Output is correct
37 Correct 158 ms 358368 KB Output is correct
38 Correct 308 ms 358268 KB Output is correct
39 Correct 232 ms 358316 KB Output is correct
40 Correct 296 ms 358368 KB Output is correct
41 Correct 314 ms 358312 KB Output is correct
42 Correct 393 ms 358232 KB Output is correct
43 Correct 264 ms 358204 KB Output is correct
44 Correct 224 ms 358288 KB Output is correct
45 Correct 161 ms 358208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 146 ms 352548 KB Output is correct
2 Correct 132 ms 352460 KB Output is correct
3 Correct 128 ms 352496 KB Output is correct
4 Correct 142 ms 352528 KB Output is correct
5 Correct 130 ms 352520 KB Output is correct
6 Correct 135 ms 352588 KB Output is correct
7 Correct 129 ms 352556 KB Output is correct
8 Correct 127 ms 352452 KB Output is correct
9 Correct 135 ms 352528 KB Output is correct
10 Correct 134 ms 352540 KB Output is correct
11 Correct 128 ms 352548 KB Output is correct
12 Correct 133 ms 352564 KB Output is correct
13 Correct 130 ms 352500 KB Output is correct
14 Correct 129 ms 352552 KB Output is correct
15 Correct 133 ms 352564 KB Output is correct
16 Correct 129 ms 352552 KB Output is correct
17 Correct 151 ms 352516 KB Output is correct
18 Correct 132 ms 352548 KB Output is correct
19 Correct 130 ms 352476 KB Output is correct
20 Correct 131 ms 352448 KB Output is correct
21 Correct 132 ms 352468 KB Output is correct
22 Correct 130 ms 352524 KB Output is correct
23 Correct 129 ms 352556 KB Output is correct
24 Correct 130 ms 352532 KB Output is correct
25 Correct 132 ms 352508 KB Output is correct
26 Correct 130 ms 352484 KB Output is correct
27 Correct 131 ms 352528 KB Output is correct
28 Correct 130 ms 352516 KB Output is correct
29 Correct 132 ms 352464 KB Output is correct
30 Correct 130 ms 352508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 146 ms 352548 KB Output is correct
2 Correct 132 ms 352460 KB Output is correct
3 Correct 128 ms 352496 KB Output is correct
4 Correct 142 ms 352528 KB Output is correct
5 Correct 130 ms 352520 KB Output is correct
6 Correct 135 ms 352588 KB Output is correct
7 Correct 129 ms 352556 KB Output is correct
8 Correct 127 ms 352452 KB Output is correct
9 Correct 135 ms 352528 KB Output is correct
10 Correct 134 ms 352540 KB Output is correct
11 Correct 128 ms 352548 KB Output is correct
12 Correct 133 ms 352564 KB Output is correct
13 Correct 130 ms 352500 KB Output is correct
14 Correct 129 ms 352552 KB Output is correct
15 Correct 133 ms 352564 KB Output is correct
16 Correct 130 ms 352980 KB Output is correct
17 Correct 130 ms 352964 KB Output is correct
18 Correct 130 ms 352972 KB Output is correct
19 Correct 132 ms 352988 KB Output is correct
20 Correct 133 ms 352984 KB Output is correct
21 Correct 133 ms 352940 KB Output is correct
22 Correct 129 ms 352908 KB Output is correct
23 Correct 141 ms 352976 KB Output is correct
24 Correct 133 ms 352972 KB Output is correct
25 Correct 135 ms 352944 KB Output is correct
26 Correct 135 ms 352968 KB Output is correct
27 Correct 134 ms 352996 KB Output is correct
28 Correct 134 ms 352904 KB Output is correct
29 Correct 157 ms 352988 KB Output is correct
30 Correct 130 ms 352924 KB Output is correct
31 Correct 129 ms 352552 KB Output is correct
32 Correct 151 ms 352516 KB Output is correct
33 Correct 132 ms 352548 KB Output is correct
34 Correct 130 ms 352476 KB Output is correct
35 Correct 131 ms 352448 KB Output is correct
36 Correct 132 ms 352468 KB Output is correct
37 Correct 130 ms 352524 KB Output is correct
38 Correct 129 ms 352556 KB Output is correct
39 Correct 130 ms 352532 KB Output is correct
40 Correct 132 ms 352508 KB Output is correct
41 Correct 130 ms 352484 KB Output is correct
42 Correct 131 ms 352528 KB Output is correct
43 Correct 130 ms 352516 KB Output is correct
44 Correct 132 ms 352464 KB Output is correct
45 Correct 130 ms 352508 KB Output is correct
46 Correct 154 ms 353060 KB Output is correct
47 Correct 139 ms 352968 KB Output is correct
48 Correct 132 ms 352996 KB Output is correct
49 Correct 142 ms 353012 KB Output is correct
50 Correct 163 ms 352964 KB Output is correct
51 Correct 131 ms 352924 KB Output is correct
52 Correct 141 ms 352980 KB Output is correct
53 Correct 146 ms 352984 KB Output is correct
54 Correct 142 ms 353044 KB Output is correct
55 Correct 138 ms 352968 KB Output is correct
56 Correct 146 ms 353020 KB Output is correct
57 Correct 146 ms 352980 KB Output is correct
58 Correct 138 ms 352984 KB Output is correct
59 Correct 148 ms 352932 KB Output is correct
60 Correct 152 ms 352948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 146 ms 352548 KB Output is correct
2 Correct 132 ms 352460 KB Output is correct
3 Correct 128 ms 352496 KB Output is correct
4 Correct 142 ms 352528 KB Output is correct
5 Correct 130 ms 352520 KB Output is correct
6 Correct 135 ms 352588 KB Output is correct
7 Correct 129 ms 352556 KB Output is correct
8 Correct 127 ms 352452 KB Output is correct
9 Correct 135 ms 352528 KB Output is correct
10 Correct 134 ms 352540 KB Output is correct
11 Correct 128 ms 352548 KB Output is correct
12 Correct 133 ms 352564 KB Output is correct
13 Correct 130 ms 352500 KB Output is correct
14 Correct 129 ms 352552 KB Output is correct
15 Correct 133 ms 352564 KB Output is correct
16 Correct 130 ms 352980 KB Output is correct
17 Correct 130 ms 352964 KB Output is correct
18 Correct 130 ms 352972 KB Output is correct
19 Correct 132 ms 352988 KB Output is correct
20 Correct 133 ms 352984 KB Output is correct
21 Correct 133 ms 352940 KB Output is correct
22 Correct 129 ms 352908 KB Output is correct
23 Correct 141 ms 352976 KB Output is correct
24 Correct 133 ms 352972 KB Output is correct
25 Correct 135 ms 352944 KB Output is correct
26 Correct 135 ms 352968 KB Output is correct
27 Correct 134 ms 352996 KB Output is correct
28 Correct 134 ms 352904 KB Output is correct
29 Correct 157 ms 352988 KB Output is correct
30 Correct 130 ms 352924 KB Output is correct
31 Correct 218 ms 358332 KB Output is correct
32 Correct 214 ms 358280 KB Output is correct
33 Correct 150 ms 358276 KB Output is correct
34 Correct 279 ms 358332 KB Output is correct
35 Correct 312 ms 358268 KB Output is correct
36 Correct 233 ms 358272 KB Output is correct
37 Correct 158 ms 358368 KB Output is correct
38 Correct 308 ms 358268 KB Output is correct
39 Correct 232 ms 358316 KB Output is correct
40 Correct 296 ms 358368 KB Output is correct
41 Correct 314 ms 358312 KB Output is correct
42 Correct 393 ms 358232 KB Output is correct
43 Correct 264 ms 358204 KB Output is correct
44 Correct 224 ms 358288 KB Output is correct
45 Correct 161 ms 358208 KB Output is correct
46 Correct 129 ms 352552 KB Output is correct
47 Correct 151 ms 352516 KB Output is correct
48 Correct 132 ms 352548 KB Output is correct
49 Correct 130 ms 352476 KB Output is correct
50 Correct 131 ms 352448 KB Output is correct
51 Correct 132 ms 352468 KB Output is correct
52 Correct 130 ms 352524 KB Output is correct
53 Correct 129 ms 352556 KB Output is correct
54 Correct 130 ms 352532 KB Output is correct
55 Correct 132 ms 352508 KB Output is correct
56 Correct 130 ms 352484 KB Output is correct
57 Correct 131 ms 352528 KB Output is correct
58 Correct 130 ms 352516 KB Output is correct
59 Correct 132 ms 352464 KB Output is correct
60 Correct 130 ms 352508 KB Output is correct
61 Correct 154 ms 353060 KB Output is correct
62 Correct 139 ms 352968 KB Output is correct
63 Correct 132 ms 352996 KB Output is correct
64 Correct 142 ms 353012 KB Output is correct
65 Correct 163 ms 352964 KB Output is correct
66 Correct 131 ms 352924 KB Output is correct
67 Correct 141 ms 352980 KB Output is correct
68 Correct 146 ms 352984 KB Output is correct
69 Correct 142 ms 353044 KB Output is correct
70 Correct 138 ms 352968 KB Output is correct
71 Correct 146 ms 353020 KB Output is correct
72 Correct 146 ms 352980 KB Output is correct
73 Correct 138 ms 352984 KB Output is correct
74 Correct 148 ms 352932 KB Output is correct
75 Correct 152 ms 352948 KB Output is correct
76 Correct 629 ms 358760 KB Output is correct
77 Correct 693 ms 358388 KB Output is correct
78 Correct 177 ms 358340 KB Output is correct
79 Correct 666 ms 358432 KB Output is correct
80 Runtime error 1236 ms 524288 KB Execution killed with signal 6
81 Halted 0 ms 0 KB -