Bzoj 3223 & Zone flipping

Source: Internet
Author: User

Test instructions

is to put a code, this is my introductory question of the weakening version. However, a total of 40 minutes to write, not focus (while watching the game while playing) is a problem, splay each operation of the details is indeed a bit more (when Updata ah. When Pushdown ah. Order AH). or focus on a bit as far as possible to write, tune code too torture.

CODE:

/*==========================================================================# last modified:2016-02-21 19:13# filename:bz3223.cpp# Description: ==========================================================================*/# Define me Acrossthesky #include <cstdio> #include <cmath> #include <ctime> #include <string> #inc (in)  Lude <cstring> #include <cstdlib> #include <iostream> #include <algorithm> #include <set> #include <map> #include <stack> #include <queue> #include <vector> #define LOWBIT (x) (x) & (-X ) #define for (I,A,B) for ((i) = (a);(i) <= (b);(i) + +) #define FORP (I,A,B) for (int i= (a); i<= (b); i++) #define FORM (i,a,b ) for (int i= (a); i>= (b); i--) #define LS (A, a) (((a) + (b)) << 1) #define RS (A, B) (((a) + (c)) >> 1) #define GETLC (a) ch[(a)][0] #define GETRC (a) ch[(a)][1] #define MAXN 200000 #define MAXM 100000 #define PI 3.1415926535898 #define _e 2.718281828459 #define INF 1070000000 using NAMESPAce STD; typedef long Long LL;  typedef unsigned long long ull;     Template<class t> inline void read (t& num) {bool start=false,neg=false;     char c;     num=0;         while ((C=getchar ())!=eof) {if (c== '-') start=neg=true;             else if (c>= ' 0 ' && c<= ' 9 ') {start=true;         num=num*10+c-' 0 ';     } else if (start) break; } if (neg) num=-num; }/*==================split line==================*/int n,m;int ch[maxn][2],s[maxn],flip[maxn],fa[maxn];int root, null=0;void updata (int node) {S[NODE]=S[GETLC (node)]+s[getrc (node)]+1;} void pushdown (int node) {if (!flip[node]) Return;flip[node]=0;swap (GETLC (node), GETRC (node)), FLIP[GETLC (node)]^=1; FLIP[GETRC (node)]^=1;} int build (int l,int r) {if (l>r) return 0;if (l==r) {S[l]=1;return l;} int Mid=rs (L,R); Fa[ch[mid][0]=build (l,mid-1)]=mid; Fa[ch[mid][1]=build (Mid+1,r)]=mid;updata (mid); return mid;} void rotate (int x) {int p=fa[x],q=fa[p],d=ch[p][1]==x;pushdown (x); pushdown (p); fa[ch[p][d]=ch[x][d^1]]=p; Updata (P); fa[ch[x][d^1]=p]=x; Updata (x); fa[x]=q;if (q) {if (GETLC (q) ==p) GETLC (q) =x;else if (GETRC (q) ==p) getrc (q) =x;updata (q);}} void splay (int x,int &aim) {for (int y; (Y=fa[x])!=aim;rotate (x)) if (Fa[y]!=aim) rotate ((GETLC (y) ==x) = = (GETRC (fa[y)) ==y) y:x); Updata (x); if (aim==0) root=x ;} int kth (int k,int node) {int X=node;while (x) {pushdown (x); int ss=s[ch[x][0]];if (k==ss+1) return x;if (K&LT;=SS) x=ch[x][0 ];else x=ch[x][1],k-=ss,k--;}} void Change (int l,int r) {int node=kth (l,root); splay (node,null); node=kth (r+2,root); splay (node,root); FLIP[GETLC ( GETRC (root))]^=1;} void print (int node) {if (!node) return;pushdown (node);p rint (GETLC (node)), if (node!=1 && node!=n+2) printf ("%d" , node-1);p rint (GETRC (node));} int main () {read (n); read (m); Memset (flip,0,sizeof (flip)); Root=build (1,n+2); Forp (i,1,m) {int l,r; read (l); Read (R); change (l,r);} print (root);}

Bzoj 3223 & Zone flipping

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.