树状数组。Easy.

 /* 4267 */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 const int maxn = ;
const int maxm = ;
int n; inline int lowest(int x) {
return -x & x;
} typedef struct arr_t {
int s[maxn]; void clr() {
memset(s, , sizeof(s));
} void update(int x, int delta) {
while (x <= n) {
s[x] += delta;
x += lowest(x);
}
} int sum(int x) {
int ret = ; while (x) {
ret += s[x];
x -= lowest(x);
}
return ret;
}
} arr_t; arr_t ts[maxm];
int A[maxn], M[][maxn];
int ID[][]; void init_() {
int cnt = ; rep(i, , ) {
rep(j, , i) {
ID[i][j] = cnt++;
}
} rep(i, , ) {
int k = i-;
rep(j, , maxn) {
M[k][j] = M[k][j-] + ;
if (M[k][j] == i)
M[k][j] = ;
}
}
} void init() {
rep(i, , maxm)
ts[i].clr();
} void update(int a, int b, int k, int delta) {
int from = a;
int to = a+(b-a)/k*k;
int findex = (from+k-)/k;
int tindex = (to+k-)/k;
int id = ID[k][a%k]; ts[id].update(findex, delta);
ts[id].update(tindex+, -delta);
} int sum(int x) {
int id, index, delta;
int ret = ; rep(i, , ) {
index = (x+i-)/i;
id = ID[i][M[i-][x]];
delta = ts[id].sum(index);
ret += delta;
}
return ret;
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif int type;
int a, b, k, c;
int q;
int ans; init_();
while (scanf("%d", &n)!=EOF) {
rep(i, , n+)
scanf("%d", &A[i]);
init();
scanf("%d", &q);
while (q--) {
scanf("%d %d", &type, &a);
if (type == ) {
scanf("%d %d %d", &b, &k, &c);
update(a, b, k, c);
} else {
ans = sum(a) + A[a];
printf("%d\n", ans);
}
}
} #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}

【HDOJ】4267 A Simple Problem with Integers的更多相关文章

  1. 【POJ】3468 A Simple Problem with Integers ——线段树 成段更新 懒惰标记

    A Simple Problem with Integers Time Limit:5000MS   Memory Limit:131072K Case Time Limit:2000MS Descr ...

  2. 【POJ】3468 A Simple Problem with Integers

    这题用线段树轻松解了,重新用树状数组解,关键点是区间更新.公式推导如下:sum[x] = org_sum[x] + delta[1]*x + delta[2]*(x-1) + delta[x]*1   ...

  3. HDU 4267 A Simple Problem with Integers

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  4. HDU 4267 A Simple Problem with Integers(树状数组区间更新)

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  5. 【树状数组区间修改单点查询+分组】HDU 4267 A Simple Problem with Integers

    http://acm.hdu.edu.cn/showproblem.php?pid=4267 [思路] 树状数组的区间修改:在区间[a, b]内更新+x就在a的位置+x. 然后在b+1的位置-x 树状 ...

  6. 【HDOJ】4972 A simple dynamic programming problem

    水题. #include <cstdio> #include <cstring> #include <cstdlib> int abs(int x) { ? -x: ...

  7. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  8. HDOJ 4267 A Simple Problem with Integers (线段树)

    题目: Problem Description Let A1, A2, ... , AN be N elements. You need to deal with two kinds of opera ...

  9. 【HDOJ】3828 A + B problem

    显然需要贪心,重叠越长越好,这样最终的串长尽可能短.需要注意的是,不要考虑中间结果,显然是个状态dp.先做预处理去重,然后求任意一对串的公共长度. /* 3828 */ #include <io ...

随机推荐

  1. Jquery中Ajax异步请求中的async参数的作用

    之前不知道这个参数的作用,上网找了前辈的博客,在此收录到自己的博客,希望能帮到更多的朋友: test.html <a href="javascript:void(0)" on ...

  2. 检测PC端和移动端的方法总结

    正在苦逼的实习中,昨天公司让做一个页面,涉及到检测终端的问题,如果是手机设备,就跳转到指定的网页上,以前写响应式布局只要用@media screen来实现布局的差异化适应,但是现在不仅仅是布局,还要针 ...

  3. Hdu 1042 N! (高精度数)

    Problem Description Givenan integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input OneN in one ...

  4. Boot Petalinux Project Using a remote system

    通过jtag实现在远程服务器端下载petalinux image到连接在本地PC的开发板上的方法. 具体连接方式为 比如Host的系统为Windows,Remote system为运载在远程服务器上的 ...

  5. [翻译][MVC 5 + EF 6] 8:更新相关数据

    原文:Updating Related Data with the Entity Framework in an ASP.NET MVC Application 1.定制Course的Create和E ...

  6. (转)web.config 为某个单独页面设置编码格式

    原文链接:http://www.cnblogs.com/mytechblog/articles/1937407.html 全站应用utf-8格式,在web.config里的<system.web ...

  7. 路由器无线桥接 router wireless bridge

    实验环境:TP-Link A,TP-Link B,两个路由器都有子网,分别为子网 A,子网 B.TP-Link A连接学校子网 IP A,TP-Link B连接学校子网 IP B.两个路由器都能够通过 ...

  8. 简单重置Centos服务器中Mysql的root密码

    1.编辑MySQL配置文件my.cnf vi /etc/my.cnf #编辑文件,找到[mysqld],在下面添加一行skip-grant-tables [mysqld] skip-grant-tab ...

  9. div+css实现的左右两个等高div

    工作当中我们经常会有这样的需求,尤其是在一些内容页面或者网站后台管理页面:左边的div的高度会随着右边的div的内容的增加儿增加,右边div的高度也会随着左边div的内容的增加而增加,也就是左右两侧两 ...

  10. 巧妙使用checkbox制作纯css动态导航栏

    前提:很多时候.我们的网页都需要一个垂直的导航栏.可以分类.有分类.自然就有展开.关闭的功能.你还在使用jquery操作dom来制作吗?那你就out了! 方案:使用checkbox 的 checked ...