QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#850862#9962. Diminishing FractionsZawosCompile Error//C++233.1kb2025-01-10 12:24:202025-01-10 12:24:21

Judging History

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

  • [2025-01-10 12:24:21]
  • 评测
  • [2025-01-10 12:24:20]
  • 提交

answer

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using ld=long double;
using vi=vector<int>;
template<class T> using oset =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ;
//上
const int N = 50001;
int wh[N];
int inv[5217][5217];
int euclid(int a, int b, ll &x, ll &y) {
	if (!b) return x = 1, y = 0, a;
	int d = euclid(b, a % b, y, x);
	return y -= a/b * x, d;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(wh,-1,sizeof(wh));
    memset(inv,-1,sizeof(inv));
    vector<int> prime(N+1,1);
    for(int i = 2; i <= N; i++){
        if(prime[i] == 1) for(int j = i; j <=N;j+=i) prime[j] = i;
    }

    vector<pair<int,int>> pot;

    for(int i = 2; i <= N;i++){
        unordered_map<int,int> fac;
        int x = i;
        int r = 1;
        while( x > 1){
            fac[prime[x]]++;
            r *= prime[x];
            x /= prime[x];
            
            if(fac.size() > 1) break;
        }
        if(fac.size() == 1){
            for(auto &u: fac) pot.push_back({u.first,r});
        }
    }
    for(int i = 0; i < 5217;i++) wh[pot[i].second] = i;
    ll y;

    int t;
    cin >>t;
    unordered_map<int,int> mp;
    vector<pair<int,int>> q;
    for(int tt = 0; tt < t; tt++){
        int n;
        cin >> n;
        q.push_back({n,tt});
    }
    sort(q.begin(),q.end());
    vector<pair<int,string>> res;
    int last = 1;
    for(int tt = 0; tt < t; tt++){
        if(q[tt].first == 1){
            res.push_back({q[tt].second,"1/1\n"});
            continue;
        }else if(q[tt].first == 2){
            res.push_back({q[tt].second,"1/2\n"});
            continue;
        }

        for(int i = last; i <= q[tt].first; i++){
            if(wh[i] != -1){
                mp[pot[wh[i]].first] = wh[i];
            }
            last++;
        }
        double ans = 0.0;
        int co = 0;
        res.push_back({q[tt].second,""});
        for(auto &u: mp){
            ll a = 1;
            for(auto &e:mp){
                if(u.first == e.first) continue;
                a =a*pot[e.second].second;
                if(a > 1e13) a%= pot[u.second].second;
            }
            a%= pot[u.second].second;
                    euclid(a,pot[u.second].second,a,y);
                    if(a <0) a += pot[u.second].second;
                
            if(co > 0)(res.back()).second+="+";
            (res.back()).second+=to_string(a)+"/"+to_string(pot[u.second].second);
            co++;
            ans += (double)a/(double)pot[u.second].second;
        }
        ans += 0.5;
        int xx = floor(ans);
        (res.back()).second+="-"+to_string(xx)+"/1\n";
    }
    sort(res.begin(),res.end());
    for(auto &u: res) for(auto&e:u.second) printf("%c",e);
}

详细

In file included from /usr/include/c++/13/string:43,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from answer.code:4:
/usr/include/c++/13/bits/allocator.h: In destructor ‘constexpr std::_Vector_base<int, std::allocator<int> >::_Vector_impl::~_Vector_impl()’:
/usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to ‘always_inline’ ‘constexpr std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = int]’: target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53:
/usr/include/c++/13/bits/stl_vector.h:133:14: note: called from here
  133 |       struct _Vector_impl
      |              ^~~~~~~~~~~~