QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#715756#9381. 502 Bad GatewayStargazer#AC ✓349ms3612kbC++201.4kb2024-11-06 13:16:422024-11-06 13:16:43

Judging History

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

  • [2024-11-06 13:16:43]
  • 评测
  • 测评结果:AC
  • 用时:349ms
  • 内存:3612kb
  • [2024-11-06 13:16:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define fi first
#define se second
#define bg begin
#define gc getchar
inline int read(){
	char ch=gc();
	int res=0;bool f=1;
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
	return f?res:-res;
}
inline ll readll(){
	char ch=gc();
	ll res=0;bool f=1;
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
	return f?res:-res;
}
template<typename tp>inline void chemx(tp &a,tp b){(a<b)?(a=b):0;}
template<typename tp>inline void chemn(tp &a,tp b){(a>b)?(a=b):0;}

int n;
#define pll pair<ll,ll>
pll calc(int r){
	pll x;
	x.fi=1ll*r*(r+1)/2+n-r,x.se=r;
	return x;
}
bool check(int k){
	pll x=calc(k);
	pll y=calc(k+1);
	if((__int128)x.fi*y.se<=(__int128)x.se*y.fi)return true;
	else return false;
}

void solve(){
	n=read();
	int l=1,r=n-1,res=n;
	while(l<=r){
		int mid=(l+r)/2;
		if(check(mid))res=mid,r=mid-1;
		else l=mid+1;
	}
	//pll a=calc(1),b=calc(2);
	//cout<<a.fi<<" "<<a.se<<" "<<b.fi<<" "<<b.se<<'\n';
	pll rr=calc(res);
	ll g=__gcd(rr.fi,rr.se);
//	cout<<res<<'\n';
	cout<<rr.fi/g<<" "<<rr.se/g<<'\n';
}

int main(){
	#ifdef Stargazer
	freopen("1.in","r",stdin);
	#endif
	int T=read();
	while(T--)solve();
	
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3612kb

input:

3
1
2
3

output:

1 1
3 2
2 1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 166ms
memory: 3564kb

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
1999961560 44721
1 1
1 1
1999961560 44721
1 1
1999961560 44721
1 1
1 1
1 1
1999961560 44721
1 1
1 1
1999961560 44721
1 1
1999961560 44721
1999961560 44721
1 1
1999961560 44721
1 1
1 1
1999961560 44721
1 1
1999961560 44721
1999961560 44721
1 1
1999961560 44721
1999961560 44721
1999961560 44721
19...

result:

ok 1000000 lines

Test #3:

score: 0
Accepted
time: 349ms
memory: 3528kb

input:

1000000
158260522
877914575
602436426
24979445
861648772
623690081
433933447
476190629
262703497
211047202
971407775
628894325
731963982
822804784
450968417
430302156
982631932
161735902
880895728
923078537
707723857
189330739
910286918
802329211
404539679
303238506
317063340
492686568
773361868
125...

output:

316511467 17791
1755824328 41903
1204845831 34711
49954223 7068
1723292600 41513
623676492 17659
867864517 29460
952375859 30861
262700539 11461
422085442 20545
1942776701 44077
251551941 7093
1463896912 38261
1645584679 40566
901913913 30032
107573492 3667
1965228547 44331
323457022 17985
176178307...

result:

ok 1000000 lines

Extra Test:

score: 0
Extra Test Passed