杭电多校第五场 Glad You Came(倍增算法 ST表)

Glad You Came

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 2187    Accepted Submission(s): 959


 

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

⎧⎩⎨⎪⎪lirivi=min((f3i−2modn)+1,(f3i−1modn)+1)=max((f3i−2modn)+1,(f3i−1modn)+1)=f3imod230(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.

 

 

Source

2018 Multi-University Training Contest 5

 

 

Recommend

chendu

 

 

Statistic | Submit | Discuss | Note

题意:有m次操作,每次在l到r这个区间中,让a[i]=max(a[i],v),最后得出每一位数字*i的异或和。

题解:每次告诉一个区间的最大值,最后让你求出每一个数字,其实可以考虑用一下ST表,其实是ST表的逆用,对于每一次区间的修改都变成ST表的查询操作,将这个区间分成两段,每一段都维护一下最大值v,最后再由大区间慢慢缩成小的区间,将每个区间分成两段,前半段维护和整个区间的最大值,后半段同样维护和整个区间的最大值,最后进行计算即可。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+7;
typedef pair<ll,ll> PII;

int lg[maxn];
unsigned int x,y,z;
unsigned int get_ans()
{
    ll w;
    x=x^(x<<11);
    x=x^(x>>4);
    x=x^(x<<5);
    x=x^(x>>14);
    w=x^(y^z);
    x=y;
    y=z;
    z=w;
    return z;
}

int dp[maxn][50];
void update(int &x,int y)
{
    x=max(x,y);
}

int main()
{
    for(int i=2;i<maxn;i++)
        lg[i]=lg[i>>1]+1;
    int T;
    scanf("%d",&T);
    while(T--)
    {
        ll n,m;
        cin>>n>>m>>x>>y>>z;

        for(int i=1;i<=m;i++)
        {
            int l=get_ans()%n+1;
            int r=get_ans()%n+1;
            int v=get_ans()&((1<<30)-1);
            if(l>r) swap(l,r);
            int d=lg[r-l+1];
            update(dp[l][d],v);
            update(dp[r-(1<<d)+1][d],v);
        }
        for(int i=lg[n];i>0;i--)
            for(int j=1;j+(1<<i)-1<=n;j++)
            {
                update(dp[j][i-1],dp[j][i]);
                update(dp[j+(1<<i-1)][i-1],dp[j][i]);
                dp[j][i]=0;
            }
        ll ans=0;
        for(ll i=1;i<=n;i++)
        {
            ans=ans^(i*dp[i][0]);
            dp[i][0]=0;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我来给你简单介绍一下使用glfw glad绘制三维场景的步骤。 1. 安装glfw glad 首先,你需要在你的项目中安装glfw glad。你可以使用包管理器如apt、brew或者conda,也可以手动下载和编译glfw glad的源代码。 2. 初始化glfw 在你的代码中,你需要在使用glfw之前初始化它。这可以通过调用glfwInit()函数来完成。 ``` if (!glfwInit()) { // 初始化失败 return -1; } ``` 3. 创建窗口 接下来,你需要创建一个窗口来绘制你的3D场景。你可以使用glfwCreateWindow()函数来创建一个窗口。 ``` GLFWwindow* window = glfwCreateWindow(800, 600, "My Window", NULL, NULL); if (!window) { glfwTerminate(); return -1; } ``` 4. 设置上下文 在创建窗口之后,你需要设置OpenGL上下文。这可以通过调用glfwMakeContextCurrent()函数来完成。 ``` glfwMakeContextCurrent(window); ``` 5. 加载glad 在设置上下文之后,你需要加载glad。这可以通过调用gladLoadGLLoader()函数来完成。 ``` if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { // glad加载失败 return -1; } ``` 6. 绘制三维场景 现在,你已经准备好绘制你的3D场景了。你可以使用OpenGL的函数来创建和渲染场景。这里只是简单的介绍一下,具体的实现取决于你的需求。 7. 交换缓冲区 当你完成了绘制场景之后,你需要交换缓冲区来显示你的场景。这可以通过调用glfwSwapBuffers()函数来完成。 ``` glfwSwapBuffers(window); ``` 8. 处理输入事件 最后,你需要处理输入事件。这可以通过调用glfwPollEvents()函数来完成。 ``` glfwPollEvents(); ``` 以上就是使用glfw glad绘制三维场景的简单步骤。希望能对你有所帮助。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值