답안 #204728

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
204728 2020-02-26T18:52:31 Z Kastanda Bubble Sort 2 (JOI18_bubblesort2) C++11
100 / 100
2575 ms 53668 KB
// In The Name Of The Queen
#include<bits/stdc++.h>
#include "bubblesort2.h"
#define lc (id << 1)
#define rc (lc ^ 1)
#define md (l + r >> 1)
using namespace std;
const int N = 500005, MXS = N * 2 * 4;
int n, q, MX[MXS], LZ[MXS];
vector < pair < int , int > > U;
void Add(int le, int ri, int val, int id = 1, int l = 0, int r = (int)U.size())
{
    if (ri <= l || r <= le)
        return ;
    if (le <= l && r <= ri)
    {
        MX[id] += val;
        LZ[id] += val;
        return ;
    }
    Add(le, ri, val, lc, l, md);
    Add(le, ri, val, rc, md, r);
    MX[id] = max(MX[lc], MX[rc]) + LZ[id];
}
vector < int > countScans(vector < int > A, vector < int > X, vector < int > V)
{
    n = (int)A.size();
    q = (int)X.size();
    for (int i = 0; i < n; i ++)
        U.push_back({A[i], i});
    for (int i = 0; i < q; i ++)
        U.push_back({V[i], X[i]});
    sort(U.begin(), U.end());
    U.resize(unique(U.begin(), U.end()) - U.begin());

    auto GetId = [&] (pair < int , int > val) {
        return (int)(lower_bound(U.begin(), U.end(), val) - U.begin());
    };

    auto Apply = [&] (int i, int val) {
        int p = GetId({A[i], i});
        Add(p, p + 1, (i + 1) * val);
        int l = GetId({A[i], -1});
        Add(l, (int)U.size(), -val);
    };

    for (int i = 0; i < n; i ++)
        Apply(i, 1);
    vector < int > R;
    for (int i = 0; i < q; i ++)
    {
        Apply(X[i], -1);
        A[X[i]] = V[i];
        Apply(X[i], 1);
        R.push_back(MX[1]);
    }
    return (R);
}

Compilation message

bubblesort2.cpp: In function 'void Add(int, int, int, int, int, int)':
bubblesort2.cpp:6:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
 #define md (l + r >> 1)
             ~~^~~
bubblesort2.cpp:21:29: note: in expansion of macro 'md'
     Add(le, ri, val, lc, l, md);
                             ^~
bubblesort2.cpp:6:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
 #define md (l + r >> 1)
             ~~^~~
bubblesort2.cpp:22:26: note: in expansion of macro 'md'
     Add(le, ri, val, rc, md, r);
                          ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 7 ms 376 KB Output is correct
3 Correct 10 ms 504 KB Output is correct
4 Correct 9 ms 504 KB Output is correct
5 Correct 10 ms 504 KB Output is correct
6 Correct 9 ms 628 KB Output is correct
7 Correct 9 ms 504 KB Output is correct
8 Correct 9 ms 508 KB Output is correct
9 Correct 9 ms 504 KB Output is correct
10 Correct 9 ms 504 KB Output is correct
11 Correct 9 ms 504 KB Output is correct
12 Correct 9 ms 504 KB Output is correct
13 Correct 10 ms 508 KB Output is correct
14 Correct 9 ms 632 KB Output is correct
15 Correct 9 ms 504 KB Output is correct
16 Correct 9 ms 504 KB Output is correct
17 Correct 9 ms 504 KB Output is correct
18 Correct 9 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 7 ms 376 KB Output is correct
3 Correct 10 ms 504 KB Output is correct
4 Correct 9 ms 504 KB Output is correct
5 Correct 10 ms 504 KB Output is correct
6 Correct 9 ms 628 KB Output is correct
7 Correct 9 ms 504 KB Output is correct
8 Correct 9 ms 508 KB Output is correct
9 Correct 9 ms 504 KB Output is correct
10 Correct 9 ms 504 KB Output is correct
11 Correct 9 ms 504 KB Output is correct
12 Correct 9 ms 504 KB Output is correct
13 Correct 10 ms 508 KB Output is correct
14 Correct 9 ms 632 KB Output is correct
15 Correct 9 ms 504 KB Output is correct
16 Correct 9 ms 504 KB Output is correct
17 Correct 9 ms 504 KB Output is correct
18 Correct 9 ms 504 KB Output is correct
19 Correct 23 ms 1144 KB Output is correct
20 Correct 26 ms 1400 KB Output is correct
21 Correct 26 ms 1272 KB Output is correct
22 Correct 25 ms 1272 KB Output is correct
23 Correct 24 ms 1272 KB Output is correct
24 Correct 24 ms 1272 KB Output is correct
25 Correct 26 ms 1272 KB Output is correct
26 Correct 24 ms 1272 KB Output is correct
27 Correct 24 ms 1272 KB Output is correct
28 Correct 23 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 1396 KB Output is correct
2 Correct 84 ms 3156 KB Output is correct
3 Correct 153 ms 5356 KB Output is correct
4 Correct 143 ms 5356 KB Output is correct
5 Correct 156 ms 5356 KB Output is correct
6 Correct 144 ms 5356 KB Output is correct
7 Correct 160 ms 5356 KB Output is correct
8 Correct 140 ms 5356 KB Output is correct
9 Correct 147 ms 5356 KB Output is correct
10 Correct 112 ms 4332 KB Output is correct
11 Correct 110 ms 4308 KB Output is correct
12 Correct 116 ms 4332 KB Output is correct
13 Correct 116 ms 4332 KB Output is correct
14 Correct 111 ms 4332 KB Output is correct
15 Correct 118 ms 4332 KB Output is correct
16 Correct 116 ms 4332 KB Output is correct
17 Correct 110 ms 4332 KB Output is correct
18 Correct 108 ms 4436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 7 ms 376 KB Output is correct
3 Correct 10 ms 504 KB Output is correct
4 Correct 9 ms 504 KB Output is correct
5 Correct 10 ms 504 KB Output is correct
6 Correct 9 ms 628 KB Output is correct
7 Correct 9 ms 504 KB Output is correct
8 Correct 9 ms 508 KB Output is correct
9 Correct 9 ms 504 KB Output is correct
10 Correct 9 ms 504 KB Output is correct
11 Correct 9 ms 504 KB Output is correct
12 Correct 9 ms 504 KB Output is correct
13 Correct 10 ms 508 KB Output is correct
14 Correct 9 ms 632 KB Output is correct
15 Correct 9 ms 504 KB Output is correct
16 Correct 9 ms 504 KB Output is correct
17 Correct 9 ms 504 KB Output is correct
18 Correct 9 ms 504 KB Output is correct
19 Correct 23 ms 1144 KB Output is correct
20 Correct 26 ms 1400 KB Output is correct
21 Correct 26 ms 1272 KB Output is correct
22 Correct 25 ms 1272 KB Output is correct
23 Correct 24 ms 1272 KB Output is correct
24 Correct 24 ms 1272 KB Output is correct
25 Correct 26 ms 1272 KB Output is correct
26 Correct 24 ms 1272 KB Output is correct
27 Correct 24 ms 1272 KB Output is correct
28 Correct 23 ms 1272 KB Output is correct
29 Correct 29 ms 1396 KB Output is correct
30 Correct 84 ms 3156 KB Output is correct
31 Correct 153 ms 5356 KB Output is correct
32 Correct 143 ms 5356 KB Output is correct
33 Correct 156 ms 5356 KB Output is correct
34 Correct 144 ms 5356 KB Output is correct
35 Correct 160 ms 5356 KB Output is correct
36 Correct 140 ms 5356 KB Output is correct
37 Correct 147 ms 5356 KB Output is correct
38 Correct 112 ms 4332 KB Output is correct
39 Correct 110 ms 4308 KB Output is correct
40 Correct 116 ms 4332 KB Output is correct
41 Correct 116 ms 4332 KB Output is correct
42 Correct 111 ms 4332 KB Output is correct
43 Correct 118 ms 4332 KB Output is correct
44 Correct 116 ms 4332 KB Output is correct
45 Correct 110 ms 4332 KB Output is correct
46 Correct 108 ms 4436 KB Output is correct
47 Correct 594 ms 19552 KB Output is correct
48 Correct 2316 ms 50912 KB Output is correct
49 Correct 2523 ms 53460 KB Output is correct
50 Correct 2575 ms 53204 KB Output is correct
51 Correct 2535 ms 53460 KB Output is correct
52 Correct 2560 ms 53332 KB Output is correct
53 Correct 2557 ms 53460 KB Output is correct
54 Correct 2328 ms 53332 KB Output is correct
55 Correct 2426 ms 53588 KB Output is correct
56 Correct 2244 ms 53668 KB Output is correct
57 Correct 2369 ms 53660 KB Output is correct
58 Correct 2232 ms 53588 KB Output is correct
59 Correct 2054 ms 52312 KB Output is correct
60 Correct 2100 ms 52136 KB Output is correct
61 Correct 2112 ms 52184 KB Output is correct
62 Correct 2005 ms 52048 KB Output is correct
63 Correct 2009 ms 51924 KB Output is correct
64 Correct 1974 ms 52044 KB Output is correct
65 Correct 1870 ms 51956 KB Output is correct
66 Correct 1868 ms 51824 KB Output is correct
67 Correct 1871 ms 52052 KB Output is correct