Submission #1351002

#TimeUsernameProblemLanguageResultExecution timeMemory
1351002nguyenkhangninh99Strange Device (APIO19_strange_device)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

void solve(){
    int n, a, b; cin >> n >> a >> b;
    int x = a / gcd(b + 1, a);
    int loop = (x > 2e18 / b ? 2e18 : x * b);

    vector<pair<int, int>> range;
    for(int i = 1; i <= n; i++){
        int l, r; cin >> l >> r;
        if(r - l + 1 >= loop){
            cout << loop << '\n';
            return;
        }
        l = l % loop;
        r = r % loop;
        if(l <= r) range.push_back({l, r});
        else{
            range.push_back({l, loop - 1});
            range.push_back({0, r});
        }
    }
    sort(range.begin(), range.end());
    int ans = 0, mxr = -1;
    for(auto [l, r]: range){
        ans += max(0ll, r - max(l - 1, mxr));
        maxr = max(mxr, r);
    }
    cout << ans;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    solve();
}

Compilation message (stderr)

strange_device.cpp: In function 'void solve()':
strange_device.cpp:30:9: error: 'maxr' was not declared in this scope; did you mean 'mxr'?
   30 |         maxr = max(mxr, r);
      |         ^~~~
      |         mxr