답안 #144012

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
144012 2019-08-15T16:18:40 Z shashwatchandra Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
5376 ms 222168 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>

using namespace std;

#define all(v) v.begin(),v.end()
#define pb push_back
#define REP(i,n) for(int i = 0;i < n;i++)
#define RE(i,n) for(int i = 1;i <= n;i++)

const int N = 1e6+1;
int seg[4*N];
int f[4*N];
int lazy[4*N];
set<int> best[N];
map<int,int> cool;
vector<int> comp;
int n;

#define mid (l+r)/2
#define child 2*node

void build(int node,int l,int r){
	lazy[node] = 0;
	if(l == r){
		f[node] = 0;
		seg[node] = -*best[l].begin();
		return;
	}
	build(child,l,mid);
	build(child+1,mid+1,r);
	seg[node] = max(seg[child+1],seg[child]);
}

inline void pushdown(int node,int l,int r,bool goat = 1){
	seg[node] -= lazy[node];
	f[node] -= lazy[node];
	if(l != r){
		lazy[child] += lazy[node];
		lazy[child+1] += lazy[node];
		if(goat){
			pushdown(child,l,mid,0);
			pushdown(child+1,mid+1,r,0);
		}
	}
	lazy[node] = 0;
	return;
}

void add(int node,int l,int r,int start,int end,int val){
	
	pushdown(node,l,r);
	if(l > end or start > r)return;
	if(start <= l and r <= end){
		
		lazy[node] += val;
		pushdown(node,l,r);
		return;
	}
	add(child,l,mid,start,end,val);
	add(child+1,mid+1,r,start,end,val);
	seg[node] = max(seg[child+1],seg[child]);
}

void update(int node,int l,int r,int ind){
	pushdown(node,l,r);
	if(l == r){
		seg[node] = f[node]-*best[l].begin();
		return;
	}
	if(ind <= mid)update(child,l,mid,ind);
	else update(child+1,mid+1,r,ind);
	seg[node] = max(seg[child+1],seg[child]);
}

int cur = 0;

void compress(){
	sort(all(comp));
	REP(i,comp.size()){
		if(!i or comp[i] != comp[i-1]){
			cur++;
			best[cur].insert(0);
			cool[comp[i]] = cur;
		}
	}
}

vector<int> countScans(vector<int> a,vector<int> x,vector<int> v){
	vector<int> answer;
	n = a.size();
	int q = x.size();
	REP(i,n)comp.pb(a[i]);
	REP(i,q)comp.pb(v[i]);
	compress();
	REP(i,n){
		a[i] = cool[a[i]];
		best[a[i]].insert(-(i+1));
	}
	REP(i,q){
		v[i] = cool[v[i]];
	}
	build(1,1,cur);
	REP(i,n){
		add(1,1,cur,a[i],cur,1);
	}	
	REP(i,q){
		int ind = x[i];
		int val = v[i];
		if(a[ind] != val){
			int upd = (a[ind] > val)?1:-1;
			add(1,1,cur,min(a[ind],val),max(a[ind],val)-1,upd);
			best[a[ind]].erase(-(ind+1));
			best[val].insert(-(ind+1));
			update(1,1,cur,a[ind]);
			update(1,1,cur,val);
			a[ind] = val;
		}
		answer.push_back(seg[1]);
	}
	return answer;
}

Compilation message

bubblesort2.cpp: In function 'void compress()':
bubblesort2.cpp:8:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define REP(i,n) for(int i = 0;i < n;i++)
bubblesort2.cpp:80:6:
  REP(i,comp.size()){
      ~~~~~~~~~~~~~                
bubblesort2.cpp:80:2: note: in expansion of macro 'REP'
  REP(i,comp.size()){
  ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 47608 KB Output is correct
2 Correct 48 ms 47608 KB Output is correct
3 Correct 52 ms 47992 KB Output is correct
4 Correct 53 ms 47992 KB Output is correct
5 Correct 52 ms 47992 KB Output is correct
6 Correct 53 ms 47992 KB Output is correct
7 Correct 52 ms 47992 KB Output is correct
8 Correct 52 ms 47992 KB Output is correct
9 Correct 52 ms 48020 KB Output is correct
10 Correct 53 ms 47940 KB Output is correct
11 Correct 52 ms 47992 KB Output is correct
12 Correct 52 ms 47992 KB Output is correct
13 Correct 52 ms 47864 KB Output is correct
14 Correct 52 ms 47864 KB Output is correct
15 Correct 53 ms 47864 KB Output is correct
16 Correct 51 ms 47992 KB Output is correct
17 Correct 52 ms 47864 KB Output is correct
18 Correct 52 ms 47864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 47608 KB Output is correct
2 Correct 48 ms 47608 KB Output is correct
3 Correct 52 ms 47992 KB Output is correct
4 Correct 53 ms 47992 KB Output is correct
5 Correct 52 ms 47992 KB Output is correct
6 Correct 53 ms 47992 KB Output is correct
7 Correct 52 ms 47992 KB Output is correct
8 Correct 52 ms 47992 KB Output is correct
9 Correct 52 ms 48020 KB Output is correct
10 Correct 53 ms 47940 KB Output is correct
11 Correct 52 ms 47992 KB Output is correct
12 Correct 52 ms 47992 KB Output is correct
13 Correct 52 ms 47864 KB Output is correct
14 Correct 52 ms 47864 KB Output is correct
15 Correct 53 ms 47864 KB Output is correct
16 Correct 51 ms 47992 KB Output is correct
17 Correct 52 ms 47864 KB Output is correct
18 Correct 52 ms 47864 KB Output is correct
19 Correct 74 ms 49784 KB Output is correct
20 Correct 79 ms 50168 KB Output is correct
21 Correct 79 ms 50168 KB Output is correct
22 Correct 83 ms 50212 KB Output is correct
23 Correct 78 ms 49912 KB Output is correct
24 Correct 78 ms 49928 KB Output is correct
25 Correct 75 ms 49784 KB Output is correct
26 Correct 77 ms 49784 KB Output is correct
27 Correct 75 ms 49656 KB Output is correct
28 Correct 74 ms 49628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 49188 KB Output is correct
2 Correct 117 ms 50724 KB Output is correct
3 Correct 170 ms 52336 KB Output is correct
4 Correct 172 ms 52268 KB Output is correct
5 Correct 167 ms 52336 KB Output is correct
6 Correct 167 ms 52412 KB Output is correct
7 Correct 160 ms 52324 KB Output is correct
8 Correct 162 ms 52208 KB Output is correct
9 Correct 159 ms 52280 KB Output is correct
10 Correct 120 ms 52336 KB Output is correct
11 Correct 113 ms 52336 KB Output is correct
12 Correct 112 ms 52336 KB Output is correct
13 Correct 122 ms 52408 KB Output is correct
14 Correct 128 ms 52336 KB Output is correct
15 Correct 120 ms 52392 KB Output is correct
16 Correct 128 ms 52336 KB Output is correct
17 Correct 128 ms 52336 KB Output is correct
18 Correct 128 ms 52460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 47608 KB Output is correct
2 Correct 48 ms 47608 KB Output is correct
3 Correct 52 ms 47992 KB Output is correct
4 Correct 53 ms 47992 KB Output is correct
5 Correct 52 ms 47992 KB Output is correct
6 Correct 53 ms 47992 KB Output is correct
7 Correct 52 ms 47992 KB Output is correct
8 Correct 52 ms 47992 KB Output is correct
9 Correct 52 ms 48020 KB Output is correct
10 Correct 53 ms 47940 KB Output is correct
11 Correct 52 ms 47992 KB Output is correct
12 Correct 52 ms 47992 KB Output is correct
13 Correct 52 ms 47864 KB Output is correct
14 Correct 52 ms 47864 KB Output is correct
15 Correct 53 ms 47864 KB Output is correct
16 Correct 51 ms 47992 KB Output is correct
17 Correct 52 ms 47864 KB Output is correct
18 Correct 52 ms 47864 KB Output is correct
19 Correct 74 ms 49784 KB Output is correct
20 Correct 79 ms 50168 KB Output is correct
21 Correct 79 ms 50168 KB Output is correct
22 Correct 83 ms 50212 KB Output is correct
23 Correct 78 ms 49912 KB Output is correct
24 Correct 78 ms 49928 KB Output is correct
25 Correct 75 ms 49784 KB Output is correct
26 Correct 77 ms 49784 KB Output is correct
27 Correct 75 ms 49656 KB Output is correct
28 Correct 74 ms 49628 KB Output is correct
29 Correct 69 ms 49188 KB Output is correct
30 Correct 117 ms 50724 KB Output is correct
31 Correct 170 ms 52336 KB Output is correct
32 Correct 172 ms 52268 KB Output is correct
33 Correct 167 ms 52336 KB Output is correct
34 Correct 167 ms 52412 KB Output is correct
35 Correct 160 ms 52324 KB Output is correct
36 Correct 162 ms 52208 KB Output is correct
37 Correct 159 ms 52280 KB Output is correct
38 Correct 120 ms 52336 KB Output is correct
39 Correct 113 ms 52336 KB Output is correct
40 Correct 112 ms 52336 KB Output is correct
41 Correct 122 ms 52408 KB Output is correct
42 Correct 128 ms 52336 KB Output is correct
43 Correct 120 ms 52392 KB Output is correct
44 Correct 128 ms 52336 KB Output is correct
45 Correct 128 ms 52336 KB Output is correct
46 Correct 128 ms 52460 KB Output is correct
47 Correct 1262 ms 104948 KB Output is correct
48 Correct 5001 ms 208080 KB Output is correct
49 Correct 5376 ms 222048 KB Output is correct
50 Correct 5296 ms 221900 KB Output is correct
51 Correct 5310 ms 221908 KB Output is correct
52 Correct 5189 ms 221952 KB Output is correct
53 Correct 5241 ms 221852 KB Output is correct
54 Correct 4761 ms 222056 KB Output is correct
55 Correct 5152 ms 222064 KB Output is correct
56 Correct 4819 ms 221944 KB Output is correct
57 Correct 4992 ms 222168 KB Output is correct
58 Correct 4657 ms 222016 KB Output is correct
59 Correct 4265 ms 208992 KB Output is correct
60 Correct 4335 ms 209160 KB Output is correct
61 Correct 4336 ms 209048 KB Output is correct
62 Correct 4122 ms 202976 KB Output is correct
63 Correct 4099 ms 203128 KB Output is correct
64 Correct 4103 ms 203140 KB Output is correct
65 Correct 3826 ms 197224 KB Output is correct
66 Correct 3821 ms 197132 KB Output is correct
67 Correct 3757 ms 197116 KB Output is correct