QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#668347 | #5072. Future Coder | qinglu09 | TL | 706ms | 98776kb | C++23 | 1.4kb | 2024-10-23 13:49:01 | 2024-10-23 13:49:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long LL;
#define endl '\n'
#define per(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
typedef pair<int,int> PII;
#define ld double
const int N=2e6+10;
#define lowbit(x) (x&-x)
ll n;
int tree[N];
long long a[N];
ld b[N];
vector<double>mp;
int query(int k)//求1-k的和
{
int ans=0;
for(int i=k;i>0;i-=lowbit(i)) ans+=tree[i];
return ans;
}
void add(int x,int k)//x位置+k
{
if(x==0) return;
for(int i=x;i<N;i+=lowbit(i)) tree[i]+=k;
}
void solve()
{
cin>>n;
for(int i=1;i<=2*n;i++) tree[i]=0;
unordered_map<ld,int>to;
int cnt=0;
for(int i=1;i<=n;i++)
{
cin >> a[i];
mp.push_back(a[i]);
if(a[i]^1) b[i] = (ld)a[i] / (a[i] - 1);
if(a[i]^1) mp.push_back(b[i]);
}
sort(mp.begin(),mp.end());//先排序
mp.erase(unique(mp.begin(),mp.end()),mp.end());//后去重
for(auto x:mp)
{
to[x]=++cnt;
}
mp.resize(0);
ll ans=0;
for(int i=1;i<=n;i++)
{
if(!(a[i]^1))
{
ans+=i-1;
}
else if(a[i]>1)
{
ans+=query(to[b[i]]-1);
}
else
{
ans+=i - 1-query(to[b[i]]);
}
add(to[a[i]],1);
}
cout<<ans<<endl;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int T=1;
cin>>T;
while(T--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 11964kb
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: 281ms
memory: 11740kb
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: 0
Accepted
time: 219ms
memory: 11976kb
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 0 1 0 0 1 1 0 1 0 1 1 1 1 1 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 1 1 0 1 1 1 1 1 1 0 1 0 1 1 1 1 0 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 0 ...
result:
ok 500000 numbers
Test #4:
score: 0
Accepted
time: 216ms
memory: 11732kb
input:
333333 3 -456843986 158506254 -534204016 3 1 813811307 1 3 1 -670006360 -532705717 3 -254727252 981735583 1 3 -225553465 -935705776 1 3 -988632504 1 1 3 -178872231 -583515677 1 3 623311036 -686255588 1 3 -737001211 1 392980906 3 18055918 1 -646425457 3 1 410678121 356903351 3 -236953261 -340219283 -...
output:
2 3 2 3 2 3 2 3 3 3 2 0 0 3 2 2 2 3 3 2 2 0 3 0 2 3 3 2 3 3 0 0 3 3 3 3 2 2 3 2 2 0 2 0 3 3 2 3 2 2 2 3 2 3 2 2 3 2 3 0 3 2 2 3 2 3 0 3 3 2 3 2 0 2 2 0 2 3 2 3 3 3 0 3 3 3 0 3 2 2 3 0 2 2 2 0 2 3 2 3 3 2 2 2 2 3 3 2 3 3 3 0 2 2 3 2 3 2 2 3 3 2 3 0 3 3 3 3 2 2 3 3 3 2 3 3 3 3 2 3 3 3 3 0 0 3 2 2 3 3 ...
result:
ok 333333 numbers
Test #5:
score: 0
Accepted
time: 224ms
memory: 11752kb
input:
200000 5 313866785 1 1 332623105 1 5 334914680 1 194045152 1 1 5 913547424 828356629 1 318514317 463423920 5 -966604134 -394859623 -546920218 1 -475480757 5 911091114 -965977622 -623955994 -821624784 1 5 122007245 1 515943642 -958411032 1 5 -365415275 1 724364010 -425774782 -588760639 5 -976139440 1...
output:
9 9 4 4 7 9 7 9 6 6 4 7 8 7 4 10 9 7 9 7 9 10 8 9 7 9 9 8 9 10 10 7 7 10 9 7 4 4 10 9 6 9 10 9 9 9 9 4 9 9 9 10 8 9 4 9 6 4 9 7 8 7 7 7 7 10 4 9 8 9 9 10 7 9 9 10 7 7 8 10 9 9 10 4 9 7 7 7 9 9 9 7 8 8 9 4 7 7 8 7 9 6 4 7 8 10 9 4 7 7 6 6 7 7 8 8 10 8 7 4 9 9 9 9 6 8 6 8 6 7 7 7 10 9 9 9 7 9 6 7 10 7...
result:
ok 200000 numbers
Test #6:
score: 0
Accepted
time: 250ms
memory: 11932kb
input:
100000 10 18068807 665885439 1 1 -2862331 223630963 316366506 -474236418 1 -382176675 10 1 201015992 359736557 473174856 424044050 -323477656 129444459 541668958 1 791240074 10 1 -334263857 1 1 1 -629142457 740241044 1 1 1 10 -69729129 19893939 -454991275 418716614 698053473 177178246 843340692 1 -3...
output:
36 24 44 27 35 27 32 29 39 38 39 41 29 30 36 39 32 36 17 42 41 38 41 33 34 33 38 34 39 29 29 32 32 29 36 35 34 25 27 34 35 32 36 30 36 17 41 36 35 34 24 36 33 35 36 29 39 32 30 23 34 17 29 32 27 24 29 32 34 41 39 30 27 32 33 36 38 23 34 29 43 33 32 38 30 43 38 36 34 39 39 42 36 29 38 29 34 29 29 36 ...
result:
ok 100000 numbers
Test #7:
score: 0
Accepted
time: 269ms
memory: 11736kb
input:
10000 100 742189771 1 104362715 -508913885 -966596725 529680000 303155662 329730769 776744919 602196557 985408061 959317657 -229768261 -981695323 -971828593 31678627 1 809632782 427378586 1 -762586269 -428528786 -24043242 366495643 -455501573 1 -337736679 -352408190 -431766238 303924054 -540026786 1...
output:
3926 3723 3609 3719 3617 3467 3894 4107 3744 3987 3803 3926 3554 3504 3686 3855 3954 3582 3954 3618 3827 3890 3626 3957 4193 3554 3723 3983 3764 3794 3681 3789 3735 3859 4016 3922 3859 3984 3859 4110 3614 3689 3878 3969 3841 3579 4067 4019 3855 3989 3554 3983 4076 3779 4154 3894 3782 4055 4110 4050 ...
result:
ok 10000 numbers
Test #8:
score: 0
Accepted
time: 313ms
memory: 12048kb
input:
1000 1000 799675571 -147968613 935620048 724246778 487114192 346596834 378670063 27796944 -951842007 -102859312 -373060982 542829748 -351959523 -434320520 -323683332 734883536 152033886 1 -584793481 336220497 217919037 909497937 -855764710 1 1 -659362222 1 795745826 353787300 -494723929 1 206014470 ...
output:
395816 385254 381008 388022 384231 391910 387788 382517 382230 388479 383335 387529 381779 382516 388371 386939 388242 381504 381821 390926 388908 389118 385398 394494 388934 391488 388934 388814 385226 380595 386156 388919 383391 384237 384523 386574 391844 380463 391536 379758 392529 384774 388928...
result:
ok 1000 numbers
Test #9:
score: 0
Accepted
time: 339ms
memory: 12400kb
input:
100 10000 719870830 -352100131 709937014 572622881 604184377 -210915406 1 -913240674 -403693546 717949766 812371661 -321027479 1 528674382 1 -415654942 1 368884126 111017614 331104804 1 1 -442301304 1 -965207861 24312770 801936514 1 900862682 1 1 1 -970462441 -539712661 1 902604312 314530973 1 -1235...
output:
38802434 38776923 38929334 38518261 38522529 38661674 38584709 38834534 38769609 38928129 38899229 38423228 38728406 38589231 38547861 38753594 38558154 38476022 38604193 38601925 38778599 38858729 38783244 38677748 38896989 38480468 38475344 38708231 38889155 38822069 38835835 38696711 38975776 385...
result:
ok 100 numbers
Test #10:
score: 0
Accepted
time: 470ms
memory: 19572kb
input:
10 100000 1 1 1 -826727751 1 1 1 994561710 30875659 451531117 -613181225 -939124713 -302107149 -524962718 599224276 1 -893343886 -476139259 1 -392048340 452792359 365990035 419735825 -281226601 233858845 -508639066 -716578294 1 -329202930 -868474727 1 1 204347154 -993309867 -954688030 1 -614549993 3...
output:
3888463079 3875815289 3887803404 3881233365 3877531899 3877406400 3882421754 3874118223 3868092869 3878564525
result:
ok 10 numbers
Test #11:
score: 0
Accepted
time: 472ms
memory: 21888kb
input:
10 100000 -122582831 -600037920 101001605 -438694939 -295712621 1 -438659998 -737589851 370687908 1 -545621665 1 1 89841290 -61642105 274057992 -368951270 -21499741 1 -172728940 -429892874 -557496719 299378737 118428150 1 1 1 -401093659 -495653276 599152756 1 896361702 -900598995 511597965 1 7518184...
output:
3877271969 3874158232 3871084584 3873537735 3874129050 3878206810 3883100904 3868290843 3880238778 3878907468
result:
ok 10 numbers
Test #12:
score: 0
Accepted
time: 656ms
memory: 98776kb
input:
1 1000000 -667373390 280487798 1 1 1 -766422426 399232521 847629585 1 655312241 157670619 687626034 -200625353 -804824338 1 613276861 1 -713419387 1 592106539 -282921968 540840171 -655201339 904916903 1 -727617963 1 -259019351 1 1 -607516081 1 614705495 -475556582 -210171528 1 -913004294 571740512 5...
output:
387775170212
result:
ok 1 number(s): "387775170212"
Test #13:
score: 0
Accepted
time: 692ms
memory: 97400kb
input:
1 1000000 223843475 1 198303459 918528278 648615205 1 1 -83749218 1 248939114 1 43487845 126454153 1 1 -764157201 459633267 844902448 589441232 1 1 1 -16445037 749102015 1 -741440756 -477036417 -878864628 589542835 -906426699 29827995 747968690 223715418 1 1 -876859565 559975222 1 -531710724 5433042...
output:
387919742844
result:
ok 1 number(s): "387919742844"
Test #14:
score: 0
Accepted
time: 706ms
memory: 98700kb
input:
1 1000000 -843504022 263065141 -675598306 1 619134990 1 549452845 708287641 625746540 1 1 1 1 1 1 -755621094 882472549 -726731700 -779321318 983847217 193859527 -407914470 513306972 1 1 1 -628382567 128579146 1 160037431 1 1 -384797017 790056771 51775292 -178064558 355255537 369525548 1 1 889398342 ...
output:
387972032558
result:
ok 1 number(s): "387972032558"
Test #15:
score: 0
Accepted
time: 674ms
memory: 97328kb
input:
1 1000000 1 1 1 1 -571577427 1 372835328 1 1 -459244424 360949619 488949341 -269440189 1 516177878 209450912 272730077 -820248412 -127974173 1 -867322552 -494527428 948494225 -658931435 361690180 526189481 1 137230040 -732361379 564744545 696106595 -422353886 1 902804134 -820955936 -337168447 1 1 76...
output:
387689271521
result:
ok 1 number(s): "387689271521"
Test #16:
score: 0
Accepted
time: 681ms
memory: 96548kb
input:
1 1000000 555575182 -489550674 -57491130 1 48387813 1 144123688 -396444255 928098385 -47742952 930268309 -999273581 -42854339 368020303 -955234321 -845223250 -987030151 361884546 478030511 -746413161 223916271 -990378945 358822659 1 1 1 1 -366937206 1 -437629362 845645953 -472763508 1 1 1 -315077956...
output:
387516615933
result:
ok 1 number(s): "387516615933"
Test #17:
score: 0
Accepted
time: 82ms
memory: 28572kb
input:
1 1000000 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 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 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 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 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 ...
output:
499999500000
result:
ok 1 number(s): "499999500000"
Test #18:
score: -100
Time Limit Exceeded
input:
1 1000000 -308212647 -654494679 -662770175 -369597654 -689669005 -453340797 -112978204 -284868951 -632329393 -854155790 -198771152 -695295095 -208518851 -279070810 -655433320 -15970181 -990391176 -173798333 -941455141 -221134289 -849477565 -755292789 -485310016 -404986409 -67746319 -533521433 -35504...