Submission #156816

# Submission time Handle Problem Language Result Execution time Memory
156816 2019-10-07T14:54:26 Z georgerapeanu Bubble Sort 2 (JOI18_bubblesort2) C++11
60 / 100
1759 ms 312272 KB
#include "bubblesort2.h"
#pragma once
#include <vector>
#include <map>
#include <algorithm>
#include <set>

using namespace std;

const int NMAX = 5e5;
const int inf = 1 << 28;

int aint[4 * NMAX + 5];
int cnt_less[4 * NMAX + 5];
int lazy[4 * NMAX + 5];
set<int> wh[4 * NMAX + 5];

void propag(int nod,int st,int dr){
    if(lazy[nod] == 0 || st == dr){
        return ;
    }

    aint[2 * nod] -= lazy[nod];
    cnt_less[2 * nod] += lazy[nod];
    lazy[2 * nod] += lazy[nod];
    
    aint[2 * nod + 1] -= lazy[nod];
    cnt_less[2 * nod + 1] += lazy[nod];
    lazy[2 * nod + 1] += lazy[nod];

    lazy[nod] = 0;
}

void update(int nod,int st,int dr,int pos,int val,bool mode){
    propag(nod,st,dr);

    if(dr < pos || st > pos){
        return ;
    }

    if(st == dr){
        if(mode == false){
           wh[nod].erase(val); 
        }
        else{
            wh[nod].insert(val);
        }

        aint[nod] = (wh[nod].empty() ? -inf:*wh[nod].rbegin()) - cnt_less[nod];
        return ;
    }

    int mid = (st + dr) / 2;

    update(nod * 2,st,mid,pos,val,mode);
    update(nod * 2 + 1,mid + 1,dr,pos,val,mode);

    aint[nod] = max(aint[nod * 2],aint[nod * 2 + 1]);
}

void add_range(int nod,int st,int dr,int l,int r,int val){
    propag(nod,st,dr);

    if(dr < l || st > r){
        return ;
    }

    if(l <= st && dr <= r){
        cnt_less[nod] += val;
        aint[nod] -= val;
        lazy[nod] += val;
        return ;
    }

    int mid = (st + dr) / 2;

    add_range(nod * 2,st,mid,l,r,val);
    add_range(nod * 2 + 1,mid + 1,dr,l,r,val);

    aint[nod] = max(aint[nod * 2],aint[nod * 2 + 1]);
}

vector<int> countScans(vector<int> A,vector<int> X,vector<int> V){

    map<int,int> to_norm;

    for(auto it:A){
        to_norm[it] = 1;
    }
    
    for(auto it:V){
        to_norm[it] = 1;
    }

    int lst = 0;

    for(auto &it:to_norm){
        it.second = ++lst;
    }

    for(int i = 0;i < (int)A.size();i++){
        update(1,1,lst,to_norm[A[i]],i + 1,1);
        add_range(1,1,lst,to_norm[A[i]],lst,1);
    }

    vector<int> answer;

    for(int i = 0;i < (int)X.size();i++){
        add_range(1,1,lst,to_norm[A[X[i]]],lst,-1);
        update(1,1,lst,to_norm[A[X[i]]],X[i] + 1,false);
        update(1,1,lst,to_norm[V[i]],X[i] + 1,true);
        add_range(1,1,lst,to_norm[V[i]],lst,1);
        A[X[i]] = V[i];

        answer.push_back(aint[1]);
    }

    return answer;
}

Compilation message

bubblesort2.cpp:2:9: warning: #pragma once in main file
 #pragma once
         ^~~~
# Verdict Execution time Memory Grader output
1 Correct 103 ms 94464 KB Output is correct
2 Correct 93 ms 94452 KB Output is correct
3 Correct 96 ms 94768 KB Output is correct
4 Correct 95 ms 94712 KB Output is correct
5 Correct 96 ms 94788 KB Output is correct
6 Correct 96 ms 94688 KB Output is correct
7 Correct 95 ms 94720 KB Output is correct
8 Correct 98 ms 94712 KB Output is correct
9 Correct 96 ms 94816 KB Output is correct
10 Correct 95 ms 94732 KB Output is correct
11 Correct 97 ms 94816 KB Output is correct
12 Correct 95 ms 94716 KB Output is correct
13 Correct 95 ms 94864 KB Output is correct
14 Correct 95 ms 94712 KB Output is correct
15 Correct 96 ms 94764 KB Output is correct
16 Correct 94 ms 94712 KB Output is correct
17 Correct 95 ms 94696 KB Output is correct
18 Correct 95 ms 94712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 94464 KB Output is correct
2 Correct 93 ms 94452 KB Output is correct
3 Correct 96 ms 94768 KB Output is correct
4 Correct 95 ms 94712 KB Output is correct
5 Correct 96 ms 94788 KB Output is correct
6 Correct 96 ms 94688 KB Output is correct
7 Correct 95 ms 94720 KB Output is correct
8 Correct 98 ms 94712 KB Output is correct
9 Correct 96 ms 94816 KB Output is correct
10 Correct 95 ms 94732 KB Output is correct
11 Correct 97 ms 94816 KB Output is correct
12 Correct 95 ms 94716 KB Output is correct
13 Correct 95 ms 94864 KB Output is correct
14 Correct 95 ms 94712 KB Output is correct
15 Correct 96 ms 94764 KB Output is correct
16 Correct 94 ms 94712 KB Output is correct
17 Correct 95 ms 94696 KB Output is correct
18 Correct 95 ms 94712 KB Output is correct
19 Correct 122 ms 96104 KB Output is correct
20 Correct 128 ms 96248 KB Output is correct
21 Correct 127 ms 96376 KB Output is correct
22 Correct 127 ms 96248 KB Output is correct
23 Correct 124 ms 96180 KB Output is correct
24 Correct 125 ms 96096 KB Output is correct
25 Correct 124 ms 96120 KB Output is correct
26 Correct 122 ms 96112 KB Output is correct
27 Correct 121 ms 95992 KB Output is correct
28 Correct 122 ms 96032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 95940 KB Output is correct
2 Correct 170 ms 97528 KB Output is correct
3 Correct 229 ms 98704 KB Output is correct
4 Correct 241 ms 98808 KB Output is correct
5 Correct 254 ms 98808 KB Output is correct
6 Correct 221 ms 98808 KB Output is correct
7 Correct 221 ms 98820 KB Output is correct
8 Correct 217 ms 98808 KB Output is correct
9 Correct 232 ms 98900 KB Output is correct
10 Correct 187 ms 98820 KB Output is correct
11 Correct 189 ms 98808 KB Output is correct
12 Correct 186 ms 98828 KB Output is correct
13 Correct 183 ms 98868 KB Output is correct
14 Correct 184 ms 98856 KB Output is correct
15 Correct 183 ms 98872 KB Output is correct
16 Correct 186 ms 98896 KB Output is correct
17 Correct 187 ms 98912 KB Output is correct
18 Correct 177 ms 98808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 94464 KB Output is correct
2 Correct 93 ms 94452 KB Output is correct
3 Correct 96 ms 94768 KB Output is correct
4 Correct 95 ms 94712 KB Output is correct
5 Correct 96 ms 94788 KB Output is correct
6 Correct 96 ms 94688 KB Output is correct
7 Correct 95 ms 94720 KB Output is correct
8 Correct 98 ms 94712 KB Output is correct
9 Correct 96 ms 94816 KB Output is correct
10 Correct 95 ms 94732 KB Output is correct
11 Correct 97 ms 94816 KB Output is correct
12 Correct 95 ms 94716 KB Output is correct
13 Correct 95 ms 94864 KB Output is correct
14 Correct 95 ms 94712 KB Output is correct
15 Correct 96 ms 94764 KB Output is correct
16 Correct 94 ms 94712 KB Output is correct
17 Correct 95 ms 94696 KB Output is correct
18 Correct 95 ms 94712 KB Output is correct
19 Correct 122 ms 96104 KB Output is correct
20 Correct 128 ms 96248 KB Output is correct
21 Correct 127 ms 96376 KB Output is correct
22 Correct 127 ms 96248 KB Output is correct
23 Correct 124 ms 96180 KB Output is correct
24 Correct 125 ms 96096 KB Output is correct
25 Correct 124 ms 96120 KB Output is correct
26 Correct 122 ms 96112 KB Output is correct
27 Correct 121 ms 95992 KB Output is correct
28 Correct 122 ms 96032 KB Output is correct
29 Correct 115 ms 95940 KB Output is correct
30 Correct 170 ms 97528 KB Output is correct
31 Correct 229 ms 98704 KB Output is correct
32 Correct 241 ms 98808 KB Output is correct
33 Correct 254 ms 98808 KB Output is correct
34 Correct 221 ms 98808 KB Output is correct
35 Correct 221 ms 98820 KB Output is correct
36 Correct 217 ms 98808 KB Output is correct
37 Correct 232 ms 98900 KB Output is correct
38 Correct 187 ms 98820 KB Output is correct
39 Correct 189 ms 98808 KB Output is correct
40 Correct 186 ms 98828 KB Output is correct
41 Correct 183 ms 98868 KB Output is correct
42 Correct 184 ms 98856 KB Output is correct
43 Correct 183 ms 98872 KB Output is correct
44 Correct 186 ms 98896 KB Output is correct
45 Correct 187 ms 98912 KB Output is correct
46 Correct 177 ms 98808 KB Output is correct
47 Correct 1759 ms 136416 KB Output is correct
48 Runtime error 1419 ms 312272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
49 Halted 0 ms 0 KB -