QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#43807 | #4563. Radio Towers | fecto_elfilis | 0 | 109ms | 50472kb | C++ | 3.1kb | 2022-08-11 10:02:50 | 2022-08-11 10:02:52 |
Judging History
answer
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
const int N=100010,M=4000010;
int n,tot,cnt,las,nx[N],pre[N],h[N],rt[N],val[N],nv[N],ch[M][2],siz[M],lg[N],st[N][20],st2[N][20];
priority_queue < pair<int,int> > q;
map <int,int> mp;
int gtmx (int l,int r) {
int k=lg[r-l+1];
return max(st[l][k],st[r-(1<<k)+1][k]);
}
int gtmn (int l,int r) {
int k=lg[r-l+1];
return min(st2[l][k],st2[r-(1<<k)+1][k]);
}
void upd (int i) {
nv[i]=0x3f3f3f3f;
if (nx[i]) {nv[i]=min(nv[i],gtmx(i+1,nx[i]-1)-h[i]+1);}
if (pre[i]) {nv[i]=min(nv[i],gtmx(pre[i]+1,i-1)-h[i]+1);}
q.push(make_pair(-nv[i],i));
}
int modify (int rt,int l,int r,int pos,int v) {
int p=++tot;
siz[p]=siz[rt]+v;
if (l==r) {return p;}
int mid=(l+r)>>1;
if (pos<=mid) {
ch[p][0]=modify(ch[rt][0],l,mid,pos,v);
ch[p][1]=ch[rt][1];
} else {
ch[p][0]=ch[rt][0];
ch[p][1]=modify(ch[rt][1],mid+1,r,pos,v);
}
return p;
}
int query (int rt,int l,int r,int xl,int xr) {
if (xl<=l&&r<=xr) {return siz[rt];}
if (xr<l||r<xl) {return 0;}
int mid=(l+r)>>1;
return query(ch[rt][0],l,mid,xl,xr)+query(ch[rt][1],mid+1,r,xl,xr);
}
int querynx (int rt,int l,int r,int pos) {
if (r<pos||!siz[rt]) {return n+1;}
if (l==r) {return l;}
int mid=(l+r)>>1,tmp=querynx(ch[rt][0],l,mid,pos);
if (tmp<=n) {return tmp;}
else {return querynx(ch[rt][1],mid+1,r,pos);}
}
int querypre (int rt,int l,int r,int pos) {
if (l>pos||!siz[rt]) {return 0;}
if (l==r) {return l;}
int mid=(l+r)>>1,tmp=querypre(ch[rt][1],mid+1,r,pos);
if (tmp) {return tmp;}
else {return querypre(ch[rt][0],l,mid,pos);}
}
void init (int N,vector <int> H) {
n=N,las=0,val[0]=1,lg[0]=-1;
for (int i=1;i<=n;i++) {lg[i]=lg[i>>1]+1,st[i][0]=st2[i][0]=h[i]=H[i-1],mp[h[i]]=i;}
for (int i=1;i<=18;i++) {
for (int j=1;j+(1<<i)-1<=n;j++) {
st[j][i]=max(st[j][i-1],st[j+(1<<(i-1))][i-1]);
st2[j][i]=min(st2[j][i-1],st2[j+(1<<(i-1))][i-1]);
}
}
for (int i=1;i<=n;i++) {
if ((i==1||h[i-1]>h[i])&&(i==n||h[i+1]>h[i])) {
pre[i]=las,nx[las]=i;
rt[0]=modify(rt[0],1,n,i,1),las=i;
}
}
pre[0]=las;
for (int i=las;i;i=pre[i]) {upd(i);}
las=1;
while (q.size()) {
pair<int,int> a=q.top();
q.pop();
int x=a.second,v=-a.first;
if (nv[x]!=v) {continue;}
if (v==las) {rt[cnt]=modify(rt[cnt],1,n,x,-1);}
else {
val[++cnt]=las=v;
rt[cnt]=modify(rt[cnt-1],1,n,x,-1);
}
nx[pre[x]]=nx[x];
pre[nx[x]]=pre[x];
if (pre[x]) {upd(pre[x]);}
if (nx[x]) {upd(nx[x]);}
}
}
int max_towers (int L, int R, int D) {
L++,R++;
int l=0,r=cnt;
while (l<r) {
int mid=(l+r+1)>>1;
if (D>=val[mid]) {l=mid;}
else {r=mid-1;}
}
int res=query(rt[l],1,n,L,R),fir=querynx(rt[l],1,n,L),las=querypre(rt[l],1,n,R);
if (fir>R) {
int mid=mp[gtmx(L,R)];
if (mid>L&&mid<R&&h[mid]-gtmn(L,mid-1)>=D&&h[mid]-gtmx(mid+1,R)>=D) {res+=2;}
else {res++;}
} else {
if (fir>L+1) {
int mid=mp[gtmx(L+1,fir-1)];
if (h[mid]-gtmn(L,mid-1)>=D) {res++;}
}
if (las<R-1) {
int mid=mp[gtmx(las+1,R-1)];
if (h[mid-gtmn(mid+1,R)]>=D) {res++;}
}
}
return res;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 109ms
memory: 18468kb
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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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:
wrong answer 14th lines differ - expected: '2', found: '1'
Subtask #2:
score: 0
Runtime Error
Test #8:
score: 11
Accepted
time: 0ms
memory: 6168kb
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: -11
Runtime Error
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:
result:
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Runtime Error
Test #65:
score: 0
Runtime Error
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:
result:
Subtask #5:
score: 0
Wrong Answer
Test #86:
score: 0
Wrong Answer
time: 106ms
memory: 50472kb
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:
7141 6989 -42030 4134 4447 7292 -5785 6522 -4452 5517 3881 7453 3399 -1367 4663 6258 7647 7183 7788 -1401 6082 6981 7261 3654 -22028 -4349 5107 -4617 5957 3917 4021 4060 -158 -14978 5374 -561 7694 6869 -4815 5461 7147 3658 -9296 6380 -722 -13279 6434 6932 7185 5742 4375 6408 -2986 -4193 2862 5262 30...
result:
wrong answer 3rd lines differ - expected: '7197', found: '7141'
Subtask #6:
score: 0
Runtime Error
Test #97:
score: 0
Runtime Error
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:
result:
Subtask #7:
score: 0
Skipped
Dependency #1:
0%