Submission #232858

#TimeUsernameProblemLanguageResultExecution timeMemory
232858nicolaalexandraFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
865 ms11684 KiB
#include <bits/stdc++.h> #define DIM 200010 using namespace std; long long aib[DIM],v[DIM]; int n,q,x,y,i; long long s,t,val; void update (int p, long long val){ for (;p<=n;p+=(p&-p)) aib[p] += val; } long long query (int p){ if (p <= 0) return 0; long long sol = 0; for (;p;p-=(p&-p)) sol += aib[p]; return sol; } int main (){ //ifstream cin ("date.in"); //ofstream cout ("date.out"); cin>>n>>q>>s>>t; long long sum = 0; for (i=0;i<=n;i++){ cin>>v[i]; if (!i) continue; if (v[i-1] < v[i]) sum -= s * (v[i] - v[i-1]); else sum += t * (v[i-1] - v[i]); update (i,v[i]); update (i+1,-v[i]); } for (;q--;){ cin>>x>>y>>val; long long nr = query (x-1), nr2 = query (x); if (nr < nr2) sum += s * (nr2 - nr); else sum -= t * (nr - nr2); nr = query (y), nr2 = query (y+1); if (y < n){ if (nr < nr2) sum += s * (nr2 - nr); else sum -= t * (nr - nr2); } update (x,val); update (y+1,-val); nr = query (x-1), nr2 = query (x); if (nr < nr2) sum -= s * (nr2 - nr); else sum += t * (nr - nr2); nr = query (y), nr2 = query (y+1); if (y < n){ if (nr < nr2) sum -= s * (nr2 - nr); else sum += t * (nr - nr2); } cout<<sum<<"\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...