QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#282584 | #5404. 述树术 | zhoukangyang | 0 | 9ms | 5660kb | C++14 | 3.0kb | 2023-12-12 14:35:04 | 2023-12-12 14:35:05 |
Judging History
answer
#include<bits/stdc++.h>
#include"tree.h"
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define vi vector <int>
#define sz(a) ((int) (a).size())
#define me(f, x) memset(f, x, sizeof(f))
#define uint unsigned int
#define ull unsigned long long
#define i128 __int128
#define pb emplace_back
using namespace std;
const int N = 1007;
int n;
int ord[N];
mt19937_64 orz;
map < vi, int > mp;
inline int query(vi S) {
sort(S.begin(), S.end());
if(mp.count(S))return mp[S];
// for(auto&x : S)
// x = ord[x];
return mp[S] = Query(S);
}
void report(int x, int y){
if(x == -1) return Report(x, y), void();
Report(x, y);
// Report(ord[x], ord[y]);
}
int GG;
int val[N];
int vis[N];
int fa[N];
inline int get0(vi S){
for(auto&u : S)if(fa[u] == 0)return u;
return 0;
}
void slv(vi S) {
if(sz(S) <= 1) return;
if(GG) return;
shuffle(S.begin(), S.end(), orz);
L(t, 0, sz(S) - 1) {
int u = S[t], win = 0;
for(auto&v : S)
if(u == v) val[v] = 1;
else val[v] = query(vi{u, v}), win |= val[v] > 2;
if(win) {
// cout << "u = " << u << endl;
auto dfs = [&] (auto self, vi ls, vi rs) {
if(!sz(rs)){
slv(ls);
return;
}
int p = rs[orz() % sz(rs)];
int fp = 0;
for(auto&r : ls) vis[r] = 0;
for(auto&r : ls)if(r != u) {
if(query(vi{p, r}) == 2) vis[r] = 1;
}
for(auto&r : ls)if(vis[r]) {
if(query(vi{u, p, r}) == 3) {
fp = r;
break;
}
}
// cout << u << ", " << p << " and " << fp << endl;
assert(fp != 0);
vi L_l, L_r;
vi R_l, R_r;
vi midS;
for(auto&r : ls)if(r != fp){
if(vis[r]) R_l.emplace_back(r);
else L_l.emplace_back(r);
}
midS.emplace_back(p);
for(auto&r : rs) if(p != r) {
if(query(vi{r, fp}) == 3) {
R_r.emplace_back(r);
} else if(query(vi{r, u, fp}) == 3) {
midS.emplace_back(r);
} else {
L_r.emplace_back(r);
}
}
slv(midS);
self(self, L_l, L_r);
self(self, R_l, R_r);
// cout << "ok solved" << endl;
fa[get0(midS)] = fp;
if(sz(L_l))fa[get0(L_l)] = fp;
int xs = 0;
for(auto&p : R_l) xs ^= p ^ fa[p];
if(xs)fa[fp] = xs;
return;
};
vi ls, rs;
for(auto&u : S)
if(val[u] <= 2) ls.emplace_back(u);
else rs.emplace_back(u);
// cout << "ls : "; for(auto&x : ls) cout << x << ' '; cout << '\n';
// cout << "rs : "; for(auto&x : rs) cout << x << ' '; cout << '\n';
dfs(dfs, ls, rs);
return;
}
if(t == 2) {
// cout<<"GG.., S = ";
// for(auto&u:S)cout<<u<<' ';
// cout<<endl;
return GG = 1, report(-1, -1), void();
}
}
// cout<<"GG??, S = ";
// for(auto&u:S)cout<<u<<' ';
// cout<<endl;
GG = 1, report(-1, -1);
}
void Solve(int N) {
n = N;
if(n == 2)return report(-1, -1), void();
vi S;
L(i, 1, n) S.emplace_back(i);
slv(S);
L(i, 1, n) if(fa[i])report(fa[i], i);
}
/*
11 250000
2 3
4 5
6 7
8 9
10 11
0 0
0 0
0 0
0 0
0 0
1
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Acceptable Answer
Test #1:
score: 0
Acceptable Answer
time: 4ms
memory: 4864kb
input:
499 7890 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
1 7676
result:
points 0.69635780480 x = 7676
Subtask #2:
score: 0
Wrong Answer
Test #30:
score: 0
Wrong Answer
time: 9ms
memory: 5660kb
input:
999 16789 0 0 0 0 0 0 495 639 428 443 0 0 511 28 0 0 0 0 0 0 0 0 31 729 899 866 429 959 357 322 795 615 235 620 0 0 0 0 85 389 33 50 234 522 276 468 480 269 0 0 705 536 0 0 87 446 889 578 86 472 0 0 699 53 0 0 706 976 381 493 0 0 441 164 0 0 0 0 0 0 283 215 0 0 113 208 334 225 372 487 0 0 878 418 0 ...
output:
0 Too many queries.
result:
wrong answer Too