/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#include "prize.h"
using namespace std;
const int N = 200005;
int used[N], n, k = 500, pre[N],len;
vector<int> res[N];
vector<int> Ask(int pos)
{
if (used[pos])
return res[pos];
used[pos] = 1;
return res[pos] = ask(pos);
}
int get(int pos)
{
return Ask(pos)[0] + Ask(pos)[1];
}
int letsfind(int x)
{
int id = x / len;
if (Ask(id * len) != Ask(x))
{
int l = x, r = min(x + len - 1, n - 1), m, pos;
while (l <= r)
{
m = (l + r) / 2;
if (Ask(m) == Ask(x))
{
pos = m;
l = m + 1;
}
else
r = m - 1;
}
return pos;
}
else
{
int pos = -1;
for (int i = id; i <= k && i * len < n; i++)
if (Ask(i * len) == Ask(x))
pos = pre[i];
return pos;
}
}
int find_best(int nn)
{
n = nn;
int mx = 0, ans = -1;
for (int i = 0; i < min(500, n); i++)
mx = max(mx, get(i));
k = ((int)sqrt(n)) / 2 + 1;
len = n / k;
for (int i = 0; i <= k; i++)
{
int l = i * len, r = min(n-1, l + len - 1), m;
pre[i] = -1;
while (l <= r && get(i * len) == mx)
{
m = (l + r) / 2;
if (Ask(m) == Ask(i * len))
{
pre[i] = m;
l = m + 1;
}
else
r = m - 1;
}
}
for (int i = 0; i < n; i++)
{
int now = get(i);
if (now == mx)
i = letsfind(i);
else if (now == 0)
{
ans = i;
break;
}
}
return ans;
}
//int main()
//{
//
// return 0;
//}
/*
8
3 2 3 1 3 3 2 3
10
2 2 2 2 2 1 2 2 2 2
*/
Compilation message
prize.cpp: In function 'int letsfind(int)':
prize.cpp:49:46: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
int l = x, r = min(x + len - 1, n - 1), m, pos;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
5880 KB |
Output is correct |
2 |
Correct |
23 ms |
5940 KB |
Output is correct |
3 |
Correct |
34 ms |
5880 KB |
Output is correct |
4 |
Correct |
32 ms |
5880 KB |
Output is correct |
5 |
Correct |
37 ms |
5880 KB |
Output is correct |
6 |
Correct |
37 ms |
5916 KB |
Output is correct |
7 |
Correct |
32 ms |
5880 KB |
Output is correct |
8 |
Correct |
38 ms |
5880 KB |
Output is correct |
9 |
Correct |
33 ms |
5880 KB |
Output is correct |
10 |
Correct |
40 ms |
5884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
5940 KB |
Output is correct |
2 |
Correct |
33 ms |
5880 KB |
Output is correct |
3 |
Correct |
33 ms |
5880 KB |
Output is correct |
4 |
Correct |
39 ms |
5880 KB |
Output is correct |
5 |
Correct |
23 ms |
5940 KB |
Output is correct |
6 |
Correct |
32 ms |
5880 KB |
Output is correct |
7 |
Correct |
30 ms |
5840 KB |
Output is correct |
8 |
Correct |
29 ms |
5880 KB |
Output is correct |
9 |
Correct |
34 ms |
5880 KB |
Output is correct |
10 |
Correct |
36 ms |
5880 KB |
Output is correct |
11 |
Correct |
30 ms |
5880 KB |
Output is correct |
12 |
Correct |
33 ms |
5844 KB |
Output is correct |
13 |
Correct |
36 ms |
5880 KB |
Output is correct |
14 |
Correct |
14 ms |
5080 KB |
Output is correct |
15 |
Correct |
38 ms |
5880 KB |
Output is correct |
16 |
Partially correct |
59 ms |
6008 KB |
Partially correct - number of queries: 6368 |
17 |
Correct |
37 ms |
5884 KB |
Output is correct |
18 |
Partially correct |
74 ms |
6036 KB |
Partially correct - number of queries: 7035 |
19 |
Correct |
31 ms |
5880 KB |
Output is correct |
20 |
Correct |
36 ms |
5496 KB |
Output is correct |
21 |
Correct |
46 ms |
5884 KB |
Output is correct |
22 |
Correct |
36 ms |
5884 KB |
Output is correct |
23 |
Correct |
38 ms |
5896 KB |
Output is correct |
24 |
Correct |
34 ms |
5880 KB |
Output is correct |
25 |
Partially correct |
56 ms |
6008 KB |
Partially correct - number of queries: 5317 |
26 |
Partially correct |
51 ms |
5984 KB |
Partially correct - number of queries: 5279 |
27 |
Correct |
23 ms |
5940 KB |
Output is correct |
28 |
Partially correct |
68 ms |
6008 KB |
Partially correct - number of queries: 7144 |
29 |
Partially correct |
41 ms |
6064 KB |
Partially correct - number of queries: 6090 |
30 |
Partially correct |
68 ms |
6012 KB |
Partially correct - number of queries: 6929 |
31 |
Correct |
33 ms |
5860 KB |
Output is correct |
32 |
Correct |
40 ms |
5860 KB |
Output is correct |
33 |
Correct |
8 ms |
4992 KB |
Output is correct |
34 |
Correct |
41 ms |
6072 KB |
Output is correct |
35 |
Correct |
24 ms |
5944 KB |
Output is correct |
36 |
Correct |
37 ms |
5960 KB |
Output is correct |
37 |
Correct |
34 ms |
5880 KB |
Output is correct |
38 |
Correct |
25 ms |
5892 KB |
Output is correct |
39 |
Correct |
49 ms |
5880 KB |
Output is correct |
40 |
Partially correct |
41 ms |
6124 KB |
Partially correct - number of queries: 6344 |
41 |
Partially correct |
57 ms |
6012 KB |
Partially correct - number of queries: 5412 |
42 |
Partially correct |
43 ms |
6064 KB |
Partially correct - number of queries: 5412 |
43 |
Partially correct |
34 ms |
6052 KB |
Partially correct - number of queries: 5147 |
44 |
Correct |
50 ms |
6008 KB |
Output is correct |
45 |
Correct |
49 ms |
5880 KB |
Output is correct |
46 |
Correct |
27 ms |
5932 KB |
Output is correct |
47 |
Correct |
56 ms |
5912 KB |
Output is correct |
48 |
Partially correct |
59 ms |
5956 KB |
Partially correct - number of queries: 5861 |
49 |
Correct |
38 ms |
5880 KB |
Output is correct |
50 |
Partially correct |
68 ms |
6008 KB |
Partially correct - number of queries: 7091 |
51 |
Correct |
41 ms |
6008 KB |
Output is correct |
52 |
Correct |
39 ms |
5880 KB |
Output is correct |
53 |
Correct |
23 ms |
5940 KB |
Output is correct |
54 |
Correct |
43 ms |
5880 KB |
Output is correct |
55 |
Correct |
34 ms |
5880 KB |
Output is correct |
56 |
Partially correct |
44 ms |
6116 KB |
Partially correct - number of queries: 7074 |
57 |
Partially correct |
38 ms |
6072 KB |
Partially correct - number of queries: 5820 |
58 |
Partially correct |
58 ms |
6008 KB |
Partially correct - number of queries: 5901 |
59 |
Partially correct |
48 ms |
5976 KB |
Partially correct - number of queries: 5413 |
60 |
Partially correct |
44 ms |
5880 KB |
Partially correct - number of queries: 5024 |
61 |
Correct |
24 ms |
5940 KB |
Output is correct |
62 |
Correct |
32 ms |
5880 KB |
Output is correct |
63 |
Correct |
36 ms |
5880 KB |
Output is correct |
64 |
Correct |
29 ms |
5880 KB |
Output is correct |
65 |
Correct |
33 ms |
5880 KB |
Output is correct |
66 |
Correct |
25 ms |
6000 KB |
Output is correct |
67 |
Correct |
23 ms |
5888 KB |
Output is correct |
68 |
Correct |
31 ms |
5880 KB |
Output is correct |
69 |
Correct |
33 ms |
5880 KB |
Output is correct |
70 |
Correct |
31 ms |
5880 KB |
Output is correct |
71 |
Partially correct |
73 ms |
6008 KB |
Partially correct - number of queries: 7005 |
72 |
Correct |
37 ms |
5880 KB |
Output is correct |
73 |
Partially correct |
72 ms |
6020 KB |
Partially correct - number of queries: 6935 |
74 |
Partially correct |
72 ms |
6136 KB |
Partially correct - number of queries: 6965 |
75 |
Correct |
41 ms |
5880 KB |
Output is correct |
76 |
Partially correct |
52 ms |
6008 KB |
Partially correct - number of queries: 6410 |
77 |
Partially correct |
74 ms |
6204 KB |
Partially correct - number of queries: 7186 |
78 |
Correct |
40 ms |
5880 KB |
Output is correct |
79 |
Partially correct |
51 ms |
6008 KB |
Partially correct - number of queries: 5148 |
80 |
Partially correct |
69 ms |
6264 KB |
Partially correct - number of queries: 7208 |
81 |
Partially correct |
65 ms |
5980 KB |
Partially correct - number of queries: 7090 |
82 |
Partially correct |
69 ms |
6008 KB |
Partially correct - number of queries: 7116 |
83 |
Correct |
30 ms |
6136 KB |
Output is correct |
84 |
Partially correct |
68 ms |
6008 KB |
Partially correct - number of queries: 6473 |
85 |
Partially correct |
64 ms |
6008 KB |
Partially correct - number of queries: 7173 |
86 |
Correct |
32 ms |
5880 KB |
Output is correct |
87 |
Correct |
31 ms |
5844 KB |
Output is correct |
88 |
Correct |
42 ms |
5852 KB |
Output is correct |
89 |
Correct |
35 ms |
5880 KB |
Output is correct |
90 |
Correct |
31 ms |
5880 KB |
Output is correct |
91 |
Correct |
35 ms |
5884 KB |
Output is correct |
92 |
Correct |
34 ms |
5856 KB |
Output is correct |
93 |
Correct |
25 ms |
5892 KB |
Output is correct |
94 |
Correct |
35 ms |
5880 KB |
Output is correct |
95 |
Correct |
36 ms |
5880 KB |
Output is correct |
96 |
Correct |
37 ms |
5880 KB |
Output is correct |
97 |
Correct |
32 ms |
5880 KB |
Output is correct |