QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#367896#6343. Bitaro's travelltunjic#5 6ms4588kbC++14842b2024-03-26 16:28:502024-07-04 03:31:53

Judging History

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

  • [2024-07-04 03:31:53]
  • 评测
  • 测评结果:5
  • 用时:6ms
  • 内存:4588kb
  • [2024-03-26 16:28:50]
  • 提交

answer

#include <cstdio> 
#include <stack> 

using namespace std; 

typedef long long ll;

const int N = 1e5 + 10; 
const ll OO = 1e18;

int n, A[N]; 

stack<int> L, R; 

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; ++i) scanf("%d", A + i); 
	int q, x; scanf("%d%d", &q, &x);

	int lo = -1, hi = n;
	for(; hi - lo > 1; ) {
		int mi = (lo + hi) / 2;
		if(A[mi] <= x) lo = mi;
		else hi = mi;
	}

	for(int i = 0; i <= lo; ++i) L.push(A[i]);
	for(int i = n - 1; i >= hi; --i) R.push(A[i]); 

	ll ans = 0;
	for(; !L.empty() || !R.empty(); ) {
		ll l = L.empty() ? OO : x - L.top(); 
		ll r = R.empty() ? OO : R.top() - x;
		if(l <= r) {
			ans += x - L.top(); 
			x = L.top(); 
			L.pop();
		} else {
			ans += R.top() - x;
			x = R.top();
			R.pop();
		}
	}

	printf("%lld\n", ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 1ms
memory: 4016kb

input:

2000
154914587 154914588 154914591 154914592 154914594 154914596 154914598 154914599 154914601 154914603 154914608 154914610 154914612 154914615 154914618 154914619 154914621 154914622 154914626 154914627 154914631 154914633 154914636 154914638 154914640 154914641 154914642 154914644 154914645 15491...

output:

809906250

result:

ok 1 number(s): "809906250"

Test #2:

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

input:

2000
356563033 356563037 356563039 356563041 356563043 356563045 356563048 356563050 356563051 356563052 356563054 356563055 356563057 356563060 356563061 356563062 356563065 356563067 356563069 356563074 356563076 356563077 356563079 356563080 356563082 356563085 356563086 356563090 356563091 35656...

output:

722242888

result:

ok 1 number(s): "722242888"

Test #3:

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

input:

2000
24477976 24477978 24477981 24477982 24477986 24477988 24477990 24477992 24477993 24477996 24477998 24477999 24478001 24478002 24478003 24478005 24478007 24478008 24478009 24478011 24478012 24478013 24478015 24478016 24478017 24478019 24478020 24478022 24478024 24478026 24478029 24478031 2447803...

output:

795269579

result:

ok 1 number(s): "795269579"

Test #4:

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

input:

2000
118383953 118383958 118383960 118383964 118383966 118383970 118383971 118383972 118383974 118383976 118383977 118383978 118383979 118383981 118383982 118383983 118383986 118383987 118383989 118383990 118383991 118383993 118383994 118383996 118383998 118383999 118384000 118384002 118384006 11838...

output:

633902161

result:

ok 1 number(s): "633902161"

Test #5:

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

input:

2000
272693597 272693671 272693681 272693702 272693821 272693831 272693847 272693875 272693993 272694064 272694229 272694559 272694705 272694761 272694801 272694938 272695137 272695221 272695495 272695544 497465806 497465807 497465809 497465811 497465813 497465815 497465816 497465817 497465819 49746...

output:

224780330

result:

ok 1 number(s): "224780330"

Test #6:

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

input:

2000
164199708 164199714 164199741 164199803 164199830 164199964 164200182 164200363 164200417 164200604 164200739 164200758 164200777 164201008 164201058 164201062 164201119 164201206 164201308 164201582 568938433 568938436 568938440 568938442 568938446 568938448 568938449 568938452 568938454 56893...

output:

404746823

result:

ok 1 number(s): "404746823"

Test #7:

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

input:

1
964813969
1
24961702

output:

939852267

result:

ok 1 number(s): "939852267"

Test #8:

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

input:

1
492812692
1
492812692

output:

0

result:

ok 1 number(s): "0"

Test #9:

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

input:

1
819738491
1
871545564

output:

51807073

result:

ok 1 number(s): "51807073"

Test #10:

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

input:

1
964813971
1
925278587

output:

39535384

result:

ok 1 number(s): "39535384"

Test #11:

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

input:

2
253257833 492812697
1
801030938

output:

547773105

result:

ok 1 number(s): "547773105"

Test #12:

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

input:

10
122861190 170244470 313637646 547293542 557767683 701410141 705452393 819738518 859150721 987518805
1
857449755

output:

1602648112

result:

ok 1 number(s): "1602648112"

Test #13:

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

input:

2000
346838 1137625 2006182 2714727 3062547 3877790 4774903 5016683 5100124 5947146 6363889 7142496 8219943 9913673 10499786 10641688 10929569 11277685 11325053 11977547 12601991 12646876 13722054 14836426 15008615 15250796 16045457 17235758 17556322 17685977 18102009 19184164 19263658 19974844 2038...

output:

1654008616

result:

ok 1 number(s): "1654008616"

Test #14:

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

input:

2000
743982 1493878 1718132 1810575 1882146 2552776 2611689 3114975 3229588 3341359 3699120 3840597 3904572 5058917 6038144 6194653 6618139 6786522 8387028 8443750 9643914 9829181 10446710 10816676 11402658 12787879 13130024 13352051 13946478 14160206 14209716 14474473 14716259 14983734 15687019 165...

output:

1421041440

result:

ok 1 number(s): "1421041440"

Test #15:

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

input:

2000
303288 1146965 1808284 2456179 2479090 2692039 2724480 3624997 3642488 4829238 4981072 5161924 7384691 8030369 9147077 10341325 10424498 10772436 11533204 12219489 12219994 12527510 13411498 13805137 14640093 14743330 15382882 16704507 16934318 17667539 17748510 18253649 19219338 20280530 20297...

output:

1982070571

result:

ok 1 number(s): "1982070571"

Subtask #2:

score: 0
Runtime Error

Dependency #1:

100%
Accepted

Test #16:

score: 0
Runtime Error

input:

200000
3362993 3362996 3362997 3363002 3363005 3363008 3363009 3363011 3363013 3363015 3363017 3363019 3363022 3363024 3363026 3363030 3363032 3363033 3363035 3363036 3363038 3363040 3363043 3363044 3363045 3363047 3363048 3363049 3363050 3363052 3363053 3363054 3363056 3363057 3363060 3363061 33630...

output:


result:


Subtask #3:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 6ms
memory: 4588kb

input:

200000
9 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181...

output:

100218

result:

wrong answer 1st numbers differ - expected: '200107', found: '100218'

Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%