Submission #31120

#TimeUsernameProblemLanguageResultExecution timeMemory
31120trathFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
693 ms23772 KiB
#include <stdio.h> #include <vector> #include <algorithm> using namespace std; #define F first #define S second #define mp make_pair #define pb push_back #define ll long long int #define ieps 200010 #define eps (int) 1e9 #define pii pair<int,int> struct node{ ll leftmost, rightmost, sumup , sumdown; void clv(){ leftmost = rightmost = sumup = sumdown = 0; } }; int a , b , val; int n , q , v[200100] ; ll s , t; ll lazy[560000]; node st[560000]; void propagate(int curr , int l , int r){ if(lazy[curr]){ st[curr].leftmost += lazy[curr]; st[curr].rightmost += lazy[curr]; if(l != r){ lazy[2*curr] += lazy[curr]; lazy[2*curr + 1] += lazy[curr]; } lazy[curr] = 0; } return; } node mixnode(node left, node right){ node x; x.clv(); ll toadd = 0 , tosubtract = 0; if(left.rightmost >= right.leftmost){ toadd += t*(left.rightmost - right.leftmost); } else if(left.rightmost < right.leftmost){ tosubtract += s*(right.leftmost - left.rightmost); } x.leftmost = left.leftmost; x.rightmost = right.rightmost; x.sumup = left.sumup + right.sumup + toadd; x.sumdown = left.sumdown + right.sumdown + tosubtract; return x; } void build(int l = 0 , int r = n- 1 , int curr = 1){ if(l == r){ st[curr].clv(); st[curr].rightmost = st[curr].leftmost = v[l]; return; } build(l , (l+r)/2 , 2*curr); build((l+r)/2 + 1 , r, 2*curr + 1); st[curr] = mixnode(st[2*curr] , st[2*curr + 1]); return; } void update(int x , int y , int l = 0 , int r = n- 1 , int curr = 1){ propagate(curr, l , r); if(l == x && r == y){ lazy[curr]+=val; propagate(curr, l , r); return; } ll mid = (l+r)/2; if(y <= mid){ update(x , y, l , mid , 2*curr); } else if(x > mid){ update(x ,y, mid + 1 ,r , 2*curr + 1); } else{ update(x , mid , l , mid , 2*curr); update(mid + 1 , y , mid + 1 , r , 2*curr + 1); } propagate(2*curr , l , mid); propagate(2*curr + 1 , mid + 1 , r); st[curr] = mixnode(st[2*curr] , st[2*curr + 1]); return; } int main(){ scanf("%d %d %lld %lld", &n, &q, &s, &t); n = n+1; for(int i = 0;i<n;i++) scanf("%d", &(v[i]));; build(); for(int i = 0;i<q;i++){ scanf("%d%d%d", &a, &b, &val); update(a , b); ll p = st[1].sumup; p-=st[1].sumdown; printf("%lld\n",p); } return 0; }

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:89:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %lld %lld", &n, &q, &s, &t);
                                          ^
foehn_phenomena.cpp:91:45: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0;i<n;i++) scanf("%d", &(v[i]));;
                                             ^
foehn_phenomena.cpp:94:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &a, &b, &val);
                                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...