zoukankan      html  css  js  c++  java
  • BZOJ 4627: [BeiJing2016]回转寿司

    线段树裸题

    #include<cstdio>
    using namespace std;
    int cnt,root,sz[10000005],ls[10000005],rs[10000005];
    long long a[100005];
    int query(int t,long long l,long long r,long long x,long long y){
    	if (!t) return 0;
    	if (r<x || l>y) return 0;
    	if (l>=x && r<=y) return sz[t];
    	long long mid=(l+r)>>1;
    	return query(ls[t],l,mid,x,y)+query(rs[t],mid+1,r,x,y);
    }
    void insert(int &t,long long l,long long r,long long x){
    	if (!t) t=++cnt;
    	if (l==r) {
    		sz[t]++;
    		return;
    	}
    	long long mid=(l+r)>>1;
    	if (x<=mid) insert(ls[t],l,mid,x);
    	else insert(rs[t],mid+1,r,x);
    	sz[t]=sz[ls[t]]+sz[rs[t]];
    }
    int main(){
    	int n,L,R;
    	scanf("%d%d%d",&n,&L,&R);
    	for (int i=1; i<=n; i++) scanf("%lld",&a[i]);
    	for (int i=1; i<=n; i++) a[i]+=a[i-1];
    	insert(root,-1ll<<60,1ll<<60,0);
    	long long ans=0;
    	for (int i=1; i<=n; i++){
    		if (L>R) continue;
    		ans+=query(root,-1ll<<60,1ll<<60,a[i]-R,a[i]-L);
    		insert(root,-1ll<<60,1ll<<60,a[i]);
    	}
    	printf("%lld
    ",ans);
    	return 0;
    }
    

      

  • 相关阅读:
    Win10 蓝屏
    XE Button Color
    IOS 屏幕尺寸
    Delphi 转圈 原型进度条 AniIndicator 及线程配合使用
    Delphi 询问框 汉化
    Delphi Android 询问框
    Delphi BLE 控件
    浮点高低位赋值
    delphi 蓝牙 TBluetoothLE
    16进制字节转换
  • 原文地址:https://www.cnblogs.com/silenty/p/9892887.html
Copyright © 2011-2022 走看看