6356.Glad You Came

题意就是给你一个随机生成函数,然后从随机函数里确定查询的左右区间以及要更新的val值。然后最后求一下异或和就可以了。

线段树,区间最大值和最小值维护一下,因为数据有点大,不剪枝就会超时。(默默吐槽,剪了枝照样超时)

因为太菜,交了24遍也是没过,TLE,WA,RE轮流来,而且感觉这题有毒,删一个没用的变量就会WA。。。

百度了一下题解,发现有人和我写的几乎一模一样,但是人家的就可以过,我的死也过不去。

人家的博客:HDU6356 Glad You Came(线段树区间更新+剪枝)

贴一下人家的代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef unsigned int ui;
  4. typedef long long ll;
  5. const int maxn = 1e5 + ;
  6. const int maxm = 5e6 + ;
  7. const ui mod = << ;
  8. ui x, y, z, w, f[*maxm], Left[maxm], Right[maxm], v[maxm];
  9. ui fun()
  10. {
  11. x ^= (x << );
  12. x ^= (x >> );
  13. x ^= (x << );
  14. x ^= (x >> );
  15. w = x ^ (y ^ z);
  16. x = y;
  17. y = z;
  18. z = w;
  19. return z;
  20. }
  21.  
  22. ll ans, a[maxn], maxa[maxn<<], mina[maxn<<], lazy[maxn<<];
  23. #define lson l,m,rt<<1
  24. #define rson m+1,r,rt<<1|1
  25. #define getm int m = l + r >> 1
  26. void pushup(int rt)
  27. {
  28. mina[rt] = min(mina[rt<<],mina[rt<<|]);
  29. maxa[rt] = max(maxa[rt<<],maxa[rt<<|]);
  30. }
  31.  
  32. void pushdown(int rt)
  33. {
  34. if(lazy[rt])
  35. {
  36. lazy[rt<<] = lazy[rt<<|] = lazy[rt];
  37. maxa[rt<<] = maxa[rt<<|] = lazy[rt];
  38. mina[rt<<] = mina[rt<<|] = lazy[rt];
  39. lazy[rt] = ;
  40. }
  41. }
  42.  
  43. void update(ui L,ui R,ui val,int l,int r,int rt)
  44. {
  45. if(mina[rt] >= val) return ;//最小值都比v大,不用更新
  46. if(L <= l && r <= R)
  47. {
  48. if(maxa[rt] <= val)//最大值比v小,全部更新,打标记
  49. {
  50. maxa[rt] = val;
  51. lazy[rt] = val;
  52. return ;
  53. }
  54. //否则继续切分区间,向下更新
  55. }
  56.  
  57. getm;
  58. pushdown(rt);
  59. if(L<=m)
  60. update(L,R,val,lson);
  61. if(R>m)
  62. update(L,R,val,rson);
  63. pushup(rt);
  64. }
  65.  
  66. ll query(int pos,int l,int r,int rt)
  67. {
  68. if(l==r)
  69. return maxa[rt];
  70. getm;
  71. pushdown(rt);
  72. if(pos<=m)
  73. return query(pos,lson);
  74. else
  75. return query(pos,rson);
  76. }
  77.  
  78. int T, N, M;
  79. int main()
  80. {
  81. scanf("%d",&T);
  82. while(T--)
  83. {
  84. memset(a,,*(N+));
  85. memset(lazy,,*(N+));
  86. memset(mina,,*(N+));
  87. memset(maxa,,*(N+));
  88. scanf("%d%d%u%u%u",&N,&M,&x,&y,&z);
  89. for(int i=;i<=*M;++i)
  90. f[i] = fun();
  91. for(int i=;i<=M;++i)
  92. {
  93. Left[i] = min(f[*i-] % N, f[*i-] % N) + ;
  94. Right[i] = max(f[*i-] % N, f[*i-] % N) + ;
  95. v[i] = f[*i] % mod;
  96. update(Left[i],Right[i],v[i],,N,);
  97. }
  98. ans = ;
  99. for(int i=;i<=N;++i)
  100. ans ^= ((ll)i * query(i,,N,));
  101. printf("%lld\n",ans);
  102. }
  103. return ;
  104. }

最后贴一下我的死也没过去的代码,哪个大佬好心看一下,然后拯救一下我。。。

我队友帮我调了也快20发了,依旧没过,哭死༼༎ຶᴗ༎ຶ༽

  1. //1007-6356-线段树
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<cstring>
  5. #include<algorithm>
  6. #include<bitset>
  7. #include<cassert>
  8. #include<cctype>
  9. #include<cmath>
  10. #include<cstdlib>
  11. #include<ctime>
  12. #include<deque>
  13. #include<iomanip>
  14. #include<list>
  15. #include<map>
  16. #include<queue>
  17. #include<set>
  18. #include<stack>
  19. #include<vector>
  20. using namespace std;
  21. typedef unsigned int ui;
  22. typedef long long ll;
  23. const double PI=acos(-1.0);
  24. const double eps=1e-;
  25. const int inf=0x3f3f3f3f;
  26. const int maxn=1e5+;
  27. const int maxm=5e6+;
  28. const ui mod=<<;
  29. #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  30.  
  31. #define lson l,m,rt<<1
  32. #define rson m+1,r,rt<<1|1
  33.  
  34. ll lazy[maxn<<],MAX[maxn<<],MIN[maxn<<];
  35. ui x,y,z,w,f[maxm];
  36.  
  37. void pushup(int rt)
  38. {
  39. MIN[rt]=min(MIN[rt<<],MIN[rt<<|]);
  40. MAX[rt]=max(MAX[rt<<],MAX[rt<<|]);
  41. }
  42.  
  43. void pushdown(int rt)
  44. {
  45. if(lazy[rt]){
  46. lazy[rt<<]=lazy[rt<<|]=lazy[rt];
  47. MAX[rt<<]=MAX[rt<<|]=lazy[rt];
  48. MIN[rt<<]=MIN[rt<<|]=lazy[rt];
  49. lazy[rt]=;
  50. }
  51. }
  52.  
  53. void build(int l,int r,int rt)
  54. {
  55. lazy[rt]=;MAX[rt]=MIN[rt]=;
  56. if(l==r){
  57. return ;
  58. }
  59.  
  60. int m=(l+r)>>;
  61. build(lson);
  62. build(rson);
  63. }
  64.  
  65. void update(ui L,ui R,ui val,int l,int r,int rt)
  66. {
  67. if(MIN[rt]>=val) return ;
  68. if(L<=l&&r<=R){
  69. if(MAX[rt]<=val){
  70. MAX[rt]=val;
  71. lazy[rt]=val;
  72. return ;
  73. }
  74. }
  75.  
  76. pushdown(rt);
  77. int m=(l+r)>>;
  78. if(L<=m) update(L,R,val,lson);
  79. if(R> m) update(L,R,val,rson);
  80. pushup(rt);
  81. }
  82.  
  83. ll query(int pos,int l,int r,int rt)
  84. {
  85. if(l==r){
  86. return MAX[rt];
  87. }
  88.  
  89. pushdown(rt);
  90. int m=(l+r)>>;
  91. if(pos<=m) return query(pos,lson);
  92. if(pos> m) return query(pos,rson);
  93. }
  94.  
  95. ui RNG61()
  96. {
  97. x ^= (x << );
  98. x ^= (x >> );
  99. x ^= (x << );
  100. x ^= (x >> );
  101. w = x ^ (y^z);
  102. x = y;
  103. y = z;
  104. z = w;
  105. return z;
  106. }
  107.  
  108. int t,n,m;
  109.  
  110. int main()
  111. {
  112. scanf("%d",&t);
  113. while(t--){
  114. scanf("%d%d%u%u%u",&n,&m,&x,&y,&z);
  115. build(,n,);
  116. for(int i=;i<=*m;i++)
  117. f[i]=RNG61();
  118. for(int i=;i<=m;i++){
  119. ui l=min(f[*i-]%n,f[*i-]%n)+;
  120. ui r=max(f[*i-]%n,f[*i-]%n)+;
  121. ui v=f[*i]%mod;
  122. update(l,r,v,,n,);
  123. }
  124. ll ans=;
  125. for(int i=;i<=n;i++)
  126. ans^=(ll)i*query(i,,n,);
  127. printf("%lld\n",ans);
  128. }
  129. }

滚了滚了,滚回垃圾桶了。

HDU 6356.Glad You Came-线段树(区间更新+剪枝) (2018 Multi-University Training Contest 5 1007)的更多相关文章

  1. HDU.1556 Color the ball (线段树 区间更新 单点查询)

    HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...

  2. HDU 1556 Color the ball(线段树区间更新)

    Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...

  3. (简单) HDU 1698 Just a Hook , 线段树+区间更新。

    Description: In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of ...

  4. HDU 1698 Just a Hook(线段树区间更新查询)

    描述 In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes ...

  5. hdu - 1689 Just a Hook (线段树区间更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=1698 n个数初始每个数的价值为1,接下来有m个更新,每次x,y,z 把x,y区间的数的价值更新为z(1<= ...

  6. 2014多校第四场1006 || HDU 4902 Nice boat (线段树 区间更新)

    题目链接 题意 : 给你n个初值,然后进行两种操作,第一种操作是将(L,R)这一区间上所有的数变成x,第二种操作是将(L,R)这一区间上所有大于x的数a[i]变成gcd(x,a[i]).输出最后n个数 ...

  7. HDU 4614-Vases and Flowers(线段树区间更新)

    题意: n个花瓶(0-n-1) 现有两个操作, 操作1 给a,f 从a位置开始向后连续插f个花(一个花瓶插一个)若当前花瓶有花则向后找,直到n-1位置如果还有多余的花则丢掉求查完花的第一和最后一个位置 ...

  8. HDU 1698 Just a Hook 线段树区间更新、

    来谈谈自己对延迟标记(lazy标记)的理解吧. lazy标记的主要作用是尽可能的降低时间复杂度. 这样说吧. 如果你不用lazy标记,那么你对于一个区间更新的话是要对其所有的子区间都更新一次,但如果用 ...

  9. hdu 1556 Color the ball 线段树 区间更新

    水一下 #include <bits/stdc++.h> #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 ...

随机推荐

  1. Java IO 之 System类

    1.使用System.in.read读取,使用System.out.println 输出 package org.zln.io; import java.io.IOException; /** * C ...

  2. 【bzoj4236】JOIOJI STL-map

    题目描述 JOIOJI桑是JOI君的叔叔.“JOIOJI”这个名字是由“J.O.I”三个字母各两个构成的. 最近,JOIOJI桑有了一个孩子.JOIOJI桑想让自己孩子的名字和自己一样由“J.O.I” ...

  3. AGC018D Tree and Hamilton Path(树+树的重心)

    题目大意: 给你一棵n个结点树,然后根据这棵树构造一个完全图,求完全图的一条最长的哈密顿路径. 构造方式是,完全图中的dis(u, v)就等于树上的u和v的距离. 题解: 这...这..不就是杜教的那 ...

  4. Treap 模板

    感觉平衡树也没有以前想的那么玄乎,(其实set超好用的),非旋式Treap挺好理解,和可并堆,二叉搜索树有很大联系 推荐博客:http://memphis.is-programmer.com/post ...

  5. 【BZOJ 3172】[Tjoi2013]单词 AC自动机

    关于AC自动机:一个在kmp与Trie的基础上建立的数据结构,关键在于Trie树结构与fail指针,他们各有各的应用.在AC自动机里最典型的就是多串匹配,原本效率为O(n*l+n*l+m*l),(n是 ...

  6. 【NOIP 模拟赛】中值滤波 打表找规律

    对于这样看起来不像什么算法也没什么知识点的题,一脸懵逼的话不是手推规律就是打表找规律......... 当然还有一些超出你能力之外的数学题...... #include <cstdio> ...

  7. 如何使用Eclipse调试framework

    1.下载Eclipse EE(下载地址:http://www.eclipse.org/downloads/) 2.下载并安装JDK(下载地址:http://www.oracle.com/technet ...

  8. HNOI2002 彩票 [搜索]

    题目描述 某地发行一套彩票.彩票上写有1到M这M个自然数.彩民可以在这M个数中任意选取N个不同的数打圈.每个彩民只能买一张彩票,不同的彩民的彩票上的选择不同. 每次抽奖将抽出两个自然数X和Y.如果某人 ...

  9. POJ3159:Candies(差分约束)

    Candies Time Limit: 1500MS   Memory Limit: 131072K Total Submissions: 39666   Accepted: 11168 题目链接:h ...

  10. 安卓中使用iconfont

    https://www.cnblogs.com/dongweiq/p/5730212.html