2062. Ambitious Experiment

Time limit: 3.0 second
Memory limit: 128 MB
During several decades, scientists from planet Nibiru are working to create an engine that would allow spacecrafts to fall into hyperspace and move there with superluminal velocity. To check whether their understanding of properties of hyperspace is right, scientists have developed the following experiment.
A chain of n particles is placed in hyperspace. Positions of particles in the chain are numbered from 1 to n. Initially, ith particle has charge ai.
According to the current theory, if particle number i got special radiation with power d, oscillations would spread by hyperspace and increase by d charge of particles with numbers i, 2i, 3iand so on (i.e. with numbers divisible by i).
Using a special device, scientists can direct the radiation of the same power at a segment of adjacent particles. For example, suppose that initially there were 6 particles with zero charges, and scientists have sent radiation with power five to particles with numbers 2 and 3. Then charge of 2nd, 3rd, and 4th particles will increase to five, and charge of 6th particle will increase to ten (the oscillations will reach it twice). Charge of other particles won’t change.
Charge of particles can’t change without impact of the device.
During the experiment, the scientists plan to perform actions of the following types:
  1. Measure current charge of the particle number i.
  2. Direct radiation with power d at particles with numbers from l to r inclusive.
Your program will be given a list of performed actions. For every action of the first type the program should output value of expected charge of the particle calculated in accordance with the current theory described above.
If the expected charges of the particles coincide with charges measured during the experiment, it will turn out that scientists’ understanding of hyperspace is right, and they will be able to start building of the hyperdrives. Then inhabitants of Nibiru will finally meet their brothers from Earth in just a few years!

Input

The first line contains a single integer n — number of particles (1 ≤ n ≤ 3 · 105).
The second line contains n integers ai separated by spaces — initial charges of the particles (0 ≤ ai ≤ 106).
The third line contains a single integer q — number of actions in the experiment (1 ≤ q ≤ 3 · 105).
Each of the following q lines contain two or four integers — a description of the next action in one of the following formats:
  • i — measure current charge of the particle number i (1 ≤ i ≤ n).
  • l r d — direct radiation with power d at particles with numbers from l to r inclusive (1 ≤l ≤ r ≤ n, 0 ≤ d ≤ 106).

Output

For each query output the expected charge of the ith particle.

Samples

input output
3
1 2 3
2
2 1 3 5
1 2
12
6
1 2 1 4 5 6
5
2 2 4 2
1 3
1 4
2 3 5 1
1 5
3
8
6
Problem Author: Alexey Danilyuk (prepared by Nikita Sivukhin)
Problem Source: Ural Regional School Programming Contest 2015
Difficulty: 478
 
 
题意:给n个数,两种操作:1、询问x的值,2、修改l~r的值,对于每个l<=i<=r的i,都对 i,2i,3i....这些点加d
分析:首先很容易想到分块做法
对于每个点x,它对于其他点(2x,3x,....)的贡献都是一样的
那么对于每个查询的点x,对它有贡献的点就是是他的因数的那些点
那么修改就分段sqrt(n)暴力修改
查询就sqrt(x)枚举约数,查询到每一个贡献点的值加起来
 
 /**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mk make_pair inline int getInt()
{
int ret = ;
char ch = ' ';
bool flag = ;
while(!(ch >= '' && ch <= ''))
{
if(ch == '-') flag ^= ;
ch = getchar();
}
while(ch >= '' && ch <= '')
{
ret = ret * + ch - '';
ch = getchar();
}
return flag ? -ret : ret;
} const int N = , M = ;
int n, m;
LL block[N / M + ][M], tag[N / M + ], arr[N]; inline int getBlockIndex(int x)
{
return x / M;
} inline int getIndex(int x)
{
return x % M;
} inline void input()
{
cin >> n;
for(int i = ; i < n; i++) cin >> arr[i];
} inline LL work(int x)
{
int b = getBlockIndex(x), idx = getIndex(x);
return block[b][idx] + tag[b];
} inline LL query(int x)
{
x++;
LL ret = ;
for(int i = ; i * i <= x; i++)
if(x % i == )
{
ret += work(i - );
if(x / i != i) ret += work(x / i - );
}
return ret;
} inline void change(int l, int r, int d)
{
int left = getBlockIndex(l), right = getBlockIndex(r);
for(int i = left + ; i <= right - ; i++) tag[i] += d;
if(left < right)
{
for(int i = getIndex(l); i < M; i++) block[left][i] += d;
for(int i = ; i <= getIndex(r); i++) block[right][i] += d;
}
else
{
for(int i = getIndex(l); i <= getIndex(r); i++)
block[left][i] += d;
}
} inline void solve()
{
for(cin >> m; m--; )
{
int opt, l, r, x;
cin >> opt;
if(opt == )
{
cin >> x;
x--;
cout << query(x) + arr[x] << "\n";
}
else
{
cin >> l >> r >> x;
l--, r--;
change(l, r, x);
}
}
} int main()
{
ios::sync_with_stdio();
input();
solve();
return ;
}

ural 2062 Ambitious Experiment的更多相关文章

  1. URAL 2062 Ambitious Experiment(分块)

    [题目链接] http://acm.timus.ru/problem.aspx?space=1&num=2062 [题目大意] 给出两个操作,操作一给出区间[l,r],对l到r中的每一个下标i ...

  2. ural2062 Ambitious Experiment

    Ambitious Experiment Time limit: 3.0 secondMemory limit: 128 MB During several decades, scientists f ...

  3. Ural 2062:Ambitious Experiment(树状数组 || 分块)

    http://acm.timus.ru/problem.aspx?space=1&num=2062 题意:有n个数,有一个值,q个询问,有单点询问操作,也有对于区间[l,r]的每个数i,使得n ...

  4. ural Ambitious Experiment 树状数组

    During several decades, scientists from planet Nibiru are working to create an engine that would all ...

  5. 【树状数组】【枚举约数】 - Ambitious Experiment

    给定一个序列,支持以下操作: 对区间[l,r]的每个i,将1i,2i,3i,...这些位置的数都加d. 询问某个位置的数的值. 如果把修改看作对区间[l,r]的每个数+d,那么询问x位置上的数时,显然 ...

  6. URAL 2062 树状数组

    一个长度为n的数组 每次对lr区间进行修改 如果要修改i 则对i i*2 i*3...都修改 最后单点查询值 思想是利用树状数组维护每一个区间的更新值 查询的时候得出这个点的所有因子的查询值的和 加上 ...

  7. An interesting experiment on China’s censorship

    This paper presented a very interesting topic. Censorship in China has always drawn people's attenti ...

  8. Reading With Purpose: A grand experiment

    Reading With Purpose: A grand experiment This is the preface to a set of notes I'm writing for a sem ...

  9. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

随机推荐

  1. .net 获取https页面的信息 在iis7.5服务器上不管用

    让我纠结了一天多的问题,给大家看下,有相同情况的可以不用浪费时间了,本人当时找了好半天都没找到什么有用的信息,项目在本地没有问题,但部署在服务器后,获取不到https页面的信息,加入下面的代码就可以了 ...

  2. js windows对象

    一.DOM操作 windows对象操作 document对象操作     二.属性.事件 1.window的属性: window.shuxing(属性) window.fangfa()(方法) 方法后 ...

  3. iOS 百度地图坐标标注

    注:由于iOS9改用更安全的https,为了能够在iOS9中正常使用地图SDK,请在"Info.plist"中进行如下配置,否则影响SDK的使用. <key>NSApp ...

  4. hdu1798(几何面积计算)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1798 题意:给出两个圆的圆心坐标与半径,求他们相交部分的大小 思路:有三种情况: 1. 两圆相离,ar ...

  5. 数据结构之AVL树

    AVL树是高度平衡的而二叉树.它的特点是:AVL树中任何节点的两个子树的高度最大差别为1. 旋转 如果在AVL树中进行插入或删除节点后,可能导致AVL树失去平衡.这种失去平衡的可以概括为4种姿态:LL ...

  6. 通过btn获取所在cell

    [cell.btn addTarget:self action:@selector(cellBtnClicked:event:) forControlEvents:UIControlEventTouc ...

  7. 傻瓜式十分钟免费开启 HTTPS,是时候为你的站点加上小绿锁了

    http://gold.xitu.io/entry/57df65690bd1d00057f9455b?from=singlemessage&isappinstalled=0 原文链接:http ...

  8. 图结构练习——判断给定图是否存在合法拓扑序列(dfs算法(第一个代码),邻接矩阵(前两个代码),邻接表(第三个代码))

    sdut 2140 图结构练习——判断给定图是否存在合法拓扑序列 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述  给定一个有向图 ...

  9. JavaScript是如何实现继承的(六种方式)

    大多OO语言都支持两种继承方式: 接口继承和实现继承 ,而ECMAScript中无法实现接口继承,ECMAScript只支持实现继承,而且其实现继承主要是依靠原型链来实现,下文给大家技术js实现继承的 ...

  10. <转>删除文件夹下所有的.svn文件

    当使用了svn版本控制系统后每个目录下都会有一个.svn目录存在,开发完当交付产品或者上传到服务器时一般要把这些目录删除,这里总结了一下在linux和win下的办法. 一.在linux下 删除这些目录 ...