题目描述

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;
}

最新文章

  1. Python之路Day15--JavaScript(一)
  2. kali 在线教学群 第一次 公开课 小结(1)
  3. 打包jar文件 外部调用资源 so等
  4. 关于在官网上查看和下载特定版本的webrtc代码
  5. linux设备驱动归纳总结(三):4.ioctl的实现【转】
  6. poj 3352 Road Construction
  7. leetcode@ [336] Palindrome Pairs (HashMap)
  8. [工具]toolbox_graph基本操作
  9. OD: Big_Endian vs Little_Endian
  10. webstorm入门1-主题和配色
  11. Sybase Unwired Platform(SUP) 经常使用资源整理(不断更新中)
  12. 如何自动以管理员身份运行.NET程序?
  13. Nginx和php是怎么通信的?
  14. Android项目中的换肤总结
  15. AngularJS进阶(二十一)Angularjs中scope与rootscope区别及联系
  16. Scala操作Hbase空指针异常java.lang.NullPointerException处理
  17. Delphi 10.3版本获取windows系统版本和CPU信息
  18. web类协议脚本-飞机订票系统示例
  19. c3p0配置之preferredTestQuery参数默认值探秘
  20. 不用ajax实现异步请求:XmlHttpRequest 小记

热门文章

  1. vue 请求完接口后执行方法
  2. Linux监控命令之==&gt;vmstat
  3. iptables规则
  4. pandas DataFram的insert函数
  5. 【Linux开发】Linux动态链接库搜索路径问题
  6. .net core 学习小结之环境配置篇
  7. Mysql 5.7存储过程的学习
  8. 打印 PRINT
  9. JS基础篇--JS获取元素的宽高以及offsetTop,offsetLeft等的属性值
  10. python字符串替换的2种方法