QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#43910 | #4563. Radio Towers | 1kri | 17 | 584ms | 80624kb | C++11 | 2.7kb | 2022-08-11 16:40:36 | 2022-08-11 16:40:37 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include "towers.h"
#define inf 2000000000
using namespace std;
int n,h[100005];
int tot,s[100005];
struct node{
int l,r,val;
node(){
l=r=val=0;
return;
}
}tree[5000005];
int cnt,rt[100005];
int log_2[100005],st[100005][25];
int q[100005],tail;
int pl[100005],pr[100005];
vector<int> e[100005];
int st_ask(int l,int r){
if (l>r)return inf;
int w=log_2[r-l+1];
return min(st[l][w],st[r-(1<<w)+1][w]);
}
int larger(int x){
int l=1,r=tot,ans=0;
while(l<=r){
int mid=(l+r)/2;
if (s[mid]>=x)ans=mid,r=mid-1;
else l=mid+1;
}
return ans;
}
void ins(int &now,int nowl,int nowr,int pos){
int pre=now;
now=++cnt;
tree[now]=tree[pre];
tree[now].val++;
if (nowl==nowr)return;
int mid=(nowl+nowr)/2;
if (pos<=mid)ins(tree[now].l,nowl,mid,pos);
else ins(tree[now].r,mid+1,nowr,pos);
return;
}
int sgt_ask(int now,int nowl,int nowr,int lt,int rt){
if (now==0)return 0;
if (nowl>=lt&&nowr<=rt)return tree[now].val;
int mid=(nowl+nowr)/2,s=0;
if (mid>=lt)s+=sgt_ask(tree[now].l,nowl,mid,lt,rt);
if (mid+1<=rt)s+=sgt_ask(tree[now].r,mid+1,nowr,lt,rt);
return s;
}
void init(int _n,vector<int> _h){
n=_n;
for (int i=1;i<=n;i++)h[i]=_h[i-1];
h[0]=h[n+1]=inf;
for (int i=2;i<=n;i++)log_2[i]=log_2[i/2]+1;
for (int i=1;i<=n;i++)st[i][0]=h[i];
for (int w=1;(1<<w)<=n;w++)
for (int i=1;i+(1<<w)-1<=n;i++)
st[i][w]=min(st[i][w-1],st[i+(1<<(w-1))][w-1]);
tail=0;
q[0]=0;
for (int i=1;i<=n;i++){
while(tail>0&&h[q[tail]]<=h[i])tail--;
pl[i]=q[tail];
q[++tail]=i;
}
tail=0;
q[0]=n+1;
for (int i=n;i>=1;i--){
while(tail>0&&h[q[tail]]<h[i])tail--;
pr[i]=q[tail];
q[++tail]=i;
}
for (int i=1;i<=n;i++)s[++tot]=h[i]-max(st_ask(pl[i]+1,i-1),st_ask(i+1,pr[i]-1));
sort(s+1,s+1+tot);
for (int i=1;i<=n;i++)e[larger(h[i]-max(st_ask(pl[i]+1,i-1),st_ask(i+1,pr[i]-1)))].push_back(i);
for (int i=tot;i>=1;i--){
rt[i]=rt[i+1];
for (int j=0;j<(int)e[i].size();j++)ins(rt[i],1,n,e[i][j]);
}
return;
}
int max_towers(int l,int r,int d){
l++,r++;
d=larger(d);
int ans=sgt_ask(rt[d],1,n,l,r);
if (ans==0)return 1;
int ql=l,qr=r,pos=0;
while(ql<=qr){
int mid=(ql+qr)/2;
if (sgt_ask(rt[d],1,n,l,mid)>0)pos=mid,qr=mid-1;
else ql=mid+1;
}
if (h[pos]-max(st_ask(max(l,pl[pos]+1),pos-1),st_ask(pos+1,min(r,pr[pos]-1)))<d)ans--;
if (ans>0){
ql=l,qr=r,pos=0;
while(ql<=qr){
int mid=(ql+qr)/2;
if (sgt_ask(rt[d],1,n,mid,r)>0)pos=mid,ql=mid+1;
else qr=mid-1;
}
if (h[pos]-max(st_ask(max(l,pl[pos]+1),pos-1),st_ask(pos+1,min(r,pr[pos]-1)))<d)ans--;
}
return ans+1;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 82ms
memory: 74384kb
input:
59640 49885 57346 58504 87383 113182 129676 204090 205404 259925 276583 300332 324014 333675 359377 364049 408489 414852 428310 438038 440113 458193 554789 643468 666525 683112 690791 707313 720088 741028 748785 789826 796576 800966 832867 851750 861044 862283 900756 926925 939560 955678 965636 9740...
output:
1 2 1 1 2 1 1 1 1 1 1 2 1 1 2 1 1 2 1 1 1 1 2 2 1 1 2 1 2 1 2 2 1 1 1 2 1 1 1 1 1 1 1 2 2 2 1 2 2 1 2 2 1 1 1 1 1 2 1 2 1 1 1 1 2 1 1 2 1 2 1 2 1 1 2 2 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 2 2 2 1 1 1 2 1 1 1 2 1 1 2 1 1 1 2 2 1 2 1 1 2 1 1 1 2 1 1 2 1 1 1 1 1 1 2 ...
result:
wrong answer 4th lines differ - expected: '1', found: '2'
Subtask #2:
score: 0
Wrong Answer
Test #8:
score: 11
Accepted
time: 16ms
memory: 65936kb
input:
425 753881706 405729786 890889563 29736246 598281970 208352067 357783003 663497023 178397034 4832890 562140755 510307001 354540290 538848551 436879256 86659033 42928516 24145404 749159097 118423198 506851985 204895765 719719998 726244368 991372008 681703480 799303017 657138050 88278945 417801236 260...
output:
13
result:
ok 3 lines
Test #9:
score: 0
Accepted
time: 8ms
memory: 65452kb
input:
2000 510696791 617882876 373405425 518361747 407161508 435668375 559543221 465317236 38039460 717410075 714427583 977153243 679286738 23933545 750215417 37078782 973334934 244734879 243897181 603105656 981870220 85688930 807317304 901266308 225354691 737318933 824323690 365669439 111883771 153256479...
output:
292
result:
ok 3 lines
Test #10:
score: -11
Wrong Answer
time: 4ms
memory: 67020kb
input:
2000 516351740 512181903 200723571 993230512 160881035 858124753 539677115 120758992 855511696 883443323 930303372 707938300 186981787 145199071 581235758 65550786 7197175 474759320 732341567 517832089 220614631 428681162 168642809 331743780 689236970 514407524 725936494 447118446 628858360 36946526...
output:
92
result:
wrong answer 3rd lines differ - expected: '91', found: '92'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #65:
score: 0
Wrong Answer
time: 568ms
memory: 80032kb
input:
99308 491693640 24020487 317364185 726230755 737284540 951143270 709116045 641023337 360629062 964879440 47884022 532494780 803629825 635450854 688041998 573937055 113198481 191311841 929603572 636688 598629732 895342035 396521271 619919754 716589045 657789547 373121546 866402108 609316614 60046511 ...
output:
11903 4770 14278 13956 571 9308 4389 9 22097 16784 26037 2813 8487 16602 2029 6158 17236 29707 19863 12083 20816 18090 4195 11612 4623 6658 7660 624 9839 13012 14475 11799 14795 6365 7308 5981 13614 14208 15922 17325 6020 10291 1819 29076 3117 6638 5810 28747 14944 9541 5498 1015 5001 20938 305 1993...
result:
wrong answer 10675th lines differ - expected: '14958', found: '14957'
Subtask #5:
score: 17
Accepted
Test #86:
score: 17
Accepted
time: 76ms
memory: 70116kb
input:
23881 605288257 422163932 155875880 339929874 76049859 196344969 958160745 767945284 469191956 997116006 387749577 15911341 920437918 367576975 800789357 351557615 283723284 369507452 841548133 643412903 309731505 256549694 370065644 699518122 559017597 347646657 469353381 575240521 501893001 454519...
output:
7197 7063 150 5030 5227 7333 1778 6675 2012 5921 4878 7477 4598 2769 5360 6465 7660 7234 7794 2760 6321 7056 7302 4749 464 2029 5650 1973 6227 4900 4966 4990 3142 785 5818 3005 7705 6967 1940 5880 7201 4752 1278 6554 2951 894 6601 7019 7236 6076 5182 6579 2343 2070 4337 5744 4437 2262 6686 1739 7756...
result:
ok 31567 lines
Test #87:
score: 0
Accepted
time: 377ms
memory: 80404kb
input:
100000 187962236 252322706 659740540 756184857 615615021 870954164 997894181 924184575 178246679 206117936 948374169 611376809 940125697 583402158 621243496 179806768 420420048 261580744 495350370 179501503 624736464 865025098 132756697 396891347 254854635 384499314 232013282 699329403 718265326 972...
output:
21501 24099 33073 16936 24145 8440 674 23350 29618 2899 7659 19499 19027 10215 4083 14518 30601 23009 17970 7096 15472 32634 26673 29553 6232 11457 690 8753 7786 4078 28404 25386 28535 1752 5912 16456 18098 25382 30618 28242 30215 30920 19228 20981 27023 18696 16047 19091 7953 9832 13542 4224 26991 ...
result:
ok 100002 lines
Test #88:
score: 0
Accepted
time: 368ms
memory: 80116kb
input:
100000 195876641 146621733 341834495 380796725 369334549 293410542 978028075 874593626 703011075 519634832 164249958 637129162 298077642 409700388 597488029 208278772 746990129 51413696 131278404 949003744 715997226 208017329 494082201 972593011 718736913 14104256 281109734 780778410 380464107 29853...
output:
31327 32678 5845 12353 3257 8926 13111 9562 10067 19324 255 7803 6244 5462 17193 33299 5823 24299 31456 20379 13299 17670 10250 31047 750 28337 5058 5037 31225 2578 18079 32308 15960 21734 23722 17448 3403 22865 12869 22981 12521 27550 32677 8772 16024 27145 32107 20420 31630 25199 583 30494 13145 2...
result:
ok 100002 lines
Test #89:
score: 0
Accepted
time: 443ms
memory: 80436kb
input:
100000 140151127 703171223 64650609 807179656 91579199 616439566 262279532 635385641 182204773 746966272 29134735 694384584 151383885 835424004 374370699 839210095 26199233 802967114 424348660 929961627 334908843 613933030 264472963 967927306 374534013 795616963 181399017 942772713 325557168 6356971...
output:
16852 44989 5073 188 18334 719 37773 31991 27369 49758 2886 37462 2269 14671 36297 47833 45768 45948 44197 36763 13579 37257 34232 22326 19121 4483 3193 9572 44327 43476 37410 4641 9134 21884 17460 39750 31826 13138 6713 29509 28834 48569 47845 14636 42288 209 9318 7431 45730 16465 5906 40699 39638 ...
result:
ok 100002 lines
Test #90:
score: 0
Accepted
time: 431ms
memory: 80392kb
input:
100000 229371426 615845385 8395463 725670138 253945139 837481603 267122821 564928938 88384991 615119435 233045729 736737408 9623699 705904592 292693606 920163778 297466268 725313668 361252589 813252985 350864743 741659990 170849476 539562600 432839207 511464025 99353592 875179636 297454089 687124695...
output:
17581 24948 38391 14419 27799 4569 38668 35697 26067 49978 42190 1235 1655 28211 22625 47715 40160 39008 37550 19341 5003 109 10527 40699 48346 4305 5676 8370 23348 27672 31587 48842 49999 46869 20992 43858 6386 35113 50 46394 49096 24013 33036 49696 44127 30556 26524 3723 36254 9349 12089 2510 3087...
result:
ok 100002 lines
Test #91:
score: 0
Accepted
time: 380ms
memory: 80224kb
input:
100000 487111066 855860485 99041551 892763368 90402565 506637676 222215611 835773505 321823015 869201207 89953137 536799062 104579533 834586895 472040129 763002761 152483347 634595719 449887741 956583186 34700464 521025155 55345113 944384213 127641496 513194723 356649230 967880428 337980827 91463839...
output:
942 45725 29253 32000 34983 3056 10934 34915 6732 11677 1908 652 47087 1198 27913 18121 7533 3821 24817 31833 5715 2456 36255 41755 48827 46825 46456 9695 562 7920 24435 19004 5205 24363 3456 48946 23953 49466 31719 39841 12272 16871 42212 19612 38959 9101 5563 12587 43949 48475 41360 6428 41967 184...
result:
ok 100002 lines
Test #92:
score: 0
Accepted
time: 423ms
memory: 80440kb
input:
100000 27073748 576331364 400237255 795460519 71014022 637435072 214575137 823870913 216504420 807569134 433278403 608674530 363485760 723516242 157786468 990284424 191375275 730792204 290439949 971661182 370244883 986406055 345467763 738556373 233197961 953353962 129769517 642436238 381534949 97463...
output:
15228 45987 5889 540 24979 14594 39331 30269 9981 22404 3267 11420 12707 42431 49834 35779 22037 20640 28981 41713 13306 2152 44699 25014 49999 49722 28703 25852 31644 27995 42377 43981 46325 34863 25315 25298 48064 12187 614 35850 45155 47254 21988 7289 5643 47552 48834 14785 10748 44858 26283 2402...
result:
ok 100002 lines
Test #93:
score: 0
Accepted
time: 157ms
memory: 80608kb
input:
100000 14044 31568 48921 51214 59358 71379 100023 115598 139483 155653 157116 163984 169449 181325 188904 191112 194401 200495 208085 244825 258317 269389 271415 278442 294904 302861 331145 358689 365346 371514 371674 420312 426358 426926 439486 447109 449034 452747 459208 464379 471543 477242 48520...
output:
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 1 1 1 ...
result:
ok 100002 lines
Test #94:
score: 0
Accepted
time: 154ms
memory: 80624kb
input:
100000 999997134 999971880 999971447 999963682 999958496 999954233 999941005 999934956 999913043 999912124 999899751 999895915 999889723 999865869 999850495 999849430 999843930 999825051 999812617 999790616 999785641 999771255 999768902 999766470 999753769 999744896 999726315 999707943 999707638 999...
output:
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 1 1 1 ...
result:
ok 100002 lines
Test #95:
score: 0
Accepted
time: 213ms
memory: 80120kb
input:
100000 10308 12726 14970 29067 32105 43123 49977 68697 88015 88028 126474 130169 135685 137521 160062 169353 177310 194965 211656 230278 234919 235394 248590 252495 255260 261674 277375 302750 310249 323236 330372 331411 353695 359830 374529 382948 412643 433170 449860 454473 473256 476229 477424 48...
output:
5 3 5 5 1 5 1 2 1 3 3 5 3 5 5 5 5 2 3 5 5 1 5 1 1 2 3 5 5 2 2 5 5 1 1 4 1 1 1 5 5 1 1 1 1 5 5 3 5 5 1 1 3 5 3 5 5 3 4 4 5 1 2 3 1 4 5 3 5 3 5 5 1 4 2 3 5 5 1 3 1 3 5 5 4 1 5 2 5 1 1 3 5 5 1 3 1 5 5 5 5 3 5 1 5 2 1 4 5 4 1 5 4 1 5 3 2 5 1 5 2 5 5 2 5 1 2 5 1 3 5 2 3 1 4 1 3 5 4 4 1 2 5 3 5 3 2 5 1 1 ...
result:
ok 100002 lines
Test #96:
score: 0
Accepted
time: 231ms
memory: 80556kb
input:
100000 999999375 999993451 999991946 999986204 999984712 999978443 999965310 999963490 999950472 999950215 999935622 999934052 999920801 999884366 999878792 999871703 999841904 999839499 999835391 999831297 999828717 999815901 999773795 999769518 999747787 999736911 999729803 999726952 999716990 999...
output:
3 1 3 5 3 3 1 4 5 3 3 3 3 1 3 3 3 3 1 4 1 1 3 3 1 2 4 1 3 3 1 3 3 2 4 3 1 3 3 2 2 3 3 3 3 1 5 3 3 5 1 3 1 3 3 3 4 3 3 5 3 3 4 3 1 3 3 3 5 3 3 5 5 3 5 3 2 3 5 3 5 5 3 4 3 3 5 3 3 3 3 3 5 3 1 3 3 1 3 3 3 3 3 5 3 4 3 4 3 1 3 1 3 5 3 5 3 3 1 3 2 3 3 5 3 3 4 4 3 3 3 3 5 3 4 3 1 3 1 3 3 1 1 3 5 3 3 3 3 3 ...
result:
ok 100002 lines
Subtask #6:
score: 0
Wrong Answer
Test #97:
score: 0
Wrong Answer
time: 584ms
memory: 78868kb
input:
88768 238644804 620122421 789364401 899010695 885388612 437964772 845379533 657562749 773925456 625793781 916240972 291506550 379611161 905077982 629848170 530056471 520438258 806293637 326792996 785404568 74285074 565304193 846963319 63529729 804909008 212070492 69936548 656129389 408708069 3070450...
output:
7293 18702 4922 19044 23488 1992 20887 9156 21248 15708 115 11736 8529 19158 9407 9139 5401 20114 1699 3993 22639 5925 17883 12913 5726 12378 21617 15763 646 5418 16982 7639 6140 1776 6289 619 766 3080 8806 11541 7217 2650 15835 2238 2024 9705 23983 4664 8898 5006 2392 20170 8341 14535 16454 6623 18...
result:
wrong answer 16th lines differ - expected: '19157', found: '19158'
Subtask #7:
score: 0
Skipped
Dependency #1:
0%