QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#754870#9431. The Quest for El DoradowsxcbRE 0ms3864kbC++172.3kb2024-11-16 16:00:292024-11-16 16:00:38

Judging History

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

  • [2024-11-16 16:00:38]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3864kb
  • [2024-11-16 16:00:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
typedef vector<vector<ll>> Mat;
const int N=3e5+10,mod=998244353,inf=2e9+18;
const double pi=acos(-1.0),esp=1e-9;
const ll INF=1e18;
struct node{
	int u,col,v1,v2;
	bool operator<(const node &t)const{
		if(v1==t.v1) return t.v2>v2;
		return t.v1<v1;
	}
};
const int M=20;
void solve(){
	int n,m,k;
	cin>>n>>m>>k;
	vector< vector<vector<int>> >st(m+1,vector<vector<int>>(20));
	vector<vector<int>>pos(m+1);
	vector<int>vis(n+1);
	vector< vector< array<int,3> > >e(n+1);
	pair<int,int>sc={inf,inf};
	vector<pair<int,int>>dis(n+1,sc);
	dis[1]={0,0};
	//cout<<e.size()<<'\n';
	for(int i=1;i<=m;i++){
		int u,v,c,l;
		cin>>u>>v>>c>>l;
		e[u].pb({v,c,l});
		e[v].pb({u,c,l});
		pos[i].pb(0);
		st[i][0].pb(0);
	}
	
	priority_queue<node>q;
	for(int i=1;i<=k;i++){
		int a,b;
		cin>>a>>b;
		pos[a].pb(i);
		st[a][0].pb(b);
	}
	
	for(int i=1;i<=m;i++){
		int len1=pos[i].size(),len2=__lg(pos[i].size());
		for(int j=1;j<len2;j++){
			st[i][j].resize(len1);
			for(int k=0;k+(1<<j)-1<len1;k++)
			st[i][j][k]=max(st[i][j-1][k],st[i][j-1][k+(1<<(j-1))]);
		}
	}
	
	auto get=[&](int col,int l,int r){
		int len=__lg(r-l+1);
		return max(st[col][len][l],st[col][len][r-(1<<len)+1]);
	};
	
	q.push({1,0,0,0});
	while(q.size()){
		auto [u,col1,v1,v2]=q.top();
		q.pop();
		if(vis[u])continue;
		vis[u]=1;
		for(auto [v,col2,l]:e[u]){
			if(col1==col2&&v2>=l){
				if(dis[v].fi>v1||(dis[v].fi==v1&&dis[v].se<v2-l))
				{
					dis[v]={v1,v2-l};
					q.push({v,col1,v1,v2-l});
				}
				continue;
			}
			int p1=upper_bound(pos[col2].begin(),pos[col2].end(),v1)-pos[col2].begin();
			int l1=p1,r1=pos[col2].size()-1,ans=-1;
			while(l1<=r1){
				int mid=(l1+r1)/2;
				if(get(col2,p1,mid)>=l){
					r1=mid-1;
					ans=mid;
				}else
				l1=mid+1;
			}
			if(ans==-1)continue;
			int x=pos[col2][ans],y=st[col2][0][ans]-l;
			if(x<dis[v].fi||(x==dis[v].fi&&y>dis[v].se)){
				dis[v]={x,y};
				q.push({v,col2,x,y});
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(dis[i].fi<=k)cout<<1;
		else cout<<0;
	}
	cout<<'\n';
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int t=1;
    cin>>t;
    while(t--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3864kb

input:

2
5 6 4
1 2 1 30
2 3 1 50
2 5 5 50
3 4 6 10
2 4 5 30
2 5 1 40
1 70
6 100
5 40
1 30
3 1 1
2 3 1 10
1 100

output:

11011
100

result:

ok 2 lines

Test #2:

score: -100
Runtime Error

input:

1110
46 80 30
44 23 5 46
10 28 1 64
32 34 3 40
9 36 1 26
15 14 5 95
38 19 2 34
2 17 4 183
10 38 2 81
5 15 2 83
31 38 3 100
40 30 1 53
41 10 1 193
29 20 5 18
14 41 3 78
8 16 5 74
46 13 3 78
44 28 3 45
1 40 3 133
5 32 1 108
22 26 2 83
10 38 1 77
11 40 1 11
17 21 2 66
41 46 3 98
9 36 2 25
40 18 1 19
27...

output:


result: