博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
BZOJ 1112 线段树
阅读量:7171 次
发布时间:2019-06-29

本文共 1314 字,大约阅读时间需要 4 分钟。

思路:

权值线段树 (找中位数用的) 记录下出现的次数和sum

一定要注意 有可能中位数的值有许多数 这怎么办呢 (离散化以后不去重就行了嘛…….)

(为什么他们想得那么麻烦)

//By SiriusRen#include 
#include
#include
using namespace std;#define N 100500#define int long longint n,k,sum[N*10],tree[N*10],xx,ans=100000LL*1000000LL;struct Node{ int num,pos; friend bool operator < (Node a,Node b){ if(a.num!=b.num)return a.num
>1,lson=pos<<1,rson=pos<<1|1; if(mid>=num)insert(l,mid,lson,wei,num); else insert(mid+1,r,rson,wei,num); tree[pos]=tree[lson]+tree[rson]; sum[pos]=sum[lson]+sum[rson];}void query(int l,int r,int pos,int num){ if(l==r){xx=l;return;} int mid=(l+r)>>1,lson=pos<<1,rson=pos<<1|1; if(tree[lson]>=num)query(l,mid,lson,num); else query(mid+1,r,rson,num-tree[lson]);}int query_sum(int l,int r,int pos,int L,int R){ if(l>=L&&r<=R)return sum[pos]; int mid=(l+r)>>1,lson=pos<<1,rson=pos<<1|1; if(mid
=R)return query_sum(l,mid,lson,L,R); else return query_sum(l,mid,lson,L,R)+query_sum(mid+1,r,rson,L,R);}signed main(){ scanf("%lld%lld",&n,&k); for(int i=1;i<=n;i++) scanf("%lld",&node[i].num),node[i].pos=i,cpy[i]=node[i]; sort(cpy+1,cpy+1+n); for(int i=1;i

这里写图片描述

转载于:https://www.cnblogs.com/SiriusRen/p/6532170.html

你可能感兴趣的文章
filebeat 插件开发
查看>>
网络基础
查看>>
技术加油站:5月19日,技术大佬等你来撩
查看>>
supervisor配置详解(转)
查看>>
Confluence 6 Microsoft SQL Server 设置准备
查看>>
Nginx.conf配置文件
查看>>
EI检索期刊JA检索与CA检索有什么区别?
查看>>
人脸识别技术探讨:1:1,1:小N/大N,大姿态识别,活体识别
查看>>
面向对象程序设计
查看>>
非主从同步 mysql master slave pt-slave-delay
查看>>
【思科×××】IPsec ×××基本部署
查看>>
SpringFramework之mvc controller的单元测试
查看>>
检验新买内存条的真假
查看>>
解密:华为的敏捷网络是SDN吗
查看>>
u16 u32 __u16 __u32 u_int16_t u_int32_t
查看>>
android: BaseAdapter和ListView简单运用(08)
查看>>
自带内存上的读写(openFileOutput和openFileInput)
查看>>
服务器搭建:3.2、openresty图片压缩之 lua调用GraphicsMagick
查看>>
bash 脚本编程 变量、变量类型 (笔记)
查看>>
win7 管理员权限
查看>>