QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#227934 | #6544. Cooperation Game | wangqingxian | WA | 51ms | 17492kb | C++14 | 1.7kb | 2023-10-28 09:44:15 | 2023-10-28 09:44:15 |
Judging History
answer
#include<algorithm>
#include<vector>
#include<cstdio>
#include<map>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<queue>
#include<iomanip>
#include<stdlib.h>
#include<set>
#include<cmath>
#define lowbit(i) (i&-i)
using namespace std;
const int N=3e5+10,inf=0x7fffffff,mod=1e9+7;
int t;
int n;
int a[N];
int stk[N];
int top=0;
int c[N];
struct giao{
int l;
int r;
bool operator < (const giao &temp) const{
return temp.r-temp.l>r-l;
}
};
priority_queue<giao> que;
vector<int> wei[N];
int sum[N];
int get_sum(int t){
int res=0;
while(t){
res+=sum[t];
t-=lowbit(t);
}
return res;
}
void add(int t,int k){
while(t<=n){
sum[t]+=k;
t+=lowbit(t);
}
}
signed main(){
cin>>t;
while(t--){
memset(stk,0,sizeof(stk));top=0;
memset(c,0,sizeof(c));
memset(sum,0,sizeof(sum));
memset(wei,0,sizeof(wei));
int ans=0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
wei[a[i]].push_back(i);
if(!c[a[i]]){
c[a[i]]=1;
stk[++top]=a[i];
}
}
for(int i=1;i<=top;i++){
int num=stk[i];
for(int j=0;(j+1)*2<=wei[num].size();j++)
que.push({wei[num][j],wei[num][wei[num].size()-j-1]});
}
while(!que.empty()){
giao hd=que.top();
que.pop();
ans+=hd.r-hd.l-get_sum(hd.r)+get_sum(hd.l);
add(hd.l,1);
add(hd.r,1);
}
cout<<ans<<endl;
}
return 0;
}
/*
2
7
1 2 1 1 2 1 2
12
1 2 3 1 2 3 1 2 3 1 2 3
1 1 2
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 14696kb
input:
2 7 1 2 1 1 2 1 2 12 1 2 3 1 2 3 1 2 3 1 2 3
output:
10 30
result:
ok 2 number(s): "10 30"
Test #2:
score: 0
Accepted
time: 0ms
memory: 13904kb
input:
1 7 1 2 1 1 2 1 2
output:
10
result:
ok 1 number(s): "10"
Test #3:
score: 0
Accepted
time: 0ms
memory: 14112kb
input:
1 12 1 2 3 1 2 3 1 2 3 1 2 3
output:
30
result:
ok 1 number(s): "30"
Test #4:
score: 0
Accepted
time: 0ms
memory: 14688kb
input:
1 5 1 1 1 1 1
output:
6
result:
ok 1 number(s): "6"
Test #5:
score: 0
Accepted
time: 2ms
memory: 13952kb
input:
1 5 1 2 2 2 2
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 0ms
memory: 14344kb
input:
1 5 1 2 4 1 4
output:
4
result:
ok 1 number(s): "4"
Test #7:
score: 0
Accepted
time: 0ms
memory: 14760kb
input:
1 6 6 2 3 1 5 5
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 0ms
memory: 13904kb
input:
1 7 3 3 4 1 2 1 7
output:
3
result:
ok 1 number(s): "3"
Test #9:
score: 0
Accepted
time: 0ms
memory: 14424kb
input:
1 8 6 7 1 8 2 2 4 4
output:
2
result:
ok 1 number(s): "2"
Test #10:
score: 0
Accepted
time: 0ms
memory: 14912kb
input:
1 9 2 2 5 6 3 4 6 8 9
output:
4
result:
ok 1 number(s): "4"
Test #11:
score: 0
Accepted
time: 0ms
memory: 14448kb
input:
1 10 10 1 2 2 8 4 4 7 1 5
output:
9
result:
ok 1 number(s): "9"
Test #12:
score: 0
Accepted
time: 4ms
memory: 14120kb
input:
1 11 10 3 4 11 10 11 8 11 6 1 11
output:
12
result:
ok 1 number(s): "12"
Test #13:
score: 0
Accepted
time: 0ms
memory: 15048kb
input:
1 12 5 9 9 1 11 11 10 3 5 7 6 6
output:
11
result:
ok 1 number(s): "11"
Test #14:
score: 0
Accepted
time: 0ms
memory: 14260kb
input:
1 13 6 2 11 7 1 5 9 2 3 7 10 11 4
output:
19
result:
ok 1 number(s): "19"
Test #15:
score: 0
Accepted
time: 0ms
memory: 13960kb
input:
1 14 7 3 11 12 7 13 3 2 7 5 2 10 5 1
output:
17
result:
ok 1 number(s): "17"
Test #16:
score: 0
Accepted
time: 4ms
memory: 13904kb
input:
1 15 9 12 8 12 2 13 9 14 15 3 7 9 15 1 11
output:
16
result:
ok 1 number(s): "16"
Test #17:
score: 0
Accepted
time: 3ms
memory: 14476kb
input:
1 16 16 1 14 7 3 2 13 1 9 10 14 10 9 12 9 8
output:
19
result:
ok 1 number(s): "19"
Test #18:
score: 0
Accepted
time: 0ms
memory: 13856kb
input:
1 17 3 1 10 8 15 1 15 13 10 3 3 8 14 11 12 13 16
output:
30
result:
ok 1 number(s): "30"
Test #19:
score: 0
Accepted
time: 2ms
memory: 14908kb
input:
1 18 6 15 12 8 13 8 10 11 15 14 1 17 16 11 14 16 18 17
output:
23
result:
ok 1 number(s): "23"
Test #20:
score: 0
Accepted
time: 0ms
memory: 14620kb
input:
1 15 1 1 2 1 2 2 2 2 2 1 2 1 1 1 2
output:
52
result:
ok 1 number(s): "52"
Test #21:
score: 0
Accepted
time: 0ms
memory: 14788kb
input:
1 16 3 2 1 3 2 2 1 3 3 1 2 2 1 1 2 1
output:
47
result:
ok 1 number(s): "47"
Test #22:
score: 0
Accepted
time: 4ms
memory: 13956kb
input:
1 17 1 1 1 1 1 2 1 1 2 1 1 1 1 2 1 2 2
output:
55
result:
ok 1 number(s): "55"
Test #23:
score: 0
Accepted
time: 2ms
memory: 14128kb
input:
1 18 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
output:
81
result:
ok 1 number(s): "81"
Test #24:
score: 0
Accepted
time: 0ms
memory: 14664kb
input:
1 18 2 1 1 2 2 2 2 2 2 2 1 2 2 2 1 1 1 2
output:
74
result:
ok 1 number(s): "74"
Test #25:
score: 0
Accepted
time: 3ms
memory: 14440kb
input:
1 18 3 3 3 2 1 3 2 2 3 2 3 3 2 2 3 1 2 2
output:
63
result:
ok 1 number(s): "63"
Test #26:
score: 0
Accepted
time: 0ms
memory: 14320kb
input:
1 500 137 146 125 351 189 109 382 104 211 422 391 129 256 490 177 460 366 191 205 75 84 65 93 417 61 47 453 206 261 243 286 263 314 431 295 423 285 201 195 47 435 60 88 219 12 224 23 50 351 286 325 315 388 113 135 262 389 390 187 211 21 18 150 460 452 391 80 174 281 474 471 423 298 456 260 279 316 3...
output:
23820
result:
ok 1 number(s): "23820"
Test #27:
score: 0
Accepted
time: 0ms
memory: 14400kb
input:
1 1000 356 859 87 222 368 232 533 255 448 434 593 395 634 828 364 790 146 262 851 257 619 11 964 699 802 713 125 523 395 45 773 304 73 900 97 98 634 579 673 278 553 985 280 29 891 567 999 117 346 871 218 823 829 642 177 599 510 368 489 984 850 180 961 205 181 78 277 617 636 255 863 208 728 984 929 4...
output:
94557
result:
ok 1 number(s): "94557"
Test #28:
score: 0
Accepted
time: 4ms
memory: 14824kb
input:
1 2000 126 1070 1218 159 394 609 1783 1957 1265 1242 359 303 692 1677 1379 932 1989 1331 1457 781 811 1528 1673 1240 1954 1612 824 887 824 1203 288 66 1074 1029 1894 1697 1685 718 323 1490 1341 255 1828 1849 1225 1867 1050 411 1452 1643 1019 1506 1006 555 687 924 26 250 483 396 1997 1150 746 1288 71...
output:
360267
result:
ok 1 number(s): "360267"
Test #29:
score: 0
Accepted
time: 0ms
memory: 14684kb
input:
1 3000 1705 281 2645 287 2932 2690 625 2763 2674 2154 2021 2316 749 1822 2882 1370 2832 2889 1359 1408 3 2238 2677 781 2210 911 1035 1652 1150 2361 1995 2723 1482 1350 1795 2591 927 857 782 599 424 1013 2185 861 2751 2359 2398 1513 854 415 2116 2597 1479 1572 2900 2849 837 621 2478 808 1657 312 42 1...
output:
887149
result:
ok 1 number(s): "887149"
Test #30:
score: 0
Accepted
time: 0ms
memory: 14140kb
input:
1 5000 2350 599 3307 3943 2600 1636 1526 2270 3605 474 153 4237 3056 3521 2207 2551 2918 1324 1058 2455 2579 681 1389 2263 1515 1109 2649 4292 3713 86 2433 1335 3083 1503 894 4085 3515 2647 2699 2816 1592 3746 4385 2181 1507 1342 285 3908 3171 4152 2013 2475 321 3501 3023 3291 1868 4873 571 4145 487...
output:
2222345
result:
ok 1 number(s): "2222345"
Test #31:
score: 0
Accepted
time: 4ms
memory: 14044kb
input:
1 5000 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 1 1...
output:
6250000
result:
ok 1 number(s): "6250000"
Test #32:
score: 0
Accepted
time: 4ms
memory: 14540kb
input:
1 5000 1 2 1 2 1 1 1 1 2 2 2 1 2 2 2 1 2 1 1 2 2 1 2 1 1 1 2 2 1 2 2 2 1 1 2 2 2 1 1 1 1 1 2 1 1 1 2 2 2 1 2 2 2 1 1 1 1 2 1 2 2 1 1 2 1 1 1 2 1 1 1 2 2 1 1 1 1 2 1 1 1 2 2 2 1 2 2 2 1 2 2 2 1 1 1 1 2 2 2 1 1 2 1 1 1 2 1 2 1 2 1 2 1 1 1 1 1 1 1 2 2 2 2 1 2 1 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 2 1 1 2 2 1...
output:
6176349
result:
ok 1 number(s): "6176349"
Test #33:
score: 0
Accepted
time: 0ms
memory: 14644kb
input:
1 5000 1 3 3 2 2 1 1 3 3 1 1 1 3 3 3 2 1 1 2 3 2 3 1 1 1 1 1 2 2 2 2 3 3 3 3 3 1 1 2 2 2 2 3 3 1 1 2 3 1 2 1 2 3 2 1 2 3 1 1 1 2 1 3 3 1 3 3 2 2 1 2 2 2 2 1 2 3 1 3 1 3 3 1 1 1 3 3 1 3 3 2 1 2 3 1 2 2 3 1 2 2 1 1 1 3 1 1 1 2 2 3 1 3 1 2 3 1 2 1 2 1 3 1 3 1 1 2 3 2 1 3 2 3 3 3 2 1 1 3 1 1 1 1 2 2 1 2...
output:
6188117
result:
ok 1 number(s): "6188117"
Test #34:
score: 0
Accepted
time: 0ms
memory: 14872kb
input:
1 5000 3 1 3 1 2 2 1 1 1 2 2 4 4 4 2 4 1 1 3 3 1 1 2 3 1 3 4 4 2 4 3 1 1 1 1 2 3 1 4 4 2 4 4 4 3 2 3 4 2 1 2 1 1 2 1 4 1 4 3 4 3 1 3 2 4 4 4 1 1 1 2 3 4 4 3 2 2 2 3 3 3 2 1 2 1 2 4 3 1 3 2 3 3 1 4 2 3 4 4 3 3 4 1 3 2 2 3 2 1 1 4 4 4 2 4 1 1 4 3 1 1 4 2 1 1 2 1 4 2 3 3 3 1 1 4 2 4 2 2 4 4 1 1 3 1 4 4...
output:
6160622
result:
ok 1 number(s): "6160622"
Test #35:
score: 0
Accepted
time: 4ms
memory: 15064kb
input:
1 5000 5 1 1 5 3 3 5 1 3 3 1 4 2 1 1 3 2 1 3 2 2 1 1 3 2 4 1 2 4 1 3 5 5 1 4 4 5 3 4 4 1 5 2 3 4 3 5 5 4 4 1 4 4 5 5 3 1 1 4 2 3 2 3 4 1 3 3 1 2 5 2 5 2 5 4 1 5 4 1 4 5 2 5 2 1 3 4 2 4 3 1 2 2 4 4 4 4 1 2 1 1 5 5 3 2 5 4 5 5 4 3 3 5 4 5 4 3 3 1 2 5 3 5 5 3 5 2 3 3 4 3 5 1 3 2 3 4 4 5 2 3 4 1 1 1 1 3...
output:
6143208
result:
ok 1 number(s): "6143208"
Test #36:
score: 0
Accepted
time: 12ms
memory: 15056kb
input:
1 50000 14319 5515 19656 16731 116 13372 1204 4497 18199 2381 17358 14883 12446 8351 17368 14809 2695 3878 15368 12082 1952 9676 15080 15810 3564 13037 9685 4878 2436 1242 10465 1394 19891 18070 9586 8475 10745 7996 4320 10318 14442 247 10234 12831 19596 14279 13570 14555 6012 4163 17580 17118 4330 ...
output:
350726492
result:
ok 1 number(s): "350726492"
Test #37:
score: 0
Accepted
time: 26ms
memory: 15780kb
input:
1 100000 21754 27048 9891 6525 24522 9160 19237 22607 25962 990 3621 18344 24028 1096 15056 27867 16485 25458 5796 20163 14399 20992 2902 28203 13144 7416 28669 19684 28274 24581 20612 12530 1025 13557 18220 4335 28448 18364 15799 14023 9372 4047 17262 13131 4151 970 23261 4270 20599 4059 23922 1063...
output:
1525230220
result:
ok 1 number(s): "1525230220"
Test #38:
score: -100
Wrong Answer
time: 51ms
memory: 17492kb
input:
1 200000 38483 10514 31812 19484 36945 2891 23483 3223 9429 18651 14138 12335 19265 35958 13423 25907 27820 34082 17594 13957 36130 10236 16879 8281 26592 9843 5272 12986 12313 12556 34929 12934 24563 1372 35946 35629 27275 22929 2793 23221 1965 42 39173 2681 34076 5754 24268 4261 6608 10345 28606 2...
output:
-1839736537
result:
wrong answer 1st numbers differ - expected: '6750198055', found: '-1839736537'