Regionals 2013 :: North America - Southeast USA
Regionals 2013 :: North America - Southeast USA
It Takes a Village
Input
There will be several test cases in the input. Each test case will begin with a line with two integers, n (2≤n≤100,000) and k (1≤k≤109), where n is the number of points, and k is the desired maximum distance. On each of the following n lines will be three integers x, y and z (-109≤x,y,z≤109) which are the (x,y,z) coordinates of one point. Within a test case, there will be no duplicate points. Since star systems are generally sparse, it is guaranteed that no more than 100,000 pairs of points will be within k of each other. The input will end with a line with two 0s.
Output
For each test case, output a single integer indicating the number of unique pairs of points that are less than k apart from each other. Output no spaces, and do not separate answers with blank lines.
题目大意:给定一张无向图带环图,不包含自边和重边。定义,
<1>如果P、Q两点间存在两条完全不重合路径;
<2>如果P到capital的路径经过Q,则P受Q的影响;
<3>P和Z互相影响,Z和Q互相影响,则P和Q互相影响。
Capital 恒为点1.
多组输入,包括n,m,q。(n个点,m条边,q次操作)
1 < n < 1e5 , 1< m < 1e5 , 1 < q < 2e5;
q表示两种操作的数量:
<1> + K X 给K点加权X
<2> ? K 查询K点的权和影响它的点的权的总和
1 <= k <= n,1 <= x <= 1000
在政神的指导下,这题应该是双连通分量+数据结构
根据给定的条件<1>、<2>、<3>,可以知道,相互影响的点一定是在同一个双连通分量里的,这样我们可以对原图缩点,缩完点之后图转化为一棵以capital为根的树,这时候利用树状数组维护DFS序列。所以,先 tarjan 缩点,然后从capital节点做一遍DFS,记录每个节点入栈和出栈的序列。用树状数组维护节点权值,遇到 + K X,就在点的入栈序列上 +X,在出栈序列+1上 –X,查询操作返回节点入栈序列的前缀和。
由于点数是100,000,在原图是一条链的情况下,会RE爆栈,
#pragma comment(linker, "/STACK:102400000,102400000")这是一条C++的扩栈指令,师大的OJ不提供C++编译器,是无法扩栈的。需要用到传说中的汇编扩栈!
上代码:
const int main_stack = 16;
char my_stack[128 << 20];
__asm__("movl %%esp, (%%eax);\n"::"a"(my_stack):"memory");
__asm__("movl %%eax, %%esp;\n"::"a"(my_stack + sizeof(my_stack) - main_stack):"%esp");
__asm__("movl (%%eax), %%esp;\n"::"a"(my_stack):"%esp");
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<cstdlib> using namespace std;
const int nMax = 2e5+;
struct Edge{
int u,v,nxt;
}edge[nMax<<],edge_v[nMax<<];
int g[nMax],g_v[nMax],nume,Nume;
int mark[nMax<<],s[nMax<<];
int cor[nMax],low[nMax],dfn[nMax],cnt,bcc;
int in_idx[nMax],out_idx[nMax];
int n,m;
stack<int> st;
inline int Low_bit(int x)
{
return x&-x;
}
void take_plus(int pos,int x)
{
while( pos < nMax )
s[pos]+=x,pos+=Low_bit(pos);
}
int take_sum(int pos)
{
int ret = ;
while( pos )
ret+=s[pos],pos-=Low_bit(pos);
return ret;
}
inline void addedge(int u,int v,int flag)
{
if( !flag ){
edge[++nume].u = u,edge[nume].v = v,edge[nume].nxt = g[u],g[u] = nume;
edge[++nume].u = v,edge[nume].v = u,edge[nume].nxt = g[v],g[v] = nume;
}
else{
edge_v[++Nume].u = u,edge_v[Nume].v = v,edge_v[Nume].nxt = g_v[u],g_v[u] = Nume;
edge_v[++Nume].u = v,edge_v[Nume].v = u,edge_v[Nume].nxt = g_v[v],g_v[v] = Nume;
}
}
void init()
{
memset(s,,sizeof(s));
memset(g,,sizeof(g));
memset(mark,,sizeof(mark));
nume = ;
for(int i = ;i <= m;i++){
int x,y;
scanf("%d%d",&x,&y);
addedge(x,y,);
}
}
void tarjan_dfs(int cur)
{
low[cur] = dfn[cur] = ++cnt;
st.push(cur);
for(int i = g[cur];i;i = edge[i].nxt){
if( mark[i] || mark[i^] )
continue;
mark[i] = ;
int v = edge[i].v;
if( !dfn[v] ){
tarjan_dfs(v);
low[cur] = min(low[cur],low[v]);
}
else
low[cur] = min(low[cur],dfn[v]);
}
if( low[cur] == dfn[cur] ){
++bcc;
while( ){
int temp = st.top();
st.pop();
cor[temp] = bcc;
if( temp == cur )
break;
}
}
}
void tarjan()
{
while( !st.empty() )
st.pop();
cnt = bcc = ;
memset(low,,sizeof(low));
memset(dfn,,sizeof(dfn));
memset(cor,,sizeof(cor));
for(int i = ;i <= n;i++)
if( !dfn[i] )
tarjan_dfs(i);
}
void tree_dfs(int cur,int fa)
{
in_idx[cur] = ++cnt;
mark[cur] = ;
for(int i = g_v[cur];i;i = edge_v[i].nxt){
int v = edge_v[i].v;
if( v != fa && !mark[v] )
tree_dfs(v,cur);
}
out_idx[cur] = ++cnt;
}
void build_tree()
{
memset(g_v,,sizeof(g_v));
Nume = ;
for(int i = ;i <= nume;i++){
int a = edge[i].u,b = edge[i].v;
if( cor[a] != cor[b] )
addedge(cor[a],cor[b],);
}
memset(mark,,sizeof(mark));
cnt = ;
tree_dfs(cor[],);
}
const int main_stack = ;
char my_stack[ << ];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
__asm__("movl %%esp, (%%eax);\n"::"a"(my_stack):"memory");
__asm__("movl %%eax, %%esp;\n"::"a"(my_stack + sizeof(my_stack) - main_stack):"%esp");
int q;
char type[];
int a,b;
while( scanf("%d%d%d",&n,&m,&q),n||m||q ){
init();
tarjan();
build_tree();
for(int i = ;i <= q;i++){
scanf("%s",type);
if( type[] == '+' ){
scanf("%d%d",&a,&b);
take_plus(in_idx[cor[a]],b);
take_plus(out_idx[cor[a]]+,-b);
}
else{
scanf("%d",&a);
int ans = take_sum(in_idx[cor[a]]);
printf("%d\n",ans);
}
}
}
__asm__("movl (%%eax), %%esp;\n"::"a"(my_stack):"%esp");
return ;
}
Regionals 2013 :: North America - Southeast USA的更多相关文章
- 2015 UESTC Winter Training #6【Regionals 2010 >> North America - Rocky Mountain】
2015 UESTC Winter Training #6 Regionals 2010 >> North America - Rocky Mountain A - Parenthesis ...
- [New Portal]Windows Azure Cloud Service (34) TechEd 2013 North America关于Azure的最新消息
<Windows Azure Platform 系列文章目录> 话说TechEd 2013 US上个月3-6日在美国举办了,笔者的文章又有点姗姗来迟了. 需要了解相关视频的网友,请浏览ht ...
- 组队练习赛(Regionals 2012, North America - East Central NA)
A.Babs' Box Boutique 给定n个盒子,每个盒子都有长宽高(任意两个盒子长宽高不完全相同),现在选盒子的任意两面,要求x1 <= x2 && y1 <= y ...
- Regionals 2012, North America - Greater NY 解题报告
这套题..除了几何的都出了 完全没时间学几何.杯具 A,B,J 水题不解释 C.Pen Counts 这题的话 写几个不等式限制边得范围就行了 然后枚举最小边 D.Maximum Random Wal ...
- 130825组队赛-Regionals 2012, North America - East Central NA
A.Babs' Box Boutique 一道简单的dfs搜索题,需要两两比较,然后搜到底,得到最大值就行了.比赛时队友写的,我只负责debug..赛后自己写的.. #include<iostr ...
- MPI Maelstrom(East Central North America 1996)(poj1502)
MPI Maelstrom 总时间限制: 1000ms 内存限制: 65536kB 描述 BIT has recently taken delivery of their new supercom ...
- HNU 13064 Cuckoo for Hashing解题报告 North America - East Central 2013
题目大意:使用两个哈希表来解决哈希冲突的问题.假如现在有两个哈希表分别为:H1,H2 ,大小分别为:n1,n2:现有一数据X需要插入,其插入方法为: 1.计算index1 = X MOD N1, 若 ...
- North America Qualifier (2015)
https://icpc.baylor.edu/regionals/finder/north-america-qualifier-2015 一个人打.... B 概率问题公式见代码 #include ...
- poj 2732 Countdown(East Central North America 2005)
题意:建一个家庭树,找出有第d代子孙的名字,按照要求的第d代子孙的数从大到小输出三个人名,如果有一样大小子孙数的,就按字母序从小到大将同等大小的都输出,如果小于三个人的就全输出. 题目链接:http: ...
随机推荐
- cocos2d-x android 字体的设置
我们知道 ios 自带的字体 和 android 自带的字体不同 为了使我们开发的游戏中的字体统一 我们就需要自己的字体(包括从mac 拷贝出来的 字体) 从 mac 中 copy 出 Thonbur ...
- 剑指 offer set 9 包含min函数的栈
总结 1. 要求栈的 push, pop, min 都是 o(1). 普通栈支持 Push Pop 操作, 且时间复杂度已为 o(1), 再加上 Min 函数, 时间复杂度已无法优化, 只能通过加空间 ...
- mfc extention dll 與 normal dll 的區別
extention dll 1.指從MFC中繼承過來的DLL,一般要求使用共享MFC DLL進行連接,也要求調用者也使用MFC且使用共享MFC,如此可保證DLL與調用者有相同的MFC庫. 2.在使用資 ...
- SQL server connection KeepAlive[转]
1.什么是SQL server TCP连接的keep Alive? 简单说,keep alive 是SQL server在建立每一个TCP 连接的时候,指定了TCP 协议的keepaliveinter ...
- CF 335A(Banana-贪心-priority_queue是大根堆)
A. Banana time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- 代码片段------find批量处理
应用案例: 当前目录下有若干目录,有多个目录下有一个名叫build.sh的脚本,但是没有可执行权限,现在要将所有的build.sh假如可执行权限. pengdl@debian:~/work/SDK_3 ...
- Booting ARM Linux
来源:linux-2.6.30.4/Documentation/arm/Booting ARM Linux Booting ARM Linux ================= ...
- IIS 之 HTTP 错误 500.19(无法访问请求页面,因为该页的相关配置数据无效)
HTTP 错误 500.19- Internal Server Error 错误解决方法,碰到这个问题的原因有很多,大家可以参考下,看属于哪种情况. 刚在本机部署了一个WebService测试,浏览的 ...
- 【源码】初探C#爬虫,持续更新中。。。
最近看到园子里有人用python做的爬虫软件并且上传的源码,苦于不懂python,便想着用C#也实现一个简易的爬虫软件.于是昨晚花了一个多小时的时间实现了一个简单的爬虫软件,功能十分简单,但是觉 ...
- [super dealloc]内存释放的先后顺序
心得:从前做内存释放,只是觉得应该,没体会到这个的重要性,如果不及时释放就会有很多内存泄露,就像我早期遇到的前赴后继的崩溃,比如:没使用完,就释放会崩溃等明显的release问题. 作为全局的 ...