题目大意:
  有$n(n\le2\times10^5)$张卡片排成一排,每张卡片正反面有两个数$a_i$和$b_i$。$m(m\le10^6)$次操作,每次交换第$c_i$和第$d_i$张卡片,问若可以任意翻转卡片,是否存在一种方案使得卡片上的数字构成一个不下降序列。

思路:
  用线段树维护区间,左端点取最大/小值时,右端点取最大值还是最小值。

 #include<cstdio>
#include<cctype>
#include<algorithm>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'';
while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
const int N=;
int a[N][];
class SegmentTree {
#define _left <<1
#define _right <<1|1
private:
int val[N<<][];
void push_up(const int &p,const int &b,const int &e) {
const int mid=(b+e)>>;
val[p][]=val[p][]=-;
if(val[p _left][]==-) return;
if(a[mid+][]>=a[mid][val[p _left][]]) val[p][]=val[p _right][];
if(a[mid+][]>=a[mid][val[p _left][]]) val[p][]=val[p _right][];
if(val[p _left][]==-) return;
if(a[mid+][]>=a[mid][val[p _left][]]) val[p][]=val[p _right][];
if(a[mid+][]>=a[mid][val[p _left][]]) val[p][]=val[p _right][];
}
public:
void build(const int &p,const int &b,const int &e) {
if(b==e) {
val[p][]=;
val[p][]=;
return;
}
const int mid=(b+e)>>;
build(p _left,b,mid);
build(p _right,mid+,e);
push_up(p,b,e);
}
void modify(const int &p,const int &b,const int &e,const int &x) {
if(b==e) return;
const int mid=(b+e)>>;
if(x<=mid) modify(p _left,b,mid,x);
if(x>mid) modify(p _right,mid+,e,x);
push_up(p,b,e);
}
bool query() const {
return val[][]!=-;
}
#undef _left
#undef _right
};
SegmentTree t;
int main() {
const int n=getint();
for(register int i=;i<=n;i++) {
a[i][]=getint(),a[i][]=getint();
if(a[i][]>a[i][]) std::swap(a[i][],a[i][]);
}
t.build(,,n);
for(register int m=getint();m;m--) {
const int x=getint(),y=getint();
std::swap(a[x][],a[y][]);
std::swap(a[x][],a[y][]);
t.modify(,,n,x);
t.modify(,,n,y);
puts(t.query()?"TAK":"NIE");
}
return ;
}

[POI2014]Cards的更多相关文章

  1. BZOJ 1004 【HNOI2008】 Cards

    题目链接:Cards 听说这道题是染色问题的入门题,于是就去学了一下\(Bunside\)引理和\(P\acute{o}lya\)定理(其实还是没有懂),回来写这道题. 由于题目中保证"任意 ...

  2. Codeforces Round #384 (Div. 2) 734E Vladik and cards

    E. Vladik and cards time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. BZOJ 3524: [Poi2014]Couriers [主席树]

    3524: [Poi2014]Couriers Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 1892  Solved: 683[Submit][St ...

  4. bzoj 1004 Cards

    1004: [HNOI2008]Cards Description 小春现在很清闲,面对书桌上的N张牌,他决定给每张染色,目前小春只有3种颜色:红色,蓝色,绿色.他询问Sun有 多少种染色方案,Sun ...

  5. codeforces 744C Hongcow Buys a Deck of Cards

    C. Hongcow Buys a Deck of Cards time limit per test 2 seconds memory limit per test 256 megabytes in ...

  6. BZOJ 3524: [Poi2014]Couriers

    3524: [Poi2014]Couriers Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 1905  Solved: 691[Submit][St ...

  7. CF 204B Little Elephant and Cards

    题目链接: 传送门 Little Elephant and Cards time limit per test:2 second     memory limit per test:256 megab ...

  8. HDU 1535 Invitation Cards(最短路 spfa)

    题目链接: 传送门 Invitation Cards Time Limit: 5000MS     Memory Limit: 32768 K Description In the age of te ...

  9. Codeforces Round #227 (Div. 2) E. George and Cards set内二分+树状数组

    E. George and Cards   George is a cat, so he loves playing very much. Vitaly put n cards in a row in ...

随机推荐

  1. save?commit

    数据库的隐式提交 先看一段SQL,最后一条SQL的输出你认为是什么? 1 2 3 4 5 6 7 SET AUTOCOMMIT = 1; BEGIN; INSERT INTO t1 VALUES (1 ...

  2. hp raid json

    hp机器均已在装OS之前划好raid,统一规格为2*480G SSD, 12*4T SATA ,2*1.6T SSD,其中2*480G SSD做系统盘,划分raid1 已知disk controlle ...

  3. 【视觉SLAM14讲】ch4心得与课后题答案【仅供参考】

    答案: Q1:验证SO(3) SE(3) Sim(3)关于乘法成群 SO(3) : 由P64最开始可知,乘法代表了旋转,而SO(3)是旋转矩阵的集合, SE(3)  Sim(3)  同理(最基础的部分 ...

  4. Leetcode 665.非递减数列

    非递减数列 给定一个长度为 n 的整数数组,你的任务是判断在最多改变 1 个元素的情况下,该数组能否变成一个非递减数列. 我们是这样定义一个非递减数列的: 对于数组中所有的 i (1 <= i ...

  5. springmvc maven搭建二之springmvc的security

    上一篇文档初步搭建了一个springmvc的web工程,现在要来实现第二步咯.将登录校验整合到项目中,我用的是spring 3.0.2的版本,所以这里的登录用了security来处理.不多说,上代码. ...

  6. 【距离GDOI:128天】【POJ2778】DNA Sequence(AC自动机+矩阵加速)

    已经128天了?怎么觉得上次倒计时150天的日子还很近啊 ....好吧为了把AC自动机搞透我也是蛮拼的..把1030和这道题对比了无数遍...最终结论是...无视时间复杂度,1030可以用这种写法解. ...

  7. 接水果(fruit)

    接水果(fruit) 风见幽香非常喜欢玩一个叫做 osu! 的游戏,其中她最喜欢玩的模式就是接水果.由于她已经 DT FC 了 The big black,她觉得这个游戏太简单了,于是发明了一个更加难 ...

  8. python下载链接内容

    下面代码下载京东注册码,可接收参数num dir 可以将连接构造成其它网址,比如移动联通网上营业厅的验证码都是固定网址+13位时间戳的结构. #!/usr/bin/python #code utf-8 ...

  9. .ini配置读取

    ini文件的格式 格式 INI文件由节.键.值组成. 节 [section] 参数(键=值) name=value 注解 注解使用分号表示(;).在分号后面的文字,直到该行结尾都全部为注解.     ...

  10. 【ZOJ4062】Plants vs. Zombies(二分)

    题意:有n个植物排成一排,标号为1-n,每株植物有自己的生长速度ai,每对植物浇一次水,该株植物就长高ai, 现在机器人从第0个格子出发,每次走一步,不能停留,每一步浇一次水,总共可以走m步,问最矮的 ...