#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(a, b);}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ull mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
//mt19937_64 rng(1);
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
double rngesus_d(double l, double r){
double wow = (double) ((ull) rng()) / ((ull)(0-1));
return wow * (r - l) + l;
}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
#include "minerals.h"
void Solve(int N);
namespace InteractorLib{
vector<int> color;
vector<bool> chosen;
map<int, int> mp;
vector<pair<int, int>> ans;
int o_cnt = 0;
int Query(int i){
o_cnt++;
if (!chosen[i]){
mp[color[i]]++;
}
else{
mp[color[i]]--;
if (mp[color[i]] == 0) mp.erase(color[i]);
}
chosen[i] = !chosen[i];
return mp.size();
}
void Answer(int i, int j){
if (i > j) swap(i, j);
ans.push_back({i, j});
}
int grade(){
int n = 15000;
color.resize(n * 2 + 1); chosen.resize(n * 2 + 1);
for(int i = 1; i<= n*2; ++i) color[i] = (i + 1) / 2;
shuffle(1 + ALL(color), rng);
o_cnt = 0;
mp.clear();
ans.clear();
Solve(n);
cout << "Operation used: " << o_cnt << "\n";
remove_dup(ans);
if (ans.size() != n) return 0;
for(pair<int, int> i: ans)
if (i.first == i.second || color[i.first] != color[i.second])
return 0;
if (o_cnt >= 1e6) return 0;
return 1;
}
}
void Solve(int n) {
vector<int> X, Y;
for(int i = 1; i <= n * 2; ++i){
X.push_back(i);
if (Query(i) != X.size()){
Query(i);
X.pop_back();
Y.push_back(i);
}
}
for(int i: X) Query(i);
vector<int> ans(n);
for(int bit = 0; MASK(bit) < X.size(); ++bit){
int cnt = 0;
for(int i = 0; i < (int) X.size(); ++i) if (GETBIT(i, bit)) {
Query(X[i]);
cnt++;
}
for(int j = 0; j < (int) Y.size(); ++j){
if (Query(Y[j]) == cnt) ans[j] += MASK(bit);
Query(Y[j]);
}
for(int i = 0; i < (int) X.size(); ++i) if (GETBIT(i, bit)) {
Query(X[i]);
}
}
for(int i = 0; i < n; ++i) Answer(Y[i], X[ans[i]]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |