QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#355245 | #6343. Bitaro's travel | Rikku_eq | 5 | 102ms | 18024kb | C++14 | 2.9kb | 2024-03-16 14:51:24 | 2024-03-16 14:51:24 |
Judging History
answer
#include <bits/stdc++.h>
#define ls(u) tr[0][u].ls
#define rs(u) tr[0][u].rs
#define INF 4000000000
#define N 200005
using namespace std;
typedef long long ll;
int n, tot, rt, Q;
ll x[N];
struct Seg { int ls, rs; ll mx; } tr[2][N*2];
void buildST (int &u, int l, int r, bool tg)
{
if (!u) { u=++tot; }
if (l==r) {
if (!tg) { tr[tg][u].mx=x[l]*2-x[l-1]; }
else { tr[tg][u].mx=x[r+1]-x[r]*2; }
return;
}
int md=(l+r)/2;
buildST(ls(u), l, md, tg);
buildST(rs(u), md+1, r, tg);
tr[tg][u].mx=max(tr[tg][ls(u)].mx, tr[tg][rs(u)].mx);
}
int qry0 (int u, int l, int r, ll val)
{
if (l==r) { return l; }
int md=(l+r)/2;
if (tr[0][rs(u)].mx<=val) { return qry0(ls(u), l, md, val); }
else { return qry0(rs(u), md+1, r, val); }
}
int qry1 (int u, int l, int r, ll val)
{
if (l==r) { return l; }
int md=(l+r)/2;
if (tr[1][ls(u)].mx>=val) { return qry1(ls(u), l, md, val); }
else { return qry1(rs(u), md+1, r, val); }
}
struct Pnt { int u, l, r; };
vector <Pnt> vec;
void dfs (int u, int l, int r, int ql, int qr)
{
if (l>qr || r<ql) { return; }
if (ql<=l && r<=qr) { vec.push_back((Pnt){ u, l, r }); return; }
int md=(l+r)/2;
dfs(ls(u), l, md, ql, qr);
dfs(rs(u), md+1, r, ql, qr);
}
int main ()
{
// freopen("0test.in", "r", stdin);
// freopen("0test.out", "w", stdout);
scanf("%d", &n);
for (int i=1; i<=n; i++) { scanf("%lld", &x[i]); }
x[0]=-INF; x[n+1]=INF;
buildST(rt, 1, n, 0);
buildST(rt, 1, n, 1);
// x[l]*2-x[l-1] > cr
// x[r+1]-x[r]*2 >= -cl
scanf("%d", &Q);
while (Q--) {
int pos; scanf("%d", &pos);
ll ans=0;
int id=lower_bound(x+1, x+n+1, pos)-x;
if (id==n+1 || (id!=1 && x[id]-pos>=pos-x[id-1])) { id--; }
ans+=abs(pos-x[id]);
// 0 <- 1 ->
bool dir;
if (x[id]-x[id-1]<=x[id+1]-x[id]) { dir=0; }
else { dir=1; }
int idl=id, idr=id;
while (idl>1 || idr<n) {
if (idr==n || idl==1) { ans+=x[n]-x[1]; break; }
vec.clear();
if (!dir) {
dfs(rt, 1, n, 1, idl);
for (int i=vec.size()-1; i>=0; i--) {
int u=vec[i].u, l=vec[i].l, r=vec[i].r;
if (tr[0][u].mx>x[idr+1]) { idl=qry0(u, l, r, x[idr+1]); break; }
}
ans+=x[idr]-x[idl];
}
else {
dfs(rt, 1, n, idr, n);
for (int i=0; i<(int)vec.size(); i++) {
int u=vec[i].u, l=vec[i].l, r=vec[i].r;
if (tr[1][u].mx>=-x[idl-1]) { idr=qry1(u, l, r, x[idl-1]); break; } //>=!!!!!!!
}
ans+=x[idr]-x[idl];
}
dir^=1;
}
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: 8060kb
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: 0ms
memory: 8128kb
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: 0ms
memory: 8128kb
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: 8128kb
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: 0ms
memory: 6044kb
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: 8068kb
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: 1ms
memory: 5952kb
input:
1 964813969 1 24961702
output:
939852267
result:
ok 1 number(s): "939852267"
Test #8:
score: 0
Accepted
time: 1ms
memory: 6016kb
input:
1 492812692 1 492812692
output:
0
result:
ok 1 number(s): "0"
Test #9:
score: 0
Accepted
time: 1ms
memory: 5832kb
input:
1 819738491 1 871545564
output:
51807073
result:
ok 1 number(s): "51807073"
Test #10:
score: 0
Accepted
time: 0ms
memory: 6020kb
input:
1 964813971 1 925278587
output:
39535384
result:
ok 1 number(s): "39535384"
Test #11:
score: 0
Accepted
time: 1ms
memory: 7932kb
input:
2 253257833 492812697 1 801030938
output:
547773105
result:
ok 1 number(s): "547773105"
Test #12:
score: 0
Accepted
time: 1ms
memory: 8016kb
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: 8008kb
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: 5968kb
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: 8132kb
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
Wrong Answer
Dependency #1:
100%
Accepted
Test #16:
score: 0
Wrong Answer
time: 12ms
memory: 18020kb
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:
1258851191
result:
wrong answer 1st numbers differ - expected: '1253123755', found: '1258851191'
Subtask #3:
score: 0
Wrong Answer
Test #31:
score: 30
Accepted
time: 89ms
memory: 18024kb
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:
200107 999999991 202154 346046 379455 269768 313076 381369 366120 265794 363817 348433 342292 260613 302587 332141 311760 281789 345769 366459 218270 221124 225466 313243 322095 332977 281351 224651 257342 259560 206246 231269 316285 371811 394056 382486 202443 357928 359464 357158 354417 368006 326...
result:
ok 200000 numbers
Test #32:
score: 0
Accepted
time: 101ms
memory: 17968kb
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:
200107 999999991 214953 203176 263561 315480 345760 288169 362438 292732 224749 214412 299705 264321 211653 248956 233685 236984 306911 206078 236282 203851 343753 216241 366274 383291 227991 214501 208691 248280 282497 201835 302961 384269 339680 249381 395777 201468 253356 249808 316046 217202 336...
result:
ok 200000 numbers
Test #33:
score: 0
Accepted
time: 102ms
memory: 17932kb
input:
200000 0 100 101 102 103 104 105 106 107 108 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...
output:
200098 1000000000 200809 332026 340583 320747 327951 280466 335577 392195 262246 384764 279889 296343 206119 282306 382710 389025 369823 307624 382688 379733 319319 266016 316382 273064 390368 312448 210119 335070 205821 256717 233293 235566 200495 327143 380534 281176 293482 211483 317727 234273 21...
result:
ok 200000 numbers
Test #34:
score: 0
Accepted
time: 98ms
memory: 17844kb
input:
200000 9 109 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 182...
output:
200108 999999991 398935 342885 372407 268595 300075 371409 353777 253452 348389 342780 337158 251989 290087 326120 302345 280025 337667 354788 207572 219029 219537 312936 309352 322171 278794 215577 238037 256322 203016 217393 307132 363991 389419 367602 395084 350195 342074 354917 333585 353297 307...
result:
ok 200000 numbers
Test #35:
score: 0
Accepted
time: 96ms
memory: 17976kb
input:
200000 9 109 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 182...
output:
200108 999999991 399468 396515 254881 299064 337551 286690 358899 284471 214726 211350 282076 246510 393082 233179 230206 229157 287918 388371 216198 398026 326810 396152 352980 362859 207997 211382 207339 245208 279636 387108 287348 370846 326052 238182 377891 390157 238807 236535 303642 200314 331...
result:
ok 200000 numbers
Test #36:
score: 0
Accepted
time: 91ms
memory: 18020kb
input:
200000 0 100 102 103 104 105 106 107 108 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...
output:
200099 1000000000 400101 324295 330652 307228 323659 266967 326296 376082 254255 366054 279702 288698 394108 278540 364606 386882 367087 297310 377645 367863 306592 251530 299280 261817 381250 300696 395926 325927 202038 238905 217436 228164 390510 326430 365953 266838 281214 396382 308060 213534 39...
result:
ok 200000 numbers
Test #37:
score: 0
Accepted
time: 28ms
memory: 8020kb
input:
1 752274513 200000 0 1000000000 3062543 353824670 471209108 300038685 972824952 279683767 647873489 455102926 383075404 304797585 248935750 197299138 525182332 495865149 664082073 708206991 86351822 501205423 604244437 984963897 681547274 314559829 730183804 245318283 760613011 309037613 514660147 8...
output:
752274513 247725487 749211970 398449843 281065405 452235828 220550439 472590746 104401024 297171587 369199109 447476928 503338763 554975375 227092181 256409364 88192440 44067522 665922691 251069090 148030076 232689384 70727239 437714684 22090709 506956230 8338498 443236900 237614366 115943118 686592...
result:
ok 200000 numbers
Test #38:
score: 0
Accepted
time: 18ms
memory: 7880kb
input:
1 73 200000 0 1000000000 10 72 125 39 37 127 54 106 35 45 65 95 80 77 45 50 6 54 43 102 2 97 92 59 65 15 16 6 97 31 15 102 110 95 68 0 72 36 101 143 94 97 142 19 15 70 145 22 41 7 35 51 78 141 13 4 143 49 34 37 134 132 14 24 111 19 1 31 113 96 106 34 74 74 27 31 37 96 84 62 47 34 33 133 15 78 120 72...
output:
73 999999927 63 1 52 34 36 54 19 33 38 28 8 22 7 4 28 23 67 19 30 29 71 24 19 14 8 58 57 67 24 42 58 29 37 22 5 73 1 37 28 70 21 24 69 54 58 3 72 51 32 66 38 22 5 68 60 69 70 24 39 36 61 59 59 49 38 54 72 42 40 23 33 39 1 1 46 42 36 23 11 11 26 39 40 60 58 5 47 1 38 7 14 51 73 46 61 8 45 59 33 51 70...
result:
ok 200000 numbers
Test #39:
score: -30
Wrong Answer
time: 81ms
memory: 17888kb
input:
200000 67 98 181 270 354 429 496 561 572 671 696 787 856 935 1022 1065 1091 1129 1188 1256 1296 1316 1386 1388 1462 1495 1513 1563 1621 1665 1760 1790 1812 1855 1918 1971 1990 2087 2137 2234 2313 2329 2423 2501 2585 2642 2695 2795 2893 2990 3085 3095 3185 3279 3315 3327 3377 3454 3493 3553 3617 3662...
output:
10100896 999999933 14574238 13002253 19727669 11009705 15218711 13678079 18071902 18516120 13910578 13098664 12765541 19245270 18563620 19531507 17598566 16639075 18337352 14028651 11260968 14138243 18288313 14125110 18034945 17514062 15950989 17179910 10723293 17833318 17175872 16182912 17058697 17...
result:
wrong answer 57th numbers differ - expected: '13876864', found: '13877052'
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%