QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#36830#2448. Make Rounddog Happy_VeritasWA 112ms13044kbC++1.8kb2022-06-28 23:29:172022-06-28 23:29:18

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-06-28 23:29:18]
  • 评测
  • 测评结果:WA
  • 用时:112ms
  • 内存:13044kb
  • [2022-06-28 23:29:17]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
    int x=0;char c=getchar();
    while(c<'0'||c>'9') c=getchar();
    while(c>='0'&&c<='9'){
        x=x*10+c-'0';
        c=getchar();
    }
    return x;
}
const int N=300005;
int n,k,a[N],pre[N],nxt[N],t[N];
int solve(int l,int r){
    if(l>r) return 0;
    if(l==r) return (a[l]-1<=k);
    int mid=(l+r)/2,res=solve(l,mid-1)+solve(mid+1,r);
    {
        int maxpre=pre[mid],minlpos=mid,Mx=a[mid];
        for(int R=mid;R<=r;++R){
            Mx=max(Mx,a[R]);
            while(minlpos>=l&&a[minlpos]<=Mx) --minlpos; ++minlpos;
            maxpre=max(maxpre,pre[R]);
            res+=max(0ll,min(mid,R+k+1-Mx)-max(maxpre+1,minlpos)+1);
        }
    }
    {
        int minnxt=nxt[mid],maxrpos=mid,Mx=a[mid],L=mid-1;
        while(a[L]<=a[mid]&&L>=l){
            Mx=max(Mx,a[L]);
            minnxt=min(minnxt,nxt[L]);
            --L;
        }
        for(;L>=l;--L){
            Mx=max(Mx,a[L]);
            while(maxrpos<=r&&a[maxrpos]<=Mx) ++maxrpos; --maxrpos;
            minnxt=min(minnxt,nxt[L]);
            res+=max(0ll,min(minnxt-1,maxrpos)-max(mid,L-k-1+Mx)+1);
            // cout<<Mx<<' '<<minnxt<<' '<<maxrpos<<' '<<L<<' '<<res<<endl;
        }
    }
    // cout<<l<<' '<<r<<' '<<res<<endl;
    return res;
}
signed main(){
    int T=read();
    while(T--){
        n=read();k=read(); a[0]=a[n+1]=19260817;
        for(int i=1;i<=n;++i) a[i]=read(),pre[i]=t[i]=0,nxt[i]=n+1;
        for(int i=1;i<=n;++i) pre[i]=t[a[i]],t[a[i]]=i;
        for(int i=1;i<=n;++i) t[i]=n+1;
        for(int i=n;i>=1;--i) nxt[i]=t[a[i]],t[a[i]]=i;
        // for(int i=1;i<=n;++i) cout<<nxt[i]<<' '; cout<<endl;
        printf("%lld\n",solve(1,n));
    }
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 112ms
memory: 13044kb

input:

13
10000 9950
8745 9998 467 7434 1964 9375 9997 48 8597 2568 3761 9498 1576 6348 4819 4870 9997 9043 8623 2147 8768 9555 9709 2657 5124 2631 3010 2249 2212 2997 9996 4320 796 5189 5556 5548 5290 2026 5555 187 9090 9149 908 8714 5238 3236 3986 5510 8571 3020 5118 2522 2465 384 9105 1342 8220 8291 672...

output:

256343
4
2581
3108
9670
278088
5
2760
3208
360
453261899
755766289
759654215

result:

wrong answer 1st lines differ - expected: '224745', found: '256343'