差分模版题(需理解才明白)AT2442 フェーン現象 (Foehn Phenomena)

https://www.luogu.org/problemnew/show/AT2442

 1 #include <bits/stdc++.h>
 2 #define read read()
 3 #define up(i,l,r) for(register int i = (l);i <= (r);i++)
 4 #define down(i,l,r) for(register int i = (l);i >= (r);i--)
 5 #define traversal_vedge(i) for(register int i = head[u]; i ;i = e[i].nxt)
 6 #define ll long long
 7 using namespace std;
 8 int read
 9 {
10     int x = 0, f = 1; char ch = getchar();
11     while(ch < 48 || ch > 57) {if(ch == ‘-‘)f = -1; ch = getchar();}
12     while(ch >=48 && ch <=57) {x = 10 * x + ch - 48;ch = getchar();}
13     return x * f;
14 }
15 const int N =  2e5+7;
16 ll n,q,S,T,b[N],ans;
17
18 inline ll get(ll x)
19 {
20     return x > 0 ? (-x*S) : (-x*T);
21 }
22
23 int main()
24 {
25     freopen("input.txt","r",stdin);
26     n = read; q = read; S = read; T = read;
27     ll last = read;
28     up(i,1,n)
29     {
30         ll x = read;
31         b[i] = x - last;
32         last = x;
33         ans += get(b[i]);
34     }
35     //ans代表b[i](1~n)遍历后的答案;
36     while(q--)
37     {
38         int l = read, r = read, x = read;
39         ans -= get(b[l]);// b[l]改变,先减后加;
40         b[l] += x;
41         ans += get(b[l]);
42         if(r < n)
43         {
44             ans -= get(b[r+1]);//debug -= -> +=
45             b[r+1] -= x;
46             ans += get(b[r+1]);//degug += -> -=
47         }
48         printf("%lld\n",ans);
49     }
50     return 0;
51 }

原文地址:https://www.cnblogs.com/mzg1805/p/10413166.html

时间: 2024-08-29 23:40:29

差分模版题(需理解才明白)AT2442 フェーン現象 (Foehn Phenomena)的相关文章

[noip模拟20170921]模版题

  今天考的是一套很基础的模版题,但是我这种蒟蒻竟然还是没有AK,不得不说,蒟蒻和大佬的差别不是一点点啊 1.暴走的猴子(walk.pas/c/cpp) [题目描述] 从前有一个森林,森林里生活着一群猴子,这里猴子有个恶趣味——暴走.现在给你这个森林里的树木描述,你能计算出这只猴子在暴走k步后会蹦达到哪里吗(友情提示:由于你上周帮助猎人写程序打死了猴子父亲,所以今天猴子特别不爽,故意暴走了很多很多步来为难你,从而导致了k非常的大,做好心里准备噢-) [输入数据] 第一行两个数n,m表示树木数和询

lct 模版题 bzoj 2002 2049

很早就有人给我推荐的模版题,然后我最近才刷的(' '    ) 昨天的tree 不知道比他们高到哪里去了,我和他谈笑风生啊! bzoj 2002 弹飞绵羊 重点:这道题的cut和link 由于这道题链的特殊性所以不能用提根的方法搞,可以注意到每一次cut位置一定是前面的一个元素,所以access 上去之后直接把左边的儿子丢掉就行了(我原来的cut 是在不知道两个点的儿子关系时就强行提根(' '    )) 然后link的时候直接把cut的那一棵splay接过去就行了 1 #include <io

poj 1986 Distance Queries 带权lca 模版题

Distance Queries Description Farmer John's cows refused to run in his marathon since he chose a path much too long for their leisurely lifestyle. He therefore wants to find a path of a more reasonable length. The input to this problem consists of the

五条垂暮之年才明白的道理

5 life lessons you will learn the hard way五条垂暮之年才明白的道理Life is not easy when you are pursuing something worthwhile and ready to learn from the best experiences. Most of the time, we learn the lessons from the old and wise as they have already been whe

HDU 2222-Keywords Search-AC自动机模版题

纯粹的模版... 学习模版总会是一个快乐的过程.... #include <cstdio> #include <cstdlib> #include <string> #include <climits> #include <iostream> #include <vector> #include <set> #include <cmath> #include <cctype> #include &l

HDU ACM 2966 In case of failure -&gt;K_D树模版题

分析:k_d树的模版题,参考了别人的写的:划分的时候采用坐标跨度作为分割依据的效率略比采用树的深度作为划分依据的高:nth_element函数比sort函数的效率高:全部采用getchar和putchar效率也能提高一些. #include<iostream> #include<algorithm> using namespace std; struct POINT { int x,y; }; struct K_D_Node { POINT mid; //分割中点 int spli

HDU 2896 病毒侵袭(AC自动机模版题)

AC自动模版题,中文题目就不叙述题意了啊. AC自动主要是构造出字典树之后找到fail指针的跳转,类似于KMP里面的next数组的跳转啊,注意这里是多模式跳转.意思就是这个串跳到下一个串的什么位置啊. 先帖一下,做多了再一起总结吧. 病毒侵袭 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 11347    Accepted Submi

UVa 12534 Binary Matrix 2 zkw费用流模版题

题目链接:点击打开链接 思路: 我们首先假设这个图都是全0的 用n个点代表行,m个点代表列 用源点向行连一个值x 表示每行1的个数,向列连一个y表示每列y个1 则若行i和列j之间流过一个流量就表示 (i,j) 点填了1 那么若原来图中(i,j)点为0 则花费就是1 若原图中(i,j)点是1,则花费是-1 如此枚举x跑个费用流就好了 ==居然把我多年的白书费用流坑掉了... zkw走起啊 #include <stdio.h> #include <string.h> #include

HDU3966 Aragorn&#39;s Story(树链剖分 点权 模版题)

#include <iostream> #include <algorithm> #include <cstring> #include <cmath> #include <queue> #include <map> #include <set> #include <vector> #include <cstdio> using namespace std; const int N=50010; s