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. JSP乱码问题

    在JSP中通过request对象获取请求参数时,如果遇到参数值为中文的情况,若不进行处理,获取到的参数值将是乱码.乱码情况分为以下两种: 1. 获取访问请求参数时乱码,采用如下方式解决. String ...

  2. [CF409F]000001

    题目大意:输入一个数,输出一个数(愚人节系列) 题解:$OEIS$的$A000001$(原来我不想写的,但是洛谷的智能推荐推荐我做这个...是不是我太菜了) 卡点:无 C++ Code: #inclu ...

  3. bzoj2002: [Hnoi2010]Bounce 弹飞绵羊 分块

    这个题体现了分块不只是最大值最小值众数次数,而是一种清真的思想. 我们把整个序列分块,在每个块里处理每个位置跳出这个块的次数和跳出的位置,那么每次修改n0.5,每次查询也是,那么O(m* n0.5)的 ...

  4. 压缩跟踪Compressive Tracking

    好了,学习了解了稀疏感知的理论知识后,终于可以来学习<Real-Time Compressive Tracking>这个paper介绍的感知跟踪算法了.自己英文水平有限,理解难免出错,还望 ...

  5. HDU 5655 四边形判断

    CA Loves Stick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) ...

  6. 洛谷P1346 电车

    P1346 电车 236通过 757提交 题目提供者yeszy 标签图论福建省历届夏令营 难度普及/提高- 提交该题 讨论 题解 记录 最新讨论 解不好啊,快疯了!!哪位大… 求解:为何除了-1的点之 ...

  7. angular js自定义service的简单示例

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  8. wget下载HTTPS链接

    wget -c -O master.zip --no-check-certificate https://github.com/mitsuhiko/flask/archive/master.zip # ...

  9. Binding and styling text to a RichTextBox in WPF

    http://www.codeproject.com/Articles/137209/Binding-and-styling-text-to-a-RichTextBox-in-WPF The Rich ...

  10. Java之戳中痛点 - (3)三目运算符的两个操作数类型尽量一致

    先看一个例子: package com.test; public class TernaryOperator { public static void main(String[] args) { in ...