Submission #1148942

#TimeUsernameProblemLanguageResultExecution timeMemory
1148942blackslexStrange Device (APIO19_strange_device)C++20
10 / 100
462 ms33388 KiB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<ll, ll>;

int n;
ll a, b, x, y;

int main() {
    scanf("%d %lld %lld", &n, &a, &b);
    ll m = (a > 1e18 / b ? 1e18 : 1LL * a * b);
    vector<pii> c;
    auto add = [&] (ll l, ll r) {
        if (l > r) return;
        l %= m; r %= m;
        if (l > r) {
            c.emplace_back(l, m - 1);
            c.emplace_back(0, r);
        } else {
            c.emplace_back(l, r);
        }
    };
    for (int i = 0; i < n; i++) {
        scanf("%lld %lld", &x, &y);
        add(x, min(y, x + (m - x % m - 1)));
        add(x + (m - x % m), y - y % m - 1);
        add(max(x, y - y % m), y);
    }
    sort(c.begin(), c.end());
    ll ans = 0, st = 0, ed = -1;
    for (auto &[x, y]: c) {
        if (x <= ed) ed = max(ed, y);
        else {
            ans += ed - st + 1;
            st = x; ed = y;
        }
    }
    ans += ed - st + 1;
    printf("%lld", ans);
}

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%d %lld %lld", &n, &a, &b);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         scanf("%lld %lld", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
#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...