• bzoj1935


    题解:

    x升序排序

    y离散化+树状数组

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    const int N=500005;
    inline int read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    int n,m,tot,que,disc[N*3],x[N],y[N],a[N],b[N],c[N],d[N],t[3*N],ans[N][5];
    struct data{int x,y,id,f;}q[5*N];
    int operator<(data a,data b)
    {
        return a.x<b.x||(a.x==b.x&&a.f<b.f);
    }
    void add(int x,int y)
    {
        for (int i=x;i<=tot;i+=i&-i)t[i]+=y;
    }
    int query(int x)
    {
        int sum=0;
        for (int i=x;i;i-=i&-i)sum+=t[i];
        return sum;
    }
    int find(int x)
    {
        int l=1,r=tot;
        while (l<=r)
         {
            int mid=(l+r)>>1;
            if (disc[mid]==x)return mid;
            else if(disc[mid]<x)l=mid+1;
            else r=mid-1;
         }
    }
    void solve()
    {
        sort(q+1,q+que+1);
        for (int i=1;i<=que;i++)
         {
            if (!q[i].f)add(q[i].y,1);
            else 
             {
                int t=query(q[i].y);
                ans[q[i].id][q[i].f]=t;
             }
         }
    }
    int main()
    {
        scanf("%d%d",&n,&m);
        for (int i=1;i<=n;i++)
         {
            scanf("%d%d",&x[i],&y[i]);
            disc[++tot]=y[i];
         }
        for (int i=1;i<=m;i++)
         {
             scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
            disc[++tot]=b[i];disc[++tot]=d[i];
         }
        sort(disc,disc+tot+1);
        for (int i=1;i<=n;i++)
         {
            y[i]=find(y[i]);
            q[++que].x=x[i];q[que].y=y[i];
         }
        for (int i=1;i<=m;i++)
         {
            b[i]=find(b[i]);d[i]=find(d[i]);
            q[++que].x=c[i];q[que].y=d[i];q[que].id=i;q[que].f=1;
            q[++que].x=a[i]-1;q[que].y=d[i];q[que].id=i;q[que].f=2;
            q[++que].x=c[i];q[que].y=b[i]-1;q[que].id=i;q[que].f=3;
            q[++que].x=a[i]-1;q[que].y=b[i]-1;q[que].id=i;q[que].f=4;
         }
        solve();
        for (int i=1;i<=m;i++)
         {
            int t=ans[i][1]+ans[i][4]-ans[i][2]-ans[i][3];
            printf("%d
    ",t);
         }
        return 0;
    }
  • 相关阅读:
    Python并发编程之多进程(实战)
    ThreadPoolExecutor源码分析
    JDK 1.8 JVM的变化
    JDK1.8 hashMap源码分析
    Spring解决循环依赖
    spring
    实现一个可重入锁和不可重入锁
    B树与B+树
    WebMagic
    Java高频面试题
  • 原文地址:https://www.cnblogs.com/xuanyiming/p/8576315.html
Copyright © 2020-2023  润新知