QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#502532#4924. 蜘蛛爬树WrongAnswer_900 1118ms155576kbC++148.4kb2024-08-03 09:05:402024-08-03 09:05:41

Judging History

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

  • [2024-08-03 09:05:41]
  • 评测
  • 测评结果:0
  • 用时:1118ms
  • 内存:155576kb
  • [2024-08-03 09:05:40]
  • 提交

answer

#include<bits/stdc++.h>
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define ll long long
#define lll __int128
#define fi first
#define se second
#define e emplace
#define eb emplace_back
#define db double
#define ef emplace_front
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vp vector<pii>
#define mp make_pair

//#define LOCALJUDGE
#define int ll
bool ST;
static const ll MOD=1e9+7,Phi=998244352,inv2=499122177,Root=3,iRoot=332748118;
static const ll inf=1073741823,INF=4557430888798830399;
static const double eps=1e-8,pi=3.1415926535;
char in[1<<20],*p1=in,*p2=in;
using namespace std;
//#define getchar() (p1==p2&&(p2=(p1=in)+fread(in,1,1<<20,stdin),p1==p2)?EOF:*p1++)
struct tup{int x,y,z;tup(int X=0,int Y=0,int Z=0){x=X,y=Y,z=Z;}};
namespace FastIO
{
	template<typename T> inline void write(T x,char ch=' ')
	{
		if(is_same<char,T>::value)putchar(x);
		else
		{
			if(x<0)x=-x,putchar('-');
			static char st[25];int top=0;
			do{st[top++]=x%10+'0',x/=10;}while(x);
			while(top)putchar(st[--top]);
		}
		ch!='~'?putchar(ch):0;
	}
	inline void write(const char*x,char ch=' ')
	{
		for(int i=0;x[i]!='\0';++i)putchar(x[i]);
		ch!='~'?putchar(ch):0;
	}
	inline void read(char&s){do s=getchar();while(s=='\n'||s==' ');}
	inline void read(char s[])
	{
		int len=0;char st;
		do st=getchar();while(st=='\n'||st==' ');
		s[++len]=st,st=getchar();
		while(st!='\n'&&st!=' ')s[++len]=st,st=getchar();
		s[++len]='\0';
	}
	template<typename T> inline void read(T &s)
	{
		s=0;char ch=getchar();
		while((ch>'9'||ch<'0')&&ch!='-')ch=getchar();
		bool tf=(ch=='-')&&(ch=getchar());
		while((ch>='0')&&(ch<='9'))s=(s<<1)+(s<<3)+ch-'0',ch=getchar();
		s=(tf?-s:s);
	}
	template<typename T1,typename T2> inline void read(pair<T1,T2> &s){read(s.fi),read(s.se);}
	template<typename T,typename...Args> inline void write(T x,Args...args){write(x,'~'),write(args...);}
	template<typename T,typename...Args> inline void read(T&x,Args&...args){read(x),read(args...);}
}
using namespace FastIO;
namespace MTool
{
	inline int Cadd(int a,int b){return (ll)a+b>=MOD?(ll)a+b-MOD:a+b;}
	inline int Cdel(int a,int b){return a-b<0?a-b+MOD:a-b;}
	inline int Cmul(int a,int b){return 1ll*a*b%MOD;}
	inline int sqr(int a){return 1ll*a*a%MOD;}
	inline void Madd(int&a,int b){a=((ll)a+b>=MOD?(ll)a+b-MOD:a+b);}
	inline void Mdel(int&a,int b){a=(a-b<0?a-b+MOD:a-b);}
	inline void Mmul(int&a,int b){a=1ll*a*b%MOD;}
	template<typename T> inline bool Mmax(T&a,T b){return a<b?a=b,1:0;}
	template<typename T> inline bool Mmin(T&a,T b){return a>b?a=b,1:0;}
	template<typename...Args> inline void Madd(int&a,int b,Args...args){Madd(a,b),Madd(a,args...);}
	template<typename...Args> inline void Mmul(int&a,int b,Args...args){Mmul(a,b),Mmul(a,args...);}
	template<typename...Args> inline void Mdel(int&a,int b,Args...args){Mdel(a,b),Mdel(a,args...);}
	template<typename...Args> inline int Cadd(int a,int b,Args...args){return Cadd(Cadd(a,b),args...);}
	template<typename...Args> inline int Cmul(int a,int b,Args...args){return Cmul(Cmul(a,b),args...);}
	template<typename...Args> inline int Cdel(int a,int b,Args...args){return Cdel(Cdel(a,b),args...);}
	template<typename...Args,typename T> inline bool Mmax(T&a,T b,Args...args){return Mmax(a,b)|Mmax(a,args...);}
	template<typename...Args,typename T> inline bool Mmin(T&a,T b,Args...args){return Mmin(a,b)|Mmin(a,args...);}
	inline int power(int x,int y){int s=1;for(;y;y>>=1,Mmul(x,x))if(y&1)Mmul(s,x);return s;}
}
using namespace MTool;
namespace WrongAnswer_90
{
	int n,m,q,len,cnt,tot,s[200010],head[200010],to[400010],v[400010],nex[400010];
	int ans[200010],fin[200010],b[200010],lca[200010],rt[200010],a[200010];
	int end[200010],dfn[200010],siz[200010],dep[200010],rt1[200010];
	int son[200010],top[200010],fa[200010],id[200010];
	inline void add(int x,int y,int z){to[++cnt]=y,v[cnt]=z,nex[cnt]=head[x],head[x]=cnt;}
	vi ve[200010],tr[200010],ve2[200010];
	namespace LCT
	{
		#define ls(x) t[x].ls
		#define rs(x) t[x].rs
		pii c[8000010];
		int cnt,root;
		inline int calc(int x,int y){return c[x].fi*y+c[x].se;}
		struct{int ls,rs,v;}t[8000010];
		void add(int&p,int L,int R,int x)
		{
			if(!p)return t[p=++cnt]={0,0,x},void();
			int mid=L+((R-L)>>1);
			if(calc(x,mid)<calc(t[p].v,mid))swap(x,t[p].v);
			if(calc(x,L)<calc(t[p].v,L))add(ls(p),L,R,x);
			if(calc(x,R)<calc(t[p].v,R))add(rs(p),L,R,x);
		}
		int ask(int p,int L,int R,int x)
		{
			if(!p)return INF;
			int v=calc(t[p].v,x),mid=L+((R-L)>>1);
			if(x<=mid)return min(ask(ls(p),L,mid,x),v);
			return min(ask(rs(p),mid+1,R,x),v);
		}
		void merge(int&x,int y,int L=1,int R=1e9)
		{
			if(!x||!y)return x|=y,void();
			merge(ls(x),ls(y)),merge(rs(x),rs(y));
			add(x,L,R,t[y].v);
		}
		void copy(int&now,int from,int del)
		{
			if(!from)return;
			c[++len]=c[t[from].v],c[len].se+=del,t[now=++cnt].v=len;
			copy(ls(now),ls(from),del),copy(rs(now),rs(from),del);
		}
		#undef ls
		#undef rs
	}
	using namespace LCT;
	namespace Segment
	{
		#define ls(x) (t[x].l+t[x].r)
		#define rs(x) (ls(x)^1)
		struct{int l,r,rt;vi ve;}t[400010];
		void build(int p,int l,int r)
		{
			t[p].l=l,t[p].r=r,t[p].rt=0,t[p].ve.clear();
			if(l==r)return t[p].rt=rt1[id[l]],void();
			int mid=l+((r-l)>>1);
			build(ls(p),l,mid),build(rs(p),mid+1,r);
		}
		void modify(int p,int l,int r,int id)
		{
			if(l<=t[p].l&&r>=t[p].r)return t[p].ve.eb(id),void();
			if(l<=t[ls(p)].r)modify(ls(p),l,r,id);
			if(r>t[ls(p)].r)modify(rs(p),l,r,id);
		}
		void solve(int p,int L,int R)
		{
			if(L<R)
			{
				int mid=L+((R-L)>>1);
				solve(ls(p),L,mid),merge(t[p].rt,t[ls(p)].rt);
				solve(rs(p),mid+1,R),merge(t[p].rt,t[rs(p)].rt);
			}
			for(auto x:t[p].ve)Mmax(ans[x],ask(t[p].rt,1,1e9,b[x]));
		}
	}
	using namespace Segment;
	void dfs(int x,int Fa)
	{
		dep[x]=dep[fa[x]=Fa]+1,siz[x]=1;
		for(int i=head[x];i;i=nex[i])if(to[i]!=Fa)
		{
			s[to[i]]=s[x]+v[i],dfs(to[i],x),siz[x]+=siz[to[i]];
			if(siz[to[i]]>siz[son[x]])son[x]=to[i];
		}
	}
	void dfs1(int x,int topp)
	{
		top[x]=topp,id[dfn[x]=++tot]=x;
		if(son[x])dfs1(son[x],topp),end[x]=end[son[x]];
		else end[x]=tot;
		for(int i=head[x];i;i=nex[i])
		if(to[i]!=fa[x]&&to[i]!=son[x])dfs1(to[i],to[i]);
	}
	vector<tup> rl[200010];
	inline int LCA(int x,int y,int id)
	{
		while(top[x]!=top[y])
		{
			if(dep[top[x]]>dep[top[y]])
			ve[x].eb(id),x=fa[top[x]];
			else ve[y].eb(id),y=fa[top[y]];
		}
		rl[top[x]].eb(tup(x,y,id));
		return dep[x]<dep[y]?x:y;
	}
	inline void modify(int x,int id){while(x)ve2[x].eb(id),x=fa[top[x]];}
	void dfs2(int x)
	{
		c[++len]=mp(a[x],2*s[x]),add(rt[x],1,1e9,len);
		if(son[x])dfs2(son[x]);
		for(int i=head[x];i;i=nex[i])if(to[i]!=fa[x]&&to[i]!=son[x])
		dfs2(to[i]),merge(rt[x],rt[to[i]]),root=0;
		if(x!=son[fa[x]])
		{
			for(int i=dfn[x];i<=end[x];++i)copy(rt1[id[i]],rt[id[i]],-2*s[id[i]]);
			for(int i=dfn[x];i<=end[x];++i)
			{
				merge(root,rt1[id[i]]);
				for(auto p:ve[id[i]])Mmin(ans[p],ask(root,1,1e9,b[p]));
			}
			root=0;
			for(int i=dfn[x];i<=end[x];++i)copy(rt1[id[i]],rt[id[i]],-4*s[id[i]]);
			for(int i=dfn[x];i<=end[x];++i)
			{
				merge(root,rt1[id[i]]);
				for(auto p:ve2[id[i]])Mmin(ans[p],ask(root,1,1e9,b[p])+2*s[lca[p]]);
			}
			for(int i=dfn[x];i<=end[x];++i)copy(rt1[id[i]],rt[id[i]],-2*s[id[i]]);
			for(int i=end[x];i>=dfn[x];--i)
			{
				if(i<dfn[x])merge(rt[id[i]],rt[id[i+1]]);
				for(auto p:tr[id[i]])Mmin(ans[p],ask(rt[id[i]],1,1e9,b[p])-2*s[id[i]]);
			}
			build(1,dfn[x],end[x]);
			for(auto [l,r,id]:rl[x])modify(1,dfn[l],dfn[r],id);
			solve(1,dfn[x],end[x]);
		}
	}
	inline void mian()
	{
		read(n,m,q);int x,y,z;
		for(int i=1;i<=n;++i)read(a[i]);
		for(int i=1;i<n;++i)read(x,y,z),add(x,y,z),add(y,x,z);
		dfs(1,0),dfs1(1,1);
		for(int i=1;i<=q;++i)
		{
			read(x,y),b[i]=abs((y-1)/n-(x-1)/n),ans[i]=INF;
			modify(lca[i]=LCA(x=(x-1)%n+1,y=(y-1)%n+1,i),i);
			tr[x].eb(i),tr[y].eb(i),fin[i]=s[x]+s[y]-2*s[lca[i]];
		}
		dfs2(1);
		for(int i=1;i<=q;++i)write(fin[i]+ans[i],'\n');
	}
}
bool ED;
signed main()
{
	#ifdef LOCALJUDGE
	freopen("1.in","r",stdin);
	freopen("1.out","w",stdout);
	#endif
	double st=clock();
	WrongAnswer_90::mian();
	double ed=clock();
	#ifndef LOCALJUDGE
 	cerr<<endl;
	#endif
 	cerr<<"Time: "<<ed-st<<" ms\n";
	#ifdef LOCALJUDGE
 	cerr<<"     ";
	#endif
 	cerr<<"Memory: "<<abs(&ST-&ED)/1024.0/1024.0<<" MB\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 13ms
memory: 68392kb

input:

97 99 1000
763118300 558295517 80676328 362318619 473105413 468927175 311496507 936935430 176032966 304576040 308583326 681580095 549392233 518152994 829474320 751189715 542810029 587869244 878512027 530678371 832766129 535259635 799122942 596982955 884696876 605325753 495661541 506105495 561218313 ...

output:

6132871220289
10814072524161
3440559556796
5464304655037
4477528208468
1566659300400
7949065497977
1883962967227
5138395872137
6973812673144
4716323979405
5271806746618
4634302659698
3178392425395
2369520344240
965219608895
14354872116920
9715867834543
4256954122467
7333255321628
8385238479593
12353...

result:

wrong answer 1st lines differ - expected: '6130845802041', found: '6132871220289'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #20:

score: 0
Wrong Answer
time: 434ms
memory: 151076kb

input:

200000 20 200000
679416469 548913625 468159997 137709609 883140368 682558021 473174374 400192350 124143873 825920417 372498686 851213321 822264481 78195915 5427143 453304163 233551905 810910186 810046144 52603791 282167184 385032797 81387991 747194790 917579656 585184539 12659388 249218417 158295502...

output:

920563165
1043352910
1770322086
618880466
575380882
765208640
574887138
473946535
556330093
980019441
3360884887
857772051
325701622
373824634
197258906
1149352956
172379629
583233306
1051825833
253016414
657338293
356330666
1075234645
573783312
780829923
3309972562
954474031
1032884265
1010080549
1...

result:

wrong answer 2nd lines differ - expected: '270738856', found: '1043352910'

Subtask #4:

score: 0
Wrong Answer

Test #28:

score: 0
Wrong Answer
time: 1118ms
memory: 155576kb

input:

200000 1000000000 200000
28270302 472359923 262785485 923929785 393684160 761485431 72038469 116384740 426631758 437934930 610834083 455314140 734276543 903544756 220163018 756113376 732404264 947339315 109784905 625451008 794076307 818852312 758007217 124450858 674924509 311761991 507260538 7032362...

output:

29375557839697483
9980503160824533
73299057563898792
38129291407212050
57389423733282830
54425124319330092
19676101968962141
225951028291179501
3196384863587003
361466803799403139
91896876547626655
65609495812941401
164996391351053470
457769628738297687
19213682025389514
46439751325530566
8271105749...

result:

wrong answer 1st lines differ - expected: '29294995135992468', found: '29375557839697483'

Subtask #5:

score: 0
Wrong Answer

Test #36:

score: 0
Wrong Answer
time: 322ms
memory: 135444kb

input:

199918 1000000000 199903
1496 2382 3896 3664 1177 1627 2821 4200 3074 3783 2069 4403 629 2610 4991 4074 3033 2798 4333 3501 3667 3064 663 2821 2818 458 2950 4020 2665 3578 63 4855 4941 3492 2423 4510 1489 1018 4829 1912 3133 3174 309 287 2909 4102 4296 4526 3170 3683 4960 4863 4738 2927 2405 3600 44...

output:

1352416884531
1380463318391
923920163167
1525224977139
1405019709299
869269749781
715671043328
876194052054
1358007874327
127994985855
1230162209719
1532026808855
611656467332
1023855959729
414792924571
1316679734677
827308370883
1265411315424
821484360433
1051517948640
837509712760
582943943131
457...

result:

wrong answer 258th lines differ - expected: '1251426204676', found: '1251613120990'

Subtask #6:

score: 0
Wrong Answer

Test #43:

score: 0
Wrong Answer
time: 362ms
memory: 148676kb

input:

200000 1000000000 200000
81882094 47220813 43282454 17633207 52769165 4830673 31396360 64793163 9174729 36727563 71268262 24662923 40146030 1430053 62926106 30042905 1330107 81817720 98841078 87766129 51155045 23216268 79896310 66625868 87854925 42976560 86542933 28336449 34932261 19698851 584453 90...

output:

1877351389435064
3790041079788980
24817685754355558
5401784984289501
1962549076711999
886356683982791
490196874038410
1746881254682865
503103779838715
5460186734318023
4603411740162676
10179528036407656
1084451057728926
25259297232093852
9010357087952534
715522076938027
4992993862775635
170419773765...

result:

wrong answer 1st lines differ - expected: '516260625003899', found: '1877351389435064'

Subtask #7:

score: 0
Skipped

Dependency #1:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

0%