QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#784529#9431. The Quest for El DoradohotdogsellerWA 195ms19016kbC++144.2kb2024-11-26 15:16:032024-11-26 15:16:03

Judging History

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

  • [2024-11-26 15:16:03]
  • 评测
  • 测评结果:WA
  • 用时:195ms
  • 内存:19016kb
  • [2024-11-26 15:16:03]
  • 提交

answer

#include<bits/stdc++.h>

#define maxn 500005
#define INF 1e18
#define pii pair<int,int>
#define int long long

using namespace std;

inline int read(){
    int lre=0,f=1;
    char c=getchar();
    while(!isdigit(c)){
        if(c=='-'){
            f=-1;
        }
        c=getchar();
    }
    while(isdigit(c)){
        lre=(lre<<3)+(lre<<1)+(c-'0');
        c=getchar();
    }
    return lre*f;
}

struct edge{
	int to;
	int val;
	int c;
	int next;
}e[2*maxn];

int e_cnt=1,head[maxn];

void add(int u,int v,int w,int c){
	e[e_cnt].to=v;
	e[e_cnt].val=w;
	e[e_cnt].c=c;
	e[e_cnt].next=head[u];
	head[u]=e_cnt++;
}

int n,m,k;
int lg[maxn],a[maxn],b[maxn];
pii dis[maxn]; 

unordered_map<int,int> len;//长度 
unordered_map<int,vector<int> > val;//值 
unordered_map<int,vector<int> > st[25];//rmq查询(返回的是a,b数组中指针)

int query(int x,int l,int r){
	int LG=lg[r-l+1];
	int p1=st[LG][x][l],p2=st[LG][x][r-(1<<LG)+1];
	if(b[p1]>=b[p2])return b[p1];
	return b[p2];
}//返回值 

int binar(int x,int beg,int val){
	if(len[x]==0)return -1;
	int l=beg,r=len[x]-1,mid,lre=-1;
	while(l<=r){
		mid=l+r>>1;
		if(query(x,beg,mid)>=val){
			lre=mid;
			r=mid-1;
		}else{
			l=mid+1;
		}
	}
	if(lre==-1)return -1;
	return st[0][x][lre];
}//同一个公司,返回a,b内指针 

bool better(pii a,pii b){
	if(a.first==b.first){
		return a.second<b.second;
	}
	return a.first<b.first;
}//是否更优 

struct node{
	int x;
	pii val;
}; 

node make_node(int x,pii val){
	node lre;lre.x=x;
	lre.val=val;return lre;
}

bool operator <(node a,node b){
	return better(b.val,a.val);
}

priority_queue<node> pq;

void solve(){
	memset(head,0,sizeof(head));
	e_cnt=1;len.clear();val.clear();
	for(int i=0;i<=20;i++){
		st[i].clear();
		dis[i].first=dis[i].second=INF;
	}
	n=read();m=read();k=read();
	for(int i=1;i<=m;i++){
		int u=read(),v=read(),c=read(),w=read();
		add(u,v,w,c);add(v,u,w,c);
	}
	for(int i=1;i<=k;i++){
		a[i]=read();b[i]=read();
		val[a[i]].push_back(b[i]);
		st[0][a[i]].push_back(i);
		len[a[i]]=val[a[i]].size(); 
	}
	for(int i=1;i<=k;++i){
		if(!st[1][a[i]].empty())continue;
		for(int j=1;(1<<j)<=len[a[i]];++j){
			for(int q=0;q+(1<<j)-1<len[a[i]];++q){
				int p1=st[j-1][a[i]][q],p2=st[j-1][a[i]][q+(1<<(j-1))];
				if(b[p1]>=b[p2]){
					st[j][a[i]].push_back(p1);
				}else{
					st[j][a[i]].push_back(p2);
				}
			}
		}
	//	cout<<"val="<<a[i]<<endl;
	//	for(int j=0;(1<<j)<=len[a[i]];++j){
		//	cout<<"j="<<j<<" ";
		//	for(int q=0;q+(1<<j)-1<len[a[i]];++q){
		//		printf("%lld ",st[j][a[i]][q]);
		//	}
		//	putchar('\n');
	//	} 
	}
//	cout<<"begin bfs!"<<endl; 
	dis[1].first=1;dis[1].second=0;
	pq.push(make_node(1,make_pair(1,0)));
	while(!pq.empty()){
		int x=pq.top().x;
		pii val=pq.top().val;
		pq.pop();
		if(better(dis[x],val))continue;
		dis[x]=val;
	//	cout<<"x="<<x<<" dis={"<<dis[x].first<<","<<dis[x].second<<"}"<<endl;
		for(int i=head[x];i;i=e[i].next){
			int v=e[i].to,w=e[i].val,c=e[i].c;
			pii nxt=val;
		//	cout<<"to "<<v<<endl;
		//	cout<<val.first<<" "<<val.second<<endl;
		//	cout<<"w="<<w<<" c="<<c<<endl;
			if(val.first==c&&val.second+w<=b[val.first]){
				//直接上
			//	cout<<"direct use"<<endl;
				nxt.second+=w;
				if(better(nxt,dis[v])){
					dis[v]=nxt;
					pq.push(make_node(v,nxt));
				}
			}else{
				//换票 
			//	cout<<"change!"<<endl;
				int id=binar(c,upper_bound(st[0][c].begin(),st[0][c].end(),val.first)-st[0][c].begin(),w);
				if(id==-1)continue;
			//	cout<<"change to "<<id<<endl;
				nxt.first=id;nxt.second=w;
				if(better(nxt,dis[v])){
					dis[v]=nxt;
					pq.push(make_node(v,nxt));
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(dis[i].first<INF){
			putchar('1');
		}else{
			putchar('0'); 
		}
	}
	putchar('\n'); 
}

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

signed main(){
	
	for(int i=2;i<=500000;i++){
		lg[i]=lg[i>>1]+1;
	}
	
	int t=read();
	while(t--){
		solve();
	} 
	
	return 0;
}
/*
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
*/

详细

Test #1:

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

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
Wrong Answer
time: 195ms
memory: 19016kb

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:

1000000000000000000011111111111111111111111111
1000000000001001000011111111111111111111111111
1000000000000000000011111111111111111111111111
1000000000000000000011111111111111111111111111
1000000000000000000011111111111111111111111111
1000000000000000000011111111111111111111111
100010000000000000001...

result:

wrong answer 1st lines differ - expected: '1000110011110111110010100001010100100101000000', found: '1000000000000000000011111111111111111111111111'