HDU-6356

题意:有m次操作,每次操作通过给定的随机函数生成 l , r , v,使得在 到 区间内,所有的a【i】变为max(a[i] , v).

  最后输出n个a【i】* i的异或和。

 

思路:线段树操作,每次维护区间的最小值,如果当前的v小于区间的最小值,直接return,lazy标记维护区间未加的最大值,必要时pushdown就ok;

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000") //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull; typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii; //priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
// #define endl '\n' #define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
#define REP(i , j , k) for(int i = j ; i < k ; ++i)
//priority_queue<int ,vector<int>, greater<int> >que; const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; // template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
}
// #define _DEBUG; //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*-----------------------show time----------------------*/
unsigned X,Y,Z,W;
unsigned RNG61(){
X = X ^ (X<<);
X = X ^ (X>>);
X = X ^ (X<<);
X = X ^ (X>>);
W = X ^ (Y ^ Z);
X = Y;
Y = Z;
Z = W;
return Z;
} const ll MOD = (<<);
const int maxn = 1e5+;
int n,m; ll sum[maxn*],lazy[maxn*];
void build(int l,int r,int rt){
sum[rt] = ;
lazy[rt] = ;
if(l==r){
return;
}
int mid = (l + r)/;
build(l,mid,rt<<);
build(mid+,r,rt<<|);
}
void pushup(int rt){
sum[rt] = min(sum[rt<<] , sum[rt<<|]);
}
void pushdown(int rt){
if(lazy[rt]){
lazy[rt<<] = max(lazy[rt],lazy[rt<<]);
lazy[rt<<|] = max(lazy[rt],lazy[rt<<|]);
sum[rt<<] = max(sum[rt<<] , lazy[rt]);
sum[rt<<|] = max(sum[rt<<|] , lazy[rt]);
lazy[rt] = ;
}
}
void update(int l, int r, int rt,int L,int R,ll val){
if(sum[rt] > val)return;
if(l>=L && r <=R){ sum[rt] = max(sum[rt],val); lazy[rt] = max(lazy[rt],val);
return;
}
pushdown(rt);
int mid = (l+r)/;
if(mid >= L)update(l,mid,rt<<,L,R,val);
if(mid < R)update(mid+,r, rt<<|, L,R,val);
pushup(rt);
}
ll ans = 0ll;
void g_ans(int l,int r,int rt,int L,int R){
if(l==r){
// debug(sum[rt]);
ans ^= (1ll*l*sum[rt]);
return;
}
pushdown(rt);
int mid = (l+r)/;
g_ans(l,mid,rt<<,L,R);
g_ans(mid+,r, rt<<|, L,R);
}
int main(){
int t; scanf("%d", &t);
while(t--){ scanf("%d%d", &n, &m);
scanf("%u%u%u", &X, &Y, &Z);
build(,n,);
// debug(X);
for(int i=; i<=m; i++){
ll s = RNG61();
ll t = RNG61();
int tmp1 = s%n+;
int tmp2 = t%n+; int le = min(tmp1 , tmp2);
int ri = max(tmp1, tmp2);
ll v = RNG61() % MOD;
update(,n,,le,ri,v);
}
ans = 0ll;
g_ans(,n,,,n);
printf("%lld\n", ans);
} return ;
}

线段树

由于询问只有一次,就是最后的输出,所以可以用ST表,这道题算是一个逆向的构造ST表,推出dp【0】【i】的结果;

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <iostream>
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000") //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull; typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii; //priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
// #define endl '\n' #define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
#define REP(i , j , k) for(int i = j ; i < k ; ++i)
//priority_queue<int ,vector<int>, greater<int> >que; const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; // template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
}
// #define _DEBUG; //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*-----------------------show time----------------------*/
unsigned X,Y,Z,W;
unsigned RNG61(){
X = X ^ (X<<);
X = X ^ (X>>);
X = X ^ (X<<);
X = X ^ (X>>);
W = X ^ (Y ^ Z);
X = Y;
Y = Z;
Z = W;
return Z;
} const ll MOD = (<<);
const int maxn = 1e5+;
int n,m; ll dp[][maxn];
int Log[maxn];
void update(int le,int ri,ll val){
int k = Log[ri-le+];
dp[k][le] = max(dp[k][le], val);
dp[k][ri-(<<k)+] = max(val,dp[k][ri-(<<k)+]);
}
void solve(){
cin>>n>>m>>X>>Y>>Z;
for(int j=; j<;j++){
for(int i=; i<=n; i++){
dp[j][i] = ;
}
} for(int i=; i<=m; i++){
int t1 = RNG61()%n + ;
int t2 = RNG61()%n + ;
int le = min(t1, t2);
int ri = max(t1, t2);
ll val = RNG61() % MOD; update(le,ri,val);
// cout<<val<<endl;
} for(int j=; j; j--){
for(int i=; i+(<<(j-)) <=n; i++){
dp[j-][i] = max(dp[j][i] , dp[j-][i]);
dp[j-][i+(<<(j-))] = max(dp[j-][i+(<<(j-))] ,dp[j][i]);
}
} ll ans = ;
for(int i=; i<=n; i++){
ans = ans ^ (i * dp[][i]);
// cout<<dp[0][i]<<" ";
}
// cout<<endl;
cout<<ans<<endl;
} int main(){
OKC;
Log[] = ;
for(int i=; i<maxn; i++){
Log[i] = Log[i>>] + ;
}
int t; cin>>t; while(t--){
solve();
}
return ;
}

ST表

HDU-6356 Glad You Came 线段树 ST表的更多相关文章

  1. HDU 6356.Glad You Came-线段树(区间更新+剪枝) (2018 Multi-University Training Contest 5 1007)

    6356.Glad You Came 题意就是给你一个随机生成函数,然后从随机函数里确定查询的左右区间以及要更新的val值.然后最后求一下异或和就可以了. 线段树,区间最大值和最小值维护一下,因为数据 ...

  2. 51Nod.1766.树上最远点对(树的直径 RMQ 线段树/ST表)

    题目链接 \(Description\) 给定一棵树.每次询问给定\(a\sim b,c\sim d\)两个下标区间,从这两个区间中各取一个点,使得这两个点距离最远.输出最远距离. \(n,q\leq ...

  3. luoguP5108 仰望半月的夜空 [官方?]题解 后缀数组 / 后缀树 / 后缀自动机 + 线段树 / st表 + 二分

    仰望半月的夜空 题解 可以的话,支持一下原作吧... 这道题数据很弱..... 因此各种乱搞估计都是能过的.... 算法一 暴力长度然后判断判断,复杂度\(O(n^3)\) 期望得分15分 算法二 通 ...

  4. CF803G-Periodic RMQ Problem【离散化,线段树,ST表】

    正题 题目链接:https://www.luogu.com.cn/problem/CF803G 题目大意 一个长度为\(n\)的序列\(a\)复制\(k\)份连接,要求支持 区间赋值 区间查询最小值 ...

  5. 线段树模板(HDU 6356 Glad You Came)

    题目: HDU 6356 http://acm.hdu.edu.cn/showproblem.php?pid=6356 很裸的线段树 #include<bits/stdc++.h> #de ...

  6. HDU 3016 Man Down (线段树+dp)

    HDU 3016 Man Down (线段树+dp) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  7. HDU.5692 Snacks ( DFS序 线段树维护最大值 )

    HDU.5692 Snacks ( DFS序 线段树维护最大值 ) 题意分析 给出一颗树,节点标号为0-n,每个节点有一定权值,并且规定0号为根节点.有两种操作:操作一为询问,给出一个节点x,求从0号 ...

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

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

  9. HDU.1166 敌兵布阵 (线段树 单点更新 区间查询)

    HDU.1166 敌兵布阵 (线段树 单点更新 区间查询) 题意分析 加深理解,重写一遍 代码总览 #include <bits/stdc++.h> #define nmax 100000 ...

随机推荐

  1. Git 学习笔记之(一) 使用 git gui 从github上下载代码

    背景: 目前一些开源代码均在 GitHub上管理的,包括自己写的代码也可以放在上面进行管理.但问题是,当你换一台电脑,想要将你自己放在 GitHub 上的代码工程下载下来的时候,会遇到各种问题,目前可 ...

  2. 前端面试 js 你有多了解call,apply,bind?

    函数原型链中的 apply,call 和 bind 方法是 JavaScript 中相当重要的概念,与 this 关键字密切相关,相当一部分人对它们的理解还是比较浅显,所谓js基础扎实,绕不开这些基础 ...

  3. IT技术管理者的自我修养

    1. 前言 本来写<IT技术管理者的自我修养>与<IT技术人员的自我修养>是一开始就有的想法.但发表<IT技术人员的自我修养>后,收到了不少良好的反馈,博客园的编辑 ...

  4. 解决报错:类型“System.Object”在未被引用的程序集中定义。必须添加对程序集“System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”的引用

    Razor视图引擎中,使用部分视图编译报错 类型“System.Object”在未被引用的程序集中定义.必须添加对程序集“System.Runtime, Version=4.0.0.0, Cultur ...

  5. 理解MySQL(一)--MySQL介绍

    一.Mysql逻辑架构: 1. 第一层:服务器层的服务,连接\线程处理. 2. 第二层:查询执行引擎,MySQL的核心服务功能,包括查询解析.分析.优化和缓存,所有跨存储引擎的功能都在这一层实现. 3 ...

  6. 图片格式:gif / png / pg / webp 介绍

    本文引自:https://www.cnblogs.com/changyangzhe/articles/5718285.html GIF介绍 GIF 意为Graphics Interchange for ...

  7. HBuilderX使用Vant组件库

    HBuilderX使用Vant组件库 HBuilderX是一款由国人开发的开发工具,其官网称其为轻如编辑器.强如IDE的合体版本.但是官方的社区中关于Vant组件的安装大多都是针对微信小程序开发安装V ...

  8. Java——反射:运行时的类信息

    RTTI的使用 如果不知道某个对象的确切类型,RTTI会告诉我们,但是有一个限制:这个类型在编译时必须已知,这样才能使用RTTI识别它,并利用这些信息做一些有用的事情.  2.什么情况下需要反射 假设 ...

  9. 深入理解 linux磁盘顺序写、随机写

    一.前言 ● 随机写会导致磁头不停地换道,造成效率的极大降低:顺序写磁头几乎不用换道,或者换道的时间很短 ● 本文来讨论一下两者具体的差别以及相应的内核调用 二.环境准备 组件 版本 OS Ubunt ...

  10. lxml解析网页

    目录 1. 什么是lxml 2. 初次使用 3. xpath 3.2 标签定位 3.3 序列定位 3.4 轴定位 4. 实例 1. 什么是lxml lxml是干什么的?简单的说来,lxml是帮助我们解 ...