zoukankan      html  css  js  c++  java
  • hdu 4325

    #include<stdio.h>//数据弱线段树延迟更新水过
    #define N 100100
    struct node {
    int x,y,yanchi,num;
    }a[N*4];
    void build(int t,int x,int y) {
    a[t].x=x;
    a[t].y=y;
    a[t].yanchi=0;
    a[t].num=0;
    if(x==y)
    return ;
    int temp=t<<1;
    int mid=(x+y)/2;
    build(temp,x,mid);
    build(temp+1,mid+1,y);
    }
    void update(int t,int x,int y) {
    if(a[t].x==x&&a[t].y==y) {
    a[t].yanchi++;
    return ;
    }
    a[t].num=a[t].num+y-x+1;
    int temp=t<<1;
    int mid=(a[t].x+a[t].y)/2;
    if(mid<x)
    update(temp+1,x,y);
    else
    if(mid>=y)
    update(temp,x,y);
    else {
    update(temp,x,mid);
    update(temp+1,mid+1,y);
    }
    return;
    }
    int qury(int t,int h) {
    if(a[t].x==h&&a[t].y==h) 
    return a[t].num+a[t].yanchi;
    a[t].num=a[t].num+a[t].yanchi*(a[t].y-a[t].x+1);
    int temp=t<<1;
    a[temp].yanchi+=a[t].yanchi;
    a[temp+1].yanchi+=a[t].yanchi;
    a[t].yanchi=0;
    int mid=(a[t].x+a[t].y)/2;
    if(mid<h)
    return qury(temp+1,h);
    else
    return qury(temp,h);
    }
    int main() {
    int t,n,m,x,y,i,k,count=0;
    scanf("%d",&t);
    while(t--) {
    scanf("%d%d",&n,&m);
    printf("Case #%d: ",++count);
    build(1,1,100000);
    for(i=0;i<n;i++) {
    scanf("%d%d",&x,&y);
    update(1,x,y);
    }
    while(m--) {
    scanf("%d",&k);
    printf("%d ",qury(1,k));
    }
    }
    return 0;
    }
  • 相关阅读:
    杭电ACM1.2.6 Decimal System
    杭电ACM1.2.7 GPA
    taro hook 倒计时setTimeout版
    taro hook 倒计时setInterval版
    Vuecli3内存溢出解决方案记录
    哈希
    hashmap和hashtable区别
    HashMap[转]
    JAVA中List、Map、Set
    C++和MATLAB混合编程DLL篇[转]
  • 原文地址:https://www.cnblogs.com/thefirstfeeling/p/4410923.html
Copyright © 2011-2022 走看看