zoukankan      html  css  js  c++  java
  • 差分模版题(需理解才明白)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 }
  • 相关阅读:
    jQuery---三组基本动画 show hide
    jQuery---表格全选案例
    jQuery---prop方法和表格全选案例
    jQuery---美女相册案例
    jQuery---属性操作
    jQuery---tab栏切换
    jQuery---Class操作
    jQuery---CSS操作
    jQuery---第一部分复习
    DirBuste 使用
  • 原文地址:https://www.cnblogs.com/mzg1805/p/10413166.html
Copyright © 2011-2022 走看看