bzoj 3526 : [Poi2014]Card

  把每张卡牌看成两个点,裸的线段树维护连通性。

  

  1 #include<iostream>
  2 #include<cstdio>
  3 #include<cstring>
  4 #include<algorithm>
  5 #define ls x*2,l,mid
  6 #define rs x*2+1,mid+1,r
  7 #define N 200005
  8 using namespace std;
  9 int read()
 10 {
 11     char c=getchar();int p=0;
 12     while(c<‘0‘||c>‘9‘)c=getchar();
 13     while(c>=‘0‘&&c<=‘9‘)p=p*10+c-‘0‘,c=getchar();
 14     return p;
 15 }
 16 int n;
 17 int aa[N][2];
 18 struct node
 19 {
 20     int v[2][2];
 21 }a[N*4];
 22 void push_up(int x,int mid)
 23 {
 24     int lc=x*2,rc=x*2+1;
 25     a[x].v[0][0]=a[x].v[0][1]=a[x].v[1][0]=a[x].v[1][1]=0;
 26     if(aa[mid][0]<=aa[mid+1][0])
 27     {
 28         a[x].v[0][0]|=(a[lc].v[0][0]&a[rc].v[0][0]);
 29         a[x].v[0][1]|=(a[lc].v[0][0]&a[rc].v[0][1]);
 30         a[x].v[1][0]|=(a[lc].v[1][0]&a[rc].v[0][0]);
 31         a[x].v[1][1]|=(a[lc].v[1][0]&a[rc].v[0][1]);
 32     }
 33     else if(aa[mid][0]<=aa[mid+1][1])
 34     {
 35         a[x].v[0][0]|=(a[lc].v[0][0]&a[rc].v[1][0]);
 36         a[x].v[0][1]|=(a[lc].v[0][0]&a[rc].v[1][1]);
 37         a[x].v[1][0]|=(a[lc].v[1][0]&a[rc].v[1][0]);
 38         a[x].v[1][1]|=(a[lc].v[1][0]&a[rc].v[1][1]);
 39     }
 40     if(aa[mid][1]<=aa[mid+1][0])
 41     {
 42         a[x].v[0][0]|=(a[lc].v[0][1]&a[rc].v[0][0]);
 43         a[x].v[0][1]|=(a[lc].v[0][1]&a[rc].v[0][1]);
 44         a[x].v[1][0]|=(a[lc].v[1][1]&a[rc].v[0][0]);
 45         a[x].v[1][1]|=(a[lc].v[1][1]&a[rc].v[0][1]);
 46     }
 47     else if(aa[mid][1]<=aa[mid+1][1])
 48     {
 49         a[x].v[0][0]|=(a[lc].v[0][1]&a[rc].v[1][0]);
 50         a[x].v[0][1]|=(a[lc].v[0][1]&a[rc].v[1][1]);
 51         a[x].v[1][0]|=(a[lc].v[1][1]&a[rc].v[1][0]);
 52         a[x].v[1][1]|=(a[lc].v[1][1]&a[rc].v[1][1]);
 53     }
 54     return ;
 55 }
 56 void build(int x,int l,int r)
 57 {
 58     if(l==r)
 59     {
 60         a[x].v[0][1]=1;
 61         a[x].v[0][0]=a[x].v[1][1]=1;
 62         return ;
 63     }
 64     int mid=(l+r)>>1;
 65     build(ls);build(rs);
 66     push_up(x,mid);
 67 }
 68 void gai(int x,int l,int r,int pos)
 69 {
 70     if(l==r)return ;
 71     int mid=(l+r)>>1;
 72     if(pos<=mid)gai(ls,pos);
 73     else gai(rs,pos);
 74     push_up(x,mid);
 75 }
 76 int main()
 77 {
 78     scanf("%d",&n);
 79     for(int i=1;i<=n;i++)
 80     {
 81         aa[i][0]=read(),aa[i][1]=read();
 82         if(aa[i][0]>aa[i][1])swap(aa[i][0],aa[i][1]);
 83     }
 84     build(1,1,n);
 85     int m;
 86     scanf("%d",&m);int t1,t2;
 87     for(int i=1;i<=m;i++)
 88     {
 89         t1=read();t2=read();
 90         swap(aa[t1][0],aa[t2][0]);
 91         swap(aa[t1][1],aa[t2][1]);
 92         gai(1,1,n,t1);gai(1,1,n,t2);
 93         if(a[1].v[1][1]||a[1].v[1][0]||a[1].v[0][0]||a[1].v[0][1])
 94         {
 95             puts("TAK");
 96         }
 97         else puts("NIE");
 98     }
 99     return 0;
100 }
时间: 2024-08-02 23:49:23

bzoj 3526 : [Poi2014]Card的相关文章

【BZOJ3526】[Poi2014]Card 线段树

[BZOJ3526][Poi2014]Card Description 有n张卡片在桌上一字排开,每张卡片上有两个数,第i张卡片上,正面的数为a[i],反面的数为b[i].现在,有m个熊孩子来破坏你的卡片了!第i个熊孩子会交换c[i]和d[i]两个位置上的卡片.每个熊孩子捣乱后,你都需要判断,通过任意翻转卡片(把正面变为反面或把反面变成正面,但不能改变卡片的位置),能否让卡片正面上的数从左到右单调不降. Input 第一行一个n.接下来n行,每行两个数a[i],b[i].接下来一行一个m.接下来

BZOJ 3524: [Poi2014]Couriers

3524: [Poi2014]Couriers Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 1905  Solved: 691[Submit][Status][Discuss] Description 给一个长度为n的序列a.1≤a[i]≤n.m组询问,每次询问一个区间[l,r],是否存在一个数在[l,r]中出现的次数大于(r-l+1)/2.如果存在,输出这个数,否则输出0. Input 第一行两个数n,m.第二行n个数,a[i].接下来m行,

bzoj 3831: [Poi2014]Little Bird

3831: [Poi2014]Little Bird Description In the Byteotian Line Forest there are   trees in a row. On top of the first one, there is a little bird who would like to fly over to the top of the last tree. Being in fact very little, the bird might lack the

BZOJ 3524: [Poi2014]Couriers( 主席树 )

卡我空间.... 这道题应该是主席树入门题...无修改 , 离散化都不用...出题人业界良心啊 一开始的空白树我 build 出来结果就多了整整 2n 个 Node , 然后就 MLE 了... ( 双倍经验 , 另一道见上图 ) ---------------------------------------------------------------------------------------------- #include<cstdio> #include<cstring&g

bzoj 3832: [Poi2014]Rally(线段树+拓扑排序)

3832: [Poi2014]Rally Time Limit: 20 Sec  Memory Limit: 128 MBSec  Special Judge Submit: 113  Solved: 56 [Submit][Status][Discuss] Description An annual bicycle rally will soon begin in Byteburg. The bikers of Byteburg are natural long distance cyclis

【刷题】BZOJ 3832 [Poi2014]Rally

Description An annual bicycle rally will soon begin in Byteburg. The bikers of Byteburg are natural long distance cyclists. Local representatives of motorcyclists, long feuding the cyclists, have decided to sabotage the event. There are intersections

BZOJ 3827: [Poi2014]Around the world

Sol 并查集. 一个点所能到达的最远是单调不降的.然后将链延长到两倍,预处理出每个点到达的最远点,然后倒着计算深度. 再然后一直跳,跳到>=x+n的点,因为跳到的点都能到最终的点,并且不影响后面的答案. Code /************************************************************** Problem: 3827 User: BeiYu Language: C++ Result: Accepted Time:70156 ms Memory:

bzoj 3522: [Poi2014]Hotel

呵呵,一开始天真的我以为求个 西格玛 C(??,3)就好了.. (题解:比枚举2个数的再多一个,,一样搞) 1 #include <bits/stdc++.h> 2 #define LL long long 3 #define lowbit(x) x&(-x) 4 #define inf 1e15 5 using namespace std; 6 inline int ra() 7 { 8 int x=0,f=1; char ch=getchar(); 9 while (ch<'

BZOJ 3834 [Poi2014]Solar Panels 数学

题意: n组询问,每次问smin<=x<=smax, wmin<=y<=wmax时gcd(x, y)的最大值. 解析: md以前有个结论忘了结果这题坑我30分钟+ 我们显然可以找到一个结论. 令gcd(x,y)=z; 那么显然有(smin-1)/z #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace