QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#931954#7036. Can You Solve the Harder Problem?louhao088WA 2209ms125688kbC++232.7kb2025-03-11 23:34:442025-03-11 23:34:46

Judging History

This is the latest submission verdict.

  • [2025-03-11 23:34:46]
  • Judged
  • Verdict: WA
  • Time: 2209ms
  • Memory: 125688kb
  • [2025-03-11 23:34:44]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define lowbit(i) (i&(-i))
#define fi first
#define se second
#define pi pair<int,int>
#define mp make_pair
#define ls (rt<<1)
#define rs (rt<<1|1)
#define mid (l+r>>1)
const int maxn=5e5+5;
inline int read(){
	char ch=getchar();int x=0;bool f=0;
	for(;!isdigit(ch);ch=getchar())if(ch=='-')f=1;
	for(;isdigit(ch);ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
	if(f==1)x=-x;return x;
}
vector<pi>Q[maxn];
long long ans=0,c[maxn*4],s[maxn*4],tag[maxn*4];
int a[maxn],n,T,pos[maxn];
void build(int rt,int l,int r){
    c[rt]=s[rt]=tag[rt]=0;
    if(l==r){return;}
    build(ls,l,mid),build(rs,mid+1,r);
}
void pushx(int rt,int l,int r,int x){
    tag[rt]=x,c[rt]=x;s[rt]=(r-l+1)*x;
}
void push(int rt,int l,int r){
    if(tag[rt]){
        pushx(ls,l,mid,tag[rt]);
        pushx(rs,mid+1,r,tag[rt]);
        tag[rt]=0;
    }
}
void change(int rt,int l,int r,int L,int R,int x){
    if(l>R||r<L){return ;}
    if(l>=L&&r<=R){
        pushx(rt,l,r,x);
        return ;
    }
    push(rt,l,r);
    change(ls,l,mid,L,R,x),change(rs,mid+1,r,L,R,x);
    c[rt]=min(c[ls],c[rs]);s[rt]=s[ls]+s[rs];
}
int query(int rt,int l,int r,int L,int R){
    if(l>R||r<L){return 0;}
    //cout<<R<<" "<<L<<" "<<l<<" "<<r<<" "<<s[rt]<<endl;
    if(l>=L&&r<=R)return s[rt];
    push(rt,l,r);
    return query(ls,l,mid,L,R)+query(rs,mid+1,r,L,R);
}
int find(int rt,int l,int r,int x){
    if(l==r)return l;
    push(rt,l,r);
    if(c[ls]<x){
        return find(ls,l,mid,x);
    }
    else return find(rs,mid+1,r,x);
}
struct Sam
{
	unordered_map<int,int> ch[maxn];
    int len[maxn],fa[maxn];
	int t=1,tot=1;
    void clear(){
        for(int i=1;i<=tot;i++)len[i]=fa[i]=0,ch[i].clear();
        t=1,tot=1;
    }
	void ins(int x,int id)
	{
		int p=t;t=++tot;len[t]=len[p]+1;pos[t]=id;
		for(;p&&!ch[p][x];p=fa[p])ch[p][x]=t;
		if(!p){fa[t]=1;return;}int q=ch[p][x];
		if(len[q]==len[p]+1){fa[t]=q;return;}
		len[++tot]=len[p]+1;fa[tot]=fa[q];
        fa[q]=fa[t]=tot;pos[tot]=id;
		ch[tot]=ch[q];
		for(int i=p;ch[i][x]==q;i=fa[i])ch[i][x]=tot;
	}
    void work(){
        for(int i=2;i<=tot;i++){
            Q[pos[i]].pb(mp(pos[i]-len[i]+1,pos[i]-len[fa[i]]));
        }
        build(1,1,n);
        for(int i=1;i<=n;i++){
            int k=find(1,1,n,a[i]);
            change(1,1,n,k,i,a[i]);
            for(auto j:Q[i]){
                ans+=query(1,1,n,j.fi,j.se);
            }
        }
    }
	
}S;
void solve(){
    S.clear();
    n=read();ans=0;
    for(int i=1;i<=n;i++)a[i]=read(),S.ins(a[i],i);
    S.work();
    for(int i=1;i<=n;i++)Q[i].clear();
    cout<<ans<<endl;
}

signed main(){
    T=read();
    while(T--)solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 5ms
memory: 46040kb

input:

2
3
1 2 3
3
2 3 3

output:

14
14

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 2209ms
memory: 125688kb

input:

1000
407
205460 200518 200561 199235 198814 198136 198802 206763 198795 200705 205862 209366 204017 209481 206300 198499 197364 200897 208928 196983 205605 206396 205140 201050 199886 207314 196947 207905 204999 203288 200298 198594 198286 197714 206506 203962 197628 201127 206380 199090 200711 2063...

output:

17377263880
484769420621
1469039857
473739194467
490764968536
305434410403
488123854116
494441224927
484272937511
482411215077
34438338505
225764586244
494494400870
492874976740
486779601551
483167680203
341192630235
492747353987
491280077388
9765154255
491745355442
120812820486
487737922489
4725166...

result:

wrong answer 163rd lines differ - expected: '19215921038327717', found: '5451446321061'