题目链接

传送门

思路

\(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重构树+线段树+倍增)的更多相关文章

  1. Pandaria(Kruskal重构树+线段树合并)

    题意 是 有n个花园 一个花园内所有的花的颜色都是一样的 有很多种不同的颜色  花园到花园之间有路,走不同的路有不同的代价   如果选一个点作为起点 只走小于等于w的路  可以经过的这些花园里  那种 ...

  2. luoguP4197:Peaks(Kruskal重构树+主席树)或者(点分树+离线)

    题意:有N座山,M条道路.山有山高,路有困难值(即点权和边权).现在Q次询问,每次给出(v,p),让求从v出发,只能结果边权<=p的边,问能够到达的山中,第K高的高度(从大到小排序). 思路:显 ...

  3. 【BZOJ-3545&3551】Peaks&加强版 Kruskal重构树 + 主席树 + DFS序 + 倍增

    3545: [ONTAK2010]Peaks Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1202  Solved: 321[Submit][Sta ...

  4. LOJ.2865.[IOI2018]狼人(Kruskal重构树 主席树)

    LOJ 洛谷 这题不就是Peaks(加强版)或者归程么..这算是\(IOI2018\)撞上\(NOI2018\)的题了? \(Kruskal\)重构树(具体是所有点按从小到大/从大到小的顺序,依次加入 ...

  5. BZOJ3545&3551[ONTAK2010]Peaks——kruskal重构树+主席树+dfs序+树上倍增

    题目描述 在Bytemountains有N座山峰,每座山峰有他的高度h_i.有些山峰之间有双向道路相连,共M条路径,每条路径有一个困难值,这个值越大表示越难走,现在有Q组询问,每组询问询问从点v开始只 ...

  6. 洛谷P4197 Peaks(Kruskal重构树 主席树)

    题意 题目链接 往后中文题就不翻译了qwq Sol 又是码农题..出题人这是强行把Kruskal重构树和主席树拼一块了啊.. 首先由于给出的限制条件是<=x,因此我们在最小生成树上走一定是最优的 ...

  7. [SCOI2013]摩托车交易 kruskal重构树(最大生成树) 倍增

    ---题面--- 题解: 这题想法简单,,,写起来真的是失智,找了几个小时的错误结果是inf没开到LL范围.... 首先我们需要找到任意两点之间能够携带黄金的上限值,因为是在经过的道路权值中取min, ...

  8. [BZOJ3551][ONTAK2010]Peaks(加强版)(Kruskal重构树,主席树)

    3551: [ONTAK2010]Peaks加强版 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 2438  Solved: 763[Submit][ ...

  9. UOJ#407. 【IOI2018】狼人 Kruskal,kruskal重构树,主席树

    原文链接https://www.cnblogs.com/zhouzhendong/p/UOJ407.html 题解 套路啊. 先按照两个节点顺序各搞一个kruskal重构树,然后问题转化成两棵krus ...

随机推荐

  1. 【2019.7.26 NOIP模拟赛 T1】数字查找(figure)(数学)

    推式子 我们设\(n=kp+w\),则: \[(kp+w)a^{kp+w}\equiv b(mod\ p)\] 将系数中的\(kp+w\)向\(p\)取模,指数中的\(kp+w\)根据欧拉定理向\(p ...

  2. 2020年数据库概念与MySQL的安装与配置-从零基础入门MySQL-mysql8版本

    作者 | Jeskson 来源 | 达达前端小酒馆 从零基础入门MySQL数据库基础课 数据的概念,简介,安装与配置,Windows平台下MySQL的安装与配置. 数据库的概念:数据库是一个用来存放数 ...

  3. Spring security 知识笔记【内存角色授权】

    一.原有的配置文件中,增加注解@EnableGlobalMethodSecurity(prePostEnabled = true) 二.原有配置文件中,内存新建账号的时候添加角色 package El ...

  4. 推荐支付宝 Android 专项测试工具SoloPi

    推荐支付宝 Android 专项测试工具SoloPi 1 介绍 SoloPi是一个无线化.非侵入式的Android自动化工具,公测版拥有录制回放.性能测试.一机多控三项主要功能,能为测试开发人员节省宝 ...

  5. SQLserver 存储过程游标使用

    ALTER PROCEDURE [dbo].[p_DeleteStretchData] ) , ) AS BEGIN ) ) declare @stretch_cursor cursor -- 声明游 ...

  6. proxy 简化版本

    public interface People { public String eat(String param); } public class Jack implements People { @ ...

  7. 如何解决macbook pro摄像头不工作的问题

    背景:上周用qq视频聊天都正常,这周突然显示检测不到摄像头.打开facetime和photo booth也显示“相机未连接”排查一切问题后只好给苹果客服打电话,在客服的帮助下解决了这个问题. 解决办法 ...

  8. SQLServer查看分区表详细信息

    SQL查看分区内记录个数,常规方法需要知道分区函数然后再显示,网上看到一个一句话显示的方法 ), ps.name ) as partition_scheme, p.partition_number, ...

  9. sql server删除重复记录只保留一条

    今天遇到一个历史导入数据重复的问题,于是要删除重复的记录,一开始想用子查询的方式找到要删除记录的id删除,后来发现DELETE语句可以直接用外连接,这样更加简单,效率也更高. delete sys_p ...

  10. Redis(九)高可用专栏之《简介篇》

    在互联网的大趋势下,用户体验.服务的可用性日趋重要.任何一个服务的不可用,都可能导致连锁式功能故障. 前言 高可用模型的已经逐渐形成一种套路: 主备/主从模式 集群模式 主备/主从模式 至少有两台服务 ...