QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#196453#7017. Sequences Generatorbrz#AC ✓1717ms366252kbC++204.9kb2023-10-01 17:35:242023-10-01 17:35:25

Judging History

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

  • [2023-10-01 17:35:25]
  • 评测
  • 测评结果:AC
  • 用时:1717ms
  • 内存:366252kb
  • [2023-10-01 17:35:24]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define maxn 1200010

#define cn getchar
template<class TY>void read(TY &x){
	x=0;int f1=1;char ch=cn();
	while(ch<'0'||ch>'9'){if(ch=='-')f1=-1;ch=cn();}
	while(ch>='0'&&ch<='9')x=x*10+(ch-'0'),ch=cn(); x*=f1;
}
template<class TY>void write2(TY x){
	if(x>9)write2(x/10);
	putchar(x%10+'0');
}
template<class TY>void write(TY x){
	if(x<0)putchar('-'),x=-x;
	write2(x);
}
int L[maxn>>2],R[maxn>>2];
double prob[maxn>>2][11];
double Prob[maxn>>2];
int sa[maxn],fir[maxn],sec[maxn],c[maxn];
int s[maxn], t[maxn];
void get_sa(const int N){
	int m=N;
	for(int i=1;i<=m;i++) c[i] = 0;
	for(int i=1;i<=N;i++) c[fir[i]=s[i]]++;
	for(int i=1;i<=m;i++) c[i] += c[i-1];
	for(int i=1;i<=N;i++) sa[c[fir[i]]--] = i;
	for(int len=1;len<N;len<<=1){
		int tot=0;
		for(int i=1;i<=N;i++)
			if(sa[i]+len > N) sec[++tot] = sa[i];
		for(int i=1;i<=N;i++)
			if(sa[i]-len > 0) sec[++tot] = sa[i]-len;
		
		for(int i=1;i<=m;i++) c[i]=0;
		for(int i=1;i<=N;i++) c[fir[i]]++;
		for(int i=1;i<=m;i++) c[i] += c[i-1];
		for(int i=N;i>=1;i--) sa[c[fir[sec[i]]]--] = sec[i];
		
		for(int i=1;i<=N;i++) swap(fir[i], sec[i]); m=0;
		for(int i=1;i<=N;i++)
			if(i == 1 || sec[sa[i]] != sec[sa[i-1]] || sec[sa[i]+len] != sec[sa[i-1]+len])
				fir[sa[i]] = ++m;
			else fir[sa[i]] = m;
		
		if(m == N) return;
	}
}
int rk[maxn],h[maxn];
void get_height(int N){
	for(int i=1;i<=N;i++)
		rk[sa[i]] = i;
	int k = 0;
	for(int i=1;i<=N;i++){
		if(rk[i] == 1){
			h[rk[i]] = 0;
			continue;
		}
		if(k) k--;
		while(s[i+k] == s[sa[rk[i]-1]+k]) k++;
		h[rk[i]] = k;
	}
}
int log_2[maxn],st[maxn][22];
void get_st(int N){
	for(int i=2;i<=N;i++)
		log_2[i] = log_2[i>>1] + 1;
	for(int i=1;i<=N;i++)
		st[i][0] = h[i];
	for(int j=1;j<=19;j++)
		for(int i=1;i<=N-(1<<j)+1;i++)
			st[i][j] = min(st[i][j-1], st[i+(1<<j-1)][j-1]);
}
int get_lcp(int x,int y){
	x = rk[x], y = rk[y];
	if(x>y) swap(x,y); x++;
	int lg = log_2[y-x+1];
	return min(st[x][lg], st[y-(1<<lg)+1][lg]);
}
struct CatTree{
	double pre[22][maxn],suf[22][maxn];
	void build(int dep,int l,int r){
		if(l==r){
			pre[dep][l] = suf[dep][l] = Prob[l];
			return;
		}
		int mid=l+r>>1;
		build(dep+1,l,mid);
		build(dep+1,mid+1,r);
		double p = 1;
		for(int i=l;i<=r;i++)
			p *= Prob[i], pre[dep][i] = p;
		p = 1;
		for(int i=r;i>=l;i--)
			p *= Prob[i], suf[dep][i] = p;
	}
	double query(int dep,int l,int r,int x,int y){
		if(l == r) return pre[dep][l];
		int mid=l+r>>1;
		if(y<=mid) return query(dep+1,l,mid,x,y);
		else if(x>mid) return query(dep+1,mid+1,r,x,y);
		else return suf[dep+1][x] * pre[dep+1][y];
	}
}tr;

int main()
{
	// int st=clock();
	// freopen("data.txt","r",stdin);
	// freopen("mine.txt","w",stdout);
	int Te;read(Te);
	for(int Test=1;Test<=Te;Test++){
		int n,m;
		read(n);read(m);
		for(int i=1;i<=n+1;i++)
			for(int j=0;j<=9;j++)
				prob[i][j] = 0;
		for(int i=1;i<=n;i++){
			read(L[i]);read(R[i]);
			int ma=0;
			for(int j=L[i];j<=R[i];j++){
				int x; read(x);
				prob[i][j-L[i]] = x/1000000000.0;
				if(prob[i][j-L[i]] > prob[i][ma]) ma = j-L[i];
			}
			s[i] = ma + L[i];
			Prob[i] = prob[i][ma];
		}
		for(int i=1;i<=m;i++){
			read(t[i]);
			s[i+n] = t[i];
		}
		for(int i=n+m+1;i<=2*(n+m);i++) s[i]=0;
		printf("Case #%d:\n",Test);
		get_sa(n+m); get_height(n+m); get_st(n+m);
		// for(int i=1;i<=n+m;i++)
		// 	printf("%d ",sa[i]); puts("");
		// for(int i=1;i<=n+m;i++)
		// 	printf("%d ",rk[i]); puts("");
		// for(int i=1;i<=n+m;i++)
		// 	printf("%d ",h[i]); puts("");
		// printf("%d %d\n",st[3][0],st[4][0]);
		
		int up = 1;
		while(up <= n) up<<=1;
		s[n+1] = 1;
		prob[n+1][0] = 0;
		tr.build(0,0,up-1);
		// fprintf(stderr,"2\n");
		auto in=[&](int x,int y){
			return y >= L[x] && y <= R[x];
		};
		for(int i=1;i<=n-m+1;i++){
			double ans = 1;
			int len = 0;
			while(len < m && ans >= 1e-10){
				int p = get_lcp(i+len, n+1+len);
				// fprintf(stderr,"p : %d\n",p);
				if(p) ans *= tr.query(0,0,up-1, i+len,i+len+p-1);
				if(len + p < m){
					if(!in(i+len+p, t[1+len+p])){
						ans = 0; break;
					}
					ans *= prob[i+len+p][t[1+len+p] - L[i+len+p]];
					len += p+1;
				}else{
					len += p;
				}
			}
			printf("%.12lf\n",ans);
		}
		// fprintf(stderr,"finish!\n");
	}
	// fprintf(stderr,"%d\n",clock()-st);
}
/*
3
5 3
1 3 100000000 200000000 700000000
1 3 600000000 150000000 250000000
1 3 333333333 333333334 333333333
3 4 450000000 550000000
1 3 999999998 1 1
1 2 3

6 4
4 6 100000000 200000000 700000000
4 6 200000000 200000000 600000000
4 6 300000000 400000000 300000000
4 6 400000000 300000000 300000000
4 6 500000000 200000000 300000000
4 6 500000000 100000000 400000000
4 5 5 6

5 3
1 1 1000000000
2 2 1000000000
3 3 1000000000
4 4 1000000000
5 5 1000000000
1 2 3

1
5 2
1 1 1000000000
1 1 1000000000
1 1 1000000000
1 1 1000000000
1 1 1000000000
1 1
*/

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 42576kb

input:

1
5 3
1 3 100000000 200000000 700000000
1 3 600000000 150000000 250000000
1 3 333333333 333333334 333333333
3 4 450000000 550000000
1 3 999999998 1 1
1 2 3

output:

Case #1:
0.004999999995
0.090000000180
0.000000000000

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 1310ms
memory: 364320kb

input:

4015
20 8
1 3 373586118 8354633 618059249
1 3 158307273 451097738 390594989
1 3 9506857 445819337 544673806
1 3 671557685 235269904 93172411
1 3 326363633 299898227 373738140
1 3 364711536 50092575 585195889
1 3 69986237 720301720 209712043
1 3 718630973 214486040 66882987
1 3 120012062 348911423 53...

output:

Case #1:
0.000000031810
0.000002823479
0.000010008852
0.000011973127
0.000060802296
0.000016354302
0.000203617362
0.000001939677
0.000004082070
0.000017787865
0.000013792107
0.000009732823
0.000159429270
Case #2:
0.000000251561
0.000000570390
0.000001173172
0.000086517950
0.000008236994
0.0003159568...

result:

ok 913392 lines

Test #3:

score: 0
Accepted
time: 1717ms
memory: 366252kb

input:

7
200000 133333
11 13 999999992 7 1
57 61 999999996 3 1 0 0
61 65 5 999999990 1 2 2
12 13 999999995 5
74 76 3 4 999999993
57 61 1 1 1 3 999999994
41 45 1 0 0 0 999999999
15 16 999999998 2
14 17 999999997 1 1 1
48 52 2 0 999999997 0 1
40 42 8 0 999999992
1 2 1 999999999
10 14 1 0 999999997 2 0
35 36 ...

output:

Case #1:
0.999298273331
0.000000000000
0.000000000000
0.000000000000
0.000000000000
0.000000000000
0.000000000000
0.000000000000
0.000000000000
0.000000000000
0.000000000000
0.000000000000
0.000000000000
0.000000000000
0.000000000000
0.000000000000
0.000000000000
0.000000000000
0.000000000000
0.0000...

result:

ok 466683 lines