国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Ural 2062

2019-11-08 03:26:40
字體:
來源:轉載
供稿:網友

Time limit: 3.0 second
Memory limit: 128 MB

Description

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, *i*th 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, 2*i*, 3*i* and 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:

Measure current charge of the particle number i.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 a**i 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:

1 i — measure current charge of the particle number i (1 ≤ in).2 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 *i*th particle.

題意

給定 n 個數,每個數均有一個初值 a1,a2,...,an。之后有 q 個操作。操作分為兩種:

給定 1 i ——要求輸出當前點 i 的值給定 2 l r d —— 將區間 [l, r] 內的每一點 k ,將 k, 2k, 3k, 4k, … 位置上的值都加上 d 。

分析

很顯然,初始值不會對后續的操作產生任何影響,此處僅需要單獨保存在一個數組中,在每次詢問的最后加上初值就可以。

考慮到區間更新,單點查詢的話,很容易能夠想到套用樹狀數組的板。

但是,此處的區間更新顯示不只是更新區間,區間內的點同時也會對其倍數點產生影響。如果考慮在更新的同時更新后續倍數點,復雜度顯然無法滿足條件。因此,對于2 l r d ,僅考慮更新區間 [l, r] 。單次操作復雜度為 O(logN)

由于上述無法處理區間更新帶來的后續倍數點的更新,故在單點查詢過程中必須對最后結果加以保證。我想到的方法是——每個點的更新對其倍數點產生影響,可以理解為每個點的值必須考慮其約數點對其的影響,故暴力尋找點的約數,并通過單點查詢獲取對當前值的貢獻。單次操作復雜度O(logN×N??√)

雖然覺得這個代碼是不可能過的,但是,抱著試一試的態度,果斷Accepted

代碼

#include<bits/stdc++.h>using namespace std;const int N = 1e6 + 10;int a[N];long long bin[N];inline int lowbit(int x){return x & -x;}long long sum(int x){ long long res = 0; for(int i=x;i;i-=lowbit(i)) res += bin[i]; return res;}void add(int x,int w){ for(int i=x;i<N;i+=lowbit(i)) bin[i] += w;}void update(int x,int y,int w){ add(x,w); add(y+1,-w);}int main(){ int n,q; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); scanf("%d",&q); for(int i=0,typ,l,r,val,x;i<q;i++) { scanf("%d",&typ); if(typ == 2) { scanf("%d %d %d",&l,&r,&val); update(l, r, val); } else { scanf("%d",&x); long long ans = a[x]; int seq = sqrt(x+0.5); for(int i=1;i<=seq;i++) { if(x % i == 0) { ans += sum(i); if(i*i != x) ans += sum(x/i); } } printf("%I64d/n",ans); } }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 法库县| 固始县| 郴州市| 府谷县| 西乡县| 马龙县| 湖南省| 寿宁县| 安仁县| 沙洋县| 临沭县| 金山区| 岱山县| 吴江市| 阿拉尔市| 孟州市| 左云县| 海原县| 德州市| 晋城| 兴国县| 和田县| 漳浦县| 信宜市| 鹤庆县| 北京市| 平和县| 晋江市| 巢湖市| 隆化县| 邢台市| 上林县| 安徽省| 迭部县| 嘉黎县| 阿拉善盟| 镇远县| 碌曲县| 台东市| 碌曲县| 盐津县|