题目大意:
  有$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. postman导出excel出现response

    https://jingyan.baidu.com/article/915fc414559b4351394b2084.html

  2. freemaker示例

    第一步  创建一个User.java文件 来两个变量 public class User {      private String userName;       private String us ...

  3. 孤荷凌寒自学python第三十六天文件内容的迭代操作

     孤荷凌寒自学python第三十六天python的文件操作对文件内容的迭代操作 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 一.os模块的其它文件操作方法补充 1 os.remove(文件 ...

  4. AppCan试用体验

    最近自己想开发一个基于Android平台的小应用,但不想使用JAVA开发,还要快速实现功能,学习成本低. 所以找了很多框架,最后基本锁定在phoneGap和AppCan,又看了AppCan与phone ...

  5. 巧用Fiddler代理来禁止资源缓存,从而达到每次都是从服务器加载最新的资源

    Fiddler ->  Rules ->  Performance  -> Disable Caching 直接设置禁用缓存,再在没有清除缓存功能的APP 中重新加载最新的页面, 每 ...

  6. update-database -script

    update-database -script 更新脚本生成失败? 项目选择的不对 update后面-database空格-script

  7. js文字跳动效果

    /*! * chaffle v1.0.0 * * Licensed under MIT * Copyright 2013-2014 blivesta * http://blivesta.com */ ...

  8. P3141 [USACO16FEB]围栏Fenced In_Platinum

    题目描述 Farmer John has realized that many of his cows are strangely agoraphobic (being fearful of larg ...

  9. 如何在CentOS7上改变网络接口名

    如何在CentOS7上改变网络接口名 传统上,Linux的网络接口被枚举为eth[0123...],但这些名称并不一定符合实际的硬件插槽,PCI位置,USB接口数量等,这引入了一个不可预知的命名问题( ...

  10. gulp技巧总结

    1. gulp.dest 会自动创建目录 gulp.dest(dir),若dir不存在,gulp会自动创建它 2. gulp.src copy具名路径(即不子目录**的路径)的文件,不会保留文件夹路径 ...