Submission #321593

# Submission time Handle Problem Language Result Execution time Memory
321593 2020-11-12T19:58:45 Z CaroLinda Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
5015 ms 110408 KB
#include <bits/stdc++.h>
#include "bubblesort2.h"

#define sz(x) (int)(x.size() )
#define all(x) x.begin(),x.end()

const int MAX = 1e6+10 ;
const int inf = 1e8+10 ;

using namespace std ;

int Key ;

struct Tree
{
	
	int tree[MAX*4] ;
	int lz[MAX*4] ;

	int m(int l, int r ) { return (l+r)>>1 ; }

	void refresh(int pos, int l, int r )
	{
		tree[pos] += lz[pos] ;

		if( l == r ) return (void)(lz[pos] = 0 ) ;

		lz[pos<<1] += lz[pos] ;
		lz[pos<<1|1] += lz[pos] ;

		lz[pos] = 0 ;

	}

	void updInterval(int pos, int l,int r, int beg, int en, int val )
	{
		refresh(pos,l,r) ;

		if( l > en || r < beg ) return ;
		if( l >= beg && r <= en )
		{
			lz[pos] += val ;
			refresh(pos,l,r) ;
			return ;
		}

		updInterval(pos<<1 , l, m(l,r) , beg, en, val ) ;
		updInterval(pos<<1|1 , m(l,r)+1, r, beg, en, val ) ;

		tree[pos] = max(tree[pos<<1], tree[pos<<1|1] ) ;

	}

	void updPoint(int pos, int l ,int r, int idx, int val )
	{
		refresh(pos,l,r) ;

		if( l > idx || r < idx ) return ;
		if( l == r ) return (void)(tree[pos] = val) ;

		updPoint(pos<<1 , l ,m(l,r), idx, val ) ;
		updPoint(pos<<1|1 , m(l,r)+1, r, idx, val ) ;	

		tree[pos] = max(tree[pos<<1] , tree[pos<<1|1] ) ;

	}

	int getMax() { refresh(1,0,1) ; return tree[1] ; }

} seg ;

struct Bit
{
	
	int bit[MAX] ;

	void upd(int pos, int x ) { for(; pos < MAX ; pos += pos & -pos ) bit[pos] += x ; }
	int qry(int pos )
	{
		int tot = 0 ;
		for(; pos > 0 ; pos -= pos & -pos ) tot += bit[pos] ;
		return tot ;
	}

} bit ;

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

	int n = sz(A) ;
	int q = sz(V) ;

	map< pair<int,int> , int > compression ;

	for(int i = 0 ; i < n ; i++ ) compression[ make_pair(A[i],i) ] = 0 ;
	for(int i = 0 ; i < q ; i++ ) compression[ make_pair(V[i], X[i]) ] = 0 ;

	for(auto &e : compression ) e.second = ++Key ;

	for(int i = 0 ; i < n ; i++ ) A[i] = compression[ make_pair(A[i], i) ] ;
	for(int i = 0 ; i < q ; i++ ) V[i] = compression[ make_pair(V[i] , X[i] ) ] ;

	seg.updInterval(1,1,Key, 1,Key, -inf ) ;

	for(int i = 0 ; i < n ; i++ )	bit.upd(A[i], 1) ;
	for(int i = 0 ; i < n ; i++ ) seg.updPoint(1,1, Key,A[i],  i-bit.qry(A[i]-1) ) ;

	vector<int> ans ;

	for(int i = 0 ; i < q ; i++ )
	{
		bit.upd( A[ X[i] ] , -1 ) ;
		bit.upd( V[i] , 1 ) ;

		seg.updInterval( 1 , 1 , Key , A[ X[i] ] + 1 , Key , 1 ) ;
		seg.updInterval(1 , 1 , Key , V[i] + 1 , Key , -1 ) ;

		seg.updPoint(1 , 1  , Key , A[ X[i] ] , -inf ) ;
		seg.updPoint(1,1,Key, V[i] , X[i] - bit.qry(V[i] - 1) ) ;

		A[X[i]] = V[i] ;

		ans.push_back( seg.getMax() ) ;	
	
	}

	return ans ;

}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 3 ms 620 KB Output is correct
3 Correct 6 ms 876 KB Output is correct
4 Correct 6 ms 876 KB Output is correct
5 Correct 14 ms 876 KB Output is correct
6 Correct 5 ms 876 KB Output is correct
7 Correct 7 ms 876 KB Output is correct
8 Correct 6 ms 876 KB Output is correct
9 Correct 12 ms 876 KB Output is correct
10 Correct 8 ms 748 KB Output is correct
11 Correct 7 ms 748 KB Output is correct
12 Correct 7 ms 748 KB Output is correct
13 Correct 6 ms 748 KB Output is correct
14 Correct 17 ms 748 KB Output is correct
15 Correct 5 ms 748 KB Output is correct
16 Correct 7 ms 748 KB Output is correct
17 Correct 5 ms 748 KB Output is correct
18 Correct 5 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 3 ms 620 KB Output is correct
3 Correct 6 ms 876 KB Output is correct
4 Correct 6 ms 876 KB Output is correct
5 Correct 14 ms 876 KB Output is correct
6 Correct 5 ms 876 KB Output is correct
7 Correct 7 ms 876 KB Output is correct
8 Correct 6 ms 876 KB Output is correct
9 Correct 12 ms 876 KB Output is correct
10 Correct 8 ms 748 KB Output is correct
11 Correct 7 ms 748 KB Output is correct
12 Correct 7 ms 748 KB Output is correct
13 Correct 6 ms 748 KB Output is correct
14 Correct 17 ms 748 KB Output is correct
15 Correct 5 ms 748 KB Output is correct
16 Correct 7 ms 748 KB Output is correct
17 Correct 5 ms 748 KB Output is correct
18 Correct 5 ms 748 KB Output is correct
19 Correct 26 ms 2028 KB Output is correct
20 Correct 27 ms 2156 KB Output is correct
21 Correct 29 ms 2156 KB Output is correct
22 Correct 26 ms 2156 KB Output is correct
23 Correct 23 ms 2028 KB Output is correct
24 Correct 28 ms 2028 KB Output is correct
25 Correct 24 ms 1900 KB Output is correct
26 Correct 24 ms 1900 KB Output is correct
27 Correct 27 ms 1900 KB Output is correct
28 Correct 22 ms 1900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 3180 KB Output is correct
2 Correct 116 ms 6892 KB Output is correct
3 Correct 226 ms 11116 KB Output is correct
4 Correct 209 ms 11116 KB Output is correct
5 Correct 216 ms 11216 KB Output is correct
6 Correct 247 ms 11244 KB Output is correct
7 Correct 234 ms 10992 KB Output is correct
8 Correct 217 ms 10988 KB Output is correct
9 Correct 364 ms 10988 KB Output is correct
10 Correct 154 ms 7276 KB Output is correct
11 Correct 162 ms 7276 KB Output is correct
12 Correct 157 ms 7276 KB Output is correct
13 Correct 156 ms 7404 KB Output is correct
14 Correct 149 ms 7276 KB Output is correct
15 Correct 160 ms 7276 KB Output is correct
16 Correct 137 ms 7276 KB Output is correct
17 Correct 137 ms 7292 KB Output is correct
18 Correct 162 ms 7276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 3 ms 620 KB Output is correct
3 Correct 6 ms 876 KB Output is correct
4 Correct 6 ms 876 KB Output is correct
5 Correct 14 ms 876 KB Output is correct
6 Correct 5 ms 876 KB Output is correct
7 Correct 7 ms 876 KB Output is correct
8 Correct 6 ms 876 KB Output is correct
9 Correct 12 ms 876 KB Output is correct
10 Correct 8 ms 748 KB Output is correct
11 Correct 7 ms 748 KB Output is correct
12 Correct 7 ms 748 KB Output is correct
13 Correct 6 ms 748 KB Output is correct
14 Correct 17 ms 748 KB Output is correct
15 Correct 5 ms 748 KB Output is correct
16 Correct 7 ms 748 KB Output is correct
17 Correct 5 ms 748 KB Output is correct
18 Correct 5 ms 748 KB Output is correct
19 Correct 26 ms 2028 KB Output is correct
20 Correct 27 ms 2156 KB Output is correct
21 Correct 29 ms 2156 KB Output is correct
22 Correct 26 ms 2156 KB Output is correct
23 Correct 23 ms 2028 KB Output is correct
24 Correct 28 ms 2028 KB Output is correct
25 Correct 24 ms 1900 KB Output is correct
26 Correct 24 ms 1900 KB Output is correct
27 Correct 27 ms 1900 KB Output is correct
28 Correct 22 ms 1900 KB Output is correct
29 Correct 33 ms 3180 KB Output is correct
30 Correct 116 ms 6892 KB Output is correct
31 Correct 226 ms 11116 KB Output is correct
32 Correct 209 ms 11116 KB Output is correct
33 Correct 216 ms 11216 KB Output is correct
34 Correct 247 ms 11244 KB Output is correct
35 Correct 234 ms 10992 KB Output is correct
36 Correct 217 ms 10988 KB Output is correct
37 Correct 364 ms 10988 KB Output is correct
38 Correct 154 ms 7276 KB Output is correct
39 Correct 162 ms 7276 KB Output is correct
40 Correct 157 ms 7276 KB Output is correct
41 Correct 156 ms 7404 KB Output is correct
42 Correct 149 ms 7276 KB Output is correct
43 Correct 160 ms 7276 KB Output is correct
44 Correct 137 ms 7276 KB Output is correct
45 Correct 137 ms 7292 KB Output is correct
46 Correct 162 ms 7276 KB Output is correct
47 Correct 1075 ms 36624 KB Output is correct
48 Correct 4397 ms 102616 KB Output is correct
49 Correct 5015 ms 110128 KB Output is correct
50 Correct 4936 ms 110096 KB Output is correct
51 Correct 4973 ms 110124 KB Output is correct
52 Correct 4935 ms 110076 KB Output is correct
53 Correct 4796 ms 110172 KB Output is correct
54 Correct 4181 ms 110304 KB Output is correct
55 Correct 4648 ms 110360 KB Output is correct
56 Correct 4195 ms 110348 KB Output is correct
57 Correct 4582 ms 110288 KB Output is correct
58 Correct 4035 ms 110408 KB Output is correct
59 Correct 3724 ms 100928 KB Output is correct
60 Correct 3710 ms 100692 KB Output is correct
61 Correct 3741 ms 100832 KB Output is correct
62 Correct 3710 ms 96464 KB Output is correct
63 Correct 3615 ms 96484 KB Output is correct
64 Correct 3605 ms 96404 KB Output is correct
65 Correct 3440 ms 92144 KB Output is correct
66 Correct 3454 ms 92216 KB Output is correct
67 Correct 3431 ms 92068 KB Output is correct