답안 #956275

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
956275 2024-04-01T13:15:08 Z LucaIlie Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
3034 ms 129144 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>

using namespace std;

struct SegTree {
    int segLeft, segRight;
    vector<int> segTree;
    vector<int> lazy;

    void init( int l, int r  ) {
        segLeft = l;
        segRight = r;

        segTree.resize( 4 * (r - l + 1) );
        lazy.resize( 4 * (r - l + 1) );
    }

    void propag( int v, int l, int r ) {
        segTree[v] += lazy[v];
        if ( l != r ) {
            lazy[v * 2 + 1] += lazy[v];
            lazy[v * 2 + 2] += lazy[v];
        }
        lazy[v] = 0;
    }

    void update( int v, int l, int r, int lu, int ru, int x ) {
        propag( v, l, r );
        if ( l > ru || r < lu )
            return;

        if ( lu <= l && r <= ru ) {
            lazy[v] = x;
            propag( v, l, r );
            return;
        }

        int mid = (l + r) / 2;
        update( v * 2 + 1, l, mid, lu, ru, x );
        update( v * 2 + 2, mid + 1, r, lu, ru, x );
        segTree[v] = max( segTree[v * 2 + 1], segTree[v * 2 + 2] );
    }
    void update( int l, int r, int x ) {
        update( 0, segLeft, segRight, l, r, x );
    }

    int query() {
        return segTree[0];
    }
};

map<long long, int> values;
SegTree inversions;

vector<int> countScans( vector<int> A, vector<int> pos, vector<int> V ){
    int n = A.size(), q = V.size();
    vector<int> ans( q );
    vector<long long> a( n ), val( q );

    for ( int i = 0; i < n; i++ )
        values[(long long)A[i] * n + i] = 1;
    for ( int i = 0; i < q; i++ )
        values[(long long)V[i] * n + pos[i]] = 1;
    int m = 0;
    for ( auto p: values )
        values[p.first] = ++m;
    for ( int i = 0; i < n; i++ )
        a[i] = values[(long long)A[i] * n + i];
    for ( int i = 0; i < q; i++ )
        val[i] = values[(long long)V[i] * n + pos[i]];

    inversions.init( 1, m );
    for ( int i = 0; i < n; i++ ) {
        inversions.update( a[i], a[i], i );
        inversions.update( a[i] + 1, m, -1 );
    }

    for ( int u = 0; u < q; u++ ) {
        int i = pos[u];
        inversions.update( a[i], a[i], -i );
        inversions.update( a[i] + 1, m, 1 );
        a[i] = val[u];
        inversions.update( a[i], a[i], i );
        inversions.update( a[i] + 1, m, -1 );
        ans[u] = inversions.query();
    }

    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
3 Correct 5 ms 860 KB Output is correct
4 Correct 4 ms 856 KB Output is correct
5 Correct 4 ms 856 KB Output is correct
6 Correct 4 ms 856 KB Output is correct
7 Correct 4 ms 860 KB Output is correct
8 Correct 4 ms 860 KB Output is correct
9 Correct 4 ms 860 KB Output is correct
10 Correct 5 ms 848 KB Output is correct
11 Correct 4 ms 600 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 4 ms 604 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
3 Correct 5 ms 860 KB Output is correct
4 Correct 4 ms 856 KB Output is correct
5 Correct 4 ms 856 KB Output is correct
6 Correct 4 ms 856 KB Output is correct
7 Correct 4 ms 860 KB Output is correct
8 Correct 4 ms 860 KB Output is correct
9 Correct 4 ms 860 KB Output is correct
10 Correct 5 ms 848 KB Output is correct
11 Correct 4 ms 600 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 4 ms 604 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 1880 KB Output is correct
20 Correct 19 ms 2292 KB Output is correct
21 Correct 20 ms 2140 KB Output is correct
22 Correct 19 ms 2140 KB Output is correct
23 Correct 18 ms 2136 KB Output is correct
24 Correct 22 ms 2104 KB Output is correct
25 Correct 17 ms 1880 KB Output is correct
26 Correct 18 ms 1884 KB Output is correct
27 Correct 17 ms 2084 KB Output is correct
28 Correct 17 ms 1916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 3676 KB Output is correct
2 Correct 81 ms 7840 KB Output is correct
3 Correct 143 ms 12472 KB Output is correct
4 Correct 145 ms 12476 KB Output is correct
5 Correct 167 ms 12372 KB Output is correct
6 Correct 147 ms 12112 KB Output is correct
7 Correct 157 ms 12112 KB Output is correct
8 Correct 143 ms 12328 KB Output is correct
9 Correct 144 ms 12324 KB Output is correct
10 Correct 118 ms 8160 KB Output is correct
11 Correct 123 ms 8312 KB Output is correct
12 Correct 120 ms 8328 KB Output is correct
13 Correct 113 ms 8276 KB Output is correct
14 Correct 110 ms 8364 KB Output is correct
15 Correct 109 ms 8276 KB Output is correct
16 Correct 107 ms 8272 KB Output is correct
17 Correct 106 ms 8360 KB Output is correct
18 Correct 107 ms 8276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
3 Correct 5 ms 860 KB Output is correct
4 Correct 4 ms 856 KB Output is correct
5 Correct 4 ms 856 KB Output is correct
6 Correct 4 ms 856 KB Output is correct
7 Correct 4 ms 860 KB Output is correct
8 Correct 4 ms 860 KB Output is correct
9 Correct 4 ms 860 KB Output is correct
10 Correct 5 ms 848 KB Output is correct
11 Correct 4 ms 600 KB Output is correct
12 Correct 4 ms 604 KB Output is correct
13 Correct 4 ms 604 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 1880 KB Output is correct
20 Correct 19 ms 2292 KB Output is correct
21 Correct 20 ms 2140 KB Output is correct
22 Correct 19 ms 2140 KB Output is correct
23 Correct 18 ms 2136 KB Output is correct
24 Correct 22 ms 2104 KB Output is correct
25 Correct 17 ms 1880 KB Output is correct
26 Correct 18 ms 1884 KB Output is correct
27 Correct 17 ms 2084 KB Output is correct
28 Correct 17 ms 1916 KB Output is correct
29 Correct 27 ms 3676 KB Output is correct
30 Correct 81 ms 7840 KB Output is correct
31 Correct 143 ms 12472 KB Output is correct
32 Correct 145 ms 12476 KB Output is correct
33 Correct 167 ms 12372 KB Output is correct
34 Correct 147 ms 12112 KB Output is correct
35 Correct 157 ms 12112 KB Output is correct
36 Correct 143 ms 12328 KB Output is correct
37 Correct 144 ms 12324 KB Output is correct
38 Correct 118 ms 8160 KB Output is correct
39 Correct 123 ms 8312 KB Output is correct
40 Correct 120 ms 8328 KB Output is correct
41 Correct 113 ms 8276 KB Output is correct
42 Correct 110 ms 8364 KB Output is correct
43 Correct 109 ms 8276 KB Output is correct
44 Correct 107 ms 8272 KB Output is correct
45 Correct 106 ms 8360 KB Output is correct
46 Correct 107 ms 8276 KB Output is correct
47 Correct 581 ms 38256 KB Output is correct
48 Correct 2662 ms 117940 KB Output is correct
49 Correct 2965 ms 128796 KB Output is correct
50 Correct 3034 ms 128796 KB Output is correct
51 Correct 2950 ms 128804 KB Output is correct
52 Correct 3004 ms 129004 KB Output is correct
53 Correct 2970 ms 128804 KB Output is correct
54 Correct 2759 ms 129092 KB Output is correct
55 Correct 2876 ms 129144 KB Output is correct
56 Correct 2712 ms 128948 KB Output is correct
57 Correct 2704 ms 129088 KB Output is correct
58 Correct 2706 ms 128972 KB Output is correct
59 Correct 2419 ms 115892 KB Output is correct
60 Correct 2463 ms 116140 KB Output is correct
61 Correct 2485 ms 116012 KB Output is correct
62 Correct 2509 ms 109848 KB Output is correct
63 Correct 2383 ms 109864 KB Output is correct
64 Correct 2414 ms 110012 KB Output is correct
65 Correct 2318 ms 103912 KB Output is correct
66 Correct 2399 ms 103652 KB Output is correct
67 Correct 2294 ms 103848 KB Output is correct