HDU 6356.Glad You Came-线段树(区间更新+剪枝) (2018 Multi-University Training Contest 5 1007)
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)的更多相关文章
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- HDU 1556 Color the ball(线段树区间更新)
Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...
- (简单) HDU 1698 Just a Hook , 线段树+区间更新。
Description: In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of ...
- 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 ...
- hdu - 1689 Just a Hook (线段树区间更新)
http://acm.hdu.edu.cn/showproblem.php?pid=1698 n个数初始每个数的价值为1,接下来有m个更新,每次x,y,z 把x,y区间的数的价值更新为z(1<= ...
- 2014多校第四场1006 || HDU 4902 Nice boat (线段树 区间更新)
题目链接 题意 : 给你n个初值,然后进行两种操作,第一种操作是将(L,R)这一区间上所有的数变成x,第二种操作是将(L,R)这一区间上所有大于x的数a[i]变成gcd(x,a[i]).输出最后n个数 ...
- HDU 4614-Vases and Flowers(线段树区间更新)
题意: n个花瓶(0-n-1) 现有两个操作, 操作1 给a,f 从a位置开始向后连续插f个花(一个花瓶插一个)若当前花瓶有花则向后找,直到n-1位置如果还有多余的花则丢掉求查完花的第一和最后一个位置 ...
- HDU 1698 Just a Hook 线段树区间更新、
来谈谈自己对延迟标记(lazy标记)的理解吧. lazy标记的主要作用是尽可能的降低时间复杂度. 这样说吧. 如果你不用lazy标记,那么你对于一个区间更新的话是要对其所有的子区间都更新一次,但如果用 ...
- hdu 1556 Color the ball 线段树 区间更新
水一下 #include <bits/stdc++.h> #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 ...
随机推荐
- input只改变光标的颜色 不改变字的颜色
color: red; text-shadow: 0px 0px 0px #000; -webkit-text-fill-color: transparent;把这些放到input里文字通过阴影实现 ...
- 批处理中的IF详解
在CMD使用IF /?打开IF的系统帮助会发现IF有3种基本的用法! 第一种用法:IF [NOT] ERRORLEVEL number command 这种用法现在很少用了,因为它需要使用到CHOIC ...
- Java IO 之 RandomAccessFile 操作文件内容
RandomAccessFile类实现对文件内容的随机读写 文件内容的随机操作,重难点在于字符操作,具体查看API package org.zln.io.file; import java.io.IO ...
- JDK的弃儿:Vector、Stack、Hashtable、Enumeration
随着JDK的发展,一些设计缺陷或者性能不足的类库难免会被淘汰,最常见的就是Vector.Stack.HashTable和Enumeration了. Vector(@since 1.0) 首先看看Vec ...
- 关于IE缓存
为了提高访问网页的速度,Internet Explorer浏览器会采用累积式加速的方法,将你曾经访问的网页内容(包括图片以及cookie文件等)存放在电脑里.这个存放空间,我们就称它为IE缓存.以后我 ...
- BZOJ4415 SHOI2013发牌(线段树)
似乎是noip2017d2t3的一个部分分.用splay的话当然非常裸,但说不定会被卡常.可以发现序列中数的(环上)相对位置是不变的,考虑造一棵权值线段树维护权值区间内还有多少个数留在序列中,每次在线 ...
- Clevo P950笔记本加装4G模块
要补全的电路部分如下(原理图见附件) 这里经过尝试,发现左上角R217,R218不用接,3G_POWER部分不接(包括MTS3572G6.UK3018及电阻电容,3G_PWR_EN实测是3.3V,驱动 ...
- Web应用程序开发,基于Ajax技术的JavaScript树形控件
感谢http://www.cnblogs.com/dgrew/p/3181769.html#undefined 在Web应用程序开发领域,基于Ajax技术的JavaScript树形控件已经被广泛使用, ...
- hdu 6223 Infinite Fraction Path
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6223 题意:给定长度为n的一串数字S,现在要按照一种规则寻找长度为n的数字串,使得该数字串的字典序最大 ...
- 【BZOJ2742】【HEOI2012】Akai的数学作业 [数论]
Akai的数学作业 Time Limit: 10 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description 这里是广袤无垠的宇宙这里 ...