zoukankan      html  css  js  c++  java
  • luogu AT2300 Snuke Line |树状数组

    有一趟列车有 M+1 个车站,从 0 到 M 编号。有 N 种商品,第 i 种只在编号 [li,ri] 的车站出售。一辆列车有一个预设好的系数 d,从 0 出发,只会在 d 的倍数车站停车。对于 d 从 1 到 M 的列车,求最多能买到多少种商品。


    把区间放进树状数组里,logn查询

    但是长区间可能会算重复,所以先把长度区间小于d的区间放进去

    长度大于等于d的必定会有交,所以直接统计答案

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    const int _=3e5+10;
    int n,m,c[_];
    inline void add(int x,int y){
        for(;x<=m;x+=x&(-x))c[x]+=y;
    }
    inline int sum(int x){
        int res=0;
        for(;x;x-=x&(-x))res+=c[x];
        return res;
    }
    struct node{
        int l,r,len;
    }e[_];
    inline bool cmp(node t1,node t2){
        return t1.len<t2.len;
    }
    signed main(){
        cin>>n>>m;
        for(int i=1;i<=n;i++){
            scanf("%d%d",&e[i].l,&e[i].r);
            e[i].len=e[i].r-e[i].l+1;
        }
        sort(e+1,e+1+n,cmp);
        int num=1;
        for(int d=1;d<=m;d++){
            while(e[num].len<d&&num<=n)
            { add(e[num].l,1); add(e[num].r+1,-1); num++; }
            int ans=n-num+1;
            for(int j=1;j*d<=m && d;j++)ans+=sum(j*d);
            printf("%d
    ",ans);
        }
    }
    
  • 相关阅读:
    chrome视频播放加速
    centos磁盘空间重新分配
    mseed2sac的安装和使用
    查找台站信息得到台站数据的网站
    java install
    CMT learning
    hosts持续更新
    what is SVD and how to calculate it
    google 镜像
    z变换
  • 原文地址:https://www.cnblogs.com/naruto-mzx/p/12188227.html
Copyright © 2011-2022 走看看