QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#729952 | #9570. Binary Tree | ucup-team987# | AC ✓ | 320ms | 14308kb | C++23 | 13.8kb | 2024-11-09 18:06:09 | 2024-11-09 18:06:11 |
Judging History
answer
/**
* date : 2024-11-09 19:05:58
* author : Nyaan
*/
#define NDEBUG
using namespace std;
// intrinstic
#include <immintrin.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <cfloat>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tr2/dynamic_bitset>
#include <tuple>
#include <type_traits>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
// utility
namespace Nyaan {
using ll = long long;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
template <typename T>
using V = vector<T>;
template <typename T>
using VV = vector<vector<T>>;
using vi = vector<int>;
using vl = vector<long long>;
using vd = V<double>;
using vs = V<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename U>
struct P : pair<T, U> {
template <typename... Args>
constexpr P(Args... args) : pair<T, U>(args...) {}
using pair<T, U>::first;
using pair<T, U>::second;
P &operator+=(const P &r) {
first += r.first;
second += r.second;
return *this;
}
P &operator-=(const P &r) {
first -= r.first;
second -= r.second;
return *this;
}
P &operator*=(const P &r) {
first *= r.first;
second *= r.second;
return *this;
}
template <typename S>
P &operator*=(const S &r) {
first *= r, second *= r;
return *this;
}
P operator+(const P &r) const { return P(*this) += r; }
P operator-(const P &r) const { return P(*this) -= r; }
P operator*(const P &r) const { return P(*this) *= r; }
template <typename S>
P operator*(const S &r) const {
return P(*this) *= r;
}
P operator-() const { return P{-first, -second}; }
};
using pl = P<ll, ll>;
using pi = P<int, int>;
using vp = V<pl>;
constexpr int inf = 1001001001;
constexpr long long infLL = 4004004004004004004LL;
template <typename T>
int sz(const T &t) {
return t.size();
}
template <typename T, typename U>
inline bool amin(T &x, U y) {
return (y < x) ? (x = y, true) : false;
}
template <typename T, typename U>
inline bool amax(T &x, U y) {
return (x < y) ? (x = y, true) : false;
}
template <typename T>
inline T Max(const vector<T> &v) {
return *max_element(begin(v), end(v));
}
template <typename T>
inline T Min(const vector<T> &v) {
return *min_element(begin(v), end(v));
}
template <typename T>
inline long long Sum(const vector<T> &v) {
return accumulate(begin(v), end(v), 0LL);
}
template <typename T>
int lb(const vector<T> &v, const T &a) {
return lower_bound(begin(v), end(v), a) - begin(v);
}
template <typename T>
int ub(const vector<T> &v, const T &a) {
return upper_bound(begin(v), end(v), a) - begin(v);
}
constexpr long long TEN(int n) {
long long ret = 1, x = 10;
for (; n; x *= x, n >>= 1) ret *= (n & 1 ? x : 1);
return ret;
}
template <typename T, typename U>
pair<T, U> mkp(const T &t, const U &u) {
return make_pair(t, u);
}
template <typename T>
vector<T> mkrui(const vector<T> &v, bool rev = false) {
vector<T> ret(v.size() + 1);
if (rev) {
for (int i = int(v.size()) - 1; i >= 0; i--) ret[i] = v[i] + ret[i + 1];
} else {
for (int i = 0; i < int(v.size()); i++) ret[i + 1] = ret[i] + v[i];
}
return ret;
};
template <typename T>
vector<T> mkuni(const vector<T> &v) {
vector<T> ret(v);
sort(ret.begin(), ret.end());
ret.erase(unique(ret.begin(), ret.end()), ret.end());
return ret;
}
template <typename F>
vector<int> mkord(int N, F f) {
vector<int> ord(N);
iota(begin(ord), end(ord), 0);
sort(begin(ord), end(ord), f);
return ord;
}
template <typename T>
vector<int> mkinv(vector<T> &v) {
int max_val = *max_element(begin(v), end(v));
vector<int> inv(max_val + 1, -1);
for (int i = 0; i < (int)v.size(); i++) inv[v[i]] = i;
return inv;
}
vector<int> mkiota(int n) {
vector<int> ret(n);
iota(begin(ret), end(ret), 0);
return ret;
}
template <typename T>
T mkrev(const T &v) {
T w{v};
reverse(begin(w), end(w));
return w;
}
template <typename T>
bool nxp(T &v) {
return next_permutation(begin(v), end(v));
}
// 返り値の型は入力の T に依存
// i 要素目 : [0, a[i])
template <typename T>
vector<vector<T>> product(const vector<T> &a) {
vector<vector<T>> ret;
vector<T> v;
auto dfs = [&](auto rc, int i) -> void {
if (i == (int)a.size()) {
ret.push_back(v);
return;
}
for (int j = 0; j < a[i]; j++) v.push_back(j), rc(rc, i + 1), v.pop_back();
};
dfs(dfs, 0);
return ret;
}
// F : function(void(T&)), mod を取る操作
// T : 整数型のときはオーバーフローに注意する
template <typename T>
T Power(T a, long long n, const T &I, const function<void(T &)> &f) {
T res = I;
for (; n; f(a = a * a), n >>= 1) {
if (n & 1) f(res = res * a);
}
return res;
}
// T : 整数型のときはオーバーフローに注意する
template <typename T>
T Power(T a, long long n, const T &I = T{1}) {
return Power(a, n, I, function<void(T &)>{[](T &) -> void {}});
}
template <typename T>
T Rev(const T &v) {
T res = v;
reverse(begin(res), end(res));
return res;
}
template <typename T>
vector<T> Transpose(const vector<T> &v) {
using U = typename T::value_type;
if(v.empty()) return {};
int H = v.size(), W = v[0].size();
vector res(W, T(H, U{}));
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
res[j][i] = v[i][j];
}
}
return res;
}
template <typename T>
vector<T> Rotate(const vector<T> &v, int clockwise = true) {
using U = typename T::value_type;
int H = v.size(), W = v[0].size();
vector res(W, T(H, U{}));
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (clockwise) {
res[W - 1 - j][i] = v[i][j];
} else {
res[j][H - 1 - i] = v[i][j];
}
}
}
return res;
}
} // namespace Nyaan
// bit operation
namespace Nyaan {
__attribute__((target("popcnt"))) inline int popcnt(const u64 &a) {
return __builtin_popcountll(a);
}
inline int lsb(const u64 &a) { return a ? __builtin_ctzll(a) : 64; }
inline int ctz(const u64 &a) { return a ? __builtin_ctzll(a) : 64; }
inline int msb(const u64 &a) { return a ? 63 - __builtin_clzll(a) : -1; }
template <typename T>
inline int gbit(const T &a, int i) {
return (a >> i) & 1;
}
template <typename T>
inline void sbit(T &a, int i, bool b) {
if (gbit(a, i) != b) a ^= T(1) << i;
}
constexpr long long PW(int n) { return 1LL << n; }
constexpr long long MSK(int n) { return (1LL << n) - 1; }
} // namespace Nyaan
// inout
namespace Nyaan {
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
int s = (int)v.size();
for (int i = 0; i < s; i++) os << (i ? " " : "") << v[i];
return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
for (auto &x : v) is >> x;
return is;
}
istream &operator>>(istream &is, __int128_t &x) {
string S;
is >> S;
x = 0;
int flag = 0;
for (auto &c : S) {
if (c == '-') {
flag = true;
continue;
}
x *= 10;
x += c - '0';
}
if (flag) x = -x;
return is;
}
istream &operator>>(istream &is, __uint128_t &x) {
string S;
is >> S;
x = 0;
for (auto &c : S) {
x *= 10;
x += c - '0';
}
return is;
}
ostream &operator<<(ostream &os, __int128_t x) {
if (x == 0) return os << 0;
if (x < 0) os << '-', x = -x;
string S;
while (x) S.push_back('0' + x % 10), x /= 10;
reverse(begin(S), end(S));
return os << S;
}
ostream &operator<<(ostream &os, __uint128_t x) {
if (x == 0) return os << 0;
string S;
while (x) S.push_back('0' + x % 10), x /= 10;
reverse(begin(S), end(S));
return os << S;
}
void in() {}
template <typename T, class... U>
void in(T &t, U &...u) {
cin >> t;
in(u...);
}
void out() { cout << "\n"; }
template <typename T, class... U, char sep = ' '>
void out(const T &t, const U &...u) {
cout << t;
if (sizeof...(u)) cout << sep;
out(u...);
}
struct IoSetupNya {
IoSetupNya() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
cerr << fixed << setprecision(7);
}
} iosetupnya;
} // namespace Nyaan
// debug
#ifdef NyaanDebug
#define trc(...) (void(0))
#endif
#ifndef NyaanDebug
#define trc(...) (void(0))
#endif
#ifndef NyaanLocal
#define trc2(...) (void(0))
#endif
// macro
#define each(x, v) for (auto&& x : v)
#define each2(x, y, v) for (auto&& [x, y] : v)
#define all(v) (v).begin(), (v).end()
#define rep(i, N) for (long long i = 0; i < (long long)(N); i++)
#define repr(i, N) for (long long i = (long long)(N)-1; i >= 0; i--)
#define rep1(i, N) for (long long i = 1; i <= (long long)(N); i++)
#define repr1(i, N) for (long long i = (N); (long long)(i) > 0; i--)
#define reg(i, a, b) for (long long i = (a); i < (b); i++)
#define regr(i, a, b) for (long long i = (b)-1; i >= (a); i--)
#define fi first
#define se second
#define ini(...) \
int __VA_ARGS__; \
in(__VA_ARGS__)
#define inl(...) \
long long __VA_ARGS__; \
in(__VA_ARGS__)
#define ins(...) \
string __VA_ARGS__; \
in(__VA_ARGS__)
#define in2(s, t) \
for (int i = 0; i < (int)s.size(); i++) { \
in(s[i], t[i]); \
}
#define in3(s, t, u) \
for (int i = 0; i < (int)s.size(); i++) { \
in(s[i], t[i], u[i]); \
}
#define in4(s, t, u, v) \
for (int i = 0; i < (int)s.size(); i++) { \
in(s[i], t[i], u[i], v[i]); \
}
#define die(...) \
do { \
Nyaan::out(__VA_ARGS__); \
return; \
} while (0)
namespace Nyaan {
void solve();
}
int main() { Nyaan::solve(); }
//
using namespace Nyaan;
int send(int u, int v) {
out("?", u + 1, v + 1);
cout.flush();
ini(x);
return x;
}
void q() {
ini(N);
vvi g(N);
rep(i, N) {
ini(l, r);
--l, --r;
if (l != -1) g[i].push_back(l), g[l].push_back(i);
if (r != -1) g[i].push_back(r), g[r].push_back(i);
}
vi banned(N);
int root = 0;
while (1) {
vi sub(N);
{
auto dfs = [&](auto rc, int c, int p) -> int {
sub[c] = 1;
each(d, g[c]) {
if (d == p or banned[d]) continue;
sub[c] += rc(rc, d, c);
}
return sub[c];
};
dfs(dfs, root, -1);
}
int S = sub[root];
if (S == 1) {
out("!", root + 1);
cout.flush();
break;
}
int nroot = root;
{
int c = root, p = -1;
while (true) {
int nxc = -1, s = 0;
each(d, g[c]) {
if (d == p or banned[d]) continue;
if (amax(s, sub[d])) nxc = d;
}
if (s <= S / 2) break;
p = c, c = nxc;
}
nroot = c;
}
vi adj;
each(d, g[nroot]) {
if (banned[d]) continue;
adj.push_back(d);
}
fill(all(sub), 0);
{
auto dfs = [&](auto rc, int c, int p) -> int {
sub[c] = 1;
each(d, g[c]) {
if (d == p or banned[d]) continue;
sub[c] += rc(rc, d, c);
}
return sub[c];
};
dfs(dfs, nroot, -1);
}
sort(all(adj), [&](int i, int j) { return sub[i] > sub[j]; });
if (sz(adj) == 1) {
assert(S == 2);
int u = adj[0];
int v = nroot;
int x = send(u, v);
if (x == 0) {
root = u;
banned[v] = 1;
} else {
root = v;
banned[u] = 1;
}
continue;
}
int u = adj[0];
int v = adj[1];
int x = send(u, v);
if (x == 0) {
root = u;
banned[nroot] = 1;
} else if (x == 1) {
root = nroot;
banned[u] = banned[v] = 1;
} else {
root = v;
banned[nroot] = 1;
}
}
}
void Nyaan::solve() {
int t = 1;
in(t);
while (t--) q();
}
/*
// 4 以上 2 べき
pair<vi, vi> beki(int N) {
if (N == 4) {
vi p{0, 3, 1, 2};
vi q{0, 1, 2, 3};
return mkp(p, q);
}
auto [p, q] = beki(N / 2);
rep(i, N / 2) {
p.push_back(p[i] + N / 2);
q.push_back(q[i] + N / 2);
}
reg(i, N / 4, N / 2) swap(q[i], q[N - 1 - i]);
return {p, q};
}
pair<vi, vi> f(int N) {
if (N % 4 != 0) return {};
if ((N & (N - 1)) == 0) return beki(N);
int t = ctz(N);
auto [p, q] = f(N - (1 << t));
auto [r, s] = f(1 << t);
each(x, r) x ^= N - (1 << t);
each(x, s) x ^= N - (1 << t);
int u = ctz(N - (1 << t));
int rest = N - PW(t) - PW(u);
reg(i, PW(t - 1), PW(t)) swap(q[rest + i - PW(t - 1)], s[i]);
each(x, r) p.push_back(x);
each(x, s) q.push_back(x);
return {p, q};
}
bool check(vi p, vi q) {
int N = sz(p);
vi r(N);
rep(i, N) r[i] = p[i] ^ q[i];
trc(r);
sort(all(r));
rep(i, N) if (r[i] != i) return false;
return true;
}
void test() {
rep1(nd4, 100) {
int N = nd4 * 4;
if ((N & (N - 1)) == 0) {
auto [p, q] = beki(N);
trc(p);
trc(q);
assert(check(p, q));
}
{
auto [p, q] = f(N);
trc(p);
trc(q);
assert(check(p, q));
}
}
}
void q() { test(); }
void Nyaan::solve() {
int t = 1;
// in(t);
while (t--) q();
}
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3888kb
input:
2 5 0 0 1 5 2 4 0 0 0 0 1 0 2 0 2 0 0 2
output:
? 3 1 ? 5 2 ! 5 ? 2 1 ! 1
result:
ok OK (2 test cases)
Test #2:
score: 0
Accepted
time: 78ms
memory: 4276kb
input:
5555 8 2 0 8 6 0 0 3 0 0 0 7 0 0 0 5 4 0 0 2 8 0 0 1 4 2 0 0 0 7 8 0 0 3 0 6 0 0 0 0 8 5 8 0 0 1 7 0 0 0 0 4 2 0 0 6 0 0 1 2 5 4 5 3 1 0 0 0 0 0 0 0 2 8 0 0 0 0 5 6 0 0 1 4 2 0 3 8 0 0 0 0 5 3 0 5 1 0 0 0 0 4 0 0 2 5 5 0 0 0 0 0 3 0 2 4 0 0 3 3 0 1 0 0 0 2 2 2 0 0 0 0 3 2 3 0 0 0 0 2 10 2 8 9 7 0 0 ...
output:
? 8 6 ? 4 5 ? 3 4 ! 4 ? 7 2 ? 8 7 ? 6 8 ! 6 ? 8 3 ? 4 2 ? 8 6 ! 6 ? 2 4 ? 3 2 ! 2 ? 5 6 ? 1 4 ! 1 ? 5 1 ? 4 5 ! 5 ? 4 1 ? 3 4 ! 3 ? 3 2 ! 2 ? 2 1 ! 2 ? 2 3 ! 3 ? 7 1 ? 7 4 ? 3 6 ! 6 ? 2 1 ! 2 ? 5 9 ? 4 8 ? 5 3 ! 5 ? 10 3 ? 8 6 ? 2 4 ! 2 ? 9 3 ? 1 7 ? 9 2 ! 9 ? 2 1 ! 1 ? 4 3 ? 1 7 ! 7 ? 4 9 ? 8 4 ? 3...
result:
ok OK (5555 test cases)
Test #3:
score: 0
Accepted
time: 39ms
memory: 3772kb
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 0 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 0 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:
? 2 1 ! 1 ? 1 3 ! 3 ? 4 2 ? 3 4 ! 3 ? 4 3 ? 5 3 ! 5 ? 6 4 ? 6 3 ! 6 ? 2 6 ? 4 2 ! 5 ? 5 7 ? 8 5 ? 4 8 ! 4 ? 1 9 ? 8 9 ? 5 8 ! 8 ? 2 10 ? 7 8 ? 2 7 ! 7 ? 2 9 ? 8 4 ? 9 4 ! 4 ? 6 1 ? 4 2 ? 4 11 ! 4 ? 2 3 ? 5 9 ? 5 11 ! 6 ? 12 9 ? 11 8 ? 11 12 ! 12 ? 2 14 ? 15 8 ? 8 13 ! 13 ? 13 8 ? 14 10 ? 12 14 ? 4 1...
result:
ok OK (600 test cases)
Test #4:
score: 0
Accepted
time: 137ms
memory: 14308kb
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:
? 70790 43991 ? 36882 98065 ? 17626 87676 ? 23816 44703 ? 44123 980 ? 61196 90504 ? 54094 11034 ? 34051 63621 ? 79154 26980 ? 55857 22501 ? 15747 28077 ? 35270 76840 ? 97062 8937 ? 61940 22539 ? 70074 43281 ? 70074 79154 ! 79154 ? 5676 85780 ? 39704 57748 ? 58489 42043 ? 30188 50842 ? 36012 24131 ? ...
result:
ok OK (2 test cases)
Test #5:
score: 0
Accepted
time: 73ms
memory: 9232kb
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:
? 1 3 ! 2 ? 5 1 ? 1 4 ! 4 ? 6 9 ? 7 3 ? 7 10 ! 7 ? 13 29 ? 17 18 ? 1 24 ? 1 17 ! 17 ? 37 8 ? 30 14 ? 55 56 ? 22 19 ? 19 56 ! 31 ? 36 89 ? 96 110 ? 20 79 ? 62 106 ? 82 86 ? 61 82 ! 82 ? 64 233 ? 148 51 ? 1 176 ? 126 78 ? 251 252 ? 200 224 ? 176 200 ! 176 ? 439 48 ? 144 457 ? 376 142 ? 193 427 ? 173 2...
result:
ok OK (15 test cases)
Test #6:
score: 0
Accepted
time: 66ms
memory: 9032kb
input:
16 2 2 0 0 0 2 4 4 0 3 0 1 0 0 0 0 0 8 5 0 0 0 4 0 8 0 2 0 3 0 6 0 1 0 0 0 2 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 0 0 0 0 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:
? 2 1 ! 1 ? 3 4 ? 2 3 ! 2 ? 4 1 ? 6 4 ? 7 6 ! 6 ? 11 1 ? 6 10 ? 7 6 ? 12 7 ! 12 ? 16 13 ? 29 19 ? 7 5 ? 27 7 ? 8 27 ! 27 ? 8 24 ? 6 20 ? 13 10 ? 25 32 ? 7 25 ? 29 7 ! 29 ? 80 113 ? 16 115 ? 63 112 ? 25 50 ? 81 89 ? 11 81 ? 114 11 ! 114 ? 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: 69ms
memory: 9236kb
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 0 0 0 2 62 24 0 22 0 18 0 17 0 49 0 53 0 3...
output:
? 2 1 ! 1 ? 5 2 ? 6 5 ! 5 ? 4 9 ? 7 10 ? 4 7 ! 5 ? 27 20 ? 2 13 ? 18 17 ? 11 18 ! 18 ? 33 30 ? 4 32 ? 11 31 ? 19 59 ? 11 59 ! 37 ? 94 9 ? 59 69 ? 17 52 ? 111 44 ? 46 51 ? 52 51 ! 52 ? 12 100 ? 71 118 ? 62 146 ? 36 61 ? 48 247 ? 155 179 ? 146 179 ! 179 ? 68 449 ? 190 319 ? 239 141 ? 62 353 ? 265 488 ...
result:
ok OK (15 test cases)
Test #8:
score: 0
Accepted
time: 55ms
memory: 3740kb
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 0 0 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 0 1 8 0 0 3 7 1 0 2 5 6 8 0 0 0 0 0 0 0 1 0 9 9 8 0 0 7 2 0 0 0 0 0 0 0 0 4 5 3 6 0 1 2 10 3 6 8 0 4 2 5 7 0 0 10 9 0 0 0 0 0 0 0 0 0 1 2 11 0 0 4 9 5 8 6 3 0 0...
output:
? 2 1 ! 1 ? 3 2 ! 2 ? 4 3 ? 2 4 ! 2 ? 2 4 ? 5 3 ! 5 ? 2 3 ? 2 6 ! 2 ? 1 4 ? 3 7 ! 1 ? 4 3 ? 4 6 ? 8 5 ! 8 ? 1 3 ? 1 4 ? 5 8 ! 8 ? 1 4 ? 1 10 ? 9 6 ! 6 ? 2 6 ? 2 10 ? 11 9 ! 9 ? 1 11 ? 4 1 ? 8 7 ! 7 ? 13 7 ? 9 11 ? 6 5 ! 9 ? 12 11 ? 5 10 ? 4 13 ! 13 ? 8 14 ? 2 5 ? 11 6 ! 6 ? 10 9 ? 8 2 ? 16 12 ! 12 ?...
result:
ok OK (600 test cases)
Test #9:
score: 0
Accepted
time: 89ms
memory: 9884kb
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:
? 50379 69076 ? 79924 11838 ? 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 ? 72481 78976 ? 96633 84675 ? 2124 81852 ? 13836 79494 ? 80643 24965 ? 38932 5573 ? 5...
result:
ok OK (2 test cases)
Test #10:
score: 0
Accepted
time: 51ms
memory: 7388kb
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 ? 7 2 ? 3 6 ! 6 ? 15 5 ? 9 1 ? 2 4 ! 2 ? 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: 52ms
memory: 7252kb
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 0 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:
? 2 1 ! 1 ? 4 2 ? 3 4 ! 3 ? 8 1 ? 6 4 ? 8 7 ! 7 ? 16 15 ? 6 12 ? 8 10 ? 13 8 ! 13 ? 19 2 ? 3 15 ? 25 18 ? 13 27 ? 30 13 ! 13 ? 9 14 ? 58 24 ? 29 32 ? 17 3 ? 15 39 ? 57 15 ! 57 ? 28 83 ? 75 21 ? 10 7 ? 30 38 ? 111 64 ? 65 51 ! 65 ? 221 218 ? 199 243 ? 66 123 ? 247 165 ? 57 198 ? 138 196 ? 15 146 ! 14...
result:
ok OK (16 test cases)
Test #12:
score: 0
Accepted
time: 50ms
memory: 7212kb
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 0 0 1 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 0 0 0 2 62 0 0 0 0 28 47 7 38 0 0 0 0 17 26...
output:
? 2 1 ! 1 ? 2 6 ? 2 3 ! 3 ? 14 6 ? 3 4 ? 5 11 ! 3 ? 28 2 ? 23 26 ? 18 6 ? 8 10 ! 10 ? 61 36 ? 18 30 ? 31 50 ? 10 51 ? 42 44 ! 44 ? 18 44 ? 53 93 ? 75 45 ? 107 41 ? 80 32 ? 57 89 ! 32 ? 253 196 ? 42 224 ? 178 31 ? 218 103 ? 244 223 ? 102 147 ? 62 32 ! 32 ? 69 30 ? 210 172 ? 19 233 ? 188 349 ? 94 198 ...
result:
ok OK (15 test cases)
Test #13:
score: 0
Accepted
time: 53ms
memory: 3752kb
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 0 0 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 0 7 0 0 0 0 2 4 5 6 0 0 0 0 1 3 0 1 8 2 7 0 0 6 0 0 0 8 3 0 0 4 5 0 0 0 0 0 9 5 2 0 0 7 4 6 8 0 0 0 0 0 0 9 1 0 0 0 0 2 10 3 5 10 7 0 0 0 0 6 2 0 0 4 0 9 1 0 0 0 0 2 0 0 11 9 6 4 1 0 0 0 0 11 ...
output:
? 2 1 ! 1 ? 1 3 ! 3 ? 4 2 ? 3 4 ! 3 ? 1 4 ? 3 5 ! 3 ? 4 5 ? 3 4 ! 3 ? 4 7 ? 5 6 ! 4 ? 5 1 ? 3 8 ? 6 3 ! 6 ? 4 1 ? 3 6 ? 7 3 ! 3 ? 1 2 ? 7 10 ? 4 7 ! 4 ? 10 1 ? 10 11 ? 8 5 ! 5 ? 12 1 ? 12 11 ? 2 11 ! 2 ? 2 4 ? 12 2 ? 7 12 ! 12 ? 8 12 ? 10 8 ? 5 8 ! 8 ? 14 9 ? 1 14 ? 11 15 ! 15 ? 10 15 ? 2 10 ? 5 9 ?...
result:
ok OK (600 test cases)
Test #14:
score: 0
Accepted
time: 121ms
memory: 12200kb
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:
? 71188 96970 ? 87538 6820 ? 59029 32876 ? 46360 20365 ? 49372 9490 ? 17131 97012 ? 63260 47373 ? 50792 54267 ? 90948 40354 ? 57900 28477 ? 45466 57947 ? 49953 61749 ? 74237 46253 ? 80813 36006 ? 50792 80813 ? 51961 80813 ! 51961 ? 70265 86513 ? 11800 36225 ? 99536 25987 ? 59217 63730 ? 29352 84543 ...
result:
ok OK (2 test cases)
Test #15:
score: 0
Accepted
time: 57ms
memory: 8124kb
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 0 1 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 0 0 1 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 0 0 0 0 63 51 35 33 57 ...
output:
? 1 3 ! 2 ? 2 5 ? 1 7 ! 2 ? 15 4 ? 1 15 ? 2 11 ! 1 ? 14 1 ? 10 18 ? 29 10 ? 30 13 ! 30 ? 38 44 ? 42 1 ? 2 9 ? 34 2 ? 5 23 ! 23 ? 51 31 ? 96 62 ? 100 8 ? 52 89 ? 82 52 ? 70 57 ! 70 ? 124 122 ? 162 102 ? 84 231 ? 110 135 ? 147 223 ? 236 147 ? 201 80 ! 80 ? 322 266 ? 146 414 ? 72 335 ? 66 306 ? 89 76 ?...
result:
ok OK (15 test cases)
Test #16:
score: 0
Accepted
time: 63ms
memory: 8364kb
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 0 0 2 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 0 0 0 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:
? 2 1 ! 1 ? 3 1 ? 4 3 ! 4 ? 5 7 ? 6 8 ? 2 6 ! 6 ? 8 4 ? 16 8 ? 9 6 ? 3 9 ! 3 ? 11 17 ? 7 2 ? 9 7 ? 27 22 ? 20 27 ! 27 ? 31 10 ? 6 60 ? 45 22 ? 26 45 ? 14 4 ? 64 14 ! 64 ? 24 37 ? 55 56 ? 61 25 ? 115 10 ? 85 115 ? 120 27 ? 21 120 ! 21 ? 60 89 ? 248 208 ? 203 99 ? 234 222 ? 108 210 ? 173 108 ? 131 42 ...
result:
ok OK (16 test cases)
Test #17:
score: 0
Accepted
time: 63ms
memory: 8364kb
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:
? 2 1 ! 1 ? 2 6 ? 4 6 ! 4 ? 14 11 ? 11 13 ? 4 11 ! 4 ? 8 20 ? 9 1 ? 1 8 ? 29 1 ! 1 ? 42 59 ? 12 31 ? 19 40 ? 12 40 ? 47 40 ! 40 ? 40 17 ? 11 102 ? 27 88 ? 3 93 ? 93 27 ? 89 93 ! 93 ? 90 189 ? 158 221 ? 198 132 ? 32 240 ? 4 49 ? 49 240 ? 1 49 ! 1 ? 60 192 ? 29 303 ? 190 312 ? 241 495 ? 35 402 ? 71 20...
result:
ok OK (15 test cases)
Test #18:
score: 0
Accepted
time: 96ms
memory: 10048kb
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:
? 52174 35226 ? 26122 16093 ? 11494 10853 ? 11494 91694 ? 90037 73088 ? 90037 21572 ? 51091 91442 ? 7067 93596 ? 75096 14316 ? 75096 55875 ? 42793 41734 ? 59747 42793 ? 472 67072 ? 59747 64770 ! 92650 ? 80592 36933 ? 50906 68004 ? 73367 65219 ? 20489 33796 ? 74041 19704 ? 35779 74041 ? 35779 85560 ?...
result:
ok OK (2 test cases)
Test #19:
score: 0
Accepted
time: 320ms
memory: 3608kb
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:
? 2 1 ! 1 ? 2 1 ! 2 ? 2 1 ! 1 ? 2 1 ! 2 ? 2 1 ! 1 ? 2 1 ! 2 ? 2 1 ! 2 ? 2 1 ! 2 ? 2 1 ! 2 ? 2 1 ! 1 ? 2 1 ! 2 ? 2 1 ! 2 ? 2 1 ! 1 ? 2 1 ! 1 ? 2 1 ! 2 ? 2 1 ! 1 ? 2 1 ! 1 ? 2 1 ! 1 ? 2 1 ! 1 ? 2 1 ! 2 ? 2 1 ! 2 ? 2 1 ! 2 ? 2 1 ! 1 ? 2 1 ! 2 ? 2 1 ! 2 ? 2 1 ! 1 ? 2 1 ! 1 ? 2 1 ! 1 ? 2 1 ! 1 ? 2 1 ! 1 ...
result:
ok OK (100000 test cases)
Extra Test:
score: 0
Extra Test Passed