Submission #106999

#TimeUsernameProblemLanguageResultExecution timeMemory
106999FiloSanzaFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
320 ms17504 KiB
#include<bits/stdc++.h> using namespace std; #define int long long int N, Q, S, T; const int MAXN = 200005; vector<int> seg; inline int left(int x){return 2*x+1;} inline int right(int x){return 2*(x+1);} inline int father(int x){return (x-1)/2;} void build(const vector<int>& in){ int sz = (1<<(int)ceil(log2(in.size()))) * 2 - 1; seg.resize(sz, 0); for(int i=0; i<in.size(); i++) seg[i+seg.size()/2] = in[i] >= 0 ? T*in[i] : S*in[i]; for(int i=seg.size()/2-1; i>=0; i--) seg[i] = seg[left(i)] + seg[right(i)]; } void debug(){ for(auto i : seg) cout << i << " "; cout << "\n\n"; } void update(int pos, int delta){ pos += seg.size()/2; int curr = seg[pos]; curr /= curr >= 0 ? T : S; curr += delta; curr *= curr >= 0 ? T : S; seg[pos] = curr; while(pos != 0){ pos = father(pos); seg[pos] = seg[left(pos)] + seg[right(pos)]; } // debug(); } int query(){ return seg.front(); } signed main(){ cin.tie(0); cin.sync_with_stdio(0); cin >> N >> Q >> S >> T; vector<int> in(N+1), v; for(auto &i : in) cin >> i; for(int i=1; i<=N; i++) v.push_back(in[i-1] - in[i]); build(v); int a, b, c; while(Q--){ cin >> a >> b >> c; update(a-1, -c); if(b < N) update(b, c); cout << query() << "\n"; } }

Compilation message (stderr)

foehn_phenomena.cpp: In function 'void build(const std::vector<long long int>&)':
foehn_phenomena.cpp:19:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<in.size(); i++)
                  ~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...