bzoj 4383: [POI2015]Pustynia
复习了一下线段树优化建图的姿势,在线段树上连边跑拓扑排序
这题竟然卡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的更多相关文章
- @bzoj - 4378@ [POI2015] Pustynia
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个长度为 n 的正整数序列 a,每个数都在 1 到 10^ ...
- [POI2015]Pustynia
[POI2015]Pustynia 题目大意: 给定一个长度为\(n(n\le10^5)\)的正整数序列\(a\),每个数都在\(1\)到\(10^9\)范围内,告诉你其中\(s\)个数,并给出\(m ...
- 【BZOJ4383】[POI2015]Pustynia 线段树优化建图
[BZOJ4383][POI2015]Pustynia Description 给定一个长度为n的正整数序列a,每个数都在1到10^9范围内,告诉你其中s个数,并给出m条信息,每条信息包含三个数l,r ...
- 洛谷P3588 - [POI2015]Pustynia
Portal Description 给定一个长度为\(n(n\leq10^5)\)的正整数序列\(\{a_n\}\),每个数都在\([1,10^9]\)范围内,告诉你其中\(s\)个数,并给出\(m ...
- bzoj 4386: [POI2015]Wycieczki
bzoj 4386: [POI2015]Wycieczki 这题什么素质,爆long long就算了,连int128都爆……最后还是用long double卡过的……而且可能是我本身自带大常数吧,T了 ...
- BZOJ 4385: [POI2015]Wilcze doły
4385: [POI2015]Wilcze doły Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 648 Solved: 263[Submit][ ...
- BZOJ 4384: [POI2015]Trzy wieże
4384: [POI2015]Trzy wieże Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 217 Solved: 61[Submit][St ...
- Bzoj 3747: [POI2015]Kinoman 线段树
3747: [POI2015]Kinoman Time Limit: 60 Sec Memory Limit: 128 MBSubmit: 553 Solved: 222[Submit][Stat ...
- BZOJ 3747 POI2015 Kinoman 段树
标题效果:有m点,每个点都有一个权值.现在我们有这个m为点的长度n该序列,寻求区间,它仅出现一次在正确的点区间内值和最大 想了很久,甚至神标题,奔说是水的问题--我醉了 枚举左点 对于每个请求留点右键 ...
随机推荐
- PAT (Advanced Level) 1112. Stucked Keyboard (20)
找出一定没问题的字符(即一连串的额字符x个数能被k整除的),剩下的字符都是可能有问题的. #include<cstdio> #include<cstring> #include ...
- Windows API 之 CreateFile、CreateFileMapping 、MapViewOfFile
CreateFile Creates or opens a file or I/O device. The most commonly used I/O devices are as follows: ...
- mac编译PHP报错 configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/
解决办法 brew install curl xcode-select --install
- JS 从一个字符串中截取两个字符串之间的字符串
/************************************************* 函数说明:从一个字符串中截取 两个字符串之间的字符串 参数说明:src_str 原串, start ...
- Spring + iBATIS完整示例
最近研究了一下Spring + iBATIS.发现看别人的例子是一回事,自己写一个完整的应用又是另外一回事.自己受够了网上贴的一知半解的代码. iBATIS是一个持久化框架,封面了sql过程,虽然sq ...
- Net 自定义Excel模板导出数据
转载自:http://www.cnblogs.com/jbps/p/3549671.html?utm_source=tuicool&utm_medium=referral 1 using Sy ...
- java日期格式大全 format SimpleDateFormat(转)
java日期格式大全 format SimpleDateFormat /** * 字符串转换为java.util.Date<br> * 支持格式为 yyyy.MM.dd G ...
- ERROR security.UserGroupInformation
[java] 15/11/14 12:58:19 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. ...
- (poj 3660) Cow Contest (floyd算法+传递闭包)
题目链接:http://poj.org/problem?id=3660 Description N ( ≤ N ≤ ) cows, conveniently numbered ..N, are par ...
- PHP实现畅言留言板和网易跟帖样式
原文:http://justcoding.iteye.com/blog/2251192 我要实现的就是下图的这种样式,可参考下面这两个网站的留言板,他们的实现原理都是一样的 http://chan ...