树状数组,其实很简单。只是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的更多相关文章

  1. 【HDOJ】5288 OO’s Sequence

    二分寻找对于指定pos的最左因数点和最右因数点. /* 5288 */ #include <iostream> #include <string> #include <m ...

  2. 【HDOJ】5063 Operation the Sequence

    #include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 100005 #defin ...

  3. 【分块】hdu5057 Argestes and Sequence

    分块,v[i][j][k]表示第i块内第j位是k的元素数.非常好写.注意初始化 要注意题意,①第i位是从右往左算的. ②若x没有第i位,则用前导零补齐10位.比如103---->00000001 ...

  4. 【BZOJ1345】[Baltic2007]序列问题Sequence 贪心+单调栈

    [BZOJ1345][Baltic2007]序列问题Sequence Description 对于一个给定的序列a1, …, an,我们对它进行一个操作reduce(i),该操作将数列中的元素ai和a ...

  5. hdu 5057 Argestes and Sequence(分块算法)

    Argestes and Sequence Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  6. hdu 5057 Argestes and Sequence

    Argestes and Sequence Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  7. 【SPOJ】1182 Sorted bit sequence

    [算法]数位DP [题解]动态规划 写了预处理函数却忘了调用是一种怎样的体验? #include<cstdio> #include<cstring> #include<a ...

  8. 【HDOJ】2062 Subset sequence

    这道题目非常好,饶了点儿圈子.我的思路是,先按照组排列.例如,1            2           31 2         2 1        3 11 2 3      2 1 3  ...

  9. 【HDOJ】3397 Sequence operation

    线段树的应用,很不错的一道题目.结点属性包括:(1)n1:1的个数:(2)c1:连续1的最大个数:(3)c0:连续0的最大个数:(4)lc1/lc0:从区间左边开始,连续1/0的最大个数:(5)rc1 ...

随机推荐

  1. 第一篇:数据库需求与ER建模

    前言 在数据库建设过程中,哪一步最重要?绝大多数资料会告诉你,是需求分析阶段.这一步的好坏甚至直接决定数据库项目的成败. 需求分析阶段,也被称为ER建模(entity-relationship mod ...

  2. [转] linux下的c/c++调试器gdb

    PS:1. 断点C++类函数,用b 命名空间::类名::方法名 2. 编译参数一定要加-g,才可断点调试 http://www.cnblogs.com/xd502djj/archive/2012/08 ...

  3. Linux 基本命令(持续更新ing)

    cd -> 变换路径                        //文件一般存在/var/路径下,var为可修改存储盘 ls -> 列出所有隐藏文件与相关文件的属性   #ls -al ...

  4. noip 2012 疫情控制

    /* 考试的时候没想出正解 也没打暴力 时间不够了 随便yy了几种情况按出现的先后顺序处理而没有贪心 的了20分 不粘了 正解是围绕首都的儿子来搞的 显然先二分答案 对于每个限定的最大时间 我们尝试着 ...

  5. C#中的操作数据库的SQLHelper类

    using System; using System.Collections.Generic; using System.Configuration; using System.Data; using ...

  6. http2.0

    HTTP2.0性能增强的核心:二进制分帧 HTTP 2.0最大的特点: 不会改动HTTP 的语义,HTTP 方法.状态码.URI 及首部字段,等等这些核心概念上一如往常,却能致力于突破上一代标准的性能 ...

  7. java获取对象属性类型、属性名称、属性值 【转】

    /** * 根据属性名获取属性值 * */ private Object getFieldValueByName(String fieldName, Object o) { try { String ...

  8. Oracle 创建分页存储过程(转帖)

    原贴地址:http://19880614.blog.51cto.com/4202939/1316560 ps:源代码还有很多错误,我修改了 ------------------------------ ...

  9. scn转换为十进制

  10. 【原】push过快的错误 (Pushing the same view controller instance more than once is not supported)

    今天在点击按钮push viewController 时,控制台报错: Terminating app due to uncaught exception 'NSInvalidArgumentExce ...