isaster(Comet OJ - Contest #11D题+kruskal重构树+线段树+倍增)
题目链接
思路
\(kruskal\)重构树\(+\)线段树\(+\)倍增
代码
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define fi first
#define se second
#define lson (rt<<1)
#define rson (rt<<1|1)
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://Code//in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)
const double eps = 1e-8;
const int mod = 998244353;
const int maxn = 100000 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
inline int read() {
int f = 0, x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar();
while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
return x = f ? -x : x;
}
pii edge[maxn*2];
vector<int> vec[maxn];
int n, m, q, op, x, y, dfn;
int Fa[maxn], mul[maxn<<2], fa[maxn][22], w[maxn], ls[maxn], rs[maxn], dd[maxn];
int fi(int x) {
return Fa[x] == x ? x : Fa[x] = fi(Fa[x]);
}
void dfs(int u, int p) {
fa[u][0] = p, ls[u] = ++dfn, dd[dfn] = u;
for(int i = 1; i <= 20; ++i) fa[u][i] = fa[fa[u][i-1]][i-1];
for(int i = 0; i < (int)vec[u].size(); ++i) {
int v = vec[u][i];
dfs(v, u);
}
rs[u] = dfn;
}
void push_up(int rt) {
mul[rt] = 1LL * mul[lson] * mul[rson] % mod;
}
void build(int rt, int l, int r) {
if(l == r) {
mul[rt] = w[dd[l]];
return;
}
int mid = (l + r) >> 1;
build(lson, l, mid), build(rson, mid + 1, r);
push_up(rt);
}
void update(int rt, int l, int r, int pos, int val) {
if(l == r) {
mul[rt] = val % mod;
return;
}
int mid = (l + r) >> 1;
if(pos <= mid) update(lson, l, mid, pos, val);
else update(rson, mid + 1, r, pos, val);
push_up(rt);
}
int query(int rt, int l, int r, int L, int R) {
if(l == L && R == r) return mul[rt];
int mid = (l + r) >> 1;
if(R <= mid) return query(lson, l, mid, L, R);
else if(L > mid) return query(rson, mid + 1, r, L, R);
else return 1LL * query(lson, l, mid, L, mid) * query(rson, mid + 1, r, mid + 1, R) % mod;
}
void solve(int x, int y) {
if(x > y) {
printf("0\n");
return;
}
for(int i = 20; i >= 0; --i) {
if(fa[x][i] != 0 && fa[x][i] <= y) x = fa[x][i];
}
printf("%d\n", query(1, 1, n, ls[x], rs[x]));
}
int main() {
#ifndef ONLINE_JUDGE
FIN;
#endif // ONLINE_JUDGE
n = read(), m = read(), q = read();
for(int i = 1; i <= n; ++i) w[i] = read(), w[i] %= mod, Fa[i] = i;
int x, y;
for(int i = 1; i <= m; ++i) {
x = read(), y = read();
if(x < y) swap(x, y);
edge[i] = {x, y};
}
sort(edge + 1, edge + m + 1);
for(int i = 1; i <= m; ++i) {
x = edge[i].fi, y = edge[i].se;
x = fi(x), y = fi(y);
if(x == y) continue;
if(x > y) Fa[y] = x, vec[x].push_back(y);
else Fa[x] = y, vec[y].push_back(x);
}
dfs(n, 0);
build(1, 1, n);
while(q--) {
op = read(), x = read(), y = read();
if(op == 1) {
solve(x, y);
} else {
update(1, 1, n, ls[x], y);
}
}
return 0;
}
isaster(Comet OJ - Contest #11D题+kruskal重构树+线段树+倍增)的更多相关文章
- Pandaria(Kruskal重构树+线段树合并)
题意 是 有n个花园 一个花园内所有的花的颜色都是一样的 有很多种不同的颜色 花园到花园之间有路,走不同的路有不同的代价 如果选一个点作为起点 只走小于等于w的路 可以经过的这些花园里 那种 ...
- luoguP4197:Peaks(Kruskal重构树+主席树)或者(点分树+离线)
题意:有N座山,M条道路.山有山高,路有困难值(即点权和边权).现在Q次询问,每次给出(v,p),让求从v出发,只能结果边权<=p的边,问能够到达的山中,第K高的高度(从大到小排序). 思路:显 ...
- 【BZOJ-3545&3551】Peaks&加强版 Kruskal重构树 + 主席树 + DFS序 + 倍增
3545: [ONTAK2010]Peaks Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1202 Solved: 321[Submit][Sta ...
- LOJ.2865.[IOI2018]狼人(Kruskal重构树 主席树)
LOJ 洛谷 这题不就是Peaks(加强版)或者归程么..这算是\(IOI2018\)撞上\(NOI2018\)的题了? \(Kruskal\)重构树(具体是所有点按从小到大/从大到小的顺序,依次加入 ...
- BZOJ3545&3551[ONTAK2010]Peaks——kruskal重构树+主席树+dfs序+树上倍增
题目描述 在Bytemountains有N座山峰,每座山峰有他的高度h_i.有些山峰之间有双向道路相连,共M条路径,每条路径有一个困难值,这个值越大表示越难走,现在有Q组询问,每组询问询问从点v开始只 ...
- 洛谷P4197 Peaks(Kruskal重构树 主席树)
题意 题目链接 往后中文题就不翻译了qwq Sol 又是码农题..出题人这是强行把Kruskal重构树和主席树拼一块了啊.. 首先由于给出的限制条件是<=x,因此我们在最小生成树上走一定是最优的 ...
- [SCOI2013]摩托车交易 kruskal重构树(最大生成树) 倍增
---题面--- 题解: 这题想法简单,,,写起来真的是失智,找了几个小时的错误结果是inf没开到LL范围.... 首先我们需要找到任意两点之间能够携带黄金的上限值,因为是在经过的道路权值中取min, ...
- [BZOJ3551][ONTAK2010]Peaks(加强版)(Kruskal重构树,主席树)
3551: [ONTAK2010]Peaks加强版 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 2438 Solved: 763[Submit][ ...
- UOJ#407. 【IOI2018】狼人 Kruskal,kruskal重构树,主席树
原文链接https://www.cnblogs.com/zhouzhendong/p/UOJ407.html 题解 套路啊. 先按照两个节点顺序各搞一个kruskal重构树,然后问题转化成两棵krus ...
随机推荐
- 洛谷P2996 [USACO10NOV]拜访奶牛Visiting Cows
题目 树形dp 设f[i][j]表示走到第i号节点的最大权值 j为0/1表示这个点选或者不选 如果这个点不选 就从他的子树里的选或者不选选最大 如果这个点选 就加上他子树的不选 f[x][0] += ...
- day 22
Creativity requires the courage to let go of certainties. 创新需要勇气承担不确定性.
- Magisk —— 安卓新一代的第三方拓展,systemless模式
Magisk由宝岛台湾学生 topjohnwu 开发, XDA主贴:https://forum.xda-developers.com/apps/magisk 使用方法:第三方rec刷入zip 介绍: ...
- idea maven项目打包并部署到tomcat
打包 打开Maven管理器,邮寄package,执行Run Maven Build,执行成功后将war包生成到target目录下. 部署 1.将war包复制到tomcat安装目录下的webapps目录 ...
- Java中HashMap和TreeMap的区别
什么是Map集合在数组中我们是通过数组下标来对其内容索引的,而在Map中我们通过对象来对对象进行索引,用来索引的对象叫做key,其对应的对象叫做value.这就是我们平时说的键值对. HashMap ...
- Scala字符串插值 - StringContext
翻译自:STRING INTERPOLATION 简介 自2.10.0版本开始,Scala提供了一种新的机制来根据数据生成字符串:字符串插值.字符串插值允许使用者将变量引用直接插入处理过的字面字符中. ...
- SpringCloud项目中使用Nacos作为注册中心
SpringCloud和Nacos的介绍原理在这里就不多说了,百度一大堆,这里就只是记录一下刚开始学习时候项目的使用过程 Nacos-server 我这里是从官网下载的Nacos-server 下载地 ...
- vertica单节点故障恢复 Startup Failed, ASR Required
测试环境的vertica是单节点的,无法做到故障自动恢复,需要手工处理.案例如下: 发现5433端口连接不上,vertica挂了,手工运行admintools,重新启动vertica,仍然失败,提示: ...
- git bash 使用自带 curl 命令出现乱码解决方法
前言 使用过 git 的小伙伴应该都不会陌生,git 自带一个终端 git bash 类似于 window 自带的 dos git 官网下载:https://git-scm.com/dow ...
- Linux 安装Redis4.0.8【yum安装】
.下载yum源 yum install epel-release2.安装redisyum install redis3.启动redis # 启动redis service redis start # ...