QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#454764#8547. Whose Land?masterhuangCompile Error//C++172.5kb2024-06-25 13:33:192024-06-25 13:33:20

Judging History

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

  • [2024-06-25 13:33:20]
  • 评测
  • [2024-06-25 13:33:19]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define P pair<int,int>
#define fi first
#define se second
#define LL long long
#define vec basic_string<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],c[N][25];
basic_string<int>g[N];
vec G[19][N];bool v[N][25],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=A,z;
	for(auto i:B) Z.push_back(i);
	// sort(Z.begin(),Z.end(),[](P x,P y){return x.se>y.se;});
	for(auto [u,d]:Z) v[u][d]=1;
	for(auto [u,d]:Z)
	{
		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&&!V[u][d]) z.push_back({u,d}),V[u][d]=1;
	}
	for(auto [u,d]:Z) v[u][d]=0;
	for(auto [u,d]:z) 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),ans=0;
			vec z=hb(G[t][l],G[t][r-(1<<t)+1]);
			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;
}

详细

In file included from /usr/include/c++/13/bits/basic_string.h:47,
                 from /usr/include/c++/13/string:54,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from answer.code:2:
/usr/include/c++/13/string_view: In instantiation of ‘class std::basic_string_view<std::pair<int, int>, std::char_traits<std::pair<int, int> > >’:
answer.code:45:8:   required from here
/usr/include/c++/13/string_view:109:21: error: static assertion failed
  109 |       static_assert(is_trivial_v<_CharT> && is_standard_layout_v<_CharT>);
      |                     ^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/string_view:109:21: note: ‘std::is_trivial_v<std::pair<int, int> >’ evaluates to false