Comet OJ - Contest #5 迫真图论 (图分块)
大意: 给定无向图, 点$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]]&°[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 迫真图论 (图分块)的更多相关文章
- Comet OJ - Contest #2 简要题解
Comet OJ - Contest #2 简要题解 cometoj A 模拟,复杂度是对数级的. code B 易知\(p\in[l,r]\),且最终的利润关于\(p\)的表达式为\(\frac{( ...
- Comet OJ - Contest #11 题解&赛后总结
Solution of Comet OJ - Contest #11 A.eon -Problem designed by Starria- 在模 10 意义下,答案变为最大数的最低位(即原数数位的最 ...
- Comet OJ - Contest #5 简要题解
好久没更博了,还是象征性地更一次. 依然延续了简要题解的风格. 题目链接 https://cometoj.com/contest/46 题解 A. 迫真字符串 记 \(s_i\) 表示数字 \(i\) ...
- Comet OJ - Contest #5
Comet OJ - Contest #5 总有一天,我会拿掉给\(dyj\)的小裙子的. A 显然 \(ans = min(cnt_1/3,cnt_4/2,cnt5)\) B 我们可以感性理解一下, ...
- Comet OJ - Contest #2简要题解
Comet OJ - Contest #2简要题解 前言: 我没有小裙子,我太菜了. A 因自过去而至的残响起舞 https://www.cometoj.com/contest/37/problem/ ...
- Comet OJ - Contest #4--前缀和
原题:Comet OJ - Contest #4-B https://www.cometoj.com/contest/39/problem/B?problem_id=1577传送门 一开始就想着暴力打 ...
- Comet OJ - Contest #8
Comet OJ - Contest #8 传送门 A.杀手皇后 签到. Code #include <bits/stdc++.h> using namespace std; typede ...
- Comet OJ - Contest #13-C2
Comet OJ - Contest #13-C2 C2-佛御石之钵 -不碎的意志-」(困难版) 又是一道并查集.最近做过的并查集的题貌似蛮多的. 思路 首先考虑,每次处理矩形只考虑从0变成1的点.这 ...
- Comet OJ - Contest #13 「火鼠的皮衣 -不焦躁的内心-」
来源:Comet OJ - Contest #13 芝士相关: 复平面在信息学奥赛中的应用[雾 其实是道 sb 题??? 发现原式貌似十分可二项式定理,然后发现确实如此 我们把 \(a^i\) 替换成 ...
随机推荐
- Qt 的插件制作
首先会遇到一些插件使用的问题: 插件加载的时候出现乱码 qrc:/main.qml:20: Error: Qt.createQmlObject(): failed to create object: ...
- SpringCloud介绍及入门(二)
接口的实现 在user_service_interface中添加一个User的类. 增加私有属性 id,name , 并利用快捷键Alt+Insert 实现get,set的快速生成. 实体类User ...
- Python实现协程
什么是进程和线程 有一定基础的小伙伴们肯定都知道进程和线程. 进程是什么呢? 直白地讲,进程就是应用程序的启动实例.比如我们运行一个游戏,打开一个软件,就是开启了一个进程. 进程拥有代码和打开的文件资 ...
- 淘宝npm镜像安装失败的问题
一:背景 心血来潮要简单搞一搞前端运行.打包的东西.结果第一步通过npm安装淘宝npm的时候就出问题了,如图: 二:解决方法 图片显示有点垃圾,但是看出来“Missing write access t ...
- webSphere 部署项目时,访问报错:Error 500: javax.servlet.ServletException: SRVE0207E: Uncaught initialization exception created by servlet【我】
前提: 一个普通maven项目,在本地用Tomcat运行没有任何问题,但是放到 webSphere 测试环境上,访问时就报如下错误: Error 500: javax.servlet.Servlet ...
- Swift学习 (四)
5.枚举与结构体: 不必给枚举成员提供一个值.如果我们想要为枚举成员提供一个值(raw value),我们可以用字符串,字符,整型或浮点数类型. 1 2 3 4 5 6 7 enum CompassP ...
- Laravel用户认证系统的实现细节
原文地址:http://www.php.cn/php-weizijiaocheng-406076.html 这篇文章主要介绍了关于Laravel用户认证系统的实现细节,有着一定的参考价值,现在分享给大 ...
- [转]NopCommerce中的多商店支持:权威指南
[转]NopCommerce中的多商店支持:权威指南 多商店支持是最强大的nopCommerce功能之一.但究竟什么是多店支持?它是谁的?如何在nopCommerce中设置多个商店?在今天的帖子中,我 ...
- CF1210A Anadi and Domino
思路: 很有意思的思维题. 实现: #include <bits/stdc++.h> using namespace std; int check(vector<int>&am ...
- 性能优化-Bitmap内存管理及优化
Bitmap作为重要Android应用之一,在很多时候如果应用不当,很容易造成内存溢出,那么这篇文章的目的就在于探讨Bitmap的有效运用及其优化 缓存介绍 当多次发送请求的时候,请求同一内容,为了使 ...