题面

题意:有3e5个人排成一列,然后Li,Ri表示每个人可以站在[Li,Ri]中的一个,然后M(1e6)个限制条件,某个人一定要在某个人前面,求一种合法方案,无解输出-1

题解:首先可以想到对于限制条件,先进行拓扑排序,如果不能则无解

针对拓扑排序的结果,可以更精确每个人站的位置的区间[Li,Ri]

然后从后往前进行考虑,我们考虑每个位置由谁来坐比较好,那我们策略是,R能覆盖这个位置的中,L最大的那一个来最优,

我们一直维护一个R的堆,每次我们将R超过当前位置的人都丢进一个新的堆里,这个堆按L大来排序,再使用最大的那个L

如此贪心做完,不行则无解

 #include<bits/stdc++.h>
#define lld long long
#define N 300005
using namespace std;
vector<int> g[N];
int n,m,du[N],x,y,ans[N];
struct rec
{
int l,r,id;
bool operator <(const rec& a)const
{
if (r!=a.r) return r<a.r;
return l>a.l;
}
}a[N];
struct ssy
{
int l,r,id;
bool operator <(const ssy& a)const
{
return l<a.l;
}
}b[N];
int ask()
{
priority_queue<ssy>q;
priority_queue<rec>qq;
ssy st;
while (!q.empty()) q.pop();
while (!qq.empty()) qq.pop();
for (int i=;i<=n;i++) if (du[i]==) qq.push(a[i]);
for (int i=n;i>=;i--)
{
while (!qq.empty())
{
if (qq.top().r<i) break;
q.push(b[qq.top().id]);
// cout << b[qq.top().id].id << endl;
qq.pop();
}
if (q.empty() || q.top().l>i) return ;
st=q.top();
// cout<<st.id << endl;
q.pop(); //cout<<"id"<<st.id<<endl;
ans[i]=st.id; for (int j=;j<g[st.id].size();j++)
{
int u=g[st.id][j];
du[u]--;
if (du[u]==) qq.push(a[u]);
}
}
return ;
}
int c[N];
bool dfs(int u)
{
c[u]=-;
for (int v=;v<g[u].size();v++)
{
int to=g[u][v];
if (c[to]<)
{
//cout<<"u xxx:"<<u<<endl;
//cout<<"1 xxx:"<<to<<endl;
return ;
}else
if (!c[to] && !dfs(to))
{
//cout<<"u xxx:"<<u<<endl;
//cout<<"1 xxx:"<<to<<endl;
return ;
}
a[u].l=max(a[u].l,a[to].l+);
b[u].l=a[u].l;
}
c[u]=;
return ;
}
bool toposort()
{
memset(c,,sizeof(c));
for (int u=;u<=n;u++) if (!c[u])
if (!dfs(u)) return ;
return ;
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++)
{
scanf("%d%d",&a[i].l,&a[i].r);a[i].id=i;
b[i].l=a[i].l;
b[i].r=a[i].r;
b[i].id=a[i].id;
}
for (int i=;i<=m;i++)
{
scanf("%d%d",&x,&y);
g[y].push_back(x);
du[x]++;
}
if (!toposort()) printf("-1\n");else
if (!ask()) printf("-1\n");else
for (int i=;i<=n;i++) printf("%d\n",ans[i]); //for (int i=1;i<=n;i++) cout<<a[i].l<<" "<<a[i].r<<endl;
}

Gym - 102059D 2018-2019 XIX Open Cup, Grand Prix of Korea D. Dumae 贪心+堆的更多相关文章

  1. 【GYM 102059】2018-2019 XIX Open Cup, Grand Prix of Korea

    vp了一场gym,我又开心地划水了. A. Coloring Roads 题意:给定一棵树,树边一开始都是无色的,每次操作可以把一个点到根的路径染成某个颜色,每次询问当前树上出现过某个次数的颜色种数. ...

  2. 2018-2019 XIX Open Cup, Grand Prix of Korea (Division 2) GYM 102058 F SG函数

    http://codeforces.com/gym/102058/problem/F 题意:平面上n个点  两个人轮流在任意两个点之间连一条线但是不能和已有的线相交,先围成一个凸多边形的获胜,先手赢还 ...

  3. Gym.102059: 2018-2019 XIX Open Cup, Grand Prix of Korea(寒假gym自训第一场)

    整体来说,这一场的质量比较高,但是题意也有些难懂. E.Electronic Circuit 题意:  给你N个点,M根线,问它是否是一个合法的电路. 思路:  一个合法的电路,经过一些串联并联关系, ...

  4. Codeforces gym102058 J. Rising Sun-简单的计算几何+二分 (2018-2019 XIX Open Cup, Grand Prix of Korea (Division 2))

    J. Rising Sun time limit per test 1.0 s memory limit per test 1024 MB input standard input output st ...

  5. 2018-2019 XIX Open Cup, Grand Prix of Korea B - Dev, Please Add This!

    B - Dev, Please Add This! 思路: 对于每一个经过 '*' 的横线和竖线看成一个整体,设他们分别为分量x和分量y 用2-sat考虑这个问题, 如果要经过 '*' ,那么x和y至 ...

  6. XVIII Open Cup named after E.V. Pankratiev. Grand Prix of Korea

    A. Donut 扫描线+线段树. #include<cstdio> #include<algorithm> using namespace std; typedef long ...

  7. 【推导】【数学期望】【冒泡排序】Petrozavodsk Winter Training Camp 2018 Day 5: Grand Prix of Korea, Sunday, February 4, 2018 Problem C. Earthquake

    题意:两地之间有n条不相交路径,第i条路径由a[i]座桥组成,每座桥有一个损坏概率,让你确定一个对所有桥的检测顺序,使得检测所需的总期望次数最小. 首先,显然检测的时候,是一条路径一条路径地检测,跳跃 ...

  8. 【线段树】【扫描线】Petrozavodsk Winter Training Camp 2018 Day 5: Grand Prix of Korea, Sunday, February 4, 2018 Problem A. Donut

    题意:平面上n个点,每个点带有一个或正或负的权值,让你在平面上放一个内边长为2l,外边长为2r的正方形框,问你最大能圈出来的权值和是多少? 容易推出,能框到每个点的 框中心 的范围也是一个以该点为中心 ...

  9. 2020-2021 Winter Petrozavodsk Camp, Belarusian SU Contest (XXI Open Cup, Grand Prix of Belarus) 题解

    题目列表 C. Brave Seekers of Unicorns D. Bank Security Unification G. Biological Software Utilities I. B ...

随机推荐

  1. 1002 A+B for Polynomials (PAT (Advanced Level) Practice)

    This time, you are supposed to find A+B where A and B are two polynomials. Input Specification: Each ...

  2. 关于JavaScript的一些笔试题

    1.原题: function Foo() { getName = function () { alert (); }; return this; } Foo.getName = function () ...

  3. DS26C31M和DS26C32AM

    DS26C31M是产生差分信号的芯片,实际使用的时候,测得在5V供电的情况下,输出+和输出-的压差是5V其中输出+和输入的特性相同. DS26C32AM是接收差分信号的芯片,与DS26C31M可以向配 ...

  4. MySQL导入-导出数据库-mac版

    MySQL导入-导出数据库-mac版 导出数据库-表结构,和数据 mysqldump -u 账号 -p 数据库名 表 > 文件名.sql 例如:mysqldump -u root -p test ...

  5. [bzoj1001]狼爪兔子[平面图的最小割等于其对偶图的最短路]

    一定要仔细算内存,,,又少写一个零.. #include <bits/stdc++.h> using namespace std; template<const int _n,con ...

  6. 在代码动态设置RelativeLayout的属性,比如layout_below

    ( (RelativeLayout.LayoutParams)holder.ivLvDivider.getLayoutParams()).addRule(RelativeLayout.BELOW, R ...

  7. CentOS 安装Oracle 11g R2

    CentOS 安装Oracle 11g R2 学习了-/ https://www.osyunwei.com/archives/5445.html

  8. [bzoj1617][Usaco2008 Mar]River Crossing渡河问题_动态规划

    River Crossing渡河问题 bzoj-1617 Usaco-2008 Mar 题目大意:题目链接. 注释:略. 想法:zcs0724出考试题的时候并没有发现这题我做过... 先把m求前缀和, ...

  9. HDU 1166敌兵布阵

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  10. MyBatis3-实现单表数据的增删查改

    继续前一篇文章http://www.cnblogs.com/EasonJim/p/7050710.html所示的例子,返回的是单个实体,而接下来将进行列表的返回等操作: 一.查询列表 查询出列表,也就 ...