题目链接:https://nanti.jisuanke.com/t/40259

Ichuan really likes to play games, so he organized a game competition with NN participating players.

Follows are the rule of the game competition.

  1. There are three modes in the game, in each mode, players have different ability values, in addition, each player may have different ability value in different mode.

  2. There are a total of N-1 matches. In each match, two players who have not yet been eliminated will play against each other in one of the modes. The player who has high ability in this mode will win, and the other one will be eliminated.

  3. The only player who remains in the game after all N-1 matches will be the winner.

As the organizer of the game, ichuan can manipulate the result of the game. Namely, for each match, he can choose both players and match mode. Of course, he can only choose players who have not yet been eliminated.

Ichuan has some friends, some of them will ask him: "Does player XX will be the winner?" Answering this question will give you a lot of reward, so you need to write a program which can answer these questions.

Input

The first line contains integers N and Q(1≤N,Q≤105), the number of players and the number of requests.

The next three lines, each line contains N integers, the Xth​ integer Y(1≤Y≤106)represents the ability value of player X in this mode.,

The next qq lines, each line only has one integer X(1≤X≤n), which means ichuan's friend wants to know if player X can be the winner.

Output

For each query, if player X has a chance to be the winner, output "YES", otherwise output "NO"

输出时每行末尾的多余空格,不影响答案正确性

样例输入复制

4 4
1 2 3 4
1 2 4 3
2 1 3 4
1
2
3
4

样例输出复制

NO
NO
YES
YES   

题意:有n个选手,有3个比赛模式,每个模式下每个选手有一个实力值,实力值高者可以打败低者,裁判可以任意选择两个选手在任意模式下比赛,实力高者获胜,实力低着淘汰,q个询问,问裁判是否可以帮助玩家i在经历n-1场获胜。

思路:三个模式,在每个模式下,按照实力排序,再将相邻实力高者与实力低者连边,缩点,入度为0的强连通分量的点都是可以获胜的点。

代码:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int maxm=1e6+10;
struct node{int u,v,w,nxt;
}e[maxm];
int h[maxn],low[maxn],dfn[maxn],vis[maxn];
int st[maxn],belong[maxn],du[maxn];
int n,q,cnt,tot,top,num,y;
struct nd{int x,id;
}a[maxn];
bool cmp(nd a1,nd a2)
{return a1.x<a2.x;
}
void init()
{memset(h,-1,sizeof(h));memset(belong,0,sizeof(belong));memset(du,0,sizeof(du));memset(dfn,0,sizeof(dfn));memset(vis,0,sizeof(vis));cnt=tot=num=top=0;
}void add(int u,int v)
{e[cnt].u=u,e[cnt].v=v;e[cnt].nxt=h[u];h[u]=cnt++;
}void tarjan(int u)//缩点
{dfn[u]=low[u]=++tot;vis[u]=1;st[++top]=u;for(int i=h[u];i!=-1;i=e[i].nxt){int v=e[i].v;if(!dfn[v]) {tarjan(v);low[u]=min(low[u],low[v]);    }else if(vis[v])low[u]=min(low[u],dfn[v]);}if(dfn[u]==low[u]){int t;num++;do{t=st[top--];vis[t]=0;belong[t]=num;}while(t!=u);}
}int main()
{init();scanf("%d%d",&n,&q);for(int i=1;i<=3;i++){for(int j=1;j<=n;j++){scanf("%d",&a[j].x);a[j].id=j;}sort(a+1,a+n+1,cmp);//排序 for(int j=1;j<n;j++)//连边 add(a[j+1].id,a[j].id);}for(int i=1;i<=n;i++)if(!dfn[i])tarjan(i);for(int i=0;i<cnt;i++)//计算入度 if(belong[e[i].u]!=belong[e[i].v])du[belong[e[i].v]]++;for(int i=1;i<=q;i++){scanf("%d",&y);if(du[belong[y]]==0)printf("YES\n");elseprintf("NO\n");}return 0;
}

转载于:https://www.cnblogs.com/xiongtao/p/11248278.html

2019 icpc南昌邀请赛 G Winner相关推荐

  1. 2019 ICPC南昌邀请赛网络赛比赛过程及题解

    解题过程 中午吃饭比较晚,到机房lfw开始发各队的账号密码,byf开始读D题,shl电脑卡的要死,启动中...然后听到谁说A题过了好多,然后shl让blf读A题,A题blf一下就A了.然后lfw读完M ...

  2. 2019 ICPC南昌邀请赛比赛游记 队伍名:莫比乌斯

    南昌队伍是学长临时组的 飞的那天和学长们坐 6.1的飞机 川航还发了棒棒糖 下飞机就落在了座位上了 然后难道大暴雨 我鞋子都湿了 我们和学长去了酒店 酒店是很有情趣味道 滑稽 于是拍下了学长的背影 学 ...

  3. 2019 ICPC 南昌邀请赛 A-Attack(斯坦纳树)

    题意:给出一个无向图,和四对数据.每对数据分别为图中的两个点.要求添加一些边,使每对点都能连通,让总边权最小. 分析:POJ3123.NWERC2006原题,<acm国际大学生程序设计竞赛:题目 ...

  4. 2019 ICPC全国邀请赛(西安)I. Cracking Password(序列检验,BSGS,细节题)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 2019 ICPC全国邀请赛(西安)I. Cracking Password Weblink http ...

  5. 2019 ICPC 南昌网络赛 H. The Nth Item

    2019 ICPC 南昌网络赛 H. The Nth Item 题目大意:已知一个数列F(n): F(0)=0,F(1)=1 F(n)=3∗F(n−1)+2∗F(n−2),(n≥2) ​ 给你一个操作 ...

  6. 2019 ICPC中国邀请赛(南昌)暨国际丝绸之路程序设计竞赛-网络赛题解

    以下所有AC题解程序来自"仙客传奇"团队. AC题数:10/13 ABCDHIJKLM A. PERFECT NUMBER PROBLEM 解题思路:先编写离线程序计算出最小的5个 ...

  7. 2019 ACM/ICPC 南昌站 G,拉格朗日插值

    题意: 求∑i=1t∑k=xyf(i,k)\sum^t_{i=1}\sum^y_{k=x}f(i,k)i=1∑t​k=x∑y​f(i,k) 其中f(i,k)f(i,k)f(i,k)表示1,2,3,.. ...

  8. 2019 ICPC 南昌 K. Tree(树上启发式合并,平衡树 treap)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 题目链接 https://nanti.jisuanke.com/t/42586 Problem 给定一 ...

  9. 2019 ICPC南昌网络赛 E题 Magic Master 【双向队列】

    传送门:E.Magic Master John is not only a magic master but also a shuffling master. Famous though he is, h ...

最新文章

  1. 2017 年最流行的 15 个数据科学 Python 库
  2. jQuery源码dom ready分析
  3. python中uss的用法_使用不同内存ussag管理Python多进程进程进程
  4. Delphi 105错误
  5. FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
  6. Davinci及U-boot的一些介绍
  7. unity json解析IPA后续
  8. 冠军方案 | 第二届中国“高分杯”美丽乡村大赛第一名总结
  9. python安装与使用Ta-Lib,获取金融技术面特征
  10. python 计算时间重叠_python whilepython计算两个矩形框重合百分比的实例
  11. 网络排障少走弯路两案例速解网管疑难
  12. Java库转oc,(java转行oc)什么是block,用java来解释oc中的block
  13. Zookeeper-watcher机制源码分析(一)
  14. 硅谷钢铁侠的的传奇人生
  15. 前后端交互、Node、npm、Express、mysql基础
  16. 使用poi操作word
  17. 数字化转型 — 新能源汽车 — 生产制造流程 — 总装车间
  18. sqlite优化简单分析
  19. 一些Mac OS X技巧
  20. 【二叉搜索树】(三) 小结

热门文章

  1. 华为鸿蒙OS正式发布!教你如何升级
  2. android studio signingconfigs 打正式包,Android-SigningConfigs打包配置
  3. 计算机英语第四版可可英语翻译,专四英语作文高分范文背诵(MP3+中英字幕)第28篇:计算机和人翻译...
  4. 【Java基础】类的具体细节
  5. CPT203 软件工程开发 笔记
  6. 名帖205 蔡襄 行书《蔡襄自书诗》
  7. 简易炸弹超人 题解(蓝桥杯中级组2023选拔赛)
  8. [049] 微信公众平台开发视频公开课第1讲-基础入门
  9. java计算机毕业设计疫情期间高校师生外出请假管理系统录屏源代码+系统+数据库+lw文档
  10. Navicat导入excel表格(xlsx)报错解决