QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#464769#2533. Two BuildingsThirvinAC ✓208ms30464kbC++141018b2024-07-06 14:45:002024-07-06 14:45:01

Judging History

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

  • [2024-07-06 14:45:01]
  • 评测
  • 测评结果:AC
  • 用时:208ms
  • 内存:30464kb
  • [2024-07-06 14:45:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
using pii = pair<int,int>;

ll ans = 0;
int f(int l, int r, int ql, int qr, vector<pii> &L, vector<pii> &R){
	if(l == r)
		return 0;
	int mid = (l + r ) / 2;
	int id;
	int mx = 0;
	for(int i = ql; i < qr;i ++){
		int d = (R[i].first + L[mid].first) * abs(L[mid].second - R[i].second);
		if(d > mx){
			mx = d;
			id = i;
		}
	}

	return max(mx, max(f(l, mid, ql, id+1, L, R), f(mid+1, r, id, qr, L, R)));
}
void solve(){
	int n;
	cin >> n;
	vector<int> arr(n);
	for(int &i : arr){
		cin >> i;
	}
	vector<pii> L;
	vector<pii> R;
	for(int i = 0;i < n;i ++){
		if(L.size() == 0 || arr[i] > L.back().first ){
			L.emplace_back(arr[i],i);
		}
	}
	for(int i = 0;i < n;i ++){
		while(R.size() > 0 && arr[i] > R.back().first){
			R.pop_back();
		}
		R.emplace_back(arr[i], i);
	}
	
	cout << f(0,L.size(),0,R.size(),L,R) << "\n";
}

signed main(){
	int t = 1;
	while(t -- ){
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
1 3 2 5 4

output:

21

result:

ok single line: '21'

Test #2:

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

input:

100
2 8 10 10 11 13 18 24 29 29 30 30 33 34 39 41 46 47 47 49 49 50 51 52 52 53 54 55 57 59 61 70 73 77 83 84 89 89 90 94 95 95 98 97 94 93 91 90 87 86 86 80 79 79 75 74 72 66 66 63 63 62 53 52 52 52 51 50 49 48 48 47 47 45 42 42 40 40 40 38 31 27 22 22 18 17 13 11 10 10 9 5 4 4 4 3 2 1 1 1

output:

5700

result:

ok single line: '5700'

Test #3:

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

input:

1000
86 452 475 818 305 976 305 135 130 60 508 457 968 368 502 769 92 417 621 996 43 505 506 65 858 221 843 304 822 174 829 401 291 450 325 945 169 783 766 444 985 58 291 969 35 167 739 110 677 830 423 296 375 330 741 790 295 738 294 584 708 575 781 210 401 652 8 733 591 806 227 662 208 292 75 503 5...

output:

1886632

result:

ok single line: '1886632'

Test #4:

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

input:

1000
453 852 468 906 23 224 650 790 584 985 623 746 515 418 379 909 924 686 994 388 37 464 215 19 625 256 211 791 810 301 171 161 652 298 497 498 321 872 682 532 933 148 713 806 924 858 943 458 133 877 752 195 379 91 172 7 857 131 778 3 857 932 645 433 63 41 706 241 658 389 663 194 938 35 668 997 16...

output:

1919667

result:

ok single line: '1919667'

Test #5:

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

input:

1000
579 206 855 567 852 805 157 214 398 176 262 642 396 275 594 917 594 45 101 143 209 470 988 660 436 169 8 969 147 351 931 587 415 243 129 55 660 876 236 167 598 772 932 927 543 269 194 142 364 809 518 271 521 995 944 310 101 469 257 583 174 440 939 969 16 191 99 356 227 564 221 958 426 210 34 21...

output:

1905134

result:

ok single line: '1905134'

Test #6:

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

input:

1000
4 5 6 6 7 9 9 9 13 14 15 17 19 22 27 28 29 36 38 39 42 43 44 45 48 49 50 50 50 51 51 56 56 58 59 62 62 64 66 67 72 73 76 78 79 79 80 80 80 81 85 86 90 92 92 93 94 95 95 96 96 96 98 101 103 103 106 109 110 114 114 114 115 119 120 121 121 122 122 123 125 126 127 129 131 132 133 134 135 139 142 14...

output:

506476

result:

ok single line: '506476'

Test #7:

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

input:

10000
4915 8586 3700 9039 6288 2199 1668 3207 8119 8308 4580 7242 1859 4755 2673 8188 5067 6142 3456 3111 1127 550 2622 495 3060 9545 1378 3116 6289 4243 8529 9049 3231 4688 1432 5659 9185 5158 5876 8006 7463 7610 4748 1432 4957 3334 5953 9618 9817 6510 8219 1544 6992 45 8109 9802 1778 9899 1675 580...

output:

197159718

result:

ok single line: '197159718'

Test #8:

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

input:

10000
8525 9481 5121 3857 7770 2735 94 333 9244 6281 6369 6393 3858 7404 192 2512 1001 137 5263 8547 8664 8274 4476 8613 7247 2236 8802 8991 9981 7156 2668 871 2966 1899 9095 8622 6997 2520 5576 8695 7713 8584 9356 2198 7630 2537 8474 5292 7615 6936 2270 5782 7969 5366 8132 7733 7726 3264 814 5490 8...

output:

197407098

result:

ok single line: '197407098'

Test #9:

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

input:

10000
1777 2050 926 8245 6795 3408 345 3305 9551 9930 3527 3847 9076 3975 6386 8796 7036 618 2286 533 2983 1105 5157 6801 83 2025 5822 4756 1707 9603 7308 4718 6883 14 5469 1298 474 4432 6637 544 2358 3885 8145 5215 1397 1851 4884 712 494 6238 7920 2100 3746 4153 4841 5680 1270 245 2052 5181 2261 71...

output:

196237848

result:

ok single line: '196237848'

Test #10:

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

input:

5
1 3 2 5 4

output:

21

result:

ok single line: '21'

Test #11:

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

input:

10000
4 5 7 7 9 10 11 11 12 16 19 19 23 29 31 32 36 38 42 44 45 45 48 48 49 51 51 54 57 58 58 61 64 66 68 71 71 72 73 75 77 78 79 79 79 86 88 89 90 93 93 94 95 98 99 101 108 114 120 120 121 123 124 125 129 131 132 136 136 139 141 144 144 147 147 148 148 152 152 154 155 155 156 161 163 164 164 165 16...

output:

51190524

result:

ok single line: '51190524'

Test #12:

score: 0
Accepted
time: 17ms
memory: 3876kb

input:

100000
55299 92209 92416 44881 46451 68170 93602 48186 82552 35567 84317 86245 45197 72889 43775 2157 36842 79646 67612 18372 99792 54828 19815 91739 79784 86458 28460 12970 68223 11626 80509 56326 21603 6172 78082 67395 83455 76073 2823 14003 98284 72080 9332 52104 59656 92901 39679 89899 10336 592...

output:

19896932246

result:

ok single line: '19896932246'

Test #13:

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

input:

5
8 3 6 3 1

output:

36

result:

ok single line: '36'

Test #14:

score: 0
Accepted
time: 18ms
memory: 3984kb

input:

100000
24874 58010 74186 64645 76312 74351 49833 29372 9229 59752 97292 15345 44132 23323 78962 91004 22253 45611 93162 24939 78564 16809 46236 88253 21313 23388 34180 33259 57147 83670 61479 28994 39290 76598 42482 67271 3845 18026 82019 5209 49197 93446 50818 44453 15085 405 44028 8187 39044 26641...

output:

19826974835

result:

ok single line: '19826974835'

Test #15:

score: 0
Accepted
time: 14ms
memory: 3832kb

input:

100000
23753 29021 72717 23278 87965 57611 36658 28353 41080 43809 13532 14145 20004 23484 44356 79636 83073 52652 14625 2044 54518 88790 7206 24987 86773 35349 38808 71801 79685 6726 33574 88987 6327 64909 10316 79417 78344 75386 26515 33806 82029 44468 42599 78603 61168 45305 49194 44352 36111 224...

output:

19831383793

result:

ok single line: '19831383793'

Test #16:

score: 0
Accepted
time: 19ms
memory: 6168kb

input:

100000
1 6 7 7 8 11 11 11 12 12 13 14 21 22 24 25 27 27 29 35 36 38 38 39 40 42 53 59 62 62 62 69 74 76 76 80 85 86 86 88 95 97 97 100 107 107 109 109 120 123 128 130 131 133 136 136 139 141 143 144 146 148 153 155 155 156 159 160 162 163 164 168 169 171 171 172 173 178 182 183 183 183 183 185 187 1...

output:

5010363358

result:

ok single line: '5010363358'

Test #17:

score: 0
Accepted
time: 201ms
memory: 11064kb

input:

1000000
418440 646670 651311 399053 462832 973036 198578 523900 909707 427729 666928 592301 781213 918038 359634 573344 826210 279960 866610 513877 266745 219646 278040 504463 119143 634659 147124 268971 426017 572012 1296 600036 335117 654550 420825 427733 512931 965951 125019 591684 621177 73402 4...

output:

1995498534400

result:

ok single line: '1995498534400'

Test #18:

score: 0
Accepted
time: 199ms
memory: 11084kb

input:

1000000
436829 575412 926659 377710 794143 695663 393232 8221 443364 608059 251943 670625 781 29529 526109 739086 442398 129701 87480 806318 74555 771872 552781 737480 140204 957741 463625 476707 834888 926902 177923 997858 578791 516153 596465 718081 397474 308681 528610 885016 74705 18147 201267 1...

output:

1998161365787

result:

ok single line: '1998161365787'

Test #19:

score: 0
Accepted
time: 195ms
memory: 11088kb

input:

1000000
266542 261935 148550 208300 860665 274027 414779 422627 868390 111659 430465 578898 327934 753382 297797 607767 586278 226800 935014 678307 935392 89476 618561 534517 505631 795431 693038 653611 88063 310701 573569 434702 727483 312532 638138 223696 711323 351332 61874 484618 452821 779455 1...

output:

1998332346320

result:

ok single line: '1998332346320'

Test #20:

score: 0
Accepted
time: 208ms
memory: 30464kb

input:

1000000
5 8 14 16 17 17 18 19 20 22 23 26 26 29 29 30 31 33 35 37 37 45 46 58 62 63 63 63 64 65 70 71 76 77 77 78 81 86 88 92 92 93 94 96 96 97 97 100 102 104 108 109 110 110 124 124 126 126 127 128 129 131 134 134 137 137 139 142 146 148 149 152 153 157 160 162 162 164 167 172 172 174 175 177 182 1...

output:

501069850814

result:

ok single line: '501069850814'

Test #21:

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

input:

5
8 3 6 3 1

output:

36

result:

ok single line: '36'

Test #22:

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

input:

10
7 9 9 7 7 1 7 9 9 3

output:

128

result:

ok single line: '128'

Test #23:

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

input:

10
7 7 7 7 7 7 7 7 7 7

output:

126

result:

ok single line: '126'

Test #24:

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

input:

10
8 8 8 7 7 6 6 5 1 1

output:

91

result:

ok single line: '91'

Test #25:

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

input:

10
3 6 7 3 3 3 4 2 6 5

output:

88

result:

ok single line: '88'

Test #26:

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

input:

10
1 3 4 4 6 6 6 7 8 8

output:

88

result:

ok single line: '88'

Test #27:

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

input:

1000
37 687 594 789 924 210 547 103 547 620 547 789 620 855 167 997 994 994 167 14 37 547 997 789 29 37 810 222 620 268 789 997 421 37 432 954 573 855 268 37 620 810 157 103 29 789 855 855 573 421 421 103 789 547 103 924 14 692 994 303 594 421 14 924 997 303 331 679 82 692 210 210 969 210 157 969 57...

output:

1917333

result:

ok single line: '1917333'

Test #28:

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

input:

1000
754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754 754...

output:

1506492

result:

ok single line: '1506492'

Test #29:

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

input:

1000
999 998 993 991 991 991 987 987 984 982 980 979 978 977 976 976 976 975 975 972 971 971 971 969 968 968 965 964 961 960 960 960 960 959 959 958 958 957 957 957 955 955 954 951 950 950 950 949 949 945 943 943 941 941 941 940 940 939 935 934 933 930 928 928 926 925 924 924 924 923 922 921 920 920...

output:

1006848

result:

ok single line: '1006848'

Test #30:

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

input:

1000
1 2 2 3 5 5 6 7 7 7 8 9 10 10 11 11 12 13 14 14 15 17 18 18 21 21 21 22 23 23 23 23 26 27 28 29 29 30 31 31 32 32 32 33 35 35 36 38 38 43 44 44 45 46 49 50 50 51 51 53 54 55 55 55 56 57 59 60 64 64 65 65 68 69 70 72 74 74 75 75 76 81 81 82 82 82 85 86 89 90 93 93 94 95 97 97 98 99 99 99 100 100...

output:

999000

result:

ok single line: '999000'

Test #31:

score: 0
Accepted
time: 199ms
memory: 11160kb

input:

1000000
655937 621649 960492 309146 335005 255677 174185 100818 110418 658829 453432 172936 495993 961936 663534 445822 615176 904276 993859 468443 830564 478712 27538 330614 94312 250592 465576 690126 281240 369328 274844 940751 243079 953874 788645 447932 335005 193893 998154 728064 597379 70549 1...

output:

1998473174096

result:

ok single line: '1998473174096'

Test #32:

score: 0
Accepted
time: 195ms
memory: 28788kb

input:

1000000
531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 531418 53141...

output:

1062834937164

result:

ok single line: '1062834937164'

Test #33:

score: 0
Accepted
time: 186ms
memory: 29416kb

input:

1000000
999999 999997 999996 999996 999995 999994 999992 999990 999989 999988 999984 999982 999981 999980 999979 999979 999979 999978 999978 999976 999975 999974 999974 999974 999973 999972 999971 999971 999971 999969 999967 999967 999966 999964 999963 999963 999963 999963 999962 999960 999959 99995...

output:

1000074257490

result:

ok single line: '1000074257490'

Test #34:

score: 0
Accepted
time: 205ms
memory: 29564kb

input:

1000000
2 3 4 5 6 7 8 8 10 10 10 12 12 14 14 14 15 16 17 17 17 19 19 19 22 22 22 23 25 27 27 28 28 29 30 30 30 31 31 31 33 33 35 35 36 37 39 39 39 39 42 44 44 44 45 45 49 49 50 50 53 54 54 55 55 56 61 61 61 61 62 63 65 65 67 68 68 68 69 69 70 70 70 71 73 74 75 76 77 80 81 82 82 83 83 84 84 89 89 89 ...

output:

999999999999

result:

ok single line: '999999999999'

Test #35:

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

input:

10
9 4 8 2 6 5 6 8 2 8

output:

153

result:

ok single line: '153'

Test #36:

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

input:

10
2 8 8 7 2 3 3 9 5 2

output:

102

result:

ok single line: '102'

Test #37:

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

input:

10
2 2 3 3 3 4 8 8 9 9

output:

99

result:

ok single line: '99'

Test #38:

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

input:

100
66 80 91 50 1 13 9 84 39 39 29 12 14 54 95 9 57 25 5 23 4 85 41 71 36 42 41 74 15 95 20 89 53 49 73 12 30 7 9 17 39 36 25 24 83 50 16 83 47 62 74 84 21 18 57 25 77 94 81 66 4 4 94 87 36 89 85 77 20 3 2 79 97 30 90 22 16 52 38 16 4 59 87 81 50 93 11 25 48 79 74 29 2 21 27 57 64 97 27 99

output:

18430

result:

ok single line: '18430'

Test #39:

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

input:

100
84 34 48 67 51 74 63 7 39 88 76 71 36 41 66 51 95 15 62 74 3 96 87 37 77 24 61 88 21 21 9 52 71 95 25 65 41 87 73 29 44 34 71 55 36 31 46 50 14 95 85 70 88 18 90 26 89 99 67 62 75 68 35 9 35 28 78 4 60 16 37 76 92 59 17 86 3 81 83 64 14 40 64 86 40 12 14 6 80 90 36 31 21 68 21 87 31 47 26 3

output:

16245

result:

ok single line: '16245'

Test #40:

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

input:

100
74 14 88 91 6 21 68 81 66 52 18 38 50 24 30 14 5 67 63 10 65 27 12 26 83 88 86 8 81 46 9 52 42 20 64 89 82 36 32 91 9 98 95 43 56 90 56 56 18 13 27 93 16 48 80 68 86 93 7 32 61 12 74 16 12 22 25 33 93 47 18 18 10 15 10 53 80 86 42 99 8 25 31 98 21 42 82 28 12 93 29 19 26 58 15 7 87 57 11 1

output:

16554

result:

ok single line: '16554'