其他分享
首页 > 其他分享> > 9.25模拟赛

9.25模拟赛

作者:互联网

 

 1 #include<bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 const int N=2e6+11,M=61,L=(1<<13)+11,St=(1<<13);
 5 int n,a[M];
 6 int tot,fr[N],to[N],g[L][L];
 7 ll dp[2][N];
 8  
 9 inline int re_ad() {
10     char ch=getchar(); int x=0,f=1;
11     while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
12     while('0'<=ch && ch<='9') x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
13     return x*f;
14 }
15  
16 int main()
17 {
18     n=re_ad();
19     for(int i=1;i<=n;++i) a[i]=re_ad();
20     for(int i=0;i<St;++i) {
21         int ii=i^(St-1);
22         for(int j=ii;j;j=(j-1)&ii) g[j][i]=++tot,fr[tot]=i,to[tot]=j;
23         g[0][i]=++tot,fr[tot]=i,to[tot]=0;
24     }
25 //    printf("%d\n",tot);
26 //    for(int i=1;i<=20;++i) printf("%d %d\n",fr[i],to[i]);
27     dp[0][g[0][0]]=1;
28 //    printf("g[0][0]: %d\n",g[0][0]);
29     for(int i=1;i<=n;++i) {
30         int t=(i&1)^1;
31         for(int j=1;j<=tot;++j) dp[t^1][j]=dp[t][j];
32         for(int j=1;j<=tot;++j) {
33             if(!dp[t][j]) continue;
34 //            printf("%d %d: %d %d\n",i,j,fr[j]|to[j],to[j]);
35             int x=fr[j]|to[j],y=fr[j];
36             x|=a[i],y^=a[i];
37             dp[t^1][g[x^y][y]]+=dp[t][j];
38         }
39     }
40     ll ans=0;
41     for(int i=1;i<=tot;++i) if(!to[i] && fr[i]) ans+=dp[n&1][i];
42     printf("%lld\n",ans);
43     return 0;
44 }

 

 

 

 

 

 

 

 

 

 

 

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N=3e5+11,M=61,St=50;
 4 int n,m,a[N];
 5 
 6 inline int re_ad() {
 7     char ch=getchar(); int x=0,f=1;
 8     while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
 9     while('0'<=ch && ch<='9') x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
10     return x*f;
11 }
12 
13 struct Node {
14     int len,val[M];
15     Node Init() { len=0; for(int i=1;i<=St;++i) val[i]=0; }
16     Node operator + (const Node &B) const {
17         int d1=1,d2=1;
18         Node res; res.len=len+B.len;
19         for(int i=1;i<=St;++i) {
20             if(d1>len && d2>B.len) return res;
21             if(d1>len) res.val[i]=B.val[d2++];
22             else if(d2>B.len) res.val[i]=val[d1++];
23             else if(val[d1]>B.val[d2]) res.val[i]=val[d1++];
24             else res.val[i]=B.val[d2++];
25         }
26         return res;
27     }
28 };
29 
30 namespace ST {
31     Node t[N];
32     inline void Pushup(int d) {
33         t[d]=t[d<<1]+t[d<<1|1];
34     }
35     void build(int d,int l,int r) {
36         t[d].Init(); t[d].len=r-l+1;
37         if(l==r) { t[d].val[1]=a[l]; return ; }
38         int mid=(l+r)>>1;
39         build(d<<1,l,mid);
40         build(d<<1|1,mid+1,r);
41         Pushup(d);
42     }
43     inline void Build() { build(1,1,n); }
44     void modify(int d,int l,int r,int x,int z) {
45         if(l==r) { t[d].val[1]=z; return ; }
46         int mid=(l+r)>>1;
47         (x<=mid)?modify(d<<1,l,mid,x,z):modify(d<<1|1,mid+1,r,x,z);
48         Pushup(d);
49     }
50     inline void Modify(int x,int z) { modify(1,1,n,x,z); }
51     Node query(int d,int l,int r,int x,int y) {
52         Node res; res.Init();
53         if(x>y || l>r) return res;
54         if(x<=l && r<=y) return t[d];
55         int mid=(l+r)>>1;
56         if(x<=mid) res=res+query(d<<1,l,mid,x,y);
57         if(y>=mid+1) res=res+query(d<<1|1,mid+1,r,x,y);
58         return res;
59     }
60     inline void Query(int x,int y) {
61         Node tmp=query(1,1,n,x,y);
62 //        printf("query: %d %d: %d: %d %d %d %d %d\n",x,y,tmp.len,tmp.val[1],tmp.val[2],tmp.val[3],tmp.val[4],tmp.val[5]);
63         if(tmp.len<3) { printf("0\n"); return ; }
64         for(int i=1;i<=tmp.len-2;++i) if(tmp.val[i]<tmp.val[i+1]+tmp.val[i+2])
65             { printf("%d\n",tmp.val[i]+tmp.val[i+1]+tmp.val[i+2]); return ; }
66         printf("0\n");
67     }
68 /*
69     void print_search(int d,int l,int r) {
70         printf("%d %d %d: %d: %d %d %d %d %d\n",d,l,r,t[d].len,t[d].val[1],t[d].val[2],t[d].val[3],t[d].val[4],t[d].val[5]);
71         if(l==r) return ;
72         int mid=(l+r)>>1;
73         print_search(d<<1,l,mid),print_search(d<<1|1,mid+1,r);
74     }
75     inline void Print_Test() {
76         print_search(1,1,n);
77     }
78 */
79 }
80 
81 int main()
82 {
83     n=re_ad(),m=re_ad();
84     for(int i=1;i<=n;++i) a[i]=re_ad();
85     ST::Build();
86 //    ST::Print_Test();
87     for(int i=1,op,x,y;i<=m;++i) {
88         op=re_ad(),x=re_ad(),y=re_ad();
89 //        if(op==2) ST::Query(x,y);
90         op==1 ? ST::Modify(x,y) : ST::Query(x,y);
91 //        ST::Print_Test();
92     }
93     return 0;
94 }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 1 //std
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include<iostream>
 5 #include <cstring>
 6 using namespace std;
 7 const int MAX_N = 1000005, S = (1 << 20) - 1;
 8 class Edge
 9 {
10 public:
11     int nxt, to;
12 } e[MAX_N << 1];
13 int head[MAX_N], cnt;
14 void addedge(int u, int v)
15 {
16     e[++cnt] = (Edge){head[u], v}, head[u] = cnt;
17     e[++cnt] = (Edge){head[v], u}, head[v] = cnt;
18 }
19 int N, dep[MAX_N], f[1 << 20];
20 void dfs(int u, int v)
21 {
22     dep[u] = dep[v] + 1;
23     for (int i = head[u]; i; i = e[i].nxt)
24     if (e[i].to != v)
25         dfs(e[i].to, u);
26 }
27 int val[MAX_N];
28 int main() 
29 {
30 freopen("tree.in","r",stdin);
31 freopen("tree.out","w",stdout);
32     scanf("%d", &N);
33     
34     for (int i = 1; i <= N; ++i)
35     scanf("%d", &val[i]);
36     for (int i = 1, u, v; i < N; ++i) 
37     {
38     scanf("%d%d", &u, &v);
39     addedge(u, v);
40     }
41     dfs(1, 0);
42     
43     for (int i = 1; i <= N; ++i) f[dep[i] - 1] ^= val[i];
44 
45 
46     
47     for (int i = 0; i < 20; ++i)
48     for (int j = 0; j <= S; ++j)
49         if ((j >> i) & 1)
50         f[j] ^= f[j ^ (1 << i)];
51 
52 
53     
54     for (int i = 0; i < N; ++i)
55     printf("%d ", f[i ^ S]);
56     puts("");
57     return 0;
58 }

标签:ch,9.25,val,int,res,include,d2,模拟
来源: https://www.cnblogs.com/shangguanshufang/p/9_25_mo_ni_sai.html