【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 ...
随机推荐
- 浅析Android中的消息机制-解决:Only the original thread that created a view hierarchy can touch its views.
在分析Android消息机制之前,我们先来看一段代码: public class MainActivity extends Activity implements View.OnClickListen ...
- git 在linux中的使用
1,经常使用操作 一,clone远程仓库 比如clone test项目的分支v1.0 git -c diff.mnemonicprefix=false -c core.quotepath=false ...
- [Firebase] Deploy you website to Firebase
If you are looking for a host website, you can try Firebase, heroku or AWS... Today, I tried to depl ...
- PHP安全编程:shell命令注入(转)
使用系统命令是一项危险的操作,尤其在你试图使用远程数据来构造要执行的命令时更是如此.如果使用了被污染数据,命令注入漏洞就产生了. exec()是用于执行shell命令的函数.它返回执行并返回命令输出的 ...
- MYSQL 体系结构图-log (踏雪无痕) (UC技术博客)
http://www.cnblogs.com/chenpingzhao/category/690116.html http://www.cnblogs.com/chenpingzhao/p/51074 ...
- linux下显卡信息的查看
lspci | grep -i vga 这样就可以显示机器上的显卡信息,比如 [root@localhost conf]# lspci | grep -i vga01:00.0 VGA compat ...
- Java 8 Features – The ULTIMATE Guide--reference
Now, it is time to gather all the major Java 8 features under one reference post for your reading pl ...
- 第五篇:R语言数据可视化之散点图
散点图简介 散点图通常是用来表述两个连续变量之间的关系,图中的每个点表示目标数据集中的每个样本. 同时散点图中常常还会拟合一些直线,以用来表示某些模型. 绘制基本散点图 本例选用如下测试数据集: 绘制 ...
- RxJava RxAndroid【简介】
资源 RxJava:https://github.com/ReactiveX/RxJava RxAndroid :https://github.com/ReactiveX/RxAndroid 官网:h ...
- jquery对同级的td做radio限制
<html> <head> <title></title> <script src="http://libs.baidu.com/jqu ...