답안 #788229

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
788229 2023-07-20T02:52:37 Z Charizard2021 Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
1974 ms 51528 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 1000001;
vector<pair<int, int> > val;
int T[N << 2], SegTree[N << 2];
void push(int s, int l, int r) {
    if (!SegTree[s]){
        return;
    }
    T[s] += SegTree[s];
    if (l != r) {
        SegTree[s << 1] += SegTree[s];
        SegTree[s << 1 | 1] += SegTree[s];
    }
    SegTree[s] = 0;
}
void up(int s, int l, int r, int from, int to, int val) {
    push(s, l, r);
    if (l > to || r < from) return;
    if (from <= l && r <= to) {
        SegTree[s] += val;
        push(s, l, r);
        return;
    }
    int mid = l + r >> 1;
    up(s << 1, l, mid, from, to, val);
    up(s << 1 | 1, mid + 1, r, from, to, val);
    T[s] = max(T[s << 1], T[s << 1 | 1]);
}
vector<int> countScans(vector<int> a, vector<int> pos, vector<int> val2) {
    vector<int> ans(pos.size());
    int n = a.size();
    for(int i = 0; i < n; i++){
        val.push_back(make_pair(a[i], i));
    }
    for(int i = 0; i < pos.size(); i++){
        val.push_back(make_pair(val2[i], pos[i]));
    }
    sort(val.begin(), val.end());
    val.resize(unique(val.begin(), val.end()) - val.begin());
    int m = val.size();
    for(int i = 0; i < n; i++) {
        int idx = upper_bound(val.begin(), val.end(), make_pair(a[i], i)) - val.begin();
        up(1, 1, m, idx, idx, i + 1);
        up(1, 1, m, idx, m, -1);
    }
    for(int i = 0; i < pos.size(); i++) {
        int idx = upper_bound(val.begin(), val.end(), make_pair(a[pos[i]], pos[i])) - val.begin();
        up(1, 1, m, idx, idx, -pos[i] - 1);
        up(1, 1, m, idx, m, 1);
        a[pos[i]] = val2[i];
        idx = upper_bound(val.begin(), val.end(), make_pair(val2[i], pos[i])) - val.begin();
        up(1, 1, m, idx, idx, pos[i] + 1);
        up(1, 1, m, idx, m, -1);
        ans[i] = T[1];
    }
    return ans;
}

Compilation message

bubblesort2.cpp: In function 'void up(int, int, int, int, int, int)':
bubblesort2.cpp:25:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   25 |     int mid = l + r >> 1;
      |               ~~^~~
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:36:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i = 0; i < pos.size(); i++){
      |                    ~~^~~~~~~~~~~~
bubblesort2.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for(int i = 0; i < pos.size(); i++) {
      |                    ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 4 ms 548 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 4 ms 468 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 4 ms 452 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 6 ms 536 KB Output is correct
13 Correct 4 ms 544 KB Output is correct
14 Correct 4 ms 468 KB Output is correct
15 Correct 6 ms 452 KB Output is correct
16 Correct 4 ms 448 KB Output is correct
17 Correct 5 ms 468 KB Output is correct
18 Correct 4 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 4 ms 548 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 4 ms 468 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 4 ms 452 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 6 ms 536 KB Output is correct
13 Correct 4 ms 544 KB Output is correct
14 Correct 4 ms 468 KB Output is correct
15 Correct 6 ms 452 KB Output is correct
16 Correct 4 ms 448 KB Output is correct
17 Correct 5 ms 468 KB Output is correct
18 Correct 4 ms 468 KB Output is correct
19 Correct 15 ms 1212 KB Output is correct
20 Correct 16 ms 1216 KB Output is correct
21 Correct 18 ms 1244 KB Output is correct
22 Correct 17 ms 1192 KB Output is correct
23 Correct 15 ms 1236 KB Output is correct
24 Correct 15 ms 1228 KB Output is correct
25 Correct 15 ms 1224 KB Output is correct
26 Correct 15 ms 1220 KB Output is correct
27 Correct 17 ms 1212 KB Output is correct
28 Correct 15 ms 1204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 1552 KB Output is correct
2 Correct 64 ms 3056 KB Output is correct
3 Correct 113 ms 5208 KB Output is correct
4 Correct 132 ms 5220 KB Output is correct
5 Correct 134 ms 5232 KB Output is correct
6 Correct 112 ms 5228 KB Output is correct
7 Correct 113 ms 5228 KB Output is correct
8 Correct 111 ms 5208 KB Output is correct
9 Correct 112 ms 5240 KB Output is correct
10 Correct 90 ms 4288 KB Output is correct
11 Correct 91 ms 4288 KB Output is correct
12 Correct 91 ms 4212 KB Output is correct
13 Correct 89 ms 4228 KB Output is correct
14 Correct 90 ms 4216 KB Output is correct
15 Correct 100 ms 4192 KB Output is correct
16 Correct 96 ms 4264 KB Output is correct
17 Correct 87 ms 4180 KB Output is correct
18 Correct 86 ms 4156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 4 ms 548 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 4 ms 468 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 4 ms 452 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 6 ms 536 KB Output is correct
13 Correct 4 ms 544 KB Output is correct
14 Correct 4 ms 468 KB Output is correct
15 Correct 6 ms 452 KB Output is correct
16 Correct 4 ms 448 KB Output is correct
17 Correct 5 ms 468 KB Output is correct
18 Correct 4 ms 468 KB Output is correct
19 Correct 15 ms 1212 KB Output is correct
20 Correct 16 ms 1216 KB Output is correct
21 Correct 18 ms 1244 KB Output is correct
22 Correct 17 ms 1192 KB Output is correct
23 Correct 15 ms 1236 KB Output is correct
24 Correct 15 ms 1228 KB Output is correct
25 Correct 15 ms 1224 KB Output is correct
26 Correct 15 ms 1220 KB Output is correct
27 Correct 17 ms 1212 KB Output is correct
28 Correct 15 ms 1204 KB Output is correct
29 Correct 25 ms 1552 KB Output is correct
30 Correct 64 ms 3056 KB Output is correct
31 Correct 113 ms 5208 KB Output is correct
32 Correct 132 ms 5220 KB Output is correct
33 Correct 134 ms 5232 KB Output is correct
34 Correct 112 ms 5228 KB Output is correct
35 Correct 113 ms 5228 KB Output is correct
36 Correct 111 ms 5208 KB Output is correct
37 Correct 112 ms 5240 KB Output is correct
38 Correct 90 ms 4288 KB Output is correct
39 Correct 91 ms 4288 KB Output is correct
40 Correct 91 ms 4212 KB Output is correct
41 Correct 89 ms 4228 KB Output is correct
42 Correct 90 ms 4216 KB Output is correct
43 Correct 100 ms 4192 KB Output is correct
44 Correct 96 ms 4264 KB Output is correct
45 Correct 87 ms 4180 KB Output is correct
46 Correct 86 ms 4156 KB Output is correct
47 Correct 423 ms 18648 KB Output is correct
48 Correct 1803 ms 48788 KB Output is correct
49 Correct 1935 ms 51316 KB Output is correct
50 Correct 1928 ms 51268 KB Output is correct
51 Correct 1974 ms 51264 KB Output is correct
52 Correct 1939 ms 51264 KB Output is correct
53 Correct 1953 ms 51268 KB Output is correct
54 Correct 1713 ms 51364 KB Output is correct
55 Correct 1920 ms 51456 KB Output is correct
56 Correct 1783 ms 51412 KB Output is correct
57 Correct 1768 ms 51528 KB Output is correct
58 Correct 1684 ms 51408 KB Output is correct
59 Correct 1492 ms 50104 KB Output is correct
60 Correct 1562 ms 50100 KB Output is correct
61 Correct 1574 ms 50084 KB Output is correct
62 Correct 1516 ms 49820 KB Output is correct
63 Correct 1504 ms 49948 KB Output is correct
64 Correct 1498 ms 49956 KB Output is correct
65 Correct 1379 ms 49864 KB Output is correct
66 Correct 1372 ms 49916 KB Output is correct
67 Correct 1429 ms 49804 KB Output is correct