Submission #406354

# Submission time Handle Problem Language Result Execution time Memory
406354 2021-05-17T12:51:24 Z nathanlee726 Library (JOI18_library) C++14
100 / 100
593 ms 484 KB
//#include<i_am_noob_orz>
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
//#define int ll
#define ull unsigned long long
#define pii pair<int,int>
#define X first
#define Y second
#define mod ((ll)1e9+7)
#define pb push_back
#define mp make_pair
#define abs(x) ((x)>0?(x):(-(x)))
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define memres(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
#define sz(a) ((int)a.size())
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define endl '\n'
#define bit_count(x) __builtin_popcountll((x))
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define jimmy_is_kind false
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;

//#define LOCAL
#ifdef LOCAL
#define bug(...) cerr<<"#"<<__LINE__<<' '<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr<<x<<", "; _do(y...);}
#define IOS()
int Query(const vector<int>& v){return 1;}
void Answer(const vector<int> &v){for(int i:v)cout<<i<<" ";cout<<endl;}
#else
#include<library.h>
#define IOS() ios_base::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define bug(...)
#endif
 
int add(int a,int b){return(a+b>=mod?a+b-mod:a+b);}
int sub(int a,int b){return(a<b?a+mod-b:a-b);}
int po(int a,int b){
	if(b==0)return 1;
	if(b==1)return(a%mod);
	int tem=po(a,b/2);
	if(b&1)return(((tem*tem)%mod)*a)%mod;
	else return(tem*tem)%mod; 
}
int GCD(int a,int b){
	int x=0;
	int ra,rb;
	while(a&&b){
		if(((a&1)==0)&&((b&1)==0)){
			a>>=1,b>>=1,x++;
		}
		else if((a^b)&1){
			if(a&1)b>>=1;
			else a>>=1;
		}
		else{
			ra=abs(a-b),rb=min(a,b);
			a=ra,b=rb;
		}
	}
	return max(a,b)<<x;
}
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
vector<int> ans(1005),ud(1005,0);
int n1=1000;
int bs(vector<int>& l,vector<int>& r,int id){
	if(sz(l)==0||sz(r)==0){
		while(sz(l)==0&&sz(r)==0);
		if(sz(l)==1||sz(r)==1){
			if(sz(l)==1)return l[0];
			else return r[0];
		}
		else{
			vector<int> v,lv,rv;
			if(sz(r)==0)v=l;
			else v=r;
			int N=sz(v),cnt=0;
			for(int i:v){
				if(cnt>=(N)/2)rv.pb(i);
				else lv.pb(i);
				cnt++;
			}	
			return bs(lv,rv,id);
		}
	} 
	vector<int> qr(n1,0);
	for(int i:l){while(i>=sz(qr));qr[i]=1;}
	int re=Query(qr);
	F(id){
		while(ans[i]-1>=sz(qr));
		qr[ans[i]-1]=1;
	}
	int re1=Query(qr);
	vector<int> v,lv,rv;
	if(re==re1)v=l;
	else v=r;
	int N=sz(v),cnt=0;
	for(int i:v){
		if(cnt>=(N)/2)rv.pb(i);
		else lv.pb(i);
		cnt++;
	}	
	return bs(lv,rv,id);
}
void Solve(int n){
	n1=n;
	if(n==1){
		vector<int> v;
		v.pb(1);
		Answer(v);
		return;
	}
	int p=0;
	F(n){
		vector<int> v(n,1);
		v[i]=0;
		int re=Query(v);
		if(re==1){p=i;break;} 
	}
	ans[0]=p+1;
	ud[p]=1;
	Fl(i,1,n){
		int cnt=0;
		vector<int> lv,rv;
		Fi(j,n){
			while(j>=sz(ud));
			if(ud[j])continue;
			if(cnt>=(n-i)/2)rv.pb(j);
			else lv.pb(j);
			cnt++;
		}
		int re=bs(lv,rv,i);
		while(i>=sz(ans));
		ans[i]=re+1;
		while(re>=sz(ud));
		ud[re]=1;
	}
	ans.resize(n);
	Answer(ans);
}
/*
signed main(){
	int n;
	cin>>n;
	Solve(n);
	return 0;
}
*/
# Verdict Execution time Memory Grader output
1 Correct 39 ms 200 KB # of queries: 2375
2 Correct 39 ms 200 KB # of queries: 2409
3 Correct 58 ms 296 KB # of queries: 2648
4 Correct 47 ms 200 KB # of queries: 2595
5 Correct 54 ms 200 KB # of queries: 2508
6 Correct 51 ms 200 KB # of queries: 2551
7 Correct 39 ms 200 KB # of queries: 2544
8 Correct 50 ms 304 KB # of queries: 2420
9 Correct 58 ms 200 KB # of queries: 2546
10 Correct 29 ms 200 KB # of queries: 1474
11 Correct 1 ms 200 KB # of queries: 0
12 Correct 1 ms 200 KB # of queries: 1
13 Correct 1 ms 200 KB # of queries: 4
14 Correct 1 ms 200 KB # of queries: 7
15 Correct 2 ms 200 KB # of queries: 77
16 Correct 4 ms 200 KB # of queries: 183
# Verdict Execution time Memory Grader output
1 Correct 39 ms 200 KB # of queries: 2375
2 Correct 39 ms 200 KB # of queries: 2409
3 Correct 58 ms 296 KB # of queries: 2648
4 Correct 47 ms 200 KB # of queries: 2595
5 Correct 54 ms 200 KB # of queries: 2508
6 Correct 51 ms 200 KB # of queries: 2551
7 Correct 39 ms 200 KB # of queries: 2544
8 Correct 50 ms 304 KB # of queries: 2420
9 Correct 58 ms 200 KB # of queries: 2546
10 Correct 29 ms 200 KB # of queries: 1474
11 Correct 1 ms 200 KB # of queries: 0
12 Correct 1 ms 200 KB # of queries: 1
13 Correct 1 ms 200 KB # of queries: 4
14 Correct 1 ms 200 KB # of queries: 7
15 Correct 2 ms 200 KB # of queries: 77
16 Correct 4 ms 200 KB # of queries: 183
17 Correct 556 ms 368 KB # of queries: 17982
18 Correct 524 ms 328 KB # of queries: 17293
19 Correct 545 ms 448 KB # of queries: 17467
20 Correct 490 ms 468 KB # of queries: 16325
21 Correct 457 ms 292 KB # of queries: 15324
22 Correct 593 ms 448 KB # of queries: 17669
23 Correct 545 ms 428 KB # of queries: 17224
24 Correct 204 ms 320 KB # of queries: 7915
25 Correct 526 ms 292 KB # of queries: 17136
26 Correct 474 ms 428 KB # of queries: 15963
27 Correct 172 ms 336 KB # of queries: 8040
28 Correct 526 ms 352 KB # of queries: 15957
29 Correct 454 ms 352 KB # of queries: 15939
30 Correct 504 ms 484 KB # of queries: 15957