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

Posted mzg1805

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了差分模版题(需理解才明白)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
",ans);
49     }
50     return 0;
51 }

 

以上是关于差分模版题(需理解才明白)AT2442 フェーン現象 (Foehn Phenomena)的主要内容,如果未能解决你的问题,请参考以下文章

html ページの迁移时にフェードアウト,フェードイン效果をだすためのjQuery的プラグイン

java ネストした型やインターフェースの例

css CSSでフェードイン

css CSSでフェードイン

csharp IPickupインターフェースを持つコンポーネンををInjectする例

java 継承とインターフェースの使い方阶层が1つのポリモーフィズム