我会告诉你我看了很久很久才把题目看懂吗???怀疑智商了

原来他给的l,r还有k个数字都是下标...

比如给了一个样例 l, r, k, x1,x2,x3...xk,代表的是一个数组num[l]~num[r],其中有k个数num[x1],num[x2]....num[xk]这k个数都比l~r区间剩下的(下标不是x1...xk)的任何一个数大。题目就是给m个这种信息然后构造一个符合条件的数列

知道了这一点可以发现每一个信息都是一组偏序关系,即num[x1] > l~r区间剩下的数 .....num[xk] > l~r区间剩下的数.当然如果数量级小的话直接就每一个关系建一条边直接拓扑排序就可以了.但是这道题数量实在太大,然后这里就有一种黑科技---线段树建图优化.因为我们可以保证每次建边的时候,num[xi]都是和一个区间相连的(单个点也算一个区间),这样我们可考虑区间这个整体,当然具体代码怎么写没这么简单.

又学到一种黑科技....

 #include <iostream>
#include <string.h>
#include <cstdio>
#include <vector>
#include <queue>
#include <math.h>
#include <string>
#include <algorithm>
#include <time.h> #define SIGMA_SIZE 26
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) (x&-x)
#define foe(i, a, b) for(int i=a; i<=b; i++)
#define fo(i, a, b) for(int i=a; i<b; i++)
#pragma warning ( disable : 4996 ) using namespace std;
typedef long long LL;
inline LL LMax(LL a, LL b) { return a>b ? a : b; }
inline LL LMin(LL a, LL b) { return a>b ? b : a; }
inline LL lgcd(LL a, LL b) { return b == ? a : lgcd(b, a%b); }
inline LL llcm(LL a, LL b) { return a / lgcd(a, b)*b; } //a*b = gcd*lcm
inline int Max(int a, int b) { return a>b ? a : b; }
inline int Min(int a, int b) { return a>b ? b : a; }
inline int gcd(int a, int b) { return b == ? a : gcd(b, a%b); }
inline int lcm(int a, int b) { return a / gcd(a, b)*b; } //a*b = gcd*lcm
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = ;
const double eps = 1e-;
const int inf = 0x3f3f3f3f;
const int maxk = 3e6+;
const int maxn = 1e6+; int cnt, tot;
int indexx[maxn], val1[maxn], val2[maxn], x[maxn], in[maxn];
int linjie[maxn];
int n, s, m;
queue<int> q;
struct node {
int to, nnext, len;
}pp[maxk]; void addedge( int u, int v, int l )
{ pp[cnt].to = v; pp[cnt].len = l; pp[cnt].nnext = linjie[u]; linjie[u] = cnt++; in[v]++; } void build(int rt, int L, int R)
{
if ( L == R )
{ indexx[L] = rt; return; } int mid = (L+R)>>;
build(lson, L, mid);
build(rson, mid+, R);
addedge(lson, rt, ); addedge(rson, rt, );
} void update(int rt, int L, int R, int lhs, int rhs, int C)
{
if ( lhs <= L && rhs >= R )
{
addedge(rt, C, );
return;
} int mid = (L+R)>>;
if ( lhs <= mid ) update(lson, L, mid, lhs, rhs, C);
if ( rhs > mid ) update(rson, mid+, R, lhs, rhs, C);
} void init()
{
cnt = ;
memset(linjie, -, sizeof(linjie));
build(, , n); tot = n << ; int a, b;
while (s--)
{
scanf("%d %d", &a, &b);
val1[indexx[a]] = val2[indexx[a]] = b;
}
} int main()
{
cin >> n >> s >> m;
init(); int l, r, k;
while (m--)
{
scanf("%d %d %d", &l, &r, &k);
x[] = l-; x[k+] = r+; tot++; foe(i, , k) {
scanf("%d", &x[i]);
addedge(tot, indexx[x[i]], );
} foe(i, , k) {
if (x[i+] - x[i] > )
update(, , n, x[i]+, x[i+]-, tot);
}
} foe(i, , tot)
if (!in[i]) {
val1[i] = Max(val1[i], );
q.push(i);
} int a, b;
while (!q.empty())
{
a = q.front(); q.pop();
for (int i = linjie[a]; ~i; i = pp[i].nnext) {
val1[pp[i].to] = Max(val1[pp[i].to], val1[a]+pp[i].len);
in[pp[i].to] --; if (val2[pp[i].to] && val1[pp[i].to] > val2[pp[i].to]) {
printf("NIE\n");
return ;
}
if ( !in[pp[i].to] )q.push(pp[i].to);
}
} foe(i, , n)
if ( !val1[indexx[i]] || val1[indexx[i]] > )
{ printf("NIE\n"); return ; } printf("TAK\n");
fo(i, , n)
printf("%d ", val1[indexx[i]]);
printf("%d\n", val1[indexx[n]]);
return ;
}

BZOJ4383/LuoGuP3588 Pustynia/PUS 线段树建图优化的更多相关文章

  1. 【转】Codeforces Round #406 (Div. 1) B. Legacy 线段树建图&&最短路

    B. Legacy 题目连接: http://codeforces.com/contest/786/problem/B Description Rick and his co-workers have ...

  2. HDU5669 Road 分层最短路+线段树建图

    分析:(官方题解) 首先考虑暴力,显然可以直接每次O(n^2) ​的连边,最后跑一次分层图最短路就行了. 然后我们考虑优化一下这个连边的过程 ,因为都是区间上的操作,所以能够很明显的想到利用线段树来维 ...

  3. Codeforces Round #406 (Div. 1) B. Legacy 线段树建图跑最短路

    B. Legacy 题目连接: http://codeforces.com/contest/786/problem/B Description Rick and his co-workers have ...

  4. Codeforces Round #406 (Div. 2) D. Legacy (线段树建图dij)

    D. Legacy time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  5. POJ 2374 线段树建图+Dijkstra

    题意: 思路: 线段树+Dijkstra(要堆优化的) 线段树要支持打标记 一个栅栏 拆成两个点 :左和右 新加一个栅栏的时候 看看左端点有没有被覆盖过 如果有的话 就分别从覆盖的那条线段的左右向当前 ...

  6. 【Codeforces720D】Slalom 线段树 + 扫描线 (优化DP)

    D. Slalom time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

  7. 『The Captain 最短路建图优化』

    The Captain(BZOJ 4152) Description 给定平面上的n个点,定义(x1,y1)到(x2,y2)的费用为min(|x1-x2|,|y1-y2|),求从1号点走到n号点的最小 ...

  8. 【BZOJ3672】【NOI2014】购票(线段树,斜率优化,动态规划)

    [BZOJ3672][NOI2014]购票(线段树,斜率优化,动态规划) 题解 首先考虑\(dp\)的方程,设\(f[i]\)表示\(i\)的最优值 很明显的转移\(f[i]=min(f[j]+(de ...

  9. [POI2015]PUS [线段树优化建图]

    problem 线段树优化建图,拓扑,没了. #include <bits/stdc++.h> #define ls(x) ch[x][0] #define rs(x) ch[x][1] ...

随机推荐

  1. Hadoop配置lzo

    编译: 0. 环境准备 maven(下载安装,配置环境变量,修改sitting.xml加阿里云镜像) gcc-c++ zlib-devel autoconf automake libtool 通过yu ...

  2. Could not open file ..\obj\sys.o: No such file or directory解决办法

    一.你的keil的安装路径以及系统用户名是否带中文字符以及一些特殊字符.二.环境变量的值存在中文或者特殊字符了,解决方法如下: 1.在C盘建立一个新的文件夹,命名为英文,如qcl2.右击"此 ...

  3. hdu多校第三场 1006 (hdu6608) Fansblog Miller-Rabin素性检测

    题意: 给你一个1e9-1e14的质数P,让你找出这个质数的前一个质数Q,然后计算Q!mod P 题解: 1e14的数据范围pass掉一切素数筛法,考虑Miller-Rabin算法. 米勒拉宾算法是一 ...

  4. 多线程的基本概念和Delphi线程对象Tthread介绍

    多线程的基本概念和Delphi线程对象Tthread介绍 作者:xiaoru    WIN 98/NT/2000/XP是个多任务操作系统,也就是:一个进程可以划分为多个线程,每个线程轮流占用CPU运行 ...

  5. Docker系列(五):Docker网络机制(上)

    Linux路由机制打通网络 路由机制是效率最好的 docker128上修改Docker0的网络地址,与docker130不冲突 vi /usr/lib/systemd/system/docker.se ...

  6. Java 12 正式发布,8大新特性!

    自 2 月 7 日开始,Java/JDK 12 就进入了 RC 阶段.按照发布周期,美国当地时间 3 月 19 日,也就是北京时间 20 号 Java 12 正式发布了! △ JDK 12 GA 发布 ...

  7. Java学习之创建对象内存使用机制

    Java内存空间分两种,一种是栈内存,有多个,一种是堆内存,只有一个,在堆内存中又有一块方法区. 方法区中存储的是:类的信息(类名,类的直接父类,类的访问修饰符),类变量,类方法代码,实例方法代码,常 ...

  8. Python3升级3.6强力Django+杀手级xadmin打造在线教育平台✍✍✍

    Python3升级3.6强力Django+杀手级xadmin打造在线教育平台 教程 Xadmin安装方法: settings.py 的配置: users App 下的 adminx.py 的配置:

  9. Neo4j全文检索

    全文检索基本概念 搜索 搜索这个行为是用户与搜索引擎的一次交互过程,用户需要找一些数据,他提供给搜索引擎一些约束条件.搜索引擎通过约束条件抽取一些结果给用户 搜索引擎 搜索引擎存在的目的是存储,查找和 ...

  10. bzoj1010: [HNOI2008]玩具装箱toy——斜率优化

    方程 $\Large f(i)=min(f(j)+(s(i)-s(j)-1-L)^2)$ 其中$s(i)$为i的前缀和再加上$i$ 对于某个$i$若$j$比$k$优,则 $\large f(j)+(s ...