2018 徐州网络赛 H

Ryuji is not a good student, and he doesn‘t want to study. But there are n books he should learn, each book has its knowledge a[i]a[i].

Unfortunately, the longer he learns, the fewer he gets.

That means, if he reads books from ll to rr, he will get a[l] \times L + a[l+1] \times (L-1) + \cdots + a[r-1] \times 2 + a[r]a[l]×L+a[l+1]×(L−1)+?+a[r−1]×2+a[r] (LL is the length of [ ll, rr ] that equals to r - l + 1r−l+1).

Now Ryuji has qq questions, you should answer him:

11. If the question type is 11, you should answer how much knowledge he will get after he reads books [ ll, rr ].

22. If the question type is 22, Ryuji will change the ith book‘s knowledge to a new value.

Input

First line contains two integers nn and qq (nn, q \le 100000q≤100000).

The next line contains n integers represent a[i]( a[i] \le 1e9)a[i](a[i]≤1e9) .

Then in next qq line each line contains three integers aa, bb, cc, if a = 1a=1, it means question type is 11, and bb, ccrepresents [ ll , rr ]. if a = 2a=2 , it means question type is 22 , and bb, cc means Ryuji changes the bth book‘ knowledge to cc

Output

For each question, output one line with one integer represent the answer.

样例输入复制

5 3
1 2 3 4 5
1 1 3
2 5 0
1 4 5

样例输出复制

10
8

题目来源

ACM-ICPC 2018 徐州赛区网络预赛

思路:

维护两个树状数组。

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
typedef long long ll;
ll t1[maxn],t2[maxn],a[maxn];
inline int lowbit(int x){return x&-x;}
void update(int x,ll val,ll *tree){
    for (int i=x; i<maxn; i+=lowbit(i)) tree[i]+=val;
}
ll Query(int x,ll *tree){
    ll res=0;
    for (int i=x; i; i-=lowbit(i)) res+=tree[i];
    return res;
}
int n,q;
int op,l,r;
int main(){
    scanf("%d%d",&n,&q);
    for (int i=1; i<=n; i++) {
        scanf("%lld",&a[i]);
        update(i,a[i]*(n-i+1),t1);
        update(i,a[i],t2);
    }

    while(q--){
        scanf("%d",&op);
        if(op==1){
            scanf("%d%d",&l,&r);
            ll tmp=Query(r,t1)-Query(l-1,t1);
            tmp-=1ll*(Query(r,t2)-Query(l-1,t2))*(n-r);
            cout<<tmp<<endl;
        } else {
            scanf("%d%d",&l,&r);
            update(l,(r-a[l])*(n-l+1),t1);
            update(l,(r-a[l]),t2);
            a[l]=r;
        }
    }
    return 0;
}

原文地址:https://www.cnblogs.com/acerkoo/p/9638095.html

时间: 2024-08-30 03:09:12

2018 徐州网络赛 H的相关文章

2018徐州网络赛H. Ryuji doesn&#39;t want to study

题目链接: https://nanti.jisuanke.com/t/31458 题解: 建立两个树状数组,第一个是,a[1]*n+a[2]*(n-1)....+a[n]*1;第二个是正常的a[1],a[2],a[3]...a[n] #include "bits/stdc++.h" using namespace std; #define ll long long const int MAXN=1e5+10; ll sum[MAXN],ans[MAXN]; ll num[MAXN];

ACM-ICPC 2018徐州网络赛-H题 Ryuji doesn&#39;t want to study

C*M....死于update的一个long long写成int了 心累 不想写过程了 ******** 树状数组,一个平的一个斜着的,怎么斜都行 题库链接:https://nanti.jisuanke.com/t/31460 #include <iostream> #include <cstring> #define ll long long #define lowbit(x) (x & -x) using namespace std; const int maxn =

2018 徐州网络赛A

262144K After Incident, a feast is usually held in Hakurei Shrine. This time Reimu asked Kokoro to deliver a Nogaku show during the feast. To enjoy the show, every audience has to wear a Nogaku mask, and seat around as a circle. There are N guests Re

2018 徐州网络赛 J

131072K After the long vacation, the maze designer master has to do his job. A tour company gives him a map which is a rectangle. The map consists of N \times MN×M little squares. That is to say, the height of the rectangle is NN and the width of the

ACM-ICPC 2018青岛网络赛-H题

把这题的每个点分成两种情况看,如果是从这个点开始,0算作2,1算作1,如果是中间点或者是结束点,如果和前面的相同看作2,不相同看作1 #include <iostream> #include <string> #include <string.h> using namespace std; int main() { ios::sync_with_stdio(false); int t; cin >> t; while (t--) { int a, b; st

2019徐州网络赛 H.function

题意: 先有\(n=p_1^{k_1}p_2^{k_2}\cdots p_m^{k_m}\),定义\(f(n)=k_1+k_2+\cdots+k_m\). 现在计算 \[ \sum_{i=1}^nf(i!)\% 998244353 \] 思路: 首先注意到\(f\)函数有这样一个性质:\(f(ab)=f(a)+f(b)\). 那么我们化简所求式子有: \[ \begin{aligned} &\sum_{i=1}^nf(i!)\=&\sum_{i=1}^n\sum_{j=1}^if(j)\=

ACM 2018 南京网络赛H题Set解题报告

题目描述 给定\(n\)个数$a_i$,起初第\(i\)个数在第\(i\)个集合.有三种操作(共\(m\)次): 1 $u$ $v$ 将第$u$个数和第$v$个数所在集合合并 2 $u$ 将第$u$个数所在集合所有数加1 3 $u$ $k$ $x$ 问$u$所在集合有多少个数模$2^k$余$x$. 数据范围:\(n,m \le 500000,a_i \le 10^9, 0 \le k \le 30\). 简要题解 显然此题可以用set加启发式合并在\(O(n \log ^2 n)\)时间复杂度解

【2018徐州网络赛】Morgana Net (矩阵快速幂)

给你一个n*n的矩阵A,和一个m*m的矩阵B(m%2==1) B是卷积核,让你用B对A做t次卷积运算,并且对于A中的每一个元素计算出来的值要模2,所以A最后会是一个01矩阵. 问你经过t此后,A中有多少个元素=1 1<=t<=1e9,1<=n<=8,1<=m<=n SOLUTION: 二维矩阵展成1维 那么做法就是把A矩阵变成一个1*(n*n)的一维向量,然后构造一个(n*n)*(n*n)的辅助矩阵 我们观察到对于A中的每一个元素,每一次卷积运算,所要求乘积的值的位置是

2018 ICPC 徐州网络赛

2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution 将环变成链,设\(f[i][0\)~\(2]\),分别表示与第一个数相同,与第一个数不同,与第一个数相同,与第一个数的反相同.然后\(dp\)即可. 时间复杂度:\(O(n)\) B. BE, GE or NE solution 根据题目描述\(dp\)即可. 时间复杂度:\(O(nm)\) C.