Advertisement
Guest User

Untitled

a guest
Jan 7th, 2016
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. #define filer() freopen("far","r",stdin)
  2. #define filew() freopen("out.txt","w",stdout)
  3.  
  4. #include <set>
  5. #include<iostream>
  6. #include<stdio.h>
  7. #include<string.h>
  8. #include<math.h>
  9. #include<algorithm>
  10. #include<queue>
  11. #include<stack>
  12. #include<vector>
  13. #include <map>
  14. #include<ctime>
  15. #define SET(a, x) memset((a), (x), sizeof(a))
  16. #define ll long long
  17. #define pb push_back
  18. #define mp make_pair
  19. #define all(x) (x).begin(),(x).end()
  20. #define SZ(x) ((int)(x).size())
  21. #define i64 ll
  22. #define IN(A, B, C) ((B) <= (A) && (A) <= (C))
  23. #define MAX
  24. #define xx first
  25. #define yy second
  26. using namespace std;
  27. typedef vector<int> VI;
  28. typedef vector<string> VS;
  29. typedef vector<double> VD;
  30. typedef vector<ll> VL;
  31. typedef pair<int,int> PII;
  32. typedef pair<ll,ll> PLL;
  33. const int inf=0x20202020;
  34. const ll mod=1000000007;
  35. const double eps=1e-9;
  36. const double pi=3.1415926535897932384626;
  37.  
  38. const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
  39. ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
  40. ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
  41. ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
  42.  
  43.  
  44. template<class X>void debug(vector<X>&v){for(int i=0;i<v.size();i++)cout<<v[i]<<" ";cout<<endl;}
  45.  
  46. int tree[2000009],MaxVal;
  47.  
  48. struct node
  49. {
  50. bool point;
  51. bool start;
  52. int id;
  53. int i;
  54. int x;
  55. int y;
  56. int yy;
  57. int y1;
  58. int y2;
  59. };
  60. vector<node>A;
  61.  
  62. bool cmp1(node a, node b)
  63. {
  64. return a.y<b.y;
  65. }
  66. bool cmp2(node a, node b)
  67. {
  68. return a.i<b.i;
  69. }
  70. bool cmp3(node a,node b)
  71. {
  72. if(a.x==b.x)return a.point>b.point;
  73. return a.x<b.x;
  74. }
  75. int ans[ 50009];
  76.  
  77. int read(int idx){
  78. int sum = 0;
  79. while (idx > 0){
  80. sum += tree[idx];
  81. idx -= (idx & -idx);
  82. }
  83. return sum;
  84. }
  85.  
  86. void update(int idx ,int val){
  87. while (idx <= MaxVal){
  88. tree[idx] += val;
  89. idx += (idx & -idx);
  90. }
  91. }
  92.  
  93. int main()
  94. {
  95.  
  96.  
  97. int i,j,k ,T,cas=0;
  98. scanf("%d",&T);
  99. while(T--)
  100. {
  101. A.clear();
  102. int p,q;
  103. scanf("%d%d",&p,&q);
  104. node a;
  105. for(i=0;i<p;i++)
  106. {
  107. a.i=i;
  108. a.point=true;
  109. a.id=i;
  110. scanf("%d%d",&a.x,&a.y);
  111. A.pb(a);
  112. }
  113. for(j=0;j<q;j++)
  114. {
  115. a.i=i++;
  116. a.point=false;
  117. a.start=true;
  118. a.id=j;
  119. a.i=i++;
  120. scanf("%d%d",&a.x,&a.y);
  121. a.x--;
  122. A.pb(a);
  123. a.i=i++;
  124. a.point=false;
  125. a.start=false;
  126. a.id=j;
  127. a.i=i++;
  128. scanf("%d%d",&a.x,&a.y);
  129. A.pb(a);
  130. }
  131. sort(all(A),cmp1);
  132. int cnt=1;
  133. A[0].yy=cnt;
  134. for(i=1;i<SZ(A);i++)
  135. {
  136. if(A[i].y!=A[i-1].y)cnt++;
  137. A[i].yy=cnt;
  138. }
  139. sort(all(A),cmp2);
  140. for(i=p;i<SZ(A);i+=2)
  141. {
  142. A[i].y1=A[i].yy;
  143. A[i].y2=A[i+1].yy;
  144. A[i+1].y1=A[i].yy;
  145. A[i+1].y2=A[i+1].yy;
  146. }
  147. sort(all(A),cmp3);
  148. MaxVal=SZ(A)+2;
  149. for(i=0;i<SZ(A);i++)
  150. {
  151.  
  152. if(A[i].point)
  153. {
  154. // cout<<"Point:\n";
  155. // cout<<A[i].x<<' '<<A[i].y<<endl;
  156. update(A[i].yy,1);
  157. continue;
  158. }
  159. // cout<<"Rect:\n";
  160. // cout<<A[i].start<<endl;
  161. // cout<<"x: "<<A[i].x<<endl;
  162. // cout<<"y1: "<<A[i].y1<<"y2: "<<A[i].y2<<endl;
  163. if(A[i].start)
  164. {
  165. ans[A[i].id]=read(A[i].y2)-read(A[i].y1-1);
  166. }
  167. else
  168. {
  169. ans[A[i].id]=read(A[i].y2)-read(A[i].y1-1)-ans[A[i].id];
  170. }
  171. // cout<<"ans->"<<ans[A[i].id]<<endl;
  172. }
  173. printf("Case %d:\n",++cas);
  174. for(i=0;i<q;i++)printf("%d\n",ans[i]);
  175. }
  176. return 0;
  177. }
  178. /*Test Cases
  179.  
  180.  
  181. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement