QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#420730#8642. Spy 3Kevin53070 65ms76596kbC++236.6kb2024-05-24 21:30:522024-05-24 21:30:52

Judging History

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

  • [2024-05-24 21:30:52]
  • 评测
  • 测评结果:0
  • 用时:65ms
  • 内存:76596kb
  • [2024-05-24 21:30:52]
  • 提交

Aoi

#include<bits/stdc++.h>
#include"Aoi.h"
using namespace std;
using ll=long long;
string aoi(int N,int M,int Q,int K,vector<int> A,vector<int> B,vector<ll> C,vector<int> T,vector<int> X)
{
	map<pair<int,int>,int> Mp;
	vector<int> lst(N,-1);
	vector<ll> dist(N,0x3f3f3f3f3f3f3f3f);
	dist[0]=0;
	vector<vector<pair<int,ll>>> G(N);
	vector<vector<int>> Tree(N);
	vector<int> depth(N);
	for(int i=0;i<M;i++)
	{
		Mp[make_pair(A[i],B[i])]=Mp[make_pair(B[i],A[i])]=i;
		G[A[i]].emplace_back(B[i],C[i]);
		G[B[i]].emplace_back(A[i],C[i]);
	}
	priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
	pq.emplace(0,0);
	while(!pq.empty())
	{
		ll d=pq.top().first;
		int u=pq.top().second;
		pq.pop();
		if(dist[u]!=d) continue;
		for(auto pr:G[u])
			if(dist[pr.first]>d+pr.second)
			{
				lst[pr.first]=u;
				dist[pr.first]=d+pr.second;
				pq.emplace(d+pr.second,pr.first);
			}
	}
	for(int i=1;i<N;i++)
		Tree[lst[i]].push_back(i);
	vector<int> dfn(N),vfa(N,-1);
	int tot;
	auto dfs=[&](auto dfs,int u)->void
	{
		dfn[u]=++tot;
		for(auto v:Tree[u])
		{
			depth[v]=depth[u]+1;
			dfs(dfs,v);
		}
	};
	auto lca=[&](int u,int v)
	{
		while(u!=v)
		{
			if(depth[u]<depth[v]) swap(u,v);
			u=lst[u];
		}
		return u;
	};
	vector<int> qind(N,Q);
	for(int i=0;i<Q;i++)
		qind[T[i]]=i;
	dfs(dfs,0);
	vector<int> pool;
	for(auto x:T)
		pool.push_back(x);
	sort(pool.begin(),pool.end(),[&](int a,int b){return dfn[a]<dfn[b];});
	for(int i=1;i<T.size();i++)
		pool.push_back(lca(pool[i-1],pool[i]));
	sort(pool.begin(),pool.end());
	pool.resize(unique(pool.begin(),pool.end())-pool.begin());
	sort(pool.begin(),pool.end(),[&](int a,int b){return dfn[a]<dfn[b];});
	for(int i=1;i<pool.size();i++)
	{
		int w=lca(pool[i-1],pool[i]);
		vfa[pool[i]]=w;
	}
	sort(pool.begin(),pool.end(),[&](int a,int b)
	{
		if(qind[a]!=qind[b])
			return qind[a]<qind[b];
		return depth[a]>depth[b];
	});
	vector<int> order(N);
	for(int i=0;i<pool.size();i++)
		order[pool[i]]=i;
	vector<int> fa(Q+Q-1,Q+Q-1);
	for(int i=0;i<pool.size();i++)
		if(vfa[pool[i]]==-1)
			fa[i]=Q+Q-1;
		else
			fa[i]=order[vfa[pool[i]]];
	vector<int> vmsk(N);
	for(int i=0;i<Q;i++)
		vmsk[i]=1<<i;
	for(int i=0;i<Q+Q;i++)
		for(int j=0;j<pool.size();j++)
			if(vfa[pool[j]]!=-1)
				vmsk[fa[j]]|=vmsk[j];
	vector<int> qmsk(M);
	for(int i=0;i<Q;i++)
	{
		int v=T[i];
		while(v)
		{
			qmsk[Mp[make_pair(v,lst[v])]]|=(1<<i);
			v=lst[v];
		}
	}
	string ans;
	auto write_32=[&](int x)
	{
		for(int i=0;i<5;i++)
			ans+=(char)(48^(x>>i&1));
	};
	auto write_120bits=[&](__int128 x)
	{
		for(int i=0;i<120;i++)
			ans+=(char)(48^(x>>i&1));
	};
	__int128 val=0;
	for(int i=0;i<Q+Q-1;i++)
	{
		if(i<=Q)
			val*=(Q+Q);
		else
			val*=(Q+Q-1-i);
		if(i<Q)
			val+=fa[i];
		else
			val+=fa[i]-i-1;
	}
	write_120bits(val);
	for(auto e:X)
	{
		for(int j=0;j<pool.size();j++)
			if(vmsk[j]==qmsk[e])
				write_32(j);
		if(!qmsk[e])
			write_32(31);
	}
	return ans;
}

Bitaro

#include<bits/stdc++.h>
#include"Bitaro.h"
using namespace std;
using ll=long long;
void bitaro(int N,int M,int Q,int K,vector<int> A,vector<int> B,vector<ll> C,vector<int> T,vector<int> X,string s)
{
	#define pb emplace_back
	#define mp make_pair
	#define ALL(x) (x).begin(),(x).end()
	#define rALL(x) (x).rbegin(),(x).rend()
	#define srt(x) sort(ALL(x))
	#define rev(x) reverse(ALL(x))
	#define rsrt(x) sort(rALL(x))
	#define sz(x) (int)(x.size())
	#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
	#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
	#define uni(v) v.resize(unique(ALL(v))-v.begin())
	vector<int> pool;
	for(auto e:X)
	{
		pool.pb(A[e]);
		pool.pb(B[e]);
	}
	pool.pb(0);
	srt(pool);
	uni(pool);
	vector<vector<ll>> dist(sz(pool),vector<ll>(N,0x3f3f3f3f3f3f3f3f));
	vector<vector<int>> lst(sz(pool),vector<int>(N,-1));
	vector<vector<pair<int,ll>>> G(N);
	map<pair<int,int>,int> Mp;
	vector<int> called(sz(pool));
	for(int i=0;i<M;i++) if(C[i]!=-1)
	{
		Mp[mp(A[i],B[i])]=Mp[mp(B[i],A[i])]=i;
		G[A[i]].emplace_back(B[i],C[i]);
		G[B[i]].emplace_back(A[i],C[i]);
	}
	auto solve=[&](int i)
	{
		priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
		dist[i][pool[i]]=0;
		pq.emplace(0,pool[i]);
		while(!pq.empty())
		{
			ll d=pq.top().first;
			int u=pq.top().second;
			pq.pop();
			if(d!=dist[i][u]) continue;
			for(auto pr:G[u])
				if(dist[i][pr.first]>d+pr.second)
				{
					lst[i][pr.first]=u;
					dist[i][pr.first]=d+pr.second;
					pq.emplace(d+pr.second,pr.first);
				}
		}
	};
	vector<int> fa(Q+Q-1);
	int P=0;
	auto read_32=[&]()
	{
		int ans=0;
		for(int i=0;i<5;i++)
			ans|=(48^s[P++])<<i;
		return ans;
	};
	auto read_120bits=[&]()
	{
		__int128 ans=0;
		for(int i=0;i<120;i++)
			ans|=((__int128)(48^s[P++]))<<i;
		return ans;
	};
	__int128 val=read_120bits();
	for(int i=Q+Q-2;i>=0;i--)
	{
		if(i>=Q)
			fa[i]=i+1+val%(Q+Q-1-i);
		else
			fa[i]=val%(Q+Q);
		if(i>Q)
			val/=(Q+Q-i-1);
		else
			val/=(Q+Q);
	}
	vector<int> vmsk(Q+Q);
	for(int i=0;i<Q;i++)
		vmsk[i]=(1<<i);
	for(int i=0;i<Q+Q;i++)
		for(int j=0;j<Q+Q-1;j++)
			vmsk[fa[j]]|=vmsk[j];
	vector<vector<int>> vh(Q);
	for(int i=0;i<K;i++)
	{
		int msk=read_32();
		if(msk==31) continue;
		cerr<<vmsk[msk]<<endl;
		for(int j=0;j<Q;j++)
			if(vmsk[msk]>>j&1)
				vh[j].pb(X[i]);
	}
	int indd=0;
	for(auto v:T)
	{
		vector<int> ans;
		int cur=0;
		vector<int> have=vh[indd++];
		vector<int> vis(sz(have));
		vector<int> path;
		for(int i=1;i<=sz(have);i++)
		{
			int ind=lb(pool,cur);
			if(!called[ind])
			{
				called[ind]=1;
				solve(ind);
			}
			int mxp=-1;
			for(int j=0;j<sz(have);j++)
				if(!vis[j])
					if(mxp==-1||dist[ind][mxp]>dist[ind][A[have[j]]])
						mxp=A[have[j]];
			for(int j=0;j<sz(have);j++)
				if(!vis[j])
					if(mxp==-1||dist[ind][mxp]>dist[ind][B[have[j]]])
						mxp=B[have[j]];
			int tmp=mxp;
			while(tmp!=cur)
			{
				path.pb(Mp[mp(tmp,lst[ind][tmp])]);
				tmp=lst[ind][tmp];
			}
			rev(path);
			for(auto e:path)
				ans.pb(e);
			for(int j=0;j<sz(have);j++) if(!vis[j])
			{
				if(A[have[j]]==mxp)
				{
					cur=B[have[j]];
					vis[j]=1;
					ans.pb(have[j]);
				}
				else if(B[have[j]]==mxp)
				{
					cur=A[have[j]];
					vis[j]=1;
					ans.pb(have[j]);
				}
			}
			path.clear();
		}
		int ind=lb(pool,cur);
		if(!called[ind])
		{
			called[ind]=1;
			solve(ind);
		}
		int tmp=v;
		while(tmp!=cur)
		{
			path.pb(Mp[mp(tmp,lst[ind][tmp])]);
			tmp=lst[ind][tmp];
		}
		rev(path);
		for(auto e:path)
			ans.pb(e);
		answer(ans);
	}
	return ;
}

详细

Test #1:

score: 100
Accepted
time: 15ms
memory: 7916kb

Manager to Aoi

200 19900
13 70 985302938314
120 174 18964037101
18 153 170196070829
45 129 323777973024
62 198 689223413645
88 133 457404464825
19 57 803409835578
22 187 662331177910
18 31 529437059733
161 182 637731822589
109 131 32831735773
109 191 875742441191
43 78 135479410688
56 60 19000632823
44 143 6823771...

Aoi to Manager

A11111110011010001011101100101010100111110010111011010110000000100000001010001100001011101000000000111101101001001100101011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

Manager to Bitaro

200 19900
13 70 985302938314
120 174 18964037101
18 153 170196070829
45 129 323777973024
62 198 689223413645
88 133 457404464825
19 57 803409835578
22 187 662331177910
18 31 529437059733
161 182 637731822589
109 131 32831735773
109 191 875742441191
43 78 135479410688
56 60 19000632823
44 143 6823771...

Bitaro to Manager

4
17135 3534 4830 14466
1
11921
2
17135 9906
4
17135 3534 18777 907
6
18033 13659 9145 14255 10379 11567
7
11921 7585 5782 2139 15549 19315 13987
2
17135 13815
5
17135 13815 8201 7265 15719
4
17135 3534 4830 9175
4
11921 7585 5782 8018
2
18033 13659
4
11921 7585 10922 14444
5
468 273 10532 11483 845...

Manager to Checker

1.00

result:

points 1.0

Test #2:

score: 100
Accepted
time: 1ms
memory: 3896kb

Manager to Aoi

6 7
0 5 839719370667
2 4 244076065937
1 5 337346113825
2 3 716558559511
1 4 837188452057
0 3 661778933008
1 3 678360389380
5
2 3 1 5 4
7
4 2 0 6 1 5 3

Aoi to Manager

A11111101101100000111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111010001100011111001001000000000F

Manager to Bitaro

6 7
0 5 -1
2 4 -1
1 5 -1
2 3 -1
1 4 -1
0 3 -1
1 3 -1
5
2 3 1 5 4
7
4 2 0 6 1 5 3
A11111101101100000111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111010001100011111001001000000000F

Bitaro to Manager

2
5 3
1
5
2
0 2
1
0
3
5 3 1
F

Manager to Checker

1.00

result:

points 1.0

Test #3:

score: 0
Wrong Answer
time: 65ms
memory: 76596kb

Manager to Aoi

10000 19480
2933 9484 1000000000000
2567 9405 1000000000000
5263 6064 1000000000000
1453 8911 1000000000000
2445 8695 1000000000000
5686 7074 1000000000000
5031 5441 1000000000000
253 5144 1000000000000
8087 8704 1000000000000
263 3499 1000000000000
5200 8741 1000000000000
5764 8908 1000000000000
20...

Aoi to Manager

A11100111010000101001110101000001000101010001101111011011011000100011011100011100011000111001101001110010010100111110000011111111111111111111111111110111111001011111111111111111111111111111110101011111111111111111111111111110111111111111111111111101001111110011111111100111111111111011011111111111111...

Manager to Bitaro

10000 19480
2933 9484 1000000000000
2567 9405 1000000000000
5263 6064 1000000000000
1453 8911 1000000000000
2445 8695 1000000000000
5686 7074 1000000000000
5031 5441 1000000000000
253 5144 1000000000000
8087 8704 1000000000000
263 3499 1000000000000
5200 8741 1000000000000
5764 8908 1000000000000
20...

Bitaro to Manager

97
3060 18368 7726 17142 5985 14532 2640 14471 7194 19306 3061 5161 16214 7373 11764 3296 12515 7042 6222 1690 5352 14008 12642 6794 293 10981 6900 13148 16790 5580 4232 18515 15247 861 11590 7841 2964 16468 12973 6217 15383 9794 11429 6053 10375 9579 5235 16442 17666 18734 13812 14712 4824 9707 190...

Manager to Checker

0.00

result:

points 0.0