QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#398542#3765. Make Rounddog *Very* Happyxlwang#WA 294ms54240kbC++142.7kb2024-04-25 14:48:242024-04-25 14:48:29

Judging History

你现在查看的是最新测评结果

  • [2024-04-25 14:48:29]
  • 评测
  • 测评结果:WA
  • 用时:294ms
  • 内存:54240kb
  • [2024-04-25 14:48:24]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define fr(i,j,k) for(register int i=j;i<=k;++i)
#define rf(i,j,k) for(register int i=j;i>=k;--i)
#define foredge(i,j) for(register int i=head[j];i;i=e[i].nxt)
#define pb push_back
#define Times printf("Time:%.3lf\n",clock()/CLOCKS_PER_SEC)
using namespace std;
inline int read(){
	int x=0;
	bool f=0;
	char c=getchar();
	while(!isdigit(c)) f|=(c=='-'),c=getchar();
	while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f?-x:x;
}
inline void write(int x){
    if(x<0){putchar('-');x=-x;}
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void writeln(int x){write(x); puts("");}
inline void writepl(int x){write(x); putchar(' ');}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int randfind(int l,int r){return rnd()%(r-l+1)+l;}
//inline void init(){
//	int t=read();
//	while(t--) work();
//}
const int Maxn=1e6+10;
int n;
int a[Maxn],stk[Maxn],top;
int l[Maxn],r[Maxn],m;
int ans;
inline int getsum(int l,int r){
    if(l>r) return 0;
    return (l+r)*(r-l+1)/2;
}
int d1[Maxn],d2[Maxn];
int answer[Maxn];
inline void add1(int l,int r,int k){
    // cout<<"tp=1:"<<l<<' '<<r<<' '<<k<<endl;
    if(l<=r) d1[l]+=k,d1[r+1]-=k;
}
inline void add2(int l,int r,int k){
    // cout<<"tp=2:"<<l<<' '<<r<<' '<<k<<endl;
    if(l<=r) d2[l]+=k,d2[r+1]-=k,add1(r+1,n,-(r-l+1)*k);
}
inline void update(int l,int r,int id){
    int now=a[id]-m;
    if(now<=0) return;
    int ln1,ln2;ln1=id-l+1;
    int tot;tot=now+id-ln1;
    if(tot>=id) add1(id,tot,ln1);
    int nxt=tot+1;nxt=max(nxt,id);
    int s=min(ln1,now-(nxt-id));
    add1(nxt,r,s+1);
    add2(nxt,r,-1);
    // fr(i,id,r){
    //     if(i-id+1>now) break;
    //     answer[i]+=min(ln1,now-(i-id));
    // }
}
inline void work(){
    m=read();
    fr(i,1,n) a[i]=read(),answer[i]=0;
    fr(i,0,n+5) d1[i]=d2[i]=0;
    top=0;stk[top=1]=0;
    fr(i,1,n){
        while(top>1 && a[stk[top]]<=a[i]) --top;
        l[i]=stk[top];stk[++top]=i;
    }
    stk[top=1]=n+1;
    rf(i,n,1){
        while(top>1 && a[stk[top]]<a[i]) --top;
        r[i]=stk[top];stk[++top]=i;
    }
    // puts("");
    // fr(i,1,n) cout<<i<<' '<<l[i]<<' '<<r[i]<<endl;
    ans=0;fr(i,1,n) update(l[i]+1,r[i]-1,i);
    fr(i,1,n) d1[i]+=d1[i-1],d2[i]+=d2[i-1];
    fr(i,1,n) d2[i]+=d2[i-1];
    // fr(i,1,n) cout<<d2[i]<<' ';cout<<endl;
    fr(i,1,n) answer[i]=d1[i]+d2[i];
    fr(i,1,n) writepl(answer[i]);puts("");
}
inline void init(){
    while(cin>>n) work();
}
signed main(){
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
    init();
    // printf("\nTIME:%.3lf",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 294ms
memory: 54240kb

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 3 4 3 2 -1 -3 3 2 -1 
1 2 4 5 9 12 7 9 12 10 
1 3 6 7 9 12 19 19 20 23 
1 2 3 5 7 8 10 9 10 10 
1 1 0 -1 -2 -3 -4 -5 -6 -7 
1 3 4 8 9 15 16 18 19 21 
0 0 0 1 0 -1 -2 -3 1 0 
1 3 4 8 9 10 11 15 16 17 
0 2 1 0 -1 -2 -3 -4 -5 -5 
1 3 4 5 6 11 12 12 14 15 
1 2 3 6 7 12 13 15 1...

result:

wrong answer 4th lines differ - expected: '1 2 3 2 2 1 0 4 4 2', found: '1 3 4 3 2 -1 -3 3 2 -1 '