# bzoj1691 [Usaco2007 Dec]挑剔的美食家

set可做，写treap练手

 1 #include<algorithm>
2 #include<iostream>
3 #include<cstdlib>
4 #include<cstring>
5 #include<cstdio>
6 #include<string>
7 #include<cmath>
8 #include<ctime>
9 #include<queue>
10 #include<stack>
11 #include<map>
12 #include<set>
13 #define rre(i,r,l) for(int i=(r);i>=(l);i--)
14 #define re(i,l,r) for(int i=(l);i<=(r);i++)
15 #define Clear(a,b) memset(a,b,sizeof(a))
16 #define inout(x) printf("%d",(x))
17 #define douin(x) scanf("%lf",&x)
18 #define strin(x) scanf("%s",(x))
19 #define LLin(x) scanf("%lld",&x)
20 #define op operator
21 #define CSC main
22 typedef unsigned long long ULL;
23 typedef const int cint;
24 typedef long long LL;
25 using namespace std;
26 void inin(int &ret)
27 {
28     ret=0;int f=0;char ch=getchar();
29     while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();}
30     while(ch>='0'&&ch<='9')ret*=10,ret+=ch-'0',ch=getchar();
31     ret=f?-ret:ret;
32 }
33 int ch[100010][2],w[100010],r[100010],c[100010];
34 int root,n,ed;
35 void rotate(int &k,int d)
36 {
37     int p=ch[k][d^1];
38     ch[k][d^1]=ch[p][d];
39     ch[p][d]=k;k=p;
40 }
41 void add(int &k,const int &x)
42 {
43     if(!k)
44     {
45         k=++ed,w[k]=x,r[k]=rand(),c[k]=1,ch[k][0]=ch[k][1]=0;
46         return ;
47     }
48     if(x==w[k]){c[k]++;return ;}
49     int d=x>w[k];
51     if(r[ch[k][d]]<r[k])rotate(k,d^1);
52 }
53 void del(int &k,const int &x)
54 {
55     if(x==w[k])
56     {
57         if(c[k]>1){c[k]--;return ;}
58         if(!ch[k][0]){k=ch[k][1];return ;}
59         if(!ch[k][1]){k=ch[k][0];return ;}
60         if(r[ch[k][0]]<r[ch[k][1]])rotate(k,1);
61         else rotate(k,0);
62         del(k,x);return ;
63     }
64     int d=x>w[k];
65     del(ch[k][d],x);
66 }
67 void find(int k,const int &x,int &ans)
68 {
69     if(!k)return ;
70     if(w[k]>=x){ans=k,find(ch[k][0],x,ans);}
71     else find(ch[k][1],x,ans);
72 }
73 int m;
74 struct wocao
75 {
76     int x,y;
77     bool op < (const wocao &rhs)const {return y>rhs.y;}
78 }a[100010],b[100010];
79 int CSC()
80 {
81     inin(n),inin(m);
82     re(i,1,n)inin(a[i].x),inin(a[i].y);
83     re(i,1,m)inin(b[i].x),inin(b[i].y);
84     sort(a+1,a+n+1);sort(b+1,b+m+1);
85     int j=1;
86     LL ans=0;
87     re(i,1,n)
88     {
97 }