Submission #547989

# Submission time Handle Problem Language Result Execution time Memory
547989 2022-04-12T07:38:39 Z MilosMilutinovic Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
4258 ms 78120 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
const int N=500050;
const int M=4*N;
int n,q,a[N],x[N],v[N],was[2*N];
int st[M],val[M],root,ls[M],rs[M],tsz,lzy[M];
void push(int c,int ss,int se){
    if(ss!=se){
        if(!ls[c])ls[c]=++tsz;
        if(!rs[c])rs[c]=++tsz;
        val[ls[c]]+=lzy[c];
        val[rs[c]]+=lzy[c];
        st[ls[c]]+=lzy[c];
        st[rs[c]]+=lzy[c];
        lzy[ls[c]]+=lzy[c];
        lzy[rs[c]]+=lzy[c];
    }
    lzy[c]=0;
}
void Set(int&c,int ss,int se,int qs,int qe,int w){
    if(!c)c=++tsz;
    if(ss>se||ss>qe||se<qs)return;
    if(qs<=ss&&se<=qe){st[c]+=w,lzy[c]+=w,val[c]+=w,push(c,ss,se);return;}
    push(c,ss,se);
    int mid=ss+se>>1;
    Set(ls[c],ss,mid,qs,qe,w);
    Set(rs[c],mid+1,se,qs,qe,w);
    val[c]=-1e9;
    if(ls[c])val[c]=max(val[c],val[ls[c]]);
    if(rs[c])val[c]=max(val[c],val[rs[c]]);
}
void Act(int c,int ss,int se,int qi,int i){
    if(ss==se){val[c]=(i==1?st[c]:-1e9);return;}
    push(c,ss,se);
    int mid=ss+se>>1;
    if(qi<=mid)Act(ls[c],ss,mid,qi,i);
    else Act(rs[c],mid+1,se,qi,i);
    val[c]=max(val[ls[c]],val[rs[c]]);
}
void Input(vector<int> A,vector<int> X,vector<int> V){
    n=A.size(),q=X.size();
    vector<pair<int,int>> cpr;
    for(int i=0;i<n;i++)cpr.pb({A[i],i});
    for(int i=0;i<q;i++)cpr.pb({V[i],X[i]});
    sort(cpr.begin(),cpr.end());
    cpr.erase(unique(cpr.begin(),cpr.end()),cpr.end());
    for(int i=0;i<n;i++)a[i]=(int)(lower_bound(cpr.begin(),cpr.end(),mp(A[i],i))-cpr.begin())+1;
    for(int i=0;i<q;i++)v[i]=(int)(lower_bound(cpr.begin(),cpr.end(),mp(V[i],X[i]))-cpr.begin())+1;
    for(int i=0;i<q;i++)x[i]=X[i];
}
void Print(int c,int ss,int se){
    if(ss==se){if(ss<=10)printf("debug at %d == %d\n",ss,st[c]);return;}
    int mid=ss+se>>1;
    Print(ls[c],ss,mid);
    Print(rs[c],mid+1,se);
}
vector<int> countScans(vector<int> A,vector<int> X,vector<int> V){
    Input(A,X,V);
    //for(int i=0;i<n;i++)printf("%d ",a[i]);puts("");
    for(int i=0;i<n;i++)Set(root,1,2*N,a[i],a[i],i+1),was[a[i]]=1;
    for(int i=0;i<q;i++)if(!was[v[i]])Set(root,1,2*N,v[i],v[i],x[i]+1),Act(root,1,2*N,v[i],0),was[v[i]]=1;
    for(int i=0;i<n;i++)Set(root,1,2*N,a[i],2*N,-1);
    for(int i=0;i<n;i++)Act(root,1,2*N,a[i],1);
    //for(int i=0;i<n;i++)printf("%d ",a[i]);puts("");
    vector<int> ans;
    for(int i=0;i<q;i++){
        Set(root,1,2*N,a[x[i]],2*N,1);
        //Print(root,1,2*N);
        Act(root,1,2*N,a[x[i]],0);
        a[x[i]]=v[i];
        //printf("ww %d\n",v[i]);
        Set(root,1,2*N,a[x[i]],2*N,-1);
        Act(root,1,2*N,a[x[i]],1);
        ans.pb(val[root]);
    }
    return ans;
}

Compilation message

bubblesort2.cpp: In function 'void Set(int&, int, int, int, int, int)':
bubblesort2.cpp:28:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |     int mid=ss+se>>1;
      |             ~~^~~
bubblesort2.cpp: In function 'void Act(int, int, int, int, int)':
bubblesort2.cpp:38:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |     int mid=ss+se>>1;
      |             ~~^~~
bubblesort2.cpp: In function 'void Print(int, int, int)':
bubblesort2.cpp:56:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   56 |     int mid=ss+se>>1;
      |             ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 5 ms 468 KB Output is correct
3 Correct 9 ms 704 KB Output is correct
4 Correct 9 ms 740 KB Output is correct
5 Correct 10 ms 748 KB Output is correct
6 Correct 9 ms 744 KB Output is correct
7 Correct 9 ms 724 KB Output is correct
8 Correct 10 ms 704 KB Output is correct
9 Correct 9 ms 704 KB Output is correct
10 Correct 9 ms 724 KB Output is correct
11 Correct 10 ms 728 KB Output is correct
12 Correct 9 ms 708 KB Output is correct
13 Correct 9 ms 700 KB Output is correct
14 Correct 9 ms 596 KB Output is correct
15 Correct 9 ms 596 KB Output is correct
16 Correct 9 ms 596 KB Output is correct
17 Correct 9 ms 616 KB Output is correct
18 Correct 9 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 5 ms 468 KB Output is correct
3 Correct 9 ms 704 KB Output is correct
4 Correct 9 ms 740 KB Output is correct
5 Correct 10 ms 748 KB Output is correct
6 Correct 9 ms 744 KB Output is correct
7 Correct 9 ms 724 KB Output is correct
8 Correct 10 ms 704 KB Output is correct
9 Correct 9 ms 704 KB Output is correct
10 Correct 9 ms 724 KB Output is correct
11 Correct 10 ms 728 KB Output is correct
12 Correct 9 ms 708 KB Output is correct
13 Correct 9 ms 700 KB Output is correct
14 Correct 9 ms 596 KB Output is correct
15 Correct 9 ms 596 KB Output is correct
16 Correct 9 ms 596 KB Output is correct
17 Correct 9 ms 616 KB Output is correct
18 Correct 9 ms 596 KB Output is correct
19 Correct 35 ms 1576 KB Output is correct
20 Correct 37 ms 1664 KB Output is correct
21 Correct 38 ms 1744 KB Output is correct
22 Correct 39 ms 1760 KB Output is correct
23 Correct 35 ms 1640 KB Output is correct
24 Correct 34 ms 1636 KB Output is correct
25 Correct 36 ms 1576 KB Output is correct
26 Correct 35 ms 1600 KB Output is correct
27 Correct 32 ms 1496 KB Output is correct
28 Correct 33 ms 1548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 2248 KB Output is correct
2 Correct 146 ms 4796 KB Output is correct
3 Correct 254 ms 7428 KB Output is correct
4 Correct 236 ms 7352 KB Output is correct
5 Correct 253 ms 7384 KB Output is correct
6 Correct 231 ms 7276 KB Output is correct
7 Correct 237 ms 7416 KB Output is correct
8 Correct 244 ms 7356 KB Output is correct
9 Correct 232 ms 7260 KB Output is correct
10 Correct 193 ms 5480 KB Output is correct
11 Correct 188 ms 5504 KB Output is correct
12 Correct 181 ms 5536 KB Output is correct
13 Correct 184 ms 5600 KB Output is correct
14 Correct 188 ms 5596 KB Output is correct
15 Correct 188 ms 5472 KB Output is correct
16 Correct 177 ms 5460 KB Output is correct
17 Correct 185 ms 5472 KB Output is correct
18 Correct 184 ms 5568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 5 ms 468 KB Output is correct
3 Correct 9 ms 704 KB Output is correct
4 Correct 9 ms 740 KB Output is correct
5 Correct 10 ms 748 KB Output is correct
6 Correct 9 ms 744 KB Output is correct
7 Correct 9 ms 724 KB Output is correct
8 Correct 10 ms 704 KB Output is correct
9 Correct 9 ms 704 KB Output is correct
10 Correct 9 ms 724 KB Output is correct
11 Correct 10 ms 728 KB Output is correct
12 Correct 9 ms 708 KB Output is correct
13 Correct 9 ms 700 KB Output is correct
14 Correct 9 ms 596 KB Output is correct
15 Correct 9 ms 596 KB Output is correct
16 Correct 9 ms 596 KB Output is correct
17 Correct 9 ms 616 KB Output is correct
18 Correct 9 ms 596 KB Output is correct
19 Correct 35 ms 1576 KB Output is correct
20 Correct 37 ms 1664 KB Output is correct
21 Correct 38 ms 1744 KB Output is correct
22 Correct 39 ms 1760 KB Output is correct
23 Correct 35 ms 1640 KB Output is correct
24 Correct 34 ms 1636 KB Output is correct
25 Correct 36 ms 1576 KB Output is correct
26 Correct 35 ms 1600 KB Output is correct
27 Correct 32 ms 1496 KB Output is correct
28 Correct 33 ms 1548 KB Output is correct
29 Correct 53 ms 2248 KB Output is correct
30 Correct 146 ms 4796 KB Output is correct
31 Correct 254 ms 7428 KB Output is correct
32 Correct 236 ms 7352 KB Output is correct
33 Correct 253 ms 7384 KB Output is correct
34 Correct 231 ms 7276 KB Output is correct
35 Correct 237 ms 7416 KB Output is correct
36 Correct 244 ms 7356 KB Output is correct
37 Correct 232 ms 7260 KB Output is correct
38 Correct 193 ms 5480 KB Output is correct
39 Correct 188 ms 5504 KB Output is correct
40 Correct 181 ms 5536 KB Output is correct
41 Correct 184 ms 5600 KB Output is correct
42 Correct 188 ms 5596 KB Output is correct
43 Correct 188 ms 5472 KB Output is correct
44 Correct 177 ms 5460 KB Output is correct
45 Correct 185 ms 5472 KB Output is correct
46 Correct 184 ms 5568 KB Output is correct
47 Correct 915 ms 23528 KB Output is correct
48 Correct 3522 ms 71860 KB Output is correct
49 Correct 3828 ms 77836 KB Output is correct
50 Correct 3881 ms 77832 KB Output is correct
51 Correct 3950 ms 77968 KB Output is correct
52 Correct 4258 ms 77816 KB Output is correct
53 Correct 4239 ms 78096 KB Output is correct
54 Correct 3784 ms 77992 KB Output is correct
55 Correct 4181 ms 78120 KB Output is correct
56 Correct 3726 ms 78092 KB Output is correct
57 Correct 4125 ms 78108 KB Output is correct
58 Correct 3910 ms 78000 KB Output is correct
59 Correct 3303 ms 71332 KB Output is correct
60 Correct 3244 ms 71312 KB Output is correct
61 Correct 3207 ms 71320 KB Output is correct
62 Correct 3026 ms 68440 KB Output is correct
63 Correct 2999 ms 68540 KB Output is correct
64 Correct 3046 ms 68476 KB Output is correct
65 Correct 2788 ms 65576 KB Output is correct
66 Correct 2859 ms 65608 KB Output is correct
67 Correct 2791 ms 65836 KB Output is correct