QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#795959#9804. Guess the Polygonucup-team4435#TL 166ms4564kbC++2021.2kb2024-12-01 05:08:542024-12-01 05:08:54

Judging History

This is the latest submission verdict.

  • [2024-12-01 05:08:54]
  • Judged
  • Verdict: TL
  • Time: 166ms
  • Memory: 4564kb
  • [2024-12-01 05:08:54]
  • Submitted

answer

#include "bits/stdc++.h"


#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define rep1n(i, n) for (int i = 1; i <= (n); ++i)
#define repr(i, n) for (int i = (n) - 1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define each(x, a) for (auto &x : a)
#define ar array
#define vec vector
#define range(i, n) rep(i, n)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;

using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vi>;

int Bit(int mask, int b) { return (mask >> b) & 1; }

template<class T>
bool ckmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool ckmax(T &a, const T &b) {
    if (b > a) {
        a = b;
        return true;
    }
    return false;
}

// [l, r)
template<typename T, typename F>
T FindFirstTrue(T l, T r, const F &predicat) {
    --l;
    while (r - l > 1) {
        T mid = l + (r - l) / 2;
        if (predicat(mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    return r;
}


template<typename T, typename F>
T FindLastFalse(T l, T r, const F &predicat) {
    return FindFirstTrue(l, r, predicat) - 1;
}

const int INFi = 2e9;
const ll INF = 2e18;

namespace FFT {
    template<typename T>
    struct complex {
        T x, y;

        complex() : x(0), y(0) {}
        complex(T x, T y) : x(x), y(y) {}

        complex operator*(const complex &c) const {
            return complex(x * c.x - y * c.y, x * c.y + y * c.x);
        }

        complex operator+(const complex &c) const {
            return complex(x + c.x, y + c.y);
        }

        complex operator-(const complex &c) const {
            return complex(x - c.x, y - c.y);
        }

        template<typename value_t>
        complex operator/(const value_t &value) const {
            return complex(x / value, y / value);
        }

        complex conj() const {
            return complex(x, -y);
        }
    };

    template<typename float_t = long double>
    void fft(std::vector<complex<float_t>> &a) {
        static std::vector<int> reversed_mask;
        static std::vector<complex<float_t>> roots = std::vector<complex<float_t>>(1);
        static const float_t PI = acosl(-1);

        if (a.empty())
            return;

        int n = int(a.size());
        assert((n & (n - 1)) == 0);

        if (int(reversed_mask.size()) != n) {
            int lg = std::__lg(n);
            reversed_mask.resize(n);
            for (int mask = 1; mask < n; mask++)
                reversed_mask[mask] = (reversed_mask[mask >> 1] >> 1) + ((mask & 1) << (lg - 1));
        }

        if (int(roots.size()) < n) {
            int prev_size = roots.size();
            roots.resize(n);
            for (int len = prev_size; len < n; len <<= 1)
                for (int i = 0; i < len; i++)
                    roots[len + i] = complex<float_t>(cosl(PI * i / len), sinl(PI * i / len));
        }

        for (int i = 0; i < n; i++)
            if (i < reversed_mask[i])
                std::swap(a[i], a[reversed_mask[i]]);

        for (int len = 1; len < n; len <<= 1)
            for (int i = 0; i < n; i += (len << 1))
                for (int j = 0; j < len; j++) {
                    complex<float_t> value = a[i + j + len] * roots[len + j];
                    a[i + j + len] = a[i + j] - value;
                    a[i + j] = a[i + j] + value;
                }
    }

    template<typename result_t, typename float_t = long double, typename T1, typename T2>
    std::vector<result_t> multiply(T1 a_begin, T1 a_end, T2 b_begin, T2 b_end) {
        static const float_t PI = acosl(-1);

        if (a_begin == a_end || b_begin == b_end)
            return {};

        static constexpr int BUBEN = 20;
        int n = std::distance(a_begin, a_end);
        int m = std::distance(b_begin, b_end);
        if (std::min(n, m) <= BUBEN) {
            vector<result_t> product(n + m - 1);
            for (int i = 0; a_begin != a_end; i++, a_begin++) {
                T2 iterator = b_begin;
                for (int j = 0; iterator != b_end; j++, iterator++)
                    product[i + j] += result_t(*a_begin) * result_t(*iterator);
            }
            return product;
        }

        int real_size = n + m - 1;
        int base = 2;
        while (base < real_size)
            base <<= 1;

        std::vector<complex<float_t>> res(base);
        for (int i = 0; a_begin != a_end; i++, a_begin++)
            res[i].x = *a_begin;

        for (int i = 0; b_begin != b_end; i++, b_begin++)
            res[i].y = *b_begin;

        fft<float_t>(res);
        complex<float_t> coeff(0, float_t(-0.25) / base);
        for (int i = 0; i <= (base >> 1); i++) {
            int j = (base - i) & (base - 1);
            complex<float_t> num = (res[j] * res[j] - (res[i] * res[i]).conj()) * coeff;
            res[j] = (res[i] * res[i] - (res[j] * res[j]).conj()) * coeff;
            res[i] = num;
        }
        // fft(product) == res

        for (int i = 0; i < (base >> 1); i++) {
            complex<float_t> a0 = (res[i] + res[i + (base >> 1)]);
            complex<float_t> a1 = (res[i] - res[i + (base >> 1)]) * complex<float_t>(cosl(PI * i / (base >> 1)), sinl(PI * i / (base >> 1)));
            res[i] = a0 + a1 * complex<float_t>(0, 1);
        }

        res.resize(base >> 1);
        fft<float_t>(res);
        std::vector<result_t> product(real_size);

        for (int i = 0; i < real_size; i++)
            product[i] = ((i & 1) ? res[i >> 1].y : res[i >> 1].x) + (std::is_integral<result_t>::value) * float_t(0.5);

        return product;
    }

    template<typename T>
    std::vector<T> normalize(std::vector<T> pol) {
        while (!pol.empty() && pol.back() == 0)
            pol.pop_back();

        return pol;
    }

    template<typename float_t = long double>
    void fft_2d(std::vector<std::vector<complex<float_t>>> &a, bool invert) {
        for (int rot : {0, 1}) {
            for (auto &v : a) {
                fft<float_t>(v);
                if (invert) {
                    std::reverse(v.begin() + 1, v.end());
                    for (auto &x : v)
                        x = x / v.size();
                }
            }

            for (int i = 0; i < int(a.size()); i++)
                for (int j = 0; j < i; j++)
                    std::swap(a[i][j], a[j][i]);
        }
    }

    template<typename result_t, typename float_t = long double, typename T1, typename T2>
    std::vector<std::vector<result_t>> multiply_2d(T1 a_begin, T1 a_end, T2 b_begin, T2 b_end) {
        if (a_begin == a_end || b_begin == b_end || (*a_begin).empty() || (*b_begin).empty())
            return {};

        int real_size_x = std::distance(a_begin, a_end) + std::distance(b_begin, b_end) - 1;
        int real_size_y = int((*a_begin).size() + (*b_begin).size()) - 1;
        int base = 2;
        while (base < std::max(real_size_x, real_size_y))
            base <<= 1;

        auto get = [&](auto a_begin, auto a_end) {
            std::vector<std::vector<complex<float_t>>> a(base, std::vector<complex<float_t>>(base));
            for (int i = 0; a_begin != a_end; i++, a_begin++)
                for (int j = 0; j < int((*a_begin).size()); j++)
                    a[i][j].x = (*a_begin)[j];

            return a;
        };

        auto a = get(a_begin, a_end), b = get(b_begin, b_end);
        fft_2d<float_t>(a, false);
        fft_2d<float_t>(b, false);

        for (int i = 0; i < base; i++)
            for (int j = 0; j < base; j++)
                a[i][j] = a[i][j] * b[i][j];

        fft_2d<float_t>(a, true);

        std::vector<std::vector<result_t>> product(real_size_x, std::vector<result_t>(real_size_y));
        for (int i = 0; i < real_size_x; i++)
            for (int j = 0; j < real_size_y; j++)
                product[i][j] = a[i][j].x + (std::is_integral<result_t>::value) * float_t(0.5);

        return product;
    }
} // namespace FFT

struct bigint {
    std::vector<int> digits;
    bool positive;

    bigint(long long value = 0) {
        *this = bigint(std::to_string(value));
    }

    template<typename T>
    bigint(const std::vector<T> &v) : digits(v.begin(), v.end()), positive(true) {
        normalize();
    }

    bigint(std::string s) : positive(true) {
        assert(!s.empty());
        if (s[0] == '-') {
            positive = false;
            s = s.substr(1);
        }

        for (auto c : s)
            assert(std::isdigit(c));

        std::reverse(s.begin(), s.end());
        digits.resize(s.size());
        for (int i = 0; i < int(s.size()); i++)
            digits[i] = s[i] - '0';
    }

    explicit operator std::string() const {
        std::string res;
        if (!positive)
            res += '-';

        for (int i = int(digits.size()) - 1; i >= 0; i--)
            res += '0' + digits[i];

        return res;
    }

    template<typename T>
    explicit operator T() const {
        static_assert(std::is_integral<T>::value);
        T coeff = 1, value = 0;
        for (auto &x : digits) {
            value += x * coeff;
            coeff *= 10;
        }
        return value;
    }

    void normalize() {
        for (int i = 0; i < int(digits.size()); i++) {
            if (i == int(digits.size()) - 1 && digits[i] < 0) {
                positive = !positive;
                for (auto &x : digits)
                    x *= -1;

                normalize();
                return;
            }

            int delta = digits[i] < 0 ? -((-digits[i] + 9) / 10) : digits[i] / 10;
            digits[i] -= delta * 10;

            if (delta) {
                if (i == int(digits.size()) - 1)
                    digits.push_back(delta);
                else
                    digits[i + 1] += delta;
            }
        }

        while (digits.size() > 1 && digits.back() == 0)
            digits.pop_back();

        if (digits.size() == 1 && digits[0] == 0)
            positive = true;

        if (digits.empty()) {
            digits = {0};
            positive = true;
        }
    }

    bool operator==(const bigint&) const = default;

    std::strong_ordering operator<=>(const bigint &x) const {
        if (!positive && x.positive)
            return std::strong_ordering::less;

        if (positive && !x.positive)
            return std::strong_ordering::greater;

        if (digits.size() != x.digits.size())
            return ((digits.size() < x.digits.size()) ^ (!positive))
                ? std::strong_ordering::less : std::strong_ordering::greater;

        for (int i = int(digits.size()) - 1; i >= 0; i--)
            if (digits[i] != x.digits[i])
                return (digits[i] < x.digits[i]) ^ (!positive)
                    ? std::strong_ordering::less : std::strong_ordering::greater;

        return std::strong_ordering::equal;
    }

    void to_positive() {
        if (!positive) {
            positive = true;
            for (auto &x : digits)
                x *= -1;
        }
    }

    bigint& operator+=(const bigint &x) {
        to_positive();
        if (digits.size() < x.digits.size())
            digits.resize(x.digits.size());

        for (int i = 0; i < int(x.digits.size()); i++)
            digits[i] += x.positive ? x.digits[i] : -x.digits[i];

        normalize();
        return *this;
    }

    bigint& operator-=(const bigint &x) {
        to_positive();
        if (digits.size() < x.digits.size())
            digits.resize(x.digits.size());

        for (int i = 0; i < int(x.digits.size()); i++)
            digits[i] -= x.positive ? x.digits[i] : -x.digits[i];

        normalize();
        return *this;
    }

    bigint& operator*=(const bigint &x) {
        positive = !(positive ^ x.positive);
        digits = FFT::multiply<int, double>(digits.begin(), digits.end(),
                                    x.digits.begin(), x.digits.end());
        normalize();
        return *this;
    }

    bigint shift_right(int shift) const {
        bigint res;
        if (shift >= int(digits.size())) {
            res.digits = {0};
            res.positive = true;
            return res;
        }

        res.digits = std::vector<int>(digits.begin() + shift, digits.end());
        return res;
    }

    bigint shift_left(int shift) const {
        bigint res;
        res.digits = std::vector<int>(shift, 0);
        res.digits.insert(res.digits.end(), digits.begin(), digits.end());
        return res;
    }

    std::pair<bigint, bigint> divide21(const bigint &a, const bigint &b, int n) const {
        if (a < b)
            return {bigint(0), a};

        if (n <= 9) {
            long long first = (long long) a, second = (long long) b;
            return {bigint(first / second), bigint(first % second)};
        }

        auto c = a.shift_right(n / 2);
        auto [coeff, rem] = divide32(c, b, n / 2);

        auto [coeff2, rem2] = divide32(rem.shift_left(n / 2)
            + bigint(std::vector<int>(a.digits.begin(), a.digits.begin() + std::min<int>(n / 2, a.digits.size()))),
        b, n / 2);

        return {coeff.shift_left(n / 2) + coeff2, rem2};
    }

    std::pair<bigint, bigint> divide32(const bigint &a, const bigint &b, int n) const {
        if (a < b)
            return {bigint(0), a};

        if (int(b.digits.size()) <= n)
            return divide21(a, b, n);

        if (n <= 6) {
            long long first = (long long) a, second = (long long) b;
            return {bigint(first / second), bigint(first % second)};
        }

        bigint coeff;
        int k = int(b.digits.size()) - n;
        auto a1 = a.shift_right(k), b1 = b.shift_right(k);

        if (b1.shift_left(n) < a1)
            coeff = bigint(1).shift_left(n);
        else
            coeff = divide21(a1, b1, n).first;

        auto current = a - b * coeff;
        while (current < 0) {
            current += b;
            coeff--;
        }

        return {coeff, current};
    }

    std::pair<bigint, bigint> divide(bigint a, bigint b) const {
        if (a < b)
            return {bigint(0), b};

        int size = 1;
        while (size < int(std::max(a.digits.size(), b.digits.size())))
            size <<= 1;

        auto [coeff, rem] = divide32(a, b, size);
        coeff.normalize();
        rem.normalize();
        return {coeff, rem};
    }

    bigint& operator/=(const bigint &x) {
        *this = divide(*this, x).first;
        positive = !(positive ^ x.positive);
        return *this;
    }

    bigint& operator%=(const bigint &x) {
        *this -= x * (*this / x);
        // *this = divide(*this, x).second;
        positive = true;
        return*this;
    }

    friend bigint operator+(const bigint &a, const bigint &b) {
        return bigint(a) += b;
    }

    friend bigint operator-(const bigint &a, const bigint &b) {
        return bigint(a) -= b;
    }

    friend bigint operator*(const bigint &a, const bigint &b) {
        return bigint(a) *= b;
    }

    friend bigint operator/(const bigint &a, const bigint &b) {
        return bigint(a) /= b;
    }

    friend bigint operator%(const bigint &a, const bigint &b) {
        return bigint(a) %= b;
    }

    bigint& operator++() {
        return *this += 1;
    }

    bigint& operator--() {
        return *this -= 1;
    }

    bigint operator++(int) {
        return *this += 1;
    }

    bigint operator--(int) {
        return *this -= 1;
    }

    friend std::istream& operator>>(std::istream &in, bigint &x) {
        std::string s;
        in >> s;
        x = bigint(s);
        return in;
    }

    friend std::ostream& operator<<(std::ostream &out, const bigint &x) {
        return out << std::string(x);
    }
};

bigint gcd(const bigint &a, const bigint &b) {
    if (b == bigint(0)) {
        return a;
    }
    return gcd(b, a % b);
}

template<class T>
class Frac {
public:
    T num;
    T den;
    void normalize() {
        bigint g = gcd(num, den);
        if (g < bigint(0)) {
            g = bigint(0) - g;
        }
        num /= g;
        den /= g;
    }

    Frac &operator+=(const Frac &rhs) {
        num = num * rhs.den + rhs.num * den;
        den *= rhs.den;
        return *this;
    }
    Frac &operator-=(const Frac &rhs) {
        num = num * rhs.den - rhs.num * den;
        den *= rhs.den;
        return *this;
    }
    Frac &operator*=(const Frac &rhs) {
        num *= rhs.num;
        den *= rhs.den;
        return *this;
    }
    Frac &operator/=(const Frac &rhs) {
        num *= rhs.den;
        den *= rhs.num;
        if (den < bigint(0)) {
            num = bigint(0) - num;
            den = bigint(0) - den;
        }
        return *this;
    }
    friend Frac operator+(Frac lhs, const Frac &rhs) {
        return lhs += rhs;
    }
    friend Frac operator-(Frac lhs, const Frac &rhs) {
        return lhs -= rhs;
    }
    friend Frac operator*(Frac lhs, const Frac &rhs) {
        return lhs *= rhs;
    }
    friend Frac operator/(Frac lhs, const Frac &rhs) {
        return lhs /= rhs;
    }
    friend Frac operator-(const Frac &a) {
        return Frac(bigint(0) - a.num, a.den);
    }
    friend bool operator==(const Frac &lhs, const Frac &rhs) {
        return lhs.num * rhs.den == rhs.num * lhs.den;
    }
    friend bool operator!=(const Frac &lhs, const Frac &rhs) {
        return lhs.num * rhs.den != rhs.num * lhs.den;
    }
    friend bool operator<(const Frac &lhs, const Frac &rhs) {
        return lhs.num * rhs.den < rhs.num * lhs.den;
    }
    friend bool operator>(const Frac &lhs, const Frac &rhs) {
        return lhs.num * rhs.den > rhs.num * lhs.den;
    }
    friend bool operator<=(const Frac &lhs, const Frac &rhs) {
        return lhs.num * rhs.den <= rhs.num * lhs.den;
    }
    friend bool operator>=(const Frac &lhs, const Frac &rhs) {
        return lhs.num * rhs.den >= rhs.num * lhs.den;
    }
};

using Fraction = Frac<bigint>;

Fraction ask(bigint p, bigint q) {
    cout << "? " << p << " " << q << endl;
    bigint r, s; cin >> r >> s;
    // return {0, 1};
    return {r, s};
}

void solve() {
    map<int, int> cnt;
    int n; cin >> n;
    rep(_, n) {
        int x, y; cin >> x >> y;
        cnt[x]++;
    }

    vector<pair<ll, ll>> a(all(cnt));
    if (a.size() <= 1) {
        cout << "! 0 1" << endl;
        return;
    }

    Fraction result = {bigint(0), bigint(1)};

    auto Add = [&] (Fraction len1, Fraction len2, Fraction xdiff, Fraction ladd, Fraction radd) {
        assert(xdiff.num != bigint(0));
        Fraction L = len1;
        if (ladd.num != bigint(0)) {
            auto df = len1 - len2;
            df /= xdiff;
            df *= (xdiff + ladd);
            L = df + len2;
        }
        Fraction R = len2;
        if (radd.num != bigint(0)) {
            auto df = len2 - len1;
            df /= xdiff;
            df *= (xdiff + radd);
            R = df + len1;
        }
        auto h = xdiff + ladd + radd;
        h *= Fraction{bigint(1), bigint(2)};
        auto res = (L + R) * h;
        result += res;
    };


    Fraction len1, ladd, prv;
    if (a[0].second == 1) {
        len1 = {bigint(0), bigint(1)};
        ladd = {bigint(0), bigint(1)};
        prv = {bigint(a[0].first), bigint(1)};
    } else {
        len1 = ask(bigint(a[0].first), bigint(1));
        ladd = {bigint(0), bigint(1)};
        prv = {bigint(a[0].first), bigint(1)};
    }

    for(int i = 1; i + 1 < (int)a.size(); ++i) {
        if (a[i].second == 1) {
            Fraction nx = {bigint(a[i].first), bigint(1)};
            Fraction cur = ask(bigint(a[i].first), bigint(1));

            Add(len1, cur, nx - prv, ladd, Fraction{bigint(0), bigint(1)});

            prv = nx;
            ladd = {bigint(0), bigint(1)};
            len1 = cur;
            continue;
        }
        Fraction radd = {bigint(1), bigint(4)};
        Fraction nx = {bigint(a[i].first), bigint(1)};
        Fraction rp = nx - radd;

        Fraction len2 = ask(rp.num, rp.den);

        Fraction xdiff = rp - prv;
        Add(len1, len2, xdiff, ladd, radd);

        prv = nx + radd;
        ladd = radd;
        len1 = ask(prv.num, prv.den);
    }
    {
        Fraction radd = {bigint(0), bigint(1)};
        Fraction nx = {a.back().first, 1};
        Fraction len2 = {bigint(0), bigint(1)};
        if (a.back().second > bigint(1)) {
            len2 = ask(nx.num, nx.den);
        }

        Add(len1, len2, nx - prv, ladd, radd);
    }
    result.normalize();
    cout << "! " << result.num << ' ' << result.den << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(12) << fixed;
    int t = 1;
    cin >> t;

    rep(i, t) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3644kb

input:

2
4
3 0
1 3
1 1
0 0
3 2
7 4
3
0 0
999 1000
1000 999
1999 1000

output:

? 3 4
? 5 4
! 3 1
? 999 1
! 1999 2

result:

ok correct! (2 test cases)

Test #2:

score: 0
Accepted
time: 1ms
memory: 3708kb

input:

9
4
1 1
1 3
3 0
0 0
9 4
7 8
4
0 0
1 3
1 1
3 0
3 4
21 8
4
0 0
3 0
1 2
1 1
3 4
7 8
4
0 0
3 0
1 2
1 1
3 2
7 8
4
0 0
3 0
1 1
1 2
3 4
7 4
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
1000 1
1000 1
9
4 1000
3 1
2 1000
3 1000
1 1
2 1
0 0
1 1...

output:

? 3 4
? 5 4
! 5 2
? 3 4
? 5 4
! 7 2
? 3 4
? 5 4
! 3 2
? 3 4
? 5 4
! 2 1
? 3 4
? 5 4
! 5 2
? 0 1
! 500000 1
? 0 1
? 1000 1
! 1000000 1
? 0 1
? 1 1
? 1000 1
! 1999999 2
? 3 4
? 5 4
? 7 4
? 9 4
? 11 4
? 13 4
? 4 1
! 4003 2

result:

ok correct! (9 test cases)

Test #3:

score: 0
Accepted
time: 10ms
memory: 4160kb

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
25 4
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 264
1...

output:

? 927 1
? 937 1
? 942 1
? 3803 4
? 3805 4
? 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
? 2987 4
? 2989 4
? 3007 4
? 3009 4
? 792 1
! 275 1
? 932 1
? 3747 4
? 3749 4
? 3767 4
? 3...

result:

ok correct! (78 test cases)

Test #4:

score: 0
Accepted
time: 41ms
memory: 4468kb

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: 48ms
memory: 4484kb

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
? 827 4
? 829 4
? 831 4
? 833 4
? 220 1
? 883 4
? 885 4
? 887 4
? 889 4
? 891 4
? 893 4
? 895 4
? 897 4
? 899 4
? 901 4
? 903 4
? 905 4
? 907 4
? 909 4
? 911 4
? 913 4
? 915 4
? 917 4
? 919 4
? 921 4
? 923 4
? 925 4
? 232 1
! 1600 1
? 1199 4
? 1201 4
? 1203 4
? 1205 4
? 1207 4
? 1209 4
? 121...

result:

ok correct! (47 test cases)

Test #6:

score: 0
Accepted
time: 4ms
memory: 4164kb

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
? 1407 4
? 1409 4
? 1411 4
? 1413 4
? 1415 4
? 1417 4
? 1419 4
? 1421 4
? 1423 4
? 1425 4
? 1427 4
? 1429 4
? 1431 4
? 1433 4
? 1435 4
? 1437 4
? 1439 4
? 1441 4
? 1443 4
? 1445 4
? 1447 4
? 1449 4
? 1451 4
? 1453 4
? 1455 4
? 1457 4
? 1459 4
? 1461 4
? 1463 4
? 1465 4
? 1467 4
? 1469 4
? 14...

result:

ok correct! (6 test cases)

Test #7:

score: 0
Accepted
time: 40ms
memory: 4372kb

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
? 1875 4
? 1877 4
? 1879 4
? 1881 4
? 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
? 583 1
? 584 1
? 592 1
...

result:

ok correct! (30 test cases)

Test #8:

score: 0
Accepted
time: 166ms
memory: 4508kb

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
? 1791 4
? 1793 4
? 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 1
? 280 1
...

result:

ok correct! (12 test cases)

Test #9:

score: 0
Accepted
time: 41ms
memory: 4564kb

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
? 135 4
? 137 4
? 38 1
? 43 1
? 97 1
? 104 1
? 108 1
? 132 1
? 134 1
? 138 1
? 563 4
? 565 4
? 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
? 1371 4
? 1373 4
? 352 1
? 355 1
? 360 1
? 398 1
? 403 1
? 405 1
?...

result:

ok correct! (47 test cases)

Test #10:

score: 0
Accepted
time: 2ms
memory: 4260kb

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
? 2099 4
? 2101 4
? 2103 4
? 2105 4
? 2107 4
? 2109 4
? 2111 4
? 2113 4
? 2115 4
? 2117 4
? 2119 4
? 2121 4
? 2123 4
? 2125 4
? 2127 4
? 2129 4
? 2131 4
? 2133 4
? 2135 4
? 2137 4
? 2139 4
? 2141 4
? 2143 4
? 2145 4
? 2147 4
? 2149 4
? 2151 4
? 2153 4
? 2155 4
? 2157 4
? 540 1
! 287 2
? 101 ...

result:

ok correct! (5 test cases)

Test #11:

score: 0
Accepted
time: 2ms
memory: 3808kb

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
? 2139 4
? 2141 4
? 2143 4
? 2145 4
? 2147 4
? 2149 4
? 2151 4
? 2153 4
? 2155 4
? 2157 4
? 2159 4
? 2161 4
? 2163 4
? 2165 4
? 2167 4
? 2169 4
? 2171 4
? 2173 4
? 2175 4
? 2177 4
? 2179 4
? 2181 4
? 2183 4
? 2185 4
? 2187 4
? 2189 4
? 2191 4
? 2193 4
? 2195 4
? 2197 4
? 550 1
! 287 2
? 962 ...

result:

ok correct! (5 test cases)

Test #12:

score: 0
Accepted
time: 0ms
memory: 3804kb

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
? 2191 4
? 2193 4
? 2195 4
? 2197 4
? 2199 4
? 2201 4
? 2203 4
? 2205 4
? 2207 4
? 2209 4
? 2211 4
? 2213 4
? 2215 4
? 2217 4
? 2219 4
? 2221 4
? 2223 4
? 2225 4
? 2227 4
? 2229 4
? 2231 4
? 2233 4
? 2235 4
? 2237 4
? 2239 4
? 2241 4
? 2243 4
? 2245 4
? 2247 4
? 2249 4
? 563 1
! 287 2
? 973 ...

result:

ok correct! (6 test cases)

Test #13:

score: 0
Accepted
time: 19ms
memory: 4244kb

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: -100
Time Limit Exceeded

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: