Submission #513760

# Submission time Handle Problem Language Result Execution time Memory
513760 2022-01-17T14:29:07 Z andrei_boaca Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
5187 ms 168512 KB
#include <bits/stdc++.h>
#include "bubblesort2.h"
//#include "grader.cpp"
using namespace std;
const int INF=1e9;
typedef pair<int,int> pii;
map<pii,int> nrm;
int arb[4000005],toprop[4000005];
int q,n;
vector<pii> query;
vector<int> v;
set<pii> s;
int nr=0;
void prop(int nod)
{
    int val=toprop[nod];
    for(int i=nod*2;i<=nod*2+1;i++)
    {
        arb[i]+=val;
        toprop[i]+=val;
    }
}
void update(int nod,int st,int dr,int a,int b,int val)
{
    if(toprop[nod]!=0&&st!=dr)
        prop(nod);
    toprop[nod]=0;
    if(st>=a&&dr<=b)
    {
        arb[nod]+=val;
        toprop[nod]+=val;
        return;
    }
    int mij=(st+dr)/2;
    if(a<=mij)
        update(nod*2,st,mij,a,b,val);
    if(b>mij)
        update(nod*2+1,mij+1,dr,a,b,val);
    arb[nod]=max(arb[nod*2],arb[nod*2+1]);
}
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V)
{
    vector<int> sol;
    q=X.size();
    n=A.size();
    for(int i=0;i<q;i++)
        query.push_back({X[i],V[i]});
    v=A;
    for(int i=0;i<q;i++)
        s.insert({V[i],X[i]});
    for(int i=0;i<n;i++)
        s.insert({v[i],i});
    for(pii i:s)
    {
        nr++;
        nrm[i]=nr;
    }
    for(int i=1;i<=4*nr;i++)
        arb[i]=-INF;
    for(int i=0;i<n;i++)
    {
        int poz=nrm[{v[i],i}];
        update(1,1,nr,poz,poz,+INF);
        update(1,1,nr,poz,nr,-1);
        update(1,1,nr,poz,poz,i+1);
    }
    for(int j=0;j<q;j++)
    {
        int poz;
        int p=X[j];
        poz=nrm[{v[p],p}];
        update(1,1,nr,poz,poz,-(p+1));
        update(1,1,nr,poz,nr,+1);
        update(1,1,nr,poz,poz,-INF);

        v[p]=V[j];
        poz=nrm[{v[p],p}];
        update(1,1,nr,poz,poz,(p+1));
        update(1,1,nr,poz,nr,-1);
        update(1,1,nr,poz,poz,+INF);

        sol.push_back(arb[1]);
    }
    return sol;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 444 KB Output is correct
2 Correct 3 ms 572 KB Output is correct
3 Correct 6 ms 852 KB Output is correct
4 Correct 6 ms 984 KB Output is correct
5 Correct 6 ms 952 KB Output is correct
6 Correct 6 ms 956 KB Output is correct
7 Correct 6 ms 984 KB Output is correct
8 Correct 6 ms 956 KB Output is correct
9 Correct 6 ms 960 KB Output is correct
10 Correct 5 ms 844 KB Output is correct
11 Correct 6 ms 912 KB Output is correct
12 Correct 6 ms 912 KB Output is correct
13 Correct 8 ms 824 KB Output is correct
14 Correct 6 ms 828 KB Output is correct
15 Correct 5 ms 884 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 5 ms 844 KB Output is correct
18 Correct 6 ms 836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 444 KB Output is correct
2 Correct 3 ms 572 KB Output is correct
3 Correct 6 ms 852 KB Output is correct
4 Correct 6 ms 984 KB Output is correct
5 Correct 6 ms 952 KB Output is correct
6 Correct 6 ms 956 KB Output is correct
7 Correct 6 ms 984 KB Output is correct
8 Correct 6 ms 956 KB Output is correct
9 Correct 6 ms 960 KB Output is correct
10 Correct 5 ms 844 KB Output is correct
11 Correct 6 ms 912 KB Output is correct
12 Correct 6 ms 912 KB Output is correct
13 Correct 8 ms 824 KB Output is correct
14 Correct 6 ms 828 KB Output is correct
15 Correct 5 ms 884 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 5 ms 844 KB Output is correct
18 Correct 6 ms 836 KB Output is correct
19 Correct 24 ms 2592 KB Output is correct
20 Correct 32 ms 2984 KB Output is correct
21 Correct 25 ms 2940 KB Output is correct
22 Correct 26 ms 2892 KB Output is correct
23 Correct 24 ms 2612 KB Output is correct
24 Correct 31 ms 2708 KB Output is correct
25 Correct 24 ms 2528 KB Output is correct
26 Correct 22 ms 2500 KB Output is correct
27 Correct 22 ms 2380 KB Output is correct
28 Correct 28 ms 2380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 4684 KB Output is correct
2 Correct 119 ms 10328 KB Output is correct
3 Correct 254 ms 16552 KB Output is correct
4 Correct 276 ms 16572 KB Output is correct
5 Correct 240 ms 16420 KB Output is correct
6 Correct 250 ms 16252 KB Output is correct
7 Correct 256 ms 16172 KB Output is correct
8 Correct 222 ms 16320 KB Output is correct
9 Correct 228 ms 16196 KB Output is correct
10 Correct 153 ms 10428 KB Output is correct
11 Correct 144 ms 10348 KB Output is correct
12 Correct 190 ms 10512 KB Output is correct
13 Correct 152 ms 10460 KB Output is correct
14 Correct 142 ms 10492 KB Output is correct
15 Correct 141 ms 10428 KB Output is correct
16 Correct 141 ms 10428 KB Output is correct
17 Correct 136 ms 10460 KB Output is correct
18 Correct 137 ms 10428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 444 KB Output is correct
2 Correct 3 ms 572 KB Output is correct
3 Correct 6 ms 852 KB Output is correct
4 Correct 6 ms 984 KB Output is correct
5 Correct 6 ms 952 KB Output is correct
6 Correct 6 ms 956 KB Output is correct
7 Correct 6 ms 984 KB Output is correct
8 Correct 6 ms 956 KB Output is correct
9 Correct 6 ms 960 KB Output is correct
10 Correct 5 ms 844 KB Output is correct
11 Correct 6 ms 912 KB Output is correct
12 Correct 6 ms 912 KB Output is correct
13 Correct 8 ms 824 KB Output is correct
14 Correct 6 ms 828 KB Output is correct
15 Correct 5 ms 884 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 5 ms 844 KB Output is correct
18 Correct 6 ms 836 KB Output is correct
19 Correct 24 ms 2592 KB Output is correct
20 Correct 32 ms 2984 KB Output is correct
21 Correct 25 ms 2940 KB Output is correct
22 Correct 26 ms 2892 KB Output is correct
23 Correct 24 ms 2612 KB Output is correct
24 Correct 31 ms 2708 KB Output is correct
25 Correct 24 ms 2528 KB Output is correct
26 Correct 22 ms 2500 KB Output is correct
27 Correct 22 ms 2380 KB Output is correct
28 Correct 28 ms 2380 KB Output is correct
29 Correct 40 ms 4684 KB Output is correct
30 Correct 119 ms 10328 KB Output is correct
31 Correct 254 ms 16552 KB Output is correct
32 Correct 276 ms 16572 KB Output is correct
33 Correct 240 ms 16420 KB Output is correct
34 Correct 250 ms 16252 KB Output is correct
35 Correct 256 ms 16172 KB Output is correct
36 Correct 222 ms 16320 KB Output is correct
37 Correct 228 ms 16196 KB Output is correct
38 Correct 153 ms 10428 KB Output is correct
39 Correct 144 ms 10348 KB Output is correct
40 Correct 190 ms 10512 KB Output is correct
41 Correct 152 ms 10460 KB Output is correct
42 Correct 142 ms 10492 KB Output is correct
43 Correct 141 ms 10428 KB Output is correct
44 Correct 141 ms 10428 KB Output is correct
45 Correct 136 ms 10460 KB Output is correct
46 Correct 137 ms 10428 KB Output is correct
47 Correct 1074 ms 52100 KB Output is correct
48 Correct 4692 ms 155016 KB Output is correct
49 Correct 5088 ms 168228 KB Output is correct
50 Correct 5187 ms 168236 KB Output is correct
51 Correct 5159 ms 168244 KB Output is correct
52 Correct 5061 ms 168188 KB Output is correct
53 Correct 5145 ms 168248 KB Output is correct
54 Correct 4505 ms 168364 KB Output is correct
55 Correct 5054 ms 168484 KB Output is correct
56 Correct 4482 ms 168372 KB Output is correct
57 Correct 4623 ms 168512 KB Output is correct
58 Correct 4406 ms 168476 KB Output is correct
59 Correct 3999 ms 151552 KB Output is correct
60 Correct 3797 ms 151696 KB Output is correct
61 Correct 3932 ms 151292 KB Output is correct
62 Correct 3707 ms 143376 KB Output is correct
63 Correct 4002 ms 143424 KB Output is correct
64 Correct 3843 ms 143420 KB Output is correct
65 Correct 3491 ms 135464 KB Output is correct
66 Correct 3578 ms 135368 KB Output is correct
67 Correct 3237 ms 135476 KB Output is correct