답안 #302346

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
302346 2020-09-18T15:54:24 Z TMJN 커다란 상품 (IOI17_prize) C++17
100 / 100
73 ms 3860 KB
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;

int L[200000],R[200000],tree[1<<19];
set<int>st;

void update(int x){
	x+=1<<18;
	while(x){
		tree[x]++;
		x/=2;
	}
}

int calc(int l,int r){
	l+=1<<18;
	r+=1<<18;
	int a=0;
	while(l<r){
		if(l&1)a+=tree[l];
		if(~r&1)a+=tree[r];
		l=(l+1)/2;
		r=(r-1)/2;
	}
	if(l==r)a+=tree[l];
	return a;
}

int find_best(int n){
	for(int i=0;i<n;i++){
		L[i]=R[i]=-1;
	}
	int s=-1;
	mt19937 E(869120);
	for(int i=0;i<min(600,n);i++){
		int t;
		do{
			t=E()%n;
		}while(L[t]!=-1);
		vector<int>v=ask(t);
		st.insert(t);
		L[t]=v[0];
		R[t]=v[1];
		s=max(s,L[t]+R[t]);
	}
	int last_val=-1;
	for(int i=0;i<s;i++){
		int l=last_val;
		int r=n-1;
		while(l+1!=r){
			int m=(l+r)/2;
			auto it=st.lower_bound(m);
			if(it!=st.end()&&*it<r)m=*it;
			if(it!=st.begin()){
				it--;
				if(*it>l)m=*it;
			}
			if(L[m]==-1){
				vector<int>v=ask(m);
				st.insert(m);
				L[m]=v[0];
				R[m]=v[1];
			}
			if(L[m]+R[m]!=s){
				r=m;
			}
			else if(L[m]-calc(0,m)>0){
				r=m;
			}
			else{
				l=m;
			}
		}
		if(L[r]==-1){
			vector<int>v=ask(r);
			st.insert(r);
			L[r]=v[0];
			R[r]=v[1];
		}
		update(r);
		if(L[r]==0&&R[r]==0){
			return r;
		}
		last_val=r;
	}
	return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1896 KB Output is correct
2 Correct 5 ms 1972 KB Output is correct
3 Correct 9 ms 1904 KB Output is correct
4 Correct 9 ms 2048 KB Output is correct
5 Correct 10 ms 1920 KB Output is correct
6 Correct 10 ms 1952 KB Output is correct
7 Correct 7 ms 1920 KB Output is correct
8 Correct 9 ms 1920 KB Output is correct
9 Correct 10 ms 1920 KB Output is correct
10 Correct 10 ms 1920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1980 KB Output is correct
2 Correct 9 ms 1920 KB Output is correct
3 Correct 7 ms 1972 KB Output is correct
4 Correct 7 ms 1948 KB Output is correct
5 Correct 12 ms 2048 KB Output is correct
6 Correct 9 ms 1964 KB Output is correct
7 Correct 7 ms 1920 KB Output is correct
8 Correct 8 ms 1920 KB Output is correct
9 Correct 9 ms 1920 KB Output is correct
10 Correct 8 ms 1920 KB Output is correct
11 Correct 12 ms 2152 KB Output is correct
12 Correct 9 ms 1920 KB Output is correct
13 Correct 11 ms 2552 KB Output is correct
14 Correct 9 ms 640 KB Output is correct
15 Correct 16 ms 2176 KB Output is correct
16 Correct 50 ms 3436 KB Output is correct
17 Correct 10 ms 1948 KB Output is correct
18 Correct 50 ms 3704 KB Output is correct
19 Correct 10 ms 1920 KB Output is correct
20 Correct 16 ms 1528 KB Output is correct
21 Correct 24 ms 2584 KB Output is correct
22 Correct 16 ms 2048 KB Output is correct
23 Correct 8 ms 1920 KB Output is correct
24 Correct 7 ms 1920 KB Output is correct
25 Correct 36 ms 2808 KB Output is correct
26 Correct 36 ms 2924 KB Output is correct
27 Correct 10 ms 2040 KB Output is correct
28 Correct 44 ms 3576 KB Output is correct
29 Correct 38 ms 3320 KB Output is correct
30 Correct 47 ms 3704 KB Output is correct
31 Correct 9 ms 1920 KB Output is correct
32 Correct 12 ms 2304 KB Output is correct
33 Correct 1 ms 396 KB Output is correct
34 Correct 28 ms 2424 KB Output is correct
35 Correct 11 ms 2176 KB Output is correct
36 Correct 19 ms 2560 KB Output is correct
37 Correct 11 ms 2176 KB Output is correct
38 Correct 10 ms 1920 KB Output is correct
39 Correct 26 ms 2680 KB Output is correct
40 Correct 44 ms 3800 KB Output is correct
41 Correct 33 ms 2936 KB Output is correct
42 Correct 31 ms 2936 KB Output is correct
43 Correct 29 ms 2948 KB Output is correct
44 Correct 30 ms 2680 KB Output is correct
45 Correct 19 ms 2552 KB Output is correct
46 Correct 8 ms 1920 KB Output is correct
47 Correct 32 ms 2680 KB Output is correct
48 Correct 40 ms 3192 KB Output is correct
49 Correct 13 ms 2176 KB Output is correct
50 Correct 51 ms 3704 KB Output is correct
51 Correct 25 ms 2680 KB Output is correct
52 Correct 10 ms 1920 KB Output is correct
53 Correct 7 ms 2176 KB Output is correct
54 Correct 32 ms 2680 KB Output is correct
55 Correct 7 ms 2060 KB Output is correct
56 Correct 44 ms 3636 KB Output is correct
57 Correct 38 ms 3192 KB Output is correct
58 Correct 29 ms 3324 KB Output is correct
59 Correct 32 ms 2936 KB Output is correct
60 Correct 27 ms 2808 KB Output is correct
61 Correct 7 ms 2168 KB Output is correct
62 Correct 8 ms 1920 KB Output is correct
63 Correct 9 ms 2176 KB Output is correct
64 Correct 9 ms 2048 KB Output is correct
65 Correct 8 ms 1920 KB Output is correct
66 Correct 12 ms 1920 KB Output is correct
67 Correct 8 ms 1920 KB Output is correct
68 Correct 11 ms 1920 KB Output is correct
69 Correct 15 ms 2040 KB Output is correct
70 Correct 9 ms 1920 KB Output is correct
71 Correct 73 ms 3704 KB Output is correct
72 Correct 15 ms 2552 KB Output is correct
73 Correct 58 ms 3704 KB Output is correct
74 Correct 61 ms 3704 KB Output is correct
75 Correct 9 ms 2176 KB Output is correct
76 Correct 59 ms 3616 KB Output is correct
77 Correct 45 ms 3704 KB Output is correct
78 Correct 14 ms 2552 KB Output is correct
79 Correct 42 ms 3448 KB Output is correct
80 Correct 49 ms 3704 KB Output is correct
81 Correct 51 ms 3704 KB Output is correct
82 Correct 33 ms 3732 KB Output is correct
83 Correct 6 ms 2076 KB Output is correct
84 Correct 45 ms 3704 KB Output is correct
85 Correct 37 ms 3860 KB Output is correct
86 Correct 49 ms 3580 KB Output is correct
87 Correct 11 ms 2432 KB Output is correct
88 Correct 53 ms 3504 KB Output is correct
89 Correct 33 ms 2680 KB Output is correct
90 Correct 8 ms 2048 KB Output is correct
91 Correct 34 ms 3064 KB Output is correct
92 Correct 41 ms 3064 KB Output is correct
93 Correct 46 ms 3448 KB Output is correct
94 Correct 55 ms 3544 KB Output is correct
95 Correct 56 ms 3576 KB Output is correct
96 Correct 60 ms 3576 KB Output is correct
97 Correct 55 ms 3448 KB Output is correct