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. LoadRunner函数

    一.基础函数简介 在VU左边导航栏中,有三个LoadRunner框架函数,分别是vuser_init().Action().vuser_end().这三个函数存在于任何Vuser类型的脚本中. vus ...

  2. AJAX 汽车详细信息练习

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. C#学习笔记-----C#枚举中的位运算权限分配

    一.基础知识 什么是位运算? 用二进制来计算,1&2:这就是位运算,其实它是将0001与0010做位预算   得到的结果是 0011,也就是3  2.位预算有多少种?(我们就将几种我们权限中会 ...

  4. 对Cookie和Session的深入理解

    session对象 session对象用于存储特定的用户会话所需的信息 . Session对象的引入是为了弥补HTTP协议的不足.HTTP协议本身是无状态的,这与HTTP协议本来的目的是相符的,客户端 ...

  5. djcelery的细节篇

    http://blog.csdn.net/samed/article/details/50598371 随时撸一撸,要点记心间.. 1. 下面讲解一下celery.py文件的配置内容,为何要这么配置. ...

  6. 【20140113】package 与 import

    一个完整的java源程序应该包括下列部分: package语句: //该部分至多只有一句,必须放在源程序的第一句 import语句: public classDefinition: //公共类定义部分 ...

  7. HDU4495 Rectangle

    求组成的等腰三角形面积最大值. 对此题的总结:暴力出奇迹 组成的三角形放置方式一共只有4种,用ans表示目前已知的最长三角形的边长,从上到下,从左到右枚举顶点,再枚举边长,一个重要剪枝是枚举边长l时先 ...

  8. Win10 创建应用程序包及部署

    https://msdn.microsoft.com/zh-cn/library/windows/apps/xaml/hh454036.aspx https://msdn.microsoft.com/ ...

  9. WPF Navigation

    在开始学习WPF时,一开始对WPF的Window, Page, UserControl感到很迷惑.不知道什么时候该使用哪一个.下面简单介绍一下这三者的区别. Window:故名思意,桌面程序的窗体.在 ...

  10. 深入理解ASP.NET 5的依赖注入

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:ASP.NET 5整个底层都架构于依赖注入机制之下,今天介绍的文章详细介绍了内置依赖注 ...