QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#71687#3238. Just So You KnowchenshiRE 0ms0kbC++3.2kb2023-01-11 19:27:192023-01-11 19:27:21

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-11 19:27:21]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 0kb
  • [2023-01-11 19:27:19]
  • Submitted

answer

#include<cstdio>
#include<queue>
#include<utility>
#include<algorithm>
#include<iostream>
namespace iobuff{const int LEN=1e6;char in[LEN+5],out[LEN+5];char *pin=in,*pout=out,*ed=in,*eout=out+LEN;
inline char gc(){return pin==ed&&(ed=(pin=in)+fread(in,1,LEN,stdin),ed==in)?EOF:*pin++;}
inline void pc(char c){pout==eout&&(fwrite(out,1,LEN,stdout),pout=out);(*pout++)=c;}
inline void flush(){fwrite(out,1,pout-out,stdout),pout=out;}
template<typename T>inline void scan(T&x){static int f;static char c;
for(c=gc(),f=1,x=0;c<'0'||c>'9';c=gc()) f=(c=='-'?-1:1);for(;c>='0'&&c<='9';c=gc()) x=10*x+c-'0';x*=f;}
template<typename T>inline void putint(T x,char div){static char s[20];static int top;top=0;
for(x<0?pc('-'),x=-x:0;x;x/=10) s[top++]=x%10;for(!top?pc('0'),0:0;top--;) pc(s[top]+'0');pc(div);}}
using namespace iobuff;
using namespace std;
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
const int o=1e6+10;
int T,n,a[o],sa[o],rk[o],buc[o],x[o],y[o],cnt,height[o],len[o],p[o],mx,fa[o],s[o],sz[o],lst;
long long ans,g,tot,c[o];queue<pair<long long,long long> > q;vector<int> vec[o];
int fr(int x){return fa[x]==x?x:fa[x]=fr(fa[x]);}
inline void sufsort(){
	mx=105;
	for(int i=1;i<mx;++i) buc[i]=0;
	for(int i=1;i<=n;++i) ++buc[x[i]=s[i]];
	for(int i=2;i<mx;++i) buc[i]+=buc[i-1];
	for(int i=n;i;--i) sa[buc[x[i]]--]=i;
	for(int md=1;md<=n;md<<=1){
		cnt=0;
		for(int i=n-md+1;i<=n;++i) y[++cnt]=i;
		for(int i=1;i<=n;++i) if(sa[i]>md) y[++cnt]=sa[i]-md;
		for(int i=1;i<mx;++i) buc[i]=0;
		for(int i=1;i<=n;++i) ++buc[x[i]];
		for(int i=2;i<mx;++i) buc[i]+=buc[i-1];
		for(int i=n;i;--i) sa[buc[x[y[i]]]--]=y[i],y[i]=0;
		y[sa[1]]=cnt=1;
		for(int i=2;i<=n;++i) y[sa[i]]=((x[sa[i]]==x[sa[i-1]]&&x[sa[i]+md]==x[sa[i-1]+md])?cnt:++cnt);
		if(cnt==n) break;
		for(int i=1;i<=n;++i) x[i]=y[i];
		mx=cnt+1;
	}
};
inline void get_height(){
	for(int i=0;i<=n;++i) height[i]=0,rk[sa[i]]=i,vec[i].clear(),sz[i]=0;
	for(int i=1,j,k=0;i<=n;++i) if(rk[i]>1){
		if(k) --k;
		for(j=sa[rk[i]-1];j+k<=n&&i+k<=n&&s[i+k]==s[j+k];++k);
		++sz[height[rk[i]]=k];
	}
}
inline bool cmp(int A,int B){return height[A]<height[B];}
inline void ad(long long x,long long y){ans+=x*y;if(x<=n) c[x]+=y;else q.push(make_pair(x,y));}
int main(){
	for(scan(T);T--;){
		scan(n);
		cerr<<n<<" ";
		for(int i=1;i<=n;++i) scan(a[i]),s[i]=a[i]+1,c[i]=0;
		sufsort();get_height();
		for(int i=1;i<=n;++i) len[i]=n-sa[i]+1,s[fa[i]=i]=1;
		for(int i=0;i<=n;++i) if(sz[i]) vec[i].reserve(sz[i]);
		for(int i=2;i<=n;++i) vec[height[i]].push_back(i);
		for(int i=n,p,t;i+1;--i) for(int j=vec[i].size();j--;){
			t=fr(p=vec[i][j]);
			if(len[p-1]>height[p]) ad(s[p-1],len[p-1]-height[p]);
			if(len[t]>height[p]) ad(s[t],len[t]-height[p]);
			len[t]=height[p];s[fa[p-1]=t]+=s[p-1];
		}
		if(len[fr(1)]) ad(n,len[fr(1)]);
		ans=lst=0;
		for(int i=1;i<=n;++i) if(c[i]){
			if(lst) ad(i+lst,1),lst=0,--c[i];
			if(c[i]>1) ad(i*2,c[i]/2);
			if(c[i]&1) lst=i;
		}
		for(long long v,c;!q.empty();q.pop()){
			v=q.front().first;c=q.front().second;
			if(lst) ad(v+lst,1),lst=0,--c;
			if(c>1) ad(v*2,c/2);
			if(c&1) lst=v;
		}
		tot=n*(n+1ll)/2;g=gcd(ans,tot);
		ans/=g;tot/=g;
		if(tot==1) putint(ans,'\n');
		else putint(ans,'/'),putint(tot,'\n');
	}
	flush();
	return 0;
}

详细

Test #1:

score: 0
Runtime Error

input:

1000
1033
25 82 89 85 87 49 93 78 46 30 16 55 39 50 47 99 88 31 80 70 27 85 5 2 65 40 87 6 18 34 42 68 61 73 68 36 47 8 28 83 88 19 13 27 89 64 67 26 65 35 55 50 41 5 96 54 47 82 15 85 97 62 61 36 20 49 35 9 51 89 49 91 59 12 40 63 27 39 56 49 92 45 79 34 37 78 1 2 23 53 15 0 14 13 42 30 53 80 80 79...

output:


result: