大意: 给定无向图, 点$i$点权$b_i$, 边$(x,y,z)$对序列贡献是把$A[b_x \oplus b_y]$加上$z$.

多组询问, 一共三种操作: 1. 修改点权. 2.修改边权. 3. 求序列$A$区间和.

图按度数分块.

对于轻点的贡献直接树状数组维护, 复杂度$O(17\sqrt{m})$

每一条重边选度数较大的重点$x$建一棵$01trie$, 询问$[L,R]$区间和就等价于求异或$b[x]$后范围在$[L,R]$的和, 复杂度$O(17\sqrt{m})$.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 998244353;
const int N = 131080;
const int S = 4000;
int n, m, q, x[N], y[N], z[N];
int b[N], deg[N], ID[N], E[N];
vector<int> big, small[N];
struct {
ll c[N];
void add(int x, int v) {
for (++x; x<N; x+=x&-x) c[x]+=v;
}
ll qry(int x) {
ll ret = 0;
for (++x; x; x^=x&-x) ret+=c[x];
return ret;
}
} BIT;
struct {
int T, tot;
struct {int ch[2],v;} a[N<<2];
void add(int &o, int d, int x, int v) {
if (!o) o = ++tot;
a[o].v = (a[o].v+v)%P;
if (d>=0) add(a[o].ch[x>>d&1],d-1,x,v);
}
void add(int x, int v) {
add(T,16,x,v);
}
ll qry(int o, int d, int x, int v) {
if (d<0) return a[o].v;
int f1 = x>>d&1, f2 = v>>d&1;
if (f2) return a[a[o].ch[f1]].v+qry(a[o].ch[!f1],d-1,x,v);
return qry(a[o].ch[f1],d-1,x,v);
}
ll qry(int x, int v) {
ll ret = qry(T,16,x,v);
return ret;
}
} tr[100];
void add(int id, int tp) {
if (E[id]) tr[E[id]].add(b[x[id]]^b[y[id]]^b[big[E[id]]],tp*z[id]);
else BIT.add(b[x[id]]^b[y[id]],tp*z[id]);
}
int qry(int x) {
if (x<0) return 0;
ll ans = BIT.qry(x);
for (int i=1; i<big.size(); ++i) {
ans += tr[i].qry(b[big[i]],x);
}
return ans%P;
} int main() {
scanf("%d%d%d", &n, &m, &q);
REP(i,1,n) scanf("%d", b+i);
REP(i,1,m) {
scanf("%d%d%d", x+i, y+i, z+i);
++deg[x[i]],++deg[y[i]];
}
big.pb(0);
REP(i,1,n) if (deg[i]>=S) {
ID[i] = ++*ID;
big.pb(i);
}
REP(i,1,m) {
if (ID[x[i]]&&deg[x[i]]>deg[y[i]]) {
E[i] = ID[x[i]];
small[y[i]].pb(i);
}
else if (ID[y[i]]) {
E[i] = ID[y[i]];
small[x[i]].pb(i);
}
else {
small[x[i]].pb(i);
small[y[i]].pb(i);
}
add(i, 1);
}
while (q--) {
int op,x,y;
scanf("%d%d%d", &op, &x, &y);
if (op==1) {
for (auto t:small[x]) add(t,-1);
b[x] = y;
for (auto t:small[x]) add(t,1);
}
else if (op==2) {
add(x,-1);
z[x] = y;
add(x,1);
}
else {
int ans = (qry(y)-qry(x-1))%P;
if (ans<0) ans += P;
printf("%d\n", ans);
}
}
}

Comet OJ - Contest #5 迫真图论 (图分块)的更多相关文章

  1. Comet OJ - Contest #2 简要题解

    Comet OJ - Contest #2 简要题解 cometoj A 模拟,复杂度是对数级的. code B 易知\(p\in[l,r]\),且最终的利润关于\(p\)的表达式为\(\frac{( ...

  2. Comet OJ - Contest #11 题解&赛后总结

    Solution of Comet OJ - Contest #11 A.eon -Problem designed by Starria- 在模 10 意义下,答案变为最大数的最低位(即原数数位的最 ...

  3. Comet OJ - Contest #5 简要题解

    好久没更博了,还是象征性地更一次. 依然延续了简要题解的风格. 题目链接 https://cometoj.com/contest/46 题解 A. 迫真字符串 记 \(s_i\) 表示数字 \(i\) ...

  4. Comet OJ - Contest #5

    Comet OJ - Contest #5 总有一天,我会拿掉给\(dyj\)的小裙子的. A 显然 \(ans = min(cnt_1/3,cnt_4/2,cnt5)\) B 我们可以感性理解一下, ...

  5. Comet OJ - Contest #2简要题解

    Comet OJ - Contest #2简要题解 前言: 我没有小裙子,我太菜了. A 因自过去而至的残响起舞 https://www.cometoj.com/contest/37/problem/ ...

  6. Comet OJ - Contest #4--前缀和

    原题:Comet OJ - Contest #4-B https://www.cometoj.com/contest/39/problem/B?problem_id=1577传送门 一开始就想着暴力打 ...

  7. Comet OJ - Contest #8

    Comet OJ - Contest #8 传送门 A.杀手皇后 签到. Code #include <bits/stdc++.h> using namespace std; typede ...

  8. Comet OJ - Contest #13-C2

    Comet OJ - Contest #13-C2 C2-佛御石之钵 -不碎的意志-」(困难版) 又是一道并查集.最近做过的并查集的题貌似蛮多的. 思路 首先考虑,每次处理矩形只考虑从0变成1的点.这 ...

  9. Comet OJ - Contest #13 「火鼠的皮衣 -不焦躁的内心-」

    来源:Comet OJ - Contest #13 芝士相关: 复平面在信息学奥赛中的应用[雾 其实是道 sb 题??? 发现原式貌似十分可二项式定理,然后发现确实如此 我们把 \(a^i\) 替换成 ...

随机推荐

  1. 标准6轴机器人正反解(1)-坐标系和MDH参数表

    刚来新公司不久,部门给安排了新人作业,我被分到的任务是求标准6轴机器人的正反解,以及利用就近原则选择最优解.从今天开始,逐步将这部分内容总结出来: 本文以及后续文章均使用改进DH法: 连杆坐标系: 坐 ...

  2. 研途APP——项目需求分析

    研途APP--项目需求分析 1.作业描述 项目 内容 课程 软件工程实践 作业链接 团队作业第二次-需求规格说明书 团队名称 8rookies 作业目标 作业正文 研途APP--项目需求分析 其他参考 ...

  3. OpenJudge计算概论-找和为K的两个元素

    /*============================================================== 找和为K的两个元素 总时间限制: 1000ms 内存限制: 65536 ...

  4. http://www.cnblogs.com/sealedbook/p/6194047.html

    http://www.cnblogs.com/sealedbook/p/6194047.html

  5. pgpool 的配置文件详解

    listen_addresses = 'localhost' # Host name or IP address to listen on: # '*' for all, '' for no TCP/ ...

  6. C#-片段:外侧代码

    ylbtech-C#-片段:外侧代码 1.返回顶部 ·#if #if true #endif ·#region #region MyRegion #endregion ·namespace names ...

  7. mybatis bind exception

    springboot  项目  搜了半天 网上的解决方法千篇一律,最终问题 原因 ,yml 文件路径问题 mybatis: mapper-locations: classpath:com/yang/f ...

  8. iOS 判断scrollView是否滑动到底部

      判断scrollView有没有滚动到视图的底部,用来判断下拉刷新的时间.等 - (void)scrollViewDidScroll:(UIScrollView *)scrollView1 { CG ...

  9. avro-1.8.1 serialize BigDecimal and Short error fix.

    1. create mysql table like CREATE TABLE `test` ( `a` ) ', `b` ,) DEFAULT NULL, `c` ,) DEFAULT NULL ) ...

  10. MySQL安装时出现Apply Security Settings错误的解决办法(转)

    最近在学习MySQL时,下载了MySQL5.5版本的安装包,在配置向导的最后的页面却出现了Apply Security Settings的错误.第一次安装时比较顺利,中途卸载了一下,结果第二次安装的时 ...