#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int K = 500;
const int N = 2e5;
const int L = 5000;
const int mod = 998244353;
set <int> s;
int l2[N],r2[N];
int cnt = 0;
int mx = 0;
int qcount = 0;
int ans = -1;
int seed = 17;
int f(){
return rng()%mod;
seed = 1ll*seed*seed%mod;
return seed;
}
vector<int> ask2(int x){
if(l2[x] == 0 && r2[x] == 0){
auto nr = ask(x);
l2[x] = nr[0];
r2[x] = nr[1];
}
return {l2[x],r2[x]};
}
void solve(int l,int r,int dl,int dr){
if(dl + dr >= mx)return;
if(l > r)return;
int mij = rng()%(r - l + 1) + l;
for(int i = mij;i <= r;i++){
auto x = ask2(i);
if(x[0] + x[1] == mx){
x[0]-=dl;
x[1]-=dr;
solve(i + 1,r,x[0] + dl,dr);
if(ans != -1)return;
solve(l,mij - 1,dl,dr + x[1] + i - mij);
return;
}else{
if(x[0] + x[1] == 0){
ans = i;
return;
}
}
}
solve(l,mij - 1,dl,dr);
return;
}
int find_best(int n) {
for(int i = 0;i < K;i++){
int id = f()%n;
//cout<<id<<'\n';
auto x = ask2(id);
int nr = x[0] + x[1];
if(nr == 0)return id;
if(nr > mx){
mx = nr;
cnt = 1;
}else if(nr == mx){
cnt++;
}
}
solve(0,n - 1,0,0);
return ans;
}
/**
8
3 3 3 3 2 2 2 1
**/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1764 KB |
Output is correct |
2 |
Correct |
3 ms |
2144 KB |
Output is correct |
3 |
Correct |
4 ms |
2020 KB |
Output is correct |
4 |
Correct |
3 ms |
2036 KB |
Output is correct |
5 |
Correct |
3 ms |
2008 KB |
Output is correct |
6 |
Correct |
4 ms |
1980 KB |
Output is correct |
7 |
Correct |
3 ms |
2052 KB |
Output is correct |
8 |
Correct |
3 ms |
1872 KB |
Output is correct |
9 |
Correct |
3 ms |
1892 KB |
Output is correct |
10 |
Correct |
3 ms |
1848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1864 KB |
Output is correct |
2 |
Correct |
3 ms |
1876 KB |
Output is correct |
3 |
Correct |
3 ms |
2104 KB |
Output is correct |
4 |
Correct |
4 ms |
2224 KB |
Output is correct |
5 |
Correct |
3 ms |
1832 KB |
Output is correct |
6 |
Correct |
4 ms |
2536 KB |
Output is correct |
7 |
Correct |
3 ms |
2160 KB |
Output is correct |
8 |
Correct |
3 ms |
2064 KB |
Output is correct |
9 |
Correct |
3 ms |
1884 KB |
Output is correct |
10 |
Correct |
3 ms |
1748 KB |
Output is correct |
11 |
Correct |
4 ms |
2012 KB |
Output is correct |
12 |
Correct |
8 ms |
2280 KB |
Output is correct |
13 |
Correct |
4 ms |
2048 KB |
Output is correct |
14 |
Correct |
5 ms |
456 KB |
Output is correct |
15 |
Partially correct |
20 ms |
2444 KB |
Partially correct - number of queries: 5107 |
16 |
Correct |
9 ms |
2480 KB |
Output is correct |
17 |
Partially correct |
48 ms |
2036 KB |
Partially correct - number of queries: 6071 |
18 |
Correct |
3 ms |
2288 KB |
Output is correct |
19 |
Partially correct |
33 ms |
2232 KB |
Partially correct - number of queries: 5827 |
20 |
Correct |
13 ms |
1536 KB |
Output is correct |
21 |
Correct |
24 ms |
2444 KB |
Output is correct |
22 |
Correct |
26 ms |
2692 KB |
Output is correct |
23 |
Correct |
4 ms |
2064 KB |
Output is correct |
24 |
Correct |
5 ms |
1952 KB |
Output is correct |
25 |
Correct |
11 ms |
2440 KB |
Output is correct |
26 |
Correct |
14 ms |
2248 KB |
Output is correct |
27 |
Correct |
4 ms |
2476 KB |
Output is correct |
28 |
Correct |
6 ms |
2252 KB |
Output is correct |
29 |
Correct |
6 ms |
2072 KB |
Output is correct |
30 |
Correct |
3 ms |
2092 KB |
Output is correct |
31 |
Partially correct |
31 ms |
2528 KB |
Partially correct - number of queries: 6133 |
32 |
Correct |
4 ms |
2400 KB |
Output is correct |
33 |
Correct |
0 ms |
452 KB |
Output is correct |
34 |
Correct |
24 ms |
2500 KB |
Output is correct |
35 |
Correct |
4 ms |
2384 KB |
Output is correct |
36 |
Correct |
25 ms |
2852 KB |
Output is correct |
37 |
Correct |
5 ms |
2524 KB |
Output is correct |
38 |
Correct |
3 ms |
2368 KB |
Output is correct |
39 |
Correct |
17 ms |
2928 KB |
Output is correct |
40 |
Correct |
3 ms |
1824 KB |
Output is correct |
41 |
Correct |
13 ms |
2404 KB |
Output is correct |
42 |
Correct |
19 ms |
2388 KB |
Output is correct |
43 |
Correct |
16 ms |
2384 KB |
Output is correct |
44 |
Correct |
18 ms |
2160 KB |
Output is correct |
45 |
Correct |
16 ms |
2872 KB |
Output is correct |
46 |
Partially correct |
29 ms |
2232 KB |
Partially correct - number of queries: 6249 |
47 |
Correct |
15 ms |
2408 KB |
Output is correct |
48 |
Correct |
10 ms |
2180 KB |
Output is correct |
49 |
Partially correct |
24 ms |
2452 KB |
Partially correct - number of queries: 5773 |
50 |
Correct |
3 ms |
1876 KB |
Output is correct |
51 |
Correct |
19 ms |
2648 KB |
Output is correct |
52 |
Partially correct |
24 ms |
2448 KB |
Partially correct - number of queries: 6067 |
53 |
Correct |
3 ms |
2344 KB |
Output is correct |
54 |
Correct |
15 ms |
2188 KB |
Output is correct |
55 |
Partially correct |
34 ms |
2224 KB |
Partially correct - number of queries: 6064 |
56 |
Correct |
3 ms |
2044 KB |
Output is correct |
57 |
Correct |
14 ms |
2488 KB |
Output is correct |
58 |
Correct |
11 ms |
2188 KB |
Output is correct |
59 |
Correct |
16 ms |
2340 KB |
Output is correct |
60 |
Correct |
13 ms |
2144 KB |
Output is correct |
61 |
Correct |
3 ms |
2512 KB |
Output is correct |
62 |
Correct |
4 ms |
1872 KB |
Output is correct |
63 |
Correct |
4 ms |
2496 KB |
Output is correct |
64 |
Correct |
3 ms |
2112 KB |
Output is correct |
65 |
Correct |
4 ms |
2432 KB |
Output is correct |
66 |
Correct |
4 ms |
1820 KB |
Output is correct |
67 |
Correct |
4 ms |
2052 KB |
Output is correct |
68 |
Correct |
3 ms |
2112 KB |
Output is correct |
69 |
Correct |
5 ms |
1832 KB |
Output is correct |
70 |
Correct |
4 ms |
1892 KB |
Output is correct |
71 |
Partially correct |
38 ms |
2452 KB |
Partially correct - number of queries: 8797 |
72 |
Correct |
7 ms |
2452 KB |
Output is correct |
73 |
Partially correct |
43 ms |
2236 KB |
Partially correct - number of queries: 8698 |
74 |
Partially correct |
45 ms |
2604 KB |
Partially correct - number of queries: 8755 |
75 |
Correct |
4 ms |
2280 KB |
Output is correct |
76 |
Partially correct |
36 ms |
2212 KB |
Partially correct - number of queries: 7821 |
77 |
Partially correct |
40 ms |
2680 KB |
Partially correct - number of queries: 7750 |
78 |
Correct |
7 ms |
2500 KB |
Output is correct |
79 |
Correct |
25 ms |
2660 KB |
Output is correct |
80 |
Partially correct |
44 ms |
2320 KB |
Partially correct - number of queries: 7805 |
81 |
Partially correct |
39 ms |
2392 KB |
Partially correct - number of queries: 7700 |
82 |
Partially correct |
43 ms |
2780 KB |
Partially correct - number of queries: 7802 |
83 |
Correct |
4 ms |
2248 KB |
Output is correct |
84 |
Partially correct |
26 ms |
2780 KB |
Partially correct - number of queries: 6652 |
85 |
Partially correct |
38 ms |
2776 KB |
Partially correct - number of queries: 7803 |
86 |
Correct |
27 ms |
2868 KB |
Output is correct |
87 |
Correct |
3 ms |
1988 KB |
Output is correct |
88 |
Correct |
12 ms |
2276 KB |
Output is correct |
89 |
Correct |
12 ms |
2116 KB |
Output is correct |
90 |
Correct |
3 ms |
1728 KB |
Output is correct |
91 |
Correct |
5 ms |
2496 KB |
Output is correct |
92 |
Correct |
7 ms |
2240 KB |
Output is correct |
93 |
Partially correct |
24 ms |
2592 KB |
Partially correct - number of queries: 5218 |
94 |
Correct |
31 ms |
2824 KB |
Output is correct |
95 |
Partially correct |
27 ms |
2668 KB |
Partially correct - number of queries: 5136 |
96 |
Partially correct |
20 ms |
2696 KB |
Partially correct - number of queries: 5146 |
97 |
Correct |
4 ms |
1848 KB |
Output is correct |