#include <utility>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>
#include <iostream>
#include "prize.h"
#define fori(i,n) for(int i=0;i<n;i++)
#define forib(i,n) for(int i=n-1;i>=0;i--)
#define maxl 10000000000
typedef long long lol;
using namespace std;
typedef vector<int> veci;
typedef pair<int,int> point;
lol sum=0;
veci merge(veci a ,veci b){
int i=0,j=0;
veci ans;
while(i<a.size()&&j<b.size()){
if(a[i]<b[j]){
ans.push_back(a[i++]);
sum+=j;
}else{
ans.push_back(b[j++]);
}
}
while(i<a.size()){
ans.push_back(a[i++]);
sum+=j;
}
while(j<b.size()){
ans.push_back(b[j++]);
}
return ans;
}
veci mergesort(veci a){
if(a.size()==1){
return a;
}
veci b,c;
fori(i,a.size()){
if(i<a.size()/2){
b.push_back(a[i]);
}else{
c.push_back(a[i]);
}
}
b=mergesort(b);
c=mergesort(c);
return merge(b,c);
}
int find_best(int n) {
if(n<5000){
for(int i = 0; i < n; i++) {
std::vector<int> res = ask(i);
if(res[0] + res[1] == 0)
return i;
}
}
int m=0;
int s=0;int ss=0;
fori(i,500){
vector<int> res = ask(i);
if(res[0] + res[1]>m){
m=res[0] + res[1];
ss+=s;
s=0;
}
if(res[0] + res[1]==m){
s++;
}else{
ss++;
}
if(res[0] + res[1] == 0)
return i;
}
vector<pair<point,point>> tos;
tos.push_back({{500,n-1},{ss,0}});
while(true){
pair<point,point> cur=tos.back();
tos.pop_back();
int l=cur.first.first;
int r=cur.first.second;
int ll=cur.second.first;
int rr=cur.second.second;
if(ll+rr==m){
continue;
}
int m1=(l+r)/2;
int m2=m1;
int f=0;
while(m2<=r){
vector<int> res = ask(m2++);
if(res[0] + res[1] == 0)
return m2-1;
if(res[0] + res[1] == m){
tos.push_back({{l,m1-1},{ll,res[1]+f}});
tos.push_back({{m2,r},{res[0],rr}});
m2--;
break;
}
f++;
}
if(m2>r){
tos.push_back({{l,m1-1},{ll,rr+f}});
}
}
return 0;
}
Compilation message
prize.cpp: In function 'veci merge(veci, veci)':
prize.cpp:20:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(i<a.size()&&j<b.size()){
~^~~~~~~~~
prize.cpp:20:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(i<a.size()&&j<b.size()){
~^~~~~~~~~
prize.cpp:28:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(i<a.size()){
~^~~~~~~~~
prize.cpp:32:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(j<b.size()){
~^~~~~~~~~
prize.cpp: In function 'veci mergesort(veci)':
prize.cpp:9:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define fori(i,n) for(int i=0;i<n;i++)
prize.cpp:42:7:
fori(i,a.size()){
~~~~~~~~~~
prize.cpp:42:2: note: in expansion of macro 'fori'
fori(i,a.size()){
^~~~
prize.cpp:43:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(i<a.size()/2){
~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
248 KB |
Output is correct |
2 |
Correct |
7 ms |
248 KB |
Output is correct |
3 |
Correct |
8 ms |
248 KB |
Output is correct |
4 |
Correct |
7 ms |
248 KB |
Output is correct |
5 |
Correct |
5 ms |
424 KB |
Output is correct |
6 |
Correct |
2 ms |
248 KB |
Output is correct |
7 |
Correct |
7 ms |
388 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
8 ms |
388 KB |
Output is correct |
10 |
Correct |
7 ms |
248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
304 KB |
Output is correct |
2 |
Correct |
8 ms |
248 KB |
Output is correct |
3 |
Correct |
7 ms |
248 KB |
Output is correct |
4 |
Correct |
4 ms |
504 KB |
Output is correct |
5 |
Correct |
7 ms |
304 KB |
Output is correct |
6 |
Correct |
2 ms |
248 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
7 ms |
376 KB |
Output is correct |
10 |
Correct |
7 ms |
248 KB |
Output is correct |
11 |
Correct |
6 ms |
392 KB |
Output is correct |
12 |
Correct |
14 ms |
376 KB |
Output is correct |
13 |
Correct |
7 ms |
376 KB |
Output is correct |
14 |
Correct |
13 ms |
252 KB |
Output is correct |
15 |
Correct |
31 ms |
376 KB |
Output is correct |
16 |
Correct |
16 ms |
304 KB |
Output is correct |
17 |
Correct |
4 ms |
396 KB |
Output is correct |
18 |
Correct |
4 ms |
308 KB |
Output is correct |
19 |
Correct |
6 ms |
248 KB |
Output is correct |
20 |
Correct |
27 ms |
248 KB |
Output is correct |
21 |
Correct |
38 ms |
248 KB |
Output is correct |
22 |
Correct |
37 ms |
376 KB |
Output is correct |
23 |
Correct |
7 ms |
376 KB |
Output is correct |
24 |
Correct |
10 ms |
248 KB |
Output is correct |
25 |
Correct |
27 ms |
248 KB |
Output is correct |
26 |
Correct |
27 ms |
248 KB |
Output is correct |
27 |
Correct |
9 ms |
248 KB |
Output is correct |
28 |
Correct |
9 ms |
376 KB |
Output is correct |
29 |
Correct |
6 ms |
388 KB |
Output is correct |
30 |
Correct |
6 ms |
248 KB |
Output is correct |
31 |
Correct |
6 ms |
376 KB |
Output is correct |
32 |
Correct |
8 ms |
376 KB |
Output is correct |
33 |
Correct |
2 ms |
248 KB |
Output is correct |
34 |
Correct |
36 ms |
312 KB |
Output is correct |
35 |
Correct |
5 ms |
432 KB |
Output is correct |
36 |
Correct |
22 ms |
388 KB |
Output is correct |
37 |
Correct |
10 ms |
248 KB |
Output is correct |
38 |
Correct |
9 ms |
380 KB |
Output is correct |
39 |
Correct |
35 ms |
248 KB |
Output is correct |
40 |
Correct |
4 ms |
308 KB |
Output is correct |
41 |
Correct |
26 ms |
248 KB |
Output is correct |
42 |
Correct |
14 ms |
388 KB |
Output is correct |
43 |
Correct |
14 ms |
504 KB |
Output is correct |
44 |
Correct |
18 ms |
376 KB |
Output is correct |
45 |
Correct |
32 ms |
376 KB |
Output is correct |
46 |
Correct |
4 ms |
376 KB |
Output is correct |
47 |
Correct |
20 ms |
376 KB |
Output is correct |
48 |
Correct |
22 ms |
248 KB |
Output is correct |
49 |
Correct |
51 ms |
376 KB |
Output is correct |
50 |
Correct |
4 ms |
308 KB |
Output is correct |
51 |
Correct |
34 ms |
376 KB |
Output is correct |
52 |
Correct |
48 ms |
248 KB |
Output is correct |
53 |
Correct |
8 ms |
376 KB |
Output is correct |
54 |
Correct |
31 ms |
376 KB |
Output is correct |
55 |
Correct |
4 ms |
388 KB |
Output is correct |
56 |
Correct |
8 ms |
248 KB |
Output is correct |
57 |
Correct |
20 ms |
380 KB |
Output is correct |
58 |
Correct |
22 ms |
248 KB |
Output is correct |
59 |
Correct |
18 ms |
376 KB |
Output is correct |
60 |
Correct |
27 ms |
248 KB |
Output is correct |
61 |
Correct |
6 ms |
248 KB |
Output is correct |
62 |
Correct |
5 ms |
312 KB |
Output is correct |
63 |
Correct |
7 ms |
296 KB |
Output is correct |
64 |
Correct |
5 ms |
392 KB |
Output is correct |
65 |
Correct |
7 ms |
376 KB |
Output is correct |
66 |
Correct |
11 ms |
376 KB |
Output is correct |
67 |
Correct |
10 ms |
248 KB |
Output is correct |
68 |
Correct |
4 ms |
376 KB |
Output is correct |
69 |
Correct |
11 ms |
252 KB |
Output is correct |
70 |
Correct |
11 ms |
248 KB |
Output is correct |
71 |
Partially correct |
54 ms |
248 KB |
Partially correct - number of queries: 5259 |
72 |
Correct |
11 ms |
252 KB |
Output is correct |
73 |
Partially correct |
50 ms |
252 KB |
Partially correct - number of queries: 5196 |
74 |
Partially correct |
52 ms |
248 KB |
Partially correct - number of queries: 5223 |
75 |
Correct |
9 ms |
412 KB |
Output is correct |
76 |
Correct |
25 ms |
508 KB |
Output is correct |
77 |
Partially correct |
50 ms |
248 KB |
Partially correct - number of queries: 5032 |
78 |
Correct |
6 ms |
312 KB |
Output is correct |
79 |
Correct |
28 ms |
248 KB |
Output is correct |
80 |
Partially correct |
52 ms |
248 KB |
Partially correct - number of queries: 5017 |
81 |
Correct |
58 ms |
248 KB |
Output is correct |
82 |
Correct |
44 ms |
376 KB |
Output is correct |
83 |
Correct |
7 ms |
376 KB |
Output is correct |
84 |
Correct |
44 ms |
248 KB |
Output is correct |
85 |
Correct |
41 ms |
376 KB |
Output is correct |
86 |
Correct |
7 ms |
248 KB |
Output is correct |
87 |
Correct |
9 ms |
420 KB |
Output is correct |
88 |
Correct |
7 ms |
376 KB |
Output is correct |
89 |
Correct |
5 ms |
248 KB |
Output is correct |
90 |
Correct |
5 ms |
376 KB |
Output is correct |
91 |
Correct |
8 ms |
248 KB |
Output is correct |
92 |
Correct |
5 ms |
248 KB |
Output is correct |
93 |
Correct |
11 ms |
248 KB |
Output is correct |
94 |
Correct |
8 ms |
252 KB |
Output is correct |
95 |
Correct |
11 ms |
376 KB |
Output is correct |
96 |
Correct |
10 ms |
380 KB |
Output is correct |
97 |
Correct |
8 ms |
248 KB |
Output is correct |