QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#794998#9804. Guess the Polygonucup-team296#Compile Error//C++203.1kb2024-11-30 17:23:022024-11-30 17:23:03

Judging History

This is the latest submission verdict.

  • [2024-11-30 17:23:03]
  • Judged
  • [2024-11-30 17:23:02]
  • Submitted

answer

#include <bits/stdc++.h>

#define long long long int
#define DEBUG
using namespace std;

// @author: pashka

struct rat {
    __int128_t p = 0, q = 1;

//    __int128_t mygcd()

    rat(__int128_t _p, __int128_t _q) {
        __int128_t d = gcd(_p, _q);
        p = _p / d;
        q = _q / d;
    }

    rat(long x) {
        p = x;
    }

    rat() {

    }

    rat operator + (rat x) const {
        return {p * x.q + x.p * q, q * x.q};
    }

    rat operator - (rat x) const {
        return {p * x.q - x.p * q, q * x.q};
    }

    rat operator * (rat x) const {
        return {p * x.p, q * x.q};
    }

    rat operator / (rat x) const {
        return {p * x.q, q * x.p};
    }
};

string tostring(__int128_t x) {
    if (x == 0) return "0";
    string s;
    while (x > 0) {
        s += (char)('0' + x % 10);
        x /= 10;
    }
    reverse(s.begin(), s.end());
    return s;
}

struct test {

    rat ask(rat x) {
        cout << "? " << tostring(x.p) << " " << tostring(x.q) << endl;
        int p, q;
        cin >> p >> q;
        return {p, q};
    }

    rat calc(rat y1, rat y2, rat x1, rat x2, rat d) {
        rat m = d * rat(1, 2);
        rat r = y1 + ((m - x1) * (y2 - y1) / (x2 - x1));
        return r * d;
    }

    void solve() {
        int n;
        cin >> n;
        vector<int> x(n), y(n);
        for (int i = 0; i < n; i++) {
            cin >> x[i] >> y[i];
        }
        sort(x.begin(), x.end());
        vector<pair<int, int>> xx;
        for (int i = 0; i < n; i++) {
            if (xx.empty() || x[i] > xx.back().first) {
                xx.push_back({x[i], 1});
            } else {
                xx.back().second++;
            }
        }
        int m = xx.size();
        vector<rat> val(m, 0);
        vector<rat> val2(m, 0);
        for (int i = 0; i < m; i++) {
            if (xx[i].second == 1) {
                if (i > 0 && i < m - 1)
                    val[i] = ask(xx[i].first);
            } else {
                if (i > 0) {
                    val[i] = ask(rat(xx[i].first) - rat(1, 3));
                }
                if (i < m - 1) {
                    val2[i] = ask(rat(xx[i].first) + rat(1, 3));
                }
            }
        }
        rat res = 0;
        for (int i = 0; i < m - 1; i++) {
            rat x1, y1, x2, y2;
            rat d = xx[i + 1].first - xx[i].first;
            if (xx[i].second == 1) {
                x1 = 0;
                y1 = val[i];
            } else {
                x1 = {1, 3};
                y1 = val2[i];
            }
            if (xx[i + 1].second == 1) {
                x2 = d;
                y2 = val[i + 1];
            } else {
                x2 = d - rat(1, 3);
                y2 = val[i + 1];
            }
            res = res + calc(y1, y2, x1, x2, d);
        }
//        res = res * rat(1, 2);
        cout << "! " << tostring(res.p) << " " << tostring(res.q) << endl;
    }
};

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        test().solve();
    }

    return 0;
}

Details

In file included from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:58,
                 from answer.code:1:
/usr/include/c++/13/numeric: In instantiation of ‘constexpr std::common_type_t<_Tp1, _Tp2> std::gcd(_Mn, _Nn) [with _Mn = __int128; _Nn = __int128; common_type_t<_Tp1, _Tp2> = __int128]’:
answer.code:15:27:   required from here
/usr/include/c++/13/numeric:166:21: error: static assertion failed: std::gcd arguments must be integers
  166 |       static_assert(is_integral_v<_Mn> && is_integral_v<_Nn>,
      |                     ^~~~~~~~~~~~~~~~~~
/usr/include/c++/13/numeric:166:21: note: ‘std::is_integral_v<__int128>’ evaluates to false
In file included from /usr/include/c++/13/bits/stl_pair.h:60,
                 from /usr/include/c++/13/bits/stl_algobase.h:64,
                 from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51:
/usr/include/c++/13/type_traits: In instantiation of ‘struct std::make_unsigned<__int128>’:
/usr/include/c++/13/type_traits:1983:11:   required by substitution of ‘template<class _Tp> using std::make_unsigned_t = typename std::make_unsigned::type [with _Tp = __int128]’
/usr/include/c++/13/numeric:173:24:   required from ‘constexpr std::common_type_t<_Tp1, _Tp2> std::gcd(_Mn, _Nn) [with _Mn = __int128; _Nn = __int128; common_type_t<_Tp1, _Tp2> = __int128]’
answer.code:15:27:   required from here
/usr/include/c++/13/type_traits:1836:62: error: invalid use of incomplete type ‘class std::__make_unsigned_selector<__int128, false, false>’
 1836 |     { typedef typename __make_unsigned_selector<_Tp>::__type type; };
      |                                                              ^~~~
/usr/include/c++/13/type_traits:1744:11: note: declaration of ‘class std::__make_unsigned_selector<__int128, false, false>’
 1744 |     class __make_unsigned_selector;
      |           ^~~~~~~~~~~~~~~~~~~~~~~~