Submission #171757

#TimeUsernameProblemLanguageResultExecution timeMemory
171757SenseiStrange Device (APIO19_strange_device)C++17
100 / 100
689 ms31508 KiB
/* DATE: 2019-12-30 11:10:15 NAME: PROBLEM: APIO19_strange_device */ #include <bits/stdc++.h> using namespace std; const int MAXN = 1e6; const long long LLINF = 1e18 + 100; class Segment { public: long long l, r; Segment() {} Segment(long long x, long long y) { l = x; r = y; } }; long long f(long long x, long long y) { if (x / __gcd(x, y + 1) > LLINF / y) { return LLINF; } return x / __gcd(x, y + 1) * y; } int main() { int n; cin >> n; long long A, B; cin >> A >> B; long long C = f(A, B); vector<Segment> segments; for (int i = 1; i <= n; i++) { Segment segment; scanf("%lld %lld", &segment.l, &segment.r); if (segment.r - segment.l + 1 >= C) { cout << C << "\n"; return 0; } segment.l %= C; segment.r %= C; if (segment.l <= segment.r) { segments.push_back(segment); } else { segments.push_back(Segment(0, segment.r)); segments.push_back(Segment(segment.l, C - 1)); } } sort(segments.begin(), segments.end(), [](Segment x, Segment y) { if (x.l == y.l) { return x.r < y.r; } return x.l < y.l; }); long long lastr = -1; long long ans = 0; for (int i = 0; i < segments.size(); i++) { if (segments[i].l > lastr) { lastr = segments[i].l - 1; } if (segments[i].r > lastr) { ans += segments[i].r - lastr; lastr = segments[i].r; } } cout << ans << "\n"; return 0; }

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:74:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < segments.size(); i++) {
                  ~~^~~~~~~~~~~~~~~~~
strange_device.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld", &segment.l, &segment.r);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...