1. 程式人生 > >ACM-ICPC 2018 徐州賽區網路預賽 H. Ryuji doesn't want to study (線段樹維護字首和的字首和)

ACM-ICPC 2018 徐州賽區網路預賽 H. Ryuji doesn't want to study (線段樹維護字首和的字首和)

題意
很簡答就是每次查詢 (L,R)的時候 ,查詢

a[L](RL+1)+a[L+1](RL1)+a[L+2](RL2)....a[R]1,還有修改值
思路
我們可以看出a[l]×L+a[l+1]×(L1)++a[r1]×2+a[r]這個東西其實就是字首和的字首和啊 。。。 a[1]+a[1]+a[2]+a[1]+a[2]+a[3]+a[1]+a[2]+a[3]+a[4]=4a[1]+3a[2]+2a[3]+a[4]
那麼我們線段樹就維護字首和的字首和就行了,對於查詢來說,比如說我我們查[4,6],那其實就是 a[4]+a[4]+a[5]+a[4]+a[5]+a[6],
a[1]+a[2]+a[3]+a[4]+a[1]+a[2]+a[3]+a[4]+a[5]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]
,可以看出他多了什麼? 他多了a[1]+a[2]+a[3]+a[1]+a[2]+a[3]+a[1]+a[2]+a[3],他多了一個(RL+1)(a[1]+a[2]+a[3]),那麼查詢其實就是query(l,r) - (r-l+1) *query(l-1,l-1),對於更新操作怎麼辦?我們把第4個位置上面的值+1,那其實就是所有的a[4] + 1,就是(pos,n)的這個區間我們都+1,這就是一個裸的區間更新和區間查詢
程式碼
#include <bits/stdc++.h>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define int long long
using namespace std;
const int maxn = 1e5+10;
long long a[maxn] , sum[maxn];
long long tree[maxn<<2] ,add[maxn<<2];
struct Tree
{
    void pushup(int rt)
    {
        tree[rt] = tree[rt<<1] + tree[rt<<1|1];
    }
    void pushdown(int l,
            
           

相關推薦

ACM-ICPC 2018 徐州賽區網路預賽 H. Ryuji doesn't want to study 線段維護字首字首

題意 很簡答就是每次查詢 (L,R)的時候 ,查詢 a[L]∗(R−L+1)+a[L+1]∗(R−L−1)+a[L+2]∗(R−L−2)....a[R]∗1a[L]∗(R−L+1)+a[L+1]∗(R−L−1)+a[L+2]∗(R−L−2)....a[R]∗1

ACM-ICPC 2018 徐州賽區網路預賽 H. Ryuji doesn't want to study線段區間求和

樣例輸入 5 3 1 2 3 4 5 1 1 3 2 5 0 1 4 5 樣例輸出 10 8 題意:n長的數列,q個詢問,1操作表示輸出l到r (r-l+1)*a[l]+(r-l)*a[l-1]+……+a[r]的和 ,2表示將a[l]更新為r 思路:線段樹

ACM-ICPC 2018 徐州賽區網路預賽 H. Ryuji doesn't want to study線段

 1000ms  262144K 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 know

ACM-ICPC 2018 徐州賽區網路預賽 H. Ryuji doesn't want to study —— 線段lazy標記區間修改

部落格目錄 原題 傳送門  1000ms  262144K Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each

2018 icpc徐州網路H ——Ryuji doesn't want to study ——線段

題目思路:很明顯的一個線段樹題目,但是要求的是a[l]*len+a[l+1]*(len-1)+a[l+2]*(len-2)+......+a[r],所以根據這個推得以下公式: 可以試著推一下這個公式。所以我們維護兩個線段樹,sum1儲存正常的陣列區間和,sum2儲存a[

ACM-ICPC 2018 徐州賽區網路預賽 H. Ryuji doesn't want to study 線段維護字首字首

題意 很簡答就是每次查詢 (L,R)的時候 ,查詢 a[L]∗(R−L+1)+a[L+1]∗(R−L−1)+a[L+2]∗(R−L−2)....a[R]∗1 a [

2018 ICPC徐州網路H.Ryuji doesn't want to study 狀陣列

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

2018 icpc徐州網路H Ryuji doesn't want to study 線段

題目 題意:給定一個數列,1操作求一個這樣的區間[ L , R ]和:a[ R ]+a[ R-1 ]*2+a[ R-2 ]*3+...+a[ L ]*( R - L +1  ),2操作修改一個a[ i ]的值。 思路:藉助兩顆線段樹,線段樹sum1維護正常區間和,線段樹s

徐州H-Ryuji doesn't want to study線段

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]. U

ACM-ICPC 2018 徐州賽區網路預賽 H

思路 區間詢問,單點修改,用樹狀陣列,維護區間和資訊。 AC程式碼 #include<cstdio> #include<vector> using namespac

ACM-ICPC 2018 徐州賽區網路預賽 徐州 H Ryuji doesn't want to study 線段

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]a[i]

ACM-ICPC 2018 徐州賽區網路預賽I + H水模擬 + 線段

I 題意 給定一個字串ss和一個字元LL,將所有的 |(int)(L−s[i])||(int)(L−s[i])| 轉化為一個兩位數後,按順序拼接在一起,問,這個拼接而成的新序列,去掉前導0後的長度是

ACM-ICPC 2018 徐州賽區網絡預賽 H. Ryuji doesn't want to study 線段

ace esp repr for lin n) mat put 鏈接 Ryuji is not a good student, and he doesn‘t want to study. But there are n books he should learn, each

ACM-ICPC 2018 徐州賽區網路預賽 G. Trace (線段維護)

題意 你在海灘上有浪花,所有的浪花都是矩形的,當一個浪花來了之後,就會覆蓋他的前一個浪花,問你最後浪花的周長和 思路 我們從後往前來,這樣的話,我們處理的都是會留下來的,怎樣的會留下來呢? 首先我們先看1號點和2號點,由圖我們可以很明顯的看出1號點會被淹沒,而1`和1“他們不會被淹沒

ACM-ICPC 2018 徐州賽區網路預賽 B. BE, GE or NE (記憶化搜尋)

題意 兩個人在玩遊戲,有一個初始的分數,每次輪流玩遊戲有三種操作,當前數字加上A,當前數字減去B,當前數字乘上-1,當最終分數>h 的時候就是good ending,小於l的時候就是bad ending ,其他的都是 Normal Ending。 思路 從第一次操作開始記憶化搜,

ACM-ICPC 2018 徐州賽區網路預賽 Feature Track

Morgana is learning computer vision, and he likes cats, too. One day he wants to find the cat movement from a cat video. To do this, he extracts c

[ACM-ICPC 2018 徐州賽區網路預賽] Ryuji doesn't want to study [線段]

Problem Describe 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

ACM-ICPC 2018 徐州賽區網路預賽 I

Characters with Hash Mur loves hash algorithm, and he sometimes encrypt another one's name, and call him with that encrypted value. For instance, he

ACM-ICPC 2018 焦作賽區網路預賽 H. String and Times(字尾自動機)

題目連結 題意: 求原串S中出現次數在[A,B]之間的子串的個數 解析: 字尾自動機的經典應用。 我是通過結合了求不同子串個數的d[]和不同子串出現次數的sz[]來做的。 在拓撲序遍歷字尾自動機的時候,我們求不同子串個數是預設d[]初始為1 的,因為預設一個狀態點本身也是

ACM-ICPC 2018 徐州賽區網路預賽 K. 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,