当前位置: 首页 > 编程日记 > 正文

BZOJ 3110

http://www.lydsy.com/JudgeOnline/problem.php?id=3110

整体二分+区间修改树状数组维护

#include<cstdio>
#define FOR(i,s,t) for(register int i=s;i<=t;++i)
inline int max(int a,int b){return a>b?a:b;}
inline int min(int a,int b){return a<b?a:b;}
typedef long long ll;
const int N=50011,inf=(1<<30);
int n,m,minn,maxx;
int ans[N];
ll tmp[N];
namespace BIT{ll tr1[N],tr2[N];inline void add(ll *a,int p,ll v){for(;p<=n;a[p]+=v,p+=p&-p);}inline ll query(ll *a,int p){ll ret=0;for(;p;ret+=a[p],p-=p&-p);return ret;}inline void _add(int l,int r,ll v){add(tr1,l,v);add(tr1,r+1,-v);add(tr2,l,1ll*(l-1)*v);add(tr2,r+1,-1ll*r*v);}inline ll _query(ll l,ll r){ll ans1=1ll*(l-1)*query(tr1,l-1)-1ll*query(tr2,l-1);ll ans2=1ll*r*query(tr1,r)-1ll*query(tr2,r);return ans2-ans1;}
}
using namespace BIT;
namespace divide{struct question{int a,b,c,k,pos;}p[N],t[N];inline void solve(int l,int r,int head,int tail){if(head>tail)return;if(l==r){FOR(i,head,tail)if(p[i].k==2)ans[p[i].pos]=l;return ;}int mid=(l+r)>>1;FOR(i,head,tail){if(p[i].k==1&&p[i].c>mid)_add(p[i].a,p[i].b,1ll);if(p[i].k==2)tmp[i]=_query(p[i].a,p[i].b);}	int top=head,d;FOR(i,head,tail){if(p[i].k==1&&p[i].c>mid)t[top++]=p[i],_add(p[i].a,p[i].b,-1ll);if(p[i].k==2)if(p[i].c<=tmp[i])t[top++]=p[i];}d=top;FOR(i,head,tail){if(p[i].k==1&&p[i].c<=mid)t[top++]=p[i];if(p[i].k==2)if(p[i].c>tmp[i])p[i].c-=tmp[i],t[top++]=p[i];	}FOR(i,head,tail)p[i]=t[i];solve(mid+1,r,head,d-1);solve(l,mid,d,tail);}
}
using namespace divide;
int main(){scanf("%d%d",&n,&m);minn=inf,maxx=-inf;FOR(i,1,m){scanf("%d%d%d%d",&p[i].k,&p[i].a,&p[i].b,&p[i].c);if(p[i].k==2)p[i].pos=++ans[0];if(p[i].k==1)minn=min(minn,p[i].c),maxx=max(maxx,p[i].c);}solve(minn,maxx,1,m);FOR(i,1,ans[0])printf("%d\n",ans[i]);return 0;
}

补一份树套树

树状数组套主席树

#include<cstdio>
#include<algorithm>
#define lson l,mid
#define rson (mid+1),r
using namespace std;
const int maxn=1e5,N=3000000;
int n,m,tot;
int root[maxn],ra[maxn],rb[maxn];
int a[maxn],b[maxn];
struct Query{char type;int l,r,k;
}q[maxn];
struct Chainman_Tree{int ls,rs,sum;
}tr[N];
namespace BIT_with_Chainman_Tree{inline void insert(int &rt,int p,int v,int l=1,int r=b[0]){tr[++tot]=tr[rt];tr[rt=tot].sum+=v;if(l==r)return;int mid=(l+r)>>1;p<=mid?insert(tr[rt].ls,p,v,lson):insert(tr[rt].rs,p,v,rson);}inline int ask(int k,int l=1,int r=b[0]){if(l==r)return l;register int sum=0;for(register int i=1;i<=ra[0];++i)sum-=tr[tr[ra[i]].ls].sum;for(register int i=1;i<=rb[0];++i)sum+=tr[tr[rb[i]].ls].sum;int mid=(l+r)>>1;if(k<=sum){for(register int i=1;i<=ra[0];++i)ra[i]=tr[ra[i]].ls;for(register int i=1;i<=rb[0];++i)rb[i]=tr[rb[i]].ls;return ask(k,lson);}for(register int i=1;i<=ra[0];++i)ra[i]=tr[ra[i]].rs;			for(register int i=1;i<=rb[0];++i)rb[i]=tr[rb[i]].rs;return ask(k-sum,rson);}inline int query(int l,int r,int k){ra[0]=rb[0]=0;for(register int i=l-1;i;i-=i&-i)ra[++ra[0]]=root[i];for(register int i=r;i;i-=i&-i)rb[++rb[0]]=root[i];return ask(k);}inline void modify(int pos,int val,int v){for(;pos<=n;pos+=pos&-pos)insert(root[pos],val,v);}
}
using namespace BIT_with_Chainman_Tree;
inline void disc_init(){sort(b+1,b+b[0]+1);b[0]=unique(b+1,b+b[0]+1)-b-1;for(register int i=1;i<=n;++i){a[i]=lower_bound(b+1,b+b[0]+1,a[i])-b;modify(i,a[i],1);		}
}
char s[6];
int main(){scanf("%d%d",&n,&m);for(register int i=1;i<=n;++i){scanf("%d",a+i);b[++b[0]]=a[i];}for(register int i=1;i<=m;++i){scanf("%s",s);q[i].type=s[0];if(q[i].type=='C'){scanf("%d%d",&q[i].l,&q[i].k);b[++b[0]]=q[i].k;}elsescanf("%d%d%d",&q[i].l,&q[i].r,&q[i].k);}disc_init();for(register int i=1;i<=m;++i){if(q[i].type=='C'){q[i].k=lower_bound(b+1,b+b[0]+1,q[i].k)-b;modify(q[i].l,a[q[i].l],-1);a[q[i].l]=q[i].k;modify(q[i].l,a[q[i].l],1);}elseprintf("%d\n",b[query(q[i].l,q[i].r,q[i].k)]);}	return 0;
}

转载于:https://www.cnblogs.com/Stump/p/8012641.html

相关文章:

css 选择器 伪元素_CSS伪元素-解释选择器之前和之后

css 选择器 伪元素选择器之前 (Before Selector) The CSS ::before selector can be used to insert content before the content of the selected element or elements. It is used by attaching ::before to the element it is to be used on.CSS ::before选择器可用于在选定…

各种面试题啊1

技术 基础 1.为什么说Objective-C是一门动态的语言&#xff1f; 什么叫动态静态 静态、动态是相对的&#xff0c;这里动态语言指的是不需要在编译时确定所有的东西&#xff0c;在运行时还可以动态的添加变量、方法和类 Objective-C 可以通过Runtime 这个运行时机制&#xff0c…

PEP8 Python

写在前面 对于代码而言&#xff0c;相比于写&#xff0c;它更多是读的。 pep8 一、代码编排 缩进&#xff0c;4个空格的缩进&#xff0c;编辑器都可以完成此功能&#xff1b;每行最大长度79&#xff0c;换行可以使用反斜杠&#xff0c;换行点要在操作符的后边。类和top-level函…

粒子滤波 应用_如何使用NativeScript开发粒子物联网应用

粒子滤波 应用If youre developing any type of IoT product, inevitably youll need some type of mobile app. While there are easy ways, theyre not for production use.如果您要开发任何类型的物联网产品&#xff0c;则不可避免地需要某种类型的移动应用程序。 尽管有简单…

wkwebView基本使用方法

WKWebView有两个delegate,WKUIDelegate 和 WKNavigationDelegate。WKNavigationDelegate主要处理一些跳转、加载处理操作&#xff0c;WKUIDelegate主要处理JS脚本&#xff0c;确认框&#xff0c;警告框等。因此WKNavigationDelegate更加常用。 比较常用的方法&#xff1a; #p…

引用类型(一):Object类型

对象表示方式 1、第一种方式&#xff1a;使用new操作符后跟Object构造函数 var person new Object();<br/> person.name Nicholas;<br/> person.age 29; 2、对象字面量表示法 var person {name:Nicholas,age:29 } *:在age属性的值29的后面不能添加逗号&#xf…

(第四周)要开工了

忙碌的一周又过去了&#xff0c;这周的时间很紧&#xff0c;但是把时间分配的比较均匀&#xff0c;考研复习和各门功课都投入了一定的精力&#xff0c;所以不像前三周一样把大多数时间都花费在了软件工程上。也因为结对项目刚开始&#xff0c;我们刚刚进行任务分工以及查找资料…

统计数字,空白符,制表符_为什么您应该在HTML中使用制表符空间而不是多个非空白空间(nbsp)...

统计数字,空白符,制表符There are a number of ways to insert spaces in HTML. The easiest way is by simply adding spaces or multiple character entities before and after the target text. Of course, that isnt the DRYest method.有多种方法可以在HTML中插入空格。…

Python20-Day02

1、数据 数据为什么要分不同的类型 数据是用来表示状态的&#xff0c;不同的状态就应该用不同类型的数据表示&#xff1b; 数据类型 数字&#xff08;整形&#xff0c;长整形&#xff0c;浮点型&#xff0c;复数&#xff09;&#xff0c;字符串&#xff0c;列表&#xff0c;元组…

Android网络框架-OkHttp3.0总结

一、概述 OkHttp是Square公司开发的一款服务于android的一个网络框架&#xff0c;主要包含&#xff1a; 一般的get请求一般的post请求基于Http的文件上传文件下载加载图片支持请求回调&#xff0c;直接返回对象、对象集合支持session的保持github地址&#xff1a;https://githu…

第一天写,希望能坚持下去。

该想的都想完了&#xff0c;不该想的似乎也已经尘埃落定了。有些事情&#xff0c;终究不是靠努力或者不努力获得的。顺其自然才是正理。 以前很多次想过要努力&#xff0c;学习一些东西&#xff0c;总是不能成&#xff0c;原因很多&#xff1a; 1.心中烦恼&#xff0c;不想学…

mac gource_如何使用Gource显示项目的时间表

mac gourceThe first time I heard about Gource was in 2013. At the time I watched this cool video showing Ruby on Rails source code evolution:我第一次听说Gource是在2013年 。 当时&#xff0c;我观看了这段很酷的视频&#xff0c;展示了Ruby on Rails源代码的演变&a…

insert语句让我学会的两个MySQL函数

我们要保存数据到数据库&#xff0c;插入数据是必须的&#xff0c;但是在业务中可能会出于某种业务要求&#xff0c;要在数据库中设计唯一索引&#xff1b;这时如果不小心插入一条业务上已经存在同样key的数据时&#xff0c;就会出现异常。 大部分的需求要求我们出现唯一键冲突…

对PInvoke函数函数调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。...

C#引入外部非托管类库时&#xff0c;有时候会出现“对PInvoke函数调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配”的报错。 通常在DllImport标签内加入属性CallingConventionCallingConvention.Cdecl即可解决该问题。 如&#xff1a; [Dll…

Python字符串方法用示例解释

字符串查找方法 (String Find Method) There are two options for finding a substring within a string in Python, find() and rfind().在Python中的字符串中有两个选项可以找到子字符串&#xff1a; find()和rfind() 。 Each will return the position that the substring …

关于命名空间namespace

虽然任意合法的PHP代码都可以包含在命名空间中&#xff0c;但只有以下类型的代码受命名空间的影响&#xff0c;它们是&#xff1a;类&#xff08;包括抽象类和traits&#xff09;、接口、函数和常量。在声明命名空间之前唯一合法的代码是用于定义源文件编码方式的 declare 语句…

一 梳理 从 HDFS 到 MR。

MapReduce 不仅仅是一个工具&#xff0c;更是一个框架。我们必须拿问题解决方案去适配框架的 map 和 reduce 过程很多情况下&#xff0c;需要关注 MapReduce 作业所需要的系统资源&#xff0c;尤其是集群内部网络资源的使用情况。这是MapReduce 框架在设计上的取舍&#xff0c;…

huffman树和huffman编码

不知道为什么&#xff0c;我写的代码都是又臭又长。 直接上代码&#xff1a; #include <iostream> #include <cstdarg> using namespace std; class Node{ public:int weight;int parent, lChildren, rChildren;Node(int weight, int parent, int lChildren, int …

react 监听组合键_投资组合中需要的5个React项目

react 监听组合键Youve put in the work and now you have a solid understanding of the React library.您已经完成工作&#xff0c;现在对React库有了扎实的了解。 On top of that, you have a good grasp of JavaScript and are putting its most helpful features to use …

Unity 单元测试(PLUnitTest工具)

代码测试的由来 上几个星期上面分配给我一个装备系统,我经过了几个星期的战斗写完90%的代码. 后来策划告诉我需求有一定的改动,我就随着策划的意思修改了代码. 但是测试(Xu)告诉我装备系统很多功能都用不上了. Xu: 我有300多项测试用例,现在有很多项都无法运行了. 你修改了部分…

Best Time to Buy and Sell Stock II

题目&#xff1a; Say you have an array for which the i th element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multipl…

求给定集合的幂集

数据结构中说这个问题可以用类似8皇后的状态树解法。 把求解过程看成是一棵二叉树&#xff0c;空集作为root&#xff0c;然后遍历给定集合中的元素&#xff0c;左子树表示取该元素&#xff0c;右子树表示舍该元素。 然后&#xff0c;root的左右元素分别重复上述过程。 就形成…

angular 命令行项目_Angular命令行界面介绍

angular 命令行项目Angular is closely associated with its command-line interface (CLI). The CLI streamlines generation of the Angular file system. It deals with most of the configuration behind the scenes so developers can start coding. The CLI also has a l…

oracle-imp导入小错filesize设置

***********************************************声明*********************************************************************** 原创作品&#xff0c;出自 “深蓝的blog” 博客。欢迎转载&#xff0c;转载时请务必注明出处。否则追究版权法律责任。表述有错误之处&#xf…

CentOS 7 下用 firewall-cmd / iptables 实现 NAT 转发供内网服务器联网

自从用 HAProxy 对服务器做了负载均衡以后&#xff0c;感觉后端服务器真的没必要再配置并占用公网IP资源。 而且由于托管服务器的公网 IP 资源是固定的&#xff0c;想上 Keepalived 的话&#xff0c;需要挤出来 3 个公网 IP 使用&#xff0c;所以更加坚定了让负载均衡后端服务器…

八皇后的一个回溯递归解法

解法来自严蔚敏的数据结构与算法。 代码如下&#xff1a; #include <iostream> using namespace std; const int N 8;//皇后数 int count 0;//解法统计 int a[N][N];//储存值的数组const char *YES "■"; const char *NO "□"; //const char *Y…

即时编译和提前编译_即时编译说明

即时编译和提前编译Just-in-time compilation is a method for improving the performance of interpreted programs. During execution the program may be compiled into native code to improve its performance. It is also known as dynamic compilation.即时编译是一种提…

bzoj 2588 Spoj 10628. Count on a tree (可持久化线段树)

Spoj 10628. Count on a tree Time Limit: 12 Sec Memory Limit: 128 MBSubmit: 7669 Solved: 1894[Submit][Status][Discuss]Description 给定一棵N个节点的树&#xff0c;每个点有一个权值&#xff0c;对于M个询问(u,v,k)&#xff0c;你需要回答u xor lastans和v这两个节点…

.Net SqlDbHelper

using System.Configuration; using System.Data.SqlClient; using System.Data;namespace ExamDAL {class SqHelper{#region 属性区// 连接字符串private static string strConn;public static string StrConn{get{return ConfigurationManager.ConnectionStrings["Exam&…