이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "interactive.h"
using namespace std;
vector<int> multisetDifference(vector<int> a, vector<int> b){
sort(a.begin(), a.end());
multiset<int> msb(b.begin(), b.end());
vector<int> out;
for(int x : a){
if(msb.find(x) == msb.end()){
out.push_back(x);
}else{
msb.erase(msb.find(x));
}
}
return out;
}
vector<int> setDifference(vector<int> a, vector<int> b){
sort(a.begin(), a.end());
sort(b.begin(), b.end());
/*
for(int i = 1; i < a.size(); i++) assert(a[i-1] <= a[i]);
for(int i = 1; i < b.size(); i++) assert(b[i-1] <= b[i]);
*/
vector<int> out;
for(int x : a){
if(!binary_search(b.begin(), b.end(), x)) out.push_back(x);
}
return out;
}
int front;
int lb[256];
int rb[256];
vector<int> qdep[8];
vector<int> ansdep[8];
vector<int> seg[256];
void build(int c, int l, int r, int dep = 0){
lb[c] = l;
rb[c] = r;
qdep[dep].push_back(c);
if(l == r) return;
int k = (l+r)/2;
build(2*c, l, k, dep+1);
build(2*c+1, k+1, r, dep+1);
}
void propagate(int c, int dep = 0){
if(c == 1) seg[1] = ansdep[0];
else if(c % 2 == 0){
seg[c] = setDifference(seg[c/2], seg[c+1]);
}else{
seg[c] = setDifference(seg[c/2], ansdep[dep]);
}
if(lb[c] == rb[c]) return;
propagate(2*c+1, dep+1);
propagate(2*c, dep+1);
}
void collect(int c, vector<int>& ans){
if(lb[c] == rb[c]){
ans.push_back(seg[c].front());
return;
}
collect(2*c, ans);
collect(2*c+1, ans);
}
vector<int> guess(int n) {
front = ask(1);
build(1, 1, n);
for(int i = 1; i <= n; i++) ansdep[0].push_back(i);
for(int i = 1; i < 8; i++){
if(qdep[i].empty()) break;
vector<int> query;
for(int x : qdep[i]){
if(x % 2 == 0 || x == 1){
for(int j = lb[x]; j <= rb[x]; j++) query.push_back(j);
}
}
if(query.empty()) break;
assert(query.front() == 1);
vector<int> i1 = get_pairwise_xor(query);
query.erase(query.begin());
vector<int> i2 = query.empty() ? vector<int>() : get_pairwise_xor(query);
vector<int> cur = multisetDifference(i1, i2);
sort(cur.begin(), cur.end());
cur.resize(unique(cur.begin(), cur.end()) - cur.begin());
for(int& x : cur) x ^= front;
if(cur.empty() || cur.front() != front) cur.insert(cur.begin(), front);
ansdep[i] = cur;
}
propagate(1);
vector<int> ans;
collect(1, ans);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |