6356.Glad You Came

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

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

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

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

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

贴一下人家的代码:

 #include<bits/stdc++.h>
using namespace std;
typedef unsigned int ui;
typedef long long ll;
const int maxn = 1e5 + ;
const int maxm = 5e6 + ;
const ui mod = << ;
ui x, y, z, w, f[*maxm], Left[maxm], Right[maxm], v[maxm];
ui fun()
{
x ^= (x << );
x ^= (x >> );
x ^= (x << );
x ^= (x >> );
w = x ^ (y ^ z);
x = y;
y = z;
z = w;
return z;
} ll ans, a[maxn], maxa[maxn<<], mina[maxn<<], lazy[maxn<<];
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define getm int m = l + r >> 1
void pushup(int rt)
{
mina[rt] = min(mina[rt<<],mina[rt<<|]);
maxa[rt] = max(maxa[rt<<],maxa[rt<<|]);
} void pushdown(int rt)
{
if(lazy[rt])
{
lazy[rt<<] = lazy[rt<<|] = lazy[rt];
maxa[rt<<] = maxa[rt<<|] = lazy[rt];
mina[rt<<] = mina[rt<<|] = lazy[rt];
lazy[rt] = ;
}
} void update(ui L,ui R,ui val,int l,int r,int rt)
{
if(mina[rt] >= val) return ;//最小值都比v大,不用更新
if(L <= l && r <= R)
{
if(maxa[rt] <= val)//最大值比v小,全部更新,打标记
{
maxa[rt] = val;
lazy[rt] = val;
return ;
}
//否则继续切分区间,向下更新
} getm;
pushdown(rt);
if(L<=m)
update(L,R,val,lson);
if(R>m)
update(L,R,val,rson);
pushup(rt);
} ll query(int pos,int l,int r,int rt)
{
if(l==r)
return maxa[rt];
getm;
pushdown(rt);
if(pos<=m)
return query(pos,lson);
else
return query(pos,rson);
} int T, N, M;
int main()
{
scanf("%d",&T);
while(T--)
{
memset(a,,*(N+));
memset(lazy,,*(N+));
memset(mina,,*(N+));
memset(maxa,,*(N+));
scanf("%d%d%u%u%u",&N,&M,&x,&y,&z);
for(int i=;i<=*M;++i)
f[i] = fun();
for(int i=;i<=M;++i)
{
Left[i] = min(f[*i-] % N, f[*i-] % N) + ;
Right[i] = max(f[*i-] % N, f[*i-] % N) + ;
v[i] = f[*i] % mod;
update(Left[i],Right[i],v[i],,N,);
}
ans = ;
for(int i=;i<=N;++i)
ans ^= ((ll)i * query(i,,N,));
printf("%lld\n",ans);
}
return ;
}

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

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

 //1007-6356-线段树
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
typedef unsigned int ui;
typedef long long ll;
const double PI=acos(-1.0);
const double eps=1e-;
const int inf=0x3f3f3f3f;
const int maxn=1e5+;
const int maxm=5e6+;
const ui mod=<<;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 ll lazy[maxn<<],MAX[maxn<<],MIN[maxn<<];
ui x,y,z,w,f[maxm]; void pushup(int rt)
{
MIN[rt]=min(MIN[rt<<],MIN[rt<<|]);
MAX[rt]=max(MAX[rt<<],MAX[rt<<|]);
} void pushdown(int rt)
{
if(lazy[rt]){
lazy[rt<<]=lazy[rt<<|]=lazy[rt];
MAX[rt<<]=MAX[rt<<|]=lazy[rt];
MIN[rt<<]=MIN[rt<<|]=lazy[rt];
lazy[rt]=;
}
} void build(int l,int r,int rt)
{
lazy[rt]=;MAX[rt]=MIN[rt]=;
if(l==r){
return ;
} int m=(l+r)>>;
build(lson);
build(rson);
} void update(ui L,ui R,ui val,int l,int r,int rt)
{
if(MIN[rt]>=val) return ;
if(L<=l&&r<=R){
if(MAX[rt]<=val){
MAX[rt]=val;
lazy[rt]=val;
return ;
}
} pushdown(rt);
int m=(l+r)>>;
if(L<=m) update(L,R,val,lson);
if(R> m) update(L,R,val,rson);
pushup(rt);
} ll query(int pos,int l,int r,int rt)
{
if(l==r){
return MAX[rt];
} pushdown(rt);
int m=(l+r)>>;
if(pos<=m) return query(pos,lson);
if(pos> m) return query(pos,rson);
} ui RNG61()
{
x ^= (x << );
x ^= (x >> );
x ^= (x << );
x ^= (x >> );
w = x ^ (y^z);
x = y;
y = z;
z = w;
return z;
} int t,n,m; int main()
{
scanf("%d",&t);
while(t--){
scanf("%d%d%u%u%u",&n,&m,&x,&y,&z);
build(,n,);
for(int i=;i<=*m;i++)
f[i]=RNG61();
for(int i=;i<=m;i++){
ui l=min(f[*i-]%n,f[*i-]%n)+;
ui r=max(f[*i-]%n,f[*i-]%n)+;
ui v=f[*i]%mod;
update(l,r,v,,n,);
}
ll ans=;
for(int i=;i<=n;i++)
ans^=(ll)i*query(i,,n,);
printf("%lld\n",ans);
}
}

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

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. 【转】配置Tomcat使用https协议(配置SSL协议)

    转载地址:http://ln-ydc.iteye.com/blog/1330674 内容概览: 如果希望 Tomcat 支持 Https,主要的工作是配置 SSL 协议 1.生成安全证书 2.配置to ...

  2. ActiveMQ+Zookeeper集群配置文档

    Zookeeper + ActiveMQ 集群整合配置文档 一:使用ZooKeeper实现的MasterSlave实现方式 是对ActiveMQ进行高可用的一种有效的解决方案, 高可用的原理:使用Zo ...

  3. null?对象?异常?到底应该如何返回错误信息

    这篇文章记录我的一些思考.在工作了一段时间之后. 问题的核心很简单:到底如何返回错误信息. 学生时代,见到过当时的老师的代码: if (foo() == null) { } 当然,这位老师是一位比较擅 ...

  4. 树剖模板by fcdalao

    #include<bits/stdc++.h> using namespace std; ; *MX]; *MX]; int n,Index,fir[MX],fa[MX],dfn[MX], ...

  5. wyh的物品~(二分)

    链接:https://www.nowcoder.com/acm/contest/93/I来源:牛客网 题目描述 wyh学长现在手里有n个物品,这n个物品的重量和价值都告诉你,然后现在让你从中选取k个, ...

  6. intellij IDEA与springboot项目建立

    概念问题: IntelliJ系中的Project相当于Eclipse系中的workspace.IntelliJ系中的Module相当于Eclipse系中的Project.IntelliJ中一个Proj ...

  7. Google MapReduce中文版

    英文原文链接: Google Map Reduce 译文原文链接: Google MapReduce中文版 Google MapReduce中文版 译者: alex 摘要 MapReduce是一个编程 ...

  8. 使用Spring AOP实现读写分离(MySql实现主从复制)

    1.  背景 我们一般应用对数据库而言都是“读多写少”,也就说对数据库读取数据的压力比较大,有一个思路就是说采用数据库集群的方案,其中一个是主库,负责写入数据,我们称之为:写库: 其它都是从库,负责读 ...

  9. HTTP缓存原理

    http的缓存分为强制缓存和对比缓存,两者的区别在于,强制缓存只要设置的时间不过期,就可以直接拿去用,而不用向服务器再一次发送请求.而对比缓存不管缓存是否有效,都需要向服务器发送请求. 其过程如下: ...

  10. Git菜鸟

    1.git 和svn的差异 git和svn 最大的差异在于git是分布式的管理方式而svn是集中式的管理方式.如果不习惯用代码管理工具,可能比较难理解分布式管理和集中式管理的概念.下面介绍两种工具的工 ...