Submission #977025

#TimeUsernameProblemLanguageResultExecution timeMemory
977025dubabubaStrange Device (APIO19_strange_device)C++14
0 / 100
1081 ms524288 KiB
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int, int> pii; #define ff first #define ss second #define MP make_pair int gcd(int a, int b) { if(a == 0) return b; if(b == 0) return a; return gcd(b % a, a); } struct tree { bool lazy; int tl, tr; tree *lc, *rc; int sum; tree(int l, int r) { tl = l, tr = r; lazy = sum = 0; lc = rc = NULL; } void birth() { if(tl == tr) return; if(lc != NULL) return; lc = new tree(tl, (tl + tr) / 2); rc = new tree((tl + tr) / 2 + 1, tr); } void upt(int l, int r) { // if(lazy) return; // cout << tl << ' ' << tr << ": " << l << ' ' << r << endl; if(tl == l && r == tr) { sum = r - l + 1; lazy = 1; return; } birth(); int tm = (tl + tr) / 2; if(r <= tm) lc->upt(l, r); else if(tm < l) rc->upt(l, r); else { lc->upt(l, tm); rc->upt(tm + 1, r); } sum = lc->sum + rc->sum; if(lc->lazy && rc->lazy) lazy = 1; } }; signed main() { int a, b, n; cin >> n >> a >> b; int t = a / gcd(a, b + 1) * b; tree *root = new tree(0, t - 1); // cout << "sda = " << t << endl; int l, r; bool gay = false; for(int i = 0; i < n; i++) { cin >> l >> r; if(r - l + 1 >= t) { gay = 1; continue; } l %= t; r %= t; if(l <= r) root->upt(l, r); else { root->upt(l, t - 1); root->upt(0, r); } } cout << ((gay) ? t : root->sum) << endl; return 0; }

Compilation message (stderr)

strange_device.cpp: In constructor 'tree::tree(long long int, long long int)':
strange_device.cpp:24:14: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   24 |   lazy = sum = 0;
      |          ~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...