QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#196390 | #7017. Sequences Generator | brz# | RE | 0ms | 36652kb | C++20 | 4.3kb | 2023-10-01 16:43:59 | 2023-10-01 16:43:59 |
Judging History
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);
}
double prob[maxn][11];
int sa[maxn],fir[maxn],sec[maxn],c[maxn];
int s[maxn], t[maxn];
void get_sa(const int N){
int m=10;
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++){
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][20];
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<=18;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]);
}
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[20][maxn],suf[20][maxn];
void build(int dep,int l,int r){
if(l==r){
pre[dep][l] = suf[dep][l] = prob[l][s[l]-1];
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][s[i]-1], pre[dep][i] = p;
p = 1;
for(int i=r;i>=l;i--)
p *= prob[i][s[i]-1], 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()
{
// 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++){
// if(i%1000==0) fprintf(stderr,":: %d\n",i);
int l,r; read(l);read(r);
int ma=0, sum=0;
for(int j=l;j<=r;j++){
int x; read(x); sum+=x;
prob[i][j] = x/1000000000.0;
if(prob[i][j] > prob[i][ma]) ma = j;
}
assert(sum == 1000000000);
s[i] = ma+1;
}
// fprintf(stderr,"asdgdf");
for(int i=1;i<=m;i++){
read(t[i]);
s[i+n] = t[i]+1;
}
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);
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");
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);
if(p) ans *= tr.query(0,0,up-1, i+len,i+len+p-1);
if(len + p < m){
ans *= prob[i+len+p][t[1+len+p]];
len += p+1;
}else{
len += p;
}
}
printf("%.12lf\n",ans);
}
// fprintf(stderr,"finish!\n");
}
}
/*
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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 36652kb
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: -100
Runtime Error
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...