zoukankan      html  css  js  c++  java
  • Codeforces Round #626 Div. 2 D. Present(二分 状态压缩)

    https://codeforces.com/contest/1323/problem/D

     上个题解....

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 const int maxn = 4e5+5;
     5 int a[maxn],b[maxn];
     6 int n; 
     7 int main(){
     8     scanf("%d",&n);
     9     int ans = 0;
    10     for(int i = 1;i<=n;i++) scanf("%d",&a[i]);
    11     for(int i = 0;i<25;i++){ //最多25位 
    12         for(int j = 1;j<=n;j++) b[j] = a[j]%(1<<(i+1));
    13         sort(b+1,b+1+n);
    14         for(int j = 1;j<=n;j++){
    15             int l = max(0,(1<<i)-b[j]);//第一段区间的左端点 
    16             int r = ( (1<<(i+1) ) - 1) - b[j] ;//第一段区间的右端点 
    17             int range = upper_bound(b+1,b+j,r)-lower_bound(b+1,b+j,l);
    18             if(range&1) ans^=(1<<i);
    19             l = max(0,( (1<<(i+1)) +(1<<i)-b[j] ) );//第二段区间的左端点 
    20             r = ( (1<<(i+2)) -1)-b[j];//第二段区间的右端点 
    21             range = upper_bound(b+1,b+j,r)-lower_bound(b+1,b+j,l);
    22             if(range&1) ans^=(1<<i); 
    23             //用二分求出区间长度range 
    24         } 
    25     }
    26     printf("%d",ans);
    27     return 0;
    28 }
    View Code
  • 相关阅读:
    AFO
    【WC2016】鏖战表达式
    CF 构造
    noi2020 补题
    min_25筛
    退役公告
    arthas使用
    Python 分布式缓存之Reids数据类型操作详解
    python安装读取grib库总结(推荐)
    使用python修改文件并立即写回到原始位置操作(inplace读写)
  • 原文地址:https://www.cnblogs.com/AaronChang/p/12445341.html
Copyright © 2011-2022 走看看