【HDOJ】5057 Argestes and Sequence
树状数组,其实很简单。只是MLE。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; #define MAXN 100005 short sum[][][MAXN];
char bit[][][MAXN];
int a[MAXN];
int t, n, m;
int d, p;
const int MOD = ; int lowbit(int x) {
return x & -x;
} int getSum(int x, int d, int p) {
int ret = ;
while (x > ) {
ret += (int)sum[d][p][x] + ((int)bit[d][p][x]) * MOD;
x -= lowbit(x);
}
return ret;
} void update(int x, int d, int p, int r) {
int tmp;
while (x <= n) {
tmp = (int)sum[d][p][x] + r;
sum[d][p][x] = tmp%MOD;
bit[d][p][x] += tmp/MOD;
x += lowbit(x);
}
} int query(int l, int r) {
return getSum(r, d-, p) - getSum(l-, d-, p);
} void insert(int x, int i, int delta) {
int j;
for (j=; j<=; ++j) {
update(i, j-, x%, delta);
x /= ;
}
} int main() {
int i, j, ans;
int x, y;
char cmd[]; scanf("%d", &t);
while (t--) {
scanf("%d %d", &n, &m);
for(i=; i<; i++) {
for(j=; j<; j++) {
memset(sum[i][j], , sizeof(short)*(n+));
memset(bit[i][j], , sizeof(char)*(n+));
}
}
for (i=; i<=n; ++i) {
scanf("%d", &a[i]);
insert(a[i], i, );
}
while (m--) {
scanf("%*c%s %d %d", cmd, &x, &y);
if (cmd[] == 'S') {
insert(a[x], x, -);
a[x] = y;
insert(a[x], x, );
} else {
scanf("%d %d", &d, &p);
ans = query(x, y);
printf("%d\n", ans);
}
}
} return ;
}
【HDOJ】5057 Argestes and Sequence的更多相关文章
- 【HDOJ】5288 OO’s Sequence
二分寻找对于指定pos的最左因数点和最右因数点. /* 5288 */ #include <iostream> #include <string> #include <m ...
- 【HDOJ】5063 Operation the Sequence
#include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 100005 #defin ...
- 【分块】hdu5057 Argestes and Sequence
分块,v[i][j][k]表示第i块内第j位是k的元素数.非常好写.注意初始化 要注意题意,①第i位是从右往左算的. ②若x没有第i位,则用前导零补齐10位.比如103---->00000001 ...
- 【BZOJ1345】[Baltic2007]序列问题Sequence 贪心+单调栈
[BZOJ1345][Baltic2007]序列问题Sequence Description 对于一个给定的序列a1, …, an,我们对它进行一个操作reduce(i),该操作将数列中的元素ai和a ...
- hdu 5057 Argestes and Sequence(分块算法)
Argestes and Sequence Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu 5057 Argestes and Sequence
Argestes and Sequence Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- 【SPOJ】1182 Sorted bit sequence
[算法]数位DP [题解]动态规划 写了预处理函数却忘了调用是一种怎样的体验? #include<cstdio> #include<cstring> #include<a ...
- 【HDOJ】2062 Subset sequence
这道题目非常好,饶了点儿圈子.我的思路是,先按照组排列.例如,1 2 31 2 2 1 3 11 2 3 2 1 3 ...
- 【HDOJ】3397 Sequence operation
线段树的应用,很不错的一道题目.结点属性包括:(1)n1:1的个数:(2)c1:连续1的最大个数:(3)c0:连续0的最大个数:(4)lc1/lc0:从区间左边开始,连续1/0的最大个数:(5)rc1 ...
随机推荐
- 【LeetCode】Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2-& ...
- Percona Live 2016 PPT整理-zhaiwx_yinfeng
https://yq.aliyun.com/articles/54454?spm=5176.100239.bloglist.32.CllwIr
- Swift: 基本操作符
这里只讲一下Swift中比较特殊的操作符,在其他语言中也存在操作符就不再讲了 Nil-Coalescing Operator: ?? The nil-coalescing operator (a ?? ...
- 使用ef code first模式,在部署后服务器端把数据库同步到最新版本的方法
共有两种方法: 1.使用migrate.exe 具体使用方法请参考 msdn migrate使用方法,这里只做介绍 复制migrate.exe 在使用 NuGet 安装实体框架时,migrate.ex ...
- Adobe DreamweaverCS6安装及破解(序列号+破解补丁)
一:安装 1) Adobe DreamweaverCS6中文版下载地址:Adobe DreamweaverCS6中文版下载 2)Adobe DreamweaverCS6安装及破解说明下载地址:Adob ...
- ASP.NET 实现上一篇文章 下一篇文章
select top 1 * from job_hrnews where newsid>162 --下一篇 select top 1 * from job_hrnews where newsi ...
- 12、SQL Server 行列转换
SQL Server 行转列 在SQL Server 2005中PIVOT 用于将列值转换为列名(行转列),在SQL Server 2000中是没有这个关键字的 只能用case语句实现. --创建测试 ...
- ASP.NET5 静态文件
静态文件,包括HTML文件,CSS文件,图像文件和JavaScript文件,它是一个应用里所包含的资源. 1. 提供静态文件 默认的,静态文件存储在你的webroot目录下面,webroot的路径定义 ...
- android studio主题设置-笔记3
主题背景设置(就是工具黑色背景还是白色背景),路径:File-Settings-Appearance
- (转)Android调用系统自带的文件管理器进行文件选择并获得路径
Android区别于iOS的沙盒模式,可以通过文件浏览器浏览本地的存储器.Android API也提供了相应的接口. 基本思路,先通过Android API调用系统自带的文件浏览器选取文件获得URI, ...