QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#821127#9804. Guess the PolygonSGColinTL 1ms3992kbC++202.1kb2024-12-19 13:34:422024-12-19 13:34:44

Judging History

This is the latest submission verdict.

  • [2024-12-19 13:34:44]
  • Judged
  • Verdict: TL
  • Time: 1ms
  • Memory: 3992kb
  • [2024-12-19 13:34:42]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tii;
typedef vector<int> vi;
typedef vector<pii> vii;

#define pb push_back
#define eb emplace_back
#define all(s) (s).begin(), (s).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)

inline int rd() {
    int x = 0;
    bool f = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) f |= (c == '-');
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    return f ? -x : x;
}

constexpr int mod = 998244353;
constexpr int inv2 = 499122177;

inline int fpow(int x, int t = mod - 2) {
    int res = 1;
    for (; t; t >>= 1, x = 1ll * x * x % mod)
        if (t & 1) res = 1ll * res * x % mod;
    return res;
}

inline void work() {
    int n = rd();
    vector<int> x;
    rep(i, 1, n) {x.eb(rd()); rd();}
    sort(all(x));
    x.erase(unique(all(x)), x.end());
    if (x.size() == n) { // all distinct -> ask on each x except boundary
        int lst = 0, ans = 0;
        rep(i, 1, n - 2) {
            printf("? %d 1\n", x[i]);
            fflush(stdout);
            int u = rd(), v = rd();
            int nw = 1ll * u * fpow(v) % mod;
            ans = (ans + 1ll * (x[i] - x[i - 1]) * (lst + nw) % mod) % mod;
            lst = nw;
        }
        ans = (ans + 1ll * (x[n - 1] - x[n - 2]) * lst % mod) % mod;
        if (ans & 1) printf("! %d 2\n", ans);
        else printf("! %d 1\n", ans / 2);
        fflush(stdout);
    } else {
        int ans = 0;
        rep(i, 1, x.size() - 1) {
            int p = x[i] + x[i - 1];
            if (p & 1) printf("? %d 2\n", p);
            else printf("? %d 1\n", p / 2);
            fflush(stdout);
            int u = rd(), v = rd();
            int nw = 1ll * u * fpow(v) % mod;
            ans = (ans + 1ll * (x[i] - x[i - 1]) * nw) % mod;
        }
        printf("! %d %d\n", ans, 1);
        fflush(stdout);
    }
}

int main() {
    per(t, rd(), 1) work();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

? 1 2
? 2 1
! 3 1
? 999 1
! 1999 2

result:

ok correct! (2 test cases)

Test #2:

score: -100
Time Limit Exceeded

input:

9
4
1 1
1 3
3 0
0 0
3 2
1 2

output:

? 1 2
? 2 1
! 499122179 1

result: