zoukankan      html  css  js  c++  java
  • 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
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    模板--后缀自动机
    十二省NOI“省选”联考模测(第二场)A抽卡大赛
    BZOJ 1800: [Ahoi2009]fly 飞行棋
    BZOJ 1208: [HNOI2004]宠物收养所
    BZOJ 1876: [SDOI2009]SuperGCD
    BZOJ 1013: [JSOI2008]球形空间产生器sphere
    BZOJ 1011: [HNOI2008]遥远的行星
    BZOJ 1010: [HNOI2008]玩具装箱toy
    BZOJ 1008: [HNOI2008]越狱
    BZOJ 1007: [HNOI2008]水平可见直线
  • 原文地址:https://www.cnblogs.com/czy-power/p/11451184.html
Copyright © 2011-2022 走看看