답안 #284034

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
284034 2020-08-26T14:10:44 Z AMnu Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
3382 ms 130936 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>
#define pii pair<int,int>
#define i1 first
#define i2 second
using namespace std;

const int INF=1e6+5;

int N, Q;
vector<int> H;
vector<pii> S;

struct segment {
	int L, R;
	int val, cnt, lazy;
	segment *lef, *rig;
	
	void build(int x,int y) {
		L=x;
		R=y;
		val=-INF;
		cnt=0;
		lazy=0;
		
		if (x==y) {
			return;
		}
		
		int T;
		T=(L+R)/2;
		lef=new segment;
		lef->build(L,T);
		rig=new segment;
		rig->build(T+1,R);
		
		return;
	}
	
	void balance() {
		if (!lazy) {
			return;
		}
		
		lef->val+=lazy;
		lef->lazy+=lazy;
		rig->val+=lazy;
		rig->lazy+=lazy;
		lazy=0;
		
		return;
	}
	
	void update(int x,int y) {
		if (R<x) {
			return;
		}
		
		if (L>=x) {
			val+=y;
			lazy+=y;
			return;
		}
		
		balance();
		lef->update(x,y);
		rig->update(x,y);
		val=max(lef->val,rig->val);
		
		return;
	}
	
	int query(int x) {
		if (L>x) {
			return 0;
		}
		
		if (R<=x) {
			return cnt;
		}
		
		return lef->query(x)+rig->query(x);
	}
	
	void set(int x,int y,int z) {
		if (L==R) {
			val=y;
			cnt=z;
			return;
		}
		
		int T;
		T=(L+R)/2;
		balance();
		
		if (x<=T) {
			lef->set(x,y,z);
		}
		else {
			rig->set(x,y,z);
		}
		
		cnt=lef->cnt+rig->cnt;
		val=max(lef->val,rig->val);
	}
}
data;

void del(pii x) {
	int y=lower_bound(S.begin(),S.end(),x)-S.begin();
	data.set(y,-INF,0);
	data.update(y+1,1);
}

void add(pii x) {
	int y=lower_bound(S.begin(),S.end(),x)-S.begin();
	data.set(y,x.i2-data.query(y-1),1);
	data.update(y+1,-1);
}

vector<int> countScans(vector<int> A,vector<int> X,vector<int> V){
	N=A.size();
	Q=X.size();
	H=vector<int>(Q);
	S=vector<pii>(N+Q);
	
	for (int i=0;i<N;i++) {
		S[i]={A[i],i};
	}
	
	for (int i=0;i<Q;i++) {
		S[i+N]={V[i],X[i]};
	}
	
	sort(S.begin(),S.end());
	data.build(0,N+Q-1);
	
	for (int i=0;i<N;i++) {
		add({A[i],i});
	}
	
	for (int i=0;i<Q;i++) {
		del({A[X[i]],X[i]});
		A[X[i]]=V[i];
		add({A[X[i]],X[i]});
		H[i]=data.val;
	}
	
	return H;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 6 ms 768 KB Output is correct
4 Correct 6 ms 768 KB Output is correct
5 Correct 6 ms 768 KB Output is correct
6 Correct 5 ms 768 KB Output is correct
7 Correct 5 ms 768 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 6 ms 768 KB Output is correct
10 Correct 5 ms 768 KB Output is correct
11 Correct 7 ms 768 KB Output is correct
12 Correct 5 ms 768 KB Output is correct
13 Correct 6 ms 768 KB Output is correct
14 Correct 5 ms 768 KB Output is correct
15 Correct 5 ms 768 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 5 ms 768 KB Output is correct
18 Correct 5 ms 800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 6 ms 768 KB Output is correct
4 Correct 6 ms 768 KB Output is correct
5 Correct 6 ms 768 KB Output is correct
6 Correct 5 ms 768 KB Output is correct
7 Correct 5 ms 768 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 6 ms 768 KB Output is correct
10 Correct 5 ms 768 KB Output is correct
11 Correct 7 ms 768 KB Output is correct
12 Correct 5 ms 768 KB Output is correct
13 Correct 6 ms 768 KB Output is correct
14 Correct 5 ms 768 KB Output is correct
15 Correct 5 ms 768 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 5 ms 768 KB Output is correct
18 Correct 5 ms 800 KB Output is correct
19 Correct 21 ms 2048 KB Output is correct
20 Correct 24 ms 2176 KB Output is correct
21 Correct 27 ms 2176 KB Output is correct
22 Correct 25 ms 2176 KB Output is correct
23 Correct 22 ms 2176 KB Output is correct
24 Correct 25 ms 2304 KB Output is correct
25 Correct 22 ms 2176 KB Output is correct
26 Correct 22 ms 2176 KB Output is correct
27 Correct 21 ms 2176 KB Output is correct
28 Correct 21 ms 2208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 3584 KB Output is correct
2 Correct 103 ms 7704 KB Output is correct
3 Correct 195 ms 12024 KB Output is correct
4 Correct 197 ms 12664 KB Output is correct
5 Correct 198 ms 12664 KB Output is correct
6 Correct 193 ms 12664 KB Output is correct
7 Correct 196 ms 12664 KB Output is correct
8 Correct 189 ms 12668 KB Output is correct
9 Correct 189 ms 12668 KB Output is correct
10 Correct 153 ms 12664 KB Output is correct
11 Correct 147 ms 12792 KB Output is correct
12 Correct 147 ms 12792 KB Output is correct
13 Correct 141 ms 12664 KB Output is correct
14 Correct 163 ms 12792 KB Output is correct
15 Correct 147 ms 12792 KB Output is correct
16 Correct 131 ms 12664 KB Output is correct
17 Correct 158 ms 12664 KB Output is correct
18 Correct 159 ms 12664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 6 ms 768 KB Output is correct
4 Correct 6 ms 768 KB Output is correct
5 Correct 6 ms 768 KB Output is correct
6 Correct 5 ms 768 KB Output is correct
7 Correct 5 ms 768 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 6 ms 768 KB Output is correct
10 Correct 5 ms 768 KB Output is correct
11 Correct 7 ms 768 KB Output is correct
12 Correct 5 ms 768 KB Output is correct
13 Correct 6 ms 768 KB Output is correct
14 Correct 5 ms 768 KB Output is correct
15 Correct 5 ms 768 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 5 ms 768 KB Output is correct
18 Correct 5 ms 800 KB Output is correct
19 Correct 21 ms 2048 KB Output is correct
20 Correct 24 ms 2176 KB Output is correct
21 Correct 27 ms 2176 KB Output is correct
22 Correct 25 ms 2176 KB Output is correct
23 Correct 22 ms 2176 KB Output is correct
24 Correct 25 ms 2304 KB Output is correct
25 Correct 22 ms 2176 KB Output is correct
26 Correct 22 ms 2176 KB Output is correct
27 Correct 21 ms 2176 KB Output is correct
28 Correct 21 ms 2208 KB Output is correct
29 Correct 34 ms 3584 KB Output is correct
30 Correct 103 ms 7704 KB Output is correct
31 Correct 195 ms 12024 KB Output is correct
32 Correct 197 ms 12664 KB Output is correct
33 Correct 198 ms 12664 KB Output is correct
34 Correct 193 ms 12664 KB Output is correct
35 Correct 196 ms 12664 KB Output is correct
36 Correct 189 ms 12668 KB Output is correct
37 Correct 189 ms 12668 KB Output is correct
38 Correct 153 ms 12664 KB Output is correct
39 Correct 147 ms 12792 KB Output is correct
40 Correct 147 ms 12792 KB Output is correct
41 Correct 141 ms 12664 KB Output is correct
42 Correct 163 ms 12792 KB Output is correct
43 Correct 147 ms 12792 KB Output is correct
44 Correct 131 ms 12664 KB Output is correct
45 Correct 158 ms 12664 KB Output is correct
46 Correct 159 ms 12664 KB Output is correct
47 Correct 837 ms 38776 KB Output is correct
48 Correct 3045 ms 119672 KB Output is correct
49 Correct 3361 ms 130680 KB Output is correct
50 Correct 3382 ms 130596 KB Output is correct
51 Correct 3148 ms 130680 KB Output is correct
52 Correct 3351 ms 130920 KB Output is correct
53 Correct 3362 ms 130668 KB Output is correct
54 Correct 2886 ms 130936 KB Output is correct
55 Correct 3251 ms 130868 KB Output is correct
56 Correct 2934 ms 130848 KB Output is correct
57 Correct 3127 ms 130836 KB Output is correct
58 Correct 2892 ms 130808 KB Output is correct
59 Correct 2671 ms 129484 KB Output is correct
60 Correct 2703 ms 129528 KB Output is correct
61 Correct 2638 ms 129528 KB Output is correct
62 Correct 2547 ms 129272 KB Output is correct
63 Correct 2564 ms 129528 KB Output is correct
64 Correct 2547 ms 129272 KB Output is correct
65 Correct 2369 ms 129220 KB Output is correct
66 Correct 2368 ms 129252 KB Output is correct
67 Correct 2375 ms 129196 KB Output is correct