复习了一下线段树优化建图的姿势,在线段树上连边跑拓扑排序

这题竟然卡vector……丧病

#include <bits/stdc++.h>
#define N 1810000
using namespace std;
int s, n, m;
int pi[N], vis[N];
int lt[N], nt[N], bi[N], ci[N];
int lp[N], np[N], bp[N];
int tl;
int lb[N], rb[N], lc[N], rc[N];
int out[N], intr[N];
int Q[N], fr, bc;
inline void build(int a, int b, int c)
{
nt[++ tl] = lt[a]; lt[a] = tl; bi[tl] = b; ci[tl] = c;
np[tl] = lp[b]; lp[b] = tl; bp[tl] = a; out[a] ++;
/*
bi[a].push_back(b);
bp[b].push_back(a);
ci[a].push_back(c);
*/
//printf("%d %d %d\n", a, b, c);
}
int tot;
void dfs_build(int t, int l, int r, int x)
{
if (l > r) return;
if (l <= lb[t] && rb[t] <= r) {build(x, t, ); return;}
if (l <= rb[lc[t]]) dfs_build(lc[t], l, r, x);
if (r >= lb[rc[t]]) dfs_build(rc[t], l, r, x);
}
int build_tree(int l, int r)
{
int t = ++ tot;
lb[t] = l; rb[t] = r;
if (l != r)
{
lc[t] = build_tree(l, (l + r) / );
rc[t] = build_tree((l + r) / + , r);
build(t, lc[t], );
build(t, rc[t], );
}
else intr[l] = t;
return t;
} inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} int main()
{
n = read(); s = read(); m = read();
build_tree(, n);
for (int i = ; i <= s; ++ i)
{
int p, d;
p = read(); d = read();
pi[intr[p]] = d;
} //return 0;
for (int i = ; i <= m; ++ i)
{
int l, r, k;
l = read(); r = read(); k = read(); for (int j = , p = l - ; j <= k + ; ++ j)
{
int a;
if (j <= k)
{
a = read();
build(intr[a], tot + i, );
}
else a = r + ;
if ((a - ) - (p + ) <= )
{
for (int q = p + ; q < a; ++ q)
build(tot + i, intr[q], );
}
else
dfs_build(, p + , a - , tot + i);
p = a;
}
}
for (int i = ; i <= m + tot; ++ i)
if (!out[i]) Q[bc ++] = i; while (fr != bc)
{
int hd = Q[fr ++]; vis[hd] = ;
int mx = ;
for (int i = lt[hd]; i; i = nt[i])
mx = max(mx, pi[bi[i]] + ci[i]);
if (!pi[hd])
{
if (mx > )
{
puts("NIE");
return ;
}
pi[hd] = mx;
}
else if (mx > pi[hd])
{
puts("NIE");
return ;
} for (int i = lp[hd]; i; i = np[i])
{
out[bp[i]] --;
if (!out[bp[i]])
Q[bc ++] = bp[i];
}
}
for (int i = ; i <= m + tot; ++ i)
if (!vis[i]) {puts("NIE"); return ;}
puts("TAK");
for (int i = ; i <= n; ++ i) printf("%d ", pi[intr[i]]);
}

话说是不是在主席树上也可以干一样的事情呢(手动斜眼

bzoj 4383: [POI2015]Pustynia的更多相关文章

  1. @bzoj - 4378@ [POI2015] Pustynia

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个长度为 n 的正整数序列 a,每个数都在 1 到 10^ ...

  2. [POI2015]Pustynia

    [POI2015]Pustynia 题目大意: 给定一个长度为\(n(n\le10^5)\)的正整数序列\(a\),每个数都在\(1\)到\(10^9\)范围内,告诉你其中\(s\)个数,并给出\(m ...

  3. 【BZOJ4383】[POI2015]Pustynia 线段树优化建图

    [BZOJ4383][POI2015]Pustynia Description 给定一个长度为n的正整数序列a,每个数都在1到10^9范围内,告诉你其中s个数,并给出m条信息,每条信息包含三个数l,r ...

  4. 洛谷P3588 - [POI2015]Pustynia

    Portal Description 给定一个长度为\(n(n\leq10^5)\)的正整数序列\(\{a_n\}\),每个数都在\([1,10^9]\)范围内,告诉你其中\(s\)个数,并给出\(m ...

  5. bzoj 4386: [POI2015]Wycieczki

    bzoj 4386: [POI2015]Wycieczki 这题什么素质,爆long long就算了,连int128都爆……最后还是用long double卡过的……而且可能是我本身自带大常数吧,T了 ...

  6. BZOJ 4385: [POI2015]Wilcze doły

    4385: [POI2015]Wilcze doły Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 648  Solved: 263[Submit][ ...

  7. BZOJ 4384: [POI2015]Trzy wieże

    4384: [POI2015]Trzy wieże Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 217  Solved: 61[Submit][St ...

  8. Bzoj 3747: [POI2015]Kinoman 线段树

    3747: [POI2015]Kinoman Time Limit: 60 Sec  Memory Limit: 128 MBSubmit: 553  Solved: 222[Submit][Stat ...

  9. BZOJ 3747 POI2015 Kinoman 段树

    标题效果:有m点,每个点都有一个权值.现在我们有这个m为点的长度n该序列,寻求区间,它仅出现一次在正确的点区间内值和最大 想了很久,甚至神标题,奔说是水的问题--我醉了 枚举左点 对于每个请求留点右键 ...

随机推荐

  1. android 内存优化一

    常见内存泄露原因 Context对象泄漏 1.如果一个类持有Context对象的强引用,就需要检查其生存周期是否比Context对象更长.否则就可能发生Context泄漏. 2.View持有其创建所在 ...

  2. CenOS下LAMP搭建过程

    CentOS虚拟机中安装LAMP: Linux+Apache+MySQL+PHP 安装前先关闭防火墙和Selinux 把所有安装包解压到/lamp下(根目录下的lamp目录) 安装gcc, gcc-c ...

  3. 如何play billard

    怎样打台球?(一) 首先,要打好台球,必须要做好准备:1.要有自己的专杆,每日用不同杆的人,台球水平必定一般.2.精神状态度要好,睡眠不足或心里有事儿,不要打台球.记住,台球是专注度要求极高的运动.3 ...

  4. BAT54C 二极管是如何工作的?

    这是一个多电源供电的电路:Vcc是正常供电电源(如5V,由市电变换得到),电压大于(Vcc1-Vf),正常供电时二极管不导通:Vcc1是电池供电电源,当Vcc撤掉时,DD1(上边的二极管)导通,由Vc ...

  5. C# 经典入门11章,比较

    1类型比较 所有的类懂从System.Object中继承了GetType()方法,这个方法和typeof()运算符一起使用,可以确定对象的类型.例如: if(myObj.GetType()==type ...

  6. Spring+Struts集成(方案一)

    SSH框架是现在非常流行的框架之一,本文接下来主要来对Spring和Struts的集成进行展示. 集成原理:在Action中取得BeanFactory,通过BeanFactory取得业务逻辑对象. 集 ...

  7. POJ 3984 迷宫问题 记录路径的广搜

    主要是学一下如何在广搜中记录路径:每找到一个点我就记录下这个点是由那个点得来的,这样我找到最后个点后,我就可以通过回溯得到我走过的路径,具体看代码吧~ #include<cstdio> # ...

  8. html常见标签使用

    <body> <!--标题标签--> <h1></h1> <h2></h2> <h3></h3> < ...

  9. Utils 工具 推送

    work_weipa_百度云推送 2014-09-05 17:55 7人阅读 评论(0) 收藏 举报 问题:怎么实现消息推送? 回答:下载sdk,根据文档操作即可 资料:http://develope ...

  10. ASP对数据库的操作方法

    ASP与数据库-连接.写入.修改.删除.显示代码属性与方法 PageCount 属性: 决定 Recordset 对象包括多少“页”的数据.        这里的“页”是数据记录的集合,大小等于 Pa ...