Submission #563608

#TimeUsernameProblemLanguageResultExecution timeMemory
563608Ooops_sorryStrange Device (APIO19_strange_device)C++14
0 / 100
1 ms332 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define ld long double #define ll long long mt19937 rnd(51); signed main() { #ifdef LOCAL freopen("input.txt", "r", stdin); #endif // LCOAL ios_base::sync_with_stdio(0); cin.tie(0); ll n, a, b, ans =0; cin >> n >> a >> b; bool was = 0, sum = 0; if (log2(a) + log2(b) > log2(1e18) + 1) { sum = 1; } vector<ll> l(n), r(n); vector<pair<ll, ll>> seg, u; for (int i = 0; i < n; i++) { cin >> l[i] >> r[i]; if (sum) { ans += r[i] - l[i] + 1; } else { if (r[i] - l[i] + 1 >= a * b) { was = 1; } else { ll l1 = l[i] % (a * b), r1 = r[i] % (a * b); if (l1 <= r1) { seg.pb({l1, r1}); } else { seg.pb({l1, a * b - 1}); seg.pb({0, r1}); } } } } if (sum) { cout << ans << endl; } else { for (auto to : seg) { u.pb({to.first, 1}); u.pb({to.second + 1, -1}); } sort(u.begin(), u.end()); ll bal = 0, last = -1; for (auto to : u) { if (bal > 0) { ans += to.first - last; } bal += to.second; last = to.first; } cout << ans << endl; } return 0; }

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:19:10: warning: variable 'was' set but not used [-Wunused-but-set-variable]
   19 |     bool was = 0, 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...