QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#590640#9347. Competition in Swiss-systemkevinshanCompile Error//C++234.9kb2024-09-26 09:19:412024-09-26 09:19:42

Judging History

你现在查看的是最新测评结果

  • [2024-09-26 09:19:42]
  • 评测
  • [2024-09-26 09:19:41]
  • 提交

answer

#pragma GCC optimize("Ofast,O3,unroll-loops")

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

#define ll __uint128_t
#define all(x) x.begin(), x.end()
#define pb push_back
#define f first
#define s second

#define THIRD frac(1,3)
#define ZERO frac{0,0}

void print_u128(ll value) {
    if (value == 0) {
        std::cout << "0";
        return;
    }

    const uint64_t base = 10000000000000000000ULL;  // 10^19
    char buffer[40];
    int index = 0;

    while (value > 0) {
        __uint128_t quotient = value / base;
        uint64_t remainder = value % base;
        value = quotient;

        if (index > 0) {
            std::cout << std::setfill('0') << std::setw(19) << remainder;
        } else {
            std::cout << remainder;
        }

        index++;
    }
}

struct frac {
    ll num;
    ll den;
    frac(ll n, ll d) {
        if(d == 0) num = 0, den = 0;
        else {
            ll g = gcd(n,d);
            assert(g != 0);
            num = n/g;
            den = d/g;
        }
    }
    bool is_zero() { return den == 0; }
    bool is_less() { return den == 0 || num * 3 <= den; }
    frac get_div(ll tot) {
        ll g = gcd(num, tot);
        if(g == 0) return ZERO;
        assert(g != 0);
        return {num/g, (tot/g)*den};
    }
    void display() { 
        if(is_less()) cout<<"1/3 ";
        else {
            print_u128(num); 
            cout <<"/";
            print_u128(den);
            cout<<" "; 
        }
    }
};
frac adding(frac a, frac b) {
    if(a.is_zero()) return b;
    if(b.is_zero()) return a;

    if(a.is_less()) a = THIRD;
    if(b.is_less()) b = THIRD;

    // cout<<a.num<<"|"<<a.den<<"\n";
    // cout<<b.num<<"|"<<b.den<<"\n";

    ll new_num = a.num * b.den + b.num * a.den;
    ll new_den = a.den * b.den;
    ll g = gcd(new_num, new_den);
    assert(g != 0);
    return {new_num/g, new_den/g};
}

struct match{
    int p1, p2, w1, w2, d;
    int tot() { return w1 + w2 + d; }
};

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int t; cin>>t;
    while(t--){
        int n, M;
        cin>>n>>M;

        vector<vector<int>> opponents_played(n, vector<int>());

        vector<ll> match_points(n);
        vector<ll> game_points(n);
        // tot_match_points = rounds * 3;
        vector<ll> tot_game_points(n);
        
        vector<int> ar(M+1);
        for(int i=1; i<=M; i++) cin>>ar[i];
        for(int rounds=1; rounds<=M; rounds++) {
            ll tot_match_points = rounds;
            vector<bool> played(n);
            vector<match> matches;
            for(int j=0; j<ar[rounds]; j++) {
                match m = {0,0,0,0,0};
                cin>>m.p1>>m.p2>>m.w1>>m.w2>>m.d;
                m.p1--;
                m.p2--;
                matches.pb(m);
                int winner = 0;
                if(m.w1 > m.w2) winner = 1;
                if(m.w1 < m.w2) winner = 2;
                match_points[m.p1] += (winner == 1 ? 3 : 0) + (winner == 0 ? 1 : 0);
                match_points[m.p2] += (winner == 2 ? 3 : 0) + (winner == 0 ? 1 : 0);
                game_points[m.p1] += 3*m.w1 + m.d;
                game_points[m.p2] += 3*m.w2 + m.d;
                played[m.p1] = 1;
                played[m.p2] = 1;

                opponents_played[m.p1].pb(m.p2);
                opponents_played[m.p2].pb(m.p1);
                tot_game_points[m.p1] += m.tot();
                tot_game_points[m.p2] += m.tot();
            }
            for(int j=0; j<n; j++) {
                if(!played[j]){
                    tot_game_points[j] += 2;
                    match_points[j] += 3;
                    game_points[j] += 6;
                }
            }
            cout<<"Round "<<rounds<<"\n";
            vector<frac> MWP(n, ZERO);
            vector<frac> GWP(n, ZERO);
            for(int j=0; j<n; j++) {
                GWP[j] = frac(game_points[j], 3*tot_game_points[j]);
                MWP[j] = frac(match_points[j], tot_match_points*3);
            }
            for(int j=0; j<n; j++) {
                print_u128(match_points[j]); cout<<" ";
                // auto f1 = match_win_total[j].get_div(tot_matches_played[j]);
                frac f1 = ZERO;
                for(int i:opponents_played[j]) f1 = adding(f1, MWP[i]);
                f1 = f1.get_div(opponents_played[j].size());
                auto f2 = GWP[j];
                frac f3 = ZERO;
                for(int i:opponents_played[j]) f3 = adding(f3, GWP[i]);
                f3 = f3.get_div(opponents_played[j].size());
                // auto f3 = game_win_total[j].get_div(tot_matches_played[j]);

                f1.display();
                f2.display();
                f3.display();
                cout<<"\n";
            }
        }
    }
}


Details

In file included from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:58,
                 from answer.code:3:
/usr/include/c++/13/numeric: In instantiation of ‘constexpr std::common_type_t<_Tp1, _Tp2> std::gcd(_Mn, _Nn) [with _Mn = __int128 unsigned; _Nn = __int128 unsigned; common_type_t<_Tp1, _Tp2> = __int128 unsigned]’:
answer.code:46:23:   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 unsigned>’ 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 unsigned>’:
/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 unsigned]’
/usr/include/c++/13/numeric:173:24:   required from ‘constexpr std::common_type_t<_Tp1, _Tp2> std::gcd(_Mn, _Nn) [with _Mn = __int128 unsigned; _Nn = __int128 unsigned; common_type_t<_Tp1, _Tp2> = __int128 unsigned]’
answer.code:46:23:   required from here
/usr/include/c++/13/type_traits:1836:62: error: invalid use of incomplete type ‘class std::__make_unsigned_selector<__int128 unsigned, 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 unsigned, false, false>’
 1744 |     class __make_unsigned_selector;
      |           ^~~~~~~~~~~~~~~~~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:96:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   96 |         freopen("input.in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
answer.code:97:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   97 |         freopen("output.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~