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 ...
随机推荐
- javasisst & JAVA8
今天在服务器上启动tomcat7的时候,提示如下异常: java.io.IOException: invalid constant type: 15 具体看是javasisst抛出来的. 系统运行环境 ...
- [洛谷P4015]运输问题
题目大意:有m个仓库和n个商店.第i个仓库有 $a_{i}$ 货物,第j个商店需要$b_{j}$个货物.从第i个仓库运送每单位货物到第j个商店的费用为$c_{i,j}$.求出最小费用和最大费用 题 ...
- 洛谷 P3084 [USACO13OPEN]照片Photo 解题报告
[USACO13OPEN]照片Photo 题目描述 农夫约翰决定给站在一条线上的\(N(1 \le N \le 200,000)\)头奶牛制作一张全家福照片,\(N\)头奶牛编号\(1\)到\(N\) ...
- 【COGS 2434】 暗之链锁 树上差分+LCA
差分就是把一个值拆成许多差的和如 1 2 4 6 9 那么 把这个东西拆成 1 1 2 2 3 就是了,当然也可以理解为对一个问题分解为多个子问题并对其进行操作来得到原问题的答案. 树上差分就更玄妙了 ...
- [hdu 2298] 物理推导+二分答案
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2298 #include<bits/stdc++.h> using namespace st ...
- codeforces 1077D
题目:https://codeforces.com/contest/1077/problem/D 题意:给你一个长度为n的串,你需要在里面找到出现次数最多的长度为k的子序列(子序列中元素可重复),求这 ...
- codeforces 1060 A
https://codeforces.com/contest/1060/problem/A 题意:电话号码是以8开头的11位数,给你n 个数问最多可以有多少个电话号码 题解:min(8的个数,n/11 ...
- HDU1166 敌兵布阵(树状数组实现
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- bzoj 5092 [Lydsy1711月赛]分割序列 贪心高维前缀和
[Lydsy1711月赛]分割序列 Time Limit: 5 Sec Memory Limit: 256 MBSubmit: 213 Solved: 97[Submit][Status][Dis ...
- word使用宏 在文章中插入源代码进行排版
1.宏的代码如下. Sub 设置代码表格() ' author: code4101 ' 设置代码表格 宏 ' ' ' 背景色为morning的配色方案,RGB为(229,229,229) ) With ...