zoukankan      html  css  js  c++  java
  • HDU 6356.Glad You Came-线段树(区间更新+剪枝) (2018 Multi-University Training Contest 5 1007)

    6356.Glad You Came

    题意就是给你一个随机生成函数,然后从随机函数里确定查询的左右区间以及要更新的val值。然后最后求一下异或和就可以了。

    线段树,区间最大值和最小值维护一下,因为数据有点大,不剪枝就会超时。(默默吐槽,剪了枝照样超时)

    因为太菜,交了24遍也是没过,TLE,WA,RE轮流来,而且感觉这题有毒,删一个没用的变量就会WA。。。

    百度了一下题解,发现有人和我写的几乎一模一样,但是人家的就可以过,我的死也过不去。

    人家的博客:HDU6356 Glad You Came(线段树区间更新+剪枝)

    贴一下人家的代码:

      1 #include<bits/stdc++.h>
      2 using namespace std;
      3 typedef unsigned int ui;
      4 typedef long long ll;
      5 const int maxn = 1e5 + 5;
      6 const int maxm = 5e6 + 5;
      7 const ui mod = 1 << 30;
      8 ui x, y, z, w, f[3*maxm], Left[maxm], Right[maxm], v[maxm];
      9 ui fun()
     10 {
     11     x ^= (x << 11);
     12     x ^= (x >> 4);
     13     x ^= (x << 5);
     14     x ^= (x >> 14);
     15     w = x ^ (y ^ z);
     16     x = y;
     17     y = z;
     18     z = w;
     19     return z;
     20 }
     21 
     22 ll ans, a[maxn], maxa[maxn<<2], mina[maxn<<2], lazy[maxn<<2];
     23 #define lson l,m,rt<<1
     24 #define rson m+1,r,rt<<1|1
     25 #define getm int m = l + r >> 1
     26 void pushup(int rt)
     27 {
     28     mina[rt] = min(mina[rt<<1],mina[rt<<1|1]);
     29     maxa[rt] = max(maxa[rt<<1],maxa[rt<<1|1]);
     30 }
     31 
     32 void pushdown(int rt)
     33 {
     34     if(lazy[rt])
     35     {
     36         lazy[rt<<1] = lazy[rt<<1|1] = lazy[rt];
     37         maxa[rt<<1] = maxa[rt<<1|1] = lazy[rt];
     38         mina[rt<<1] = mina[rt<<1|1] = lazy[rt];
     39         lazy[rt] = 0;
     40     }
     41 }
     42 
     43 void update(ui L,ui R,ui val,int l,int r,int rt)
     44 {
     45     if(mina[rt] >= val) return ;//最小值都比v大,不用更新
     46     if(L <= l && r <= R)
     47     {
     48         if(maxa[rt] <= val)//最大值比v小,全部更新,打标记
     49         {
     50             maxa[rt] = val;
     51             lazy[rt] = val;
     52             return ;
     53         }
     54         //否则继续切分区间,向下更新
     55     }
     56 
     57     getm;
     58     pushdown(rt);
     59     if(L<=m)
     60         update(L,R,val,lson);
     61     if(R>m)
     62         update(L,R,val,rson);
     63     pushup(rt);
     64 }
     65 
     66 ll query(int pos,int l,int r,int rt)
     67 {
     68     if(l==r)
     69         return maxa[rt];
     70     getm;
     71     pushdown(rt);
     72     if(pos<=m)
     73         return query(pos,lson);
     74     else
     75         return query(pos,rson);
     76 }
     77 
     78 int T, N, M;
     79 int main()
     80 {
     81     scanf("%d",&T);
     82     while(T--)
     83     {
     84         memset(a,0,8*(N+1));
     85         memset(lazy,0,32*(N+1));
     86         memset(mina,0,32*(N+1));
     87         memset(maxa,0,32*(N+1));
     88         scanf("%d%d%u%u%u",&N,&M,&x,&y,&z);
     89         for(int i=1;i<=3*M;++i)
     90             f[i] = fun();
     91         for(int i=1;i<=M;++i)
     92         {
     93             Left[i] = min(f[3*i-2] % N, f[3*i-1] % N) + 1;
     94             Right[i] = max(f[3*i-2] % N, f[3*i-1] % N) + 1;
     95             v[i] = f[3*i] % mod;
     96             update(Left[i],Right[i],v[i],1,N,1);
     97         }
     98         ans = 0;
     99         for(int i=1;i<=N;++i)
    100             ans ^= ((ll)i * query(i,1,N,1));
    101         printf("%lld
    ",ans);
    102     }
    103     return 0;
    104 }

    最后贴一下我的死也没过去的代码,哪个大佬好心看一下,然后拯救一下我。。。

    我队友帮我调了也快20发了,依旧没过,哭死༼༎ຶᴗ༎ຶ༽

      1 //1007-6356-线段树
      2 #include<iostream>
      3 #include<cstdio>
      4 #include<cstring>
      5 #include<algorithm>
      6 #include<bitset>
      7 #include<cassert>
      8 #include<cctype>
      9 #include<cmath>
     10 #include<cstdlib>
     11 #include<ctime>
     12 #include<deque>
     13 #include<iomanip>
     14 #include<list>
     15 #include<map>
     16 #include<queue>
     17 #include<set>
     18 #include<stack>
     19 #include<vector>
     20 using namespace std;
     21 typedef unsigned int ui;
     22 typedef long long ll;
     23 const double PI=acos(-1.0);
     24 const double eps=1e-6;
     25 const int inf=0x3f3f3f3f;
     26 const int maxn=1e5+5;
     27 const int maxm=5e6+5;
     28 const ui mod=1<<30;
     29 #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     30 
     31 #define lson l,m,rt<<1
     32 #define rson m+1,r,rt<<1|1
     33 
     34 ll lazy[maxn<<2],MAX[maxn<<2],MIN[maxn<<2];
     35 ui x,y,z,w,f[maxm];
     36 
     37 void pushup(int rt)
     38 {
     39     MIN[rt]=min(MIN[rt<<1],MIN[rt<<1|1]);
     40     MAX[rt]=max(MAX[rt<<1],MAX[rt<<1|1]);
     41 }
     42 
     43 void pushdown(int rt)
     44 {
     45     if(lazy[rt]){
     46         lazy[rt<<1]=lazy[rt<<1|1]=lazy[rt];
     47         MAX[rt<<1]=MAX[rt<<1|1]=lazy[rt];
     48         MIN[rt<<1]=MIN[rt<<1|1]=lazy[rt];
     49         lazy[rt]=0;
     50     }
     51 }
     52 
     53 void build(int l,int r,int rt)
     54 {
     55     lazy[rt]=0;MAX[rt]=MIN[rt]=0;
     56     if(l==r){
     57         return ;
     58     }
     59 
     60     int m=(l+r)>>1;
     61     build(lson);
     62     build(rson);
     63 }
     64 
     65 void update(ui L,ui R,ui val,int l,int r,int rt)
     66 {
     67     if(MIN[rt]>=val) return ;
     68     if(L<=l&&r<=R){
     69         if(MAX[rt]<=val){
     70             MAX[rt]=val;
     71             lazy[rt]=val;
     72             return ;
     73         }
     74     }
     75 
     76     pushdown(rt);
     77     int m=(l+r)>>1;
     78     if(L<=m) update(L,R,val,lson);
     79     if(R> m) update(L,R,val,rson);
     80     pushup(rt);
     81 }
     82 
     83 ll query(int pos,int l,int r,int rt)
     84 {
     85     if(l==r){
     86         return MAX[rt];
     87     }
     88 
     89     pushdown(rt);
     90     int m=(l+r)>>1;
     91     if(pos<=m) return query(pos,lson);
     92     if(pos> m) return query(pos,rson);
     93 }
     94 
     95 ui RNG61()
     96 {
     97     x ^= (x << 11);
     98     x ^= (x >> 4);
     99     x ^= (x << 5);
    100     x ^= (x >> 14);
    101     w = x ^ (y^z);
    102     x = y;
    103     y = z;
    104     z = w;
    105     return z;
    106 }
    107 
    108 int t,n,m;
    109 
    110 int main()
    111 {
    112     scanf("%d",&t);
    113     while(t--){
    114         scanf("%d%d%u%u%u",&n,&m,&x,&y,&z);
    115         build(1,n,1);
    116         for(int i=1;i<=3*m;i++)
    117             f[i]=RNG61();
    118         for(int i=1;i<=m;i++){
    119             ui l=min(f[3*i-2]%n,f[3*i-1]%n)+1;
    120             ui r=max(f[3*i-2]%n,f[3*i-1]%n)+1;
    121             ui v=f[3*i]%mod;
    122             update(l,r,v,1,n,1);
    123         }
    124         ll ans=0;
    125         for(int i=1;i<=n;i++)
    126             ans^=(ll)i*query(i,1,n,1);
    127         printf("%lld
    ",ans);
    128     }
    129 }
    View Code

    滚了滚了,滚回垃圾桶了。

  • 相关阅读:
    打开Intellij Idea 2020.1 提示 cannot load a jdk class: com.sun.jdi.Field
    win10触摸板设置为连接鼠标不打开后就自动关闭
    git配置账号
    HTTP请求中的Form Data与Request Payload的区别
    VUE—axios自定义请求配置—3、transformRequest在向服务器发送前,修改请求数据(图文详情)
    在Sass中,我们可以使用“@for”来实现循环操作
    vue项目引入背景图报Module not found: Error: Can't resolve './src/assets/theme/logo_blue.png' in'xxx'错误
    Importing code style from ESLint
    ESLint fix自动修复所有格式问题
    【T07】不要低估tcp的性能
  • 原文地址:https://www.cnblogs.com/ZERO-/p/9489472.html
Copyright © 2011-2022 走看看