主席树

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<vector>
  5. #define rd read()
  6. using namespace std;
  7. const int N = 1e5 + 5;
  8. int ls[N], tot, n, m, q;
  9. int a[N], ans;
  10. vector<int> ad[N], reduce[N];
  11. struct que {
  12. int l, r, x;
  13. }b[N];
  14. int read() {
  15. int X = 0, p = 1; char c = getchar();
  16. for (; c > '9' || c < '0'; c = getchar())
  17. if (c == '-') p = -1;
  18. for (; c >= '0' && c <= '9'; c = getchar())
  19. X = X * 10 + c - '0';
  20. return X * p;
  21. }
  22. namespace SegT {
  23. int cnt, root[N];
  24. struct node {
  25. int sum, lson, rson;
  26. }p[N * 50];
  27. #define lc(x) p[x].lson
  28. #define rc(x) p[x].rson
  29. #define sum(x) p[x].sum
  30. #define mid ((l + r) >> 1)
  31. void modify(int &x, int now, int pos, int d, int l, int r) {
  32. x = ++cnt;
  33. sum(x) = sum(now) + d;
  34. lc(x) = lc(now);
  35. rc(x) = rc(now);
  36. if (l == r) return;
  37. if (pos <= mid) modify(lc(x), lc(now), pos, d, l, mid);
  38. else modify(rc(x), rc(now), pos, d, mid + 1, r);
  39. }
  40. int query(int x, int pos, int l, int r) {
  41. if (!x) return 0;
  42. if (r <= pos) return sum(x);
  43. int res = 0;
  44. if (mid <= pos)
  45. return query(lc(x), pos, l, mid) + query(rc(x), pos, mid + 1, r);
  46. else
  47. return query(lc(x), pos, l, mid);
  48. }
  49. }using namespace SegT;
  50. int main()
  51. {
  52. n = rd; m = rd; q = rd;
  53. for (int i = 1; i <= n; ++i) a[i] = rd;
  54. for (int i = 1; i <= m; ++i)
  55. b[i].l = rd, b[i].r = rd, b[i].x = rd, ls[++tot] = b[i].x;
  56. sort(ls + 1, ls + 1 + tot);
  57. tot = unique(ls + 1, ls + 1 + tot) - ls - 1;
  58. for (int i = 1; i <= m; ++i) {
  59. int tmp = lower_bound(ls + 1, ls + 1 + tot, b[i].x) - ls;
  60. ad[tmp].push_back(b[i].l);
  61. if (b[i].r < n) reduce[tmp].push_back(b[i].r + 1);
  62. }
  63. for (int i = 1; i <= tot; ++i) {
  64. root[i] = root[i - 1];
  65. for (int j = 0, up = ad[i].size(); j < up; ++j)
  66. modify(root[i], root[i], ad[i][j], 1, 1, n);
  67. for (int j = 0, up = reduce[i].size(); j < up; ++j)
  68. modify(root[i], root[i], reduce[i][j], -1, 1, n);
  69. }
  70. for (int i = 1; i <= n; ++i) {
  71. int tmp = upper_bound(ls + 1, ls + 1 + tot, a[i]) - 1 - ls;
  72. ans += query(root[tmp], i, 1, n);
  73. }
  74. printf("%d\n", ans);
  75. for (int i = 1; i <= q; ++i) {
  76. int u = rd ^ ans, v = rd ^ ans;
  77. int tmp = upper_bound(ls + 1, ls + 1 + tot, a[u]) - 1 - ls;
  78. ans -= query(root[tmp], u, 1, n);
  79. a[u] = v;
  80. tmp = upper_bound(ls + 1, ls + 1 + tot, a[u]) - 1 - ls;
  81. ans += query(root[tmp], u, 1, n);
  82. printf("%d\n", ans);
  83. }
  84. }

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. Oracle修改系统参数导致系统无法启动对pfile文件恢复。

    1.当前现象:Oracle启动报错ORA-27102 [oracle@JYDB1 ~]$ sqlplus / as sysdba SQL*Plus: Release 10.2.0.4.0 - Prod ...

  2. TypeError: Fetch argument 0 has invalid type <type 'int'>, must be a string or Tensor. (Can not convert a int into a Tensor or Operation.)

    6月5日的時候,修改dilated_seg.py(使用tensorflow)出現了報錯: TypeError: Fetch argument 0 has invalid type <type ' ...

  3. javascript判断字符串相等

  4. Idea安装svn插件

    1. 首先要注意:TortoiseSVN在安装的时候没有command line,在安装TortoiseSVN时,要支持Idea需要点击叉的下拉单,选择will be installed local ...

  5. Windows 7升级1月更新汇总后导致SMBv2网络无法正常工作

    在本月的补丁星期二活动日中,微软面向Windows 7.Windows 2008 R2服务器系统推出了KB4480970的月度更新汇总.然而根据部分用户反馈,在安装该更新之后导致系统的网络设置无法正常 ...

  6. NE76003单片机调试DS18B20 步骤

    一.硬件部分 GND脚接地: DQ脚接P03,外加4K7上拉电阻: VCC脚接3.3v供电: 二.软件部分 1.配置P03为准准双向 IO类型: void Init_power_gpio(void){ ...

  7. Django中的auth模块

    from django.contrib import auth authenticate() 提供了用户认证功能,即验证用户名以及密码是否正确,一般需要username .password两个关键字参 ...

  8. CodeForces - 864C-Bus-(模拟加油站问题)

    https://vjudge.net/problem/CodeForces-864C 题意:两地之间有个加油站,往返走k个单程,最少加油多少次. 大佬几十行代码就解决,我却要用一百多行的if语句模拟解 ...

  9. 记一次yii2 上传文件

    1 view渲染 <form action="../src/website/import/report-flow" method="post" encty ...

  10. Google开源软负载seesaw

    https://github.com/google/seesaw ------------------------ 在分布式系统中,负载均衡是非常重要的环节,通过负载均衡将请求派发到网络中的一个或多个 ...