답안 #791598

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791598 2023-07-24T07:51:07 Z 반딧불(#10046) Sličnost (COI23_slicnost) C++17
50 / 100
352 ms 398224 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[20'000'000];
    int nodeCnt, nodeEnd;

    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;
        nodeEnd = nodeCnt;
    }

    int update(int i, int l, int r, int s, int e, int v){
        if(s<=l && r<=e){
            int tmp = (i > nodeEnd ? i : ++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 = (i > nodeEnd ? i : ++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++) 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));

        /// 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]);
        if(tree.nodeCnt > 19'000'000) while(1) printf("");
        tree.printAns();
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:153:55: warning: zero-length gnu_printf format string [-Wformat-zero-length]
  153 |         if(tree.nodeCnt > 19'000'000) while(1) printf("");
      |                                                       ^~
Main.cpp:112:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |     scanf("%d %d %d", &n, &k, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:113:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  113 |     for(int i=1; i<=n; i++) scanf("%d", &a[i]);
      |                             ~~~~~^~~~~~~~~~~~~
Main.cpp:116:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
Main.cpp:137:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  137 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 167 ms 391692 KB Output is correct
2 Correct 144 ms 391624 KB Output is correct
3 Correct 151 ms 391656 KB Output is correct
4 Correct 150 ms 391652 KB Output is correct
5 Correct 153 ms 391644 KB Output is correct
6 Correct 145 ms 391600 KB Output is correct
7 Correct 144 ms 391644 KB Output is correct
8 Correct 151 ms 391804 KB Output is correct
9 Correct 146 ms 391692 KB Output is correct
10 Correct 156 ms 391628 KB Output is correct
11 Correct 156 ms 391580 KB Output is correct
12 Correct 151 ms 391764 KB Output is correct
13 Correct 161 ms 391636 KB Output is correct
14 Correct 144 ms 391628 KB Output is correct
15 Correct 145 ms 391600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 167 ms 391692 KB Output is correct
2 Correct 144 ms 391624 KB Output is correct
3 Correct 151 ms 391656 KB Output is correct
4 Correct 150 ms 391652 KB Output is correct
5 Correct 153 ms 391644 KB Output is correct
6 Correct 145 ms 391600 KB Output is correct
7 Correct 144 ms 391644 KB Output is correct
8 Correct 151 ms 391804 KB Output is correct
9 Correct 146 ms 391692 KB Output is correct
10 Correct 156 ms 391628 KB Output is correct
11 Correct 156 ms 391580 KB Output is correct
12 Correct 151 ms 391764 KB Output is correct
13 Correct 161 ms 391636 KB Output is correct
14 Correct 144 ms 391628 KB Output is correct
15 Correct 145 ms 391600 KB Output is correct
16 Correct 156 ms 392212 KB Output is correct
17 Correct 154 ms 392112 KB Output is correct
18 Correct 145 ms 392148 KB Output is correct
19 Correct 153 ms 392104 KB Output is correct
20 Correct 158 ms 392148 KB Output is correct
21 Correct 151 ms 392120 KB Output is correct
22 Correct 165 ms 392124 KB Output is correct
23 Correct 156 ms 392164 KB Output is correct
24 Correct 152 ms 392100 KB Output is correct
25 Correct 151 ms 392108 KB Output is correct
26 Correct 154 ms 392132 KB Output is correct
27 Correct 152 ms 392140 KB Output is correct
28 Correct 155 ms 392256 KB Output is correct
29 Correct 146 ms 392200 KB Output is correct
30 Correct 149 ms 392192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 167 ms 391692 KB Output is correct
2 Correct 144 ms 391624 KB Output is correct
3 Correct 151 ms 391656 KB Output is correct
4 Correct 150 ms 391652 KB Output is correct
5 Correct 153 ms 391644 KB Output is correct
6 Correct 145 ms 391600 KB Output is correct
7 Correct 144 ms 391644 KB Output is correct
8 Correct 151 ms 391804 KB Output is correct
9 Correct 146 ms 391692 KB Output is correct
10 Correct 156 ms 391628 KB Output is correct
11 Correct 156 ms 391580 KB Output is correct
12 Correct 151 ms 391764 KB Output is correct
13 Correct 161 ms 391636 KB Output is correct
14 Correct 144 ms 391628 KB Output is correct
15 Correct 145 ms 391600 KB Output is correct
16 Correct 156 ms 392212 KB Output is correct
17 Correct 154 ms 392112 KB Output is correct
18 Correct 145 ms 392148 KB Output is correct
19 Correct 153 ms 392104 KB Output is correct
20 Correct 158 ms 392148 KB Output is correct
21 Correct 151 ms 392120 KB Output is correct
22 Correct 165 ms 392124 KB Output is correct
23 Correct 156 ms 392164 KB Output is correct
24 Correct 152 ms 392100 KB Output is correct
25 Correct 151 ms 392108 KB Output is correct
26 Correct 154 ms 392132 KB Output is correct
27 Correct 152 ms 392140 KB Output is correct
28 Correct 155 ms 392256 KB Output is correct
29 Correct 146 ms 392200 KB Output is correct
30 Correct 149 ms 392192 KB Output is correct
31 Correct 247 ms 398060 KB Output is correct
32 Correct 248 ms 398028 KB Output is correct
33 Correct 222 ms 398080 KB Output is correct
34 Correct 308 ms 398080 KB Output is correct
35 Correct 352 ms 398028 KB Output is correct
36 Correct 314 ms 398152 KB Output is correct
37 Correct 201 ms 398140 KB Output is correct
38 Correct 294 ms 398104 KB Output is correct
39 Correct 273 ms 398136 KB Output is correct
40 Correct 300 ms 398112 KB Output is correct
41 Correct 325 ms 398140 KB Output is correct
42 Correct 332 ms 398192 KB Output is correct
43 Correct 291 ms 398124 KB Output is correct
44 Correct 272 ms 398224 KB Output is correct
45 Correct 206 ms 398220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 167 ms 391692 KB Output is correct
2 Correct 144 ms 391624 KB Output is correct
3 Correct 151 ms 391656 KB Output is correct
4 Correct 150 ms 391652 KB Output is correct
5 Correct 153 ms 391644 KB Output is correct
6 Correct 145 ms 391600 KB Output is correct
7 Correct 144 ms 391644 KB Output is correct
8 Correct 151 ms 391804 KB Output is correct
9 Correct 146 ms 391692 KB Output is correct
10 Correct 156 ms 391628 KB Output is correct
11 Correct 156 ms 391580 KB Output is correct
12 Correct 151 ms 391764 KB Output is correct
13 Correct 161 ms 391636 KB Output is correct
14 Correct 144 ms 391628 KB Output is correct
15 Correct 145 ms 391600 KB Output is correct
16 Correct 151 ms 391744 KB Output is correct
17 Incorrect 162 ms 391600 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 167 ms 391692 KB Output is correct
2 Correct 144 ms 391624 KB Output is correct
3 Correct 151 ms 391656 KB Output is correct
4 Correct 150 ms 391652 KB Output is correct
5 Correct 153 ms 391644 KB Output is correct
6 Correct 145 ms 391600 KB Output is correct
7 Correct 144 ms 391644 KB Output is correct
8 Correct 151 ms 391804 KB Output is correct
9 Correct 146 ms 391692 KB Output is correct
10 Correct 156 ms 391628 KB Output is correct
11 Correct 156 ms 391580 KB Output is correct
12 Correct 151 ms 391764 KB Output is correct
13 Correct 161 ms 391636 KB Output is correct
14 Correct 144 ms 391628 KB Output is correct
15 Correct 145 ms 391600 KB Output is correct
16 Correct 156 ms 392212 KB Output is correct
17 Correct 154 ms 392112 KB Output is correct
18 Correct 145 ms 392148 KB Output is correct
19 Correct 153 ms 392104 KB Output is correct
20 Correct 158 ms 392148 KB Output is correct
21 Correct 151 ms 392120 KB Output is correct
22 Correct 165 ms 392124 KB Output is correct
23 Correct 156 ms 392164 KB Output is correct
24 Correct 152 ms 392100 KB Output is correct
25 Correct 151 ms 392108 KB Output is correct
26 Correct 154 ms 392132 KB Output is correct
27 Correct 152 ms 392140 KB Output is correct
28 Correct 155 ms 392256 KB Output is correct
29 Correct 146 ms 392200 KB Output is correct
30 Correct 149 ms 392192 KB Output is correct
31 Correct 151 ms 391744 KB Output is correct
32 Incorrect 162 ms 391600 KB Output isn't correct
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 167 ms 391692 KB Output is correct
2 Correct 144 ms 391624 KB Output is correct
3 Correct 151 ms 391656 KB Output is correct
4 Correct 150 ms 391652 KB Output is correct
5 Correct 153 ms 391644 KB Output is correct
6 Correct 145 ms 391600 KB Output is correct
7 Correct 144 ms 391644 KB Output is correct
8 Correct 151 ms 391804 KB Output is correct
9 Correct 146 ms 391692 KB Output is correct
10 Correct 156 ms 391628 KB Output is correct
11 Correct 156 ms 391580 KB Output is correct
12 Correct 151 ms 391764 KB Output is correct
13 Correct 161 ms 391636 KB Output is correct
14 Correct 144 ms 391628 KB Output is correct
15 Correct 145 ms 391600 KB Output is correct
16 Correct 156 ms 392212 KB Output is correct
17 Correct 154 ms 392112 KB Output is correct
18 Correct 145 ms 392148 KB Output is correct
19 Correct 153 ms 392104 KB Output is correct
20 Correct 158 ms 392148 KB Output is correct
21 Correct 151 ms 392120 KB Output is correct
22 Correct 165 ms 392124 KB Output is correct
23 Correct 156 ms 392164 KB Output is correct
24 Correct 152 ms 392100 KB Output is correct
25 Correct 151 ms 392108 KB Output is correct
26 Correct 154 ms 392132 KB Output is correct
27 Correct 152 ms 392140 KB Output is correct
28 Correct 155 ms 392256 KB Output is correct
29 Correct 146 ms 392200 KB Output is correct
30 Correct 149 ms 392192 KB Output is correct
31 Correct 247 ms 398060 KB Output is correct
32 Correct 248 ms 398028 KB Output is correct
33 Correct 222 ms 398080 KB Output is correct
34 Correct 308 ms 398080 KB Output is correct
35 Correct 352 ms 398028 KB Output is correct
36 Correct 314 ms 398152 KB Output is correct
37 Correct 201 ms 398140 KB Output is correct
38 Correct 294 ms 398104 KB Output is correct
39 Correct 273 ms 398136 KB Output is correct
40 Correct 300 ms 398112 KB Output is correct
41 Correct 325 ms 398140 KB Output is correct
42 Correct 332 ms 398192 KB Output is correct
43 Correct 291 ms 398124 KB Output is correct
44 Correct 272 ms 398224 KB Output is correct
45 Correct 206 ms 398220 KB Output is correct
46 Correct 151 ms 391744 KB Output is correct
47 Incorrect 162 ms 391600 KB Output isn't correct
48 Halted 0 ms 0 KB -