QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#43917 | #4563. Radio Towers | Y25t# | 0 | 440ms | 321112kb | C++11 | 2.6kb | 2022-08-11 17:04:46 | 2024-05-26 01:04:51 |
Judging History
answer
#include"towers.h"
#include<bits/stdc++.h>
#define N 100005
#define W 19
struct node{
int val;
node *son[2];
node(){
val=0,son[0]=son[1]=0;
}
};
inline node *ins(node *q,int L,int R,int x){
node *p=new node();
if(q)
*p=*q;
p->val++;
if(L==R)
return p;
int mid=(L+R)>>1;
x<=mid?p->son[0]=ins(p->son[0],L,mid,x):p->son[1]=ins(p->son[1],mid+1,R,x);
return p;
}
inline int sum(node *p,int L,int R,int l,int r){
if(L>r||R<l||!p)
return 0;
if(l<=L&&R<=r)
return p->val;
int mid=(L+R)>>1;
return sum(p->son[0],L,mid,l,r)+sum(p->son[1],mid+1,R,l,r);
}
node *rt[N],*F[N],*G[N];
int n,a[N];
int lg[N],st[N][W];
inline int mx(int L,int R){
if(!L||R>n)
return 1e9;
int k=lg[R-L+1];
return std::max(st[L][k],st[R-(1<<k)+1][k]);
}
int l[N][W],r[N][W];
std::stack<int> s;
int f[N],g[N],h[N];
void init(int n_,std::vector<int> A){
n=n_;
for(int i=1;i<=n;i++)
a[i]=A[i-1];
lg[0]=-1;
for(int i=1;i<=n;i++)
lg[i]=lg[i>>1]+1;
for(int i=1;i<=n;i++)
st[i][0]=a[i];
for(int j=1;j<W;j++) for(int i=1;i+(1<<j)-1<=n;i++)
st[i][j]=std::max(st[i][j-1],st[i+(1<<(j-1))][j-1]);
for(int i=1;i<=n;i++){
while(s.size()&&a[s.top()]>a[i])
r[s.top()][0]=i,s.pop();
s.emplace(i);
}
while(s.size())
r[s.top()][0]=n+1,s.pop();
r[n+1][0]=n+1;
for(int i=n;i;i--){
while(s.size()&&a[s.top()]>a[i])
l[s.top()][0]=i,s.pop();
s.emplace(i);
}
while(s.size())
l[s.top()][0]=0,s.pop();
l[0][0]=0;
for(int j=1;j<W;j++) for(int i=0;i<=n+1;i++)
l[i][j]=l[l[i][j-1]][j-1],r[i][j]=r[r[i][j-1]][j-1];
for(int i=1;i<=n;i++)
f[i]=mx(l[i][0],i)-a[i],g[i]=mx(i,r[i][0])-a[i],h[i]=std::min(f[i],g[i]);
for(int i=1;i<=n;i++)
rt[i]=ins(rt[i-1],0,1e9,h[i]);
for(int i=n;i;i--)
G[i]=ins(G[r[i][0]],0,1e9,g[i]);
for(int i=1;i<=n;i++)
F[i]=ins(F[l[i][0]],0,1e9,f[i]);
// for(int i=1;i<=n;i++)
// printf("%d ",h[i]);
// puts("");
// for(int i=1;i<=n;i++)
// printf("%d ",sum(rt[i],0,1e9,0,1e9));
// puts("");
}
int max_towers(int L,int R,int D){
if(L==R)
return 1;
L++,R++;
// printf("?%d %d %d\n",L,R,D);
int res=sum(rt[R],0,1e9,D,1e9)-sum(rt[L-1],0,1e9,D,1e9);
// printf("*%d\n",res);
int u=L;
for(int i=W-1;~i;i--) if(r[r[u][i]][0]<=R&&f[r[u][i]]<D)
u=r[u][i];
if(r[u][0]<=R&&f[u]<D)
// printf("@%d %d\n",u,r[u][0]),
res+=sum(G[L],0,1e9,D,1e9)-sum(G[r[u][0]],0,1e9,D,1e9);
u=R;
for(int i=W-1;~i;i--) if(l[l[u][i]][0]>=L&&g[l[u][i]]<D)
u=l[u][i];
if(l[u][0]>=L&&g[u]<D)
res+=sum(F[R],0,1e9,D,1e9)-sum(F[l[u][0]],0,1e9,D,1e9);
if(l[u][0]>=L)
u=l[u][0];
if(h[u]<D)
res++;
return res;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 4
Accepted
time: 144ms
memory: 198548kb
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 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 2 2 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 47004 lines
Test #2:
score: -4
Wrong Answer
time: 273ms
memory: 321112kb
input:
100000 2578 13067 19114 20399 28997 31651 32660 44354 74124 80988 88107 95439 96029 102645 103539 132139 137628 158023 174859 192033 205256 217839 227259 243992 248025 260099 283750 285030 294864 297371 303073 333910 343091 343725 359151 361656 361691 386777 414415 419149 425074 433963 447813 448681...
output:
1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
wrong answer 15602nd lines differ - expected: '1', found: '2'
Subtask #2:
score: 0
Wrong Answer
Test #8:
score: 11
Accepted
time: 0ms
memory: 13300kb
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
Wrong Answer
time: 4ms
memory: 19916kb
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:
293
result:
wrong answer 3rd lines differ - expected: '292', found: '293'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #65:
score: 0
Wrong Answer
time: 440ms
memory: 318880kb
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 13957 571 9308 4390 9 22097 16784 26037 2813 8488 16602 2030 6158 17237 29707 19864 12084 20816 18091 4195 11612 4623 6658 7660 624 9840 13012 14475 11799 14795 6366 7308 5981 13614 14208 15922 17325 6020 10291 1820 29077 3117 6639 5810 28747 14945 9541 5498 1015 5002 20938 305 1993...
result:
wrong answer 6th lines differ - expected: '13956', found: '13957'
Subtask #5:
score: 0
Wrong Answer
Test #86:
score: 0
Wrong Answer
time: 48ms
memory: 86992kb
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 151 5030 5227 7333 1779 6675 2012 5921 4878 7477 4598 2769 5360 6465 7660 7234 7794 2760 6321 7056 7302 4749 465 2029 5650 1974 6227 4900 4966 4990 3142 786 5818 3005 7705 6967 1941 5880 7201 4752 1279 6554 2951 895 6601 7019 7236 6076 5182 6579 2343 2070 4337 5744 4437 2262 6686 1740 7756...
result:
wrong answer 5th lines differ - expected: '150', found: '151'
Subtask #6:
score: 0
Wrong Answer
Test #97:
score: 0
Wrong Answer
time: 287ms
memory: 287836kb
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:
7294 18702 4922 19044 23488 1992 20888 9156 21248 15709 116 11736 8530 19157 9407 9139 5401 20114 1699 3993 22639 5925 17883 12913 5726 12378 21617 15763 647 5418 16982 7639 6140 1776 6289 619 766 3079 8807 11542 7217 2650 15835 2238 2024 9705 23983 4664 8899 5006 2392 20170 8341 14535 16454 6623 18...
result:
wrong answer 3rd lines differ - expected: '7293', found: '7294'
Subtask #7:
score: 0
Skipped
Dependency #1:
0%