Submission #919541

#TimeUsernameProblemLanguageResultExecution timeMemory
919541NurislamFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
301 ms15952 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define pb push_back #define ff first #define ss second #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define int long long #define double long double #define order_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> ///* __ __ __ */ ///* ====== _ /| /| __ _ / | | /| | @ | | | | / /| |\ | / | | @ | / */ ///* \- || |_| |_ / |/ | | | |_ |- | |--| /-| | | \ \ |==| |- /=| | \ | | |--| | |- */ ///* || | | |_ / | |__| _| |_ \__ | | / | |__ | __| | | | \ / | | \| \__ | | | | \ */ ///* typedef vector<int> vi; typedef vector<double> vd; typedef pair<int,int> pii; typedef vector<pii> vii; typedef vector<vi> vv; const int N = 2e5+4, inf = 1e8; int a[N]; int b[N*3]{}; void push(int i, int l, int r){ if(l == r){ a[l] += b[i]; b[i] = 0; return; } b[i*2] += b[i]; b[i*2+1] += b[i]; b[i]=0; } void upd(int i, int l, int r, int tl, int tr, int sum){ push(i, l, r); if(l > tr || r < tl || r < l)return; if(tl <= l && r <= tr){ b[i] += sum; return; } int m = (l+r)>>1; upd(i*2, l, m, tl, tr, sum); upd(i*2+1, m+1, r, tl, tr, sum); } void get(int i, int l, int r, int pos){ if(pos==0)return; push(i, l, r); if(l == r && l == pos)return; int m = (l+r)>>1; if(pos <= m)get(i*2, l, m, pos); else get(i*2+1, m+1, r, pos); } void solve(){ int n, q, s, t; cin >> n >> q >> s >> t; for(int i = 0; i <= n; i++){ cin >> a[i]; } int ans = 0; for(int i = 1; i <= n; i++){ int df = a[i-1]-a[i]; if(df > 0)ans += df*t; else ans += df*s; } while(q--){ int l, r, x; cin >> l >> r >> x; get(1, 1, n, l); get(1, 1, n, l-1); int df = a[l-1]-a[l]; if(df > 0)ans -= df*t; else ans -= df*s; if(r < n){ get(1, 1, n, r); get(1, 1, n, r+1); int df = a[r]-a[r+1]; if(df > 0)ans -= df*t; else ans -= df*s; } upd(1, 1, n, l, r, x); get(1, 1, n, l); get(1, 1, n, l-1); int nwd = a[l-1] - a[l]; if(nwd > 0)ans += nwd*t; else ans += nwd*s; if(r < n){ get(1, 1, n, r); get(1, 1, n, r+1); int nwd = a[r] - a[r+1]; if(nwd > 0)ans += nwd*t; else ans += nwd*s; } cout << ans << '\n'; } } main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int test = 1; //~ cin >> test; while(test--){ solve(); } }

Compilation message (stderr)

foehn_phenomena.cpp:105:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  105 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...