Submission #828089

# Submission time Handle Problem Language Result Execution time Memory
828089 2023-08-17T04:13:55 Z tranxuanbach The Big Prize (IOI17_prize) C++17
97.68 / 100
49 ms 9264 KB
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 5;

struct fenwick_tree{
	int fen[N];
	bool account[N];

	void update(int i){
		account[i] = true;
		i++;
		for (; i < N; i += i & -i){
			fen[i]++;
		}
	}

	int query(int i){
		i++;
		int ans = 0;
		for (; i > 0; i -= i & -i){
			ans += fen[i];
		}
		return ans;
	}

	int query(int l, int r){
		return query(r) - query(l - 1);
	}
} fen;

int n;
vector <int> query_answer[N];
int cnt_left[N], cnt_right[N];
int type[N];

void query(int x){
	if (not query_answer[x].empty()){
		return;
	}
	query_answer[x] = ask(x);
	cnt_left[x] = query_answer[x].front();
	cnt_right[x] = query_answer[x].back();
	type[x] = accumulate(query_answer[x].begin(), query_answer[x].end(), 0);
}

int find_min_lollipop(){
	int lo = 1, hi = n - 1;
	while (lo < hi){
		int mid = (lo + hi) >> 1;
		int sum = 0, t = mid;
		while (t){
			sum += t;
			t = sqrt(t - 1);
		}
		if (sum >= n){
			hi = mid;
		}
		else{
			lo = mid + 1;
		}
	}
	return lo;
}

int type_lollipop;
int jump_right[N];

int search_important(int l, int r){
	if (l > r){
		exit(0);
	}
	if (l == r){
		query(l);
		fen.update(l);
		return l;
	}
	int mid = (l + r) >> 1;
	query(mid);
	if (type[mid] == type_lollipop){
		if (fen.query(mid + 1, n - 1) != cnt_right[mid]){
			return search_important(mid + 1, r);
		}
		else{
			return search_important(l, mid - 1);
		}
		return -1;
	}
	if (not fen.account[mid]){
		fen.update(mid);
		return mid;
	}
	int &idx = jump_right[mid];
	while (idx < n){
		query(idx);
		if (type[idx] == type_lollipop){
			break;
		}
		if (not fen.account[idx]){
			fen.update(idx);
			return idx;
		}
		idx++;
	}
	if (idx < n and fen.query(idx + 1, n - 1) != cnt_right[idx]){
		return search_important(idx + 1, r);
	}
	else{
		return search_important(l, mid - 1);
	}
	return -1;
}

int find_best(int _n){
	n = _n;
	int min_lollipop = find_min_lollipop();
	int max_important = n - min_lollipop;
	int lim = min(n, max_important + 1);
	for (int i = 0; i < lim; i++){
		query(i);
		if (type[i] == 0){
			return i;
		}
	}
	type_lollipop = *max_element(type, type + lim);
	for (int i = 0; i < lim; i++){
		if (type[i] != type_lollipop){
			fen.update(i);
		}
	}
	iota(jump_right, jump_right + n, 1);
	while (true){
		int idx = search_important(lim, n - 1);
		if (type[idx] == 0){
			return idx;
		}
	}
	return -1;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5900 KB Output is correct
2 Correct 4 ms 5896 KB Output is correct
3 Correct 4 ms 5936 KB Output is correct
4 Correct 7 ms 5840 KB Output is correct
5 Correct 6 ms 5984 KB Output is correct
6 Correct 2 ms 5012 KB Output is correct
7 Correct 7 ms 5908 KB Output is correct
8 Correct 6 ms 5904 KB Output is correct
9 Correct 6 ms 5832 KB Output is correct
10 Correct 6 ms 5840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5932 KB Output is correct
2 Correct 7 ms 5832 KB Output is correct
3 Correct 5 ms 5820 KB Output is correct
4 Correct 5 ms 5812 KB Output is correct
5 Correct 6 ms 5840 KB Output is correct
6 Correct 3 ms 4944 KB Output is correct
7 Correct 5 ms 6000 KB Output is correct
8 Correct 6 ms 5796 KB Output is correct
9 Correct 4 ms 5932 KB Output is correct
10 Correct 6 ms 5840 KB Output is correct
11 Correct 8 ms 6940 KB Output is correct
12 Correct 12 ms 7624 KB Output is correct
13 Correct 5 ms 5788 KB Output is correct
14 Correct 10 ms 5456 KB Output is correct
15 Correct 20 ms 8660 KB Output is correct
16 Correct 10 ms 6372 KB Output is correct
17 Correct 4 ms 4944 KB Output is correct
18 Correct 6 ms 5916 KB Output is correct
19 Correct 5 ms 5040 KB Output is correct
20 Correct 21 ms 6612 KB Output is correct
21 Correct 33 ms 7972 KB Output is correct
22 Correct 38 ms 8880 KB Output is correct
23 Correct 7 ms 6412 KB Output is correct
24 Correct 6 ms 7172 KB Output is correct
25 Correct 22 ms 7300 KB Output is correct
26 Correct 25 ms 7388 KB Output is correct
27 Correct 7 ms 6088 KB Output is correct
28 Correct 5 ms 5972 KB Output is correct
29 Correct 11 ms 6344 KB Output is correct
30 Correct 7 ms 5932 KB Output is correct
31 Correct 4 ms 5032 KB Output is correct
32 Correct 7 ms 6344 KB Output is correct
33 Correct 2 ms 4944 KB Output is correct
34 Correct 35 ms 8200 KB Output is correct
35 Correct 6 ms 6152 KB Output is correct
36 Correct 23 ms 8468 KB Output is correct
37 Correct 7 ms 6944 KB Output is correct
38 Correct 8 ms 6404 KB Output is correct
39 Correct 21 ms 7688 KB Output is correct
40 Correct 6 ms 5896 KB Output is correct
41 Correct 22 ms 7292 KB Output is correct
42 Correct 12 ms 7256 KB Output is correct
43 Correct 21 ms 7432 KB Output is correct
44 Correct 29 ms 7924 KB Output is correct
45 Correct 31 ms 8136 KB Output is correct
46 Correct 5 ms 5020 KB Output is correct
47 Correct 12 ms 7848 KB Output is correct
48 Correct 14 ms 6788 KB Output is correct
49 Correct 42 ms 8936 KB Output is correct
50 Correct 8 ms 5840 KB Output is correct
51 Correct 16 ms 7892 KB Output is correct
52 Correct 32 ms 9140 KB Output is correct
53 Correct 7 ms 5812 KB Output is correct
54 Correct 15 ms 7852 KB Output is correct
55 Correct 6 ms 5004 KB Output is correct
56 Correct 6 ms 5932 KB Output is correct
57 Correct 10 ms 6836 KB Output is correct
58 Correct 15 ms 6820 KB Output is correct
59 Correct 15 ms 7232 KB Output is correct
60 Correct 18 ms 7368 KB Output is correct
61 Correct 8 ms 5840 KB Output is correct
62 Correct 6 ms 6480 KB Output is correct
63 Correct 5 ms 5808 KB Output is correct
64 Correct 7 ms 6088 KB Output is correct
65 Correct 6 ms 5896 KB Output is correct
66 Correct 10 ms 5832 KB Output is correct
67 Correct 12 ms 5792 KB Output is correct
68 Correct 4 ms 5040 KB Output is correct
69 Correct 6 ms 5912 KB Output is correct
70 Correct 7 ms 5812 KB Output is correct
71 Partially correct 24 ms 9256 KB Partially correct - number of queries: 5232
72 Correct 12 ms 7624 KB Output is correct
73 Partially correct 30 ms 9264 KB Partially correct - number of queries: 5169
74 Partially correct 49 ms 9204 KB Partially correct - number of queries: 5196
75 Correct 7 ms 6480 KB Output is correct
76 Correct 44 ms 9132 KB Output is correct
77 Correct 40 ms 9192 KB Output is correct
78 Correct 10 ms 7632 KB Output is correct
79 Correct 22 ms 9124 KB Output is correct
80 Correct 32 ms 9104 KB Output is correct
81 Correct 43 ms 9124 KB Output is correct
82 Correct 33 ms 9128 KB Output is correct
83 Correct 8 ms 6456 KB Output is correct
84 Correct 29 ms 9180 KB Output is correct
85 Correct 32 ms 9160 KB Output is correct
86 Correct 8 ms 5924 KB Output is correct
87 Correct 6 ms 5916 KB Output is correct
88 Correct 6 ms 5840 KB Output is correct
89 Correct 5 ms 5840 KB Output is correct
90 Correct 7 ms 5936 KB Output is correct
91 Correct 7 ms 5840 KB Output is correct
92 Correct 6 ms 5840 KB Output is correct
93 Correct 9 ms 6892 KB Output is correct
94 Correct 8 ms 7064 KB Output is correct
95 Correct 11 ms 7148 KB Output is correct
96 Correct 10 ms 6912 KB Output is correct
97 Correct 7 ms 5968 KB Output is correct