码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 6186 CS Course【前后缀位运算枚举/线段树】

时间:2018-08-24 00:33:46      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:eric   去掉   iostream   分析   long   stack   类型   lib   ble   

【前后缀枚举】

#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define debug() puts("++++")
#define gcd(a,b) __gcd(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a,b,sizeof(a))
#define be begin()
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
#define all 1,n,1
#define mod 998244353

#define pi acos(-1.0)
#define rep(i,x,n) for(int i=(x); i<(n); i++)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
const int INF = 1<<30;
const int maxn = 150000+3;
const double eps = 1e-8;
const int dx[] = {-1,1,0,0,1,1,-1,-1};
const int dy[] = {0,0,1,-1,1,-1,1,-1};
int dir[2]={-1,1};
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int t,n,m,d;
int a[maxn];
//& | ^
int px[maxn],py[maxn],pz[maxn];
int sx[maxn],sy[maxn],sz[maxn];
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        px[1]=py[1]=pz[1]=a[1];
        for(int i=2;i<=n;i++)
        {
            px[i]=px[i-1]&a[i];
            py[i]=py[i-1]|a[i];
            pz[i]=pz[i-1]^a[i];
        }
        sx[n]=sy[n]=sz[n]=a[n];
        for(int i=n-1;i>=1;i--)
        {
            sx[i]=sx[i+1]&a[i];
            sy[i]=sy[i+1]|a[i];
            sz[i]=sz[i+1]^a[i];
        }
        while(m--)
        {
            scanf("%d",&d);
            if(d==1)
                printf("%d %d %d\n",sx[2],sy[2],sz[2]);
            else if(d==n)
                printf("%d %d %d\n",px[n-1],py[n-1],pz[n-1]);
            else printf("%d %d %d\n",px[d-1]&sx[d+1],py[d-1]|sy[d+1],pz[d-1]^sz[d+1]);
        }
    }
}
/*
【题意】去掉给你的一个数d后的其他数的&、|、^

【类型】前缀+后缀去掉枚举的那个数,注意边界

【分析】女生赛有道去掉一个数求剩下数的GCD(换汤不换药

【时间复杂度&&优化】O(n)

【trick】

【数据】
*/

HDU 6186 CS Course【前后缀位运算枚举/线段树】

标签:eric   去掉   iostream   分析   long   stack   类型   lib   ble   

原文地址:https://www.cnblogs.com/Roni-i/p/9527161.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!