QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#808561#7188. Aho-Corasick Automatonjucason_xuWA 2ms11820kbC++141.5kb2024-12-10 21:32:322024-12-10 21:32:34

Judging History

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

  • [2024-12-10 21:32:34]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11820kb
  • [2024-12-10 21:32:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define rd(i,n) for(int i=0;i<n;i++)
#define rp(i,n) for(int i=1;i<=n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=b;i>=a;i--)
#define pb push_back
#define vt vector
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll>pll;
const int N=200005;
int n,p[N],c[N],f[N];
vt<int>G[N];
int root[N],ls[N<<5],rs[N<<5],s[N<<5],cnt;
inline void modify(int &i,int h,int x,int v,int l,int r){
	i=++cnt,ls[i]=ls[h],rs[i]=rs[h];
	if(l==r){
		s[i]=v;
		return;
	}
	int mid=(l+r)>>1;
	if(x<=mid)modify(ls[i],ls[h],x,v,l,mid);
	else modify(rs[i],rs[h],x,v,mid+1,r);
}
inline int query(int i,int x,int l,int r){
	if(!i)return 0;
	if(l==r)return s[i];
	int mid=(l+r)>>1;
	if(x<=mid)return query(ls[i],x,l,mid);
	else return query(rs[i],x,mid+1,r);
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n;
	rp(i,n)cin>>p[i];
	rp(i,n)cin>>c[i];
	rp(i,n)G[p[i]].pb(i);
	queue<int>q;
	for(auto i:G[0]){
		f[i]=0;
		modify(root[0],root[0],c[i],i,1,n);
	}
	for(auto i:G[0]){
		root[i]=root[0];
		q.push(i);
	}
	while(q.size()){
		int x=q.front();
		q.pop();
		for(auto i:G[x]){
			f[i]=query(root[x],c[i],1,n);
			modify(root[x],root[x],c[i],i,1,n);
		}
		for(auto i:G[x]){
			root[i]=root[x];
			q.push(i);
		}
	}
	rp(i,n)cout<<f[i]<<' ';
	cout<<'\n';
	return 0;
}
//Rain Rain Rain

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 9708kb

input:

2
0 0
1 2

output:

0 0 

result:

ok 2 number(s): "0 0"

Test #2:

score: 0
Accepted
time: 0ms
memory: 9700kb

input:

2
0 1
1 1

output:

0 1 

result:

ok 2 number(s): "0 1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 9716kb

input:

1
0
1

output:

0 

result:

ok 1 number(s): "0"

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 11820kb

input:

50
0 1 1 1 0 0 4 4 3 7 1 11 1 11 2 15 13 11 4 11 5 7 22 17 4 19 19 26 19 27 3 17 9 4 14 8 15 33 33 33 9 40 24 18 5 28 10 1 47 25
20 20 31 1 43 3 3 21 3 3 3 22 43 3 1 20 3 43 43 20 3 20 1 3 20 20 3 1 43 3 20 20 20 29 3 3 3 3 20 1 3 3 3 3 20 3 3 25 3 1

output:

0 1 0 0 0 0 11 0 11 7 6 0 5 11 4 2 11 13 13 2 6 25 4 17 2 25 7 4 19 27 2 2 31 0 14 7 11 41 33 4 9 38 24 14 1 27 10 0 47 4 

result:

wrong answer 7th numbers differ - expected: '6', found: '11'