题目描述

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】上网的更多相关文章

  1. 6409. 【NOIP2019模拟11.06】困难的图论(Tarjan求点双)

    题目描述 Description 给定由 n 个点 m 条边组成的无向连通图,保证没有重边和自环. 你需要找出所有边,满足这些边恰好存在于一个简单环中.一个环被称为简单环,当且仅当它包含的所有点都只在 ...

  2. 6423. 【NOIP2019模拟11.11】画

    题目描述 Description Input Output Sample Input 3 2 3 3 6 5 1 2 1 3 Sample Output 15 Data Constraint 题解 迫 ...

  3. 6407. 【NOIP2019模拟11.05】小 D 与随机

    题目描述 Description Input 第一行两个个整数 n,k. 之后 n -1 行,第 i 行两个整数 ui, vi, 表示一条树边. 保证输入的数据构成一棵树. Output 一行一个数表 ...

  4. 6402. 【NOIP2019模拟11.01】Cover(启发式合并)

    题目描述 Description 小 A 现在想用

  5. jzoj6404. 【NOIP2019模拟11.04】B

    题目描述 Description Input 从文件b.in中读入数据. 第丬行三个正整数 n, m, K. 接下来 n 行每行 m 个正整数, 表示矩阵A. Output 输出到文件b.out中. ...

  6. 【NOIP2019模拟11.01】Game(贪心+线段树)

    Description: ​ 小 A 和小 B 在玩一个游戏,他们两个人每人有

  7. 11.06水题Test

    11.06水题比赛 题目 描述 做法 \(BSOJ5150\) 求\(n\)个数两两之差的中位数 二分中位数,双指针判定\(\le x\)差值对数 \(BSOJ5151\) 求树的最大匹配和其个数 来 ...

  8. JZOJ 3509. 【NOIP2013模拟11.5B组】倒霉的小C

    3509. [NOIP2013模拟11.5B组]倒霉的小C(beats) (File IO): input:beats.in output:beats.out Time Limits: 1000 ms ...

  9. JZOJ 3508. 【NOIP2013模拟11.5B组】好元素

    3508. [NOIP2013模拟11.5B组]好元素(good) (File IO): input:good.in output:good.out Time Limits: 2000 ms  Mem ...

随机推荐

  1. 【漏洞学习】HOST 头攻击漏洞

    日期:2018-03-06 14:32:51 作者:Bay0net 0x01. 前言 在一般情况下,几个网站可能会放在同一个服务器上,或者几个 web 系统共享一个服务器,host 头来指定应该由哪个 ...

  2. HTML学习之==>DOM操作

    DOM(Document Object Model 文档对象模型) 一个web页面的展示,是由html标签组合成的一个页面,dom对象实际就是将html标签转换成了一个文档对象.可以通过dom对象中j ...

  3. Spring MVC 中RequestContextHolder获取request和response

    1.最简单方式:处理方法入参 例如: @RequestMapping("/test") @ResponseBody public void saveTest(HttpServlet ...

  4. 从零构建vue项目(三)--vue常用插件

    一.直接拉取的模板中,package.json如下: { "name": "vuecli2-test", "version": " ...

  5. vue封装一些常用组件loading、switch、progress

    vue封装一些常用组件loading.switch.progress github文档https://github.com/zengjielin/vue-component-library loadi ...

  6. ipad已停用 连接itunes怎么办

    问题描述: ipad 开机密码多次输入出错后,提示 ipad已停用 连接itunes 解决方法: 参考: https://jingyan.baidu.com/article/fb48e8bee9ef4 ...

  7. 根据select的option文本选中对应的选项

    function selectByOptionTxt(obj,txt){ var optionArr = $(obj).find("option"); for(var i=0;i& ...

  8. [转帖]是时候深入了解Linux的系统结构

    是时候深入了解Linux的系统结构   http://os.51cto.com/art/201905/596011.htm linux的体系结果 其实自己也知道 linus 做了一个 kernel 大 ...

  9. 【6.10校内test】T2 医院设置

    医院设置[题目链接] 感觉我超废 我是一个连floyd都不会写了的灵魂OI选手qwq(考场上写了半天spfa然后写炸了(微笑)) floyd的暴力: 1.先建树:用邻接矩阵存.存之前记得先初始化为IN ...

  10. ubuntu14 teamviewer使用

    一. 软件安装 1.1. 下载.deb文件 下载13版本的,不要下载最新版本的 1.2. 环境配置 <1>. sudo dpkg --add-architecture i386 <2 ...