Educational Codeforces Round 62 (Rated for Div. 2) F. Extending Set of Points(可撤销并查集+线段树分治)

CodeForces_1348EF – Phoenix and Memory 贪心+线段树找区间最小值 这题如果没有输出2个解就很简单。 是个之前做过的类型: 把所有限制按R排序, 然后每次取出R最小的,然后从其L开始选,尽量选能选的中最小的。 这样选如果能选完,就说明有解。 贪心正确性显然:R大的至少可以选则R做为点来用。所以按R升序遍历,每次优先选左边的,能让后边的可选的更多。 用set维护可选的数即可。 这题加了个输出2个方案。 我们考虑最简单的情况:即确定一个序列后,是否有2个位置,posi,posj,使得i,j可以交换。 显然必须满足    Lj<=posi<posj<Ri 我们枚举i,只需要找到任意一个j满足上式,就可以交换i,j然后输出。 我们可以先把所有的Lj存到以 posj为区 立即下载

题目

给定二维平面的集合S,扩展集合E(S)首先被定义为S,然后开始往里面加点

任取S内集合的三个点,如果它们能构成矩形的三个顶点,则把矩形的第四个顶点也加到E(S)里

最终的E(S),是不能再往里面加新的不存在的点的最大点集

现在给定初始为空的集合S,以下q(q<=3e5)个操作,

第i次给出一个点Pi(xi,yi),

①如果Pi已经在S中,就将Pi从S中删去

②否则将Pi加入到集合S中

每次操作后,询问当前E(S)集合的大小

思路来源

https://codeforces.com/blog/entry/66147(官方tutorial)

https://www.cnblogs.com/CJLHY/p/10606629.html

https://blog.csdn.net/ccsu_cat/article/details/88834535

https://www.cnblogs.com/uuzlove/p/10585235.html

题解

官方题解的大意,

把x轴抽象成点,把y轴也抽象成点,把形如(x,y)的点抽象成边,去连接坐标轴被抽象成的点。

每个点对应一个集合,集合内cntx[]记录这个集合内有多少条x轴线,cnty[]记录有多少条y轴线,

想象网格纸,若干条交叉线,如果一个集合内有这些x轴的线和y轴的线,

那么一定可以补全交叉线上的所有点,因为这每一条线的出现都是因为这条线上的一个点的存在,

而这些线被合并到一个集合里去,是因为一个点可以将两条线合并到一起

 

由于除插入外还有删除操作,所以考虑可撤销并查集,离线地考虑询问的事件。

将插入和删除点,转化为这个点在[L,R]事件内是存在的,按事件的时间戳建一个线段树,

如果这个点没有删除,可以认为保留到了事件尾,处理成[L,q]即可

线段树内节点(p,l,r)的vector维护的是在[l,r]事件内都存在的点,

所以可以类似区间染色问题,把每个点所代表的[l,r]事件分解成O(logq)段,添加进线段树上对应节点的vector

维护一个并查集和当前值的答案now,根据dfs序对线段树进行遍历,

当进入一个线段树上的节点时,先将这个节点存的点在并查集上进行修改,

如果已经dfs到叶了,说明当前now值就是对应事件的答案,

离开一个节点的时候,应该撤销对并查集的修改,

可撤销并查集类似于数据库刚讲的rollback回滚问题,即要回滚哪些值,即提前在日志里备用上这些值,

那么我们维护一个栈,来逆序恢复,

由于栈内存的是两棵树的树根,所以撤销的时候直接让树根恢复为树根,不用存别的sz[]、cnt[]、par[]值了

特别地,这里的并查集不能使用路径压缩,因为涉及撤销操作,sz[]用于按秩(实际是大小)合并保证复杂度

四点半睡不着起来补题可还行

代码

#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define lson p<<1,l,mid
#define rson p<<1|1,mid+1,r
using namespace std;
typedef long long ll;
const int maxn=3e5;
const int N=maxn+10;
typedef pair<int,int> P;
map<P,int> last;//last[P]代表这个点上一次存在的位置
vector<P>dat[4*N];//储存点坐标的线段树向量 
//把点i处理成在[li,ri]询问内,点i存在
//从而处理成线段树染色问题 如果完整区间包含就不递归子树 称线段树分治
//dfs序访问线段树的树 进入时修改 离开时撤销 用可撤销并查集维护 
int n,par[2*N],cntx[2*N],cnty[2*N],sz[2*N];
P a;
ll now,ans[N];
int find(int x)
{
	return par[x]==x?x:find(par[x]);//不带路径压缩,因为要撤销 
}
void merge(int x,int y,stack<P> &q)
{
	x=find(x),y=find(y);
	if(x==y)return;
	//按秩合并 按disjoint集合大小合并 小的向大的合 这里不维护高度 
	if(sz[x]<sz[y])swap(x,y);
	now-=1ll*cntx[x]*cnty[x];//在用到int*int时,转1ll 
	now-=1ll*cntx[y]*cnty[y];
	q.push(P(x,y));//用栈保留更改 由于记录的是两棵树的树根 逆序撤销时只需令par[y]=y即可 
	sz[x]+=sz[y]; 
	cntx[x]+=cntx[y];
	cnty[x]+=cnty[y];
	par[y]=x;
	now+=1ll*cntx[x]*cnty[x];
}
void undo(stack<P> &q)//撤销线段树上这个结点的操作 
{
	while(!q.empty())
	{
		int x=q.top().fi;
		int y=q.top().se;
		q.pop();
		now-=1ll*cntx[x]*cnty[x];
		sz[x]-=sz[y];
		cntx[x]-=cntx[y];
		cnty[x]-=cnty[y];
		par[y]=y;//将y还原为没合并之前的树根y
		now+=1ll*cntx[x]*cnty[x];
		now+=1ll*cntx[y]*cnty[y]; 
	} 
} 
void update(int p,int l,int r,int ql,int qr,P v)
{
	if(ql<=l&&r<=qr)
	{
		dat[p].pb(v);
		return;
	}
	int mid=(l+r)/2;
	if(ql<=mid)update(lson,ql,qr,v);
	if(qr>mid)update(rson,ql,qr,v);
}
void dfs(int p,int l,int r)
{
	stack<P>q;
	for(auto v:dat[p])//处理当前节点所包含区间的事件 
	merge(v.fi,v.se,q); 
	if(l==r)ans[l]=now;
	else
	{
		int mid=(l+r)/2;
		dfs(lson);
		dfs(rson);
	}
	undo(q);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d%d",&a.fi,&a.se);
		a.se+=maxn;
		if(last.count(a))
		{
			update(1,1,n,last[a],i-1,a);//a实际存在的事件时刻是[last[a],i-1]
			last.erase(a); 
		}
		else last[a]=i;
	}
	for(auto v:last)//没有被删掉的 认为存在到事件尾 
	update(1,1,n,v.se,n,v.fi);//第一维点对 第二维位置 
	for(int i=1;i<=maxn;++i)
	par[i]=i,sz[i]=1,cntx[i]=1;
	for(int i=maxn+1;i<=2*maxn;++i)
	par[i]=i,sz[i]=1,cnty[i]=1;
	dfs(1,1,n);//按dfs序,即前序,遍历线段树
	for(int i=1;i<=n;++i)
	printf("%I64d%c",ans[i],i==n?'\n':' ');
	return 0;
}

 

相关推荐

项目计划书、规划文档模板

项目计划书、规划文档模板 最近通过项目实践经历,整理出的一套项目计划书(仅供自己参考梳理思路使用) 有喜欢的文末加VX 辛苦码字如有转载请标明出处谢谢!——木研 更新的简版项目规划文档! 原版文件请+vx :baierfa ...

weixin_43194923的博客 994

Codeforces1042D——线段树|树状数组|分治+尺取

题目链接:https://vjudge.net/contest/357503#problem/D 题目大意: 给你一个由n个整数组成的数组a,请你计算二元组(l,r)的个数,其中(l,r)满足条件 Input 第一行两个整数n和t (1 ≤ n≤ 200,000 ,|t|≤ 2e14 ) 第二行为一个序列:a1,a2...an,注意可能有负数和零 Output 二...

mumei的博客 596

洛奇 服务器文件,MabinogiG20S2 [洛奇G20服务端]

Code:Titles:>set_title /id: /add /remove Parameters for titles>set_title /id:60001 /add add devcat title>set_title /id:60001 /remove remove devcat title===========================...

weixin_30813385的博客 4325

CodeForces - 1217F Forced Online Queries Problem(线段树分治+并查集撤销)

题目链接:点击查看 题目大意:给出 nnn 个点,初始时互相不存在连边,需要执行 mmm 次操作,每次操作分为两种类型: 1 x y1 \ x \ y1 x y:如果 (x,y)(x,y)(x,y) 之间没有连边,则增加连边;如果 (x,y)(x,y)(x,y) 之间存在连边,则删除连边 2 x y2 \ x \ y2 x y:询问点 xxx 和点 yyy 之间是否联通 询问需要强制在线 题目分析:关于强制在线实现连边与加边

Falcon的博客 592

tecplot 通过数据点、坐标点绘制云图、三维云图

使用坐标点绘制二维云图或三维云图

medicalmask的博客 3万+

告别软件轮询!用STM32G474的COMP比较器实现纳秒级硬件过压保护(CubeMX配置详解)

本文详细介绍了如何利用STM32G474的COMP比较器实现纳秒级硬件过压保护,通过CubeMX配置详解,展示了硬件比较器相比传统软件轮询方案在响应时间、CPU占用和可靠性等方面的显著优势。文章还提供了实战配置流程和优化技巧,帮助工程师快速构建高效的硬件保护系统。

weixin_28683689的博客 353

Codeforces 1444C 可撤销并查集

题意 传送门 Codeforces 1444C Team-Building 题解 图中节点划分为不相交的点集 SSS,求满足所构成子图为二分图的点集对 (S1,S2)(S_1,S_2)(S1​,S2​) 数量。 若点集 SSS 构成的子图存在奇环,则它与任意其他点集构成的子图都不可能是二分图。讨论满足二分图判定的点集即可。 若两点间存在一条边,则两点划分至不同的集合,可以通过并查集维护这样的关系。依次考虑点集 SSS,处理与它存在连边的点集 TTT,判断 S,TS,TS,T 构成的子图是否为二分图即可。可以

neweryyy的博客 776

从Axure转Figma?这篇编组、缩放、圆角、评论的对比指南帮你无缝切换

本文为资深Axure设计师提供了向Figma无缝迁移的实战指南。文章深度对比了编组、缩放、圆角、评论等核心操作,重点解析了Figma独特的自动布局、组件系统和实时协作功能,旨在帮助用户快速适应新工具,实现设计思维与工作效率的跃迁。

tomato的博客 857

可撤销并查集+MST思想-Codeforces891C

可撤销并查集,采用启发式按秩合并 struct Undo_Dsu { stack <pii> st ; int fa[N] , siz[N] ; void init() { while(!st.empty()) st.pop() ; for (int i = 1 ; i <= n ; i ++) fa[i] = i , siz[i] = 1 ; } int findroot(int x) { .

Zenith_Habitant的博客 3736

HCIE-Datacom笔试题库

关于HCIE Datacom笔试考试题目整理!

坏坏-5的博客 620

SAP_PP模块中MRP中信号灯简介

一、信号灯的作用二、常见的信号灯颜色及含义三、信号灯的来源四、常见场景示例示例1:物料满足所有需求示例2:生产订单已延迟示例3:缺料或未产生计划订单五、相关事务码参考六、如何应对红色或黄色信号灯?七、前台操作说明在 SAP PP 模块中,**MRP(物料需求计划)运行结果中的“信号灯”是一种非常直观的可视化提示工具,用于帮助用户快速识别物料计划是否存在异常或需要关注的问题。这些信号灯通常出现在MD04(库存/需求清单)、MD05(单物料MRP清单)、MD07(MRP列表)**等事务代码的界面中。

我小时候很黑的博客 663

codeforces 1217 F(时间线段树+可撤销并查集)

题目链接:https://codeforc.es/contest/1217/problem/F 思路:没有那个在线的话,就完全是一道裸题,而那个在线可以发现总共只有两种可能,那么完全可以当做离线的来做,加些判断就行了 #pragma GCC optimize(3) #include <unordered_map> #include <cstdio> #include ...

llmxby 410

Dify 本地部署教程

到这里,Dify 就安装完成了,更多操作设置可以参考官方文档,Dify 和 FastGPT 基本上差不多,也可以同时安装一下 FastGPT 进行体验~Docker Compose 部署 | Dify。

Muti-Agent 6698

codeforces 并查集_codeforces 892E 可撤销并查集

https://codeforces.com/problemset/problem/892/E把询问离线,分步回答.#include#define ll long long#define rep(ii,a,b) for(int ii=a;ii<=b;++ii)#define per(ii,a,b) for(int ii=b;ii>=a;--ii)#define forn(i,x,g,e...

weixin_39625098的博客 193

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

[均摊复杂度线段树]Codeforces 438D. The Child and Sequence

首先一个数模一个小于它的数,肯定会变成原来的一半那么用均摊复杂度线段树的套路,记一下区间最大值,区间取模时,如果区间最大值小于模数,那么不会改变数列,直接退出,否则暴力递归。每个点最多变化log次,复杂度应该就是 O(nlog2n)O(n\log^2n)#include <cstdio> #include <iostream> #include <algorithm>using namespace

CE玩家 468

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Codeforces 938G Shortest Path Queries 线段树分治+并查集+线性基

题意 给出一个连通带权无向图,边有边权,要求资瓷q个操作: 1 x y d在原图中加入一条x到y权值为b的边 2 x y把图中x到y的边删掉 3 x y表示询问x到y的异或最短路 保证任意操作后原图连通无重边自环且操作均合法 n,m,q&lt;=200000 分析 如果没有前两个操作的话,我们就可以把原图的dfs树建出来,那么x到y的异或最短路就是它们在dfs树上的路径再异或上...

beginend 682

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

Codeforces 1140 F Extending Set of Points —— 线段树分治+并查集

This way 题意: 每次给你一个二元组,如果这个二元组不存在,就插到集合S中,如果存在,就将其删除。 并且,你现在有一个集合R,R=S,接下来重复一个操作,如果S中有三个点(x1,y1),(x2,y1),(x1,y2)且没有(x2,y2),将(x2,y2)插到R中。 每次输入结束之后,问你R集合中有多少个点 题解: 对于每一个点,将它y所属的集合加到x所属的集合中,然后对于这个集合的答案就是...

天翼之城的博客 270

Codeforces Round #680 (Div. 2, based on Moscow Team Olympiad) E.Team-Building 可撤销并查集

题目链接 思路:转换题意就是求选两个不同的组构成的子图是一个二分图。 那么可以先把一些自身就构成奇环的点找出来,这些点别的组也不能选。 接下来我们对连接不同组的边进行分类讨论,因为显然两个组构成奇环肯定环上只有两个组中的点(自身构成奇环的已经被扣掉了)。那么对每一组都用并查集来check是否合法。由于有很多不同的组,那么就用可撤销并查集来撤销上一次的merge即可。 #pragma GCC optimize(2) #pragma GCC optimize(3) #include <bits/stdc+

pubgoso的博客 347

Maze 2D 【CodeForces - 413E】【线段树+状态转移思维】

题目链接 这道题不能直接用dp[][]等方式来寄存数据,所以得想办法去进行优化,于是乎,就是想到了线段树的优化作用,我们可以这样子去推一个状态转移,如图: 最后拍照下来的图像是反的…… QAQ…… 但就是这样的一个意思,我们可以这样去推状态方程,然后记录在线段树上面即可。 具体可以参考一下代码。 #include &lt;iostream&gt; #inclu...

既然弱小,就只顾变强就是了 464

【Codeforces576E_CF576E】Painting Edges(可撤销并查集+线段树分治)

题目 CF576E 分析: 从前天早上肝到明天早上qwq其实颓了一上午MC ,自己瞎yy然后1A,写篇博客庆祝一下。 首先做这题之前推荐一道很相似的题:【BZOJ4025】二分图(可撤销并查集+线段树分治) 大力每个颜色维护一个并查集,就很像上面那道题了。但是存在一个问题:在处理线段树区间[l,r][l,r][l,r]时,可能并不知道lll处的修改是否成功,所以不知道lll处修改的边具体是什么颜色...

Inspector_Javert 734

2020牛客暑期多校训练营(第八场)A.All-Star Game(线段树+带撤销并查集)

题目链接:https://ac.nowcoder.com/acm/contest/5673/A 直接线段树维护每一个关系的生命周期,加一个带撤销并查集,然后dfs更新答案就行了 题目倒是不难写,mark一个带撤销并查集的板子 代码: #include<bits/stdc++.h> #define xx first #define yy second #define mp make_pair #define pb push_back using namespace std; ..

bibibibi的博客 330

Codeforces 1140F 线段树 分治 并查集

题意及思路:https://blog.csdn.net/u013534123/article/details/89010251 之前cf有一个和这个相似的题,不过那个题只有合并操作,没有删除操作,直接并查集搞一搞就行了。对于这个题,因为有删除操作,我们对操作序列建一颗线段树,记录每个操作影响的区间操作就可以了。这里的并查集不能路径压缩,要按秩合并,这样复杂度是O(logn)的。 代码: ...

weixin_30663391的博客 161

2019牛客第八场多校 E_Explorer 可撤销并查集(栈)+线段树

目录 题意: 分析: @(2019牛客暑期多校训练营(第八场)E_Explorer) 题意: 链接 题目类似:CF366D,Gym101652T 本题给你\(n(100000)\)个点\(m(10000)\)条边,每无向边允许通过编号在\([Li,Ri](1\le Li\le Ri\le ...

ako2654的博客 355

Codeforces 813 F. Bipartite Checking 时间分治线段树 and 带权并查集 (可撤销)

题意:不断删边加边,问此时的图可不可以为二分图。 解:判断二分图就看有没与奇数环 (没有就可以,有就不行) 时间分治线段树--->来看当前的图有没有奇环(带权并查集) 写一下并查集那里连边: merge发生在 x,y的祖先身上,我们是在间接连边,最后查询dis一定是正确的 c[i]表示 点i到 它的root的距离。 所以x,y连边之后merge里yy成为新的root:c[xx]表...

fnq9999的博客 289

Codeforces 1217 F. Forced Online Queries Problem —— 又见 线段树分治+并查集

This way 题意: 每次给你两个操作: 1 x y 表示加/断点x和点y之间的连边 2 x y 问你x和y是否连通 题解: 在线的做法好像是什么ETT?不是很懂 这题是个假的强制在线,只需要一开始将所有情况处理出来放到线段树里面,dfs线段树的时候查看当前操作是否合法即可。 那么又是将询问当做叶子结点,操作当做区间更新,然后向下dfs的时候更新一下并查集即可。 #include<bits/stdc++.h> using namespace std; #define pa pair&lt

天翼之城的博客 269

[字符串Hash DP] Codeforces 613E #339 (Div. 1) E. Puzzle Lover

写这个东西的时候很需要冷静 一些细节 比如特殊情况不可避免的重复计算 很恶心 然后 自然溢出被sxbk的hacker卡了 我还因此去学习了怎么卡 构造串卡掉自然溢出BY PoPoQQQ#include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring> #define cl(x) memset(x,0,sizeof(x)

雯舞 994
上一篇: UVA11997 K Smallest Sums(思维题/优先队列)
下一篇: Codeforces Round #569 (Div. 2) (D/构造+E/线段树)
小衣同学
博客等级 码龄9年 1444粉丝 995原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小衣同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址