比赛 2024暑假C班集训5 评测结果 AWWWWWWWWW
题目名称 焚风现象 最终得分 10
用户昵称 Untitled 运行时间 0.944 s
代码语言 C++ 内存使用 6.15 MiB
提交时间 2024-07-05 11:10:19
显示代码纯文本
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4.  
  5. int const N=200100;
  6. int n,q,s,t;
  7. ll tem[N],c[N];
  8.  
  9. int lowbit(int x){
  10. return x&-x;
  11. }
  12.  
  13. void add(int l,int r,ll x){
  14. if (!l && !r){
  15. c[0]+=x;
  16. return;
  17. }
  18. while (l<=n){
  19. c[l]+=x;
  20. l+=lowbit(l);
  21. }
  22. r++;
  23. while (r<=n){
  24. c[r]-=x;
  25. r+=lowbit(r);
  26. }
  27. return;
  28. }
  29.  
  30. ll query(int x){
  31. if (x<0) return 0;
  32. ll cnt=0;
  33. while (x){
  34. cnt+=c[x];
  35. x-=lowbit(x);
  36. }
  37. return cnt;
  38. }
  39.  
  40. int main(){
  41. freopen("foehn.in","r",stdin);
  42. freopen("foehn.out","w",stdout);
  43. int a,b=0;
  44. ll w;
  45. scanf("%d %d %d %d",&n,&q,&s,&t);
  46. for (int i=0;i<=n;i++){
  47. scanf("%d",&a);
  48. add(i,i,a);
  49. //c[i]=a;
  50. if (!i) continue;
  51. if (a==b) tem[a]=tem[b];
  52. else if (a>b) tem[i]=tem[i-1]-s*(a-b);
  53. else tem[i]=tem[i-1]+t*(b-a);
  54. b=a;
  55. }
  56. for (int x=1;x<=q;x++){
  57. scanf("%d %d %lld",&a,&b,&w);
  58. ll frt,bck;
  59. ll c1=query(a-1),c2=query(a),c3=query(b),c4=query(b+1);
  60. if (c1<c2) frt=-w*s;
  61. else if (c1>c2 && c1>c2+w) frt=-w*t;
  62. else frt=-(c1-c2)*t-(w-c1+c2)*s;
  63. if (b==n) bck=0;
  64. else if (c3>c4) bck=w*t;
  65. else if (c3<c4 && c3+w<c4) bck=w*s;
  66. else bck=(c4-c3)*s+(w-c4+c3)*t;
  67. tem[n]+=frt+bck;
  68. add(a,b,w);
  69. printf("%lld\n",tem[n]);
  70. }
  71. return 0;
  72. }