Submission #883986

# Submission time Handle Problem Language Result Execution time Memory
883986 2023-12-06T13:46:25 Z vjudge1 Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
3709 ms 115460 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

//#define int ll

#define sz(x) ((x).size())

using tii = tuple<int,int,int>;
using pii = pair<int,int>;

map<tii, int> nrm;

template<typename Node, typename Lazy>
struct AINT {
    vector<Node> aint;
    vector<Lazy> lazy;
    int n;
    void init(int _n) {
        n = _n;
        aint.resize(n * 2 + 5, Node());
        lazy.resize(n * 2 + 5, Lazy());
    }

    void upd(int p, Node x, int node, int cl, int cr) {
        if(p < cl || cr < p) return;
        if(cl == cr) { aint[node] = x; return; }
        int mid = cl + cr >> 1;
        push(node, (mid - cl + 1) * 2);
        upd(p, x, node + 1, cl, mid);
        upd(p, x, node + (mid - cl + 1) * 2, mid + 1, cr);
        aint[node] = aint[node + 1] + aint[node + (mid - cl + 1) * 2];
    }
    Node query(int l, int r, int node, int cl, int cr) {
        if(r < cl || cr < l) return Node();
        if(l <= cl && cr <= r) return aint[node];
        int mid = cl + cr >> 1;
        push(node, (mid - cl + 1) * 2);
        return query(l, r, node + 1, cl, mid) + query(l, r, node + (mid - cl + 1) * 2, mid + 1, cr);
    }

    void upd(int p, Node x) { upd(p, x, 1, 1, n); }
    Node query(int l, int r) { return query(l, r, 1, 1, n); }


    void push(int node, int L) {
        aint[node + 1] += lazy[node];
        aint[node + L] += lazy[node];
        lazy[node + 1] += lazy[node];
        lazy[node + L] += lazy[node];
        lazy[node] = Lazy();
    }
    void pushsegm(int l, int r, Lazy x, int node, int cl, int cr) {
        if(cr < l || r < cl) return;
        if(l <= cl && cr <= r) {
            aint[node] += x;
            lazy[node] += x;
            return;
        }

        int mid = cl + cr >> 1;
        push(node, (mid - cl + 1) * 2);

        pushsegm(l, r, x, node + 1, cl, mid);
        pushsegm(l, r, x, node + (mid - cl + 1) * 2, mid + 1, cr);
        aint[node] = aint[node + 1] + aint[node + (mid - cl + 1) * 2];
    }
    void pushsegm(int l, int r, Lazy x) { return pushsegm(l, r, x, 1, 1, n); }

};

namespace Trolling {
    int get(vector<int> V) {
        int n = sz(V);
        vector<int> idx(n);
        iota(all(idx), 0);
        sort(all(idx), [&](int a, int b) { return V[a] < V[b] || (V[a] == V[b] && a < b); } );
        int mx = 0, cnt = 0;
        for(auto x : idx)
    //        cerr << V[x] << ' ' << x << ' ' << cnt << '\n',
            mx = max(mx, x - cnt),
            cnt++;
        return mx;
    }
}

namespace DS {
    struct Lazy {
        int sum;
        Lazy(int a = 0): sum(a) {;}
        Lazy operator +(const Lazy &x) const { return Lazy(sum + x.sum); }
        Lazy operator +=(const Lazy &x) { return *this = Lazy(sum + x.sum); }
    };

    struct Node {
        int cnt, mx;
        Node(int a = 0, int b = 0): cnt(a), mx(b) {;}
        Node operator +(const Node& x) const { return Node(cnt + x.cnt, max(mx, x.mx)); }
        Node operator +(const Lazy& x) const { return Node(cnt, mx + x.sum); }
        Node operator +=(const Lazy& x) { return *this = Node(cnt, mx + x.sum); }
    };

    AINT<Node, Lazy> aint;

    int n;
    void init(int _n) {
        aint.init(n = _n);
    }

    void insert(int a, int b, int c) {
        int P = nrm[tii{a, b, c}];
        int counter = aint.query(1, P).cnt;
        aint.upd(P, Node(1, b - counter));
        aint.pushsegm(P + 1, n, Lazy(-1));

//        cerr << counter << ' ' << a << '\t' << b << '\t' << b - counter << '\n';

    }


    void erase(int a, int b, int c) {
        int P = nrm[tii{a, b, c}];
        aint.upd(P, Node(0, 0));
        aint.pushsegm(P + 1, n, Lazy(1));
    }

    int query() {
//        for(int i = 1; i <= n; i++)
//            cerr << aint.query(i, i).cnt << ' ' << aint.query(i, i).mx << '\n';
        return aint.query(1, n).mx;
    }

}

std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
	int Q=X.size(), n = sz(A);

	vector<int> lastupdate(n, -1);

	std::vector<int> answer(Q);
	for(int i = 0; i < n; i++) {
        nrm[tii{A[i], i, -1}];
	}
	for (int j=0;j<Q;j++) {
        nrm[tii{V[j], X[j], j}];
    }

    int cnt = 1;
    for(auto &[a, b] : nrm) b = cnt++;

    DS::init(cnt - 1);

    for(auto &[a, b] : nrm) {
        auto [L, R, W] = a;
        if(W == -1)
            DS::insert(L, R, W);
    }

    for(int j = 0; j < Q; j++) {
        DS::erase(A[X[j]], X[j], lastupdate[X[j]]);
        lastupdate[X[j]] = j;
        A[X[j]] = V[j];
        DS::insert(A[X[j]], X[j], lastupdate[X[j]]);

        answer[j] = DS::query();
    }

	return answer;
}

Compilation message

bubblesort2.cpp: In instantiation of 'Node AINT<Node, Lazy>::query(int, int, int, int, int) [with Node = DS::Node; Lazy = DS::Lazy]':
bubblesort2.cpp:46:44:   required from 'Node AINT<Node, Lazy>::query(int, int) [with Node = DS::Node; Lazy = DS::Lazy]'
bubblesort2.cpp:115:38:   required from here
bubblesort2.cpp:40:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |         int mid = cl + cr >> 1;
      |                   ~~~^~~~
bubblesort2.cpp: In instantiation of 'void AINT<Node, Lazy>::upd(int, Node, int, int, int) [with Node = DS::Node; Lazy = DS::Lazy]':
bubblesort2.cpp:45:34:   required from 'void AINT<Node, Lazy>::upd(int, Node) [with Node = DS::Node; Lazy = DS::Lazy]'
bubblesort2.cpp:116:41:   required from here
bubblesort2.cpp:31:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |         int mid = cl + cr >> 1;
      |                   ~~~^~~~
bubblesort2.cpp: In instantiation of 'void AINT<Node, Lazy>::pushsegm(int, int, Lazy, int, int, int) [with Node = DS::Node; Lazy = DS::Lazy]':
bubblesort2.cpp:71:58:   required from 'void AINT<Node, Lazy>::pushsegm(int, int, Lazy) [with Node = DS::Node; Lazy = DS::Lazy]'
bubblesort2.cpp:117:41:   required from here
bubblesort2.cpp:64:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   64 |         int mid = cl + cr >> 1;
      |                   ~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 4 ms 604 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 4 ms 604 KB Output is correct
6 Correct 4 ms 604 KB Output is correct
7 Correct 4 ms 604 KB Output is correct
8 Correct 4 ms 604 KB Output is correct
9 Correct 4 ms 604 KB Output is correct
10 Correct 4 ms 840 KB Output is correct
11 Correct 4 ms 604 KB Output is correct
12 Correct 4 ms 840 KB Output is correct
13 Correct 4 ms 840 KB Output is correct
14 Correct 4 ms 604 KB Output is correct
15 Correct 4 ms 604 KB Output is correct
16 Correct 4 ms 604 KB Output is correct
17 Correct 4 ms 604 KB Output is correct
18 Correct 4 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 4 ms 604 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 4 ms 604 KB Output is correct
6 Correct 4 ms 604 KB Output is correct
7 Correct 4 ms 604 KB Output is correct
8 Correct 4 ms 604 KB Output is correct
9 Correct 4 ms 604 KB Output is correct
10 Correct 4 ms 840 KB Output is correct
11 Correct 4 ms 604 KB Output is correct
12 Correct 4 ms 840 KB Output is correct
13 Correct 4 ms 840 KB Output is correct
14 Correct 4 ms 604 KB Output is correct
15 Correct 4 ms 604 KB Output is correct
16 Correct 4 ms 604 KB Output is correct
17 Correct 4 ms 604 KB Output is correct
18 Correct 4 ms 604 KB Output is correct
19 Correct 17 ms 1884 KB Output is correct
20 Correct 24 ms 2160 KB Output is correct
21 Correct 18 ms 1884 KB Output is correct
22 Correct 19 ms 2076 KB Output is correct
23 Correct 18 ms 2076 KB Output is correct
24 Correct 19 ms 2072 KB Output is correct
25 Correct 18 ms 2072 KB Output is correct
26 Correct 18 ms 2068 KB Output is correct
27 Correct 20 ms 1884 KB Output is correct
28 Correct 18 ms 1880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 3164 KB Output is correct
2 Correct 80 ms 6748 KB Output is correct
3 Correct 146 ms 11092 KB Output is correct
4 Correct 154 ms 11176 KB Output is correct
5 Correct 152 ms 11020 KB Output is correct
6 Correct 141 ms 11184 KB Output is correct
7 Correct 138 ms 11100 KB Output is correct
8 Correct 149 ms 11188 KB Output is correct
9 Correct 149 ms 11344 KB Output is correct
10 Correct 136 ms 11264 KB Output is correct
11 Correct 134 ms 11264 KB Output is correct
12 Correct 137 ms 11264 KB Output is correct
13 Correct 133 ms 11184 KB Output is correct
14 Correct 132 ms 11060 KB Output is correct
15 Correct 131 ms 11088 KB Output is correct
16 Correct 133 ms 11192 KB Output is correct
17 Correct 133 ms 11244 KB Output is correct
18 Correct 128 ms 11244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 4 ms 604 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 4 ms 604 KB Output is correct
6 Correct 4 ms 604 KB Output is correct
7 Correct 4 ms 604 KB Output is correct
8 Correct 4 ms 604 KB Output is correct
9 Correct 4 ms 604 KB Output is correct
10 Correct 4 ms 840 KB Output is correct
11 Correct 4 ms 604 KB Output is correct
12 Correct 4 ms 840 KB Output is correct
13 Correct 4 ms 840 KB Output is correct
14 Correct 4 ms 604 KB Output is correct
15 Correct 4 ms 604 KB Output is correct
16 Correct 4 ms 604 KB Output is correct
17 Correct 4 ms 604 KB Output is correct
18 Correct 4 ms 604 KB Output is correct
19 Correct 17 ms 1884 KB Output is correct
20 Correct 24 ms 2160 KB Output is correct
21 Correct 18 ms 1884 KB Output is correct
22 Correct 19 ms 2076 KB Output is correct
23 Correct 18 ms 2076 KB Output is correct
24 Correct 19 ms 2072 KB Output is correct
25 Correct 18 ms 2072 KB Output is correct
26 Correct 18 ms 2068 KB Output is correct
27 Correct 20 ms 1884 KB Output is correct
28 Correct 18 ms 1880 KB Output is correct
29 Correct 26 ms 3164 KB Output is correct
30 Correct 80 ms 6748 KB Output is correct
31 Correct 146 ms 11092 KB Output is correct
32 Correct 154 ms 11176 KB Output is correct
33 Correct 152 ms 11020 KB Output is correct
34 Correct 141 ms 11184 KB Output is correct
35 Correct 138 ms 11100 KB Output is correct
36 Correct 149 ms 11188 KB Output is correct
37 Correct 149 ms 11344 KB Output is correct
38 Correct 136 ms 11264 KB Output is correct
39 Correct 134 ms 11264 KB Output is correct
40 Correct 137 ms 11264 KB Output is correct
41 Correct 133 ms 11184 KB Output is correct
42 Correct 132 ms 11060 KB Output is correct
43 Correct 131 ms 11088 KB Output is correct
44 Correct 133 ms 11192 KB Output is correct
45 Correct 133 ms 11244 KB Output is correct
46 Correct 128 ms 11244 KB Output is correct
47 Correct 730 ms 34316 KB Output is correct
48 Correct 3355 ms 105320 KB Output is correct
49 Correct 3620 ms 115236 KB Output is correct
50 Correct 3555 ms 115352 KB Output is correct
51 Correct 3515 ms 115108 KB Output is correct
52 Correct 3557 ms 115108 KB Output is correct
53 Correct 3563 ms 115108 KB Output is correct
54 Correct 3554 ms 115328 KB Output is correct
55 Correct 3657 ms 115296 KB Output is correct
56 Correct 3480 ms 115460 KB Output is correct
57 Correct 3547 ms 115412 KB Output is correct
58 Correct 3709 ms 115236 KB Output is correct
59 Correct 3055 ms 113920 KB Output is correct
60 Correct 2974 ms 113976 KB Output is correct
61 Correct 2994 ms 114084 KB Output is correct
62 Correct 2869 ms 113948 KB Output is correct
63 Correct 2889 ms 113896 KB Output is correct
64 Correct 2827 ms 113748 KB Output is correct
65 Correct 2750 ms 113636 KB Output is correct
66 Correct 2750 ms 113920 KB Output is correct
67 Correct 2749 ms 113684 KB Output is correct