• D - All Assign Point Add


    D - All Assign Point Add

    Score : 400400 points

    Problem Statement

    You are given a sequence A = (A_1, A_2, \dots, A_N)A=(A1​,A2​,…,AN​) of length NN.

    Given QQ queries, process all of them in order. The qq-th (1\leq q\leq Q)(1≤q≤Q) query is in one of the following three formats, which represents the following queries:

    • 1\ x _ q1 xq​: assign x_qxq​ to every element of AA.
    • 2\ i _ q\ x _ q2 iq​ xq​: add x_qxq​ to A _ {i _ q}Aiq​​.
    • 3\ i _ q3 iq​: print the value of A _ {i _ q}Aiq​​.

    Constraints

    • 1 \leq N \leq 2\times10^51≤N≤2×105
    • 1 \leq Q \leq 2\times10^51≤Q≤2×105
    • 0 \leq A _ i \leq 10^9\ (1\leq i\leq N)0≤Ai​≤109 (1≤i≤N)
    • If the qq-th (1\leq q\leq Q)(1≤q≤Q) query is in the second or third format, 1 \leq i _ q \leq N1≤iq​≤N.
    • If the qq-th (1\leq q\leq Q)(1≤q≤Q) query is in the first or second format, 0 \leq x _ q \leq 10^90≤xq​≤109.
    • There exists a query in the third format.
    • All values in the input are integers.

    Input

    The input is given from Standard Input in the following format:

    NN
    A_1A1​ A_2A2​ \dots… A_NAN​
    QQ
    \operatorname{query}_1query1​
    \operatorname{query}_2query2​
    \vdots⋮
    \operatorname{query}_QqueryQ​
    

    Here, \operatorname{query}_qqueryq​ denotes the qq-th query, which is in one of following formats: 1 x2 i x, and 3 i.

    Output

    Print XX lines, where XX is the number of qq's (1\leq q\leq Q)(1≤q≤Q) such that \operatorname{query}_qqueryq​ is in the third format. The jj-th (1\leq j\leq X)(1≤j≤X) line should contain the answer to the jj-th such query.


    Sample Input 1 Copy

    Copy

    5
    3 1 4 1 5
    6
    3 2
    2 3 4
    3 3
    1 1
    2 3 4
    3 3
    

    Sample Output 1 Copy

    Copy

    1
    8
    5
    

    Initially, A=(3,1,4,1,5)A=(3,1,4,1,5). The queries are processed as follows:

    • A_2=1A2​=1, so print 11.
    • Add 44 to A_3A3​, making A=(3,1,8,1,5)A=(3,1,8,1,5).
    • A_3=8A3​=8, so print 88.
    • Assign 11 to every element of AA, making A=(1,1,1,1,1)A=(1,1,1,1,1).
    • Add 44 to A_3A3​, making A=(1,1,5,1,1)A=(1,1,5,1,1).
    • A_3=5A3​=5, so print 55.

    Sample Input 2 Copy

    Copy

    1
    1000000000
    8
    2 1 1000000000
    2 1 1000000000
    2 1 1000000000
    2 1 1000000000
    2 1 1000000000
    2 1 1000000000
    2 1 1000000000
    3 1
    

    Sample Output 2 Copy

    Copy

    8000000000
    

    Note that the elements of AA may not fit into a 3232-bit integer type.


    Sample Input 3 Copy

    Copy

    10
    1 8 4 15 7 5 7 5 8 0
    20
    2 7 0
    3 7
    3 8
    1 7
    3 3
    2 4 4
    2 4 9
    2 10 5
    1 10
    2 4 2
    1 10
    2 3 1
    2 8 11
    2 3 14
    2 1 9
    3 8
    3 8
    3 1
    2 6 5
    3 7
    

    Sample Output 3 Copy

    Copy

    7
    5
    7
    21
    21
    19
    10
    

    1. #include
    2. #include
    3. #include
    4. using namespace std;
    5. const int N = 2e5 + 5;
    6. map<int,pair<int, unsigned long long>> m;
    7. long long tag=0,ti=0;
    8. int main()
    9. {
    10. int n;
    11. cin >> n;
    12. for (int i = 1; i <= n; i++)
    13. {
    14. long long e;
    15. cin >>e;
    16. m[i].first = 0;
    17. m[i].second = e;
    18. }
    19. int q;
    20. cin >> q;
    21. int t;
    22. for (int i = 1; i <= q; i++)
    23. {
    24. cin >> t;
    25. if (t == 1)
    26. {
    27. cin >> tag;
    28. ti = i;//tag最近的更新操作是第ti次
    29. }
    30. else if (t == 2)
    31. {
    32. unsigned long long o, x;
    33. cin >> o >> x;
    34. if(m[o].first
    35. m[o].second = x;
    36. else//如果tag更新的操作在上一次给m[o]加值之后,则在上次值后加值
    37. m[o].second += x;
    38. m[o].first = i;
    39. }
    40. else if (t == 3)
    41. {
    42. int p;
    43. cin >> p;
    44. if (m[p].first < ti)
    45. {
    46. cout << tag << endl;
    47. }
    48. else
    49. {
    50. cout << tag + m[p].second << endl;
    51. }
    52. }
    53. }
    54. }

  • 相关阅读:
    xctf攻防世界 Web高手进阶区 webshell
    地理标志农产品质量安全风险评估及预警研究
    计算机毕业设计选什么题目好?springboot 社区流浪动物救助领养系统
    JAVA中的垃圾回收器(1)
    Linux华硕笔记本安装ROG Asusctl
    JS VUE 用 canvas 给图片加水印
    vmware中的linux虚拟机如何增加磁盘容量
    陕西Biotin-LC_CAS:72040-64-3_N-生物素氨基己酸供应商价格
    彩灯控制器设计 74ls160+ne555实现
    三、OO三大特性
  • 原文地址:https://blog.csdn.net/weixin_62599885/article/details/127942983