#include "prize.h"
#include<bits/stdc++.h>
using namespace std;
int ll[300005];
int rr[300005];
int maxn = -1;
vector<int> ans;
int last = -1;
void find(int l,int r,int nowsize)
{
if(l == r)
{
ans.push_back(l);
return;
}
bool flag = true;
while(l <= r)
{
if(ll[l] == -1)
{
vector<int> temp = ask(l);
ll[l] = temp[0];rr[l] = temp[1];
if(ll[l] + rr[l] == maxn)break;
else
{
//if(ll[l] + rr[l] == 0)last = l;
ans.push_back(l);
l++;
}
}
else
{
if(ll[l] + rr[l] == maxn)break;
else
{
ans.push_back(l);
l++;
}
}
}
while(l <= r)
{
if(rr[r] == -1)
{
vector<int> temp = ask(r);
ll[r] = temp[0];rr[r] = temp[1];
if(ll[r] + rr[r] == maxn)break;
else
{
ans.push_back(r);
r--;
}
}
else
{
if(ll[r] + rr[r] == maxn)break;
else
{
ans.push_back(r);
r--;
}
}
}
if(l > r)return;
int mid1 = (l+r)>>1;
int mid2 = (l+r)>>1;
while(mid1 >= l)
{
if(rr[mid1] == -1)
{
vector<int> temp = ask(mid1);
ll[mid1] = temp[0];rr[mid1] = temp[1];
if(ll[mid1] + rr[mid1] == maxn)break;
else
{
ans.push_back(mid1);
mid1--;
}
}
else
{
if(ll[mid1] + rr[mid1] == maxn)break;
else
{
ans.push_back(mid1);
mid1--;
}
}
}
int xx = ll[mid1] - ll[l];
if(xx != 0)find(l,mid1,xx);
while(mid2 <= r)
{
if(ll[mid2] == -1)
{
vector<int> temp = ask(mid2);
ll[mid2] = temp[0];rr[mid2] = temp[1];
if(ll[mid2] + rr[mid2] == maxn)break;
else
{
ans.push_back(mid2);
mid2++;
}
}
else
{
if(ll[mid2] + rr[mid2] == maxn)break;
else
{
ans.push_back(mid2);
mid2++;
}
}
}
xx = ll[r] - ll[mid2];
if(xx!=0)find(mid2,r,xx);
return;
}
int find_best(int n)
{
srand(time(0));
for(int i=0;i<n;i++)ll[i] = -1;
for(int i=0;i<n;i++)rr[i] = -1;
int first = 0;
int xx = 475;
for(int pp=0;pp<xx;pp++)
{
int i = rand() % n;
vector<int> a = ask(i);
int su = a[0] + a[1];
ll[i] = a[0];rr[i] = a[1];
if(su == 0)return i;
if(su > maxn)
{
maxn = su;
first = i;
}
}
find(0,first-1,ll[first]);
find(first+1,n-1,rr[first]);
for(int i=0;i<ans.size();i++)
{
if(ll[ans[i]] +rr[ans[i]] == 0)return ans[i];
}
return 0;
}
Compilation message
prize.cpp: In function 'void find(int, int, int)':
prize.cpp:16:7: warning: unused variable 'flag' [-Wunused-variable]
16 | bool flag = true;
| ^~~~
prize.cpp: In function 'int find_best(int)':
prize.cpp:143:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
143 | for(int i=0;i<ans.size();i++)
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1836 KB |
Output is correct |
2 |
Correct |
3 ms |
1840 KB |
Output is correct |
3 |
Correct |
6 ms |
1836 KB |
Output is correct |
4 |
Correct |
4 ms |
1832 KB |
Output is correct |
5 |
Correct |
4 ms |
1828 KB |
Output is correct |
6 |
Correct |
2 ms |
1832 KB |
Output is correct |
7 |
Correct |
2 ms |
1836 KB |
Output is correct |
8 |
Correct |
2 ms |
1872 KB |
Output is correct |
9 |
Correct |
5 ms |
1832 KB |
Output is correct |
10 |
Correct |
5 ms |
1744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1836 KB |
Output is correct |
2 |
Correct |
3 ms |
1872 KB |
Output is correct |
3 |
Correct |
4 ms |
1832 KB |
Output is correct |
4 |
Correct |
4 ms |
1836 KB |
Output is correct |
5 |
Correct |
3 ms |
1744 KB |
Output is correct |
6 |
Correct |
4 ms |
1832 KB |
Output is correct |
7 |
Correct |
4 ms |
1744 KB |
Output is correct |
8 |
Correct |
6 ms |
1840 KB |
Output is correct |
9 |
Correct |
6 ms |
1872 KB |
Output is correct |
10 |
Correct |
7 ms |
1744 KB |
Output is correct |
11 |
Correct |
10 ms |
1828 KB |
Output is correct |
12 |
Correct |
7 ms |
1816 KB |
Output is correct |
13 |
Correct |
4 ms |
1836 KB |
Output is correct |
14 |
Correct |
14 ms |
472 KB |
Output is correct |
15 |
Correct |
17 ms |
1868 KB |
Output is correct |
16 |
Partially correct |
33 ms |
1852 KB |
Partially correct - number of queries: 5098 |
17 |
Partially correct |
29 ms |
1856 KB |
Partially correct - number of queries: 5059 |
18 |
Partially correct |
44 ms |
1836 KB |
Partially correct - number of queries: 5054 |
19 |
Correct |
41 ms |
1840 KB |
Output is correct |
20 |
Correct |
26 ms |
1100 KB |
Output is correct |
21 |
Partially correct |
45 ms |
1864 KB |
Partially correct - number of queries: 5037 |
22 |
Correct |
28 ms |
1824 KB |
Output is correct |
23 |
Correct |
3 ms |
1876 KB |
Output is correct |
24 |
Correct |
6 ms |
1872 KB |
Output is correct |
25 |
Correct |
42 ms |
1856 KB |
Output is correct |
26 |
Correct |
29 ms |
1744 KB |
Output is correct |
27 |
Correct |
5 ms |
1872 KB |
Output is correct |
28 |
Correct |
16 ms |
1868 KB |
Output is correct |
29 |
Correct |
24 ms |
1872 KB |
Output is correct |
30 |
Correct |
32 ms |
1864 KB |
Output is correct |
31 |
Correct |
44 ms |
1872 KB |
Output is correct |
32 |
Correct |
6 ms |
1872 KB |
Output is correct |
33 |
Correct |
1 ms |
208 KB |
Output is correct |
34 |
Partially correct |
27 ms |
1836 KB |
Partially correct - number of queries: 5031 |
35 |
Correct |
6 ms |
1872 KB |
Output is correct |
36 |
Correct |
17 ms |
1872 KB |
Output is correct |
37 |
Correct |
4 ms |
1828 KB |
Output is correct |
38 |
Correct |
3 ms |
1820 KB |
Output is correct |
39 |
Partially correct |
18 ms |
1880 KB |
Partially correct - number of queries: 5023 |
40 |
Correct |
15 ms |
1908 KB |
Output is correct |
41 |
Partially correct |
18 ms |
1876 KB |
Partially correct - number of queries: 5070 |
42 |
Partially correct |
17 ms |
1868 KB |
Partially correct - number of queries: 5070 |
43 |
Correct |
18 ms |
1876 KB |
Output is correct |
44 |
Partially correct |
31 ms |
1872 KB |
Partially correct - number of queries: 5083 |
45 |
Correct |
16 ms |
1876 KB |
Output is correct |
46 |
Partially correct |
18 ms |
1880 KB |
Partially correct - number of queries: 5053 |
47 |
Correct |
21 ms |
1868 KB |
Output is correct |
48 |
Partially correct |
18 ms |
1916 KB |
Partially correct - number of queries: 5108 |
49 |
Partially correct |
32 ms |
1836 KB |
Partially correct - number of queries: 5081 |
50 |
Partially correct |
18 ms |
1876 KB |
Partially correct - number of queries: 5113 |
51 |
Partially correct |
43 ms |
1872 KB |
Partially correct - number of queries: 5041 |
52 |
Partially correct |
26 ms |
1860 KB |
Partially correct - number of queries: 5048 |
53 |
Correct |
3 ms |
1872 KB |
Output is correct |
54 |
Partially correct |
17 ms |
1884 KB |
Partially correct - number of queries: 5020 |
55 |
Partially correct |
37 ms |
1872 KB |
Partially correct - number of queries: 5003 |
56 |
Partially correct |
31 ms |
1836 KB |
Partially correct - number of queries: 5017 |
57 |
Partially correct |
30 ms |
1744 KB |
Partially correct - number of queries: 5019 |
58 |
Partially correct |
29 ms |
1832 KB |
Partially correct - number of queries: 5039 |
59 |
Partially correct |
33 ms |
1872 KB |
Partially correct - number of queries: 5049 |
60 |
Partially correct |
43 ms |
1744 KB |
Partially correct - number of queries: 5035 |
61 |
Correct |
4 ms |
1816 KB |
Output is correct |
62 |
Correct |
5 ms |
1744 KB |
Output is correct |
63 |
Correct |
6 ms |
1840 KB |
Output is correct |
64 |
Correct |
3 ms |
1832 KB |
Output is correct |
65 |
Correct |
3 ms |
2000 KB |
Output is correct |
66 |
Correct |
8 ms |
1856 KB |
Output is correct |
67 |
Correct |
8 ms |
1836 KB |
Output is correct |
68 |
Correct |
9 ms |
1856 KB |
Output is correct |
69 |
Correct |
4 ms |
1876 KB |
Output is correct |
70 |
Correct |
3 ms |
1872 KB |
Output is correct |
71 |
Partially correct |
37 ms |
1872 KB |
Partially correct - number of queries: 5210 |
72 |
Correct |
10 ms |
1872 KB |
Output is correct |
73 |
Partially correct |
43 ms |
1872 KB |
Partially correct - number of queries: 5149 |
74 |
Partially correct |
32 ms |
1872 KB |
Partially correct - number of queries: 5175 |
75 |
Correct |
5 ms |
1744 KB |
Output is correct |
76 |
Correct |
28 ms |
1876 KB |
Output is correct |
77 |
Partially correct |
32 ms |
1876 KB |
Partially correct - number of queries: 5112 |
78 |
Correct |
7 ms |
1872 KB |
Output is correct |
79 |
Correct |
17 ms |
1876 KB |
Output is correct |
80 |
Partially correct |
45 ms |
1872 KB |
Partially correct - number of queries: 5097 |
81 |
Partially correct |
25 ms |
1872 KB |
Partially correct - number of queries: 5146 |
82 |
Partially correct |
42 ms |
1856 KB |
Partially correct - number of queries: 5145 |
83 |
Correct |
6 ms |
1744 KB |
Output is correct |
84 |
Correct |
23 ms |
1856 KB |
Output is correct |
85 |
Partially correct |
33 ms |
1872 KB |
Partially correct - number of queries: 5209 |
86 |
Correct |
26 ms |
1872 KB |
Output is correct |
87 |
Correct |
8 ms |
1744 KB |
Output is correct |
88 |
Correct |
33 ms |
1872 KB |
Output is correct |
89 |
Correct |
33 ms |
1872 KB |
Output is correct |
90 |
Correct |
4 ms |
1872 KB |
Output is correct |
91 |
Correct |
25 ms |
1876 KB |
Output is correct |
92 |
Correct |
17 ms |
1880 KB |
Output is correct |
93 |
Correct |
34 ms |
1872 KB |
Output is correct |
94 |
Correct |
27 ms |
1872 KB |
Output is correct |
95 |
Correct |
34 ms |
1876 KB |
Output is correct |
96 |
Correct |
20 ms |
1884 KB |
Output is correct |
97 |
Correct |
25 ms |
1872 KB |
Output is correct |