题目描述

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. python学习之文件读写操作

    open函数 在使用文件之前,需要先打开,即使用open函数 如: files=open("文件路径","操作方式") 解释如下: (1.files:为文件对象 ...

  2. 【Linux 应用编程】进程管理 - 进程间通信IPC之共享内存 mmap

    IPC(InterProcess Communication,进程间通信)是进程中的重要概念.Linux 进程之间常用的通信方式有: 文件:简单,低效,需要代码控制同步 管道:使用简单,默认阻塞 匿名 ...

  3. cocos2dx基础篇(15) 列表视图CCTableView

    [3.x] (1)去掉 "CC" (2)TableViewCell 中: > unsigned int getIdx() 返回类型改为 ssize_t(类型为 long) ( ...

  4. Django-DRF组件学习-环境安装与配置与序列化器学习

    1.DRF环境安装与配置 DRF需要以下依赖: Python (2.7, 3.2, 3.3, 3.4, 3.5, 3.6) Django (1.10, 1.11, 2.0) DRF是以Django扩展 ...

  5. 知识图谱之图数据库Neo4j

    知识图谱中的知识是通过RDF结构来进行表示的,其基本单元是事实.每个事实是一个三元组(S, P, O),在实际系统中,按照存储方式的不同,知识图谱的存储可以分为基于表结构的存储和基于图结构的存储. 基 ...

  6. 更新代码 出现 You need to upgrade the working copy first 错误

    今天更新了Eclipse的subclipse插件,更新代码报如下错误: svn: The working copy at 'E:\591woospace\kst_fashion_alipay_v1.2 ...

  7. shell脚本每隔几秒执行

    while true do cmd(shell 命令) sleep x(x为秒数) done ————————————————版权声明:本文为CSDN博主「这年头起名真难3232」的原创文章,遵循 C ...

  8. JSP技术学习总结

    1.JSP的执行过程 首先用户向服务器发出请求,服务器在接收请求后去寻找响应的jsp页面,然后服务器将jsp页面翻译成.java文件,然后进行编译得到.class字节码文件,服务器执行class文件将 ...

  9. JS跨域--window.name

    JS跨域--window.name:https://www.jianshu.com/p/43ff69d076e3

  10. [多校联考2019(Round 5 T1)] [ATCoder3912]Xor Tree(状压dp)

    [多校联考2019(Round 5)] [ATCoder3912]Xor Tree(状压dp) 题面 给出一棵n个点的树,每条边有边权v,每次操作选中两个点,将这两个点之间的路径上的边权全部异或某个值 ...