题目大意:
  有$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. CSU-2110 Keeping Cool

    题目链接 http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2110 题目 Description Kevin has just got ...

  2. Charts & canvas & RGBA

    Charts & canvas RGBA color let stopFlag = 0; // show Charts const showCharts = (name = "&qu ...

  3. 多线程 线程组 ThreadGroup

    package org.zln.thread; import java.util.Date; /** * Created by sherry on 000024/6/24 22:30. */ publ ...

  4. P2294 [HNOI2005]狡猾的商人

    题目描述 输入输出格式 输入格式: 从文件input.txt中读入数据,文件第一行为一个正整数w,其中w < 100,表示有w组数据,即w个账本,需要你判断.每组数据的第一行为两个正整数n和m, ...

  5. [poj] 3068 "Shortest" pair of paths || 最小费用最大流

    [原题](http://poj.org/problem?id=3068) 给一个有向带权图,求两条从0-N-1的路径,使它们没有公共点且边权和最小 . //是不是像传纸条啊- 是否可行只要判断最后最大 ...

  6. 疫情控制 blockade

    疫情控制 blockad 题目描述 H 国有 n 个城市,这 n 个城市用 n-1 条双向道路相互连通构成一棵树, 1 号城市是首都, 也是树中的根节点. H 国的首都爆发了一种危害性极高的传染病.当 ...

  7. 【BZOJ 5000 OI树】

    Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 107  Solved: 64[Submit][Status][Discuss] Description ...

  8. svn merge详解

    svn merge详解 [OK] http://blog.163.com/lgh_2002/blog/static/4401752620106202710487/ Subversion的分支通常用于在 ...

  9. SCP 命令(自己总结)

    \ svn 删除所有的 .svn文件 find . -name .svn -type d -exec rm -fr {} \; linux之cp/scp命令+scp命令详解   名称:cp 使用权限: ...

  10. UVA 10940 Throwing cards away II

    题意略: 先暴力打表发现规律 N=1 ans=1N=2 ans=2N=3 ans=2N=4 ans=4N=5 ans=2N=6 ans=4N=7 ans=6N=8 ans=8N=9 ans=2N=10 ...