제출 #1312384

#제출 시각아이디문제언어결과실행 시간메모리
1312384Zbyszek99Library 3 (JOI24_library3)C++20
100 / 100
530 ms448 KiB
#include "library3.h" #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define ld long double #define ull unsigned long long #define ff first #define ss second #define pii pair<int,int> #define pll pair<long long, long long> #define vi vector<int> #define vl vector<long long> #define pb push_back #define rep(i, b) for(int i = 0; i < (b); ++i) #define rep2(i,a,b) for(int i = a; i <= (b); ++i) #define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c) #define count_bits(x) __builtin_popcountll((x)) #define all(x) (x).begin(),(x).end() #define siz(x) (int)(x).size() #define forall(it,x) for(auto& it:(x)) using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; //mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());} //ll los(ll a, ll b) {return a + (mt() % (b-a+1));} const int INF = 1e9+50; const ll INF_L = 1e18+40; const ll MOD = 1e9+7; int cur_ans; vi ans; bool compare(int a, int b) { if(a == b) return 0; if(a == 0) return 1; if(b == 0) return 0; swap(ans[0],ans[a]); swap(ans[0],ans[b]); bool x = (query(ans) != cur_ans); swap(ans[0],ans[b]); swap(ans[0],ans[a]); return x; } vi merge_sort(vi x) { if(siz(x) <= 1) return x; vi l; vi r; rep(i,siz(x)/2) l.pb(x[i]); rep2(i,siz(x)/2,siz(x)-1) r.pb(x[i]); l = merge_sort(l); r = merge_sort(r); vi ans; int p1 = 0; int p2 = 0; while(p1 != siz(l) || p2 != siz(r)) { if(p1 == siz(l)) ans.pb(r[p2++]); else if(p2 == siz(r)) ans.pb(l[p1++]); else { if(compare(l[p1],r[p2])) ans.pb(l[p1++]); else ans.pb(r[p2++]); } } return ans; } void solve(int n) { ans.resize(n); rep(i,n) ans[i] = i; cur_ans = query(ans); rep2(i,1,n-1) { swap(ans[0],ans[i]); int new_ans = query(ans); if(new_ans < cur_ans) swap(ans[0],ans[i]); else cur_ans = new_ans; } vi x; rep(i,n) x.pb(i); x = merge_sort(x); vi ans2(n); rep(i,n) ans2[x[(i+1)%n]] = ans[x[i]]; answer(ans2); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...