protagonist

lines

lines

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2432    Accepted Submission(s): 1032


Problem Description
John has several lines. The lines are covered on the X axis. Let A is a point which is covered by the most lines. John wants to know how many lines cover A.
 

 

Input
The first line contains a single integer T(1T100)(the data for N>100 less than 11 cases),indicating the number of test cases.
Each test case begins with an integer N(1N105),indicating the number of lines.
Next N lines contains two integers Xi and Yi(1XiYi109),describing a line.
 

 

Output
For each case, output an integer means how many lines cover A.
 

 

Sample Input
2 5 1 2 2 2 2 4 3 4 5 1000 5 1 1 2 2 3 3 4 4 5 5
 

 

Sample Output
3 1
 

 

Source
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define lowbit(x) x&(-x)
typedef long long ll;
using namespace std;
const int maxn = 2e5 + 100000;
struct BIT{
    int n,c[maxn];
    inline void init(int _n){
        n=_n;
        memset(c,0,sizeof(c));
    }
    inline void update(int pos,int val){
        while(pos<=n){
            c[pos]+=val;
            pos+=lowbit(pos);
        }
    }
    inline int query(int pos){
        int res=0;
        while (pos){
            res+=c[pos];
            pos-=lowbit(pos);
        }
        return res;
    }
}atom;
int T,n;
int l[maxn],r[maxn],lsh[maxn];

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.txt", "r", stdin);
#endif
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        int tot=0;
        atom.init(2*n+6);
        for(register int i=1;i<=n;++i){
            scanf("%d%d",&l[i],&r[i]);
            lsh[++tot]=l[i];
            lsh[++tot]=r[i];
        }
        sort(lsh+1,lsh+1+tot);
        for(register int i=1;i<=n;++i){
            int L=lower_bound(lsh+1,lsh+1+tot,l[i])-lsh;
            int R=lower_bound(lsh+1,lsh+1+tot,r[i])-lsh;
            atom.update(L,1);
            atom.update(R+1,-1);
        }
        int ans=0;
        for(register int i=1;i<=2*n;++i){
            int cur=atom.query(i);
            if(cur>ans){
                ans=cur;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

posted @ 2019-09-03 09:41  czy-power  阅读(266)  评论(0编辑  收藏  举报