QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#881189#9804. Guess the PolygonUESTC_NLNSCompile Error//Python31.8kb2025-02-04 13:24:032025-02-04 13:24:04

Judging History

This is the latest submission verdict.

  • [2025-02-04 13:24:04]
  • Judged
  • [2025-02-04 13:24:03]
  • Submitted

answer

#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const int mod = 998244353;
void norm(int& x, int& y) {
    int d = __gcd(x, y);
    x /= d, y /= d;
}
int qpow(int x, ll y) {
    ll ans = 1;
    for (; y; y >>= 1, x = 1ll * x * x % mod)
        if (y & 1) ans = ans * x % mod;
    return ans;
}
int inv(int x) {
    return qpow(x, mod - 2);
}
int s2i(const string& a) {
    ll ans = 0;
    for (const auto u : a) ans = (ans * 10 + (u - '0')) % mod;
    return ans;
}
int query(int x, int y) {
    norm(x, y);
    cout << "? " << x << " " << y << endl;
    string sr, ss;
    cin >> sr >> ss;
    int r = s2i(sr), s = s2i(ss);
    return 1ll * r * inv(s) % mod;
}
void check(int x) {
    x = 2ll * x % mod;
    int y = 2;
    norm(x, y);
    cout << "! " << x << " " << y << endl;
}
void solve() {
    int n;
    cin >> n;
    vector<int> x(n);
    for (int i = 0, y; i < n; ++i) cin >> x[i] >> y;
    sort(x.begin(), x.end());
    bool f = 0;
    for (int i = 0; i < n - 1; ++i) f |= x[i] == x[i + 1];
    x.erase(unique(x.begin(), x.end()), x.end());
    ll ans = 0;
    if (f) {
        for (int i = 0; i < x.size() - 1; i++) {
            ans += 1ll * (x[i + 1] - x[i]) * query(x[i + 1] + x[i], 2);
        }
        check(ans % mod);
    } else {
        for (int i = 1, lst = 0; i < x.size(); ++i) {
            ll cur = i == x.size() - 1 ? 0 : query(x[i], 1);
            ans += (cur + lst) * (x[i] - x[i - 1]) % mod;
            lst = cur;
        }
        check(ans % mod * inv(2) % mod);
    }
}

int main() {
    assert(inv(mod - 1) == mod - 1);
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
    int t;
    cin >> t;
    while (t--) solve();
}
/*
2
3
1 2
1 3
2 4
3
1 2
2 3
3 4
*/

详细

  File "answer.code", line 14
    for (; y; y >>= 1, x = 1ll * x * x % mod)
                           ^
SyntaxError: invalid decimal literal