QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#120687#6660. 택시 여행xtqqwq#0 365ms122008kbC++144.4kb2023-07-07 09:45:432024-05-26 01:47:10

Judging History

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

  • [2024-05-26 01:47:10]
  • 评测
  • 测评结果:0
  • 用时:365ms
  • 内存:122008kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-07 09:45:43]
  • 提交

answer

#include<bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;

template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}

struct node{
	ll k,b;
	node(ll k=0,ll b=0):k(k),b(b){}
}line[2000005];

int n,tot,fs,mn,rt,ncnt,cnt,cur;
int v[200005],nxt[200005],h[100005],siz[100005],lch[6000005],rch[6000005],tag[6000005],dep[100005],pl[100005],f[100005],trt[100005];
ll c[200005],val[20][100005],a[100005],b[100005],dis[100005];
bool vis[100005],hv[100005];
vector<pll> vec[100005];
vector<int> inq[100005];
priority_queue<pll,vector<pll>,greater<pll> > q;

void addedge(int x,int y,ll z){
	v[++tot]=y; c[tot]=z; nxt[tot]=h[x]; h[x]=tot;
	v[++tot]=x; c[tot]=z; nxt[tot]=h[y]; h[y]=tot;
}

void getsize(int u,int fa){
	siz[u]=1;
	for(int p=h[u];p;p=nxt[p]){
		if(v[p]==fa||vis[v[p]]) continue;
		getsize(v[p],u);
		siz[u]+=siz[v[p]];
	}
}

void getroot(int u,int fa){
	int mx=0;
	for(int p=h[u];p;p=nxt[p]){
		if(v[p]==fa||vis[v[p]]) continue;
		getroot(v[p],u);
		chkmax(mx,siz[v[p]]);
	}
	if(chkmin(mn,max(mx,fs-siz[u]))) rt=u;
}

void dfs(int u,int fa){
	vec[rt].pb(mp(val[cur][u],u));
	for(int p=h[u];p;p=nxt[p]){
		if(v[p]==fa||vis[v[p]]) continue;
		val[cur][v[p]]=val[cur][u]+c[p];
		dfs(v[p],u);
	}
}

void solve(int u){
	vis[u]=1;
	getsize(u,-1);
	cur=dep[u];
	val[cur][u]=0;
	dfs(u,-1);
	sort(vec[u].begin(),vec[u].end());
	for(int p=h[u];p;p=nxt[p]){
		if(vis[v[p]]) continue;
		fs=siz[v[p]],mn=n,rt=0;
		getroot(v[p],-1);
		dep[rt]=dep[u]+1;
		// adj[u].pb(rt);
		f[rt]=u;
		solve(rt);
	}
}

ll get(int x,ll y){return line[x].k*y+line[x].b;}

void change(int &id,int l,int r,int c,int t){
	if(!id) id=++ncnt;
	if(!tag[id]) return (void)(tag[id]=c);
	if(l==r){
		if(get(tag[id],vec[t][l-1].fi)>get(c,vec[t][l-1].fi)) tag[id]=c;
		return;
	}
	int mid=(l+r)/2;
	if(line[tag[id]].k<line[c].k){
		if(get(tag[id],vec[t][mid-1].fi)>get(c,vec[t][mid-1].fi)) change(rch[id],mid+1,r,tag[id],t),tag[id]=c;
		else change(lch[id],l,mid,c,t);
	}
	else{
		if(get(tag[id],vec[t][mid-1].fi)>get(c,vec[t][mid-1].fi)) change(lch[id],l,mid,tag[id],t),tag[id]=c;
		else change(rch[id],mid+1,r,c,t);
	}
}

ll query(int id,int l,int r,int x,int t){
	if(!id) return 1ll<<60;
	if(l==r) return get(tag[id],vec[t][x-1].fi);
	int mid=(l+r)/2;
	if(x<=mid) return min(get(tag[id],vec[t][x-1].fi),query(lch[id],l,mid,x,t));
	else return min(get(tag[id],vec[t][x-1].fi),query(rch[id],mid+1,r,x,t));
}

ll calc(int x,int y){
	ll res=query(trt[x],1,siz[x],y+1,x);
	return res;
}

void init(){
	for(int i=1;i<=n;i++){
		if(pl[i]<vec[i].size()){
			ll tmp=calc(i,pl[i]);
			if(chkmin(dis[vec[i][pl[i]].se],tmp)) q.push(mp(tmp,vec[i][pl[i]].se));
			inq[vec[i][pl[i]].se].pb(i);
		}
	}
}

void push(int x){
	ll d=dis[x],ta=a[x],tb=b[x],bef=x;
	// cout<<"push "<<x<<' '<<dis[x]<<endl;
	while(x){
		line[++cnt]=node(tb,ta+d+tb*val[dep[x]][bef]);
		change(trt[x],1,siz[x],cnt,x);
		if(pl[x]<vec[x].size()){
			ll tmp=calc(x,pl[x]);
			// cout<<"pushto "<<x<<' '<<vec[x][pl[x]].se<<' '<<tmp<<' '<<line[cnt].k<<' '<<line[cnt].b<<' '<<endl;
			if(chkmin(dis[vec[x][pl[x]].se],tmp)) q.push(mp(tmp,vec[x][pl[x]].se));
		}
		x=f[x];
	}
}

void pop(int x){
	for(auto r:inq[x]){
		while(pl[r]<vec[r].size()&&hv[vec[r][pl[r]].se]) pl[r]++;
		if(pl[r]<vec[r].size()){
			ll tmp=calc(r,pl[r]);
			// cout<<"popto "<<r<<' '<<vec[r][pl[r]].se<<' '<<tmp<<endl;
			if(chkmin(dis[vec[r][pl[r]].se],tmp)) q.push(mp(tmp,vec[r][pl[r]].se));
			inq[vec[r][pl[r]].se].pb(r);
		}
	}
	inq[x].clear();
}

vector<ll> travel(vector<ll> A,vector<int> B,vector<int> U,vector<int> V,vector<int> W){
	n=A.size();
	for(int i=0;i<n;i++) a[i+1]=A[i],b[i+1]=B[i];
	for(int i=0;i<n-1;i++) addedge(U[i]+1,V[i]+1,W[i]);
	getsize(1,-1);
	fs=n,mn=n,rt=0;
	getroot(1,-1);
	solve(rt);
	for(int i=1;i<=n;i++) dis[i]=1ll<<60;
	dis[1]=0;
	init();
	push(1);
	hv[1]=1;
	while(!q.empty()){
		int t=q.top().se; q.pop();
		if(hv[t]) continue;
		hv[t]=1;
		pop(t);
		push(t);
	}
	vector<ll> ret;
	for(int i=2;i<=n;i++) ret.pb(dis[i]);
	// for(int i=2;i<=n;i++) cout<<dis[i]<<' ';
	// cout<<endl;
	return ret;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 7
Accepted
time: 0ms
memory: 47688kb

input:

2
684124582850 713748627948
74361 256955
0 1 661088

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
733283747618
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 3 lines

Test #2:

score: -7
Wrong Answer
time: 3ms
memory: 45724kb

input:

3
251115773325 363097865287 358609487841
826785 213106 914768
0 1 851938
2 0 231697

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
1152921504606846976
1152921504606846976
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

wrong answer 2nd lines differ - expected: '955485332655', found: '1152921504606846976'

Subtask #2:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 365ms
memory: 122008kb

input:

100000
746699125678 374834842799 250803643493 620187038832 454433387570 406226564003 897157438699 99473514061 734784419618 503968957100 363935477037 277126009840 52078020050 990757079812 847235285349 950784717285 271017141367 861087225700 996035427219 520682200664 282013988419 415183977876 882007771...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
2125490123782
1636760433058
2131282232650
2408842387198
2893332914530
2940403755930
3003543484926
3059216601498
3109347572318
3173036690606
3224306800424
3269329387652
3324613979094
3328434230236
3342554792694
3391237344396
3417184791476
3419985316546
343705790...

result:

wrong answer 2nd lines differ - expected: '1148030742334', found: '2125490123782'

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Wrong Answer

Test #69:

score: 0
Wrong Answer
time: 73ms
memory: 71852kb

input:

100000
15175010 23519365 21177669 27079342 9089 16784452 29693960 23124925 17048604 10179491 12828214 24992902 8483134 2928073 23807522 7332137 17421520 28460746 1607282 13224363 11900728 11794692 11495061 4687109 23460275 7657982 27417256 16978162 7326803 23083826 24942987 16610314 12147303 2828271...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
1152921504606846976
1152921504606846976
1152921504606846976
1152921504606846976
1152921504606846976
1152921504606846976
1152921504606846976
1152921504606846976
1152921504606846976
1152921504606846976
1152921504606846976
1152921504606846976
1152921504606846976
1...

result:

wrong answer 2nd lines differ - expected: '16705757', found: '1152921504606846976'

Subtask #5:

score: 0
Wrong Answer

Test #94:

score: 0
Wrong Answer
time: 79ms
memory: 69804kb

input:

99281
551670361798 568902251563 418071776626 697635341894 641578820039 117221079324 812766431051 425410617978 663769685693 282144284527 799662290178 749088952784 586626406385 122473825417 459510657357 871705247919 443707710712 735612808044 237919555727 829939639783 122127143240 616906466299 24431898...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
1152921504606846976
1152921504606846976
1152921504606846976
1152921504606846976
1152921504606846976
1152921504606846976
1152921504606846976
1152921504606846976
1152921504606846976
1152921504606846976
1152921504606846976
1152921504606846976
1152921504606846976
1...

result:

wrong answer 2nd lines differ - expected: '598598746654', found: '1152921504606846976'

Subtask #6:

score: 0
Skipped

Dependency #1:

0%