2018杭电多校 第五场 1007补题 线段树

少壮不努力,自挂线段树。

被打的自闭成环了,唉。

 

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6356

AC(跑的死慢的)代码

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define lson l, mid, pos<<1
#define rson mid+1,r,pos<<1|1
using namespace std;
const int maxn = 1e5+10;
long long f[3], lim;
long long pos[maxn<<2], mi[maxn<<2], mx[maxn<<2], lazy[maxn<<2];
long long sum;
int n,m;
long long li,ri,vi;
unsigned int x, y, z, w;
unsigned int rng(){
    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;
}

void pushdown(int pos){
    if (lazy[pos]==0)
        return ;
    lazy[pos<<1]=lazy[pos<<1|1]=mx[pos<<1]=mx[pos<<1|1]=mi[pos<<1]=mi[pos<<1|1]=lazy[pos];
    lazy[pos]=0;
    return ;
}
void init(int l, int r, int pos){
    mx[pos]=mi[pos]=lazy[pos]=0;
    if (l==r){
        return ;
    }
    int mid = (l+r)>>1;
    init(lson); init(rson);
    return ;
}

void change(int l, int r, int pos, int L, int R){
    if (mi[pos]>=vi){
        return ;
    }
    if (l>R || r<L){
        return ;
    }
    if (l>=L&&r<=R){
        if (mx[pos]<vi){
            mx[pos]=mi[pos]=lazy[pos]=vi;
            return ;
        }
        int mid = (l+r)>>1;
        change(lson,L,R);   change(rson,L,R);
        mx[pos]=max(mx[pos<<1],mx[pos<<1|1]);   mi[pos]=min(mi[pos<<1],mi[pos<<1|1]);
        return ;
    }
    pushdown(pos);
    int mid = (l+r)>>1;
    change(lson,L,R);   change(rson,L,R);
    mx[pos]=max(mx[pos<<1],mx[pos<<1|1]);   mi[pos]=min(mi[pos<<1],mi[pos<<1|1]);
    return ;
}


void update(int l, int r, int pos){
    if (mx[pos]==mi[pos]){
        for (int i=l;i<=r;++i){
            sum=sum^(i*mx[pos]);
        }
        return ;
    }
    pushdown(pos);
    int mid = (l+r)>>1;
    update(lson);   update(rson);
    return ;}

void read(){
    scanf("%d%d%u%u%u",&n,&m,&x,&y,&z);
    init(1,n,1);
    for (int i=0;i<m;++i){
        for (int j=0;j<3;++j){
            f[j]=(long long )rng();
        }
        li=min(f[0]%n+1,f[1]%n+1);  ri=max(f[0]%n+1,f[1]%n+1);
        vi=f[2]%lim;
        change(1,n,1,li,ri);
    }
    return ;
}

void solve(){
    sum=0;
    update(1,n,1);
    printf("%lld\n",sum);
    return ;
}

int main(){
    //freopen("in.txt","r",stdin);
    lim=1<<30;
    int T;
    scanf("%d",&T);
    while(T--){
        read();
        solve();
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值