Submission #322570

#TimeUsernameProblemLanguageResultExecution timeMemory
322570arborStrange Device (APIO19_strange_device)C++14
65 / 100
620 ms17108 KiB
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() using namespace std; using ll = long long; using pii = pair<int, int>; const int MN = 1e5 + 5; using ull = unsigned long long; int main() { ios_base::sync_with_stdio(0), cin.tie(0); ull n, a, b; cin >> n >> a >> b; ull p = a / __gcd(a, b + 1) * b; vector<pair<ull, ull>> v; for (int i = 0; i < n; i++) { ull l, r; cin >> l >> r; l %= p, r %= p; if (l > r) v.emplace_back(0, r), v.emplace_back(l, p - 1); else v.emplace_back(l, r); } v.emplace_back(p, p); sort(all(v)); ull ans = 0; for (int i = 0; i < v.size();) { int j = i; for (; v[i].second >= v[j].second && j < v.size(); j++); ans += v[i].second - v[i].first + 1; v[j].first = max(v[j].first, v[i].second + 1); i = j; } cout << ans - 1 << '\n'; return 0; }

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:14:23: warning: comparison of integer expressions of different signedness: 'int' and 'ull' {aka 'long long unsigned int'} [-Wsign-compare]
   14 |     for (int i = 0; i < n; i++) {
      |                     ~~^~~
strange_device.cpp:23:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long unsigned int, long long unsigned int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for (int i = 0; i < v.size();) {
      |                     ~~^~~~~~~~~~
strange_device.cpp:25:48: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long unsigned int, long long unsigned int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for (; v[i].second >= v[j].second && j < v.size(); j++);
      |                                              ~~^~~~~~~~~~
#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...