zoukankan      html  css  js  c++  java
  • P3755 [CQOI2017]老C的任务

    传送门

    可以离线,把询问拆成四个,然后把所有的按(x)坐标排序,这样就只要考虑(y)坐标了。然后把(y)坐标离散化,用树状数组统计即可
    记得开longlong

    //minamoto
    #include<bits/stdc++.h>
    #define R register
    #define int long long
    #define fp(i,a,b) for(R int i=a,I=b+1;i<I;++i)
    #define fd(i,a,b) for(R int i=a,I=b-1;i>I;--i)
    #define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
    using namespace std;
    char buf[1<<21],*p1=buf,*p2=buf;
    inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
    int read(){
        R int res,f=1;R char ch;
        while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
        for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
        return res*f;
    }
    char sr[1<<21],z[20];int C=-1,Z=0;
    inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
    void print(R int x){
        if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
        while(z[++Z]=x%10+48,x/=10);
        while(sr[++C]=z[Z],--Z);sr[++C]='
    ';
    }
    const int N=1e5+5;
    struct node{
        int x,y,id,op,v;
        node(){}
        node(R int x,R int y,R int v,R int id=0,R int op=0):x(x),y(y),v(v),id(id),op(op){}
        inline bool operator <(const node &b)const{return x==b.x?op<b.op:x<b.x;}
    }q[N*5];int p[N*3],x[N],y[N],a[N],b[N],v[N],c[N],d[N],n,m,cc[N*3],lim,tot,ans[N];
    inline void add(R int x,R int y){for(;x<=lim;x+=x&-x)cc[x]+=y;}
    inline int query(R int x){R int res=0;for(;x;x-=x&-x)res+=cc[x];return res;}
    signed main(){
    //	freopen("testdata.in","r",stdin);
        n=read(),m=read();fp(i,1,n)x[i]=read(),p[++lim]=y[i]=read(),v[i]=read();
        fp(i,1,m)a[i]=read(),p[++lim]=b[i]=read(),c[i]=read(),p[++lim]=d[i]=read();
        sort(p+1,p+1+lim),lim=unique(p+1,p+1+lim)-p-1;
        fp(i,1,n)y[i]=lower_bound(p+1,p+1+lim,y[i])-p,q[++tot]=node(x[i],y[i],v[i]);
        fp(i,1,m){
            b[i]=lower_bound(p+1,p+1+lim,b[i])-p,d[i]=lower_bound(p+1,p+1+lim,d[i])-p;
            q[++tot]=node(a[i]-1,b[i]-1,1,i,1),q[++tot]=node(a[i]-1,d[i],-1,i,1);
            q[++tot]=node(c[i],b[i]-1,-1,i,1),q[++tot]=node(c[i],d[i],1,i,1);
        }sort(q+1,q+1+tot);
        fp(i,1,tot)if(q[i].op==0)add(q[i].y,q[i].v);
        else ans[q[i].id]+=query(q[i].y)*q[i].v;
        fp(i,1,m)print(ans[i]);return Ot(),0;
    }
    
  • 相关阅读:
    ptrace
    CentOS 5.4 final下Systemtap的安装
    SystemTap 静态探针安装包
    sysdig
    ORACLE 内部原理
    An introduction to KProbes
    CentOS6.5升级手动安装GCC4.8.2 与 CentOS 6.4 编译安装 gcc 4.8.1
    在Oracle Linux上安装dtrace
    dwarf调试信息格式入门
    MySQL 5.6.20-4 and Oracle Linux DTrace
  • 原文地址:https://www.cnblogs.com/bztMinamoto/p/10082349.html
Copyright © 2011-2022 走看看