Submission #1091835

# Submission time Handle Problem Language Result Execution time Memory
1091835 2024-09-22T10:19:15 Z steveonalex Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
2278 ms 179716 KB
#include <bits/stdc++.h>
#include "bubblesort2.h"
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
#define block_of_code if(true)
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(a, b);}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
 
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
 
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
double rngesus_d(double l, double r){
    double cur = rngesus(0, MASK(60) - 1);
    cur /= MASK(60) - 1;
    return l + cur * (r - l);
}
 
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }
 
template <class T>
    void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: container) out << item << separator;
        out << finish;
    }
 
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

const int N = 5e5 + 69;
const int INF = 1e9 + 69;
 
int di(int x, int y){
    return x / y + (x % y > 0);
}
 
struct SegmentTree{
    int n;
    vector<int> a, lazy;
 
    SegmentTree(int _n){
        n = _n;
        a.resize(n * 4 + 4); lazy.resize(n * 4 + 4);
    }
 
    void update_node(int i, int v){
        a[i] += v;
        lazy[i] += v;
    }
 
    void down(int id){
        update_node(id * 2, lazy[id]); update_node(id * 2 + 1, lazy[id]);
        lazy[id] = 0;
    }
 
    void update(int u, int v, int val){if (u <= v) update(u, v, val, 0, n-1, 1);}
    void update(int u, int v, int val, int l, int r, int id){
        if (u <= l && r <= v){
            update_node(id, val);
            return;
        }
        if (lazy[id]) down(id);
        int mid = (l + r) >> 1;
        if (u <= mid) update(u, v, val, l, mid, id * 2);
        if (v > mid) update(u, v, val, mid + 1, r, id * 2 + 1);
        a[id] = max(a[id * 2], a[id * 2 + 1]);
    }
 
    int get(){return a[1];}
 
};

set<int> st[N * 2];
 
vector<int> countScans(vector<int> a,vector<int> X,vector<int> V){
    int n = a.size(), q = X.size();
 
    vector<int> b = a;
    for(int i: V) b.push_back(i);
    remove_dup(b);

    for(int &i: a) i = lower_bound(ALL(b), i) - b.begin();
    for(int &i: V) i = lower_bound(ALL(b), i) - b.begin();
    for(int i = 0; i < n; ++i){
        st[a[i]].insert(i);
    }


    int m = b.size();
        
    SegmentTree segg(m);
    for(int i = 0; i < m; ++i){
        st[i].insert(-INF);
        segg.update(i, i, *st[i].rbegin());
        segg.update(i, m - 1, -st[i].size() + 1);
    }

    vector<int> answer(q);
    for(int cur_query = 0; cur_query < q; ++cur_query){
        int i = X[cur_query], j = V[cur_query];
        segg.update(a[i], m - 1, 1);
        segg.update(a[i], a[i], -*st[a[i]].rbegin());
        st[a[i]].erase(i);
        segg.update(a[i], a[i], *st[a[i]].rbegin());

        a[i] = j;
        segg.update(a[i], m - 1, -1);
        segg.update(a[i], a[i], -*st[a[i]].rbegin());
        st[a[i]].insert(i);
        segg.update(a[i], a[i], *st[a[i]].rbegin());

        answer[cur_query] = segg.get() + 1;

    }
    
    
    
    return answer;
}
 
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47448 KB Output is correct
2 Correct 23 ms 47452 KB Output is correct
3 Correct 25 ms 47708 KB Output is correct
4 Correct 27 ms 47936 KB Output is correct
5 Correct 26 ms 47876 KB Output is correct
6 Correct 25 ms 47704 KB Output is correct
7 Correct 26 ms 47704 KB Output is correct
8 Correct 22 ms 47708 KB Output is correct
9 Correct 25 ms 47708 KB Output is correct
10 Correct 26 ms 47708 KB Output is correct
11 Correct 25 ms 47704 KB Output is correct
12 Correct 25 ms 47876 KB Output is correct
13 Correct 25 ms 47708 KB Output is correct
14 Correct 25 ms 47856 KB Output is correct
15 Correct 26 ms 47708 KB Output is correct
16 Correct 25 ms 47792 KB Output is correct
17 Correct 24 ms 47728 KB Output is correct
18 Correct 25 ms 47708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47448 KB Output is correct
2 Correct 23 ms 47452 KB Output is correct
3 Correct 25 ms 47708 KB Output is correct
4 Correct 27 ms 47936 KB Output is correct
5 Correct 26 ms 47876 KB Output is correct
6 Correct 25 ms 47704 KB Output is correct
7 Correct 26 ms 47704 KB Output is correct
8 Correct 22 ms 47708 KB Output is correct
9 Correct 25 ms 47708 KB Output is correct
10 Correct 26 ms 47708 KB Output is correct
11 Correct 25 ms 47704 KB Output is correct
12 Correct 25 ms 47876 KB Output is correct
13 Correct 25 ms 47708 KB Output is correct
14 Correct 25 ms 47856 KB Output is correct
15 Correct 26 ms 47708 KB Output is correct
16 Correct 25 ms 47792 KB Output is correct
17 Correct 24 ms 47728 KB Output is correct
18 Correct 25 ms 47708 KB Output is correct
19 Correct 44 ms 49160 KB Output is correct
20 Correct 41 ms 49492 KB Output is correct
21 Correct 54 ms 49428 KB Output is correct
22 Correct 44 ms 49488 KB Output is correct
23 Correct 39 ms 49232 KB Output is correct
24 Correct 38 ms 49240 KB Output is correct
25 Correct 37 ms 48988 KB Output is correct
26 Correct 38 ms 49244 KB Output is correct
27 Correct 39 ms 48980 KB Output is correct
28 Correct 38 ms 48936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 48976 KB Output is correct
2 Correct 61 ms 50616 KB Output is correct
3 Correct 87 ms 51848 KB Output is correct
4 Correct 88 ms 52064 KB Output is correct
5 Correct 85 ms 51856 KB Output is correct
6 Correct 87 ms 51948 KB Output is correct
7 Correct 94 ms 51852 KB Output is correct
8 Correct 83 ms 51936 KB Output is correct
9 Correct 83 ms 51852 KB Output is correct
10 Correct 70 ms 52108 KB Output is correct
11 Correct 77 ms 52112 KB Output is correct
12 Correct 73 ms 52060 KB Output is correct
13 Correct 67 ms 52112 KB Output is correct
14 Correct 68 ms 52068 KB Output is correct
15 Correct 71 ms 52056 KB Output is correct
16 Correct 63 ms 52024 KB Output is correct
17 Correct 65 ms 52116 KB Output is correct
18 Correct 66 ms 52112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47448 KB Output is correct
2 Correct 23 ms 47452 KB Output is correct
3 Correct 25 ms 47708 KB Output is correct
4 Correct 27 ms 47936 KB Output is correct
5 Correct 26 ms 47876 KB Output is correct
6 Correct 25 ms 47704 KB Output is correct
7 Correct 26 ms 47704 KB Output is correct
8 Correct 22 ms 47708 KB Output is correct
9 Correct 25 ms 47708 KB Output is correct
10 Correct 26 ms 47708 KB Output is correct
11 Correct 25 ms 47704 KB Output is correct
12 Correct 25 ms 47876 KB Output is correct
13 Correct 25 ms 47708 KB Output is correct
14 Correct 25 ms 47856 KB Output is correct
15 Correct 26 ms 47708 KB Output is correct
16 Correct 25 ms 47792 KB Output is correct
17 Correct 24 ms 47728 KB Output is correct
18 Correct 25 ms 47708 KB Output is correct
19 Correct 44 ms 49160 KB Output is correct
20 Correct 41 ms 49492 KB Output is correct
21 Correct 54 ms 49428 KB Output is correct
22 Correct 44 ms 49488 KB Output is correct
23 Correct 39 ms 49232 KB Output is correct
24 Correct 38 ms 49240 KB Output is correct
25 Correct 37 ms 48988 KB Output is correct
26 Correct 38 ms 49244 KB Output is correct
27 Correct 39 ms 48980 KB Output is correct
28 Correct 38 ms 48936 KB Output is correct
29 Correct 31 ms 48976 KB Output is correct
30 Correct 61 ms 50616 KB Output is correct
31 Correct 87 ms 51848 KB Output is correct
32 Correct 88 ms 52064 KB Output is correct
33 Correct 85 ms 51856 KB Output is correct
34 Correct 87 ms 51948 KB Output is correct
35 Correct 94 ms 51852 KB Output is correct
36 Correct 83 ms 51936 KB Output is correct
37 Correct 83 ms 51852 KB Output is correct
38 Correct 70 ms 52108 KB Output is correct
39 Correct 77 ms 52112 KB Output is correct
40 Correct 73 ms 52060 KB Output is correct
41 Correct 67 ms 52112 KB Output is correct
42 Correct 68 ms 52068 KB Output is correct
43 Correct 71 ms 52056 KB Output is correct
44 Correct 63 ms 52024 KB Output is correct
45 Correct 65 ms 52116 KB Output is correct
46 Correct 66 ms 52112 KB Output is correct
47 Correct 615 ms 86760 KB Output is correct
48 Correct 2153 ms 167104 KB Output is correct
49 Correct 2278 ms 179612 KB Output is correct
50 Correct 2086 ms 179596 KB Output is correct
51 Correct 2268 ms 179496 KB Output is correct
52 Correct 2257 ms 179376 KB Output is correct
53 Correct 2218 ms 179376 KB Output is correct
54 Correct 2115 ms 179620 KB Output is correct
55 Correct 2235 ms 179492 KB Output is correct
56 Correct 2205 ms 179716 KB Output is correct
57 Correct 2177 ms 179480 KB Output is correct
58 Correct 2087 ms 179632 KB Output is correct
59 Correct 1864 ms 168704 KB Output is correct
60 Correct 1831 ms 168884 KB Output is correct
61 Correct 1912 ms 168572 KB Output is correct
62 Correct 1756 ms 163620 KB Output is correct
63 Correct 1879 ms 163468 KB Output is correct
64 Correct 1824 ms 163664 KB Output is correct
65 Correct 1573 ms 158388 KB Output is correct
66 Correct 1645 ms 158616 KB Output is correct
67 Correct 1758 ms 158384 KB Output is correct