QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#745301#8547. Whose Land?scallionsongWA 4ms15940kbC++145.0kb2024-11-14 09:02:532024-11-14 09:02:56

Judging History

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

  • [2024-11-14 09:02:56]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:15940kb
  • [2024-11-14 09:02:53]
  • 提交

answer

bool M1;
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ull unsigned long long
#define LL __int128
#define db double
#define LD long double
#define Pii pair<int,int>
#define Pll pair<ll,ll>
#define Pull pair<ull,ull>
#define Pdb pair<db,db>
#define fir first
#define sec second
#define vec vector<int>
#define pb push_back
#define qlr cerr<<"qlr\n"
#define dyh cerr<<"dyh\n"
#define pc(x) __builtin_popcount(x)
#define uni(x,y) uniform_int_distribution<int>(x,y)(rng)
#define unl(x,y) uniform_int_distribution<ll>(x,y)(rng)
#define unr(x,y) uniform_real_distribution<double>(x,y)(rng)
#define F(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define UF(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define look_memory cerr<<'\n'<<abs(&M1-&M2)/1024.0/1024<<'\n'
#define look_time cerr<<'\n'<<clock()*1.0/CLOCKS_PER_SEC<<'\n'
mt19937 rng(time(0)^(*new int));
const ll INF=0x3f3f3f3f3f3f3f3f;
const int Mod=998244353;
template<typename T>
inline void inc(T &a,T b){
	if(b<0) b+=Mod;
	a+=b;
	if(a>=Mod) a-=Mod;
}
template<typename T>
inline void dec(T &a,T b){
	if(b<0) b+=Mod;
	a-=b;
	if(a<0) a+=Mod;
}
template<typename T>
inline void muc(T &a,T b){
	a=a*b%Mod;
}
template<typename T>
inline bool chkmin(T &a,T b){
	if(a<=b) return false;
	a=b;
	return true;
}
template<typename T>
inline bool chkmax(T &a,T b){
	if(a>=b) return false;
	a=b;
	return true;
}
struct IO{
	static const int N=1<<22;
	char buf[N],pbuf[N],*p1=buf,*p2=buf,*pp=pbuf;
	#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,N,stdin),p1==p2)?EOF:*p1++)	
	template<typename T>
	void read(T &x){
		x=0;char ch;int f=0;
		while((ch=gc())<'0'||ch>'9')f|=(ch=='-');
		while(x=(x<<1)+(x<<3)+(ch^48),(ch=gc())>='0'&&ch<='9');
		if(f) x=~x+1;
	}
	void putc(char c){
		if(pp-pbuf==N) fwrite(pbuf,1,N,stdout), pp=pbuf;
		*pp++=c;
	}
	void puts(const char* s) {while(*s) putc(*s),++s;putc('\n');}
	template<typename T>
	void print(T x){
		static int st[40];int tp=0;
		if(x<0) putc('-'),x=~x+1;
		do st[++tp]=x%10,x/=10;while(x);
		while(tp) putc(st[tp--]+'0');
	}
	~IO() {fwrite(pbuf,pp-pbuf,1,stdout);}
}io;
int T,n,K,Q;
int bfn[100010],fth[100010],ans[500010];
Pii t[100010][21];
vec e[100010];
vector<Pii> qry[100010];
queue<int> q;
struct Bit{
	#define N 100000
	int w[N+10];
	int lb(int x){
		return x&-x;
	}
	void clear(){
		F(i,1,N) w[i]=0;
	}
	void add(int x,int y){
		if(!x) return;
		for(int i=x;i<=N;i+=lb(i)) w[i]+=y;
	}
	int query(int x){
		int res=0;
		for(int i=x;i;i-=lb(i)) res+=w[i];
		return res;
	}
	int Query(int x,int y){
		return query(y)-query(x-1);
	}
	#undef N
}bit;
struct ODT{
	int l,r,val;
};
bool operator<(ODT cm1,ODT cm2){
	return cm1.l<cm2.l;
}
struct Odt{
	#define IT set<ODT>::iterator
	set<ODT> s;
	void init(int l,int r,int val){
		s.clear();
		s.insert({l,r,val});
	}
	IT split(int x){
		IT it=--s.upper_bound({x});
		if(it->l==x) return it;
		int l=it->l,r=it->r,val=it->val;
		s.erase(it);
		s.insert({l,x-1,val});
		return s.insert({x,r,val}).fir;
	}
	void change(int x,int y,int z){
		// cerr<<x<<' '<<y<<' '<<z<<'\n';
		if(x>y) return;
		IT r=split(y+1),l=split(x);
		for(IT it=l;it!=r;it++){
			int l=it->l,r=it->r,val=it->val;
			bit.add(val,-(r-l+1));
		}
		bit.add(z,y-x+1);
		s.erase(l,r);
		s.insert({x,y,z});
	}
	#undef IT
}odt;
void bfs(){
	bfn[1]=++bfn[0];
	q.push(1);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(auto v:e[u]){
			if(fth[u]==v) continue;
			fth[v]=u;
			bfn[v]=++bfn[0];
			q.push(v);
		}
	}
}
void change(int x,int y){
	F(i,0,K){
		if(x==1){
			F(j,0,K-i) odt.change(t[x][i].fir,t[x][i].sec,y);
			break;
		}
		odt.change(t[x][K-i].fir,t[x][K-i].sec,y);
		if(i!=K) odt.change(t[x][K-i-1].fir,t[x][K-i-1].sec,y);
		x=fth[x];
	}
}
void solve(){
	io.read(n),io.read(K),io.read(Q);
	F(i,1,n) e[i].clear();
	F(i,1,n-1){
		int x,y;
		io.read(x),io.read(y);
		e[x].pb(y);
		e[y].pb(x);
	}
	F(i,1,n) qry[i].clear();
	F(i,1,Q){
		int x,y;
		io.read(x),io.read(y);
		qry[y].pb({x,i});
	}
	bfs();
	bfn[0]=0;
	F(i,1,n) F(j,0,K) t[i][j]={n+1,0};
	F(i,1,n){
		int x=i;
		F(j,0,K){
			if(!x) break;
			chkmin(t[x][j].fir,bfn[i]);
			chkmax(t[x][j].sec,bfn[i]);
			x=fth[x];
		}
	}
	// F(i,1,n){
	// 	F(j,0,K) cout<<t[i][j].fir<<' '<<t[i][j].sec<<'\n';
	// 	cout<<'\n';
	// }
	odt.init(1,n,0);
	bit.clear();
	F(i,1,n){
		change(i,i);
		for(auto j:qry[i]) ans[j.sec]=bit.Query(j.fir,i);
	}
	F(i,1,Q) io.print(ans[i]),io.putc('\n');
}
bool M2;
int main(){
	// freopen("count.in","r",stdin);
	// freopen("count.out","w",stdout);
	srand(time(0)^(*new int));
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	io.read(T);
	while(T--) solve();
	look_memory;
	look_time;
	return 0;
}
/*
g++ C1.cpp -o C1 -std=c++14 -O2&&./C1

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

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
*/

詳細信息

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 15940kb

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:

4
4
6
7
5

result:

wrong answer 2nd numbers differ - expected: '5', found: '4'