QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#440166 | #8341. 序列 | A_zjzj | 100 ✓ | 243ms | 15548kb | C++17 | 1.0kb | 2024-06-13 11:05:08 | 2024-06-13 11:05:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned ll;
const int N=1e6+10;
int n,a[N],cur[N],c[N];
void add(int x,int y){
for(;x<=n;x+=x&-x)c[x]+=y;
}
int get(int x,int y=0){
for(;x;x^=x&-x)y+=c[x];
return y;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
iota(cur,cur+1+n,0);
sort(cur+1,cur+1+n,[&](int x,int y){
return a[x]^a[y]?a[x]<a[y]:x<y;
});
fill(c+2,c+1+n,1);
for(int i=1;i<=n;i++){
int x=i+(i&-i);
if(x<=n)c[x]+=c[i];
}
ll ans=0;
for(int i=1,j,len=n-1;i<=n;i=j){
for(j=i+1;j<=n&&a[cur[i]]==a[cur[j]];j++);
for(int x=i,y=j-1;x<=y;len--){
int dx=get(cur[x]),dy=len-get(cur[y]);
if(dx<=dy){
ans+=dx,add(cur[x++],-1);
}else{
ans+=dy,add(cur[y--],-1);
}
}
}
cout<<ans<<endl;
return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif
詳細信息
Subtask #1:
score: 1
Accepted
Test #1:
score: 1
Accepted
time: 0ms
memory: 7912kb
input:
10 10 9 6 2 6 1 10 8 10 9
output:
14
result:
ok single line: '14'
Test #2:
score: 1
Accepted
time: 1ms
memory: 7772kb
input:
10 2 9 3 5 2 7 5 7 4 3
output:
6
result:
ok single line: '6'
Test #3:
score: 1
Accepted
time: 1ms
memory: 7924kb
input:
10 8 1 7 10 6 8 3 8 7 3
output:
7
result:
ok single line: '7'
Test #4:
score: 1
Accepted
time: 1ms
memory: 7852kb
input:
10 9 3 4 9 2 8 10 3 9 9
output:
10
result:
ok single line: '10'
Test #5:
score: 1
Accepted
time: 0ms
memory: 7848kb
input:
8 6 2 8 1 7 2 3 7
output:
7
result:
ok single line: '7'
Subtask #2:
score: 21
Accepted
Test #6:
score: 21
Accepted
time: 1ms
memory: 7696kb
input:
100 69 30 17 89 90 47 27 42 97 29 14 78 21 21 89 87 40 9 1 86 64 63 67 20 75 36 91 97 51 14 58 78 12 78 53 91 18 32 85 32 40 32 57 86 56 90 43 31 87 11 1 31 2 51 86 19 49 26 99 66 55 45 45 47 42 3 19 79 71 60 58 46 72 29 89 45 20 31 54 83 25 56 16 92 54 82 24 89 13 59 27 10 29 63 39 45 32 57 20 71
output:
1210
result:
ok single line: '1210'
Test #7:
score: 21
Accepted
time: 0ms
memory: 7928kb
input:
100 82 70 62 98 1 66 38 88 52 14 26 77 61 64 31 19 91 44 81 48 10 75 86 100 31 45 92 91 92 65 49 21 59 70 12 49 77 78 70 22 26 39 4 28 7 32 5 80 33 91 35 34 89 32 63 63 47 11 93 35 77 60 29 39 40 60 44 30 45 27 41 53 95 78 38 31 87 56 84 42 48 24 86 29 9 22 52 95 58 70 85 44 85 17 64 83 27 6 79 18
output:
1285
result:
ok single line: '1285'
Test #8:
score: 21
Accepted
time: 1ms
memory: 7796kb
input:
100 28 51 28 49 19 11 55 85 90 67 14 99 45 7 30 98 33 32 88 33 52 86 68 41 11 95 64 34 13 5 47 16 89 44 60 80 52 17 18 11 92 58 22 60 36 71 22 34 26 32 24 34 75 60 86 23 74 48 19 69 17 50 60 82 14 64 93 49 26 100 19 64 51 70 61 22 86 84 41 62 2 15 42 15 48 62 73 25 32 65 45 71 11 12 91 73 37 8 74 50
output:
1189
result:
ok single line: '1189'
Test #9:
score: 21
Accepted
time: 0ms
memory: 7748kb
input:
100 40 50 96 69 68 97 46 97 3 30 23 51 4 59 10 33 23 60 11 18 79 48 75 24 17 34 56 22 42 75 68 66 99 4 60 96 37 100 72 31 90 44 81 4 30 68 54 16 89 65 18 21 3 1 61 48 96 12 81 30 11 24 23 27 80 50 71 36 67 31 23 43 11 58 67 7 62 3 57 8 15 55 2 88 30 85 52 37 67 82 25 12 53 80 62 49 61 78 67 81
output:
1283
result:
ok single line: '1283'
Test #10:
score: 21
Accepted
time: 1ms
memory: 7768kb
input:
95 55 88 4 19 5 75 14 93 48 2 18 73 82 56 33 49 33 48 65 25 29 21 69 69 80 74 88 84 21 1 93 83 70 65 7 33 47 88 90 94 48 52 3 35 39 94 90 87 59 71 44 76 38 90 81 30 54 92 19 52 74 63 43 80 83 27 52 9 30 65 30 32 29 12 65 16 22 59 80 75 95 36 86 82 67 51 41 74 56 21 46 25 91 27 94
output:
965
result:
ok single line: '965'
Subtask #3:
score: 36
Accepted
Test #11:
score: 36
Accepted
time: 211ms
memory: 15472kb
input:
1000000 727698 886811 348006 964227 189534 323619 61248 791021 927942 228723 790289 253678 991921 996163 163016 14258 48653 620616 739462 742181 374470 171391 988545 570764 691904 590359 101758 164155 190539 915956 467511 363262 581890 110947 363017 46865 830042 777075 385392 532804 591488 926654 60...
output:
125090849643
result:
ok single line: '125090849643'
Test #12:
score: 36
Accepted
time: 203ms
memory: 15464kb
input:
1000000 532221 713797 820040 34521 578943 904409 284030 961029 690176 45839 923063 569553 927180 428215 788984 538403 131258 546442 266500 69732 42316 22323 497367 337667 824847 945940 917921 256832 263841 473705 952945 521730 912484 213465 347848 603236 879800 817330 506091 912692 45919 965293 1215...
output:
125047392503
result:
ok single line: '125047392503'
Test #13:
score: 36
Accepted
time: 207ms
memory: 15348kb
input:
989899 794348 27304 260947 666929 766869 570546 41550 729352 620778 43047 194799 714022 594936 294949 293618 594283 823690 400845 756470 915147 838826 1451 930862 2962 144726 291213 368038 579085 859515 744823 550395 458911 310531 662425 904697 14546 606674 139025 419231 19385 880774 187275 20804 75...
output:
122410283847
result:
ok single line: '122410283847'
Test #14:
score: 36
Accepted
time: 215ms
memory: 15528kb
input:
1000000 477384 694930 378855 918999 724128 5355 205569 972604 372481 907648 310871 880563 536259 656003 376906 591863 103903 162732 366604 553920 745588 328642 503535 583744 107392 278841 85307 107648 353988 312159 124834 296936 453485 114003 49353 683103 104976 914456 48564 610794 551596 91209 9766...
output:
125099835690
result:
ok single line: '125099835690'
Test #15:
score: 36
Accepted
time: 195ms
memory: 15300kb
input:
1000000 726647 546702 790995 151076 771726 818274 658506 972474 460978 431658 661414 262747 217747 87797 490581 151177 743296 566542 75737 292929 485552 100387 385198 570740 607382 717838 669963 346804 717377 112189 382602 468884 96036 547196 613303 171309 682285 524136 778417 334551 674077 803556 4...
output:
125061190001
result:
ok single line: '125061190001'
Subtask #4:
score: 42
Accepted
Test #16:
score: 42
Accepted
time: 234ms
memory: 15468kb
input:
1000000 417207 539133 747033 930193 286724 671633 313100 655654 196738 870001 535793 194135 206243 377441 776661 779229 29066 812909 750520 575001 781316 378263 651202 26349 170017 692512 226366 453055 874271 369128 142920 198565 826737 917806 936169 574087 481434 357523 344750 332628 278689 967286 ...
output:
124987094007
result:
ok single line: '124987094007'
Test #17:
score: 42
Accepted
time: 236ms
memory: 15364kb
input:
1000000 455688 733930 113845 972942 272082 99775 876386 40750 363188 663101 923635 602229 882411 542917 59106 483228 62358 870944 563099 322713 645070 368012 344015 432282 590546 714219 892812 17366 278494 18630 950143 933906 641816 701756 676606 320594 423240 242881 167915 365873 797717 909551 8366...
output:
125031240178
result:
ok single line: '125031240178'
Test #18:
score: 42
Accepted
time: 228ms
memory: 15468kb
input:
1000000 580379 568488 53650 328394 34545 118366 36812 741717 871389 23606 828414 613973 130749 126067 991641 191547 358038 731250 491897 634868 716569 366109 977666 294653 47266 179682 226457 126753 504090 280343 167335 382538 456518 271501 933534 151076 617325 96894 665526 696048 32406 435897 82394...
output:
125033040609
result:
ok single line: '125033040609'
Test #19:
score: 42
Accepted
time: 154ms
memory: 13108kb
input:
684684 475731 157477 243491 600325 3426 610682 263652 401298 404391 76455 302145 202 113276 548798 364005 140971 366773 345739 296144 318544 150886 560221 163591 684636 11830 496059 134756 405818 420726 447441 228837 663369 654941 601587 383841 12246 49246 572587 98105 386993 334345 593682 612203 10...
output:
58587069465
result:
ok single line: '58587069465'
Test #20:
score: 42
Accepted
time: 243ms
memory: 15548kb
input:
1000000 770318 900235 346908 882693 224054 356355 838352 875077 993517 21713 732236 883457 106552 477541 778544 530011 970622 347403 375758 21199 229743 824265 918354 396884 919930 258310 487645 480597 47069 497355 337694 890255 958422 133740 189366 572488 323391 629290 126158 398873 104124 644678 9...
output:
125029423367
result:
ok single line: '125029423367'