답안 #1113579

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1113579 2024-11-16T18:40:13 Z jkb_gryz Bubble Sort 2 (JOI18_bubblesort2) C++14
38 / 100
21 ms 8052 KB
#include <bits/stdc++.h>
#include "bubblesort2.h"
 
using namespace std;
#define ll long long
 
const int base = 1<<20;
const ll INF = 1e18+7;
const ll MAXN = 1e6+7;
 
ll tree[base<<1];
ll lazy[base<<1];
int 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();
	int Q = X.size();
	vector<int> res(Q);
 
    vector<ll> skalowanie;
    for(auto i : A){
        skalowanie.push_back(i);
    }
    for(auto i : V){
        skalowanie.push_back(i);
    }
    
    sort(skalowanie.begin(), skalowanie.end());
    map<ll, ll> skalowanie2;
    for(ll i = 0; i < skalowanie.size(); ++i){
        if(skalowanie2[skalowanie[i]] == 0) skalowanie2[skalowanie[i]] = i+1;
    }
    ll id = skalowanie.size();

    p = 0, k = id;
    val = -INF;
    update(1, 1, id);

    for(ll i = 0; i < n; ++i){
        A[i] = skalowanie2[A[i]]++;
        p = 0, k = A[i]-1;
        val = 1;
        update(1, 1, id);
        p = k = A[i];
        val = INF + i; 
        update(1, 1, id);
    }

    for(ll i = 0; i < Q; ++i){
        p = 0, k = A[X[i]]-1;
        val = -1;
        update(1, 1, id);
        p = k = A[X[i]];
        val = -INF;
        update(1, 1, id);

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

        p = 0, k = A[X[i]]-1;
        val = 1;
        update(1, 1, id);
        p = k = A[X[i]];
        val = INF + X[i];
        update(1, 1, id);
        p = 0, k = id;
        res[i] = query(1, 1, id) - n + 1;
    }
 
	return res;
}

Compilation message

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:78:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for(ll i = 0; i < skalowanie.size(); ++i){
      |                   ~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2384 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 4 ms 2896 KB Output is correct
4 Correct 5 ms 2896 KB Output is correct
5 Correct 5 ms 2896 KB Output is correct
6 Correct 5 ms 2896 KB Output is correct
7 Correct 5 ms 2896 KB Output is correct
8 Correct 5 ms 2896 KB Output is correct
9 Correct 4 ms 2896 KB Output is correct
10 Correct 4 ms 2820 KB Output is correct
11 Correct 4 ms 2640 KB Output is correct
12 Correct 4 ms 2640 KB Output is correct
13 Correct 5 ms 2640 KB Output is correct
14 Correct 4 ms 2640 KB Output is correct
15 Correct 4 ms 2808 KB Output is correct
16 Correct 4 ms 2640 KB Output is correct
17 Correct 4 ms 2640 KB Output is correct
18 Correct 4 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2384 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 4 ms 2896 KB Output is correct
4 Correct 5 ms 2896 KB Output is correct
5 Correct 5 ms 2896 KB Output is correct
6 Correct 5 ms 2896 KB Output is correct
7 Correct 5 ms 2896 KB Output is correct
8 Correct 5 ms 2896 KB Output is correct
9 Correct 4 ms 2896 KB Output is correct
10 Correct 4 ms 2820 KB Output is correct
11 Correct 4 ms 2640 KB Output is correct
12 Correct 4 ms 2640 KB Output is correct
13 Correct 5 ms 2640 KB Output is correct
14 Correct 4 ms 2640 KB Output is correct
15 Correct 4 ms 2808 KB Output is correct
16 Correct 4 ms 2640 KB Output is correct
17 Correct 4 ms 2640 KB Output is correct
18 Correct 4 ms 2808 KB Output is correct
19 Correct 17 ms 7760 KB Output is correct
20 Correct 21 ms 8016 KB Output is correct
21 Correct 18 ms 8016 KB Output is correct
22 Correct 20 ms 8016 KB Output is correct
23 Correct 18 ms 7948 KB Output is correct
24 Correct 18 ms 8052 KB Output is correct
25 Correct 16 ms 7832 KB Output is correct
26 Correct 17 ms 7760 KB Output is correct
27 Correct 18 ms 7760 KB Output is correct
28 Correct 17 ms 7760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2384 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 4 ms 2896 KB Output is correct
4 Correct 5 ms 2896 KB Output is correct
5 Correct 5 ms 2896 KB Output is correct
6 Correct 5 ms 2896 KB Output is correct
7 Correct 5 ms 2896 KB Output is correct
8 Correct 5 ms 2896 KB Output is correct
9 Correct 4 ms 2896 KB Output is correct
10 Correct 4 ms 2820 KB Output is correct
11 Correct 4 ms 2640 KB Output is correct
12 Correct 4 ms 2640 KB Output is correct
13 Correct 5 ms 2640 KB Output is correct
14 Correct 4 ms 2640 KB Output is correct
15 Correct 4 ms 2808 KB Output is correct
16 Correct 4 ms 2640 KB Output is correct
17 Correct 4 ms 2640 KB Output is correct
18 Correct 4 ms 2808 KB Output is correct
19 Correct 17 ms 7760 KB Output is correct
20 Correct 21 ms 8016 KB Output is correct
21 Correct 18 ms 8016 KB Output is correct
22 Correct 20 ms 8016 KB Output is correct
23 Correct 18 ms 7948 KB Output is correct
24 Correct 18 ms 8052 KB Output is correct
25 Correct 16 ms 7832 KB Output is correct
26 Correct 17 ms 7760 KB Output is correct
27 Correct 18 ms 7760 KB Output is correct
28 Correct 17 ms 7760 KB Output is correct
29 Incorrect 16 ms 7380 KB Output isn't correct
30 Halted 0 ms 0 KB -