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 ...
随机推荐
- 开发自己的One Page Scroll插件(二)
开发自己的One Page Scroll插件(一) 5. 在其他浏览器中的特性 我经常会不停地发布当前的版本,从而可以在GitHub上得到不断的反馈.我的开发模式是不断的迭代.在开始的时候,我不会太关 ...
- ARC下 does not support automated __weak references错误
ARC下 does not support automated __weak references错误 此错误,通常是你的ARC下不支持weak 把你项目里面,weak的地方 改为 unsafe_un ...
- java记录linux top命令信息
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.Fi ...
- 深入理解javascript闭包【整理】
原文链接:http://www.cn-cuckoo.com/2007/08/01/understand-javascript-closures-72.html 英文原文:http://www.jibb ...
- http请求返回405
普通情况下,是你用了默认method=get,须要改为post
- ERP,SCM,CRM,BRP,OMS,WMS 企业管理的6大核心系统
[导读]:人体共有八大系统:运动系统.神经系统.内分泌系统.循环系统.呼吸系统.消化系统.泌尿系统.生殖系统.这些系统协调配合,使人体内各种复杂的生命活动能够正常进行. 同理,企业要想健康的运转,长久 ...
- css-input与文字的对齐
前言 目前中文网站上面的文字,就我的个人感觉而言,绝大多数网站的主流文字大小为12px,因为在目前高分辨率显示器屏幕下,11px的汉字,其像素点开始不 规整,文字不如12px来的显示良好.12px大小 ...
- 如何成为一位黑客 ( How To Become A Hacker )
http://blog.csdn.net/jarodlau/article/details/337891 How To Become A Hacker 如何成为一位黑客(转载) 这真是一个好问题,不止 ...
- 如何处理JSON中的特殊字符 介绍几种解决方案
http://www.nowamagic.net/librarys/veda/detail/216JSON 是适用于 Ajax 应用程序的一种有效格式,原因是它使 JavaScript 对象和字符串值 ...
- HttpSolrServer 实例管理参考,来自org.eclipse.smila.solr
http://dev.eclipse.org/svnroot/rt/org.eclipse.smila/trunk/core/org.eclipse.smila.solr/code/为什么要对实例管理 ...