답안 #170385

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
170385 2019-12-25T01:45:10 Z workharder Minerals (JOI19_minerals) C++14
85 / 100
182 ms 9152 KB
#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN=86005;
int lo[MAXN],hi[MAXN],arr[MAXN],res[MAXN],n,bit[MAXN];
vector<int> mid[MAXN];
 
int query(int now){
	int ret=0;
	for(int i=now;i>0;i-=(i&(-i)))ret+=bit[i];
	return ret;
}
 
void update(int now,int val){
	for(int i=now;i<=n;i+=(i&(-i)))bit[i]+=val;
}
 
int binser(int x){
	int now=0;
	for(int i=17;i>=0;i--){
		if(now+(1<<i)<=n && bit[now+(1<<i)]<x){
			now+=(1<<i);
			x-=bit[now];
		}
	}
	return now+1;
}
 
int tengah(int x,int y){
	int L=query(x-1)+1,R=query(y),T;
	T=(L+R)/2;   //angka 1 ke T
	return binser(T);  //idx angka 1 ke T
}
 
void Solve(int N) {
	int prev=0,tmpL=1,tmpR=N+1,nxt,sudah=0,C=0;
	n=N;
	vector<int> v;
	for(int i=1;i<=2*N;i++)v.push_back(i);
	for(auto i : v){
		if(tmpL==N+1 || Query(i)==prev){
			arr[tmpR]=i;
			lo[tmpR]=C+1;
			hi[tmpR]=tmpL-1;
			if(lo[tmpR]<hi[tmpR])mid[tengah(lo[tmpR],hi[tmpR])].push_back(tmpR);
			else{
				Answer(i,arr[tmpL-1]);
				update(tmpL-1,-1);
				arr[tmpL-1]=0;
				sudah++;
			}
			tmpR++;
			if(tmpL==tmpR-N)C=tmpL-1;
		}
		else{
			update(tmpL,1);
			arr[tmpL]=i;
			tmpL++;
			prev++;
		}
	}
	int prefix=0;
	while(sudah<N){
		for(int i=1;i<=N;i++){
			if(arr[i])prev=Query(arr[i]);
			while(!mid[i].empty()){
				int now=mid[i].back();
				mid[i].pop_back();
				nxt=Query(arr[now]);
				if(prefix){
					if(nxt==prev){   //sudah ada
						hi[now]=i;
						res[now]=i;
						if(query(hi[now])-query(lo[now]-1)>1)mid[tengah(lo[now],hi[now])].push_back(now);
						else{
							sudah++;
							res[now]=binser(query(hi[now]));
							Answer(arr[now],arr[res[now]]);
							update(res[now],-1);
							arr[res[now]]=0;
						}
					}
					else{
						lo[now]=i+1;
						if(query(hi[now])-query(lo[now]-1)>1)mid[tengah(lo[now],hi[now])].push_back(now);
						else{
							sudah++;
							res[now]=binser(query(hi[now]));
							Answer(arr[now],arr[res[now]]);
							update(res[now],-1);
							arr[res[now]]=0;
						}
					}
				}
				else{
					if(nxt==prev){
						lo[now]=i+1;
						if(query(hi[now])-query(lo[now]-1)>1)mid[tengah(lo[now],hi[now])].push_back(now);
						else{
							sudah++;
							res[now]=binser(query(hi[now]));
							Answer(arr[now],arr[res[now]]);
							update(res[now],-1);
							arr[res[now]]=0;
						}
					}
					else{
						hi[now]=i;
						res[now]=i;
						if(query(hi[now])-query(lo[now]-1)>1)mid[tengah(lo[now],hi[now])].push_back(now);
						else{
							sudah++;
							res[now]=binser(query(hi[now]));
							Answer(arr[now],arr[res[now]]);
							update(res[now],-1);
							arr[res[now]]=0;
						}
					}
				}
				if(sudah==N)return;
				prev=nxt;
			}
		}
		prefix=1-prefix;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2296 KB Output is correct
2 Correct 3 ms 2296 KB Output is correct
3 Correct 4 ms 2296 KB Output is correct
4 Correct 3 ms 2296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2440 KB Output is correct
2 Correct 7 ms 2680 KB Output is correct
3 Correct 11 ms 2808 KB Output is correct
4 Correct 20 ms 3320 KB Output is correct
5 Correct 39 ms 4344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2296 KB Output is correct
2 Correct 3 ms 2296 KB Output is correct
3 Correct 4 ms 2296 KB Output is correct
4 Correct 3 ms 2296 KB Output is correct
5 Correct 6 ms 2440 KB Output is correct
6 Correct 7 ms 2680 KB Output is correct
7 Correct 11 ms 2808 KB Output is correct
8 Correct 20 ms 3320 KB Output is correct
9 Correct 39 ms 4344 KB Output is correct
10 Correct 5 ms 2552 KB Output is correct
11 Correct 33 ms 3448 KB Output is correct
12 Correct 52 ms 4008 KB Output is correct
13 Correct 9 ms 3320 KB Output is correct
14 Correct 33 ms 4392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2296 KB Output is correct
2 Correct 3 ms 2296 KB Output is correct
3 Correct 4 ms 2296 KB Output is correct
4 Correct 3 ms 2296 KB Output is correct
5 Correct 6 ms 2440 KB Output is correct
6 Correct 7 ms 2680 KB Output is correct
7 Correct 11 ms 2808 KB Output is correct
8 Correct 20 ms 3320 KB Output is correct
9 Correct 39 ms 4344 KB Output is correct
10 Correct 5 ms 2552 KB Output is correct
11 Correct 33 ms 3448 KB Output is correct
12 Correct 52 ms 4008 KB Output is correct
13 Correct 9 ms 3320 KB Output is correct
14 Correct 33 ms 4392 KB Output is correct
15 Correct 157 ms 6432 KB Output is correct
16 Correct 157 ms 6428 KB Output is correct
17 Correct 17 ms 4720 KB Output is correct
18 Correct 89 ms 8760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2296 KB Output is correct
2 Correct 3 ms 2296 KB Output is correct
3 Correct 4 ms 2296 KB Output is correct
4 Correct 3 ms 2296 KB Output is correct
5 Correct 6 ms 2440 KB Output is correct
6 Correct 7 ms 2680 KB Output is correct
7 Correct 11 ms 2808 KB Output is correct
8 Correct 20 ms 3320 KB Output is correct
9 Correct 39 ms 4344 KB Output is correct
10 Correct 5 ms 2552 KB Output is correct
11 Correct 33 ms 3448 KB Output is correct
12 Correct 52 ms 4008 KB Output is correct
13 Correct 9 ms 3320 KB Output is correct
14 Correct 33 ms 4392 KB Output is correct
15 Correct 157 ms 6432 KB Output is correct
16 Correct 157 ms 6428 KB Output is correct
17 Correct 17 ms 4720 KB Output is correct
18 Correct 89 ms 8760 KB Output is correct
19 Correct 168 ms 6620 KB Output is correct
20 Correct 160 ms 6616 KB Output is correct
21 Correct 17 ms 4720 KB Output is correct
22 Correct 90 ms 8864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2296 KB Output is correct
2 Correct 3 ms 2296 KB Output is correct
3 Correct 4 ms 2296 KB Output is correct
4 Correct 3 ms 2296 KB Output is correct
5 Correct 6 ms 2440 KB Output is correct
6 Correct 7 ms 2680 KB Output is correct
7 Correct 11 ms 2808 KB Output is correct
8 Correct 20 ms 3320 KB Output is correct
9 Correct 39 ms 4344 KB Output is correct
10 Correct 5 ms 2552 KB Output is correct
11 Correct 33 ms 3448 KB Output is correct
12 Correct 52 ms 4008 KB Output is correct
13 Correct 9 ms 3320 KB Output is correct
14 Correct 33 ms 4392 KB Output is correct
15 Correct 157 ms 6432 KB Output is correct
16 Correct 157 ms 6428 KB Output is correct
17 Correct 17 ms 4720 KB Output is correct
18 Correct 89 ms 8760 KB Output is correct
19 Correct 168 ms 6620 KB Output is correct
20 Correct 160 ms 6616 KB Output is correct
21 Correct 17 ms 4720 KB Output is correct
22 Correct 90 ms 8864 KB Output is correct
23 Correct 164 ms 6712 KB Output is correct
24 Correct 168 ms 6740 KB Output is correct
25 Correct 17 ms 4848 KB Output is correct
26 Correct 93 ms 9152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2296 KB Output is correct
2 Correct 3 ms 2296 KB Output is correct
3 Correct 4 ms 2296 KB Output is correct
4 Correct 3 ms 2296 KB Output is correct
5 Correct 6 ms 2440 KB Output is correct
6 Correct 7 ms 2680 KB Output is correct
7 Correct 11 ms 2808 KB Output is correct
8 Correct 20 ms 3320 KB Output is correct
9 Correct 39 ms 4344 KB Output is correct
10 Correct 5 ms 2552 KB Output is correct
11 Correct 33 ms 3448 KB Output is correct
12 Correct 52 ms 4008 KB Output is correct
13 Correct 9 ms 3320 KB Output is correct
14 Correct 33 ms 4392 KB Output is correct
15 Correct 157 ms 6432 KB Output is correct
16 Correct 157 ms 6428 KB Output is correct
17 Correct 17 ms 4720 KB Output is correct
18 Correct 89 ms 8760 KB Output is correct
19 Correct 168 ms 6620 KB Output is correct
20 Correct 160 ms 6616 KB Output is correct
21 Correct 17 ms 4720 KB Output is correct
22 Correct 90 ms 8864 KB Output is correct
23 Correct 164 ms 6712 KB Output is correct
24 Correct 168 ms 6740 KB Output is correct
25 Correct 17 ms 4848 KB Output is correct
26 Correct 93 ms 9152 KB Output is correct
27 Correct 174 ms 6768 KB Output is correct
28 Correct 171 ms 6876 KB Output is correct
29 Correct 18 ms 4848 KB Output is correct
30 Correct 95 ms 9080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2296 KB Output is correct
2 Correct 3 ms 2296 KB Output is correct
3 Correct 4 ms 2296 KB Output is correct
4 Correct 3 ms 2296 KB Output is correct
5 Correct 6 ms 2440 KB Output is correct
6 Correct 7 ms 2680 KB Output is correct
7 Correct 11 ms 2808 KB Output is correct
8 Correct 20 ms 3320 KB Output is correct
9 Correct 39 ms 4344 KB Output is correct
10 Correct 5 ms 2552 KB Output is correct
11 Correct 33 ms 3448 KB Output is correct
12 Correct 52 ms 4008 KB Output is correct
13 Correct 9 ms 3320 KB Output is correct
14 Correct 33 ms 4392 KB Output is correct
15 Correct 157 ms 6432 KB Output is correct
16 Correct 157 ms 6428 KB Output is correct
17 Correct 17 ms 4720 KB Output is correct
18 Correct 89 ms 8760 KB Output is correct
19 Correct 168 ms 6620 KB Output is correct
20 Correct 160 ms 6616 KB Output is correct
21 Correct 17 ms 4720 KB Output is correct
22 Correct 90 ms 8864 KB Output is correct
23 Correct 164 ms 6712 KB Output is correct
24 Correct 168 ms 6740 KB Output is correct
25 Correct 17 ms 4848 KB Output is correct
26 Correct 93 ms 9152 KB Output is correct
27 Correct 174 ms 6768 KB Output is correct
28 Correct 171 ms 6876 KB Output is correct
29 Correct 18 ms 4848 KB Output is correct
30 Correct 95 ms 9080 KB Output is correct
31 Correct 176 ms 7016 KB Output is correct
32 Correct 182 ms 7080 KB Output is correct
33 Correct 18 ms 4972 KB Output is correct
34 Incorrect 94 ms 9072 KB Wrong Answer [2]
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2296 KB Output is correct
2 Correct 3 ms 2296 KB Output is correct
3 Correct 4 ms 2296 KB Output is correct
4 Correct 3 ms 2296 KB Output is correct
5 Correct 6 ms 2440 KB Output is correct
6 Correct 7 ms 2680 KB Output is correct
7 Correct 11 ms 2808 KB Output is correct
8 Correct 20 ms 3320 KB Output is correct
9 Correct 39 ms 4344 KB Output is correct
10 Correct 5 ms 2552 KB Output is correct
11 Correct 33 ms 3448 KB Output is correct
12 Correct 52 ms 4008 KB Output is correct
13 Correct 9 ms 3320 KB Output is correct
14 Correct 33 ms 4392 KB Output is correct
15 Correct 157 ms 6432 KB Output is correct
16 Correct 157 ms 6428 KB Output is correct
17 Correct 17 ms 4720 KB Output is correct
18 Correct 89 ms 8760 KB Output is correct
19 Correct 168 ms 6620 KB Output is correct
20 Correct 160 ms 6616 KB Output is correct
21 Correct 17 ms 4720 KB Output is correct
22 Correct 90 ms 8864 KB Output is correct
23 Correct 164 ms 6712 KB Output is correct
24 Correct 168 ms 6740 KB Output is correct
25 Correct 17 ms 4848 KB Output is correct
26 Correct 93 ms 9152 KB Output is correct
27 Correct 174 ms 6768 KB Output is correct
28 Correct 171 ms 6876 KB Output is correct
29 Correct 18 ms 4848 KB Output is correct
30 Correct 95 ms 9080 KB Output is correct
31 Correct 176 ms 7016 KB Output is correct
32 Correct 182 ms 7080 KB Output is correct
33 Correct 18 ms 4972 KB Output is correct
34 Incorrect 94 ms 9072 KB Wrong Answer [2]