6411. 【NOIP2019模拟11.06】上网
题目描述
Description

Input

Output
若无解,则输出”Impossible”。
否则第一行输出”Possible”,第二行输出 n 个正整数,依次输出序列 a 中每个数。
Sample Input
5 2 2
2 7
5 3
1 4 2 2 3
4 5 1 4
Sample Output
Possible
6 7 1000000000 6 3
Data Constraint

题解
线段树优化连边
ki向xij连边,xi与xi+1间的点向ki连边(线段树),线段树的点从下往上连边
一条从u到v的权值为s的边的意义是f[u]+s<=f[v],拓扑求max即可
初值就是给出的p和d(不需要求出相对大小然后再搞)
code
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
using namespace std;
struct type{
int s,x;
} b[100001];
int a[5000001][3];
int D[1000001];
int ls[1000001];
int d[1000001];
int f[1000001];
int F[1000001];
int c[100002];
int N,n,s,m,i,j,k,l,len,L,R,tot,h,t,mx;
void New(int x,int y,int z)
{
++len;
a[len][0]=y;
a[len][1]=ls[x];
ls[x]=len;
a[len][2]=z;
++D[y];
}
void mt(int t,int l,int r)
{
int mid=(l+r)/2;
N=max(N,t+n);
if (l==r) return;
mt(t*2,l,mid);
if (l<mid)
New(t*2+n,t+n,0);
else
New(l,t+n,0);
mt(t*2+1,mid+1,r);
if (mid+1<r)
New(t*2+1+n,t+n,0);
else
New(r,t+n,0);
}
void work(int t,int l,int r,int x,int y)
{
int mid=(l+r)/2;
if (x<=l && r<=y)
{
if (l==r)
New(l,N,1);
else
New(t+n,N,1);
return;
}
if (x<=mid)
work(t*2,l,mid,x,y);
if (mid<y)
work(t*2+1,mid+1,r,x,y);
}
int main()
{
freopen("web.in","r",stdin);
freopen("web.out","w",stdout);
scanf("%d%d%d",&n,&s,&m);
fo(i,1,n) f[i]=1;
fo(i,1,s)
scanf("%d%d",&b[i].x,&b[i].s),f[b[i].x]=b[i].s,F[b[i].x]=b[i].s;
mt(1,1,n);
fo(i,1,m)
{
++N;
scanf("%d%d%d",&L,&R,&tot);
fo(j,1,tot)
{
scanf("%d",&c[j]);
New(N,c[j],0);
}
c[0]=L-1;
c[++tot]=R+1;
fo(j,1,tot)
if (c[j-1]+1<=c[j]-1)
work(1,1,n,c[j-1]+1,c[j]-1);
}
h=0;t=0;
fo(i,1,N)
if (!D[i])
d[++t]=i;
while (h<t)
{
for (i=ls[d[++h]]; i; i=a[i][1])
{
f[a[i][0]]=max(f[a[i][0]],f[d[h]]+a[i][2]);
if (F[a[i][0]] && f[a[i][0]]>F[a[i][0]])
{
printf("Impossible\n");
return 0;
}
--D[a[i][0]];
if (!D[a[i][0]])
d[++t]=a[i][0];
}
}
if (t<N)
{
printf("Impossible\n");
return 0;
}
else
{
printf("Possible\n");
fo(i,1,n)
printf("%d ",f[i]);
printf("\n");
}
fclose(stdin);
fclose(stdout);
return 0;
}
6411. 【NOIP2019模拟11.06】上网的更多相关文章
- 6409. 【NOIP2019模拟11.06】困难的图论(Tarjan求点双)
题目描述 Description 给定由 n 个点 m 条边组成的无向连通图,保证没有重边和自环. 你需要找出所有边,满足这些边恰好存在于一个简单环中.一个环被称为简单环,当且仅当它包含的所有点都只在 ...
- 6423. 【NOIP2019模拟11.11】画
题目描述 Description Input Output Sample Input 3 2 3 3 6 5 1 2 1 3 Sample Output 15 Data Constraint 题解 迫 ...
- 6407. 【NOIP2019模拟11.05】小 D 与随机
题目描述 Description Input 第一行两个个整数 n,k. 之后 n -1 行,第 i 行两个整数 ui, vi, 表示一条树边. 保证输入的数据构成一棵树. Output 一行一个数表 ...
- 6402. 【NOIP2019模拟11.01】Cover(启发式合并)
题目描述 Description 小 A 现在想用
- jzoj6404. 【NOIP2019模拟11.04】B
题目描述 Description Input 从文件b.in中读入数据. 第丬行三个正整数 n, m, K. 接下来 n 行每行 m 个正整数, 表示矩阵A. Output 输出到文件b.out中. ...
- 【NOIP2019模拟11.01】Game(贪心+线段树)
Description: 小 A 和小 B 在玩一个游戏,他们两个人每人有
- 11.06水题Test
11.06水题比赛 题目 描述 做法 \(BSOJ5150\) 求\(n\)个数两两之差的中位数 二分中位数,双指针判定\(\le x\)差值对数 \(BSOJ5151\) 求树的最大匹配和其个数 来 ...
- JZOJ 3509. 【NOIP2013模拟11.5B组】倒霉的小C
3509. [NOIP2013模拟11.5B组]倒霉的小C(beats) (File IO): input:beats.in output:beats.out Time Limits: 1000 ms ...
- JZOJ 3508. 【NOIP2013模拟11.5B组】好元素
3508. [NOIP2013模拟11.5B组]好元素(good) (File IO): input:good.in output:good.out Time Limits: 2000 ms Mem ...
随机推荐
- php7.2 下安装swoole扩展
git clone git@github.com:swoole/swoole-src.git phpize ./configure make && make test make ins ...
- 机器学习【一】K最近邻算法
K最近邻算法 KNN 基本原理 离哪个类近,就属于该类 [例如:与下方新元素距离最近的三个点中,2个深色,所以新元素分类为深色] K的含义就是最近邻的个数.在sklearn中,KNN的K值是通过n ...
- 【BZOJ2622】[2012国家集训队测试]深入虎穴
虎是中国传统文化中一个独特的意象.我们既会把老虎的形象用到喜庆的节日装饰画上,也可能把它视作一种邪恶的可怕的动物,例如“武松打虎”或者“三人成虎”.“不入虎穴焉得虎子”是一个对虎的威猛的形象的极好体现 ...
- 伯努利分布、二项分布、多项分布、Beta分布、Dirichlet分布
1. 伯努利分布 伯努利分布(Bernoulli distribution)又名两点分布或0-1分布,介绍伯努利分布前首先需要引入伯努利试验(Bernoulli trial). 伯努利试验是只有两种可 ...
- 【Qt开发】【VS开发】【Linux开发】OpenCV、Qt-MinGw、Qt-msvc、VS2010、VS2015、Ubuntu Linux、ARM Linux中几个特别容易混淆的内容
[Qt开发][VS开发][Linux开发]OpenCV.Qt-MinGw.Qt-msvc.VS2010.VS2015.Ubuntu Linux.ARM Linux中几个特别容易混淆的内容 标签:[Qt ...
- JavaScript Return Object.Type
var getType = function(obj) { if (obj == null) { return String(obj); } return typeof obj === 'object ...
- Mybatis-学习笔记(N)mybatis-generator 生成DAO、Mapper、entity
1.mybatis-generator 生成DAO.Mapper.entity 所需环境:jdk 所需jar包:mybatis-generator-core-1.3.5.jar.MySQL-conne ...
- 剑指Offer编程题(Java实现)——两个链表的第一个公共结点
题目描述: 输入两个链表,找出它们的第一个公共结点. 思路一: 设 A 的长度为 a + c,B 的长度为 b + c,其中 c 为尾部公共部分长度,可知 a + c + b = b + c + a. ...
- .Net Core - 使用Supervisor进行托管部署
环境 CentOS 7 x64,详见 安装CentOS7虚拟机 .Net Core 2.1.801 详见 CentOS 7 下安装.NET Core SDK 2.1 ftp 详见 CentOS7 ...
- 极*Java速成教程 - (5)
Java语言基础 容器 这个世界是有序的,将Java对象零散地放到内存中是不符合世界常理的,特别是有一大组相似的甚至不知道有多少数据的时候.把Java对象装进盒子里可以有序收纳,这个盒子就叫容器. 初 ...