답안 #97788

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
97788 2019-02-18T13:27:32 Z Alexa2001 Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
7226 ms 114056 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>

#define mid ((st+dr)>>1)
#define left_son (node<<1)
#define right_son ((node<<1)|1)

using namespace std;

const int Nmax = 1e6 + 5, lim = 1e6, inf = 1e6;
typedef long long ll;

ll a[Nmax], val[Nmax];

class SegmentTree
{
    int lazy[Nmax<<2], a[Nmax<<2];

public:
    void add(int node, int st, int dr, int L, int R, int Add)
    {
        if(L <= st && dr <= R)
        {
            lazy[node] += Add;
            return;
        }

        if(L <= mid) add(left_son, st, mid, L, R, Add);
        if(mid < R) add(right_son, mid+1, dr, L, R, Add);

        a[node] = max(a[left_son] + lazy[left_son], a[right_son] + lazy[right_son]);
    }
    int query()
    {
        return a[1] + lazy[1];
    }
    void init(int node, int st, int dr)
    {
        a[node] = -inf; lazy[node] = 0;
        if(st == dr) return;
        init(left_son, st, mid); init(right_son, mid+1, dr);
    }

} aint;

vector<int> countScans(vector<int> A, vector<int> X, vector<int> V)
{
    int N = A.size(), i;
    int Q = V.size();
    map<ll, int> mp;

    for(i=0; i<N; ++i) a[i] = (ll) lim * A[i] + i;
    for(i=0; i<Q; ++i) val[i] = (ll) lim * V[i] + X[i];

    for(i=0; i<N; ++i) mp[a[i]] = 1;
    for(i=0; i<Q; ++i) mp[val[i]] = 1;
    int cnt = 0;
    for(auto &it : mp) it.second = ++cnt;

    aint.init(1, 1, cnt);

    for(i=0; i<N; ++i)
    {
        int pos = mp[a[i]];
        aint.add(1, 1, cnt, pos, pos, +inf+i);
        aint.add(1, 1, cnt, 1, pos, +1);
    }

    vector<int> answer(Q);
    for(i=0; i<Q; ++i)
    {
        int pos = mp[a[X[i]]];
        aint.add(1, 1, cnt, 1, pos, -1);
        aint.add(1, 1, cnt, pos, pos, -inf-X[i]);

        a[X[i]] = val[i];
        int act = mp[val[i]];
        aint.add(1, 1, cnt, act, act, +inf+X[i]);
        aint.add(1, 1, cnt, 1, act, 1);

        answer[i] = aint.query() - N;
    }
    return answer;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 640 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 9 ms 768 KB Output is correct
4 Correct 8 ms 768 KB Output is correct
5 Correct 7 ms 768 KB Output is correct
6 Correct 7 ms 768 KB Output is correct
7 Correct 8 ms 872 KB Output is correct
8 Correct 6 ms 768 KB Output is correct
9 Correct 8 ms 768 KB Output is correct
10 Correct 7 ms 768 KB Output is correct
11 Correct 7 ms 768 KB Output is correct
12 Correct 7 ms 768 KB Output is correct
13 Correct 7 ms 768 KB Output is correct
14 Correct 8 ms 768 KB Output is correct
15 Correct 8 ms 768 KB Output is correct
16 Correct 8 ms 768 KB Output is correct
17 Correct 7 ms 768 KB Output is correct
18 Correct 6 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 640 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 9 ms 768 KB Output is correct
4 Correct 8 ms 768 KB Output is correct
5 Correct 7 ms 768 KB Output is correct
6 Correct 7 ms 768 KB Output is correct
7 Correct 8 ms 872 KB Output is correct
8 Correct 6 ms 768 KB Output is correct
9 Correct 8 ms 768 KB Output is correct
10 Correct 7 ms 768 KB Output is correct
11 Correct 7 ms 768 KB Output is correct
12 Correct 7 ms 768 KB Output is correct
13 Correct 7 ms 768 KB Output is correct
14 Correct 8 ms 768 KB Output is correct
15 Correct 8 ms 768 KB Output is correct
16 Correct 8 ms 768 KB Output is correct
17 Correct 7 ms 768 KB Output is correct
18 Correct 6 ms 768 KB Output is correct
19 Correct 26 ms 2048 KB Output is correct
20 Correct 28 ms 2176 KB Output is correct
21 Correct 34 ms 2220 KB Output is correct
22 Correct 34 ms 2304 KB Output is correct
23 Correct 20 ms 2092 KB Output is correct
24 Correct 23 ms 2028 KB Output is correct
25 Correct 32 ms 1920 KB Output is correct
26 Correct 25 ms 1920 KB Output is correct
27 Correct 23 ms 1912 KB Output is correct
28 Correct 26 ms 2020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 3332 KB Output is correct
2 Correct 153 ms 7032 KB Output is correct
3 Correct 329 ms 11380 KB Output is correct
4 Correct 325 ms 11404 KB Output is correct
5 Correct 331 ms 11356 KB Output is correct
6 Correct 315 ms 11336 KB Output is correct
7 Correct 309 ms 11384 KB Output is correct
8 Correct 333 ms 11460 KB Output is correct
9 Correct 304 ms 11356 KB Output is correct
10 Correct 180 ms 7544 KB Output is correct
11 Correct 177 ms 7672 KB Output is correct
12 Correct 157 ms 7628 KB Output is correct
13 Correct 163 ms 7672 KB Output is correct
14 Correct 153 ms 7868 KB Output is correct
15 Correct 151 ms 7644 KB Output is correct
16 Correct 123 ms 7672 KB Output is correct
17 Correct 129 ms 7672 KB Output is correct
18 Correct 120 ms 7672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 640 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 9 ms 768 KB Output is correct
4 Correct 8 ms 768 KB Output is correct
5 Correct 7 ms 768 KB Output is correct
6 Correct 7 ms 768 KB Output is correct
7 Correct 8 ms 872 KB Output is correct
8 Correct 6 ms 768 KB Output is correct
9 Correct 8 ms 768 KB Output is correct
10 Correct 7 ms 768 KB Output is correct
11 Correct 7 ms 768 KB Output is correct
12 Correct 7 ms 768 KB Output is correct
13 Correct 7 ms 768 KB Output is correct
14 Correct 8 ms 768 KB Output is correct
15 Correct 8 ms 768 KB Output is correct
16 Correct 8 ms 768 KB Output is correct
17 Correct 7 ms 768 KB Output is correct
18 Correct 6 ms 768 KB Output is correct
19 Correct 26 ms 2048 KB Output is correct
20 Correct 28 ms 2176 KB Output is correct
21 Correct 34 ms 2220 KB Output is correct
22 Correct 34 ms 2304 KB Output is correct
23 Correct 20 ms 2092 KB Output is correct
24 Correct 23 ms 2028 KB Output is correct
25 Correct 32 ms 1920 KB Output is correct
26 Correct 25 ms 1920 KB Output is correct
27 Correct 23 ms 1912 KB Output is correct
28 Correct 26 ms 2020 KB Output is correct
29 Correct 45 ms 3332 KB Output is correct
30 Correct 153 ms 7032 KB Output is correct
31 Correct 329 ms 11380 KB Output is correct
32 Correct 325 ms 11404 KB Output is correct
33 Correct 331 ms 11356 KB Output is correct
34 Correct 315 ms 11336 KB Output is correct
35 Correct 309 ms 11384 KB Output is correct
36 Correct 333 ms 11460 KB Output is correct
37 Correct 304 ms 11356 KB Output is correct
38 Correct 180 ms 7544 KB Output is correct
39 Correct 177 ms 7672 KB Output is correct
40 Correct 157 ms 7628 KB Output is correct
41 Correct 163 ms 7672 KB Output is correct
42 Correct 153 ms 7868 KB Output is correct
43 Correct 151 ms 7644 KB Output is correct
44 Correct 123 ms 7672 KB Output is correct
45 Correct 129 ms 7672 KB Output is correct
46 Correct 120 ms 7672 KB Output is correct
47 Correct 1497 ms 37280 KB Output is correct
48 Correct 6556 ms 105788 KB Output is correct
49 Correct 6919 ms 113884 KB Output is correct
50 Correct 7182 ms 114004 KB Output is correct
51 Correct 7226 ms 113964 KB Output is correct
52 Correct 7225 ms 114000 KB Output is correct
53 Correct 6932 ms 113892 KB Output is correct
54 Correct 6706 ms 114056 KB Output is correct
55 Correct 7151 ms 111376 KB Output is correct
56 Correct 6684 ms 111480 KB Output is correct
57 Correct 6742 ms 111552 KB Output is correct
58 Correct 6287 ms 111372 KB Output is correct
59 Correct 5617 ms 103480 KB Output is correct
60 Correct 5275 ms 103572 KB Output is correct
61 Correct 5355 ms 103468 KB Output is correct
62 Correct 4778 ms 99832 KB Output is correct
63 Correct 4656 ms 99544 KB Output is correct
64 Correct 4858 ms 99588 KB Output is correct
65 Correct 4271 ms 95740 KB Output is correct
66 Correct 4454 ms 95708 KB Output is correct
67 Correct 4356 ms 95868 KB Output is correct