답안 #421765

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
421765 2021-06-09T11:49:06 Z ACmachine Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
1832 ms 43584 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k, l) for(int i = (j); i < (k); i += (l))
#define FORD(i, j, k, l) for(int i = (j); i >= (k); i += (l))
#define REP(i, n) FOR(i, 0, n, 1)
#define REPD(i, n) FORD(i, n, 0, 1)
#define pb push_back
typedef long long ll;
const int INF = (int)1e9;
struct node{
    int lazy = 0;
    int max = 0;
    void apply(int l, int r, int val){
        lazy += val;
        max += val;
    }
};
struct segtree{
    node comb(const node& a, const node &b){
        node res;
        res.max = max(a.max, b.max);
        return res;
    }
    void push(int l, int r, int v){
        tree[v << 1].apply(l, r, tree[v].lazy);
        tree[v << 1 | 1].apply(l, r, tree[v].lazy);
        tree[v].lazy = 0;
    }
    int n;
    vector<node> tree;
    segtree(int _n){
        n = 1; 
        while(n < _n)
            n *= 2;
        tree.resize(2 * n);
    }
    node query(int l, int r){
        return query0(l, r, 0, n, 1);
    }
    node query0(int l, int r, int beg, int end, int v){
        if(beg >= l && end <= r)
            return tree[v];
        if(beg >= r || end <= l){
            node res;
            res.max = -INF;
            return res;
        }
        push(beg, end, v);
        int mid = (beg + end) >> 1;
        return comb(query0(l, r, beg, mid, v << 1), query0(l, r, mid, end, v << 1 | 1));
    }
    void upd(int l, int r, int val){
        upd0(l, r, 0, n, 1, val);
    }
    void upd0(int l, int r, int beg, int end, int v, int val){
        if(beg >= l && end <= r){
            tree[v].apply(beg, end, val);
            return;
        }
        if(beg >= r || end <= l)
            return;
        push(beg, end, v);
        int mid = (beg + end) >> 1;
        upd0(l, r, beg, mid, v << 1, val);
        upd0(l, r, mid, end, v << 1 | 1, val);
        tree[v] = comb(tree[v << 1], tree[v << 1 | 1]);
    }
};
vector<int> countScans(vector<int> a,vector<int> x,vector<int> v){
    int q = x.size();
    int n = a.size();
    vector<int> res(q);
	vector<array<int, 3>> comp;
    REP(i, n){
        comp.pb({a[i], i, -1});
    }
    REP(i, q){
        comp.pb({v[i], x[i], i});
    }
    sort(comp.begin(), comp.end());
    // values compressed; if they were equal initially, they are tiebreaked using index; if index > .., compression value is bigger
    REP(i, comp.size()){
        auto y = comp[i];
        if(y[2] == -1){ // in intiail array
            a[y[1]] = i;
        }
        else{
            v[y[2]] = i;
        }
    }
    segtree st(comp.size() + 10);
    st.upd(0, st.n, -INF);
    REP(i, n){
        st.upd(a[i], a[i] + 1, INF + i);
        st.upd(a[i] + 1, st.n, -1);
    }
    REP(i, q){
        int id = x[i];
        st.upd(a[id], a[id] + 1, -INF - id);
        st.upd(a[id] + 1, st.n, 1);
        a[id] = v[i];
        st.upd(a[id], a[id] + 1, INF + id);
        st.upd(a[id] + 1, st.n, -1);
        auto no = st.query(0, st.n);
        res[i] = no.max;
    }
	return res;
}

Compilation message

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:4:44: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define FOR(i, j, k, l) for(int i = (j); i < (k); i += (l))
      |                                            ^
bubblesort2.cpp:6:19: note: in expansion of macro 'FOR'
    6 | #define REP(i, n) FOR(i, 0, n, 1)
      |                   ^~~
bubblesort2.cpp:83:5: note: in expansion of macro 'REP'
   83 |     REP(i, comp.size()){
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 300 KB Output is correct
2 Correct 2 ms 408 KB Output is correct
3 Correct 5 ms 460 KB Output is correct
4 Correct 5 ms 548 KB Output is correct
5 Correct 4 ms 460 KB Output is correct
6 Correct 4 ms 460 KB Output is correct
7 Correct 4 ms 460 KB Output is correct
8 Correct 4 ms 428 KB Output is correct
9 Correct 6 ms 488 KB Output is correct
10 Correct 4 ms 460 KB Output is correct
11 Correct 4 ms 460 KB Output is correct
12 Correct 4 ms 460 KB Output is correct
13 Correct 4 ms 460 KB Output is correct
14 Correct 6 ms 460 KB Output is correct
15 Correct 6 ms 540 KB Output is correct
16 Correct 6 ms 460 KB Output is correct
17 Correct 6 ms 460 KB Output is correct
18 Correct 5 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 300 KB Output is correct
2 Correct 2 ms 408 KB Output is correct
3 Correct 5 ms 460 KB Output is correct
4 Correct 5 ms 548 KB Output is correct
5 Correct 4 ms 460 KB Output is correct
6 Correct 4 ms 460 KB Output is correct
7 Correct 4 ms 460 KB Output is correct
8 Correct 4 ms 428 KB Output is correct
9 Correct 6 ms 488 KB Output is correct
10 Correct 4 ms 460 KB Output is correct
11 Correct 4 ms 460 KB Output is correct
12 Correct 4 ms 460 KB Output is correct
13 Correct 4 ms 460 KB Output is correct
14 Correct 6 ms 460 KB Output is correct
15 Correct 6 ms 540 KB Output is correct
16 Correct 6 ms 460 KB Output is correct
17 Correct 6 ms 460 KB Output is correct
18 Correct 5 ms 460 KB Output is correct
19 Correct 16 ms 1220 KB Output is correct
20 Correct 18 ms 1264 KB Output is correct
21 Correct 18 ms 1296 KB Output is correct
22 Correct 18 ms 1288 KB Output is correct
23 Correct 17 ms 1264 KB Output is correct
24 Correct 23 ms 1164 KB Output is correct
25 Correct 25 ms 1164 KB Output is correct
26 Correct 18 ms 1132 KB Output is correct
27 Correct 17 ms 1264 KB Output is correct
28 Correct 18 ms 1256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 1644 KB Output is correct
2 Correct 71 ms 3312 KB Output is correct
3 Correct 121 ms 5584 KB Output is correct
4 Correct 126 ms 5588 KB Output is correct
5 Correct 124 ms 5568 KB Output is correct
6 Correct 121 ms 5504 KB Output is correct
7 Correct 121 ms 5596 KB Output is correct
8 Correct 125 ms 5560 KB Output is correct
9 Correct 129 ms 5588 KB Output is correct
10 Correct 118 ms 5672 KB Output is correct
11 Correct 115 ms 5556 KB Output is correct
12 Correct 122 ms 5560 KB Output is correct
13 Correct 121 ms 5560 KB Output is correct
14 Correct 124 ms 5660 KB Output is correct
15 Correct 113 ms 5668 KB Output is correct
16 Correct 110 ms 5596 KB Output is correct
17 Correct 117 ms 5660 KB Output is correct
18 Correct 113 ms 5560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 300 KB Output is correct
2 Correct 2 ms 408 KB Output is correct
3 Correct 5 ms 460 KB Output is correct
4 Correct 5 ms 548 KB Output is correct
5 Correct 4 ms 460 KB Output is correct
6 Correct 4 ms 460 KB Output is correct
7 Correct 4 ms 460 KB Output is correct
8 Correct 4 ms 428 KB Output is correct
9 Correct 6 ms 488 KB Output is correct
10 Correct 4 ms 460 KB Output is correct
11 Correct 4 ms 460 KB Output is correct
12 Correct 4 ms 460 KB Output is correct
13 Correct 4 ms 460 KB Output is correct
14 Correct 6 ms 460 KB Output is correct
15 Correct 6 ms 540 KB Output is correct
16 Correct 6 ms 460 KB Output is correct
17 Correct 6 ms 460 KB Output is correct
18 Correct 5 ms 460 KB Output is correct
19 Correct 16 ms 1220 KB Output is correct
20 Correct 18 ms 1264 KB Output is correct
21 Correct 18 ms 1296 KB Output is correct
22 Correct 18 ms 1288 KB Output is correct
23 Correct 17 ms 1264 KB Output is correct
24 Correct 23 ms 1164 KB Output is correct
25 Correct 25 ms 1164 KB Output is correct
26 Correct 18 ms 1132 KB Output is correct
27 Correct 17 ms 1264 KB Output is correct
28 Correct 18 ms 1256 KB Output is correct
29 Correct 25 ms 1644 KB Output is correct
30 Correct 71 ms 3312 KB Output is correct
31 Correct 121 ms 5584 KB Output is correct
32 Correct 126 ms 5588 KB Output is correct
33 Correct 124 ms 5568 KB Output is correct
34 Correct 121 ms 5504 KB Output is correct
35 Correct 121 ms 5596 KB Output is correct
36 Correct 125 ms 5560 KB Output is correct
37 Correct 129 ms 5588 KB Output is correct
38 Correct 118 ms 5672 KB Output is correct
39 Correct 115 ms 5556 KB Output is correct
40 Correct 122 ms 5560 KB Output is correct
41 Correct 121 ms 5560 KB Output is correct
42 Correct 124 ms 5660 KB Output is correct
43 Correct 113 ms 5668 KB Output is correct
44 Correct 110 ms 5596 KB Output is correct
45 Correct 117 ms 5660 KB Output is correct
46 Correct 113 ms 5560 KB Output is correct
47 Correct 446 ms 17240 KB Output is correct
48 Correct 1610 ms 41592 KB Output is correct
49 Correct 1832 ms 43372 KB Output is correct
50 Correct 1765 ms 43484 KB Output is correct
51 Correct 1815 ms 43448 KB Output is correct
52 Correct 1734 ms 43416 KB Output is correct
53 Correct 1780 ms 43480 KB Output is correct
54 Correct 1663 ms 43568 KB Output is correct
55 Correct 1791 ms 43544 KB Output is correct
56 Correct 1742 ms 43480 KB Output is correct
57 Correct 1694 ms 43460 KB Output is correct
58 Correct 1656 ms 43472 KB Output is correct
59 Correct 1558 ms 43544 KB Output is correct
60 Correct 1602 ms 43580 KB Output is correct
61 Correct 1699 ms 43536 KB Output is correct
62 Correct 1594 ms 43496 KB Output is correct
63 Correct 1542 ms 43572 KB Output is correct
64 Correct 1579 ms 43540 KB Output is correct
65 Correct 1564 ms 43532 KB Output is correct
66 Correct 1566 ms 43476 KB Output is correct
67 Correct 1560 ms 43584 KB Output is correct