Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define filer() freopen("far","r",stdin)
- #define filew() freopen("out.txt","w",stdout)
- #include <set>
- #include<iostream>
- #include<stdio.h>
- #include<string.h>
- #include<math.h>
- #include<algorithm>
- #include<queue>
- #include<stack>
- #include<vector>
- #include <map>
- #include<ctime>
- #define SET(a, x) memset((a), (x), sizeof(a))
- #define ll long long
- #define pb push_back
- #define mp make_pair
- #define all(x) (x).begin(),(x).end()
- #define SZ(x) ((int)(x).size())
- #define i64 ll
- #define IN(A, B, C) ((B) <= (A) && (A) <= (C))
- #define MAX
- #define xx first
- #define yy second
- using namespace std;
- typedef vector<int> VI;
- typedef vector<string> VS;
- typedef vector<double> VD;
- typedef vector<ll> VL;
- typedef pair<int,int> PII;
- typedef pair<ll,ll> PLL;
- const int inf=0x20202020;
- const ll mod=1000000007;
- const double eps=1e-9;
- const double pi=3.1415926535897932384626;
- const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
- 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;}
- 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;}
- ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
- template<class X>void debug(vector<X>&v){for(int i=0;i<v.size();i++)cout<<v[i]<<" ";cout<<endl;}
- int tree[2000009],MaxVal;
- struct node
- {
- bool point;
- bool start;
- int id;
- int i;
- int x;
- int y;
- int yy;
- int y1;
- int y2;
- };
- vector<node>A;
- bool cmp1(node a, node b)
- {
- return a.y<b.y;
- }
- bool cmp2(node a, node b)
- {
- return a.i<b.i;
- }
- bool cmp3(node a,node b)
- {
- if(a.x==b.x)return a.point>b.point;
- return a.x<b.x;
- }
- int ans[ 50009];
- int read(int idx){
- int sum = 0;
- while (idx > 0){
- sum += tree[idx];
- idx -= (idx & -idx);
- }
- return sum;
- }
- void update(int idx ,int val){
- while (idx <= MaxVal){
- tree[idx] += val;
- idx += (idx & -idx);
- }
- }
- int main()
- {
- int i,j,k ,T,cas=0;
- scanf("%d",&T);
- while(T--)
- {
- A.clear();
- int p,q;
- scanf("%d%d",&p,&q);
- node a;
- for(i=0;i<p;i++)
- {
- a.i=i;
- a.point=true;
- a.id=i;
- scanf("%d%d",&a.x,&a.y);
- A.pb(a);
- }
- for(j=0;j<q;j++)
- {
- a.i=i++;
- a.point=false;
- a.start=true;
- a.id=j;
- a.i=i++;
- scanf("%d%d",&a.x,&a.y);
- a.x--;
- A.pb(a);
- a.i=i++;
- a.point=false;
- a.start=false;
- a.id=j;
- a.i=i++;
- scanf("%d%d",&a.x,&a.y);
- A.pb(a);
- }
- sort(all(A),cmp1);
- int cnt=1;
- A[0].yy=cnt;
- for(i=1;i<SZ(A);i++)
- {
- if(A[i].y!=A[i-1].y)cnt++;
- A[i].yy=cnt;
- }
- sort(all(A),cmp2);
- for(i=p;i<SZ(A);i+=2)
- {
- A[i].y1=A[i].yy;
- A[i].y2=A[i+1].yy;
- A[i+1].y1=A[i].yy;
- A[i+1].y2=A[i+1].yy;
- }
- sort(all(A),cmp3);
- MaxVal=SZ(A)+2;
- for(i=0;i<SZ(A);i++)
- {
- if(A[i].point)
- {
- // cout<<"Point:\n";
- // cout<<A[i].x<<' '<<A[i].y<<endl;
- update(A[i].yy,1);
- continue;
- }
- // cout<<"Rect:\n";
- // cout<<A[i].start<<endl;
- // cout<<"x: "<<A[i].x<<endl;
- // cout<<"y1: "<<A[i].y1<<"y2: "<<A[i].y2<<endl;
- if(A[i].start)
- {
- ans[A[i].id]=read(A[i].y2)-read(A[i].y1-1);
- }
- else
- {
- ans[A[i].id]=read(A[i].y2)-read(A[i].y1-1)-ans[A[i].id];
- }
- // cout<<"ans->"<<ans[A[i].id]<<endl;
- }
- printf("Case %d:\n",++cas);
- for(i=0;i<q;i++)printf("%d\n",ans[i]);
- }
- return 0;
- }
- /*Test Cases
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement