답안 #66799

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66799 2018-08-12T10:26:27 Z Diuven Bubble Sort 2 (JOI18_bubblesort2) C++11
100 / 100
2089 ms 80756 KB
#include "bubblesort2.h"
#include <algorithm>
#include <iostream>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int inf=2e9;

int n, q, B[1<<20], lim;

vector<pii> comp;

struct node{
	int mx, lz, cnt;
} tree[1<<21];

void lazy(int v, int val){
	tree[v].mx-=val, tree[v].cnt+=val, tree[v].lz+=val;
}
void busy(int v, int s, int e){
	int &z=tree[v].lz;
	if(s!=e){
		lazy(v*2, z);
		lazy(v*2+1,z);
	}
	z=0;
}
void del(int v, int s, int e, int pos){
	busy(v,s,e);
	node &nd=tree[v];
	if(s==e){
		nd.mx=-nd.cnt;
		return;
	}
	int m=(s+e)/2;
	if(pos<=m){
		lazy(v*2+1,-1);
		del(v*2,s,m,pos);
	}
	else{
		del(v*2+1,m+1,e,pos);
	}
	nd.mx=max(tree[v*2].mx, tree[v*2+1].mx);
}
void del(int pos){
	del(1,1,lim,pos);
}
void add(int v, int s, int e, int pos, int idx){
	busy(v,s,e);
	node &nd=tree[v];
	if(s==e){
		nd.mx=idx-nd.cnt;
		return;
	}
	int m=(s+e)/2;
	if(pos<=m){
		lazy(v*2+1,1);
		add(v*2,s,m,pos,idx);
	}
	else{
		add(v*2+1,m+1,e,pos,idx);
	}
	nd.mx=max(tree[v*2].mx, tree[v*2+1].mx);
}
void add(int pos, int idx){
	add(1,1,lim,pos,idx);
}
int mx(){
	return tree[1].mx;
}

void debug(int v=1, int s=1, int e=lim){
	busy(v,s,e);
	node &nd=tree[v];
	if(s==e){ cout<<s<<": "<<nd.mx<<' '<<nd.cnt<<'\n'; return; }
	int m=(s+e)/2;
	debug(v*2,s,m);
	debug(v*2+1,m+1,e);
}

int resp(int x, int pos){
	return lower_bound(comp.begin(), comp.end(), pii({x,pos}))-comp.begin()+1;
}

vi countScans(vi A, vi X, vi V){

	vi ans;

	n=A.size(), q=X.size();

	for(int i=0; i<n; i++) comp.push_back({A[i], i});
	for(int i=0; i<q; i++) comp.push_back({V[i], X[i]});

	sort(comp.begin(), comp.end());
	lim=unique(comp.begin(), comp.end())-comp.begin();
	comp.resize(lim);

	for(int i=0; i<n; i++){
		int val=resp(A[i], i);
		B[i]=val;
		add(val, i);
	}

	for(int ii=0; ii<q; ii++){
		int val=resp(V[ii], X[ii]), idx=X[ii];
		del(B[idx]);
		B[idx]=val;
		add(val, idx);
		ans.push_back(mx());
	}

	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 500 KB Output is correct
3 Correct 7 ms 724 KB Output is correct
4 Correct 7 ms 848 KB Output is correct
5 Correct 6 ms 948 KB Output is correct
6 Correct 8 ms 1012 KB Output is correct
7 Correct 6 ms 1060 KB Output is correct
8 Correct 7 ms 1140 KB Output is correct
9 Correct 8 ms 1244 KB Output is correct
10 Correct 8 ms 1308 KB Output is correct
11 Correct 5 ms 1348 KB Output is correct
12 Correct 7 ms 1388 KB Output is correct
13 Correct 6 ms 1432 KB Output is correct
14 Correct 7 ms 1596 KB Output is correct
15 Correct 7 ms 1596 KB Output is correct
16 Correct 8 ms 1596 KB Output is correct
17 Correct 7 ms 1596 KB Output is correct
18 Correct 9 ms 1632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 500 KB Output is correct
3 Correct 7 ms 724 KB Output is correct
4 Correct 7 ms 848 KB Output is correct
5 Correct 6 ms 948 KB Output is correct
6 Correct 8 ms 1012 KB Output is correct
7 Correct 6 ms 1060 KB Output is correct
8 Correct 7 ms 1140 KB Output is correct
9 Correct 8 ms 1244 KB Output is correct
10 Correct 8 ms 1308 KB Output is correct
11 Correct 5 ms 1348 KB Output is correct
12 Correct 7 ms 1388 KB Output is correct
13 Correct 6 ms 1432 KB Output is correct
14 Correct 7 ms 1596 KB Output is correct
15 Correct 7 ms 1596 KB Output is correct
16 Correct 8 ms 1596 KB Output is correct
17 Correct 7 ms 1596 KB Output is correct
18 Correct 9 ms 1632 KB Output is correct
19 Correct 17 ms 2440 KB Output is correct
20 Correct 21 ms 2608 KB Output is correct
21 Correct 17 ms 2800 KB Output is correct
22 Correct 19 ms 2976 KB Output is correct
23 Correct 17 ms 3116 KB Output is correct
24 Correct 16 ms 3116 KB Output is correct
25 Correct 19 ms 3116 KB Output is correct
26 Correct 19 ms 3116 KB Output is correct
27 Correct 17 ms 3116 KB Output is correct
28 Correct 22 ms 3116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 3504 KB Output is correct
2 Correct 77 ms 5132 KB Output is correct
3 Correct 126 ms 7876 KB Output is correct
4 Correct 126 ms 7876 KB Output is correct
5 Correct 120 ms 7876 KB Output is correct
6 Correct 124 ms 7876 KB Output is correct
7 Correct 129 ms 7876 KB Output is correct
8 Correct 127 ms 7904 KB Output is correct
9 Correct 107 ms 7904 KB Output is correct
10 Correct 87 ms 7904 KB Output is correct
11 Correct 90 ms 7904 KB Output is correct
12 Correct 90 ms 7904 KB Output is correct
13 Correct 99 ms 7904 KB Output is correct
14 Correct 103 ms 7904 KB Output is correct
15 Correct 86 ms 7904 KB Output is correct
16 Correct 107 ms 7904 KB Output is correct
17 Correct 81 ms 7904 KB Output is correct
18 Correct 81 ms 7904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 500 KB Output is correct
3 Correct 7 ms 724 KB Output is correct
4 Correct 7 ms 848 KB Output is correct
5 Correct 6 ms 948 KB Output is correct
6 Correct 8 ms 1012 KB Output is correct
7 Correct 6 ms 1060 KB Output is correct
8 Correct 7 ms 1140 KB Output is correct
9 Correct 8 ms 1244 KB Output is correct
10 Correct 8 ms 1308 KB Output is correct
11 Correct 5 ms 1348 KB Output is correct
12 Correct 7 ms 1388 KB Output is correct
13 Correct 6 ms 1432 KB Output is correct
14 Correct 7 ms 1596 KB Output is correct
15 Correct 7 ms 1596 KB Output is correct
16 Correct 8 ms 1596 KB Output is correct
17 Correct 7 ms 1596 KB Output is correct
18 Correct 9 ms 1632 KB Output is correct
19 Correct 17 ms 2440 KB Output is correct
20 Correct 21 ms 2608 KB Output is correct
21 Correct 17 ms 2800 KB Output is correct
22 Correct 19 ms 2976 KB Output is correct
23 Correct 17 ms 3116 KB Output is correct
24 Correct 16 ms 3116 KB Output is correct
25 Correct 19 ms 3116 KB Output is correct
26 Correct 19 ms 3116 KB Output is correct
27 Correct 17 ms 3116 KB Output is correct
28 Correct 22 ms 3116 KB Output is correct
29 Correct 23 ms 3504 KB Output is correct
30 Correct 77 ms 5132 KB Output is correct
31 Correct 126 ms 7876 KB Output is correct
32 Correct 126 ms 7876 KB Output is correct
33 Correct 120 ms 7876 KB Output is correct
34 Correct 124 ms 7876 KB Output is correct
35 Correct 129 ms 7876 KB Output is correct
36 Correct 127 ms 7904 KB Output is correct
37 Correct 107 ms 7904 KB Output is correct
38 Correct 87 ms 7904 KB Output is correct
39 Correct 90 ms 7904 KB Output is correct
40 Correct 90 ms 7904 KB Output is correct
41 Correct 99 ms 7904 KB Output is correct
42 Correct 103 ms 7904 KB Output is correct
43 Correct 86 ms 7904 KB Output is correct
44 Correct 107 ms 7904 KB Output is correct
45 Correct 81 ms 7904 KB Output is correct
46 Correct 81 ms 7904 KB Output is correct
47 Correct 512 ms 22392 KB Output is correct
48 Correct 2075 ms 51740 KB Output is correct
49 Correct 2061 ms 53556 KB Output is correct
50 Correct 2089 ms 53556 KB Output is correct
51 Correct 2045 ms 53568 KB Output is correct
52 Correct 1807 ms 53568 KB Output is correct
53 Correct 1959 ms 53568 KB Output is correct
54 Correct 1832 ms 53568 KB Output is correct
55 Correct 1913 ms 53568 KB Output is correct
56 Correct 1637 ms 53568 KB Output is correct
57 Correct 1790 ms 53568 KB Output is correct
58 Correct 1704 ms 53568 KB Output is correct
59 Correct 1595 ms 53568 KB Output is correct
60 Correct 1705 ms 53568 KB Output is correct
61 Correct 1646 ms 56432 KB Output is correct
62 Correct 1671 ms 68020 KB Output is correct
63 Correct 1728 ms 79684 KB Output is correct
64 Correct 1650 ms 80728 KB Output is correct
65 Correct 1648 ms 80728 KB Output is correct
66 Correct 1511 ms 80728 KB Output is correct
67 Correct 1670 ms 80756 KB Output is correct