首页 技术 正文
技术 2022年11月8日
0 收藏 873 点赞 2,126 浏览 2110 个字

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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,564
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,412
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,185
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905