답안 #1113515

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1113515 2024-11-16T17:20:26 Z jkb_gryz Bubble Sort 2 (JOI18_bubblesort2) C++14
17 / 100
9000 ms 7760 KB
#include <bits/stdc++.h>
#include "bubblesort2.h"

using namespace std;
#define ll long long

const ll base = 1<<20;
const ll INF = 1e18+7;

ll tree[base<<1];
ll lazy[base<<1];
ll n;

void push(ll v){
    lazy[2*v] += lazy[v];
    lazy[2*v+1] += lazy[v];
    
    tree[2*v] += lazy[v];
    tree[2*v+1] += lazy[v];

    lazy[v] = 0;
}

ll p, k;
ll val;

void update(ll v, ll l, ll r){
    if(l > k || r < p) return;
    if(p <= l && r <= k){
        tree[v] += val;
        lazy[v] += val;
    }
    else{
        ll mid = (l+r)/2;

        push(v);

        update(2*v, l, mid);
        update(2*v+1, mid+1, r);

        tree[v] = max(tree[2*v], tree[2*v+1]);
    }
}

ll query(ll v, ll l, ll r){
    if(l > k || r < p) return -INF;
    if(p <= l && r <= k){
        return tree[v];
    }
    else{
        ll mid = (l+r)/2;

        push(v);

        auto lQ = query(2*v, l, mid);
        auto rQ = query(2*v+1, mid+1, r);
        return max(lQ, rQ);
    }
}


vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){
    n = A.size();
	ll Q = X.size();
	vector<int> res(Q);

    map<long long, ll> skalowanie;
    for(auto i : A){
        skalowanie[i] = 0;
    }
    for(auto i : V){
        skalowanie[i] = 0;
    }
    ll id = 0;

    for(auto &i : skalowanie) i.second = ++id;
    
    for(ll i = 0; i < n; ++i){
        auto vi = A[i];
        p = 0, k = skalowanie[vi]-1;
        val = 1;
        update(1, 1, id);
    }
    
    for(ll i = 0; i < Q; ++i){
        p = 0, k = skalowanie[A[X[i]]]-1;
        val = -1;
        update(1, 1, id);

        A[X[i]] = V[i];

        p = 0, k = skalowanie[V[i]]-1;
        val = 1;
        update(1, 1, id);
        
        for(ll j = 0; j < n; ++j){
            p = k = skalowanie[A[j]];
            // cerr << query(1, 1, n) << " ";
            res[i] = max((ll)(res[i]), query(1, 1, id) - (n - j - 1));
        }
        // cerr << "\n";
    }

	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 2384 KB Output is correct
2 Correct 78 ms 2640 KB Output is correct
3 Correct 804 ms 2844 KB Output is correct
4 Correct 805 ms 2848 KB Output is correct
5 Correct 778 ms 2888 KB Output is correct
6 Correct 658 ms 2860 KB Output is correct
7 Correct 725 ms 2904 KB Output is correct
8 Correct 730 ms 2896 KB Output is correct
9 Correct 769 ms 2896 KB Output is correct
10 Correct 681 ms 2896 KB Output is correct
11 Correct 677 ms 2816 KB Output is correct
12 Correct 679 ms 2820 KB Output is correct
13 Correct 682 ms 2640 KB Output is correct
14 Correct 682 ms 2852 KB Output is correct
15 Correct 696 ms 2808 KB Output is correct
16 Correct 667 ms 2836 KB Output is correct
17 Correct 650 ms 2792 KB Output is correct
18 Correct 644 ms 2824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 2384 KB Output is correct
2 Correct 78 ms 2640 KB Output is correct
3 Correct 804 ms 2844 KB Output is correct
4 Correct 805 ms 2848 KB Output is correct
5 Correct 778 ms 2888 KB Output is correct
6 Correct 658 ms 2860 KB Output is correct
7 Correct 725 ms 2904 KB Output is correct
8 Correct 730 ms 2896 KB Output is correct
9 Correct 769 ms 2896 KB Output is correct
10 Correct 681 ms 2896 KB Output is correct
11 Correct 677 ms 2816 KB Output is correct
12 Correct 679 ms 2820 KB Output is correct
13 Correct 682 ms 2640 KB Output is correct
14 Correct 682 ms 2852 KB Output is correct
15 Correct 696 ms 2808 KB Output is correct
16 Correct 667 ms 2836 KB Output is correct
17 Correct 650 ms 2792 KB Output is correct
18 Correct 644 ms 2824 KB Output is correct
19 Execution timed out 9044 ms 7760 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4982 ms 2748 KB Output is correct
2 Execution timed out 9063 ms 3152 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 2384 KB Output is correct
2 Correct 78 ms 2640 KB Output is correct
3 Correct 804 ms 2844 KB Output is correct
4 Correct 805 ms 2848 KB Output is correct
5 Correct 778 ms 2888 KB Output is correct
6 Correct 658 ms 2860 KB Output is correct
7 Correct 725 ms 2904 KB Output is correct
8 Correct 730 ms 2896 KB Output is correct
9 Correct 769 ms 2896 KB Output is correct
10 Correct 681 ms 2896 KB Output is correct
11 Correct 677 ms 2816 KB Output is correct
12 Correct 679 ms 2820 KB Output is correct
13 Correct 682 ms 2640 KB Output is correct
14 Correct 682 ms 2852 KB Output is correct
15 Correct 696 ms 2808 KB Output is correct
16 Correct 667 ms 2836 KB Output is correct
17 Correct 650 ms 2792 KB Output is correct
18 Correct 644 ms 2824 KB Output is correct
19 Execution timed out 9044 ms 7760 KB Time limit exceeded
20 Halted 0 ms 0 KB -