BZOJ 3922 - Karin的弹幕
Karin的弹幕
Problem's Link
----------------------------------------------------------------------------
Mean:
给定一个长度为n(1≤n≤70000)序列,有m(1≤m≤70000)次操作:
1. 对一段下标是等差数列的子序列求最大值;
2. 单点修改.
analyse:
如果公差很大,那么速度是很快的。所以我们考虑阈值.
Time complexity: O(N)
view code
/**
* -----------------------------------------------------------------
* Copyright (c) 2016 crazyacking.All rights reserved.
* -----------------------------------------------------------------
* Author: crazyacking
* Date : 2016-02-15-13.19
*/
#include <queue>
#include <cstdio>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#include <climits>
#include <map>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long(LL);
typedef unsigned long long(ULL);
const double eps(1e-); const int N=, MXD=, oo=(~0u>>)+;
int a[N], D, sz[MXD+][MXD+], b[N];
struct node *null;
struct node
{
node *c[];
int mx;
node()
{
c[]=c[]=;
mx=oo;
}
void up()
{
mx=max(c[]->mx, c[]->mx);
}
} Po[], *iT=Po, *root[MXD+][MXD+];
node *newnode()
{
return iT++;
}
node* build(int l, int r)
{
node *x=newnode();
if(l==r)
{
x->mx=b[l];
return x;
}
int mid=(l+r)>>;
x->c[]=build(l, mid);
x->c[]=build(mid+, r);
x->up();
return x;
}
int query(int L, int R, int l, int r, node *x)
{
if(L<=l && r<=R)
{
return x->mx;
}
int mid=(l+r)>>, ret=oo;
if(L<=mid)
{
ret=query(L, R, l, mid, x->c[]);
}
if(mid<R)
{
ret=max(ret, query(L, R, mid+, r, x->c[]));
}
return ret;
}
void update(int p, int go, int l, int r, node *x)
{
if(l==r)
{
x->mx+=go;
return;
}
int mid=(l+r)>>;
if(p<=mid)
{
update(p, go, l, mid, x->c[]);
}
else
{
update(p, go, mid+, r, x->c[]);
}
x->up();
}
void init(int n)
{
D=min(MXD, n);
for(int d=; d<=D; ++d)
{
for(int i=; i<=d; ++i)
{
int &s=sz[d][i];
for(int j=i; j<=n; j+=d)
{
b[++s]=a[j];
}
root[d][i]=build(, s);
}
}
}
int query(int x, int d, int n)
{
if(d>D)
{
int mx=oo;
for(int i=x; i<=n; i+=d)
{
mx=max(mx, a[i]);
}
return mx;
}
int begin=(x-)%d+, pos=(x-)/d+, len=sz[d][begin];
return query(pos, len, , len, root[d][begin]);
}
void update(int x, int y)
{
a[x]+=y;
for(int d=; d<=D; ++d)
{
int begin=(x-)%d+, pos=(x-)/d+, len=sz[d][begin];
update(pos, y, , len, root[d][begin]);
}
}
int main()
{
int n, m;
scanf("%d", &n);
for(int i=; i<=n; ++i)
{
scanf("%d", &a[i]);
}
init(n);
scanf("%d", &m);
while(m--)
{
int op, x, y;
scanf("%d%d%d", &op, &x, &y);
if(op)
{
printf("%d\n", query(x, y, n));
}
else
{
update(x, y);
}
}
return ;
}
BZOJ 3922 - Karin的弹幕的更多相关文章
- 【BZOJ】3922: Karin的弹幕
		
题意 给定一个长度为\(n(1 \le n \le 70000)\)序列,\(m(1 \le m \le 70000)\)次操作:1. 对一段下标是等差数列的子序列求最大值:2. 单点修改. 分析 如 ...
 - BZOJ3922 Karin的弹幕  【线段树】
		
题目链接 BZOJ3922 题解 考虑暴力,修改\(O(1)\),查询\(O(\frac{n}{d})\) 考虑线段树,如果对每种差值建一棵线段树,修改\(O(nlogn)\),查询\(O(logn) ...
 - 【线段树】bzoj3922 Karin的弹幕
		
设置一个值K. d<=K:建立多组线段树:d>K:暴力. 最优时间复杂度的伪计算: O(n*K*logn(建树)+m*logn(询问类型1)+m*n/K(询问类型2)+m*K*logn(修 ...
 - bzoj AC倒序
		
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
 - BZOJ 2127: happiness [最小割]
		
2127: happiness Time Limit: 51 Sec Memory Limit: 259 MBSubmit: 1815 Solved: 878[Submit][Status][Di ...
 - BZOJ 3275: Number
		
3275: Number Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 874 Solved: 371[Submit][Status][Discus ...
 - BZOJ 2879: [Noi2012]美食节
		
2879: [Noi2012]美食节 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1834 Solved: 969[Submit][Status] ...
 - bzoj 4610 Ceiling Functi
		
bzoj 4610 Ceiling Functi Description bzoj上的描述有问题 给出\(n\)个长度为\(k\)的数列,将每个数列构成一个二叉搜索树,问有多少颗形态不同的树. Inp ...
 - 又一枚精彩的弹幕效果jQuery实现
		
精彩的弹幕效果分享给大家,具有一定的参考价值,感兴趣的朋友可以尝试制作弹幕,具体内容如下 简易弹幕效果:将发布的内容随机显示在弹幕右侧,逐渐左移最后消失. 涉及知识点:val().random ...
 
随机推荐
- strcpy与strncpy
			
char aa[]="123456789123456789123456789"; char bb[4]={0}; 1.strcpy(bb,aa); bb的空间,不能存下aa的内容, ...
 - 六个前端开发工程师必备的Web设计模式/模块资源
			
Yahoo的设计模式库 Yahoo的设计模式库包含了很多可以帮助开发设计人员解决遇到的问题的资源,包括开发中常常需要处理的导航,互动效果及其布局网格等大家常用的组件和模块 响应式设计模式库 这个响应式 ...
 - C#基础视频教程4.3 如何编写简单的计算器
			
我们接着往下改,为了让这个计算器更加实用,我们要像官方的计算器一样可以接着计算(你算出来一笔数据之后,可以接着累加累减,我们暂时不考虑加括号,优先级之类的,因为绝大部分情况下我们打开计算器就是为了进行 ...
 - 用php编写我的第一段代码:hello world
			
一.php环境的搭建 在编写php前,先搭建php环境,我选择了一站式安装软件WampServer,WampServer的下载地址:http://www.wampserver.com/ WampSer ...
 - STDIN_FILENO vs stdin
			
数据类型不一致:stdin类型为 FILE*STDIN_FILENO类型为 int 使用stdin的函数主要有:fread.fwrite.fclose等,基本上都以f开头使用STDIN_FILENO的 ...
 - chrome 禁止自动更新
			
禁止chrome自动更新 CreateTime--2017年7月4日09:07:01Author:Marydon 版本号:59.0.3071.115 x64 第一步:禁止Google更新服务 参考 ...
 - this详解与面向对象编程
			
原文链接:http://www.cnblogs.com/kongxy/p/4581223.html JS中的this对象详解 声明:文章转载自上面地址,版权归阿孔所有,这里仅供本人学习笔记使用 t ...
 - jQuery通过text值来设置选定,以及遍历select的选项个数和遍历
			
真是醉了,网上搜了很久,全都是千篇一律的. 大家都拷贝来拷贝去,全是错的. 通过text值来设置select选定 $("#CompanyID").find("option ...
 - IntelliJ IDEA 学习(二):Intellij IDEA 创建Web项目并在Tomcat中部署运行IDEA
			
一.创建Web项目 1.File -> New Module,进入创建项目窗口 2.选择Java类型,在 Module name 处输入项目名,点击Next 3.勾选 Web Applicat ...
 - Mysql 数据库数值类型详解
			
MySQL 支持所有标准SQL 中的数值类型,其中包括严格数值类型(INTEGER.SMALLINT.DECIMAL 和NUMERIC),以及近似数值数据类型(FLOAT.REAL 和DOUBLE P ...