题目大意:
  有$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. 2.0 python+appium环境搭建

    Python下载地址:链接:https://pan.baidu.com/s/1Z3H8tw8AiBVwpxdcABC7XQ 密码:z66t Pycharm下载地址: 链接:https://pan.ba ...

  2. about 2018

    2018想要完成的10件事情 1 活出更纯粹的自己.                                                      未完成2 自考本科一定要过.       ...

  3. 孤荷凌寒自学python第四天 安装python的其它IDE环境

    孤荷凌寒自学python第四天 安装python的其它IDE环境 (完整学习过程屏幕记录视频地址在文末) 因为是完全的新手,对python环境搭建完全一无所知,因此,可真是大费周章才配置了其它多个Id ...

  4. leetcode_day02

    任务二:删除排序数组中的重复项 原文链接:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/ 最开始的解决思路: ...

  5. PHP面向对象关键词static 、self

    知识点: 一.static可以修饰类内的属性或方法,被修饰的属性或方法在类外部,不能被实例化成对象访问,而是使用类本身进行访问,而静态的方法如果想使用静态的属性,则需要用self::这样的写法来访问静 ...

  6. pub/sub的实际应用总结

    pub/sub即观察者模式,有多重表现形式 1. Publisher/Subscriber2. Observer/Observable3. Listener(例如EventListener)4. Ev ...

  7. struts2的ajax支持

    struts2支持一种stream类型的Result,这种类型的Result可以直接向客户端浏览器响应二进制,文本等, 我们可以再action里面生成文本响应,然后在客户端页面动态加载该响应即可. 直 ...

  8. poj 3311 floyd+dfs或状态压缩dp 两种方法

    Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6436   Accepted: 3470 ...

  9. 内部类(inner class)的简单介绍

    本文主要介绍内部类(inner class)的一些基本应用,将从内部类的分类角度,首先对每一个具体内部类进行介绍.主要包括普通的内部类[common inner class].局部内部类[local ...

  10. box-pack

    box-pack表示父容器里面子容器的水平对齐方式,可选参数如下所示: start | end | center | justify <article class="wrap" ...