4月的时候在luogu上做过 白雪皑皑 这道题,当时一遍AC可高兴了qwq,后来去了个厕所,路上忽然发现自己的做法是错的qwq...然后就咕咕了qwq 今天看到了 疯狂的馒头 ,发现一毛一样OvO...还是好好做一下吧QWQ 先上个错误代码(虽然BZOJ和Luogu都A了) // luogu-judger-enable-o2 #include<cstdio> #include<iostream> #define R register int #define getchar() *S…
P1525 关押罪犯  题目 #include<iostream> #include<cstdlib> #include<cstdio> #include<cmath> #include<cstring> #include<iomanip> #include<algorithm> #include<queue> #include<ctime> #define ll long long #define…
题目链接 给定一张含$n$个点$m$条边的无向图,每个点有一个重要指数$a_i$.有两种操作:1.在$x$和$y$之间连一条边:2.求$x$所在连通块中重要程度第$k$小的点. --------------------------------- 维护第$k$小,很容易想到权值线段树.看到合并二字,可以想到用线段树合并的方法.维护连通块可以用并查集做. 注意并查集合并的方向和线段树合并的方向要一致.查询的时候要先找出并查集的根再查询. 代码: #include<bits/stdc++.h> us…
A. Bear and Big Brother time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak…
题面:P1197 [JSOI2008]星球大战 题解: 坑点有点多啊,加上我本来就有点头昏脑涨,一道水题写了一万年.. 并查集不支持拆开(但是可以撤销合并),只支持合并.所以把询问离线了,从最后状态到初状态开始一个个往当前图里加点. CZL:对于只有删除点/边而不增加点/边,且允许离线的题,可以考虑时光倒流,先建出最终情况,再倒着把点/边加回去. 代码: #include<cstdio> using namespace std; inline int rd(){ ; char c=getcha…
A. Hongcow Learns the Cyclic Shift time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Bein…
A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest comm…
java打印正金字塔,倒金字塔和"水影"金字塔 --------原创文章,若要转载,请注明出处   小小少年 闲来无事,想起自己初学java的时候做的经典的无非就是打印出一些有意思的图形,心血来潮自己就写了这么一个打印金字塔的demo,自己回顾一下当初的感受,同时也 分享给初学java的同道中人,一起来培养编程的兴趣<(^-^)>.   金字塔图案 1,问题分析 我们都知道,打印输出的时候,都是从最左端输出,而这里,第一个星号是在中间.这实际是因为星号之前有很多空格.当我们…
题目链接:https://www.luogu.org/problemnew/show/P1955 并查集操作,1e9要离散化,数组要开大一些,操作前先执行合并操作 样例好毒啊(全是排好序的) #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int maxn = 100010; int fa[maxn…
题目链接:https://www.luogu.org/problemnew/show/P2195 fir.吐槽题目(省略1w字 sec.考虑对一个森林的维护,每棵树用并查集维护. 操作1:输出当前查询点的树的直径 操作2:对于两条直径连接起来最短,肯定是连两个中点(显而易见 thi.小trick:重复利用vis数组-变成int,这样对于每棵树实际每个根不一样标号时的vis值也不同 #include <queue> #include <cstdio> #include <cst…