Submission #1113581

# Submission time Handle Problem Language Result Execution time Memory
1113581 2024-11-16T18:41:21 Z jkb_gryz Bubble Sort 2 (JOI18_bubblesort2) C++14
38 / 100
25 ms 8244 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()+7;

    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:77: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]
   77 |     for(ll i = 0; i < skalowanie.size(); ++i){
      |                   ~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2384 KB Output is correct
2 Correct 3 ms 2640 KB Output is correct
3 Correct 6 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 4 ms 3064 KB Output is correct
8 Correct 5 ms 2896 KB Output is correct
9 Correct 4 ms 2812 KB Output is correct
10 Correct 4 ms 2640 KB Output is correct
11 Correct 4 ms 2640 KB Output is correct
12 Correct 4 ms 2640 KB Output is correct
13 Correct 4 ms 2640 KB Output is correct
14 Correct 4 ms 2896 KB Output is correct
15 Correct 4 ms 2896 KB Output is correct
16 Correct 4 ms 2640 KB Output is correct
17 Correct 6 ms 2640 KB Output is correct
18 Correct 4 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2384 KB Output is correct
2 Correct 3 ms 2640 KB Output is correct
3 Correct 6 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 4 ms 3064 KB Output is correct
8 Correct 5 ms 2896 KB Output is correct
9 Correct 4 ms 2812 KB Output is correct
10 Correct 4 ms 2640 KB Output is correct
11 Correct 4 ms 2640 KB Output is correct
12 Correct 4 ms 2640 KB Output is correct
13 Correct 4 ms 2640 KB Output is correct
14 Correct 4 ms 2896 KB Output is correct
15 Correct 4 ms 2896 KB Output is correct
16 Correct 4 ms 2640 KB Output is correct
17 Correct 6 ms 2640 KB Output is correct
18 Correct 4 ms 2640 KB Output is correct
19 Correct 18 ms 7840 KB Output is correct
20 Correct 23 ms 8016 KB Output is correct
21 Correct 25 ms 8016 KB Output is correct
22 Correct 21 ms 8244 KB Output is correct
23 Correct 20 ms 7864 KB Output is correct
24 Correct 21 ms 8016 KB Output is correct
25 Correct 17 ms 7760 KB Output is correct
26 Correct 22 ms 7760 KB Output is correct
27 Correct 16 ms 7760 KB Output is correct
28 Correct 23 ms 8016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 7380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2384 KB Output is correct
2 Correct 3 ms 2640 KB Output is correct
3 Correct 6 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 4 ms 3064 KB Output is correct
8 Correct 5 ms 2896 KB Output is correct
9 Correct 4 ms 2812 KB Output is correct
10 Correct 4 ms 2640 KB Output is correct
11 Correct 4 ms 2640 KB Output is correct
12 Correct 4 ms 2640 KB Output is correct
13 Correct 4 ms 2640 KB Output is correct
14 Correct 4 ms 2896 KB Output is correct
15 Correct 4 ms 2896 KB Output is correct
16 Correct 4 ms 2640 KB Output is correct
17 Correct 6 ms 2640 KB Output is correct
18 Correct 4 ms 2640 KB Output is correct
19 Correct 18 ms 7840 KB Output is correct
20 Correct 23 ms 8016 KB Output is correct
21 Correct 25 ms 8016 KB Output is correct
22 Correct 21 ms 8244 KB Output is correct
23 Correct 20 ms 7864 KB Output is correct
24 Correct 21 ms 8016 KB Output is correct
25 Correct 17 ms 7760 KB Output is correct
26 Correct 22 ms 7760 KB Output is correct
27 Correct 16 ms 7760 KB Output is correct
28 Correct 23 ms 8016 KB Output is correct
29 Incorrect 20 ms 7380 KB Output isn't correct
30 Halted 0 ms 0 KB -