QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#127358 | #5072. Future Coder | _skb_# | WA | 130ms | 3524kb | C++14 | 1.1kb | 2023-07-19 16:18:25 | 2023-07-19 16:18:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
ll ans=0;
vector<int> a(n);
for(int i=0;i<n;i++) cin>>a[i];
sort(a.begin(),a.end());
// for(int i=0;i<n;i++) cout<<a[i]<<" ";
// cout<<"\n";
for(int i=0;i<n;i++){
ll y=a[i];
if(a[i]==1) ans+=n-1;
else if(a[i]<1){
ll l = 0, r = n - 1;
while (r - l > 1) {
ll m = (l + r) / 2;
if (a[m] * (y - 1) < y) r = m;
else l = m;
}
ll idx = l + 1;
// cout<<y<<" "<<idx<<"\n";
ans+=n-idx;
}
else{
ll z=y/(y-1);
ll idx=upper_bound(a.begin(),a.end(),z)-a.begin();
if(idx>i) idx--;
// cout<<y<<" "<<z<<" "<<idx<<"\n";
ans+=idx;
}
}
cout<<ans/2<<"\n";
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3504kb
input:
2 8 3 -1 4 1 -5 9 2 -6 1 0
output:
19 0
result:
ok 2 number(s): "19 0"
Test #2:
score: 0
Accepted
time: 130ms
memory: 3524kb
input:
1000000 1 -164353707 1 -282757533 1 916961328 1 -540297420 1 866372576 1 1 1 871062154 1 873753814 1 1 1 1 1 636976909 1 789718633 1 200630859 1 -855838121 1 1 1 1 1 282306491 1 -308064257 1 -220028474 1 396002423 1 765070684 1 407981535 1 1 1 184126913 1 935672434 1 -70908999 1 1 1 669665925 1 1 1 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 1000000 numbers
Test #3:
score: -100
Wrong Answer
time: 97ms
memory: 3436kb
input:
500000 2 1 790170188 2 -886864567 1 2 -579023597 746881890 2 -534254391 -756978339 2 1 1 2 -617821991 -444756587 2 -676343428 -276446748 2 -422136307 1 2 1 1 2 -280282708 -901772076 2 -958271412 676715004 2 157313986 920829551 2 1 1 2 -796480068 1 2 1 1 2 616588559 1 2 1 -922399591 2 620860427 1 2 -...
output:
1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
wrong answer 4th numbers differ - expected: '0', found: '1'