题目链接:Codeforces 482B Interesting Array

题目大意:给定一个长度为N的数组,如今有M个限制,每一个限制有l,r,q,表示从a[l]~a[r]取且后的数一定为q,问是

否有满足的数列。

解题思路:线段树维护。每条限制等于是对l~r之间的数或上q(取且的性质,对应二进制位一定为1)。那么处理全然部的

限制。在进行查询。查询相应每一个l~r之间的数取且是否还等于q。所以用线段树维护取且和。改动为或操作。

#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; const int maxn = 1e5 + 5;
const int INF = (1<<30)-1;
#define lson(x) ((x)<<1)
#define rson(x) (((x)<<1)|1)
int lc[maxn << 2], rc[maxn << 2], set[maxn << 2], val[maxn << 2]; inline void maintain (int u, int w) {
val[u] |= w;
set[u] |= w;
} inline void pushup(int u) {
val[u] = val[lson(u)] & val[rson(u)];
} inline void pushdown(int u) {
if (set[u]) {
maintain(lson(u), set[u]);
maintain(rson(u), set[u]);
set[u] = 0;
}
} void build (int u, int l, int r) {
lc[u] = l;
rc[u] = r;
set[u] = val[u] = 0; if (l == r)
return; int mid = (lc[u] + rc[u]) >> 1;
build(lson(u), l, mid);
build(rson(u), mid + 1, r);
pushup(u);
} void modify(int u, int l, int r, int w) {
if (l <= lc[u] && rc[u] <= r) {
maintain(u, w);
return;
} pushdown(u);
int mid = (lc[u] + rc[u]) >> 1;
if (l <= mid)
modify(lson(u), l, r, w);
if (r > mid)
modify(rson(u), l, r, w);
pushup(u);
} int query(int u, int l, int r) {
if (l <= lc[u] && rc[u] <= r)
return val[u]; pushdown(u);
int mid = (lc[u] + rc[u]) >> 1, ret = INF;
if (l <= mid)
ret &= query(lson(u), l, r);
if (r > mid)
ret &= query(rson(u), l, r);
pushup(u);
return ret;
} int N, M, L[maxn], R[maxn], Q[maxn]; bool judge() {
for (int i = 0; i < M; i++)
if (query(1, L[i], R[i]) != Q[i])
return true; printf("YES\n");
for (int i = 1; i <= N; i++)
printf("%d%c", query(1, i, i), i == N ? '\n' : ' ');
return false;
} int main () {
scanf("%d%d", &N, &M);
build(1, 1, N);
for (int i = 0; i < M; i++) {
scanf("%d%d%d", &L[i], &R[i], &Q[i]);
modify(1, L[i], R[i], Q[i]);
}
if (judge())
printf("NO\n");
return 0;
}

Codeforces 482B Interesting Array(线段树)的更多相关文章

  1. codeforces 482B. Interesting Array【线段树区间更新】

    题目:codeforces 482B. Interesting Array 题意:给你一个值n和m中操作,每种操作就是三个数 l ,r,val. 就是区间l---r上的与的值为val,最后问你原来的数 ...

  2. Codeforces 482B Interesting Array(线段树区间更新)

    题目链接 Interesting Array 区间更新.然后对于每一个约数重新求一遍区间的&值,不符合就跳出. #include <bits/stdc++.h> using nam ...

  3. Codeforces Round #275 Div.1 B Interesting Array --线段树

    题意: 构造一个序列,满足m个形如:[l,r,c] 的条件. [l,r,c]表示[l,r]中的元素按位与(&)的和为c. 解法: 线段树维护,sum[rt]表示要满足到现在为止的条件时该子树的 ...

  4. Codeforces 482B Interesting Array

    题意:构造一个长度为n的序列,使其满足m个形式如下如下约束:a[l]&a[l+1]&a[l+2]&....&a[r]=q 从Dalao的博客上看到这题,决定去水水.做法 ...

  5. [Codeforces 266E]More Queries to Array...(线段树+二项式定理)

    [Codeforces 266E]More Queries to Array...(线段树+二项式定理) 题面 维护一个长度为\(n\)的序列\(a\),\(m\)个操作 区间赋值为\(x\) 查询\ ...

  6. Buses and People CodeForces 160E 三维偏序+线段树

    Buses and People CodeForces 160E 三维偏序+线段树 题意 给定 N 个三元组 (a,b,c),现有 M 个询问,每个询问给定一个三元组 (a',b',c'),求满足 a ...

  7. CodeForces 877E DFS序+线段树

    CodeForces 877E DFS序+线段树 题意 就是树上有n个点,然后每个点都有一盏灯,给出初始的状态,1表示亮,0表示不亮,然后有两种操作,第一种是get x,表示你需要输出x的子树和x本身 ...

  8. [Codeforces 1197E]Culture Code(线段树优化建图+DAG上最短路)

    [Codeforces 1197E]Culture Code(线段树优化建图+DAG上最短路) 题面 有n个空心物品,每个物品有外部体积\(out_i\)和内部体积\(in_i\),如果\(in_i& ...

  9. [Codeforces 1199D]Welfare State(线段树)

    [Codeforces 1199D]Welfare State(线段树) 题面 给出一个长度为n的序列,有q次操作,操作有2种 1.单点修改,把\(a_x\)修改成y 2.区间修改,把序列中值< ...

随机推荐

  1. shell脚本书写总结

    1.shell脚本,如果重定向到文件中,则在脚本中不可以sed -i,如果用了sed -i ,则自打用了sed -i之后的打印都不能再重定向到输出文件了. 2.shell脚本中,如果将命令写在字符串里 ...

  2. UISearchBar 点击X 按钮收键盘

    - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText;{ NSLog(@"textD ...

  3. DataReader、Table、DataSet和Entity相互转化

    public class CommonService { #region DataReader转化 /// <summary> /// 将DataReader转化为Table /// &l ...

  4. STL中的set集合容器进行集合运算:并、交、差实例

    集合容器的集合运算:并.交.差: #include "stdafx.h" #include <iostream> #include <set> #inclu ...

  5. ios应用view之间数据传递的方式

    对于不同的viewcontroller之间数据的共享和处理 采用代理的方式,子viewcontroller设计代理协议,并定义协议接口,父viewcontroller实现协议接口,实现子视图控制器退出 ...

  6. QUdpSocket Class

    翻译自:QT官网文档QUdpSocket类 QUdpSocket类提供一个UDP套接字. Header: #include <QUdpSocket> qmake: QT += networ ...

  7. jquery方法详解

    jquery方法详解 http://www.365mini.com/doc

  8. F - The Circumference of the Circle

    Description To calculate the circumference of a circle seems to be an easy task - provided you know ...

  9. SQL in Qt (一)

    Connecting to Databases To access a database with QSqlQuery or QSqlQueryModel, create and open one o ...

  10. windows查询端口

    依次点击“开始→运行”,键入“cmd”并回车,打开命令提示符窗口.在命令提示符状态下键入“netstat -an”,按下回车键后就可以看到以数字形式显示的TCP和UDP连接的端口号及状态.