本文主要是介绍HDU6356 Glad You Came(2018HDU多校联赛第五场,线段树),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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 (i=1,2,⋯,3m) ( i = 1 , 2 , ⋯ , 3 m ) The i-th operation of Steve is to update aj as vi if (j=li,li+1,⋯,ri) ( j = l i , l i + 1 , ⋯ , r i ) , where
⎧⎩⎨lirivi=min((f3i−2modn)+1,(f3i−1modn)+1)=max((f3i−2modn)+1,(f3i−1modn)+1)=f3imod230(i=1,2,⋯,m). { l i = min ( ( f 3 i − 2 mod n ) + 1 , ( f 3 i − 1 mod n ) + 1 ) r i = max ( ( f 3 i − 2 mod n ) + 1 , ( f 3 i − 1 mod n ) + 1 ) v i = f 3 i mod 2 30 ( i = 1 , 2 , ⋯ , m ) .
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.
思路
题目给你了一个 n,m,x,y,z n , m , x , y , z ,还给了一个生成函数由给出的 x,y,z x , y , z ,可以生成不同的值。
刚开始有长度为 n n 全部为0的序列,然后有个操作,每个操作有 l,r,v l , r , v ,代表把区间 [l,r] [ l , r ] 内小于 v v 的数变成, l,r,v l , r , v 可以由给出的函数生成。注意这个函数里面的类型是unsigned int
。
最后询问i^a[i]
的和
直接用线段树尽心更新就好,这个题主要是题难读懂。。
代码
#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, b, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
typedef long long ll;
typedef unsigned int uint;
const int N = 1e5 + 100;
uint x, y, z;
uint calc()
{x = x ^ (x << 11);x = x ^ (x >> 4);x = x ^ (x << 5);x = x ^ (x >> 14);uint w = x ^ (y ^ z);x = y;y = z;z = w;return z;
}
int MAX[N << 2];
void pushup(int rt)
{MAX[rt] = max(MAX[rt << 1], MAX[rt << 1 | 1]);
}
void pushdown(int rt)
{if (MAX[rt]){MAX[rt << 1] = max(MAX[rt << 1], MAX[rt]);MAX[rt << 1 | 1] = max(MAX[rt << 1 | 1], MAX[rt]);}
}
void build(int l, int r, int rt)
{MAX[rt] = 0;if (l == r)return;int m = (l + r) >> 1;build(lson);build(rson);pushup(rt);
}void update(int L, int R, int v, int l, int r, int rt)
{if (v <= MAX[rt])return;if (L <= l && r <= R){MAX[rt] = v;return;}pushdown(rt);int m = (l + r) >> 1;if (L <= m)update(L, R, v, lson);if (R > m)update(L, R, v, rson);
}
int query(int p, int l, int r, int rt)
{if (l == r)return MAX[rt];pushdown(rt);int m = (l + r) >> 1;if (p <= m)return query(p, lson);elsereturn query(p, rson);
}
void solve()
{int n, m;int mod = 1 << 30;scanf("%d%d%u%u%u", &n, &m, &x, &y, &z);build(1, n, 1);while (m--){uint p = calc();uint q = calc();int l = min(p % n + 1, q % n + 1);int r = max(p % n + 1, q % n + 1);int v = calc() % mod;if (l > r)swap(l, r);update(l, r, v, 1, n, 1);}ll ans = 0;for (int i = 1; i <= n; i++)ans = ans ^ (1ll * i * query(i, 1, n, 1));printf("%lld\n", ans);
}
int main()
{//freopen("in.txt","r",stdin);int t;scanf("%d", &t);while (t--)solve();return 0;
}
这篇关于HDU6356 Glad You Came(2018HDU多校联赛第五场,线段树)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!