QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#586900 | #9381. 502 Bad Gateway | Ringup | WA | 613ms | 3624kb | C++23 | 3.3kb | 2024-09-24 16:27:21 | 2024-09-24 16:27:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n;
template<typename T>
void write(T x) {
if (x < 0) putchar('-'), x = -x;
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
__int128 gcd(__int128 a,__int128 b) { return b == 0 ? a : gcd(b , a%b); }
template<class T>
struct Frac {
T num;
T den;
Frac(T num_, T den_) : num(num_), den(den_) {
if (den < 0) {
den = -den;
num = -num;
}
}
Frac() : Frac(0, 1) {}
Frac(T num_) : Frac(num_, 1) {}
// 输出 double value = static_cast<double>(*Frac);
explicit operator double() const {
return 1. * num / den;
}
Frac &operator+=(const Frac &rhs) {
num = num * rhs.den + rhs.num * den;
den *= rhs.den;
return *this;
}
Frac &operator-=(const Frac &rhs) {
num = num * rhs.den - rhs.num * den;
den *= rhs.den;
return *this;
}
Frac &operator*=(const Frac &rhs) {
num *= rhs.num;
den *= rhs.den;
return *this;
}
Frac &operator/=(const Frac &rhs) {
num *= rhs.den;
den *= rhs.num;
if (den < 0) {
num = -num;
den = -den;
}
return *this;
}
friend Frac operator+(Frac lhs, const Frac &rhs) {
return lhs += rhs;
}
friend Frac operator-(Frac lhs, const Frac &rhs) {
return lhs -= rhs;
}
friend Frac operator*(Frac lhs, const Frac &rhs) {
return lhs *= rhs;
}
friend Frac operator/(Frac lhs, const Frac &rhs) {
return lhs /= rhs;
}
friend Frac operator-(const Frac &a) {
return Frac(-a.num, a.den);
}
friend bool operator==(const Frac &lhs, const Frac &rhs) {
return lhs.num * rhs.den == rhs.num * lhs.den;
}
friend bool operator!=(const Frac &lhs, const Frac &rhs) {
return lhs.num * rhs.den != rhs.num * lhs.den;
}
friend bool operator<(const Frac &lhs, const Frac &rhs) {
return lhs.num * rhs.den < rhs.num * lhs.den;
}
friend bool operator>(const Frac &lhs, const Frac &rhs) {
return lhs.num * rhs.den > rhs.num * lhs.den;
}
friend bool operator<=(const Frac &lhs, const Frac &rhs) {
return lhs.num * rhs.den <= rhs.num * lhs.den;
}
friend bool operator>=(const Frac &lhs, const Frac &rhs) {
return lhs.num * rhs.den >= rhs.num * lhs.den;
}
};
__int128 S(long long x) { return (__int128)(x + 1) * x / 2; }
Frac<__int128> f(int limit)
{
__int128 s = S(limit);
Frac<__int128> ans = { (s + n) * (n - limit) + s * limit , (__int128)n * limit};
return ans;
}
void solve()
{
cin >> n;
int l = 1 , r = n;
while(r - l >= 3)
{
int lmid = l + (r - l) / 3;
int rmid = r - (r - l) / 3;
if(f(lmid) <= f(rmid)) r = rmid;
else l = lmid;
}
int ans = l;
if(f(ans) > f(l+1)) ans = l+1;
if(f(ans) > f(r)) ans = r;
Frac now = f(ans);
__int128 d = gcd(now.num , now.den);
now.num /= d; now.den /= d;
write(now.num); putchar(' '); write(now.den); putchar('\n');
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
cin >> T;
while(T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
input:
3 1 2 3
output:
1 1 3 2 2 1
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 613ms
memory: 3624kb
input:
1000000 1 1000000000 1 1 1000000000 1 1000000000 1 1 1 1000000000 1 1 1000000000 1 1000000000 1000000000 1 1000000000 1 1 1000000000 1 1000000000 1000000000 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1000000000 1 1000000000 1000000000 1000000000 1000000000 1 1 1 10000000...
output:
1 1 27815811765186395 235863566 1 1 1 1 27815811765186395 235863566 1 1 27815811765186395 235863566 1 1 1 1 1 1 27815811765186395 235863566 1 1 1 1 27815811765186395 235863566 1 1 27815811765186395 235863566 27815811765186395 235863566 1 1 27815811765186395 235863566 1 1 1 1 27815811765186395 235863...
result:
wrong answer 2nd lines differ - expected: '1999961560 44721', found: '27815811765186395 235863566'