#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int,int>
#define fi first
#define se second
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int num[50005];
int best[50005];
int CURR=0;
bool same(int x){
int temp=Query(x);
int res=CURR==temp;
CURR=temp;
return res;
}
int n;
vector<int> v; //singles
vector<ii> v2; //pairs
int B1,B2;
map<int,int> pos;
struct node{
int len;
vector<int> l; //indices
node *L=nullptr,*R=nullptr;
node (int _len){
len=_len;
if (len==1){
l={v.back()}; v.pob();
}
else if (len==2 && !v2.empty()){
l={v2.back().fi,v2.back().se}; v2.pob();
}
else{
L=new node(best[len]);
R=new node(len-best[len]);
for (auto it:L->l) l.pub(it);
for (auto it:R->l) l.pub(it);
}
}
void solve(vector<int> r,bool in){
shuffle(all(r),rng);
if (L==nullptr){
if (sz(r)==2){
if (pos[r[0]]>pos[r[1]]) swap(r[0],r[1]);
if (pos[r[0]]<B1){
Answer(l[0],r[0]);
Answer(l[1],r[1]);
return;
}
else{
v=l;
L=new node(1);
R=new node(1);
}
}
else{
Answer(l[0],r[0]);
return;
}
}
for (auto it:L->l) same(it);
vector<int> r1,r2;
for (auto it:r){
if (sz(L->l)==sz(r1)) r2.pub(it);
else if (sz(R->l)==sz(r2)) r1.pub(it);
else if (same(it) != in) r1.pub(it);
else r2.pub(it);
}
L->solve(r1,!in);
R->solve(r2,in);
}
} *root;
vector<int> get(vector<int> inp){
vector<int> temp,r;
rep(x,0,sz(inp)){
if (same(inp[x])) r.pub(inp[x]);
else temp.pub(inp[x]);
}
vector<int> l,oth;
for (auto it:temp){
if (same(it)) l.pub(it);
else oth.pub(it);
}
B1=max(0LL,sz(l)/4-45);
B2=max(0LL,sz(l)/4);
rep(x,0,B2) v2.pub({l[x],l[sz(l)-1-x]});
rep(x,B2,sz(l)-B2) v.pub(l[x]);
root=new node(sz(l));
rep(x,0,sz(r)) pos[r[x]]=x;
root->solve(r,false);
return oth;
}
void Solve(signed N) {
num[1]=0;
rep(x,2,50005){
num[x]=1e9;
int l=max(1LL,(int)(x*0.25)),r=min(x,(int)(x*0.4)+2);
rep(y,l,r) if (num[x]>num[y]+num[x-y]+x+y){
num[x]=num[y]+num[x-y]+x+y;
best[x]=y;
}
}
n=N;
vector<int> idx;
rep(x,1,2*n+1) idx.pub(x);
shuffle(all(idx),rng);
vector<int> l,r;
rep(x,0,n) l.pub(idx[x]);
rep(x,n,2*n) r.pub(idx[x]);
l=get(l),r=get(r);
if (sz(l)==0) return;
v=l;
root=new node(sz(l));
root->solve(r,false);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
268 ms |
1064 KB |
Output is correct |
2 |
Correct |
266 ms |
1040 KB |
Output is correct |
3 |
Correct |
267 ms |
1032 KB |
Output is correct |
4 |
Correct |
271 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
267 ms |
1452 KB |
Output is correct |
2 |
Correct |
268 ms |
1908 KB |
Output is correct |
3 |
Correct |
280 ms |
2764 KB |
Output is correct |
4 |
Correct |
277 ms |
4256 KB |
Output is correct |
5 |
Correct |
299 ms |
7164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
268 ms |
1064 KB |
Output is correct |
2 |
Correct |
266 ms |
1040 KB |
Output is correct |
3 |
Correct |
267 ms |
1032 KB |
Output is correct |
4 |
Correct |
271 ms |
1108 KB |
Output is correct |
5 |
Correct |
267 ms |
1452 KB |
Output is correct |
6 |
Correct |
268 ms |
1908 KB |
Output is correct |
7 |
Correct |
280 ms |
2764 KB |
Output is correct |
8 |
Correct |
277 ms |
4256 KB |
Output is correct |
9 |
Correct |
299 ms |
7164 KB |
Output is correct |
10 |
Correct |
261 ms |
1556 KB |
Output is correct |
11 |
Correct |
281 ms |
5200 KB |
Output is correct |
12 |
Correct |
298 ms |
7268 KB |
Output is correct |
13 |
Correct |
284 ms |
7204 KB |
Output is correct |
14 |
Correct |
289 ms |
7188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
268 ms |
1064 KB |
Output is correct |
2 |
Correct |
266 ms |
1040 KB |
Output is correct |
3 |
Correct |
267 ms |
1032 KB |
Output is correct |
4 |
Correct |
271 ms |
1108 KB |
Output is correct |
5 |
Correct |
267 ms |
1452 KB |
Output is correct |
6 |
Correct |
268 ms |
1908 KB |
Output is correct |
7 |
Correct |
280 ms |
2764 KB |
Output is correct |
8 |
Correct |
277 ms |
4256 KB |
Output is correct |
9 |
Correct |
299 ms |
7164 KB |
Output is correct |
10 |
Correct |
261 ms |
1556 KB |
Output is correct |
11 |
Correct |
281 ms |
5200 KB |
Output is correct |
12 |
Correct |
298 ms |
7268 KB |
Output is correct |
13 |
Correct |
284 ms |
7204 KB |
Output is correct |
14 |
Correct |
289 ms |
7188 KB |
Output is correct |
15 |
Correct |
331 ms |
17228 KB |
Output is correct |
16 |
Correct |
359 ms |
17228 KB |
Output is correct |
17 |
Correct |
338 ms |
17316 KB |
Output is correct |
18 |
Correct |
366 ms |
17076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
268 ms |
1064 KB |
Output is correct |
2 |
Correct |
266 ms |
1040 KB |
Output is correct |
3 |
Correct |
267 ms |
1032 KB |
Output is correct |
4 |
Correct |
271 ms |
1108 KB |
Output is correct |
5 |
Correct |
267 ms |
1452 KB |
Output is correct |
6 |
Correct |
268 ms |
1908 KB |
Output is correct |
7 |
Correct |
280 ms |
2764 KB |
Output is correct |
8 |
Correct |
277 ms |
4256 KB |
Output is correct |
9 |
Correct |
299 ms |
7164 KB |
Output is correct |
10 |
Correct |
261 ms |
1556 KB |
Output is correct |
11 |
Correct |
281 ms |
5200 KB |
Output is correct |
12 |
Correct |
298 ms |
7268 KB |
Output is correct |
13 |
Correct |
284 ms |
7204 KB |
Output is correct |
14 |
Correct |
289 ms |
7188 KB |
Output is correct |
15 |
Correct |
331 ms |
17228 KB |
Output is correct |
16 |
Correct |
359 ms |
17228 KB |
Output is correct |
17 |
Correct |
338 ms |
17316 KB |
Output is correct |
18 |
Correct |
366 ms |
17076 KB |
Output is correct |
19 |
Correct |
377 ms |
17696 KB |
Output is correct |
20 |
Correct |
337 ms |
17596 KB |
Output is correct |
21 |
Correct |
341 ms |
17820 KB |
Output is correct |
22 |
Correct |
337 ms |
17556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
268 ms |
1064 KB |
Output is correct |
2 |
Correct |
266 ms |
1040 KB |
Output is correct |
3 |
Correct |
267 ms |
1032 KB |
Output is correct |
4 |
Correct |
271 ms |
1108 KB |
Output is correct |
5 |
Correct |
267 ms |
1452 KB |
Output is correct |
6 |
Correct |
268 ms |
1908 KB |
Output is correct |
7 |
Correct |
280 ms |
2764 KB |
Output is correct |
8 |
Correct |
277 ms |
4256 KB |
Output is correct |
9 |
Correct |
299 ms |
7164 KB |
Output is correct |
10 |
Correct |
261 ms |
1556 KB |
Output is correct |
11 |
Correct |
281 ms |
5200 KB |
Output is correct |
12 |
Correct |
298 ms |
7268 KB |
Output is correct |
13 |
Correct |
284 ms |
7204 KB |
Output is correct |
14 |
Correct |
289 ms |
7188 KB |
Output is correct |
15 |
Correct |
331 ms |
17228 KB |
Output is correct |
16 |
Correct |
359 ms |
17228 KB |
Output is correct |
17 |
Correct |
338 ms |
17316 KB |
Output is correct |
18 |
Correct |
366 ms |
17076 KB |
Output is correct |
19 |
Correct |
377 ms |
17696 KB |
Output is correct |
20 |
Correct |
337 ms |
17596 KB |
Output is correct |
21 |
Correct |
341 ms |
17820 KB |
Output is correct |
22 |
Correct |
337 ms |
17556 KB |
Output is correct |
23 |
Correct |
342 ms |
18184 KB |
Output is correct |
24 |
Correct |
340 ms |
18152 KB |
Output is correct |
25 |
Correct |
351 ms |
18176 KB |
Output is correct |
26 |
Correct |
337 ms |
17900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
268 ms |
1064 KB |
Output is correct |
2 |
Correct |
266 ms |
1040 KB |
Output is correct |
3 |
Correct |
267 ms |
1032 KB |
Output is correct |
4 |
Correct |
271 ms |
1108 KB |
Output is correct |
5 |
Correct |
267 ms |
1452 KB |
Output is correct |
6 |
Correct |
268 ms |
1908 KB |
Output is correct |
7 |
Correct |
280 ms |
2764 KB |
Output is correct |
8 |
Correct |
277 ms |
4256 KB |
Output is correct |
9 |
Correct |
299 ms |
7164 KB |
Output is correct |
10 |
Correct |
261 ms |
1556 KB |
Output is correct |
11 |
Correct |
281 ms |
5200 KB |
Output is correct |
12 |
Correct |
298 ms |
7268 KB |
Output is correct |
13 |
Correct |
284 ms |
7204 KB |
Output is correct |
14 |
Correct |
289 ms |
7188 KB |
Output is correct |
15 |
Correct |
331 ms |
17228 KB |
Output is correct |
16 |
Correct |
359 ms |
17228 KB |
Output is correct |
17 |
Correct |
338 ms |
17316 KB |
Output is correct |
18 |
Correct |
366 ms |
17076 KB |
Output is correct |
19 |
Correct |
377 ms |
17696 KB |
Output is correct |
20 |
Correct |
337 ms |
17596 KB |
Output is correct |
21 |
Correct |
341 ms |
17820 KB |
Output is correct |
22 |
Correct |
337 ms |
17556 KB |
Output is correct |
23 |
Correct |
342 ms |
18184 KB |
Output is correct |
24 |
Correct |
340 ms |
18152 KB |
Output is correct |
25 |
Correct |
351 ms |
18176 KB |
Output is correct |
26 |
Correct |
337 ms |
17900 KB |
Output is correct |
27 |
Correct |
344 ms |
18700 KB |
Output is correct |
28 |
Correct |
357 ms |
18664 KB |
Output is correct |
29 |
Correct |
333 ms |
18648 KB |
Output is correct |
30 |
Correct |
358 ms |
18420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
268 ms |
1064 KB |
Output is correct |
2 |
Correct |
266 ms |
1040 KB |
Output is correct |
3 |
Correct |
267 ms |
1032 KB |
Output is correct |
4 |
Correct |
271 ms |
1108 KB |
Output is correct |
5 |
Correct |
267 ms |
1452 KB |
Output is correct |
6 |
Correct |
268 ms |
1908 KB |
Output is correct |
7 |
Correct |
280 ms |
2764 KB |
Output is correct |
8 |
Correct |
277 ms |
4256 KB |
Output is correct |
9 |
Correct |
299 ms |
7164 KB |
Output is correct |
10 |
Correct |
261 ms |
1556 KB |
Output is correct |
11 |
Correct |
281 ms |
5200 KB |
Output is correct |
12 |
Correct |
298 ms |
7268 KB |
Output is correct |
13 |
Correct |
284 ms |
7204 KB |
Output is correct |
14 |
Correct |
289 ms |
7188 KB |
Output is correct |
15 |
Correct |
331 ms |
17228 KB |
Output is correct |
16 |
Correct |
359 ms |
17228 KB |
Output is correct |
17 |
Correct |
338 ms |
17316 KB |
Output is correct |
18 |
Correct |
366 ms |
17076 KB |
Output is correct |
19 |
Correct |
377 ms |
17696 KB |
Output is correct |
20 |
Correct |
337 ms |
17596 KB |
Output is correct |
21 |
Correct |
341 ms |
17820 KB |
Output is correct |
22 |
Correct |
337 ms |
17556 KB |
Output is correct |
23 |
Correct |
342 ms |
18184 KB |
Output is correct |
24 |
Correct |
340 ms |
18152 KB |
Output is correct |
25 |
Correct |
351 ms |
18176 KB |
Output is correct |
26 |
Correct |
337 ms |
17900 KB |
Output is correct |
27 |
Correct |
344 ms |
18700 KB |
Output is correct |
28 |
Correct |
357 ms |
18664 KB |
Output is correct |
29 |
Correct |
333 ms |
18648 KB |
Output is correct |
30 |
Correct |
358 ms |
18420 KB |
Output is correct |
31 |
Correct |
365 ms |
19004 KB |
Output is correct |
32 |
Correct |
338 ms |
18948 KB |
Output is correct |
33 |
Correct |
353 ms |
18964 KB |
Output is correct |
34 |
Correct |
346 ms |
18848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
268 ms |
1064 KB |
Output is correct |
2 |
Correct |
266 ms |
1040 KB |
Output is correct |
3 |
Correct |
267 ms |
1032 KB |
Output is correct |
4 |
Correct |
271 ms |
1108 KB |
Output is correct |
5 |
Correct |
267 ms |
1452 KB |
Output is correct |
6 |
Correct |
268 ms |
1908 KB |
Output is correct |
7 |
Correct |
280 ms |
2764 KB |
Output is correct |
8 |
Correct |
277 ms |
4256 KB |
Output is correct |
9 |
Correct |
299 ms |
7164 KB |
Output is correct |
10 |
Correct |
261 ms |
1556 KB |
Output is correct |
11 |
Correct |
281 ms |
5200 KB |
Output is correct |
12 |
Correct |
298 ms |
7268 KB |
Output is correct |
13 |
Correct |
284 ms |
7204 KB |
Output is correct |
14 |
Correct |
289 ms |
7188 KB |
Output is correct |
15 |
Correct |
331 ms |
17228 KB |
Output is correct |
16 |
Correct |
359 ms |
17228 KB |
Output is correct |
17 |
Correct |
338 ms |
17316 KB |
Output is correct |
18 |
Correct |
366 ms |
17076 KB |
Output is correct |
19 |
Correct |
377 ms |
17696 KB |
Output is correct |
20 |
Correct |
337 ms |
17596 KB |
Output is correct |
21 |
Correct |
341 ms |
17820 KB |
Output is correct |
22 |
Correct |
337 ms |
17556 KB |
Output is correct |
23 |
Correct |
342 ms |
18184 KB |
Output is correct |
24 |
Correct |
340 ms |
18152 KB |
Output is correct |
25 |
Correct |
351 ms |
18176 KB |
Output is correct |
26 |
Correct |
337 ms |
17900 KB |
Output is correct |
27 |
Correct |
344 ms |
18700 KB |
Output is correct |
28 |
Correct |
357 ms |
18664 KB |
Output is correct |
29 |
Correct |
333 ms |
18648 KB |
Output is correct |
30 |
Correct |
358 ms |
18420 KB |
Output is correct |
31 |
Correct |
365 ms |
19004 KB |
Output is correct |
32 |
Correct |
338 ms |
18948 KB |
Output is correct |
33 |
Correct |
353 ms |
18964 KB |
Output is correct |
34 |
Correct |
346 ms |
18848 KB |
Output is correct |
35 |
Correct |
349 ms |
19500 KB |
Output is correct |
36 |
Correct |
349 ms |
19556 KB |
Output is correct |
37 |
Correct |
366 ms |
19404 KB |
Output is correct |
38 |
Correct |
352 ms |
19228 KB |
Output is correct |