Submission #956274

# Submission time Handle Problem Language Result Execution time Memory
956274 2024-04-01T13:11:59 Z LucaIlie Bubble Sort 2 (JOI18_bubblesort2) C++17
38 / 100
28 ms 3672 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 + n - 1 - i] = 1;
    for ( int i = 0; i < q; i++ )
        values[(long long)V[i] * n + n - 1 - 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 + n - 1 - i];
    for ( int i = 0; i < q; i++ )
        val[i] = values[(long long)V[i] * n + n - 1 - 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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 4 ms 936 KB Output is correct
4 Correct 4 ms 856 KB Output is correct
5 Correct 4 ms 704 KB Output is correct
6 Correct 4 ms 860 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 4 ms 860 KB Output is correct
11 Correct 4 ms 836 KB Output is correct
12 Correct 4 ms 860 KB Output is correct
13 Correct 4 ms 864 KB Output is correct
14 Correct 6 ms 1108 KB Output is correct
15 Correct 4 ms 860 KB Output is correct
16 Correct 4 ms 604 KB Output is correct
17 Correct 4 ms 604 KB Output is correct
18 Correct 5 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 4 ms 936 KB Output is correct
4 Correct 4 ms 856 KB Output is correct
5 Correct 4 ms 704 KB Output is correct
6 Correct 4 ms 860 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 4 ms 860 KB Output is correct
11 Correct 4 ms 836 KB Output is correct
12 Correct 4 ms 860 KB Output is correct
13 Correct 4 ms 864 KB Output is correct
14 Correct 6 ms 1108 KB Output is correct
15 Correct 4 ms 860 KB Output is correct
16 Correct 4 ms 604 KB Output is correct
17 Correct 4 ms 604 KB Output is correct
18 Correct 5 ms 604 KB Output is correct
19 Correct 16 ms 2136 KB Output is correct
20 Correct 20 ms 2392 KB Output is correct
21 Correct 19 ms 2488 KB Output is correct
22 Correct 19 ms 2396 KB Output is correct
23 Correct 18 ms 2268 KB Output is correct
24 Correct 18 ms 2136 KB Output is correct
25 Correct 18 ms 2144 KB Output is correct
26 Correct 17 ms 2140 KB Output is correct
27 Correct 17 ms 2080 KB Output is correct
28 Correct 17 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 3672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 4 ms 936 KB Output is correct
4 Correct 4 ms 856 KB Output is correct
5 Correct 4 ms 704 KB Output is correct
6 Correct 4 ms 860 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 4 ms 860 KB Output is correct
11 Correct 4 ms 836 KB Output is correct
12 Correct 4 ms 860 KB Output is correct
13 Correct 4 ms 864 KB Output is correct
14 Correct 6 ms 1108 KB Output is correct
15 Correct 4 ms 860 KB Output is correct
16 Correct 4 ms 604 KB Output is correct
17 Correct 4 ms 604 KB Output is correct
18 Correct 5 ms 604 KB Output is correct
19 Correct 16 ms 2136 KB Output is correct
20 Correct 20 ms 2392 KB Output is correct
21 Correct 19 ms 2488 KB Output is correct
22 Correct 19 ms 2396 KB Output is correct
23 Correct 18 ms 2268 KB Output is correct
24 Correct 18 ms 2136 KB Output is correct
25 Correct 18 ms 2144 KB Output is correct
26 Correct 17 ms 2140 KB Output is correct
27 Correct 17 ms 2080 KB Output is correct
28 Correct 17 ms 1884 KB Output is correct
29 Incorrect 28 ms 3672 KB Output isn't correct
30 Halted 0 ms 0 KB -