QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#795976 | #9804. Guess the Polygon | ucup-team1134# | TL | 203ms | 4088kb | C++23 | 37.2kb | 2024-12-01 05:43:58 | 2024-12-01 05:44:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;
// https://nyaannyaan.github.io/library/math/bigint.hpp.html
#pragma once
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
#pragma once
#include <type_traits>
using namespace std;
namespace internal {
template <typename T>
using is_broadly_integral =
typename conditional_t<is_integral_v<T> || is_same_v<T, __int128_t> ||
is_same_v<T, __uint128_t>,
true_type, false_type>::type;
template <typename T>
using is_broadly_signed =
typename conditional_t<is_signed_v<T> || is_same_v<T, __int128_t>,
true_type, false_type>::type;
template <typename T>
using is_broadly_unsigned =
typename conditional_t<is_unsigned_v<T> || is_same_v<T, __uint128_t>,
true_type, false_type>::type;
#define ENABLE_VALUE(x) \
template <typename T> \
constexpr bool x##_v = x<T>::value;
ENABLE_VALUE(is_broadly_integral);
ENABLE_VALUE(is_broadly_signed);
ENABLE_VALUE(is_broadly_unsigned);
#undef ENABLE_VALUE
#define ENABLE_HAS_TYPE(var) \
template <class, class = void> \
struct has_##var : false_type {}; \
template <class T> \
struct has_##var<T, void_t<typename T::var>> : true_type {}; \
template <class T> \
constexpr auto has_##var##_v = has_##var<T>::value;
#define ENABLE_HAS_VAR(var) \
template <class, class = void> \
struct has_##var : false_type {}; \
template <class T> \
struct has_##var<T, void_t<decltype(T::var)>> : true_type {}; \
template <class T> \
constexpr auto has_##var##_v = has_##var<T>::value;
} // namespace internal
#pragma once
template <uint32_t mod>
struct LazyMontgomeryModInt {
using mint = LazyMontgomeryModInt;
using i32 = int32_t;
using u32 = uint32_t;
using u64 = uint64_t;
static constexpr u32 get_r() {
u32 ret = mod;
for (i32 i = 0; i < 4; ++i) ret *= 2 - mod * ret;
return ret;
}
static constexpr u32 r = get_r();
static constexpr u32 n2 = -u64(mod) % mod;
static_assert(mod < (1 << 30), "invalid, mod >= 2 ^ 30");
static_assert((mod & 1) == 1, "invalid, mod % 2 == 0");
static_assert(r * mod == 1, "this code has bugs.");
u32 a;
constexpr LazyMontgomeryModInt() : a(0) {}
constexpr LazyMontgomeryModInt(const int64_t &b)
: a(reduce(u64(b % mod + mod) * n2)){};
static constexpr u32 reduce(const u64 &b) {
return (b + u64(u32(b) * u32(-r)) * mod) >> 32;
}
constexpr mint &operator+=(const mint &b) {
if (i32(a += b.a - 2 * mod) < 0) a += 2 * mod;
return *this;
}
constexpr mint &operator-=(const mint &b) {
if (i32(a -= b.a) < 0) a += 2 * mod;
return *this;
}
constexpr mint &operator*=(const mint &b) {
a = reduce(u64(a) * b.a);
return *this;
}
constexpr mint &operator/=(const mint &b) {
*this *= b.inverse();
return *this;
}
constexpr mint operator+(const mint &b) const { return mint(*this) += b; }
constexpr mint operator-(const mint &b) const { return mint(*this) -= b; }
constexpr mint operator*(const mint &b) const { return mint(*this) *= b; }
constexpr mint operator/(const mint &b) const { return mint(*this) /= b; }
constexpr bool operator==(const mint &b) const {
return (a >= mod ? a - mod : a) == (b.a >= mod ? b.a - mod : b.a);
}
constexpr bool operator!=(const mint &b) const {
return (a >= mod ? a - mod : a) != (b.a >= mod ? b.a - mod : b.a);
}
constexpr mint operator-() const { return mint() - mint(*this); }
constexpr mint operator+() const { return mint(*this); }
constexpr mint pow(u64 n) const {
mint ret(1), mul(*this);
while (n > 0) {
if (n & 1) ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
constexpr mint inverse() const {
int x = get(), y = mod, u = 1, v = 0, t = 0, tmp = 0;
while (y > 0) {
t = x / y;
x -= t * y, u -= t * v;
tmp = x, x = y, y = tmp;
tmp = u, u = v, v = tmp;
}
return mint{u};
}
friend ostream &operator<<(ostream &os, const mint &b) {
return os << b.get();
}
friend istream &operator>>(istream &is, mint &b) {
int64_t t;
is >> t;
b = LazyMontgomeryModInt<mod>(t);
return (is);
}
constexpr u32 get() const {
u32 ret = reduce(a);
return ret >= mod ? ret - mod : ret;
}
static constexpr u32 get_mod() { return mod; }
};
#pragma once
template <typename mint>
struct NTT {
static constexpr uint32_t get_pr() {
uint32_t _mod = mint::get_mod();
using u64 = uint64_t;
u64 ds[32] = {};
int idx = 0;
u64 m = _mod - 1;
for (u64 i = 2; i * i <= m; ++i) {
if (m % i == 0) {
ds[idx++] = i;
while (m % i == 0) m /= i;
}
}
if (m != 1) ds[idx++] = m;
uint32_t _pr = 2;
while (1) {
int flg = 1;
for (int i = 0; i < idx; ++i) {
u64 a = _pr, b = (_mod - 1) / ds[i], r = 1;
while (b) {
if (b & 1) r = r * a % _mod;
a = a * a % _mod;
b >>= 1;
}
if (r == 1) {
flg = 0;
break;
}
}
if (flg == 1) break;
++_pr;
}
return _pr;
};
static constexpr uint32_t mod = mint::get_mod();
static constexpr uint32_t pr = get_pr();
static constexpr int level = __builtin_ctzll(mod - 1);
mint dw[level], dy[level];
void setwy(int k) {
mint w[level], y[level];
w[k - 1] = mint(pr).pow((mod - 1) / (1 << k));
y[k - 1] = w[k - 1].inverse();
for (int i = k - 2; i > 0; --i)
w[i] = w[i + 1] * w[i + 1], y[i] = y[i + 1] * y[i + 1];
dw[1] = w[1], dy[1] = y[1], dw[2] = w[2], dy[2] = y[2];
for (int i = 3; i < k; ++i) {
dw[i] = dw[i - 1] * y[i - 2] * w[i];
dy[i] = dy[i - 1] * w[i - 2] * y[i];
}
}
NTT() { setwy(level); }
void fft4(vector<mint> &a, int k) {
if ((int)a.size() <= 1) return;
if (k == 1) {
mint a1 = a[1];
a[1] = a[0] - a[1];
a[0] = a[0] + a1;
return;
}
if (k & 1) {
int v = 1 << (k - 1);
for (int j = 0; j < v; ++j) {
mint ajv = a[j + v];
a[j + v] = a[j] - ajv;
a[j] += ajv;
}
}
int u = 1 << (2 + (k & 1));
int v = 1 << (k - 2 - (k & 1));
mint one = mint(1);
mint imag = dw[1];
while (v) {
// jh = 0
{
int j0 = 0;
int j1 = v;
int j2 = j1 + v;
int j3 = j2 + v;
for (; j0 < v; ++j0, ++j1, ++j2, ++j3) {
mint t0 = a[j0], t1 = a[j1], t2 = a[j2], t3 = a[j3];
mint t0p2 = t0 + t2, t1p3 = t1 + t3;
mint t0m2 = t0 - t2, t1m3 = (t1 - t3) * imag;
a[j0] = t0p2 + t1p3, a[j1] = t0p2 - t1p3;
a[j2] = t0m2 + t1m3, a[j3] = t0m2 - t1m3;
}
}
// jh >= 1
mint ww = one, xx = one * dw[2], wx = one;
for (int jh = 4; jh < u;) {
ww = xx * xx, wx = ww * xx;
int j0 = jh * v;
int je = j0 + v;
int j2 = je + v;
for (; j0 < je; ++j0, ++j2) {
mint t0 = a[j0], t1 = a[j0 + v] * xx, t2 = a[j2] * ww,
t3 = a[j2 + v] * wx;
mint t0p2 = t0 + t2, t1p3 = t1 + t3;
mint t0m2 = t0 - t2, t1m3 = (t1 - t3) * imag;
a[j0] = t0p2 + t1p3, a[j0 + v] = t0p2 - t1p3;
a[j2] = t0m2 + t1m3, a[j2 + v] = t0m2 - t1m3;
}
xx *= dw[__builtin_ctzll((jh += 4))];
}
u <<= 2;
v >>= 2;
}
}
void ifft4(vector<mint> &a, int k) {
if ((int)a.size() <= 1) return;
if (k == 1) {
mint a1 = a[1];
a[1] = a[0] - a[1];
a[0] = a[0] + a1;
return;
}
int u = 1 << (k - 2);
int v = 1;
mint one = mint(1);
mint imag = dy[1];
while (u) {
// jh = 0
{
int j0 = 0;
int j1 = v;
int j2 = v + v;
int j3 = j2 + v;
for (; j0 < v; ++j0, ++j1, ++j2, ++j3) {
mint t0 = a[j0], t1 = a[j1], t2 = a[j2], t3 = a[j3];
mint t0p1 = t0 + t1, t2p3 = t2 + t3;
mint t0m1 = t0 - t1, t2m3 = (t2 - t3) * imag;
a[j0] = t0p1 + t2p3, a[j2] = t0p1 - t2p3;
a[j1] = t0m1 + t2m3, a[j3] = t0m1 - t2m3;
}
}
// jh >= 1
mint ww = one, xx = one * dy[2], yy = one;
u <<= 2;
for (int jh = 4; jh < u;) {
ww = xx * xx, yy = xx * imag;
int j0 = jh * v;
int je = j0 + v;
int j2 = je + v;
for (; j0 < je; ++j0, ++j2) {
mint t0 = a[j0], t1 = a[j0 + v], t2 = a[j2], t3 = a[j2 + v];
mint t0p1 = t0 + t1, t2p3 = t2 + t3;
mint t0m1 = (t0 - t1) * xx, t2m3 = (t2 - t3) * yy;
a[j0] = t0p1 + t2p3, a[j2] = (t0p1 - t2p3) * ww;
a[j0 + v] = t0m1 + t2m3, a[j2 + v] = (t0m1 - t2m3) * ww;
}
xx *= dy[__builtin_ctzll(jh += 4)];
}
u >>= 4;
v <<= 2;
}
if (k & 1) {
u = 1 << (k - 1);
for (int j = 0; j < u; ++j) {
mint ajv = a[j] - a[j + u];
a[j] += a[j + u];
a[j + u] = ajv;
}
}
}
void ntt(vector<mint> &a) {
if ((int)a.size() <= 1) return;
fft4(a, __builtin_ctz(a.size()));
}
void intt(vector<mint> &a) {
if ((int)a.size() <= 1) return;
ifft4(a, __builtin_ctz(a.size()));
mint iv = mint(a.size()).inverse();
for (auto &x : a) x *= iv;
}
vector<mint> multiply(const vector<mint> &a, const vector<mint> &b) {
int l = a.size() + b.size() - 1;
if (min<int>(a.size(), b.size()) <= 40) {
vector<mint> s(l);
for (int i = 0; i < (int)a.size(); ++i)
for (int j = 0; j < (int)b.size(); ++j) s[i + j] += a[i] * b[j];
return s;
}
int k = 2, M = 4;
while (M < l) M <<= 1, ++k;
setwy(k);
vector<mint> s(M);
for (int i = 0; i < (int)a.size(); ++i) s[i] = a[i];
fft4(s, k);
if (a.size() == b.size() && a == b) {
for (int i = 0; i < M; ++i) s[i] *= s[i];
} else {
vector<mint> t(M);
for (int i = 0; i < (int)b.size(); ++i) t[i] = b[i];
fft4(t, k);
for (int i = 0; i < M; ++i) s[i] *= t[i];
}
ifft4(s, k);
s.resize(l);
mint invm = mint(M).inverse();
for (int i = 0; i < l; ++i) s[i] *= invm;
return s;
}
void ntt_doubling(vector<mint> &a) {
int M = (int)a.size();
auto b = a;
intt(b);
mint r = 1, zeta = mint(pr).pow((mint::get_mod() - 1) / (M << 1));
for (int i = 0; i < M; i++) b[i] *= r, r *= zeta;
ntt(b);
copy(begin(b), end(b), back_inserter(a));
}
};
#pragma once
namespace ArbitraryNTT {
using i64 = int64_t;
using u128 = __uint128_t;
constexpr int32_t m0 = 167772161;
constexpr int32_t m1 = 469762049;
constexpr int32_t m2 = 754974721;
using mint0 = LazyMontgomeryModInt<m0>;
using mint1 = LazyMontgomeryModInt<m1>;
using mint2 = LazyMontgomeryModInt<m2>;
constexpr int r01 = mint1(m0).inverse().get();
constexpr int r02 = mint2(m0).inverse().get();
constexpr int r12 = mint2(m1).inverse().get();
constexpr int r02r12 = i64(r02) * r12 % m2;
constexpr i64 w1 = m0;
constexpr i64 w2 = i64(m0) * m1;
template <typename T, typename submint>
vector<submint> mul(const vector<T> &a, const vector<T> &b) {
static NTT<submint> ntt;
vector<submint> s(a.size()), t(b.size());
for (int i = 0; i < (int)a.size(); ++i) s[i] = i64(a[i] % submint::get_mod());
for (int i = 0; i < (int)b.size(); ++i) t[i] = i64(b[i] % submint::get_mod());
return ntt.multiply(s, t);
}
template <typename T>
vector<int> multiply(const vector<T> &s, const vector<T> &t, int mod) {
auto d0 = mul<T, mint0>(s, t);
auto d1 = mul<T, mint1>(s, t);
auto d2 = mul<T, mint2>(s, t);
int n = d0.size();
vector<int> ret(n);
const int W1 = w1 % mod;
const int W2 = w2 % mod;
for (int i = 0; i < n; i++) {
int n1 = d1[i].get(), n2 = d2[i].get(), a = d0[i].get();
int b = i64(n1 + m1 - a) * r01 % m1;
int c = (i64(n2 + m2 - a) * r02r12 + i64(m2 - b) * r12) % m2;
ret[i] = (i64(a) + i64(b) * W1 + i64(c) * W2) % mod;
}
return ret;
}
template <typename mint>
vector<mint> multiply(const vector<mint> &a, const vector<mint> &b) {
if (a.size() == 0 && b.size() == 0) return {};
if (min<int>(a.size(), b.size()) < 128) {
vector<mint> ret(a.size() + b.size() - 1);
for (int i = 0; i < (int)a.size(); ++i)
for (int j = 0; j < (int)b.size(); ++j) ret[i + j] += a[i] * b[j];
return ret;
}
vector<int> s(a.size()), t(b.size());
for (int i = 0; i < (int)a.size(); ++i) s[i] = a[i].get();
for (int i = 0; i < (int)b.size(); ++i) t[i] = b[i].get();
vector<int> u = multiply<int>(s, t, mint::get_mod());
vector<mint> ret(u.size());
for (int i = 0; i < (int)u.size(); ++i) ret[i] = mint(u[i]);
return ret;
}
template <typename T>
vector<u128> multiply_u128(const vector<T> &s, const vector<T> &t) {
if (s.size() == 0 && t.size() == 0) return {};
if (min<int>(s.size(), t.size()) < 128) {
vector<u128> ret(s.size() + t.size() - 1);
for (int i = 0; i < (int)s.size(); ++i)
for (int j = 0; j < (int)t.size(); ++j) ret[i + j] += i64(s[i]) * t[j];
return ret;
}
auto d0 = mul<T, mint0>(s, t);
auto d1 = mul<T, mint1>(s, t);
auto d2 = mul<T, mint2>(s, t);
int n = d0.size();
vector<u128> ret(n);
for (int i = 0; i < n; i++) {
i64 n1 = d1[i].get(), n2 = d2[i].get();
i64 a = d0[i].get();
i64 b = (n1 + m1 - a) * r01 % m1;
i64 c = ((n2 + m2 - a) * r02r12 + (m2 - b) * r12) % m2;
ret[i] = a + b * w1 + u128(c) * w2;
}
return ret;
}
} // namespace ArbitraryNTT
namespace MultiPrecisionIntegerImpl {
struct TENS {
static constexpr int offset = 30;
constexpr TENS() : _tend() {
_tend[offset] = 1;
for (int i = 1; i <= offset; i++) {
_tend[offset + i] = _tend[offset + i - 1] * 10.0;
_tend[offset - i] = 1.0 / _tend[offset + i];
}
}
long double ten_ld(int n) const {
assert(-offset <= n and n <= offset);
return _tend[n + offset];
}
private:
long double _tend[offset * 2 + 1];
};
} // namespace MultiPrecisionIntegerImpl
// 0 は neg=false, dat={} として扱う
struct MultiPrecisionInteger {
using M = MultiPrecisionInteger;
inline constexpr static MultiPrecisionIntegerImpl::TENS tens = {};
static constexpr int D = 1000000000;
static constexpr int logD = 9;
bool neg;
vector<int> dat;
MultiPrecisionInteger() : neg(false), dat() {}
MultiPrecisionInteger(bool n, const vector<int>& d) : neg(n), dat(d) {}
template <typename I,
enable_if_t<internal::is_broadly_integral_v<I>>* = nullptr>
MultiPrecisionInteger(I x) : neg(false) {
if constexpr (internal::is_broadly_signed_v<I>) {
if (x < 0) neg = true, x = -x;
}
while (x) dat.push_back(x % D), x /= D;
}
MultiPrecisionInteger(const string& S) : neg(false) {
assert(!S.empty());
if (S.size() == 1u && S[0] == '0') return;
int l = 0;
if (S[0] == '-') ++l, neg = true;
for (int ie = S.size(); l < ie; ie -= logD) {
int is = max(l, ie - logD);
long long x = 0;
for (int i = is; i < ie; i++) x = x * 10 + S[i] - '0';
dat.push_back(x);
}
while(!dat.empty() and dat.back() == 0) dat.pop_back();
}
friend M operator+(const M& lhs, const M& rhs) {
if (lhs.neg == rhs.neg) return {lhs.neg, _add(lhs.dat, rhs.dat)};
if (_leq(lhs.dat, rhs.dat)) {
// |l| <= |r|
auto c = _sub(rhs.dat, lhs.dat);
bool n = _is_zero(c) ? false : rhs.neg;
return {n, c};
}
auto c = _sub(lhs.dat, rhs.dat);
bool n = _is_zero(c) ? false : lhs.neg;
return {n, c};
}
friend M operator-(const M& lhs, const M& rhs) { return lhs + (-rhs); }
friend M operator*(const M& lhs, const M& rhs) {
auto c = _mul(lhs.dat, rhs.dat);
bool n = _is_zero(c) ? false : (lhs.neg ^ rhs.neg);
return {n, c};
}
friend pair<M, M> divmod(const M& lhs, const M& rhs) {
auto dm = _divmod_newton(lhs.dat, rhs.dat);
bool dn = _is_zero(dm.first) ? false : lhs.neg != rhs.neg;
bool mn = _is_zero(dm.second) ? false : lhs.neg;
return {M{dn, dm.first}, M{mn, dm.second}};
}
friend M operator/(const M& lhs, const M& rhs) {
return divmod(lhs, rhs).first;
}
friend M operator%(const M& lhs, const M& rhs) {
return divmod(lhs, rhs).second;
}
M& operator+=(const M& rhs) { return (*this) = (*this) + rhs; }
M& operator-=(const M& rhs) { return (*this) = (*this) - rhs; }
M& operator*=(const M& rhs) { return (*this) = (*this) * rhs; }
M& operator/=(const M& rhs) { return (*this) = (*this) / rhs; }
M& operator%=(const M& rhs) { return (*this) = (*this) % rhs; }
M operator-() const {
if (is_zero()) return *this;
return {!neg, dat};
}
M operator+() const { return *this; }
friend M abs(const M& m) { return {false, m.dat}; }
bool is_zero() const { return _is_zero(dat); }
friend bool operator==(const M& lhs, const M& rhs) {
return lhs.neg == rhs.neg && lhs.dat == rhs.dat;
}
friend bool operator!=(const M& lhs, const M& rhs) {
return lhs.neg != rhs.neg || lhs.dat != rhs.dat;
}
friend bool operator<(const M& lhs, const M& rhs) {
if (lhs == rhs) return false;
return _neq_lt(lhs, rhs);
}
friend bool operator<=(const M& lhs, const M& rhs) {
if (lhs == rhs) return true;
return _neq_lt(lhs, rhs);
}
friend bool operator>(const M& lhs, const M& rhs) {
if (lhs == rhs) return false;
return _neq_lt(rhs, lhs);
}
friend bool operator>=(const M& lhs, const M& rhs) {
if (lhs == rhs) return true;
return _neq_lt(rhs, lhs);
}
// a * 10^b (1 <= |a| < 10) の形で渡す
// 相対誤差:10^{-16} ~ 10^{-19} 程度 (処理系依存)
pair<long double, int> dfp() const {
if (is_zero()) return {0, 0};
int l = max<int>(0, _size() - 3);
int b = logD * l;
string prefix{};
for (int i = _size() - 1; i >= l; i--) {
prefix += _itos(dat[i], i != _size() - 1);
}
b += prefix.size() - 1;
long double a = 0;
for (auto& c : prefix) a = a * 10.0 + (c - '0');
a *= tens.ten_ld(-((int)prefix.size()) + 1);
a = clamp<long double>(a, 1.0, nextafterl(10.0, 1.0));
if (neg) a = -a;
return {a, b};
}
string to_string() const {
if (is_zero()) return "0";
string res;
if (neg) res.push_back('-');
for (int i = _size() - 1; i >= 0; i--) {
res += _itos(dat[i], i != _size() - 1);
}
return res;
}
long double to_ld() const {
auto [a, b] = dfp();
if (-tens.offset <= b and b <= tens.offset) {
return a * tens.ten_ld(b);
}
return a * powl(10, b);
}
long long to_ll() const {
long long res = _to_ll(dat);
return neg ? -res : res;
}
__int128_t to_i128() const {
__int128_t res = _to_i128(dat);
return neg ? -res : res;
}
friend istream& operator>>(istream& is, M& m) {
string s;
is >> s;
m = M{s};
return is;
}
friend ostream& operator<<(ostream& os, const M& m) {
return os << m.to_string();
}
// 内部の関数をテスト
static void _test_private_function(const M&, const M&);
private:
// size
int _size() const { return dat.size(); }
// a == b
static bool _eq(const vector<int>& a, const vector<int>& b) { return a == b; }
// a < b
static bool _lt(const vector<int>& a, const vector<int>& b) {
if (a.size() != b.size()) return a.size() < b.size();
for (int i = a.size() - 1; i >= 0; i--) {
if (a[i] != b[i]) return a[i] < b[i];
}
return false;
}
// a <= b
static bool _leq(const vector<int>& a, const vector<int>& b) {
return _eq(a, b) || _lt(a, b);
}
// a < b (s.t. a != b)
static bool _neq_lt(const M& lhs, const M& rhs) {
assert(lhs != rhs);
if (lhs.neg != rhs.neg) return lhs.neg;
bool f = _lt(lhs.dat, rhs.dat);
if (f) return !lhs.neg;
return lhs.neg;
}
// a == 0
static bool _is_zero(const vector<int>& a) { return a.empty(); }
// a == 1
static bool _is_one(const vector<int>& a) {
return (int)a.size() == 1 && a[0] == 1;
}
// 末尾 0 を削除
static void _shrink(vector<int>& a) {
while (a.size() && a.back() == 0) a.pop_back();
}
// 末尾 0 を削除
void _shrink() {
while (_size() && dat.back() == 0) dat.pop_back();
}
// a + b
static vector<int> _add(const vector<int>& a, const vector<int>& b) {
vector<int> c(max(a.size(), b.size()) + 1);
for (int i = 0; i < (int)a.size(); i++) c[i] += a[i];
for (int i = 0; i < (int)b.size(); i++) c[i] += b[i];
for (int i = 0; i < (int)c.size() - 1; i++) {
if (c[i] >= D) c[i] -= D, c[i + 1]++;
}
_shrink(c);
return c;
}
// a - b
static vector<int> _sub(const vector<int>& a, const vector<int>& b) {
assert(_leq(b, a));
vector<int> c{a};
int borrow = 0;
for (int i = 0; i < (int)a.size(); i++) {
if (i < (int)b.size()) borrow += b[i];
c[i] -= borrow;
borrow = 0;
if (c[i] < 0) c[i] += D, borrow = 1;
}
assert(borrow == 0);
_shrink(c);
return c;
}
// a * b (fft)
static vector<int> _mul_fft(const vector<int>& a, const vector<int>& b) {
if (a.empty() || b.empty()) return {};
auto m = ArbitraryNTT::multiply_u128(a, b);
vector<int> c;
c.reserve(m.size() + 3);
__uint128_t x = 0;
for (int i = 0;; i++) {
if (i >= (int)m.size() && x == 0) break;
if (i < (int)m.size()) x += m[i];
c.push_back(x % D);
x /= D;
}
_shrink(c);
return c;
}
// a * b (naive)
static vector<int> _mul_naive(const vector<int>& a, const vector<int>& b) {
if (a.empty() || b.empty()) return {};
vector<long long> prod(a.size() + b.size() - 1 + 1);
for (int i = 0; i < (int)a.size(); i++) {
for (int j = 0; j < (int)b.size(); j++) {
long long p = 1LL * a[i] * b[j];
prod[i + j] += p;
if (prod[i + j] >= (4LL * D * D)) {
prod[i + j] -= 4LL * D * D;
prod[i + j + 1] += 4LL * D;
}
}
}
vector<int> c(prod.size() + 1);
long long x = 0;
int i = 0;
for (; i < (int)prod.size(); i++) x += prod[i], c[i] = x % D, x /= D;
while (x) c[i] = x % D, x /= D, i++;
_shrink(c);
return c;
}
// a * b
static vector<int> _mul(const vector<int>& a, const vector<int>& b) {
if (_is_zero(a) || _is_zero(b)) return {};
if (_is_one(a)) return b;
if (_is_one(b)) return a;
if (min<int>(a.size(), b.size()) <= 128) {
return a.size() < b.size() ? _mul_naive(b, a) : _mul_naive(a, b);
}
return _mul_fft(a, b);
}
// 0 <= A < 1e18, 1 <= B < 1e9
static pair<vector<int>, vector<int>> _divmod_li(const vector<int>& a,
const vector<int>& b) {
assert(0 <= (int)a.size() && (int)a.size() <= 2);
assert((int)b.size() == 1);
long long va = _to_ll(a);
int vb = b[0];
return {_integer_to_vec(va / vb), _integer_to_vec(va % vb)};
}
// 0 <= A < 1e18, 1 <= B < 1e18
static pair<vector<int>, vector<int>> _divmod_ll(const vector<int>& a,
const vector<int>& b) {
assert(0 <= (int)a.size() && (int)a.size() <= 2);
assert(1 <= (int)b.size() && (int)b.size() <= 2);
long long va = _to_ll(a), vb = _to_ll(b);
return {_integer_to_vec(va / vb), _integer_to_vec(va % vb)};
}
// 1 <= B < 1e9
static pair<vector<int>, vector<int>> _divmod_1e9(const vector<int>& a,
const vector<int>& b) {
assert((int)b.size() == 1);
if (b[0] == 1) return {a, {}};
if ((int)a.size() <= 2) return _divmod_li(a, b);
vector<int> quo(a.size());
long long d = 0;
int b0 = b[0];
for (int i = a.size() - 1; i >= 0; i--) {
d = d * D + a[i];
assert(d < 1LL * D * b0);
int q = d / b0, r = d % b0;
quo[i] = q, d = r;
}
_shrink(quo);
return {quo, d ? vector<int>{int(d)} : vector<int>{}};
}
// 0 <= A, 1 <= B
static pair<vector<int>, vector<int>> _divmod_naive(const vector<int>& a,
const vector<int>& b) {
if (_is_zero(b)) {
cerr << "Divide by Zero Exception" << endl;
exit(1);
}
assert(1 <= (int)b.size());
if ((int)b.size() == 1) return _divmod_1e9(a, b);
if (max<int>(a.size(), b.size()) <= 2) return _divmod_ll(a, b);
if (_lt(a, b)) return {{}, a};
// B >= 1e9, A >= B
int norm = D / (b.back() + 1);
vector<int> x = _mul(a, {norm});
vector<int> y = _mul(b, {norm});
int yb = y.back();
vector<int> quo(x.size() - y.size() + 1);
vector<int> rem(x.end() - y.size(), x.end());
for (int i = quo.size() - 1; i >= 0; i--) {
if (rem.size() < y.size()) {
// do nothing
} else if (rem.size() == y.size()) {
if (_leq(y, rem)) {
quo[i] = 1, rem = _sub(rem, y);
}
} else {
assert(y.size() + 1 == rem.size());
long long rb = 1LL * rem[rem.size() - 1] * D + rem[rem.size() - 2];
int q = rb / yb;
vector<int> yq = _mul(y, {q});
// 真の商は q-2 以上 q+1 以下だが自信が無いので念のため while を回す
while (_lt(rem, yq)) q--, yq = _sub(yq, y);
rem = _sub(rem, yq);
while (_leq(y, rem)) q++, rem = _sub(rem, y);
quo[i] = q;
}
if (i) rem.insert(begin(rem), x[i - 1]);
}
_shrink(quo), _shrink(rem);
auto [q2, r2] = _divmod_1e9(rem, {norm});
assert(_is_zero(r2));
return {quo, q2};
}
// 0 <= A, 1 <= B
static pair<vector<int>, vector<int>> _divmod_dc(const vector<int>& a,
const vector<int>& b);
// 1 / a を 絶対誤差 B^{-deg} で求める
static vector<int> _calc_inv(const vector<int>& a, int deg) {
assert(!a.empty() && D / 2 <= a.back() and a.back() < D);
int k = deg, c = a.size();
while (k > 64) k = (k + 1) / 2;
vector<int> z(c + k + 1);
z.back() = 1;
z = _divmod_naive(z, a).first;
while (k < deg) {
vector<int> s = _mul(z, z);
s.insert(begin(s), 0);
int d = min(c, 2 * k + 1);
vector<int> t{end(a) - d, end(a)}, u = _mul(s, t);
u.erase(begin(u), begin(u) + d);
vector<int> w(k + 1), w2 = _add(z, z);
copy(begin(w2), end(w2), back_inserter(w));
z = _sub(w, u);
z.erase(begin(z));
k *= 2;
}
z.erase(begin(z), begin(z) + k - deg);
return z;
}
static pair<vector<int>, vector<int>> _divmod_newton(const vector<int>& a,
const vector<int>& b) {
if (_is_zero(b)) {
cerr << "Divide by Zero Exception" << endl;
exit(1);
}
if ((int)b.size() <= 64) return _divmod_naive(a, b);
if ((int)a.size() - (int)b.size() <= 64) return _divmod_naive(a, b);
int norm = D / (b.back() + 1);
vector<int> x = _mul(a, {norm});
vector<int> y = _mul(b, {norm});
int s = x.size(), t = y.size();
int deg = s - t + 2;
vector<int> z = _calc_inv(y, deg);
vector<int> q = _mul(x, z);
q.erase(begin(q), begin(q) + t + deg);
vector<int> yq = _mul(y, {q});
while (_lt(x, yq)) q = _sub(q, {1}), yq = _sub(yq, y);
vector<int> r = _sub(x, yq);
while (_leq(y, r)) q = _add(q, {1}), r = _sub(r, y);
_shrink(q), _shrink(r);
auto [q2, r2] = _divmod_1e9(r, {norm});
assert(_is_zero(r2));
return {q, q2};
}
// int -> string
// 先頭かどうかに応じて zero padding するかを決める
static string _itos(int x, bool zero_padding) {
assert(0 <= x && x < D);
string res;
for (int i = 0; i < logD; i++) {
res.push_back('0' + x % 10), x /= 10;
}
if (!zero_padding) {
while (res.size() && res.back() == '0') res.pop_back();
assert(!res.empty());
}
reverse(begin(res), end(res));
return res;
}
// convert ll to vec
template <typename I,
enable_if_t<internal::is_broadly_integral_v<I>>* = nullptr>
static vector<int> _integer_to_vec(I x) {
if constexpr (internal::is_broadly_signed_v<I>) {
assert(x >= 0);
}
vector<int> res;
while (x) res.push_back(x % D), x /= D;
return res;
}
static long long _to_ll(const vector<int>& a) {
long long res = 0;
for (int i = (int)a.size() - 1; i >= 0; i--) res = res * D + a[i];
return res;
}
static __int128_t _to_i128(const vector<int>& a) {
__int128_t res = 0;
for (int i = (int)a.size() - 1; i >= 0; i--) res = res * D + a[i];
return res;
}
static void _dump(const vector<int>& a, string s = "") {
if (!s.empty()) cerr << s << " : ";
cerr << "{ ";
for (int i = 0; i < (int)a.size(); i++) cerr << a[i] << ", ";
cerr << "}" << endl;
}
};
using bigint = MultiPrecisionInteger;
/**
* @brief 多倍長整数
*/
//有理数
bigint gcdd(bigint a,bigint b){
if(b==0) return a;
return gcdd(b,a%b);
}
bigint abss(bigint a){
if(a>=0) return a;
else return -a;
}
struct Rational{
bigint x,y;
Rational(bigint x=0,bigint y=1):x(x),y(y){}
Rational operator + (Rational p){
bigint z=y/gcdd(y,p.y)*p.y;
bigint nx=z/y*x+z/p.y*p.x,ny=z;
bigint g=gcdd(abss(nx),ny);
return Rational(nx/g,ny/g);
}
Rational operator - (Rational p){
bigint z=y/gcdd(y,p.y)*p.y;
bigint nx=z/y*x-z/p.y*p.x,ny=z;
bigint g=gcdd(abss(nx),ny);
return Rational(nx/g,ny/g);
}
Rational operator * (Rational p){
bigint nx=x*p.x,ny=y*p.y;
if(ny<0){
nx*=(-1);
ny*=(-1);
}
bigint g=gcdd(abss(nx),abss(ny));
return Rational(nx/g,ny/g);
}
Rational operator / (Rational p){
bigint nx=x*p.y,ny=y*p.x;
if(ny<0){
nx*=(-1);
ny*=(-1);
}
bigint g=gcdd(abss(nx),abss(ny));
return Rational(nx/g,ny/g);
}
bool operator < (const Rational &p)const{
return x*p.y<y*p.x;
}
bool operator == (const Rational &p)const{
return x*p.y==y*p.x;
}
};
int main(){
int Q;cin>>Q;
while(Q--){
ll N;cin>>N;
vii S;
vi use;
for(int i=0;i<N;i++){
ll a,b;cin>>a>>b;
use.pb(a);
S.pb(mp(a,b));
}
sort(all(S));
mkunique(use);
int l=0;
vector<pair<Rational,Rational>> X;
for(int i=0;i<si(use);i++){
int r=l;
while(r<N&&S[r].fi==use[i]) r++;
if(i==0||i==si(use)-1){
if(r-l>1){
cout<<"? "<<use[i]<<" "<<1<<endl;
cout.flush();
bigint a,b;cin>>a>>b;
X.pb(mp(Rational{a,b},Rational{use[i],1}));
}else{
X.pb(mp(Rational{0,1},Rational{use[i],1}));
}
}else{
if(r-l>1){
Rational A{use[i],1},B{use[i],1};
A=A-Rational{1,1000};
B=B+Rational{1,1000};
cout<<"? "<<A.x<<" "<<A.y<<endl;
bigint a,b;cin>>a>>b;
X.pb(mp(Rational{a,b},A));
cout<<"? "<<B.x<<" "<<B.y<<endl;
cin>>a>>b;
X.pb(mp(Rational{a,b},B));
}else{
cout<<"? "<<use[i]<<" "<<1<<endl;
cout.flush();
bigint a,b;cin>>a>>b;
X.pb(mp(Rational{a,b},Rational{use[i],1}));
X.pb(mp(Rational{a,b},Rational{use[i],1}));
}
}
l=r;
}
Rational ans={0,1};
for(int i=0;i+1<si(use);i++){
Rational a,b;
if(X[2*i].se.y==1){
a=X[2*i].fi;
}else{
a=X[2*i].fi-(X[2*i+1].fi-X[2*i].fi)/(X[2*i+1].se-X[2*i].se)*Rational{1,1000};
}
if(X[2*i+1].se.y==1){
b=X[2*i+1].fi;
}else{
b=X[2*i+1].fi+(X[2*i+1].fi-X[2*i].fi)/(X[2*i+1].se-X[2*i].se)*Rational{1,1000};
}
Rational su=a+b;
//cout<<su.x<<" "<<su.y<<endl;
su=su*Rational{use[i+1]-use[i],1};
ans=ans+su;
}
ans=ans*Rational{1,2};
cout<<"! "<<ans.x<<" "<<ans.y<<endl;
cout.flush();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3716kb
input:
2 4 3 0 1 3 1 1 0 0 999 500 1999 1000 3 0 0 999 1000 1000 999 1999 1000
output:
? 999 1000 ? 1001 1000 ! 3 1 ? 999 1 ! 1999 2
result:
ok correct! (2 test cases)
Test #2:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
9 4 1 1 1 3 3 0 0 0 2997 1000 1999 2000 4 0 0 1 3 1 1 3 0 999 1000 5997 2000 4 0 0 3 0 1 2 1 1 999 1000 1999 2000 4 0 0 3 0 1 2 1 1 999 500 1999 2000 4 0 0 3 0 1 1 1 2 999 1000 1999 1000 3 1000 0 0 0 0 1000 1000 1 4 0 0 1000 0 1000 1000 0 1000 1000 1 1000 1 5 0 1 1000 1000 1000 0 0 1000 1 0 999 1 10...
output:
? 999 1000 ? 1001 1000 ! 5 2 ? 999 1000 ? 1001 1000 ! 7 2 ? 999 1000 ? 1001 1000 ! 3 2 ? 999 1000 ? 1001 1000 ! 2 1 ? 999 1000 ? 1001 1000 ! 5 2 ? 0 1 ! 500000 1 ? 0 1 ? 1000 1 ! 1000000 1 ? 0 1 ? 1 1 ? 1000 1 ! 1999999 2 ? 999 1000 ? 1001 1000 ? 1999 1000 ? 2001 1000 ? 2999 1000 ? 3001 1000 ? 4 1 !...
result:
ok correct! (9 test cases)
Test #3:
score: 0
Accepted
time: 5ms
memory: 3668kb
input:
78 8 951 614 927 614 957 614 957 604 937 614 942 619 951 610 927 604 10 1 10 1 15 1 6001 1000 10 1 10 1 7 562 260 602 250 582 255 587 260 602 260 562 250 577 260 10 1 10 1 5 1 10 1 10 1 3 454 98 494 68 455 68 117 4 3 526 589 566 559 527 559 117 4 3 854 496 854 466 894 466 30 1 3 797 264 827 254 857 ...
output:
? 927 1 ? 937 1 ? 942 1 ? 950999 1000 ? 951001 1000 ? 957 1 ! 317 1 ? 562 1 ? 577 1 ? 582 1 ? 587 1 ? 602 1 ! 375 1 ? 455 1 ! 585 1 ? 527 1 ! 585 1 ? 854 1 ! 600 1 ? 827 1 ! 300 1 ? 719 1 ! 600 1 ? 162 1 ! 400 1 ? 742 1 ? 746999 1000 ? 747001 1000 ? 751999 1000 ? 752001 1000 ? 792 1 ! 275 1 ? 932 1 ...
result:
ok correct! (78 test cases)
Test #4:
score: 0
Accepted
time: 17ms
memory: 3728kb
input:
34 24 123 815 168 800 133 795 27 827 153 805 28 830 178 780 138 810 78 830 192 772 148 790 88 810 43 825 183 795 103 805 163 785 118 800 93 825 63 835 73 815 58 820 198 790 48 840 108 820 10 3 95 6 15 2 95 6 15 2 95 6 15 2 95 6 15 2 95 6 15 2 95 6 15 2 95 6 15 2 95 6 15 2 95 6 15 2 95 6 15 2 15 1 24...
output:
? 28 1 ? 43 1 ? 48 1 ? 58 1 ? 63 1 ? 73 1 ? 78 1 ? 88 1 ? 93 1 ? 103 1 ? 108 1 ? 118 1 ? 123 1 ? 133 1 ? 138 1 ? 148 1 ? 153 1 ? 163 1 ? 168 1 ? 178 1 ? 183 1 ? 192 1 ! 1925 1 ? 54 1 ? 69 1 ? 74 1 ? 84 1 ? 89 1 ? 99 1 ? 104 1 ? 114 1 ? 119 1 ? 129 1 ? 134 1 ? 144 1 ? 149 1 ? 159 1 ? 164 1 ? 174 1 ? ...
result:
ok correct! (34 test cases)
Test #5:
score: 0
Accepted
time: 17ms
memory: 3744kb
input:
47 50 227 745 183 763 230 745 208 936 223 745 220 936 232 937 183 759 183 751 226 745 207 762 207 754 207 748 224 745 207 756 207 764 207 758 230 936 232 745 231 936 222 745 221 745 228 745 183 755 224 936 208 747 183 767 183 757 207 750 231 745 183 761 225 936 183 765 229 745 227 936 183 749 207 76...
output:
? 183 1 ? 206999 1000 ? 207001 1000 ? 207999 1000 ? 208001 1000 ? 220 1 ? 220999 1000 ? 221001 1000 ? 221999 1000 ? 222001 1000 ? 222999 1000 ? 223001 1000 ? 223999 1000 ? 224001 1000 ? 224999 1000 ? 225001 1000 ? 225999 1000 ? 226001 1000 ? 226999 1000 ? 227001 1000 ? 227999 1000 ? 228001 1000 ? 22...
result:
ok correct! (47 test cases)
Test #6:
score: 0
Accepted
time: 4ms
memory: 3748kb
input:
6 200 359 161 391 193 374 252 387 189 378 252 362 165 395 197 446 252 358 161 377 252 384 252 382 252 352 155 397 199 444 247 412 252 395 252 401 252 391 252 419 252 421 252 401 203 431 233 444 252 434 237 385 252 450 252 421 223 367 252 428 252 379 252 419 221 402 252 430 252 387 252 353 252 396 19...
output:
? 350 1 ? 351999 1000 ? 352001 1000 ? 352999 1000 ? 353001 1000 ? 353999 1000 ? 354001 1000 ? 354999 1000 ? 355001 1000 ? 355999 1000 ? 356001 1000 ? 356999 1000 ? 357001 1000 ? 357999 1000 ? 358001 1000 ? 358999 1000 ? 359001 1000 ? 359999 1000 ? 360001 1000 ? 360999 1000 ? 361001 1000 ? 361999 100...
result:
ok correct! (6 test cases)
Test #7:
score: 0
Accepted
time: 11ms
memory: 3704kb
input:
30 57 482 166 584 167 538 167 506 167 618 166 526 168 563 166 629 168 547 168 475 167 583 167 582 167 546 168 471 167 628 168 593 166 634 167 521 166 557 167 539 167 476 167 470 168 505 167 580 168 465 166 514 167 653 167 617 167 570 167 562 166 619 166 472 167 660 166 520 166 491 167 558 167 635 16...
output:
? 465 1 ? 468999 1000 ? 469001 1000 ? 469999 1000 ? 470001 1000 ? 471 1 ? 472 1 ? 475 1 ? 476 1 ? 482 1 ? 483 1 ? 490 1 ? 491 1 ? 505 1 ? 506 1 ? 514 1 ? 515 1 ? 520 1 ? 521 1 ? 526 1 ? 527 1 ? 538 1 ? 539 1 ? 546 1 ? 547 1 ? 557 1 ? 558 1 ? 562 1 ? 563 1 ? 570 1 ? 571 1 ? 579 1 ? 580 1 ? 582 1 ? 58...
result:
ok correct! (30 test cases)
Test #8:
score: 0
Accepted
time: 18ms
memory: 3736kb
input:
12 20 69 340 411 520 513 767 826 881 199 805 622 48 945 965 677 968 388 519 825 72 122 508 448 348 982 932 838 965 448 182 716 450 8 857 346 351 792 433 224 449 117548 223 47161313 84517 7549481525 24425413 73924992225 225575873 42227227870624 157226383481 1076496201908 3834789841 6882360591313 2278...
output:
? 69 1 ? 122 1 ? 199 1 ? 224 1 ? 346 1 ? 388 1 ? 411 1 ? 447999 1000 ? 448001 1000 ? 513 1 ? 622 1 ? 677 1 ? 716 1 ? 792 1 ? 825 1 ? 826 1 ? 838 1 ? 945 1 ! 566163 2 ? 100 1 ? 119 1 ? 123 1 ? 141 1 ? 152 1 ? 160 1 ? 178 1 ? 180 1 ? 183 1 ? 184 1 ? 186 1 ? 204 1 ? 213 1 ? 221 1 ? 242 1 ? 274 1 ? 279 ...
result:
ok correct! (12 test cases)
Test #9:
score: 0
Accepted
time: 7ms
memory: 3720kb
input:
47 100 336 60 627 234 594 968 147 351 511 151 134 433 343 690 97 981 734 678 968 833 962 4 34 977 889 172 227 46 138 713 578 695 193 895 835 513 562 707 504 571 490 366 108 605 440 145 141 743 155 214 143 633 839 995 493 751 480 254 317 587 491 988 537 549 915 465 403 233 343 112 12 236 965 847 710 ...
output:
? 7 1 ? 12 1 ? 33 1 ? 33999 1000 ? 34001 1000 ? 38 1 ? 43 1 ? 97 1 ? 104 1 ? 108 1 ? 132 1 ? 134 1 ? 138 1 ? 140999 1000 ? 141001 1000 ? 143 1 ? 147 1 ? 155 1 ? 193 1 ? 227 1 ? 235 1 ? 252 1 ? 253 1 ? 268 1 ? 291 1 ? 295 1 ? 315 1 ? 317 1 ? 332 1 ? 336 1 ? 342999 1000 ? 343001 1000 ? 352 1 ? 355 1 ?...
result:
ok correct! (47 test cases)
Test #10:
score: 0
Accepted
time: 3ms
memory: 3932kb
input:
5 183 529 552 529 553 526 556 534 552 536 555 528 547 526 553 540 545 535 552 534 555 530 552 535 550 537 550 526 550 534 547 535 556 526 551 530 549 530 551 525 560 525 558 528 551 535 558 537 547 538 560 531 553 533 547 526 558 530 546 531 558 535 554 527 560 534 549 532 557 534 553 540 557 527 54...
output:
? 524 1 ? 524999 1000 ? 525001 1000 ? 525999 1000 ? 526001 1000 ? 526999 1000 ? 527001 1000 ? 527999 1000 ? 528001 1000 ? 528999 1000 ? 529001 1000 ? 529999 1000 ? 530001 1000 ? 530999 1000 ? 531001 1000 ? 531999 1000 ? 532001 1000 ? 532999 1000 ? 533001 1000 ? 533999 1000 ? 534001 1000 ? 534999 100...
result:
ok correct! (5 test cases)
Test #11:
score: 0
Accepted
time: 3ms
memory: 3592kb
input:
5 195 548 38 540 29 547 28 544 29 542 33 549 37 541 26 546 33 543 38 545 33 545 26 546 24 539 35 542 26 545 35 536 28 541 28 538 33 539 31 540 24 540 25 538 32 535 36 544 34 542 38 542 28 547 32 539 25 550 25 536 30 545 30 543 23 537 34 534 36 541 29 540 37 544 26 535 29 548 36 539 27 546 32 549 29 ...
output:
? 534 1 ? 534999 1000 ? 535001 1000 ? 535999 1000 ? 536001 1000 ? 536999 1000 ? 537001 1000 ? 537999 1000 ? 538001 1000 ? 538999 1000 ? 539001 1000 ? 539999 1000 ? 540001 1000 ? 540999 1000 ? 541001 1000 ? 541999 1000 ? 542001 1000 ? 542999 1000 ? 543001 1000 ? 543999 1000 ? 544001 1000 ? 544999 100...
result:
ok correct! (5 test cases)
Test #12:
score: 0
Accepted
time: 1ms
memory: 3748kb
input:
6 191 562 409 558 414 549 405 549 414 550 403 562 398 553 412 554 410 563 410 548 401 548 413 548 412 552 407 554 408 556 410 552 403 552 412 549 411 563 414 558 404 559 402 550 411 560 403 556 408 562 404 548 414 562 412 559 403 551 400 562 399 547 407 560 406 548 410 562 402 553 414 558 408 553 40...
output:
? 547 1 ? 547999 1000 ? 548001 1000 ? 548999 1000 ? 549001 1000 ? 549999 1000 ? 550001 1000 ? 550999 1000 ? 551001 1000 ? 551999 1000 ? 552001 1000 ? 552999 1000 ? 553001 1000 ? 553999 1000 ? 554001 1000 ? 554999 1000 ? 555001 1000 ? 555999 1000 ? 556001 1000 ? 556999 1000 ? 557001 1000 ? 557999 100...
result:
ok correct! (6 test cases)
Test #13:
score: 0
Accepted
time: 12ms
memory: 3892kb
input:
100 4 432 383 378 564 879 428 360 237 55425 173 20674 173 9 403 900 991 82 251 377 546 339 621 826 476 904 167 637 184 206 569 464 127483 2814 5064736823 19572978 1686763227553 5774028510 48297246268163 95848873266 57736816891 86762722 82744792 117015 554528 807 7 750 849 303 479 508 268 604 865 208...
output:
? 378 1 ? 432 1 ! 41469 1 ? 184 1 ? 251 1 ? 403 1 ? 476 1 ? 546 1 ? 569 1 ? 621 1 ! 301579 1 ? 303 1 ? 508 1 ? 604 1 ? 750 1 ? 791 1 ! 324517 1 ? 228 1 ? 322 1 ! 30319 1 ? 90 1 ? 146 1 ? 179 1 ? 182 1 ? 296 1 ? 314 1 ? 318 1 ? 326 1 ? 412 1 ? 445 1 ? 446 1 ? 451 1 ? 469 1 ? 500 1 ? 546 1 ? 623 1 ? 6...
result:
ok correct! (100 test cases)
Test #14:
score: 0
Accepted
time: 35ms
memory: 3960kb
input:
10 9 243 378 841 782 148 442 136 745 35 882 560 780 385 85 443 884 953 473 28049 204 89873 204 25756 51 81469 102 19903 35 14729 199 87053 393 17 556 767 642 508 179 298 744 572 69 787 592 841 213 929 11 152 949 762 520 41 523 827 371 990 757 661 981 146 419 519 350 27 957 818 340721 4746 3276445 40...
output:
? 136 1 ? 148 1 ? 243 1 ? 385 1 ? 443 1 ? 560 1 ? 841 1 ! 558135 2 ? 69 1 ? 179 1 ? 213 1 ? 350 1 ? 371 1 ? 419 1 ? 520 1 ? 523 1 ? 556 1 ? 592 1 ? 642 1 ? 744 1 ? 757 1 ? 949 1 ? 957 1 ! 504173 1 ? 1 1 ? 6 1 ? 11 1 ? 22 1 ? 35 1 ? 41 1 ? 56 1 ? 72 1 ? 81 1 ? 92 1 ? 96 1 ? 101 1 ? 113 1 ? 114 1 ? 13...
result:
ok correct! (10 test cases)
Test #15:
score: 0
Accepted
time: 46ms
memory: 3880kb
input:
1 999 418 860 741 570 398 686 307 967 125 323 595 219 949 428 230 577 401 658 192 266 63 130 526 928 958 736 574 300 248 530 360 734 982 201 542 337 110 305 344 477 855 188 331 887 1000 410 267 449 231 634 726 482 661 708 625 719 345 3 976 556 974 446 989 64 688 137 677 862 563 762 412 960 434 947 3...
output:
? 0 1 ? 1 1 ? 2 1 ? 2999 1000 ? 3001 1000 ? 5 1 ? 6 1 ? 7999 1000 ? 8001 1000 ? 8999 1000 ? 9001 1000 ? 10 1 ? 11 1 ? 12 1 ? 13 1 ? 14 1 ? 16 1 ? 18 1 ? 19 1 ? 21999 1000 ? 22001 1000 ? 24 1 ? 25 1 ? 26 1 ? 28 1 ? 28999 1000 ? 29001 1000 ? 30999 1000 ? 31001 1000 ? 35999 1000 ? 36001 1000 ? 38 1 ? 3...
result:
ok correct! (1 test case)
Test #16:
score: 0
Accepted
time: 14ms
memory: 3916kb
input:
100 8 965 686 363 95 657 171 462 37 13 372 46 611 839 946 375 291 92791 350 515383 793 363975 793 45734 61 42585 61 10355 22 7 384 464 164 845 825 46 292 87 14 238 329 616 458 275 95698 139 95758 165 6914 13 4993 13 2610 13 8 334 854 907 218 140 497 950 599 247 987 849 255 492 689 53 952 119329 281 ...
output:
? 46 1 ? 363 1 ? 375 1 ? 462 1 ? 657 1 ? 839 1 ! 485819 1 ? 164 1 ? 292 1 ? 329 1 ? 384 1 ? 458 1 ! 474169 2 ? 140 1 ? 247 1 ? 334 1 ? 492 1 ? 849 1 ? 907 1 ! 364259 1 ? 44 1 ? 92 1 ? 99 1 ? 102 1 ? 219 1 ? 277 1 ? 434 1 ? 447 1 ? 631 1 ? 730 1 ? 741 1 ? 800 1 ? 803 1 ? 855 1 ! 672417 2 ? 252 1 ? 30...
result:
ok correct! (100 test cases)
Test #17:
score: 0
Accepted
time: 14ms
memory: 3852kb
input:
10 127 381 549 297 504 961 486 673 617 737 870 639 562 438 661 210 337 884 488 670 963 887 728 271 264 992 860 260 650 187 121 685 794 448 797 572 932 352 480 927 172 880 121 470 933 485 258 273 288 698 340 539 671 149 299 829 56 371 971 576 105 862 199 926 209 585 837 378 125 492 202 359 453 274 57...
output:
? 28 1 ? 41 1 ? 42 1 ? 54 1 ? 60 1 ? 67 1 ? 85 1 ? 91 1 ? 94 1 ? 95 1 ? 133 1 ? 138 1 ? 147 1 ? 149 1 ? 152 1 ? 160 1 ? 170 1 ? 185 1 ? 187 1 ? 210 1 ? 213 1 ? 222 1 ? 244 1 ? 247 1 ? 260 1 ? 268 1 ? 271 1 ? 273 1 ? 274 1 ? 275 1 ? 284 1 ? 297 1 ? 313 1 ? 325 1 ? 333 1 ? 334 1 ? 341 1 ? 344 1 ? 352 ...
result:
ok correct! (10 test cases)
Test #18:
score: 0
Accepted
time: 31ms
memory: 3968kb
input:
1 997 31 967 561 563 77 899 278 232 905 414 944 891 688 470 35 589 72 942 912 459 797 102 496 946 508 427 925 744 217 287 86 2 702 732 965 675 901 433 59 200 732 623 139 180 671 907 195 275 2 631 632 574 318 798 293 785 987 60 638 532 627 641 762 432 792 837 452 842 205 700 50 874 92 920 45 76 701 8...
output:
? 1 1 ? 2 1 ? 3 1 ? 4 1 ? 5 1 ? 6 1 ? 7 1 ? 8 1 ? 9 1 ? 10 1 ? 11 1 ? 12 1 ? 13 1 ? 14 1 ? 15 1 ? 16 1 ? 17 1 ? 18 1 ? 19 1 ? 20 1 ? 21 1 ? 22 1 ? 23 1 ? 24 1 ? 25 1 ? 26 1 ? 27 1 ? 28 1 ? 29 1 ? 30 1 ? 31 1 ? 32 1 ? 33 1 ? 34 1 ? 35 1 ? 36 1 ? 37 1 ? 38 1 ? 39 1 ? 40 1 ? 41 1 ? 42 1 ? 43 1 ? 44 1 ?...
result:
ok correct! (1 test case)
Test #19:
score: 0
Accepted
time: 13ms
memory: 3632kb
input:
100 22 440 908 780 215 694 883 610 182 854 925 209 611 697 442 555 903 411 296 641 308 957 488 655 836 474 34 736 125 2 734 740 68 204 1000 536 750 584 558 96 296 518 344 761 693 469436 5037 86355113 277035 107224476167 332586540 876958338859 1648151076 505945614769 921273210 9254733032 17060615 508...
output:
? 96 1 ? 204 1 ? 209 1 ? 411 1 ? 440 1 ? 474 1 ? 518 1 ? 536 1 ? 555 1 ? 584 1 ? 610 1 ? 641 1 ? 655 1 ? 694 1 ? 697 1 ? 736 1 ? 740 1 ? 761 1 ? 780 1 ? 854 1 ! 845077 2 ? 283 1 ? 534 1 ? 603 1 ? 727 1 ! 136715 1 ? 75 1 ? 96 1 ? 146 1 ? 206 1 ? 224 1 ? 250 1 ? 284 1 ? 332 1 ? 410 1 ? 454 1 ? 676 1 ?...
result:
ok correct! (100 test cases)
Test #20:
score: 0
Accepted
time: 36ms
memory: 3804kb
input:
10 215 866 948 174 934 755 317 949 514 727 601 975 939 354 571 564 669 827 916 716 597 924 608 878 628 78 982 402 504 516 660 465 345 357 556 741 143 967 133 414 82 297 81 785 123 48 119 338 647 95 452 958 680 441 817 270 30 587 615 137 446 836 389 358 173 495 398 94 140 922 411 533 933 444 470 352 ...
output:
? 7 1 ? 14 1 ? 25 1 ? 36 1 ? 39 1 ? 43 1 ? 48 1 ? 49 1 ? 57 1 ? 69 1 ? 75 1 ? 78 1 ? 80 1 ? 85 1 ? 91 1 ? 92 1 ? 93 1 ? 94 1 ? 95 1 ? 102 1 ? 105 1 ? 111 1 ? 113 1 ? 114 1 ? 115 1 ? 117 1 ? 122 1 ? 123 1 ? 133 1 ? 134 1 ? 137 1 ? 140 1 ? 148 1 ? 151 1 ? 165 1 ? 167 1 ? 173 1 ? 174 1 ? 187 1 ? 190 1 ...
result:
ok correct! (10 test cases)
Test #21:
score: 0
Accepted
time: 58ms
memory: 3956kb
input:
1 1000 903 972 368 25 864 957 138 863 388 590 405 404 399 134 629 850 884 984 423 555 213 440 749 211 706 435 140 139 506 853 180 993 280 110 365 362 406 645 490 961 238 159 232 914 267 94 830 951 622 933 631 436 771 112 825 149 38 82 572 322 411 147 329 161 511 500 748 217 906 209 800 887 990 938 2...
output:
? 1 1 ? 2 1 ? 3 1 ? 4 1 ? 5 1 ? 6 1 ? 7 1 ? 8 1 ? 9 1 ? 10 1 ? 11 1 ? 12 1 ? 13 1 ? 14 1 ? 15 1 ? 16 1 ? 17 1 ? 18 1 ? 19 1 ? 20 1 ? 21 1 ? 22 1 ? 23 1 ? 24 1 ? 25 1 ? 26 1 ? 27 1 ? 28 1 ? 29 1 ? 30 1 ? 31 1 ? 32 1 ? 33 1 ? 34 1 ? 35 1 ? 36 1 ? 37 1 ? 38 1 ? 39 1 ? 40 1 ? 41 1 ? 42 1 ? 43 1 ? 44 1 ?...
result:
ok correct! (1 test case)
Test #22:
score: 0
Accepted
time: 16ms
memory: 3712kb
input:
100 9 387 4 620 974 157 175 47 935 157 893 978 751 978 543 387 610 620 842 39489641 55000 10321243 14375 8711257 14375 83448107537 137703000 104310049463 137703000 44113990419 70526000 208 1 38 678 102 793 490 747 91 930 210 409 297 585 383 922 937 573 945 770 164 963 160 741 69 63 8 678 201 656 412...
output:
? 156999 1000 ? 157001 1000 ? 386999 1000 ? 387001 1000 ? 619999 1000 ? 620001 1000 ? 978 1 ! 999589 2 ? 62999 1000 ? 63001 1000 ? 299999 1000 ? 300001 1000 ? 408999 1000 ? 409001 1000 ? 447999 1000 ? 448001 1000 ? 572999 1000 ? 573001 1000 ? 584999 1000 ? 585001 1000 ? 619 1 ? 632999 1000 ? 633001 ...
result:
ok correct! (100 test cases)
Test #23:
score: 0
Accepted
time: 49ms
memory: 3760kb
input:
10 265 711 246 635 106 363 296 298 516 148 548 20 264 717 993 976 382 212 151 338 427 107 918 15 648 573 138 733 967 828 489 444 793 758 988 740 898 227 906 592 734 625 702 728 912 824 323 821 483 403 571 188 872 817 384 637 685 76 375 500 685 725 299 960 630 805 902 450 638 289 548 510 181 788 975 ...
output:
? 5 1 ? 14999 1000 ? 15001 1000 ? 19999 1000 ? 20001 1000 ? 32999 1000 ? 33001 1000 ? 44999 1000 ? 45001 1000 ? 45999 1000 ? 46001 1000 ? 64999 1000 ? 65001 1000 ? 71999 1000 ? 72001 1000 ? 75999 1000 ? 76001 1000 ? 85999 1000 ? 86001 1000 ? 101999 1000 ? 102001 1000 ? 106999 1000 ? 107001 1000 ? 11...
result:
ok correct! (10 test cases)
Test #24:
score: 0
Accepted
time: 61ms
memory: 4088kb
input:
1 1000 223 436 120 685 243 500 776 484 710 948 428 611 155 840 733 209 193 469 730 884 889 899 271 55 5 495 435 573 757 224 477 493 240 827 515 664 764 929 495 443 397 912 685 352 236 819 691 276 538 348 101 934 592 69 741 90 720 693 85 849 130 885 271 752 531 849 247 41 513 181 298 458 189 475 712 ...
output:
? 2 1 ? 4999 1000 ? 5001 1000 ? 6999 1000 ? 7001 1000 ? 8999 1000 ? 9001 1000 ? 10999 1000 ? 11001 1000 ? 11999 1000 ? 12001 1000 ? 12999 1000 ? 13001 1000 ? 20999 1000 ? 21001 1000 ? 26999 1000 ? 27001 1000 ? 28999 1000 ? 29001 1000 ? 33999 1000 ? 34001 1000 ? 39999 1000 ? 40001 1000 ? 54999 1000 ?...
result:
ok correct! (1 test case)
Test #25:
score: 0
Accepted
time: 17ms
memory: 3672kb
input:
100 4 1 1000 0 0 517 791 377 129 376871 377 92713 129 9 168 332 1 0 262 723 263 932 291 27 258 311 71 543 0 1000 70 339 262932 263 74399631 76270 82331595 106778 9302862573 14567570 7300316613 14567570 40056563 86790 1165514 4785 7 494 277 1 1000 0 0 696 595 277 739 435 88 54 196 434912 435 12525677...
output:
? 1 1 ? 377 1 ! 747723 2 ? 1 1 ? 70 1 ? 71 1 ? 168 1 ? 258 1 ? 262 1 ? 263 1 ! 389725 2 ? 1 1 ? 54 1 ? 277 1 ? 435 1 ? 494 1 ! 362785 1 ? 985 1 ? 999 1 ! 116785 1 ? 117 1 ? 151 1 ? 264 1 ? 284 1 ? 292 1 ? 353 1 ? 464 1 ? 482 1 ? 491 1 ? 497 1 ? 610 1 ? 638 1 ? 665 1 ? 781 1 ? 857 1 ? 897 1 ? 999 1 !...
result:
ok correct! (100 test cases)
Test #26:
score: 0
Accepted
time: 203ms
memory: 3976kb
input:
10 9 496 52 825 592 0 0 1 1000 853 985 7 125 526 89 736 767 943 521 123987 124 8796609 8804 446131323 638716 2385697 3692 2044027 3692 1441987 8307 70740 767 17 407 499 296 912 463 41 575 862 293 242 219 602 717 283 29 11 371 775 999 1000 875 460 440 332 247 733 130 817 667 304 1000 0 56 683 457704 ...
output:
? 1 1 ? 7 1 ? 496 1 ? 526 1 ? 736 1 ? 825 1 ? 853 1 ! 1215909 2 ? 56 1 ? 130 1 ? 219 1 ? 247 1 ? 293 1 ? 296 1 ? 371 1 ? 407 1 ? 440 1 ? 463 1 ? 575 1 ? 667 1 ? 717 1 ? 875 1 ? 999 1 ! 1163041 2 ? 1 1 ? 3 1 ? 12 1 ? 14 1 ? 17 1 ? 31 1 ? 36 1 ? 37 1 ? 50 1 ? 51 1 ? 53 1 ? 56 1 ? 59999 1000 ? 60001 10...
result:
ok correct! (10 test cases)
Test #27:
score: -100
Time Limit Exceeded
input:
1 1000 665 114 208 428 52 111 52 950 170 733 664 624 466 464 727 67 144 115 435 721 594 778 227 293 965 378 796 636 454 64 999 1000 594 494 920 647 486 735 862 14 900 530 675 978 595 493 738 63 97 44 566 458 173 250 832 229 712 694 487 446 697 463 908 497 756 590 306 292 537 200 926 106 361 118 83 6...
output:
? 8 1 ? 8999 1000 ? 9001 1000 ? 9999 1000 ? 10001 1000 ? 10999 1000 ? 11001 1000 ? 11999 1000 ? 12001 1000 ? 13 1 ? 14 1 ? 15999 1000 ? 16001 1000 ? 18 1 ? 18999 1000 ? 19001 1000 ? 19999 1000 ? 20001 1000 ? 23 1 ? 25 1 ? 25999 1000 ? 26001 1000 ? 27 1 ? 29 1 ? 29999 1000 ? 30001 1000 ? 32 1 ? 33999...