QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#71569#3238. Just So You Knowchenshi#ML 0ms0kbC++2.5kb2023-01-11 12:05:182023-01-11 12:05:20

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 12:05:20]
  • Judged
  • Verdict: ML
  • Time: 0ms
  • Memory: 0kb
  • [2023-01-11 12:05:18]
  • Submitted

answer

#include<cstdio>
#include<queue>
#include<utility>
#include<map>
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=2e6+10;
int T,n,h[o],cnt,z[o];long long ans,g,tot;priority_queue<pair<long long,int> > q;
struct Edge{int v,p;}e[o];
inline void ad(int U,int V){e[++cnt].v=V;e[cnt].p=h[U];h[U]=cnt;}
struct SAM{
	int len[o],lk[o],cnt,lst;map<char,int> ch[o];
	inline void init(){
		for(int i=0;i<=cnt;++i) h[i]=z[i]=0,ch[i].clear();
		lk[0]=-1;len[0]=0;cnt=lst=0;
	}
	inline void ins(int c){
		int cur=++cnt,p=lst,q,cln;
		for(len[cur]=len[lst]+1,z[lst=cur]=1;p+1&&ch[p].find(c)==ch[p].end();p=lk[p]) ch[p][c]=cur;
		if(p==-1){lk[cur]=0;return;}
		if(len[p]+1==len[q=ch[p][c]]){lk[cur]=q;return;}
		len[cln=++cnt]=len[p]+1;ch[cln]=ch[q];
		for(lk[cln]=lk[q],lk[cur]=lk[q]=cln;p+1&&ch[p][c]==q;p=lk[p]) ch[p][c]=cln;
	}
}sam;
void dfs(int nw){
	for(int i=h[nw];i;i=e[i].p) dfs(e[i].v),z[nw]+=z[e[i].v];
	if(nw) q.push(make_pair(-z[nw],sam.len[nw]-sam.len[sam.lk[nw]]));
}
int main(){
	for(scan(T);T--;ans=cnt=0,priority_queue<pair<long long,int> >().swap(q)){
		scan(n);sam.init();
		for(int i=1,a;i<=n;++i) scan(a),sam.ins(a);
		for(int i=1;i<=sam.cnt;++i) ad(sam.lk[i],i);
		dfs(0);
		continue;
		for(long long v,v_,c,c_;1;){
			v=q.top().first;c=q.top().second;q.pop();
			if(c>1){
				ans-=c/2*2*v;q.push(make_pair(v*2,c/2));
				if(c&1) q.push(make_pair(v,1));
			}
			else if(q.empty()) break;
			else{
				v_=q.top().first;c_=q.top().second;q.pop();
				ans-=v+v_;q.push(make_pair(v+v_,1));
				if(c_>1) q.push(make_pair(v_,c_-1));
			}
		}
		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
Memory Limit Exceeded

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: