답안 #380623

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
380623 2021-03-22T14:54:11 Z ntabc05101 Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
3651 ms 128992 KB
#if not LOCAL
#define NDEBUG 1
#endif // LOCAL
#include<bits/stdc++.h>

const int inf=1e9+9;

struct SegmentTree {
        std::vector<int64_t> nodes, lazy;
        std::vector<int> L, H;

        void buildRange(int node, int low, int high) {
                L[node]=low, H[node]=high;
                nodes[node]=lazy[node]=0;
                if (low==high) {
                        return ;
                }

                int mid=(low+high)>>1;
                buildRange(node<<1, low, mid);
                buildRange(node<<1|1, mid+1, high);
        }

        SegmentTree(int n) {
                nodes.resize(n<<2); lazy.resize(n<<2);
                L.resize(n<<2), H.resize(n<<2);
                buildRange(1, 1, n);
        }

        void propagate(int node) {
                auto& t=lazy[node];

                nodes[node<<1]+=t;
                lazy[node<<1]+=t;
                nodes[node<<1|1]+=t;
                lazy[node<<1|1]+=t;

                t=0;
        }


        void update(int node, int leftq, int rightq, int delta) {
                //std::cout<<node<<" "<<L[node]<<" "<<H[node]<<" "<<leftq<<" "<<rightq<<" "<<delta<<"\n";
                if (leftq<=L[node] and rightq>=H[node]) {
                        nodes[node]+=delta;
                        lazy[node]+=delta;
                        return ;
                }

                propagate(node);
                if (H[node<<1]>=leftq) update(node<<1, leftq, rightq, delta);
                if (L[node<<1|1]<=rightq) update(node<<1|1, leftq, rightq, delta);

                nodes[node]=std::max(nodes[node<<1], nodes[node<<1|1]);
        }
};

std::vector<int> countScans(std::vector<int> a, std::vector<int> x, std::vector<int> v) {
        int n=a.size(), q=v.size();

        std::vector< std::pair<int, int> > num;
        for (int i=0; i<n; i++) {
                num.push_back({a[i], i});
        }
        for (int i=0; i<q; i++) {
                num.push_back({v[i], x[i]});
        }

        std::sort(begin(num), end(num));
        num.erase(std::unique(begin(num), end(num)), end(num));

        int s=num.size();

        //std::cout<<s<<"\n";

        SegmentTree seg(s);
        seg.update(1, 1, s, -inf);

        const auto ins=[&](int p, int r) {
                int i=std::lower_bound(begin(num), end(num), std::make_pair(p, r))-begin(num)+1;
                seg.update(1, i, i, inf+r);
                if (i<s) {
                        seg.update(1, i+1, s, -1);
                }
        };
        const auto ers=[&](int p, int r) {
                int i=std::lower_bound(begin(num), end(num), std::make_pair(p, r))-begin(num)+1;
                seg.update(1, i, i, -inf-r);
                if (i<s) {
                        seg.update(1, i+1, s, 1);
                }
        };

        for (int i=0; i<n; i++) {
                ins(a[i], i);
        }

        std::vector<int> result(q);
        for (int i=0; i<q; i++) {
                ers(a[x[i]], x[i]);
                ins(v[i], x[i]);
                a[x[i]]=v[i];
                result[i]=seg.nodes[1];
        }

        return result;
}

/*int main() {
        std::ios_base::sync_with_stdio(0); std::cin.tie(0);

        int n, q; std::cin>>n>>q;
        std::vector<int> a(n), x(q), v(q);
        for (auto& _: a) std::cin>>_;
        for (int i=0; i<q; i++) std::cin>>x[i]>>v[i];

        auto result=countScans(a, x, v);
        for (int i=0; i<q; i++) std::cout<<result[i]<<" ";

        std::cout<<std::endl;

        return 0;
}*/

/*
4 2
1 2 3 4
0 3
2 1
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
3 Correct 6 ms 876 KB Output is correct
4 Correct 6 ms 876 KB Output is correct
5 Correct 6 ms 876 KB Output is correct
6 Correct 5 ms 876 KB Output is correct
7 Correct 6 ms 876 KB Output is correct
8 Correct 6 ms 876 KB Output is correct
9 Correct 5 ms 876 KB Output is correct
10 Correct 5 ms 748 KB Output is correct
11 Correct 7 ms 748 KB Output is correct
12 Correct 5 ms 748 KB Output is correct
13 Correct 7 ms 748 KB Output is correct
14 Correct 7 ms 768 KB Output is correct
15 Correct 5 ms 748 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 6 ms 748 KB Output is correct
18 Correct 5 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
3 Correct 6 ms 876 KB Output is correct
4 Correct 6 ms 876 KB Output is correct
5 Correct 6 ms 876 KB Output is correct
6 Correct 5 ms 876 KB Output is correct
7 Correct 6 ms 876 KB Output is correct
8 Correct 6 ms 876 KB Output is correct
9 Correct 5 ms 876 KB Output is correct
10 Correct 5 ms 748 KB Output is correct
11 Correct 7 ms 748 KB Output is correct
12 Correct 5 ms 748 KB Output is correct
13 Correct 7 ms 748 KB Output is correct
14 Correct 7 ms 768 KB Output is correct
15 Correct 5 ms 748 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 6 ms 748 KB Output is correct
18 Correct 5 ms 748 KB Output is correct
19 Correct 21 ms 2156 KB Output is correct
20 Correct 26 ms 2412 KB Output is correct
21 Correct 24 ms 2540 KB Output is correct
22 Correct 29 ms 2412 KB Output is correct
23 Correct 27 ms 2412 KB Output is correct
24 Correct 24 ms 2284 KB Output is correct
25 Correct 22 ms 2156 KB Output is correct
26 Correct 22 ms 2156 KB Output is correct
27 Correct 22 ms 2028 KB Output is correct
28 Correct 22 ms 2028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 3964 KB Output is correct
2 Correct 109 ms 8036 KB Output is correct
3 Correct 203 ms 12384 KB Output is correct
4 Correct 227 ms 12452 KB Output is correct
5 Correct 200 ms 12388 KB Output is correct
6 Correct 206 ms 12384 KB Output is correct
7 Correct 192 ms 12128 KB Output is correct
8 Correct 215 ms 12292 KB Output is correct
9 Correct 200 ms 12256 KB Output is correct
10 Correct 150 ms 8288 KB Output is correct
11 Correct 175 ms 8436 KB Output is correct
12 Correct 159 ms 8416 KB Output is correct
13 Correct 145 ms 8288 KB Output is correct
14 Correct 150 ms 8288 KB Output is correct
15 Correct 143 ms 8288 KB Output is correct
16 Correct 135 ms 8288 KB Output is correct
17 Correct 136 ms 8416 KB Output is correct
18 Correct 135 ms 8288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
3 Correct 6 ms 876 KB Output is correct
4 Correct 6 ms 876 KB Output is correct
5 Correct 6 ms 876 KB Output is correct
6 Correct 5 ms 876 KB Output is correct
7 Correct 6 ms 876 KB Output is correct
8 Correct 6 ms 876 KB Output is correct
9 Correct 5 ms 876 KB Output is correct
10 Correct 5 ms 748 KB Output is correct
11 Correct 7 ms 748 KB Output is correct
12 Correct 5 ms 748 KB Output is correct
13 Correct 7 ms 748 KB Output is correct
14 Correct 7 ms 768 KB Output is correct
15 Correct 5 ms 748 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 6 ms 748 KB Output is correct
18 Correct 5 ms 748 KB Output is correct
19 Correct 21 ms 2156 KB Output is correct
20 Correct 26 ms 2412 KB Output is correct
21 Correct 24 ms 2540 KB Output is correct
22 Correct 29 ms 2412 KB Output is correct
23 Correct 27 ms 2412 KB Output is correct
24 Correct 24 ms 2284 KB Output is correct
25 Correct 22 ms 2156 KB Output is correct
26 Correct 22 ms 2156 KB Output is correct
27 Correct 22 ms 2028 KB Output is correct
28 Correct 22 ms 2028 KB Output is correct
29 Correct 44 ms 3964 KB Output is correct
30 Correct 109 ms 8036 KB Output is correct
31 Correct 203 ms 12384 KB Output is correct
32 Correct 227 ms 12452 KB Output is correct
33 Correct 200 ms 12388 KB Output is correct
34 Correct 206 ms 12384 KB Output is correct
35 Correct 192 ms 12128 KB Output is correct
36 Correct 215 ms 12292 KB Output is correct
37 Correct 200 ms 12256 KB Output is correct
38 Correct 150 ms 8288 KB Output is correct
39 Correct 175 ms 8436 KB Output is correct
40 Correct 159 ms 8416 KB Output is correct
41 Correct 145 ms 8288 KB Output is correct
42 Correct 150 ms 8288 KB Output is correct
43 Correct 143 ms 8288 KB Output is correct
44 Correct 135 ms 8288 KB Output is correct
45 Correct 136 ms 8416 KB Output is correct
46 Correct 135 ms 8288 KB Output is correct
47 Correct 838 ms 38360 KB Output is correct
48 Correct 3252 ms 117884 KB Output is correct
49 Correct 3542 ms 128840 KB Output is correct
50 Correct 3490 ms 128796 KB Output is correct
51 Correct 3439 ms 128860 KB Output is correct
52 Correct 3651 ms 128764 KB Output is correct
53 Correct 3587 ms 128864 KB Output is correct
54 Correct 3181 ms 128992 KB Output is correct
55 Correct 3440 ms 128968 KB Output is correct
56 Correct 3185 ms 128976 KB Output is correct
57 Correct 3372 ms 128904 KB Output is correct
58 Correct 3132 ms 128968 KB Output is correct
59 Correct 2857 ms 115940 KB Output is correct
60 Correct 2867 ms 115876 KB Output is correct
61 Correct 2867 ms 115804 KB Output is correct
62 Correct 2718 ms 109808 KB Output is correct
63 Correct 2671 ms 109820 KB Output is correct
64 Correct 2674 ms 109800 KB Output is correct
65 Correct 2499 ms 103772 KB Output is correct
66 Correct 2473 ms 103916 KB Output is correct
67 Correct 2446 ms 103856 KB Output is correct