QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#454750#8547. Whose Land?masterhuangWA 2ms13920kbC++202.6kb2024-06-25 13:10:422024-06-25 13:10:42

Judging History

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

  • [2024-06-25 13:10:42]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:13920kb
  • [2024-06-25 13:10:42]
  • 提交

answer

#include<bits/stdc++.h>
#define P pair<int,int>
#define fi first
#define se second
#define LL long long
#define vec vector<P>
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
namespace IO
{
	const int _Pu=2e7+5,_d=32;
	char buf[_Pu],obuf[_Pu],*p1=buf+_Pu,*p2=buf+_Pu,*p3=obuf,*p4=obuf+_Pu-_d;
	inline void fin()
	{
		memmove(buf,p1,p2-p1);
		int rlen=fread(buf+(p2-p1),1,p1-buf,stdin);
		if(p1-rlen>buf) buf[p2-p1+rlen]=EOF;p1=buf;
	}
	inline void fout(){fwrite(obuf,p3-obuf,1,stdout),p3=obuf;}
	inline int rd()
	{
		if(p1+_d>p2) fin();int isne=0,x=0;
		for(;!isdigit(*p1);++p1) isne=(*p1=='-');x=(*p1++-'0');
	    for(;isdigit(*p1);++p1) x=x*10+(*p1-'0');
		if(isne) x=-x;return x;
	}
	inline void wr(int x,char end='\n')
	{
		if(!x) return *p3++='0',*p3++=end,void();
		if(x<0) *p3++='-',x=-x;
		char sta[20],*top=sta;
		do{*top++=(x%10)+'0';x/=10;}while(x);
		do{*p3++=*--top;}while(top!=sta);(*p3++)=end;
	}
}using IO::rd;using IO::wr;
const int N=1e5+5;
int T,n,k,q,tot,f[N],d[N],c[N][25];
basic_string<int>g[N];
vec G[19][N];bool v[N][25];
void dfs(int x,int fa){f[x]=fa;for(int i:g[x]) if(i^fa) dfs(i,x);}
inline void upd(int i,int x,int y){G[0][i].push_back({x,y});}
inline vec hb(vec &A,vec &B)
{
	vec z;
	for(auto [u,d]:B) v[u][d]=1;
	for(auto [u,d]:A)
	{
		bool o=1;
		for(int j=0,x=u;j<=k-d&&x;j++,x=f[x])
			if(j&&v[x][d+j]){o=0;break;}
		if(o) z.push_back({u,d});
	}
	for(auto [u,d]:B) v[u][d]=0;
	swap(A,B);
	for(auto [u,d]:B) v[u][d]=1;
	for(auto [u,d]:A)
	{
		bool o=1;
		for(int j=0,x=u;j<=k-d&&x;j++,x=f[x])
			if(j&&v[x][d+j]){o=0;break;}
		if(o) z.push_back({u,d});
	}
	for(auto [u,d]:B) v[u][d]=0;return z;
}
int main()
{
	T=rd();
	while(T--)
	{
		n=rd(),k=rd(),q=rd();
		for(int i=1,u,v;i<n;i++) u=rd(),v=rd(),g[u]+=v,g[v]+=u;dfs(1,0);
		for(int i=1;i<=n;i++) for(int j=0,x=i;j<=k&&x;j++,x=f[x]) c[x][j]++;
		for(int i=1;i<=n;i++) for(int x=i,y=k;x&&~y;x=f[x],y--)
		{
			if(f[x]&&y>1) upd(i,x,y),upd(i,x,y-1);
			else for(int j=0;j<=y;j++) upd(i,x,j);
		}
		for(int i=1;i<=18;i++) for(int j=1;j+(1<<i)-1<=n;j++)
			G[i][j]=hb(G[i-1][j],G[i-1][j+(1<<(i-1))]);
		while(q--)
		{
			int l=rd(),r=rd(),t=__lg(r-l+1);
			vec z=hb(G[t][l],G[t][r-(1<<t)+1]);
			sort(z.begin(),z.end());
			z.erase(unique(z.begin(),z.end()),z.end());
			int ans=0;
			for(auto [u,d]:z) ans+=c[u][d];wr(ans);
		}
		for(int i=0;i<=18;i++) for(int j=1;j<=n;j++) G[i][j].clear();
		for(int i=0;i<=k;i++) for(int j=1;j<=n;j++) c[j][i]=0;
		for(int i=1;i<=n;i++) g[i].clear();
	}
	return IO::fout(),0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 13920kb

input:

2
5 1 2
1 2
1 3
2 4
2 5
2 2
2 3
8 2 3
1 2
1 3
2 4
2 5
4 6
5 7
7 8
2 2
2 5
3 4

output:

2
4
3
7
6

result:

wrong answer 1st numbers differ - expected: '4', found: '2'