Submission #524798

#TimeUsernameProblemLanguageResultExecution timeMemory
524798EvangSjeckanje (COCI21_sjeckanje)C++17
0 / 110
1 ms332 KiB
#include <bits/extc++.h> using namespace std; using namespace __gnu_pbds; #ifdef _DEBUG #define dout(x) clog << "Line " << __LINE__ << ": " << #x << "=" << (x) << el #else #define dout(x) #endif mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define uid(a,b) uniform_int_distribution<int>(a,b)(rng) #define ins insert #define ssize(x) (int((x).size())) #define bs(args...) binary_search(args) #define lb(args...) lower_bound(args) #define ub(args...) upper_bound(args) #define all(x) (x).begin(),(x).end() #define mp(a, b) make_pair(a, b) #define mt(args...) make_tuple(args) #define pb(x) push_back(x) #define eb(args...) emplace_back(args) #define ff first #define ss second #define die exit(0) template<typename T> using vc = vector<T>; template<typename T> using uset = unordered_set<T>; template<typename A, typename B> using umap = unordered_map<A, B>; template<typename T, typename Comp> using pq = std::priority_queue<T, vc<T>, Comp>; template<typename T> using maxpq = pq<T, less<T>>; template<typename T> using minpq = pq<T, greater<T>>; template<typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; using db = double; using ld = long double; using ll = long long; using ull = unsigned long long; using pi = pair<int, int>; using pll = pair<ll, ll>; using vi = vc<int>; using vll = vc<ll>; using vpi = vc<pi>; using vpll = vc<pll>; using str = string; constexpr char el = '\n'; constexpr char sp = ' '; constexpr int inf = 0x3f3f3f3f; constexpr ll llinf = 0x3f3f3f3f3f3f3f3fLL; // --------------------------------------------------------------------- const int N = 8e5+5; int n, n2, q, m[N]; ll x[N], a[N], b[N], c[N], d[N]; void pull(int i){ a[i] = max({b[2*i]+c[2*i+1], b[2*i]+a[2*i+1], a[2*i]+c[2*i+1]}); b[i] = max({b[2*i]+d[2*i+1], b[2*i]+b[2*i+1], a[2*i]+d[2*i+1]}); c[i] = max({d[2*i]+c[2*i+1], c[2*i]+a[2*i+1], c[2*i]+c[2*i+1]}); d[i] = max({d[2*i]+b[2*i+1], d[2*i]+d[2*i+1], d[2*i]+d[2*i+1]}); if(x[m[i]]>0&&x[m[i]+1]<0 || x[m[i]]<0&&x[m[i]+1]>0) return; a[i] = max(a[i], a[2*i]+a[2*i+1]); b[i] = max(b[i], a[2*i]+b[2*i+1]); c[i] = max(c[i], c[2*i]+a[2*i+1]); d[i] = max(d[i], c[2*i]+b[2*i+1]); } void evan(int i, int l, int r){ if(i>=n) return; m[i] = (l+r)/2; evan(2*i, l, m[i]); evan(2*i+1, m[i]+1, r); } void upd(int i, int v){ x[i] += v; a[i] = abs(x[i]); for(i /= 2; i > 0; i /= 2) pull(i); } void upd(int l, int r, int v){ l += n-1; r += n-1; if(l>n) upd(l-1, -v); if(r<n+n2) upd(r, v); } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed; clog << fixed; clog << unitbuf; #ifdef _DEBUG freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("debug.txt", "w", stderr); #else //freopen(".in", "r", stdin); //freopen(".out", "w", stdout); #endif cin >> n2 >> q; if(n2==1){ while(q--) cout << 0 << el; die; } --n2; n = 1; while(n<n2) n *= 2; evan(1, n, 2*n-1); for(int i = n; i <= n+n2; ++i) cin >> x[i]; for(int i = n; i < n+n2; ++i) { x[i] -= x[i + 1]; a[i] = abs(x[i]); b[i] = c[i] = -inf; } for(int i = n+n2; i < 2*n; ++i){ x[i] = 0; a[i] = 0; b[i] = c[i] = -inf; } for(int i = n-1; i > 0; --i) pull(i); while(q--){ int l, r, v; cin >> l >> r >> v; upd(l, r, v); cout << max({a[1], b[1], c[1], d[1]}) << el; } }

Compilation message (stderr)

Main.cpp: In function 'void pull(int)':
Main.cpp:72:17: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   72 |     if(x[m[i]]>0&&x[m[i]+1]<0 || x[m[i]]<0&&x[m[i]+1]>0)
      |        ~~~~~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...