QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#181630 | #3765. Make Rounddog *Very* Happy | 01team# | WA | 498ms | 95780kb | C++14 | 1.6kb | 2023-09-16 21:36:38 | 2023-09-16 21:36:40 |
Judging History
answer
#include<bits/stdc++.h>
#define N 1000005
#define LL long long
#define SZ(x) ((LL)(x.size()))
using namespace std;
long long read(){
long long q=0,w=1;
char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){q=q*10+(ch-'0');ch=getchar();}
return q*w;
}
void write(LL x){
if(x<0){putchar('-');x=(-x);}
if(x>9)write(x/10);
putchar('0'+x%10);
}
void writeln(LL x){write(x);puts("");}
void writecs(LL x){write(x);putchar(' ');}
int n,m,a[N],lg[N],Max[21][N];
int dif[N],ans[N];
int Argmax(int x,int y){return a[x]>a[y]?x:y;}
int Rangemax(int l,int r){
int k=lg[r-l+1];
return Argmax(Max[k][l],Max[k][r-(1<<k)+1]);
}
void Cartesian(int l,int r){
if(l==r)return void(ans[l]+=(a[l]-1>=m));
int Mid=Rangemax(l,r),lsiz=Mid-l,rsiz=r-Mid;
if(lsiz<rsiz){
for(int i=l;i<Mid;i++){
int lim=min(r,a[Mid]-m+i-1);
if(lim>=Mid)dif[Mid]++,dif[lim+1]--;
}
}
else{
for(int i=r;i>=Mid;i--){
int lim=max(l,m-a[Mid]+i+1);
if(lim<=Mid)ans[i]+=Mid-lim+1;
}
}
if(lsiz)Cartesian(l,Mid-1);
if(rsiz)Cartesian(Mid+1,r);
}
int main(){
while(scanf("%d%d",&n,&m)!=EOF){
for(int i=1;i<=n;i++)ans[i]=dif[i]=0;
for(int i=1;i<=n;i++)a[i]=read();
for(int i=2;i<=n;i++)lg[i]=lg[i>>1]+1;
iota(Max[0]+1,Max[0]+n+1,1);
for(int j=1;j<=lg[n];j++)
for(int i=1;i+(1<<j)-1<=n;i++)
Max[j][i]=Argmax(Max[j-1][i],Max[j-1][i+(1<<(j-1))]);
Cartesian(1,n);
for(int i=1;i<=n;i++)dif[i]+=dif[i-1];
for(int i=1;i<=n;i++)printf("%d ",ans[i]+dif[i]);
puts("");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 498ms
memory: 95780kb
input:
3 0 1 3 2 3 1 1 3 2 5 2 1 2 3 4 5 10 4 9 9 5 4 4 1 2 8 5 2 10 0 9 4 5 2 5 8 3 4 5 4 10 -2 5 10 10 3 6 6 10 2 4 5 10 0 1 10 2 5 8 3 7 2 2 3 10 8 10 1 4 8 8 4 2 1 6 2 10 -10 6 7 6 9 6 10 4 6 4 5 10 9 2 6 7 10 2 1 2 2 10 7 10 -6 8 9 2 10 7 2 1 8 6 1 10 8 6 10 2 8 1 7 8 8 8 9 10 -1 4 9 8 4 2 10 6 5 9 5 ...
output:
1 2 3 0 2 2 0 0 1 2 3 1 1 1 1 1 0 0 4 3 2 0 1 2 3 4 5 6 7 8 8 1 2 2 3 4 5 7 8 9 10 1 1 2 3 3 4 4 5 6 7 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 7 8 9 0 0 0 0 0 0 0 0 1 0 1 2 3 3 3 3 4 7 7 8 0 1 0 0 0 0 0 0 0 1 1 1 1 1 2 6 6 7 9 10 0 0 1 3 4 5 6 7 8 9 0 1 1 2 3 4 5 6 7 8 1 2 3 3 4 4 3 2 1 3 ...
result:
wrong answer 4th lines differ - expected: '1 2 3 2 2 1 0 4 4 2', found: '1 1 1 1 1 0 0 4 3 2 '