比赛 |
2024暑假C班集训5 |
评测结果 |
AWWWWWWWWW |
题目名称 |
焚风现象 |
最终得分 |
10 |
用户昵称 |
Untitled |
运行时间 |
0.944 s |
代码语言 |
C++ |
内存使用 |
6.15 MiB |
提交时间 |
2024-07-05 11:10:19 |
显示代码纯文本
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
-
- int const N=200100;
- int n,q,s,t;
- ll tem[N],c[N];
-
- int lowbit(int x){
- return x&-x;
- }
-
- void add(int l,int r,ll x){
- if (!l && !r){
- c[0]+=x;
- return;
- }
- while (l<=n){
- c[l]+=x;
- l+=lowbit(l);
- }
- r++;
- while (r<=n){
- c[r]-=x;
- r+=lowbit(r);
- }
- return;
- }
-
- ll query(int x){
- if (x<0) return 0;
- ll cnt=0;
- while (x){
- cnt+=c[x];
- x-=lowbit(x);
- }
- return cnt;
- }
-
- int main(){
- freopen("foehn.in","r",stdin);
- freopen("foehn.out","w",stdout);
-
- int a,b=0;
- ll w;
- scanf("%d %d %d %d",&n,&q,&s,&t);
- for (int i=0;i<=n;i++){
- scanf("%d",&a);
- add(i,i,a);
- //c[i]=a;
- if (!i) continue;
- if (a==b) tem[a]=tem[b];
- else if (a>b) tem[i]=tem[i-1]-s*(a-b);
- else tem[i]=tem[i-1]+t*(b-a);
- b=a;
- }
- for (int x=1;x<=q;x++){
- scanf("%d %d %lld",&a,&b,&w);
- ll frt,bck;
- ll c1=query(a-1),c2=query(a),c3=query(b),c4=query(b+1);
- if (c1<c2) frt=-w*s;
- else if (c1>c2 && c1>c2+w) frt=-w*t;
- else frt=-(c1-c2)*t-(w-c1+c2)*s;
- if (b==n) bck=0;
- else if (c3>c4) bck=w*t;
- else if (c3<c4 && c3+w<c4) bck=w*s;
- else bck=(c4-c3)*s+(w-c4+c3)*t;
- tem[n]+=frt+bck;
- add(a,b,w);
- printf("%lld\n",tem[n]);
- }
-
- return 0;
- }