QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#728679 | #9570. Binary Tree | ucup-team045# | AC ✓ | 320ms | 41264kb | C++20 | 8.3kb | 2024-11-09 15:39:24 | 2024-11-09 15:39:25 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
using namespace std;
using LL = long long;
// 1_based HLD
// struct Edge{
// int to;
// int w;
// operator int() const { return to; }
// };
using Edge = int;
struct HLD{
int n;
vector<int> sz, top, dep, fa, in, out, seq;
vector<vector<Edge> > g;
int ts;
HLD(const vector<vector<Edge> > &g, int root = 1) : n(int(g.size()) - 1), g(g) {
ts = 0;
sz.resize(n + 1);
top.resize(n + 1);
dep.resize(n + 1);
fa.resize(n + 1);
in.resize(n + 1);
out.resize(n + 1);
seq.resize(n + 1);
dep[root] = 1;
top[root] = root;
dfs_sz(root);
dfs_hld(root);
}
void dfs_sz(int u){
if (fa[u]){
for(auto it = g[u].begin(); it != g[u].end(); it++){
if (*it == fa[u]){
g[u].erase(it);
break;
}
}
}
sz[u] = 1;
for(auto &j : g[u]){
fa[j] = u;
dep[j] = dep[u] + 1;
dfs_sz(j);
sz[u] += sz[j];
if (sz[j] > sz[g[u][0]])
swap(j, g[u][0]);
}
}
void dfs_hld(int u){
in[u] = ++ts;
seq[in[u]] = u;
for (auto j : g[u]){
top[j] = (j == g[u][0] ? top[u] : j);
dfs_hld(j);
}
out[u] = ts;
}
int lca(int u, int v){
while (top[u] != top[v]){
if (dep[top[u]] > dep[top[v]]){
u = fa[top[u]];
}
else{
v = fa[top[v]];
}
}
return dep[u] < dep[v] ? u : v;
}
int dist(int u, int v){
return dep[u] + dep[v] - 2 * dep[lca(u, v)];
}
bool in_subtree(int u, int v){
return in[v] <= in[u] && in[u] <= out[v];
}
int jump(int u, int k) {
if (dep[u] < k){
return -1;
}
int d = dep[u] - k;
while (dep[top[u]] > d){
u = fa[top[u]];
}
return seq[in[u] - dep[u] + d];
}
int rooted_lca(int a, int b, int c){
return lca(a, b) ^ lca(b, c) ^ lca(c, a);
}
template<typename Q>
void modify_path(int u, int v, const Q &q, bool edge = false){
while(top[u] != top[v]){
if (dep[top[u]] < dep[top[v]]) swap(u, v);
q(in[top[u]], in[u]);
u = fa[top[u]];
}
if (dep[u] > dep[v]) swap(u, v);
q(in[u] + edge, in[v]);
}
template<typename Q>
void modify_subtree(int u, const Q &q){
q(in[u], out[u]);
}
template<typename T, typename Q>
T query_path(int u, int v, const Q &q, bool edge = false){
T ret = T();
while(top[u] != top[v]){
if (dep[top[u]] < dep[top[v]]) swap(u, v);
ret = q(in[top[u]], in[u]) + ret;
u = fa[top[u]];
}
if (dep[u] > dep[v]) swap(u, v);
return q(in[u] + edge, in[v]) + ret;
}
template<typename T, typename Q>
T query_subtree(int u, const Q &q){
return q(in[u], out[u]);
}
template<typename T, typename Q, typename F>
T query_path_noncommutative(int u, int v, const Q &q, const F &f, bool edge = false){
T left = T(), right = T();
while(top[u] != top[v]){
if (dep[top[u]] < dep[top[v]]) swap(u, v), swap(left, right);
left = q(in[top[u]], in[u]) + left;
u = fa[top[u]];
}
if (dep[u] > dep[v]) swap(u, v), swap(left, right);
return f(left, q(in[u] + edge, in[v]) + right);
}
pair<vector<int>, vector<pair<int, int> > > compress(vector<int> v){
auto cmp = [&](int a, int b) { return in[a] < in[b]; };
sort(v.begin(), v.end(), cmp);
v.erase(unique(v.begin(), v.end()), v.end());
const int k = (int)v.size();
for(int i = 0; i + 1 < k; i++){
v.push_back(lca(v[i], v[i + 1]));
}
sort(v.begin(), v.end(), cmp);
v.erase(unique(v.begin(), v.end()), v.end());
vector<pair<int, int> > edges;
vector<int> stk;
for(auto x : v){
while(!stk.empty() && out[stk.back()] < in[x]){
stk.pop_back();
}
if (!stk.empty()){
edges.push_back({stk.back(), x});
}
stk.push_back(x);
}
return {v, edges};
}
};
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int hidden = 14221;
int T;
cin >> T;
while(T--){
int n;
cin >> n;
vector<int> pt(n);
iota(pt.begin(), pt.end(), 1);
vector<pair<int, int> > edge;
vector<vector<int> > gg(n + 1);
for(int i = 1; i <= n; i++){
for(int j = 0; j < 2; j++){
int x;
cin >> x;
if (x){
edge.push_back({i, x});
gg[x].push_back(i);
gg[i].push_back(x);
}
}
}
HLD hld(gg);
auto ask = [&](int x, int y){
cout << "? " << x << ' ' << y << endl;
#ifdef LOCAL
int d1 = hld.dist(x, hidden);
int d2 = hld.dist(y, hidden);
if (d1 < d2) return 0;
if (d1 == d2) return 1;
return 2;
#endif
int t;
cin >> t;
return t;
};
while(pt.size() > 1){
if (pt.size() == 2){
if (ask(pt[0], pt[1]) == 0){
pt = {pt[0]};
}
else{
pt = {pt[1]};
}
break;
}
vector<bool> v(n + 1);
for(auto x : pt) v[x] = true;
vector<vector<int> > g(n + 1);
for(auto [x, y] : edge){
if (v[x] and v[y]){
g[x].push_back(y);
g[y].push_back(x);
}
}
vector<int> sz(n + 1), fa(n + 1);
array<int, 3> best{};
int mn = 1e9;
auto dfs = [&](auto &&dfs, int u) -> void {
sz[u] = 1;
vector<int> sons;
for(auto j : g[u]){
if (!v[j] or j == fa[u]) continue;
sons.push_back(j);
fa[j] = u;
dfs(dfs, j);
sz[u] += sz[j];
}
if (sons.size() == 2){
int sz1 = sz[sons[0]];
int sz2 = sz[sons[1]];
int sz3 = pt.size() - sz1 - sz2;
int t = max({sz1, sz2, sz3});
if (t < mn){
mn = t;
best = {sons[0], u, sons[1]};
}
}
};
int root = 0;
while(g[pt[root]].size() == 3) root += 1;
root = pt[root];
dfs(dfs, root);
for(auto u : pt){
if (fa[fa[u]] != 0){
int sz1 = sz[u];
int sz2 = sz[fa[u]] - sz[u];
int sz3 = pt.size() - sz1 - sz2;
int t = max({sz1, sz2, sz3});
if (t < mn){
mn = t;
best = {u, fa[u], fa[fa[u]]};
}
}
}
int t = best[ask(best[0], best[2])];
v[best[0]] = v[best[1]] = v[best[2]] = false;
v[t] = true;
pt.clear();
auto dfs1 = [&](auto &&dfs1, int u, int fa) -> void {
pt.push_back(u);
for(auto j : g[u]){
if (!v[j] or j == fa) continue;
dfs1(dfs1, j, u);
}
};
dfs1(dfs1, t, -1);
}
cout << "! " << pt[0] << endl;
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3504kb
input:
2 5 0 0 1 5 2 4 0 0 0 0 2 0 2 0 2 0 0 2
output:
? 5 3 ? 3 4 ! 3 ? 1 2 ! 2
result:
ok OK (2 test cases)
Test #2:
score: 0
Accepted
time: 145ms
memory: 5652kb
input:
5555 8 2 0 8 6 0 0 3 0 0 0 7 0 0 0 5 4 0 2 0 8 0 0 1 4 2 0 0 0 7 8 0 0 3 0 6 0 2 1 2 8 5 8 0 0 1 7 0 0 0 0 4 2 0 0 6 0 0 2 2 5 4 5 3 1 0 0 0 0 0 0 1 0 8 0 0 0 0 5 6 0 0 1 4 2 0 3 8 0 0 1 2 5 3 0 5 1 0 0 0 0 4 0 0 0 5 5 0 0 0 0 0 3 0 2 4 2 2 3 3 0 1 0 0 0 2 2 2 0 0 0 2 3 2 3 0 0 0 0 2 10 2 8 9 7 0 0 ...
output:
? 8 6 ? 5 4 ? 4 3 ! 4 ? 5 3 ? 1 4 ? 2 3 ! 3 ? 1 6 ? 5 3 ? 3 7 ! 7 ? 4 2 ? 1 5 ! 1 ? 6 5 ? 8 3 ! 3 ? 5 1 ? 5 4 ! 5 ? 2 4 ? 4 3 ! 3 ? 3 2 ! 2 ? 1 2 ! 2 ? 2 3 ! 3 ? 9 7 ? 4 7 ? 6 3 ! 6 ? 1 2 ! 1 ? 5 9 ? 2 1 ? 2 6 ! 2 ? 8 5 ? 7 1 ? 7 9 ! 9 ? 3 9 ? 1 7 ? 2 9 ! 9 ? 1 2 ! 2 ? 3 4 ? 1 7 ! 7 ? 4 5 ? 8 4 ? 8 ...
result:
ok OK (5555 test cases)
Test #3:
score: 0
Accepted
time: 98ms
memory: 4092kb
input:
600 2 2 0 0 0 2 3 2 0 3 0 0 0 2 4 4 0 1 0 0 0 3 0 0 0 5 4 0 0 0 1 0 2 0 3 0 2 0 6 4 0 6 0 2 0 5 0 0 0 1 0 2 0 7 7 0 3 0 6 0 5 0 2 0 1 0 0 0 0 1 8 7 0 0 0 2 0 8 0 1 0 5 0 3 0 6 0 2 0 0 9 7 0 4 0 2 0 1 0 0 0 8 0 9 0 5 0 6 0 2 0 2 10 9 0 6 0 8 0 7 0 0 0 10 0 2 0 4 0 5 0 1 0 0 0 2 11 2 0 10 0 6 0 9 0 0 ...
output:
? 1 2 ! 2 ? 3 1 ! 1 ? 4 2 ? 4 3 ! 4 ? 4 3 ? 3 5 ! 3 ? 4 6 ? 3 6 ! 3 ? 2 6 ? 4 2 ! 5 ? 7 5 ? 8 5 ? 8 4 ! 8 ? 9 1 ? 2 1 ? 2 3 ! 3 ? 2 10 ? 8 7 ? 8 3 ! 3 ? 2 9 ? 8 4 ? 4 9 ! 9 ? 2 9 ? 10 1 ? 5 10 ! 5 ? 2 3 ? 5 9 ? 11 5 ! 6 ? 12 9 ? 8 11 ? 3 8 ! 8 ? 14 2 ? 7 4 ? 2 4 ! 4 ? 8 13 ? 14 10 ? 12 14 ? 12 4 ! 1...
result:
ok OK (600 test cases)
Test #4:
score: 0
Accepted
time: 222ms
memory: 41264kb
input:
2 99999 21832 0 77205 0 62668 0 58313 0 14640 0 76941 0 62678 0 8464 0 43145 0 26195 0 46140 0 83205 0 40047 0 81645 0 27077 0 92036 0 14236 0 3576 0 15430 0 75654 0 29049 0 62218 0 83318 0 1116 0 77861 0 9755 0 49236 0 70959 0 62295 0 33580 0 88208 0 55840 0 71061 0 24695 0 88831 0 1891 0 57285 0 9...
output:
? 43991 70790 ? 98261 46637 ? 86742 20402 ? 13737 93018 ? 4868 75560 ? 77488 94866 ? 89861 22899 ? 93080 4660 ? 23392 77264 ? 36229 21731 ? 62930 3111 ? 82050 98461 ? 68697 97092 ? 25985 94878 ? 6069 37444 ? 13737 6069 ! 6069 ? 5676 85780 ? 39704 57748 ? 58489 42043 ? 30188 50842 ? 36012 24131 ? 185...
result:
ok OK (2 test cases)
Test #5:
score: 0
Accepted
time: 127ms
memory: 23532kb
input:
15 3 0 0 1 0 2 0 1 7 6 0 3 0 5 0 0 0 7 0 4 0 1 0 2 2 15 6 0 5 0 1 0 7 0 14 0 11 0 15 0 12 0 2 0 4 0 9 0 13 0 0 0 8 0 3 0 0 0 0 31 3 0 31 0 17 0 23 0 4 0 13 0 1 0 12 0 6 0 0 0 20 0 26 0 14 0 29 0 8 0 25 0 21 0 19 0 5 0 15 0 18 0 10 0 22 0 7 0 28 0 2 0 24 0 30 0 27 0 9 0 16 0 2 0 0 2 63 15 0 62 0 5 0 ...
output:
? 3 1 ! 2 ? 5 1 ? 4 1 ! 1 ? 9 6 ? 8 5 ? 13 8 ! 13 ? 13 29 ? 18 17 ? 23 5 ? 10 23 ! 23 ? 8 37 ? 10 24 ? 57 12 ? 41 25 ? 12 25 ! 63 ? 89 36 ? 6 71 ? 101 116 ? 57 64 ? 44 25 ? 6 44 ! 44 ? 64 233 ? 51 148 ? 19 31 ? 7 56 ? 217 10 ? 155 205 ? 31 155 ! 31 ? 439 48 ? 144 457 ? 142 376 ? 241 10 ? 39 178 ? 46...
result:
ok OK (15 test cases)
Test #6:
score: 0
Accepted
time: 130ms
memory: 23672kb
input:
16 2 2 0 0 0 2 4 4 0 3 0 1 0 0 0 2 2 8 5 0 0 0 4 0 8 0 2 0 3 0 6 0 1 0 2 0 0 16 2 0 5 0 1 0 11 0 13 0 14 0 8 0 6 0 0 0 4 0 3 0 7 0 15 0 10 0 16 0 9 0 2 0 0 2 32 15 0 0 0 14 0 18 0 26 0 17 0 25 0 27 0 6 0 9 0 4 0 13 0 23 0 30 0 32 0 12 0 11 0 31 0 28 0 3 0 19 0 10 0 22 0 7 0 5 0 29 0 24 0 20 0 21 0 1...
output:
? 1 2 ! 2 ? 4 3 ? 3 2 ! 2 ? 3 8 ? 5 8 ? 5 2 ! 5 ? 4 3 ? 13 2 ? 16 13 ? 16 9 ! 9 ? 16 13 ? 29 19 ? 7 5 ? 27 7 ? 27 8 ! 27 ? 3 60 ? 15 63 ? 52 12 ? 43 58 ? 47 43 ? 47 2 ! 47 ? 80 113 ? 16 115 ? 63 112 ? 25 50 ? 81 89 ? 11 81 ? 11 114 ! 11 ? 106 3 ? 82 72 ? 78 224 ? 13 105 ? 44 156 ? 184 54 ? 212 184 ?...
result:
ok OK (16 test cases)
Test #7:
score: 0
Accepted
time: 129ms
memory: 24400kb
input:
15 2 2 0 0 0 2 6 5 0 1 0 6 0 2 0 3 0 0 0 0 2 14 12 0 0 0 11 0 5 0 7 0 1 0 8 0 10 0 14 0 13 0 6 0 9 0 2 0 4 0 0 0 1 30 10 0 29 0 23 0 28 0 9 0 14 0 2 0 30 0 19 0 0 0 15 0 1 0 22 0 8 0 18 0 27 0 7 0 24 0 26 0 3 0 20 0 25 0 6 0 17 0 4 0 12 0 21 0 16 0 13 0 5 0 2 0 0 2 62 24 0 22 0 18 0 17 0 49 0 53 0 3...
output:
? 1 2 ! 2 ? 5 2 ? 6 5 ! 5 ? 4 9 ? 10 7 ? 2 10 ! 13 ? 16 21 ? 5 8 ? 12 19 ? 10 12 ! 12 ? 10 60 ? 2 9 ? 6 25 ? 16 41 ? 6 41 ! 53 ? 84 70 ? 90 37 ? 99 75 ? 30 65 ? 106 98 ? 65 98 ! 65 ? 12 100 ? 118 71 ? 192 44 ? 67 92 ? 113 41 ? 125 22 ? 113 22 ! 22 ? 68 449 ? 319 190 ? 334 450 ? 406 100 ? 483 25 ? 36...
result:
ok OK (15 test cases)
Test #8:
score: 0
Accepted
time: 93ms
memory: 4152kb
input:
600 2 2 0 0 0 2 3 3 2 0 0 0 0 2 4 3 0 0 0 0 0 1 2 2 2 5 0 0 3 1 4 5 0 0 0 0 1 0 6 3 5 1 4 0 0 6 0 0 0 0 0 0 0 7 3 7 0 0 0 0 2 5 0 0 1 4 0 0 2 0 8 0 0 3 7 1 0 2 5 6 8 0 0 0 0 0 0 2 1 2 9 9 8 0 0 7 2 0 0 0 0 0 0 0 0 4 5 3 6 2 1 2 10 3 6 8 0 4 2 5 7 0 0 10 9 0 0 0 0 0 0 0 0 1 1 2 11 0 0 4 9 5 8 6 3 0 0...
output:
? 1 2 ! 2 ? 3 2 ! 2 ? 3 4 ? 4 2 ! 2 ? 4 2 ? 3 5 ! 3 ? 1 4 ? 3 5 ! 3 ? 1 4 ? 2 5 ! 2 ? 7 4 ? 6 8 ? 5 4 ! 4 ? 3 1 ? 4 5 ? 8 1 ! 1 ? 2 1 ? 5 7 ? 4 3 ! 3 ? 2 3 ? 1 7 ? 6 4 ! 4 ? 5 1 ? 4 8 ? 7 1 ! 7 ? 7 13 ? 9 11 ? 6 5 ! 6 ? 5 14 ? 3 8 ? 1 9 ! 3 ? 8 14 ? 2 5 ? 13 12 ! 12 ? 10 9 ? 8 2 ? 16 12 ! 12 ? 2 3 ?...
result:
ok OK (600 test cases)
Test #9:
score: 0
Accepted
time: 160ms
memory: 24976kb
input:
2 99999 0 0 7999 97267 75750 37659 0 0 0 0 33761 92098 90707 18838 13602 27569 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14586 86647 1519 23132 0 0 3430 14643 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 47066 36968 95308 38482 34100 25297 0 0 0 0 0 0 0 0 88902 58991 0 0 0 0 66315 68538 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
? 22163 50379 ? 11838 79924 ? 18079 15463 ? 72017 29994 ? 80147 27856 ? 80763 26264 ? 39876 84186 ? 73287 34615 ? 43462 43070 ? 38721 85806 ? 84940 93114 ? 3443 79116 ? 49016 68555 ? 56289 87545 ? 32426 3887 ! 3887 ? 42261 72481 ? 84675 96633 ? 2124 81852 ? 13836 79494 ? 80643 24965 ? 38932 5573 ? 5...
result:
ok OK (2 test cases)
Test #10:
score: 0
Accepted
time: 98ms
memory: 17348kb
input:
15 3 3 2 0 0 0 0 1 7 0 0 3 6 0 0 7 2 0 0 0 0 5 1 2 2 15 14 12 0 0 0 0 0 0 8 6 10 11 0 0 3 7 2 4 0 0 0 0 0 0 15 5 0 0 9 1 0 0 0 31 4 9 0 0 29 17 0 0 0 0 15 31 5 21 18 14 0 0 0 0 0 0 16 2 12 7 0 0 23 10 0 0 30 13 0 0 24 27 11 26 0 0 0 0 0 0 0 0 19 20 0 0 0 0 0 0 6 25 8 1 28 22 2 0 0 2 63 53 48 40 57 0...
output:
? 3 2 ! 1 ? 2 7 ? 5 1 ! 1 ? 5 15 ? 8 6 ? 3 7 ! 3 ? 29 17 ? 30 13 ? 8 1 ? 18 14 ! 14 ? 1 2 ? 53 48 ? 63 19 ? 30 56 ? 55 59 ! 56 ? 20 115 ? 71 68 ? 67 3 ? 18 16 ? 123 55 ? 117 104 ! 104 ? 70 140 ? 78 250 ? 223 4 ? 220 204 ? 67 144 ? 75 15 ? 242 199 ! 242 ? 60 121 ? 414 74 ? 99 184 ? 301 403 ? 425 477 ...
result:
ok OK (15 test cases)
Test #11:
score: 0
Accepted
time: 100ms
memory: 17220kb
input:
16 2 0 0 1 0 2 4 4 2 0 0 0 0 3 0 0 0 8 3 0 0 0 0 0 0 0 1 2 0 0 6 4 5 7 2 1 2 16 16 15 0 0 0 0 0 0 7 11 8 10 0 0 13 0 0 0 0 0 0 0 3 9 0 0 4 2 5 14 6 12 0 0 0 0 32 0 0 22 21 25 18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 10 30 0 1 24 12 31 0 0 0 0 16 8 3 15 11 26 23 14 28 20 6 9 0 0 13 27 0 0 0 0 7 17 0 0 0 ...
output:
? 1 2 ! 2 ? 4 2 ? 4 3 ! 4 ? 2 8 ? 6 4 ? 7 8 ! 8 ? 16 15 ? 6 12 ? 8 10 ? 8 13 ! 8 ? 3 32 ? 22 21 ? 28 20 ? 7 17 ! 7 ? 9 14 ? 58 24 ? 29 32 ? 17 3 ? 15 39 ? 15 57 ! 57 ? 28 83 ? 75 21 ? 10 7 ? 30 38 ? 41 44 ? 91 89 ! 89 ? 134 221 ? 199 243 ? 66 123 ? 247 165 ? 94 171 ? 99 77 ? 251 207 ! 207 ? 324 81 ?...
result:
ok OK (16 test cases)
Test #12:
score: 0
Accepted
time: 95ms
memory: 17200kb
input:
15 2 0 0 1 0 2 6 6 4 1 5 0 0 0 0 3 0 0 0 0 2 14 0 0 1 7 5 11 13 9 0 0 2 8 0 0 10 0 0 0 0 0 0 0 14 6 0 0 3 4 2 0 2 30 7 0 5 13 0 0 0 0 14 30 15 20 0 0 0 0 3 19 0 0 0 0 11 21 9 1 16 24 0 0 0 0 28 2 8 10 0 0 0 0 0 0 0 0 18 6 0 0 4 29 12 25 0 0 23 26 0 0 27 22 2 0 0 0 62 0 0 0 0 28 47 7 38 0 0 0 0 17 26...
output:
? 1 2 ! 2 ? 1 5 ? 6 4 ! 4 ? 3 12 ? 2 8 ? 1 7 ! 7 ? 23 17 ? 5 13 ? 14 30 ? 16 24 ! 16 ? 36 61 ? 18 30 ? 31 50 ? 10 51 ? 21 8 ! 21 ? 18 44 ? 53 93 ? 51 69 ? 28 20 ? 77 115 ? 26 34 ! 34 ? 42 241 ? 112 193 ? 88 124 ? 17 30 ? 154 233 ? 186 72 ? 189 243 ! 186 ? 69 30 ? 210 172 ? 19 233 ? 186 228 ? 197 55 ...
result:
ok OK (15 test cases)
Test #13:
score: 0
Accepted
time: 111ms
memory: 4040kb
input:
600 2 0 0 1 0 2 3 0 0 1 3 0 0 2 4 2 4 0 0 0 0 3 0 2 2 5 2 5 0 0 0 0 0 0 4 3 1 0 6 6 4 0 0 0 0 3 0 2 1 0 0 0 2 7 0 0 0 0 2 4 5 6 0 0 0 0 1 3 1 2 8 2 7 0 0 6 0 0 0 8 3 0 0 4 5 0 0 2 2 0 9 5 2 0 0 7 4 6 8 0 0 0 0 0 0 9 1 0 0 1 1 2 10 3 5 10 7 0 0 0 0 6 2 0 0 4 0 9 1 0 0 0 0 2 2 0 11 9 6 4 1 0 0 0 0 11 ...
output:
? 1 2 ! 2 ? 3 1 ! 1 ? 2 4 ? 4 3 ! 3 ? 3 1 ? 5 4 ! 5 ? 4 5 ? 4 3 ! 3 ? 2 4 ? 1 3 ! 3 ? 4 5 ? 8 3 ? 3 6 ! 3 ? 4 9 ? 5 2 ? 1 8 ! 8 ? 2 1 ? 3 8 ? 8 9 ! 8 ? 3 10 ? 9 2 ? 1 6 ! 6 ? 10 4 ? 8 4 ? 8 3 ! 3 ? 4 2 ? 12 2 ? 2 10 ! 10 ? 8 12 ? 14 12 ? 1 4 ! 1 ? 12 14 ? 3 9 ? 13 2 ! 9 ? 6 1 ? 12 3 ? 11 16 ? 16 8 !...
result:
ok OK (600 test cases)
Test #14:
score: 0
Accepted
time: 192ms
memory: 33820kb
input:
2 99999 96748 53986 34197 77552 29863 63559 79099 26449 45078 1051 0 0 27416 4135 0 0 38606 81189 93892 68603 48776 185 79602 18311 51243 83678 89044 40032 28883 35663 0 0 0 0 21603 15821 0 0 51448 75971 70275 8326 0 0 0 0 57049 72937 3297 94939 0 0 59258 39159 3205 34675 54876 24769 0 0 0 0 0 0 851...
output:
? 27459 71188 ? 24680 87538 ? 11855 13278 ? 64417 35922 ? 58885 19381 ? 78595 80844 ? 18424 57349 ? 66628 9729 ? 91740 30681 ? 42472 971 ? 97140 47310 ? 26894 60710 ? 19646 66089 ? 18636 23536 ? 971 18636 ? 971 98332 ! 98332 ? 36553 70265 ? 11800 93063 ? 78349 99536 ? 59217 22534 ? 29352 84543 ? 864...
result:
ok OK (2 test cases)
Test #15:
score: 0
Accepted
time: 104ms
memory: 20724kb
input:
15 3 0 0 1 3 0 0 1 7 0 0 1 7 0 0 6 2 3 4 0 0 0 0 2 2 15 2 11 0 0 13 1 12 14 0 0 0 0 5 8 10 4 0 0 0 0 0 0 0 0 0 0 6 15 9 3 2 1 0 31 24 22 0 0 31 6 0 0 4 3 11 19 0 0 0 0 28 21 25 20 0 0 0 0 0 0 2 16 0 0 27 18 8 10 15 17 26 1 23 29 7 5 12 14 0 0 0 0 0 0 0 0 0 0 0 0 30 13 0 0 0 0 2 1 2 0 63 51 35 33 57 ...
output:
? 3 1 ! 2 ? 5 2 ? 1 7 ! 7 ? 4 15 ? 13 1 ? 9 3 ! 9 ? 1 14 ? 8 10 ? 14 18 ? 15 17 ! 15 ? 15 38 ? 48 42 ? 10 2 ? 37 9 ? 11 55 ! 55 ? 31 51 ? 18 96 ? 93 100 ? 54 59 ? 96 101 ? 65 13 ! 101 ? 83 124 ? 143 106 ? 33 252 ? 82 169 ? 18 12 ? 21 122 ? 149 164 ! 122 ? 266 322 ? 386 146 ? 381 102 ? 473 135 ? 263 ...
result:
ok OK (15 test cases)
Test #16:
score: 0
Accepted
time: 112ms
memory: 22504kb
input:
16 2 0 0 1 0 2 4 0 0 1 0 4 2 0 0 0 0 8 0 0 0 0 0 0 3 5 8 6 2 0 1 4 0 0 2 2 0 16 0 0 7 8 0 0 1 2 0 0 0 0 0 0 5 10 3 0 12 16 14 13 0 0 15 4 0 0 0 0 6 9 2 2 2 0 32 26 17 5 31 28 25 18 7 0 0 0 0 14 12 15 0 22 4 0 0 29 1 19 2 0 0 0 0 0 0 6 8 10 21 0 0 0 0 0 0 13 3 0 0 0 0 0 0 32 30 0 0 20 9 0 0 0 0 23 16...
output:
? 1 2 ! 2 ? 3 1 ? 3 4 ! 3 ? 3 5 ? 8 6 ? 6 2 ! 6 ? 7 8 ? 12 16 ? 6 9 ? 9 3 ! 9 ? 29 1 ? 28 25 ? 23 16 ? 6 8 ? 8 15 ! 8 ? 31 29 ? 34 6 ? 27 45 ? 62 26 ? 14 4 ? 14 64 ! 14 ? 46 24 ? 68 55 ? 80 61 ? 118 115 ? 87 85 ? 27 120 ? 120 21 ! 120 ? 60 97 ? 22 248 ? 251 203 ? 234 63 ? 108 109 ? 173 194 ? 131 42 ...
result:
ok OK (16 test cases)
Test #17:
score: 0
Accepted
time: 112ms
memory: 21616kb
input:
15 2 0 0 1 0 2 6 0 0 5 0 1 2 0 0 0 0 4 3 2 0 14 8 14 0 0 0 0 0 0 0 0 12 11 10 0 0 0 2 7 0 0 4 1 0 0 3 6 5 9 2 0 0 30 29 21 6 9 0 0 0 0 0 0 0 0 0 0 19 17 24 30 0 0 14 26 23 0 0 0 0 0 25 18 0 0 7 20 16 12 0 0 13 11 28 8 10 15 0 0 0 0 0 0 3 22 5 2 0 0 0 0 4 1 0 2 0 2 62 0 0 34 33 0 0 0 0 0 0 37 45 0 0 ...
output:
? 1 2 ! 2 ? 2 6 ? 6 4 ! 6 ? 11 14 ? 7 14 ? 7 10 ! 7 ? 8 20 ? 9 1 ? 8 1 ? 8 19 ! 19 ? 42 59 ? 31 12 ? 58 43 ? 31 43 ? 43 8 ! 8 ? 40 17 ? 11 102 ? 88 27 ? 72 111 ? 88 111 ? 88 91 ! 91 ? 90 189 ? 158 221 ? 198 132 ? 240 32 ? 181 178 ? 32 178 ? 32 43 ! 32 ? 60 192 ? 29 303 ? 190 312 ? 241 495 ? 35 402 ?...
result:
ok OK (15 test cases)
Test #18:
score: 0
Accepted
time: 181ms
memory: 24664kb
input:
2 99999 0 0 88119 0 72740 0 6901 19702 0 0 10620 84889 0 0 9552 63972 45156 60768 9152 72379 0 0 59875 97207 48193 0 17282 54916 65927 27713 80083 15817 36966 75381 0 0 77279 56298 0 0 11554 61779 0 0 89976 0 65282 42151 95206 62876 97329 86772 0 0 0 0 0 0 11820 0 0 0 20432 0 50520 39907 0 0 46948 1...
output:
? 35226 52174 ? 16093 26122 ? 11494 10853 ? 37465 11494 ? 73088 90037 ? 21572 90037 ? 51091 99968 ? 37874 7067 ? 75096 73345 ? 61908 88342 ? 54898 20607 ? 79113 54898 ? 28780 82981 ? 86442 82981 ! 82981 ? 80592 36933 ? 68004 50906 ? 65219 73367 ? 33796 20489 ? 61722 74041 ? 56446 35779 ? 85560 35779...
result:
ok OK (2 test cases)
Test #19:
score: 0
Accepted
time: 320ms
memory: 3560kb
input:
100000 2 0 0 0 1 2 2 0 0 0 1 0 2 0 0 0 1 2 2 0 0 0 1 0 2 0 0 0 1 2 2 0 0 0 1 0 2 0 0 0 1 0 2 0 0 0 1 0 2 0 0 0 1 0 2 0 0 0 1 2 2 0 0 0 1 0 2 0 0 0 1 0 2 0 0 0 1 2 2 0 0 0 1 2 2 0 0 0 1 0 2 0 0 0 1 2 2 0 0 0 1 2 2 0 0 0 1 2 2 0 0 0 1 2 2 0 0 0 1 0 2 0 0 0 1 0 2 0 0 0 1 0 2 0 0 0 1 2 2 0 0 0 1 0 2 0 0...
output:
? 1 2 ! 2 ? 1 2 ! 1 ? 1 2 ! 2 ? 1 2 ! 1 ? 1 2 ! 2 ? 1 2 ! 1 ? 1 2 ! 1 ? 1 2 ! 1 ? 1 2 ! 1 ? 1 2 ! 2 ? 1 2 ! 1 ? 1 2 ! 1 ? 1 2 ! 2 ? 1 2 ! 2 ? 1 2 ! 1 ? 1 2 ! 2 ? 1 2 ! 2 ? 1 2 ! 2 ? 1 2 ! 2 ? 1 2 ! 1 ? 1 2 ! 1 ? 1 2 ! 1 ? 1 2 ! 2 ? 1 2 ! 1 ? 1 2 ! 1 ? 1 2 ! 2 ? 1 2 ! 2 ? 1 2 ! 2 ? 1 2 ! 2 ? 1 2 ! 2 ...
result:
ok OK (100000 test cases)
Extra Test:
score: 0
Extra Test Passed