QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#143352 | #6744. Square | qzez | AC ✓ | 34ms | 3668kb | C++14 | 1.0kb | 2023-08-21 08:24:03 | 2023-08-21 08:24:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
if(x.empty())return out<<"[]";
out<<'['<<x[0];
for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
cerr<<x<<' ',debug(y...);
}
int T;
ll x,y;
ll ed(int x){
return x*(x-1ll)/2;
}
ll st(int x){
return ed(x-1)+1;
}
ll find(ll x){
ll y=sqrtl(x*2);
for(;y>1&&st(y)>x;y--);
for(;ed(y)<x;y++);
// debug("find",x,y);
return y;
}
int main(){
for(scanf("%d",&T);T--;){
scanf("%lld%lld",&x,&y);
if(x>=y)printf("%lld\n",x-y);
else{
ll a=find(x),b=ed(a)-x;
ll c=find(y),d=ed(c)-y;
if(b<=d)printf("%lld\n",c-a+d-b);
else{
// debug(a,b,c,d,ed(a-1));
printf("%lld\n",x-ed(a-1)+d+c-a+1);
}
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3664kb
input:
2 5 1 1 5
output:
4 3
result:
ok 2 number(s): "4 3"
Test #2:
score: 0
Accepted
time: 34ms
memory: 3668kb
input:
100000 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 ...
output:
0 2 1 4 3 2 6 5 4 3 8 7 6 5 4 10 9 8 7 6 5 12 11 10 9 8 7 6 14 13 12 11 10 9 8 7 16 15 14 13 12 11 10 9 8 18 17 16 15 14 13 12 11 10 9 20 19 18 17 16 15 14 13 12 11 10 22 21 20 19 18 17 16 15 14 13 12 11 24 23 22 21 20 19 18 17 16 15 14 13 12 26 25 24 23 22 21 20 19 18 1 0 2 2 1 3 4 3 2 4 6 5 4 3 5 ...
result:
ok 100000 numbers