QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#201089#6544. Cooperation Gameucup-team1209#TL 43ms20108kbC++201.1kb2023-10-05 10:37:332023-10-05 10:37:34

Judging History

你现在查看的是最新测评结果

  • [2023-10-05 10:37:34]
  • 评测
  • 测评结果:TL
  • 用时:43ms
  • 内存:20108kb
  • [2023-10-05 10:37:33]
  • 提交

answer

#include<bits/stdc++.h>
const int N = 300005;
const int mod = 1e9 + 7;
using ll = long long;
using pr = std::pair<int, int>;
using std::cin;
using std::cout;
int n, m;
std::vector<int> pos[N];
int a[N];
int match[N];
int bit[N];
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0);
	int T; cin >> T;
	for(int i = 1;i <= T;++i) {
		cin >> n;
		for(int i = 1;i <= n;++i) {
			cin >> a[i], pos[a[i]].push_back(i);
		}
		for(int i = 1;i <= n;++i) {
			for(int x = 0;x * 2 + 1 < (int) pos[a[i]].size();++x) {
				int A = pos[a[i]][pos[a[i]].size() - x - 1];
				int B = pos[a[i]][x];
				match[A] = B;
				match[B] = A;
			}
		}

		ll ans = 0;
		for(int i = 1;i <= n;++i) if(match[i]) {
			if(match[i] < i) {
				ans += i - match[i];
				for(int x = match[i];x;x &= x - 1) {
					ans -= bit[x];
				}
				for(int x = match[i];x <= n;x += x & -x) {
					bit[x] += 1;
				}
			} else {
				for(int x = i;x;x &= x - 1) {
					ans += bit[x];
				}
			}
		}
		cout << ans << '\n';
		for(int i = 1;i <= n;++i) {
			pos[i].clear();
			match[i] = 0;
			bit[i] = 0;
		}
	}
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 12964kb

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: 2ms
memory: 12128kb

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: 13580kb

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: 2ms
memory: 14096kb

input:

1
5
1 1 1 1 1

output:

6

result:

ok 1 number(s): "6"

Test #5:

score: 0
Accepted
time: 2ms
memory: 12684kb

input:

1
5
1 2 2 2 2

output:

4

result:

ok 1 number(s): "4"

Test #6:

score: 0
Accepted
time: 0ms
memory: 13168kb

input:

1
5
1 2 4 1 4

output:

4

result:

ok 1 number(s): "4"

Test #7:

score: 0
Accepted
time: 0ms
memory: 12244kb

input:

1
6
6 2 3 1 5 5

output:

1

result:

ok 1 number(s): "1"

Test #8:

score: 0
Accepted
time: 1ms
memory: 12148kb

input:

1
7
3 3 4 1 2 1 7

output:

3

result:

ok 1 number(s): "3"

Test #9:

score: 0
Accepted
time: 2ms
memory: 13596kb

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: 2ms
memory: 13636kb

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: 14160kb

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: 3ms
memory: 13776kb

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: 2ms
memory: 13336kb

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: 13320kb

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: 2ms
memory: 13096kb

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: 2ms
memory: 12792kb

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: 0ms
memory: 13248kb

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: 12552kb

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: 12324kb

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: 2ms
memory: 14144kb

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: 13428kb

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: 1ms
memory: 12192kb

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: 13716kb

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: 2ms
memory: 13168kb

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: 2ms
memory: 12836kb

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: 13224kb

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: 14100kb

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: 0ms
memory: 12748kb

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: 3ms
memory: 13856kb

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: 3ms
memory: 13616kb

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: 6ms
memory: 13104kb

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: 3ms
memory: 13792kb

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: 5ms
memory: 13816kb

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: 2ms
memory: 13728kb

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: 0ms
memory: 13044kb

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: 4ms
memory: 13800kb

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: 9ms
memory: 14700kb

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: 0
Accepted
time: 27ms
memory: 16136kb

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:

6750198055

result:

ok 1 number(s): "6750198055"

Test #39:

score: 0
Accepted
time: 38ms
memory: 20108kb

input:

1
300000
151794 116542 170886 235225 187763 184678 84510 217467 113166 229754 133167 123059 156441 173838 15120 220551 161229 1624 218845 290782 294345 57749 200471 131014 63919 181251 251329 99952 15494 142021 183236 115922 168694 249731 68716 299716 272911 252775 89064 89956 110722 2944 190702 113...

output:

8427945711

result:

ok 1 number(s): "8427945711"

Test #40:

score: 0
Accepted
time: 33ms
memory: 19092kb

input:

1
300000
164383 37078 172493 81232 164504 28942 155669 114157 106355 22598 129364 137766 195743 122628 55572 188911 179936 10439 120050 25517 135629 105725 40543 104508 2643 114830 148387 38634 134704 21008 151125 106553 26297 23184 145380 133089 10068 132111 195153 188363 102335 103746 108210 18946...

output:

10264263234

result:

ok 1 number(s): "10264263234"

Test #41:

score: 0
Accepted
time: 43ms
memory: 17548kb

input:

1
300000
1165 718 6804 27239 32734 97399 26828 35039 42648 39633 92857 43961 91941 71418 6424 48759 22835 53845 88550 60253 9617 20998 47912 86514 51766 56920 36932 44611 21211 91482 51718 97184 16603 20829 97852 66461 14522 21848 1242 54067 85435 4549 25719 75388 11593 72193 91758 19194 12143 98447...

output:

13327909467

result:

ok 1 number(s): "13327909467"

Test #42:

score: 0
Accepted
time: 42ms
memory: 16988kb

input:

1
300000
11020 30876 5221 9739 26264 43919 10432 19646 14383 3608 1951 23623 27606 28115 9086 21243 26052 11218 17903 24647 7860 43672 45049 44168 21527 14975 34980 38993 37840 13234 11950 46441 16614 39187 16777 1114 22997 14790 37082 42419 37261 28740 27980 36423 49810 49050 29467 31548 39914 1933...

output:

15785962088

result:

ok 1 number(s): "15785962088"

Test #43:

score: -100
Time Limit Exceeded

input:

1
300000
2 4 4 6 2 8 9 5 1 9 6 1 7 2 2 8 1 2 6 9 8 3 10 3 6 4 9 2 5 10 2 3 10 1 7 9 5 3 9 5 3 10 8 4 8 4 1 4 5 4 8 3 8 8 5 10 2 7 3 2 10 9 9 2 4 10 1 4 3 1 1 7 9 2 5 7 4 3 6 8 9 2 9 9 4 8 7 2 2 9 2 1 2 3 2 7 2 9 3 9 1 5 9 4 7 1 4 6 10 9 3 4 6 9 4 3 8 7 5 4 7 6 3 8 2 4 1 3 3 3 9 9 1 1 7 7 10 9 2 9 8 ...

output:


result: