Submission #857033

#TimeUsernameProblemLanguageResultExecution timeMemory
857033arashMLGFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
448 ms17748 KiB
#include<bits/stdc++.h> #ifdef LOCAL #include "Essentials/algo/debug.h" #else #define debug(...) 69 #endif using namespace std; //#pragma GCC optimize("O3,unroll-loops") //#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") //https://quera.org/profile/4dykhk typedef long long ll; typedef long double ldb; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const int N = 2e5 + 23; const int sq = 450; const ll mod = 1e9+7; // 998244353 const int LOG = 23; const ll inf = 1e18; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define F first #define S second #define pb push_back #define ms(x,y) memset((x) , (y) , sizeof (x)) #define done return cout<<endl , 0; #define kill(x) cout<<x<<endl, exit(0); #define isIn(x,s,e) ((x) >= (s) && (x) <= e) #define all(x) x.begin(),x.end() #define sz(x) (int)x.size() #define pc(x) __builtin_popcount(x) #define ctz(x) __builtin_ctz(x) #define MinHeap(x) priority_queue<x, vector<x> , greater<x> > #define MaxHeap(x) priority_queue<x, vector<x>> #define lc (v << 1) #define rc ((v<<1) |1) #define int ll ll pw(ll a, ll b, ll md = mod){ll res = 1; while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);} int n; int a[N]; int t[N<<2]; void build(int v=1,int tl=0,int tr=n+1) { if(tr-tl ==1) { t[v] = a[tl]; return; } int mid=(tl+tr)/2; build(lc,tl,mid); build(rc,mid,tr); } void shift(int v) { if(t[v] == 0) return; t[lc] += t[v]; t[rc] += t[v]; t[v] = 0; } void upd(int l,int r,int x,int v =1,int tl = 0 ,int tr = n+1) { if(l > r) return; if(l == tl && r == tr-1) { t[v] += x; return; } shift(v); int mid=(tl+tr)/2; upd(l,min(mid-1,r),x,lc,tl,mid); upd(max(l,mid),r,x,rc,mid,tr); } int get(int pos,int v=1,int tl = 0, int tr =n+1) { if(tr-tl ==1) return t[v]; shift(v); int mid=(tl+tr)/2; if(pos<mid) return get(pos,lc,tl,mid); else return get(pos,rc,mid,tr); } /*void print(__int128_t x) { string s; while(x > 0) { s.pb(x%10 + '0'); x/=10; } if(sz(s) ==0) s.pb('0'); reverse(all(s)); cout<<s<<'\n'; }*/ int q,s,l; int val(int i) { if(i == n) return 0; if(get(i) < get(i+1)) { return -(get(i+1)-get(i))*s; } else { return (get(i) - get(i+1))*l; } } int32_t main() { cin.tie(nullptr)->sync_with_stdio(false); cin>>n>>q>>s>>l; for(int i = 0; i <= n ;i ++) cin>>a[i]; build(); int sum =0; for(int i = 0 ; i < n; i ++) { if(a[i] < a[i+1]) { sum -= (a[i+1]-a[i])*s; } else { sum += (a[i] - a[i+1])*l; } } debug(sum); while(q--) { int l,r,x; cin>>l>>r>>x; sum -= val(l-1); sum -= val(r); debug(val(l-1),val(r)); upd(l,r,x); sum += val(l-1); sum += val(r); cout<<sum << '\n'; } done; }

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int32_t main()':
foehn_phenomena.cpp:5:20: warning: statement has no effect [-Wunused-value]
    5 | #define debug(...) 69
      |                    ^~
foehn_phenomena.cpp:126:2: note: in expansion of macro 'debug'
  126 |  debug(sum);
      |  ^~~~~
foehn_phenomena.cpp:5:20: warning: statement has no effect [-Wunused-value]
    5 | #define debug(...) 69
      |                    ^~
foehn_phenomena.cpp:131:3: note: in expansion of macro 'debug'
  131 |   debug(val(l-1),val(r));
      |   ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...