主席树

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define rd read()
using namespace std; const int N = 1e5 + 5; int ls[N], tot, n, m, q;
int a[N], ans;
vector<int> ad[N], reduce[N]; struct que {
int l, r, x;
}b[N]; int read() {
int X = 0, p = 1; char c = getchar();
for (; c > '9' || c < '0'; c = getchar())
if (c == '-') p = -1;
for (; c >= '0' && c <= '9'; c = getchar())
X = X * 10 + c - '0';
return X * p;
} namespace SegT {
int cnt, root[N];
struct node {
int sum, lson, rson;
}p[N * 50];
#define lc(x) p[x].lson
#define rc(x) p[x].rson
#define sum(x) p[x].sum
#define mid ((l + r) >> 1) void modify(int &x, int now, int pos, int d, int l, int r) {
x = ++cnt;
sum(x) = sum(now) + d;
lc(x) = lc(now);
rc(x) = rc(now);
if (l == r) return;
if (pos <= mid) modify(lc(x), lc(now), pos, d, l, mid);
else modify(rc(x), rc(now), pos, d, mid + 1, r);
} int query(int x, int pos, int l, int r) {
if (!x) return 0;
if (r <= pos) return sum(x);
int res = 0;
if (mid <= pos)
return query(lc(x), pos, l, mid) + query(rc(x), pos, mid + 1, r);
else
return query(lc(x), pos, l, mid);
}
}using namespace SegT; int main()
{
n = rd; m = rd; q = rd;
for (int i = 1; i <= n; ++i) a[i] = rd;
for (int i = 1; i <= m; ++i)
b[i].l = rd, b[i].r = rd, b[i].x = rd, ls[++tot] = b[i].x;
sort(ls + 1, ls + 1 + tot);
tot = unique(ls + 1, ls + 1 + tot) - ls - 1;
for (int i = 1; i <= m; ++i) {
int tmp = lower_bound(ls + 1, ls + 1 + tot, b[i].x) - ls;
ad[tmp].push_back(b[i].l);
if (b[i].r < n) reduce[tmp].push_back(b[i].r + 1);
}
for (int i = 1; i <= tot; ++i) {
root[i] = root[i - 1];
for (int j = 0, up = ad[i].size(); j < up; ++j)
modify(root[i], root[i], ad[i][j], 1, 1, n);
for (int j = 0, up = reduce[i].size(); j < up; ++j)
modify(root[i], root[i], reduce[i][j], -1, 1, n);
}
for (int i = 1; i <= n; ++i) {
int tmp = upper_bound(ls + 1, ls + 1 + tot, a[i]) - 1 - ls;
ans += query(root[tmp], i, 1, n);
}
printf("%d\n", ans);
for (int i = 1; i <= q; ++i) {
int u = rd ^ ans, v = rd ^ ans;
int tmp = upper_bound(ls + 1, ls + 1 + tot, a[u]) - 1 - ls;
ans -= query(root[tmp], u, 1, n);
a[u] = v;
tmp = upper_bound(ls + 1, ls + 1 + tot, a[u]) - 1 - ls;
ans += query(root[tmp], u, 1, n);
printf("%d\n", ans);
}
}

BZOJ 2016十连测 D3T3序列的更多相关文章

  1. BZOJ NOI十连测 第二测 T2

    思路:20%可以搜索.. #include<algorithm> #include<cstdio> #include<cmath> #include<cstr ...

  2. BZOJ NOI十连测 第二测 T1

    出题人居然是个哲学家.. 26%的程序,太SB了...本来我的想法也是二分+贪心,但是贪心是个怪怪的SX贪心.. #include<algorithm> #include<cstdi ...

  3. BZOJ NOI十连测 第一测 T1

    思路:首先考虑t=1的情况,t等于1,那么所有位置的颜色相同,我们不用考虑概率的问题,那么,k+d*x在模d下都相等,我们考虑预处理一个数组s[i][j],代表d为i,起始位置为j的等差数列的和,这个 ...

  4. BZOJ NOI十连测 第一测 T2

    思路:看到这题,就感觉是一道很熟悉的题目: http://www.cnblogs.com/qzqzgfy/p/5535821.html 只不过这题的K最多可以到N,而且边权不再只是1,考试的时候yy了 ...

  5. bzoj 5216 [Lydsy2017省队十连测]公路建设 线段树维护 最小生成树

    [Lydsy2017省队十连测]公路建设 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 93  Solved: 53[Submit][Status][ ...

  6. bzoj 5216: [Lydsy2017省队十连测]公路建设

    5216: [Lydsy2017省队十连测]公路建设 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 66  Solved: 37[Submit][St ...

  7. 提高十连测day3

    提高十连测day3 A 我们可以枚举两个 $ 1 $ 之间的相隔距离,然后计算形如 $ 00100100 \cdots $ 的串在原串中最⻓⼦序列匹配即可,复杂度 $ O(n^2) $ .寻找 $ S ...

  8. ZROI2019 提高十连测

    额 掰手指头一数 特么又是第三年十连测了= = 2017一场没打 那时候好像一场比赛也就100人左右 2018前几场还都好好补了 后来开始放飞自我了 这时候一场有150人还多了 2019想让今年的No ...

  9. Lydsy2017省队十连测

    5215: [Lydsy2017省队十连测]商店购物 可能FFT学傻了,第一反应是前面300*300背包,后面FFT... 实际上前面背包,后面组合数即可.只是这是一道卡常题,需要注意常数.. //A ...

随机推荐

  1. python if,循环的练习

    1.变量值的交换 ​ s1='alex'​ s2='SB' (s1,s2) = (s2,s1) 2.有存放用户信息的列表如下,分别存放用户的名字.年龄.公司信息 userinfo={ 'name':' ...

  2. redis--解析字符串

    # coding=utf-8import codecs if __name__ == '__main__': cmdlist = ("Decode") while True: cm ...

  3. JAVA REENTRANTLOCK、SEMAPHORE 的实现与 AQS 框架

    引言 ReentrantLock是JDK提供的一个可重入互斥锁,所谓可重入就是同一个锁允许被已经获得该锁的线程重新获得.可重入锁的好处可以在递归算法中使用锁,不可重入锁则导致无法在递归算法中使用锁.因 ...

  4. SecureCR 控制台输出行数设置

    1.Options –>Session Options–>Terminal–>Emulation 2.在Scrollback输入你需要的最大显示行数,最大行数是128000,修改完全 ...

  5. Unable to compile class for JSP 的可能原因

    浏览器访问web jsp文件,导致500-Unable to compile class for JSP 的原因. 原因一:查看网上的方法,说很可能的原因是tomcat版本比JDK的版本要低导致的.所 ...

  6. mysql 数据插入时的问题

    问题:在实现json串插入到数据库的时候发现中文utf-8传入的.但到数据中的时候反斜杠\就不见了,导致后面显示的时候也不能正常显示. 解决方法:comment=comment.replace(&qu ...

  7. UI设计篇·入门篇·简单动画的实现,透明动画/旋转动画/移动动画/缩放动画,混合动画效果的实现,为动画设置监听事件,自定义动画的方法

    基本的动画构成共有四种:透明动画/旋转动画/移动动画/缩放动画. 配置动画的方式有两种,一种是直接使用代码来配置动画效果,另一种是使用xml文档配置动画效果 相比而言,用xml文档写出来的动画效果,写 ...

  8. Docker 容器操作命令

    容器是镜像的一个运行实例,镜像是静态的只读文件,而容器带有运行时需要的可写文件层.如果认为虚拟机是模拟运行的一整套操作系统(包括内核.应用运行态环境和其他系统环境)和跑在上面的应用,那么Docker容 ...

  9. ArrayList的addAll方法

    方法实现如下: public boolean addAll(Collection c) { Object[] a = c.toArray(); int numNew = a.length; ensur ...

  10. Alpha冲刺

    第一天 日期:2018/6/16 1.今日完成任务情况以及遇到的问题 张天旭:根据系统的需求,完成数据库的设计 周甜甜:完成系统后台登录界面的设计及登录功能的实现 李蕾:完成系统后台首页的设计 张海鑫 ...