Submission #237839

#TimeUsernameProblemLanguageResultExecution timeMemory
237839wiwihoFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
392 ms16504 KiB
//#define NDEBUG #include <bits/stdc++.h> #include <bits/extc++.h> #define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define iter(a) a.begin(), a.end() #define riter(a) a.rbegin(), a.rend() #define lsort(a) sort(iter(a)) #define gsort(a) sort(riter(a)) #define pb(a) push_back(a) #define eb(a) emplace_back(a) #define pf(a) push_front(a) #define pob pop_back() #define pof pop_front() #define mp(a, b) make_pair(a, b) #define F first #define S second #define mt make_tuple #define gt(t, i) get<i>(t) #define iceil(a, b) ((a + b - 1) / b) #define tomax(a, b) (a = max(a, b)) #define printv(a, b) {bool pvaspace=false; \ for(auto pva : a){ \ if(pvaspace) b << " "; pvaspace=true;\ b << pva;\ }\ b << "\n";} //#define TEST using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef unsigned long long ull; typedef long double ld; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; using tiii = tuple<int, int, int>; const ll MOD = 1000000007; const ll MAX = 2147483647; template<typename A, typename B> ostream& operator<<(ostream& o, pair<A, B> p){ return o << '(' << p.F << ',' << p.S << ')'; } int lowbit(int x){ return x & -x; } struct BIT{ vector<ll> bit; explicit BIT(int sz = 0){ bit.resize(sz + 2); } void modify(int x, ll v){ for(; x < bit.size(); x += lowbit(x)){ bit[x] += v; } } ll query(int x){ ll ans = 0; for(; x > 0; x -= lowbit(x)){ ans += bit[x]; } return ans; } ll query(int l, int r){ return query(r) - query(l - 1); } }; struct RUBIT{ BIT bit1; BIT bit2; explicit RUBIT(int sz){ bit1 = BIT(sz + 1); bit2 = BIT(sz + 1); } void modify(int l, int r, ll v){ bit1.modify(l, v); bit1.modify(r + 1, -v); bit2.modify(l, l * v); bit2.modify(r + 1, -(r + 1) * v); } ll query(int x){ return (x + 1) * bit1.query(x) - bit2.query(x); } ll query(int l, int r){ return query(r) - query(l - 1); } }; int main(){ StarBurstStream int n, q, s, t; cin >> n >> q >> s >> t; RUBIT alt(n); BIT dec(n), inc(n); for(int i = 0; i <= n; i++){ int a; cin >> a; if(i != 0) alt.modify(i, i, a); } for(int i = 1; i <= n; i++){ if(alt.query(i - 1, i - 1) < alt.query(i, i)){ dec.modify(i, alt.query(i, i) - alt.query(i - 1, i - 1)); } else{ inc.modify(i, alt.query(i, i) - alt.query(i - 1, i - 1)); } } while(q--){ int l, r, x; cin >> l >> r >> x; if(alt.query(l - 1, l - 1) < alt.query(l, l)) dec.modify(l, -(alt.query(l, l) - alt.query(l - 1, l - 1))); else inc.modify(l, -(alt.query(l, l) - alt.query(l - 1, l - 1))); if(alt.query(r, r) < alt.query(r + 1, r + 1)) dec.modify(r + 1, -(alt.query(r + 1, r + 1) - alt.query(r, r))); else inc.modify(r + 1, -(alt.query(r + 1, r + 1) - alt.query(r, r))); alt.modify(l, r, x); if(alt.query(l - 1, l - 1) < alt.query(l, l)) dec.modify(l, (alt.query(l, l) - alt.query(l - 1, l - 1))); else inc.modify(l, (alt.query(l, l) - alt.query(l - 1, l - 1))); if(alt.query(r, r) < alt.query(r + 1, r + 1)) dec.modify(r + 1, (alt.query(r + 1, r + 1) - alt.query(r, r))); else inc.modify(r + 1, (alt.query(r + 1, r + 1) - alt.query(r, r))); // for(int i = 0; i <= n; i++) cerr << alt.query(i, i) << " "; // cerr << "\n"; // for(int i = 0; i <= n; i++) cerr << dec.query(i, i) << " "; // cerr << "\n"; // for(int i = 0; i <= n; i++) cerr << inc.query(i, i) << " "; // cerr << "\n"; cout << -dec.query(n) * s - inc.query(n) * t << "\n"; } return 0; }

Compilation message (stderr)

foehn_phenomena.cpp: In member function 'void BIT::modify(int, ll)':
foehn_phenomena.cpp:65:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(; x < bit.size(); x += lowbit(x)){
               ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...