Glad You Came hdu 6356 —— 线段树区间更新+剪枝

2024-04-07 01:08

本文主要是介绍Glad You Came hdu 6356 —— 线段树区间更新+剪枝,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Problem Description
Steve has an integer array a of length n (1-based). He assigned all the elements as zero at the beginning. After that, he made m operations, each of which is to update an interval of a with some value. You need to figure out ⨁ni=1(i⋅ai) after all his operations are finished, where ⨁ means the bitwise exclusive-OR operator.
In order to avoid huge input data, these operations are encrypted through some particular approach.
There are three unsigned 32-bit integers X,Y and Z which have initial values given by the input. A random number generator function is described as following, where ∧ means the bitwise exclusive-OR operator, << means the bitwise left shift operator and >> means the bitwise right shift operator. Note that function would change the values of X,Y and Z after calling.
这里写图片描述

Let the i-th result value of calling the above function as fi (i=1,2,⋯,3m). The i-th operation of Steve is to update aj as vi if aj<vi(j=li,li+1,,ri), a j < v i ( j = l i , l i + 1 , ⋯ , r i ) , where
这里写图片描述

Input
The first line contains one integer T, indicating the number of test cases.
Each of the following T lines describes a test case and contains five space-separated integers n,m,X,Y and Z.
1≤T≤100, 1≤n≤105, 1≤m≤5⋅106, 0≤X,Y,Z<230.
It is guaranteed that the sum of n in all the test cases does not exceed 106 and the sum of m in all the test cases does not exceed 5⋅107.

Output
For each test case, output the answer in one line.

Sample Input
4
1 10 100 1000 10000
10 100 1000 10000 100000
100 1000 10000 100000 1000000
1000 10000 100000 1000000 10000000

Sample Output
1031463378
1446334207
351511856
47320301347

Hint

In the first sample, a = [1031463378] after all the operations.
In the second sample, a = [1036205629, 1064909195, 1044643689, 1062944339, 1062944339, 1062944339, 1062944339, 1057472915, 1057472915, 1030626924] after all the operations.

Source
2018 Multi-University Training Contest 5

没什么好说的,就搞一个最小值然后加一个重要的剪枝,在update里面如果这个区间的最小值已经比加的值大了,就return

#include<bits/stdc++.h>
#define lson rt<<1
#define rson rt<<1|1
using namespace std;
const int mod=(1<<30);
const int maxn=100005;
typedef unsigned ll;
ll f[15000000], x,y,z;
int n,m;
unsigned rng()
{unsigned t;x^=x<<11;x^=x>>4;x^=x<<5;x^=x>>14;t=x;x=y;y=z;z=x^y^t;return z;
}
struct node{int minn,lazy;
}e[maxn<<2];
void pushdown(int rt){if(e[rt].lazy){if(e[lson].lazy<e[rt].lazy)e[lson].lazy=e[rt].lazy;if( e[rson].lazy<e[rt].lazy)e[rson].lazy=e[rt].lazy;if( e[lson].minn<e[rt].lazy)e[lson].minn=e[rt].lazy;if( e[rson].minn<e[rt].lazy)e[rson].minn=e[rt].lazy;e[rt].lazy=0;}
}
void update(int nowl,int nowr,int l,int r,int rt,ll aim){if(e[rt].minn>=aim)return ;if(nowl>=l&&nowr<=r){if(e[rt].minn>=aim){return ;}else{e[rt].minn=aim;e[rt].lazy=aim;return ;}}pushdown(rt);int mid=(nowl+nowr)/2;if(mid>=l) update(nowl,mid,l,r,lson,aim);if(mid<r) update(mid+1,nowr,l,r,rson,aim);e[rt].minn=min(e[lson].minn,e[rson].minn);
}
ll query(int nowl,int nowr,int l,int r,int rt){if(nowl>=l&&nowr<=r){return e[rt].minn;}pushdown(rt);int mid=(nowl+nowr)/2;if(mid>=l) return query(nowl,mid,l,r,lson);if(mid<r) return query(mid+1,nowr,l,r,rson);
}
int main(){int t;cin>>t;while(t--){scanf("%d%d%u%u%u",&n,&m,&x,&y,&z);memset(e,0,sizeof(e));for(int i=1;i<=3*m;i++)f[i]=rng();for(int i=1;i<=m;i++){int l=min(f[3*i-2]%n+1,f[3*i-1]%n+1);int r=max(f[3*i-2]%n+1,f[3*i-1]%n+1);ll aim=f[3*i]%mod;update(1,n,l,r,1,aim);}unsigned long long ans=0;for(int i=1;i<=n;i++){unsigned long long nows=query(1,n,i,i,1);ans^=(i*nows);}cout<<ans<<endl;}
}

这篇关于Glad You Came hdu 6356 —— 线段树区间更新+剪枝的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/881293

相关文章

poj3468(线段树成段更新模板题)

题意:包括两个操作:1、将[a.b]上的数字加上v;2、查询区间[a,b]上的和 下面的介绍是下解题思路: 首先介绍  lazy-tag思想:用一个变量记录每一个线段树节点的变化值,当这部分线段的一致性被破坏我们就将这个变化值传递给子区间,大大增加了线段树的效率。 比如现在需要对[a,b]区间值进行加c操作,那么就从根节点[1,n]开始调用update函数进行操作,如果刚好执行到一个子节点,

hdu1394(线段树点更新的应用)

题意:求一个序列经过一定的操作得到的序列的最小逆序数 这题会用到逆序数的一个性质,在0到n-1这些数字组成的乱序排列,将第一个数字A移到最后一位,得到的逆序数为res-a+(n-a-1) 知道上面的知识点后,可以用暴力来解 代码如下: #include<iostream>#include<algorithm>#include<cstring>#include<stack>#in

hdu1689(线段树成段更新)

两种操作:1、set区间[a,b]上数字为v;2、查询[ 1 , n ]上的sum 代码如下: #include<iostream>#include<algorithm>#include<cstring>#include<stack>#include<queue>#include<set>#include<map>#include<stdio.h>#include<stdl

usaco 1.3 Prime Cryptarithm(简单哈希表暴搜剪枝)

思路: 1. 用一个 hash[ ] 数组存放输入的数字,令 hash[ tmp ]=1 。 2. 一个自定义函数 check( ) ,检查各位是否为输入的数字。 3. 暴搜。第一行数从 100到999,第二行数从 10到99。 4. 剪枝。 代码: /*ID: who jayLANG: C++TASK: crypt1*/#include<stdio.h>bool h

usaco 1.3 Mixing Milk (结构体排序 qsort) and hdu 2020(sort)

到了这题学会了结构体排序 于是回去修改了 1.2 milking cows 的算法~ 结构体排序核心: 1.结构体定义 struct Milk{int price;int milks;}milk[5000]; 2.自定义的比较函数,若返回值为正,qsort 函数判定a>b ;为负,a<b;为0,a==b; int milkcmp(const void *va,c

poj 3974 and hdu 3068 最长回文串的O(n)解法(Manacher算法)

求一段字符串中的最长回文串。 因为数据量比较大,用原来的O(n^2)会爆。 小白上的O(n^2)解法代码:TLE啦~ #include<stdio.h>#include<string.h>const int Maxn = 1000000;char s[Maxn];int main(){char e[] = {"END"};while(scanf("%s", s) != EO

hdu 2093 考试排名(sscanf)

模拟题。 直接从教程里拉解析。 因为表格里的数据格式不统一。有时候有"()",有时候又没有。而它也不会给我们提示。 这种情况下,就只能它它们统一看作字符串来处理了。现在就请出我们的主角sscanf()! sscanf 语法: #include int sscanf( const char *buffer, const char *format, ... ); 函数sscanf()和

hdu 2602 and poj 3624(01背包)

01背包的模板题。 hdu2602代码: #include<stdio.h>#include<string.h>const int MaxN = 1001;int max(int a, int b){return a > b ? a : b;}int w[MaxN];int v[MaxN];int dp[MaxN];int main(){int T;int N, V;s

hdu 1754 I Hate It(线段树,单点更新,区间最值)

题意是求一个线段中的最大数。 线段树的模板题,试用了一下交大的模板。效率有点略低。 代码: #include <stdio.h>#include <string.h>#define TREE_SIZE (1 << (20))//const int TREE_SIZE = 200000 + 10;int max(int a, int b){return a > b ? a :

hdu 1166 敌兵布阵(树状数组 or 线段树)

题意是求一个线段的和,在线段上可以进行加减的修改。 树状数组的模板题。 代码: #include <stdio.h>#include <string.h>const int maxn = 50000 + 1;int c[maxn];int n;int lowbit(int x){return x & -x;}void add(int x, int num){while