ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#198611 | #459. card | snow_trace | 100 | 185ms | 10600kb | C++11 | 2.2kb | 2023-11-28 11:13:00 | 2023-11-28 12:10:35 |
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define lowbit(x) x&(-x)
/*
* __----~~~~~~~~~~~------___
* . . ~~//====...... __--~ ~~
* -. \_|// |||\\ ~~~~~~::::... /~
* ___-==_ _-~o~ \/ ||| \\ _/~~-
* __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~
* _-~~ .=~ | \\-_ '-~7 /- / || \ /
* .~ .~ | \\ -_ / /- / || \ /
* / ____ / | \\ ~-_/ /|- _/ .|| \ /
* |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\
* ' ~-| /| |-~\~~ __--~~
* |-~~-_/ | | ~\_ _-~ /\
* / \ \__ \/~ \__
* _--~ _/ | .-~~____--~-/ ~~==.
* ((->/~ '.|||' -_| ~~-/ , . _||
* -_ ~\ ~~---l__i__i__i--~~_/
* _-~-__ ~) \--______________--~~
* //.-~~~-~_--~- |-------~~~~~~~~
* //.-~~~--\
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
const int N = 200000;
int a[500005],tree[200005];int n;
void upd(int pos,int add){
for(int i = pos;i<=N;i+=lowbit(i))tree[i]+=add;
}int query(int pos){
int res =0;for(int i = pos;i>0;i-=lowbit(i))res+=tree[i];return res;
}pair<int,int> p[500005];
bool cmp(pair<int,int>a,pair<int,int>b){
if(a.first == b.first)return a.second<b.second;
return a.first>b.first;
}
signed main(){
cin >> n;
for(int i = 1;i<=n;i++)cin >> a[i];
for(int i = 1;i<=n;i++){
p[i].first = a[i],p[i].second= i;
}sort(p+1,p+1+n,cmp);int ans = 0;
// for(int i = 1;i<=n;i++)cout << p[i].second << " ";cout << endl;
for(int i = 1;i<=n;){
int j = i;
while(j<=n){
int k = query(p[j].second);ans+=min(k,i-1-k);
if(a[p[j].second]!=a[p[j+1].second])break;j++;
}for(int k = i;k<=j;k++)upd(p[k].second,1);
i = j+1;
}cout << ans << endl;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 3ms
memory: 9060kb
input:
1000 297 929 509 79 535 349 534 684 34 155 140 310 674 539 144 251 652 238 230 366 49 173 680 910 40...
output:
127184
result:
ok single line: '127184'
Test #2:
score: 10
Accepted
time: 2ms
memory: 9056kb
input:
1000 929 647 920 146 561 731 523 873 905 445 882 892 300 936 913 978 11 645 53 599 460 19 200 142 66...
output:
124708
result:
ok single line: '124708'
Test #3:
score: 10
Accepted
time: 0ms
memory: 9056kb
input:
1000 564 66 136 467 369 232 653 742 899 10 343 318 384 735 315 764 692 765 463 938 671 351 364 655 5...
output:
123615
result:
ok single line: '123615'
Test #4:
score: 10
Accepted
time: 5ms
memory: 9060kb
input:
1000 23 23 18 31 15 27 1 1 7 17 29 27 15 3 20 15 15 8 13 18 14 27 16 29 26 22 27 23 1 26 15 23 26 31...
output:
123687
result:
ok single line: '123687'
Test #5:
score: 10
Accepted
time: 0ms
memory: 9056kb
input:
1000 18 17 22 23 20 29 4 2 16 4 11 15 2 23 3 14 17 19 2 22 17 4 4 26 8 24 12 10 14 7 20 27 9 30 3 5 ...
output:
117790
result:
ok single line: '117790'
Test #6:
score: 10
Accepted
time: 0ms
memory: 9060kb
input:
1000 11 13 4 22 26 31 16 31 14 2 17 4 7 8 9 26 26 10 31 18 18 24 2 7 15 22 25 30 15 18 2 5 25 26 9 1...
output:
121361
result:
ok single line: '121361'
Test #7:
score: 10
Accepted
time: 43ms
memory: 10596kb
input:
100000 13542 54069 82240 51085 76111 10855 17181 57779 8861 58429 37437 76888 32894 12469 49555 6379...
output:
1244729175
result:
ok single line: '1244729175'
Test #8:
score: 10
Accepted
time: 42ms
memory: 10600kb
input:
100000 59354 29503 76007 97604 5462 73673 45047 48213 62217 84857 95662 5388 8515 95760 66873 64126 ...
output:
1251802144
result:
ok single line: '1251802144'
Test #9:
score: 10
Accepted
time: 50ms
memory: 10596kb
input:
100000 73760 4687 15341 40692 26249 12573 96881 76643 22623 75668 69062 79687 34893 32979 50646 4830...
output:
1249230298
result:
ok single line: '1249230298'
Test #10:
score: 10
Accepted
time: 40ms
memory: 10600kb
input:
100000 247 190 168 38 295 23 188 296 50 144 12 185 294 127 158 296 285 6 221 231 70 242 27 221 138 3...
output:
1248585884
result:
ok single line: '1248585884'