2018杭电多校:G: Glad You Came

题目描述

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), where

⎧⎩⎨⎪⎪lirivi=min((f3i−2modn)+1,(f3i−1modn)+1)=max((f3i−2modn)+1,(f3i−1modn)+1)=f3imod230(i=1,2,⋯,m).

输入

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.

输出

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

样例输入

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

样例输出

1031463378
1446334207
351511856
47320301347

提示

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.

 

解题:根据所给条件先设定所要有的原数组,构造线段树。

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
const int MOD=1<<30;//不能用define
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
typedef  long long LL;
LL a[maxn];
unsigned f[maxn<<4];
unsigned X,Y,Z;
unsigned RNG(){
    X=X^(X<<11);
    X=X^(X>>4);
    X=X^(X<<5);
    X=X^(X>>14);
    unsigned W=X^(Y^Z);
    X=Y;
    Y=Z;
    Z=W;
    return Z;
} 
void push(int rt){
    a[rt]=min(a[rt<<1],a[rt<<1|1]);
}
void update(int L,int R,LL w,int l,int r,int rt){
    if (a[rt]>=w)
       return ;
    if (l==r){
        a[rt]=w;
        return;
    }
    int mid=(l+r)>>1;
    if (L<=mid)
       update(L,R,w,lson);
    if (R>mid)
       update(L,R,w,rson);
    push(rt);
}
LL query(int L,int R,int l,int r,int rt){
    if (L<=l&&r<=R)
        return a[rt];
    LL ans=0;
    int mid=(l+r)>>1;
    if (L<=mid)
       ans=query(L,R,lson);
    if (R>mid)
       ans=query(L,R,rson);
    return ans;
}
int main()
{
    int t;
    scanf("%d",&t);
    while (t--){
        int n,m;
        memset(a,0,sizeof(a));
        scanf("%d%d%d%d%d",&n,&m,&X,&Y,&Z);
        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);
            int v=f[3*i]%MOD;
            update(l,r,v,1,n,1);
        }
        LL sum=0;
        for (int i=1;i<=n;i++){
            LL w=query(i,i,1,n,1);
            sum^=(1LL*w*i);
        }
        printf("%lld\n",sum);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在编译过程中遇到无法打开包括文件错误通常是由于缺少相应的库文件或者路径配置错误所致。针对你遇到的无法打开包括文件: "glad/glad.h": No such file or directory 错误,我可以提供以下解决方法: 1. 确保你已经正确安装了所需的库文件。在这种情况下,你需要确保你已经安装了glad库。glad是一个用于加载OpenGL函数指针的库。你可以从官方网站或其他可靠资源下载glad库。 2. 确保你正确设置了项目的包含路径。你需要告诉编译器去哪里找到glad库的头文件。在你的项目设置中,添加正确的包含路径,以确保编译器能够找到glad.h文件。这通常是在项目的属性或者配置文件中进行设置。 3. 确保你正确链接了所需的库文件。在编译链接阶段,你需要告诉编译器去哪里找到glad库的二进制文件。在你的项目设置中添加正确的库文件路径,并在链接器设置中指定链接glad库。 4. 确保你的代码中正确包含了glad.h文件。在你的代码中添加正确的头文件包含语句,以便编译器能够找到glad.h文件。通常是使用#include <glad/glad.h>这样的语句。 总结起来,你需要确保你已经正确安装了glad库,并且在项目设置中正确配置了包含路径和库文件路径,并在代码中正确包含了glad.h文件。这样就能解决无法打开包括文件: "glad/glad.h": No such file or directory 错误了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值