codeforces-315bSereja and Array
Time Limit: 1000MS |
|
Memory Limit: 262144KB |
|
64bit IO Format: %i64d &%i64u |
Submit Status Description Sereja have got an array, consisting Of n Integers, a 1,? A 2,?...,? A n . Sereja is a active boy, so he was now going to Complete m operations. Each operation would have one of the three forms:
- make v i -th array element equal To x i . In other words, perform the Assignment a v i ? =? X i .
- Increase each of the array element by yi. In other words, perform n assignments ai? =? Ai? +? Yi(1?≤? I? ≤? n).
- Take a piece of paper and write out the qi-th array element. That is, the element aqi.
Help Sereja, complete all his operations. Input The first line contains integers n, m(1?≤? N,? M.≤?105). The second line contains n space-separated integers a1,? A2,?...,? An(1?≤? ) Ai? ≤?109) -the original array. NextmLines describe operations, theI-th Line describes theI-th operation. The first number in theI-th Line is integer Ti (1?≤? ) Ti? ≤?3) That represents the operation type. If Ti? =?1 , then it was followed by and integers vi and xi ,(1?≤? ) Vi? ≤? N,? 1?≤? x i? ≤?109) . If Ti? =?2 , then it's followed by integer yi (1?≤? ) Yi? ≤?104) . And if Ti? =?3 , then it's followed by integer qi (1?≤? ) Qi? ≤? n) . Output For each third type operation print value aqi. Print the values in the order, with which the corresponding queries follow in the input. Sample Input Input10 111 2 3 4 5 6 7 8 9 103 23 92 103 13 101 1 102 102 103 13 103 9 Output291120304039
This topic everyone needs to think, do not see the topic on the line of the tree, to think there is no better way, the topic here gives three kinds of operations
It can be known that no one is operating on the interval, the only one is the whole array operation, and the effect on all the numbers.
So the code can be changed to the following:
/*author:2486memory:204 kbtime:93 mslanguage:gnu g++11 4.9.2result:acceptedvj runid:4206974real runid:12270208publi C:no yes*/#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;const int maxn= 1e5+5;int N,m,p,c,v,a[maxn];int Main () { scanf ("%d%d", &n,&m); for (int i=1; i<=n; i++) { scanf ("%d", &a[i]); } int cnt=0; while (m--) { scanf ("%d%d", &p,&c); if (p==1) { scanf ("%d", &v); a[c]=v-cnt; } else if (p==2) { cnt+=c; } else { printf ("%d\n", a[c]+cnt); } } return 0;}
|