Submission #1044619

#TimeUsernameProblemLanguageResultExecution timeMemory
1044619Onur_IlgazStrange Device (APIO19_strange_device)C++17
10 / 100
407 ms524456 KiB
#include <bits/stdc++.h> #define fast cin.tie(0)->sync_with_stdio(0); #define int long long #define inf ((int)1e18) using namespace std; const int C = inf * 2; struct segtree { int n; struct node { int sum, l, r; bool set; node(): sum(0), l(0), r(0), set(false) {} }; vector <node> t; int newnode() { t.push_back(node()); return t.size() - 1; } void init(int size) { n = size; newnode(); } void set(int l, int r) { return update(0, 0, n - 1, l, r); } void update(int v, int l, int r, int ul, int ur) { if(l >= ul and r <= ur) { t[v].sum = (r - l + 1); t[v].set = 1; return; } if(t[v].set) return; if(!t[v].l) { t[v].l = newnode(); t[v].r = newnode(); } int m = (l + r) / 2; if(ul <= m) update(t[v].l, l, m, ul, ur); if(ur > m) update(t[v].r, m + 1, r, ul, ur); t[v].sum = t[t[v].l].sum + t[t[v].r].sum; } }t; int32_t main(){ fast int n, a, b; cin >> n >> a >> b; int tekrar = gcd(a, b + 1); if(tekrar > C / a / b) { int sum = 0; for(int i = 0; i < n; i++) { int l, r; cin >> l >> r; sum += r - l + 1; } cout << sum << "\n"; return 0; } tekrar = tekrar * a * b; t.init(tekrar); for(int i = 0; i < n; i++) { int l, r; cin >> l >> r; if(r - l + 1 >= tekrar) { cout << tekrar << "\n"; return 0; } int ll = l % tekrar, rr = r % tekrar; if(ll <= rr) { t.set(ll, rr); } else { t.set(0, rr); t.set(ll, tekrar - 1); } } cout << t.t[0].sum; }
#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...