Submission #225965

#TimeUsernameProblemLanguageResultExecution timeMemory
225965BeanZStrange Device (APIO19_strange_device)C++14
100 / 100
923 ms100468 KiB
#include <bits/stdc++.h>
using namespace std;

#define ull unsigned long long
#define endl '\n'
#define ll long long
const int N = 1e6 + 5;
const ll inf = 2e18;
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (fopen("VLJUM.INP", "r")){
                freopen("VLJUM.INP", "r", stdin);
                freopen("VLJUM.OUT", "w", stdout);
        }
        ll n;
        ll a, b;
        cin >> n >> a >> b;
        ll m = a / __gcd(a, b + 1);
        m = (inf / m < b ? inf : b * m);
        map<ll, ll> mem;
        for (int i = 1; i <= n; i++) {
            ll l, r;
            cin >> l >> r;
            r++;
            if (r - l >= m) {
                    cout << m << endl;
                    return 0;
            }
            l %= m;
            r %= m;
            if (l < r){
                    mem[l]++;
                    mem[r]--;
            }
            else {
                    mem[0]++;
                    mem[r]--;
                    mem[l]++;
                    mem[m]--;
            }
        }
        ll cur = 0, cnt = 0;
        ll now = 0;
        for (auto j : mem) {
            cnt += (now > 0) * (j.first - cur);
            cur = j.first;
            now += j.second;
        }
        cout << cnt << endl;
}
/*
*/

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:14:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
                 freopen("VLJUM.INP", "r", stdin);
                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:15:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
                 freopen("VLJUM.OUT", "w", stdout);
                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...