线段树分治+线形基。

线段树分治是个锤子??

以时间轴构建线段树,把每个环以“对线段树产生影响的时间区间”的形式加入线段树即可。

#include<bits/stdc++.h>
#define ll bitset<1005>
using namespace std;
const int N=1005;
struct base{
ll p[N];
void insert(ll x){
for (int i=N-1;i>=0;i--)
if (x[i])
if (p[i].any()) x^=p[i];
else {p[i]=x;return;}
}
} tmp;
struct edge{
int u,v,l,r;ll dist;
} loop[N<<1];
int head[N],vet[N],nxt[N],fa[N],pos[N];
int n,m,q,x,y,tot,cnt,len,now;
ll dist[N],d[N],z,res;
char ch[N],opt[20];
vector <int> E[N<<2];
int getint(){
int x=0,w=1;
char ch=getchar();
while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
if (ch=='-') w=0,ch=getchar();
while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return w?x:-x;
}
ll getll(){
scanf("%s",ch);int len=strlen(ch);ll x;
for (int i=0;i<len;++i) x[len-i-1]=ch[i]-'0';return x;
}
void add(int x,int y,ll z){
nxt[++tot]=head[x];
vet[tot]=y;
head[x]=tot;
dist[tot]=z;
}
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
void dfs(int u,int father){
for (int i=head[u];i;i=nxt[i]){
int v=vet[i];
if (v!=father) d[v]=d[u]^dist[i],dfs(v,u);
}
}
void modify(int u,int l,int r,int ql,int qr,int i){
if (ql<=l&&r<=qr){
E[u].push_back(i);
return;
}
int mid=l+r>>1;
if (ql<=mid) modify(u<<1,l,mid,ql,qr,i);
if (qr>mid) modify(u<<1|1,mid+1,r,ql,qr,i);
}
void query(int u,int l,int r,base b){
for (int i=0;i<E[u].size();i++){
int j=E[u][i];
b.insert(d[loop[j].u]^d[loop[j].v]^loop[j].dist);
}
if (l==r){
ll res=0;int j=N-1;
for (int i=N-1;i>=0;i--)
if (!res[i]) res^=b.p[i];
while (j>=0&&!res[j]) j--;
while (j>=0)
if (res[j]) putchar('1'),j--; else putchar('0'),j--;
puts("");
return;
}
int mid=l+r>>1;
query(u<<1,l,mid,b);
query(u<<1|1,mid+1,r,b);
}
int main(){
scanf("%d%d%d",&n,&m,&q);
for (int i=1;i<=n;i++) fa[i]=i;
for (int i=1;i<=m;i++){
x=getint(),y=getint(),z=getll();
if (find(x)^find(y)){
add(x,y,z),add(y,x,z);
fa[find(x)]=find(y);
}
else loop[++cnt]=(edge){x,y,0,q,z};
}
dfs(1,0);
for (int i=1;i<=q;i++){
scanf("%s",opt);
if (opt[0]=='A'){
x=getint(),y=getint(),z=getll();
loop[++cnt]=(edge){x,y,i,q,z};
pos[++now]=cnt;
} else
if (opt[1]=='h'){
x=getint(),z=getll();
loop[++cnt]=(edge){loop[pos[x]].u,loop[pos[x]].v,i,q,z};
loop[pos[x]].r=i-1;
pos[x]=cnt;
}
else{
x=getint();
loop[pos[x]].r=i-1;
pos[x]=-1;
}
}
for (int i=1;i<=cnt;i++)
modify(1,0,q,loop[i].l,loop[i].r,i);
query(1,0,q,tmp);
return 0;
}

[HAOI 2017]八纵八横的更多相关文章

  1. HAOI 2017 游记

    省选 2017年4月23日 流水账式游记,不喜勿喷. Day0: 准备出发,上午敲了一顿板子,板子敲完了就打小游戏,老师也不管了. 过程中各种奶,说什么今年一定考仙人掌啦,今年一定考字符串啦,今年一定 ...

  2. CI Weekly #10 | 2017 DevOps 趋势预测

    2016 年的最后几个工作日,我们对 flow.ci Android & iOS 项目做了一些优化与修复: iOS 镜像 cocoapods 版本更新: fir iOS上传插件时间问题修复: ...

  3. 猖獗的假新闻:2017年1月1日起iOS的APP必须使用HTTPS

    一.假新闻如此猖獗 刚才一位老同事 打电话问:我们公司还是用的HTTP,马上就到2017年了,提交AppStore会被拒绝,怎么办? 公司里已经有很多人问过这个问题,回答一下: HTTP还是可以正常提 ...

  4. iOS的ATS配置 - 2017年前ATS规定的适配

    苹果规定 从2017年1月1日起,新提交的 app 不允许使用NSAllowsArbitraryLoads来绕过ATS(全称:App Transport Security)的限制. 以前为了能兼容ht ...

  5. 深入研究Visual studio 2017 RC新特性

    在[Xamarin+Prism开发详解三:Visual studio 2017 RC初体验]中分享了Visual studio 2017RC的大致情况,同时也发现大家对新的Visual Studio很 ...

  6. Xamarin+Prism开发详解三:Visual studio 2017 RC初体验

    Visual studio 2017 RC出来一段时间了,最近有时间就想安装试试,随带分享一下安装使用体验. 1,卸载visual studio 2015 虽然可以同时安装visual studio ...

  7. Microsoft Visual Studio 2017 for Mac Preview 下载+安装+案例Demo

    目录: 0. 前言 1. 在线安装器 2. 安装VS 3. HelloWorld 4. ASP.NET MVC 5. 软件下载 6. 结尾 0. 前言: 工作原因,上下班背着我的雷神,一个月瘦了10斤 ...

  8. Create an offline installation of Visual Studio 2017 RC

    Create an offline installation of Visual Studio 2017 RC ‎2016‎年‎12‎月‎7‎日                             ...

  9. .NET Core 2.0版本预计于2017年春季发布

    英文原文: NET Core 2.0 Planned for Spring 2017 微软项目经理 Immo Landwerth 公布了即将推出的 .NET Core 2.0 版本的细节,该版本预计于 ...

随机推荐

  1. hdu6704 2019CCPC网络选拔赛1003 K-th occurrence 后缀自动机+线段树合并

    解题思路: fail树上用权值线段树合并求right/endpos集合,再用倍增找到待查询串对应节点,然后权值线段树求第k大. #include<bits/stdc++.h> using ...

  2. 【原创】如何优雅的转换Bean对象

    背景 我们的故事要从一个风和日丽的下午开始说起! 这天,外包韩在位置上写代码-外包韩根据如下定义 PO(persistant object):持久化对象,可以看成是与数据库中的表相映射的 java 对 ...

  3. Activiti工作流概述

    本来打算看OCR的但是我手里有的资源是讲的PY的,涉及到CNN和RNN看得有的不太明白,捂脸,所以看看工作流吧,反正也都不会,干啥啥不会 工作流的概念 工作流的概念应该都差不多了解要不也不会搜索这个标 ...

  4. MVC里面调用webservice

    调用WebService报错404问题 (转载)   我想在MVC4的项目添加一个webservice文件,访问没问题,但是最后调用方法就报404错误.但是如果我全新ASP.NET 空Web应用程序  ...

  5. C++11的decltype关键字

    C++11的decltype关键字 概述 decltype关键字和auto有异曲同工之处 有时我们希望从表达式的类型推断出要定义的变量类型,但是不想用该表达式的值初始化变量(如果要初始化就用auto了 ...

  6. 2020年1月31日 安装Python的BeautifulSoap库记录

    C:\Users\ufo>pip install beautifulsoup4 Collecting beautifulsoup4 WARNING: Retrying (Retry(total= ...

  7. Fastbin attack——Double Free

    ptmalloc ptmalloc的基本思路是将堆上的内存区域划分为多个chunk,在分配/回收内存时,对chunk进行分割.回收等操作.在32位系统下,chunk头的大小为8 Bytes,且每个ch ...

  8. java+swing+mysql图书管理系统

    系统说明:本系统采用eclipse开发,IDEA,eclipse,myeclipse均可运行 界面采用swing实现 数据库:mysql,附sql代码,其余数据库可复制sql代码运行 数据库连接文件m ...

  9. Django 仿ajax传递数据(Django十)

    之前用form表单传递数据,没有遇到任何问题 具体见:https://blog.csdn.net/qq_38175040/article/details/104867747 然后现在我想用ajax传递 ...

  10. oracle之数据限定与排序

    数据限定与排序 6.1 简单查询语句执行顺序 from, where, group by, having, order by, select where限定from后面的表或视图,限定的选项只能是表的 ...