#include <bits/stdc++.h>
#include "chameleon.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ALL(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng(1);
ll rngesus(ll l, ll r){return ((ull) rng()) % (r - l + 1) + l;}
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll LASTBIT(ll mask){return mask & (-mask);}
ll pop_cnt(ll mask){return __builtin_popcountll(mask);}
ll ctz(ll mask){return __builtin_ctzll(mask);}
ll clz(ll mask){return __builtin_clzll(mask);}
ll logOf(ll mask){return 63 - clz(mask);}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b){a = b; return true;}
return false;
}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b){a = b; return true;}
return false;
}
template <class T>
void printArr(T& a, string separator = " ", string finish = "\n", ostream& out = cout){
for(auto i: a) out << i << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
// namespace Grader{
// int n;
// vector<int> Y, C, L;
// vector<int> check;
// int o_cnt, ans;
// int Query(const vector<int> &p){
// o_cnt++;
// vector<bool> state(n * 2 + 1);
// for(int i: p) state[i] = 1;
// vector<bool> color(n*2+1);
// for(int i: p){
// if (state[L[i]]) color[C[L[i]]] = 1;
// else color[C[i]] = 1;
// }
// int ans = 0;
// for(int i = 1; i<=2*n; ++i) ans += color[i];
// return ans;
// }
// void Answer(int x, int y){
// cout << "! " << x << " " << y << "\n";
// if (C[x] != C[y]) ans = false;
// check[x]++; check[y]++;
// }
namespace Sub1{
void Solve(int n){
vector<vector<int>> graph(n*2+1);
for(int i = 1; i<=2*n; ++i) for(int j = i + 1; j<=2*n; ++j){
vector<int> ask = {i, j};
if (Query(ask) == 1) {
graph[i].push_back(j);
graph[j].push_back(i);
}
}
for(int i = 1; i<=2*n; ++i) if (graph[i].size() != 1){
pair<int, int> legit = {-1, -1};
for(int j = 0; j < 3; ++j) for(int k = j + 1; k < 3; ++k){
vector<int> ask = {i, graph[i][j], graph[i][k]};
if (Query(ask) == 1) {
legit = {graph[i][j], graph[i][k]};
break;
}
}
graph[i] = {legit.first, legit.second};
}
for(int i = 1; i<=2*n; ++i) sort(ALL(graph[i]));
for(int i = 1; i<=2*n; ++i){
for(int j: graph[i]) if (j > i){
if (binary_search(ALL(graph[j]), i)) Answer(i, j);
}
}
}
}
namespace Sub2{
void Solve(int n){
vector<int> X, Y;
for(int i = 1; i<=n; ++i) {
X.push_back(i);
Y.push_back(i+n);
}
vector<vector<int>> graph(n*2+1);
#define add_edge(u, v) {graph[u].push_back(v);}
for(int i = 0; i<=1; ++i){
for(int i: X){
vector<int> tmp = Y;
vector<int> ask = tmp;
ask.push_back(i);
if (Query(ask) == n){
int l = 0, r = Y.size()- 1;
while(l < r){
int mid = (l + r) >> 1;
vector<int> ask;
for(int i = 0; i<=mid; ++i) ask.push_back(Y[i]);
ask.push_back(i);
if (Query(ask) == mid + 1) r = mid;
else l = mid + 1;
}
add_edge(i, Y[l]);
}
else{
vector<int> tmp = Y;
int l = 0, r = tmp.size() - 1;
while(l < r){
int mid = (l + r) >> 1;
vector<int> ask;
for(int i= 0; i<=mid; ++i) ask.push_back(tmp[i]);
ask.push_back(i);
if (Query(ask) == mid) r = mid;
else l = mid + 1;
}
add_edge(i, tmp[l]);
int u = tmp[l];
tmp.erase(tmp.begin() + l);
l = 0, r = tmp.size() - 1;
while(l < r){
int mid = (l + r) >> 1;
vector<int> ask;
for(int i= 0; i<=mid; ++i) ask.push_back(tmp[i]);
ask.push_back(u); ask.push_back(i);
if (Query(ask) == mid + 1) r = mid;
else l = mid + 1;
}
add_edge(i, tmp[l]);
tmp.erase(tmp.begin() + l);
}
}
swap(X, Y);
}
for(int i = 1; i<=2*n; ++i) sort(ALL(graph[i]));
for(int i = 1; i<=2*n; ++i){
for(int j: graph[i]) if (j > i){
if (binary_search(ALL(graph[j]), i)) Answer(i, j);
}
}
}
}
void Solve(int n){
if (n <= 50) Sub1::Solve(n);
else Sub2::Solve(n);
}
// pair<bool, int> run_test(int _n){
// n = _n;
// Y.resize(n * 2 + 1); L = C = Y;
// for(int i= 1; i<=2*n; ++i) cin >> Y[i];
// for(int i= 1; i<=2*n; ++i) cin >> C[i];
// for(int i= 1; i<=2*n; ++i) cin >> L[i];
// o_cnt = 0; ans = 1;
// check = vector<int>(2*n+1);
// Solve(n);
// if (*max_element(1+ALL(check)) != 1 || *min_element(1+ALL(check)) != 1) ans = false;
// return {ans, o_cnt};
// }
// }
// int main(void){
// ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// int n; cin >> n;
// pair<bool, int> verdict = Grader::run_test(n);
// if (verdict.first) cout << "AC\n";
// else cout << "WA\n";
// cout << "Total operation count: " << verdict.second << "\n";
// return 0;
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
56 ms |
492 KB |
Wrong Answer [6] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
48 ms |
992 KB |
Output is correct |
4 |
Correct |
39 ms |
344 KB |
Output is correct |
5 |
Correct |
38 ms |
344 KB |
Output is correct |
6 |
Correct |
39 ms |
344 KB |
Output is correct |
7 |
Correct |
39 ms |
508 KB |
Output is correct |
8 |
Correct |
39 ms |
344 KB |
Output is correct |
9 |
Correct |
39 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
56 ms |
492 KB |
Wrong Answer [6] |
4 |
Halted |
0 ms |
0 KB |
- |