답안 #739932

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
739932 2023-05-11T16:49:25 Z yuhong 순열 (APIO22_perm) C++17
100 / 100
9 ms 372 KB
#include "perm.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::steady_clock::now().time_since_epoch().count());

vector<signed> construct_permutation(int k){
	int bit=64-__builtin_clzll(k);
	
	vector<double> ans; //lazy
	
	bool flag=false;
	while (bit>0){
		bit-=2;
		if (bit==-1){
			ans.pub(1e9);
			if (k&1) ans.pub(-1e9);
		}
		else{
			int val=(k>>bit)&3;
			
			if (ans.empty()){
				if (val==2) ans={0};
				else ans={1,0},flag=true;
			}
			else{
				if (val==0){
					ans.pub(1e9);
					ans.pub(1e9+1);
				}
				else if (val==1){
					ans.pub(1e9);
					ans.pub(1e9+1);
					ans.pub(-1e9);
					flag=true;
				}
				else if (val==2){
					ans.pub(1e9);
					ans.pub(-1e9);
					ans.pub(1e9+1);
					flag=true;
				}
				else{
					if (!flag){
						ans.pub(1e9);
						ans.pub(-1e9);
						ans.pub(1e9+1);
						ans.pub(-1e9-1);
						flag=true;
					}
					else{
						ans.pub(1e9);
						ans.pub(1e9+1);
						ans.pub(1.5); //should be second guy
					}
				}
			}
			//cout<<"debug: "<<k<<" "<<bit<<" "<<val<<endl;
		}
		
		//cout<<"current: "<<endl;
		//for (auto it:ans) cout<<it<<" "; cout<<endl;
		
		vector<double> uni(all(ans));
		sort(all(uni));
		for (auto &it:ans) it=lb(all(uni),it)-uni.begin();
		
		//for (auto it:ans) cout<<it<<" "; cout<<endl;
	}
	
	return vector<signed>(all(ans));
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 5 ms 340 KB Output is correct
8 Correct 9 ms 344 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 6 ms 340 KB Output is correct
11 Correct 7 ms 344 KB Output is correct
12 Correct 7 ms 372 KB Output is correct
13 Correct 8 ms 340 KB Output is correct