Submission #229642

#TimeUsernameProblemLanguageResultExecution timeMemory
229642davooddkareshkiStrange Device (APIO19_strange_device)C++17
5 / 100
545 ms53608 KiB
// be name khoda
#include<bits/stdc++.h>

using namespace std;

#define F first
#define S second
//#define mp make_pair 
typedef long long ll;
#define int long long
#pragma GCC optimize("Ofast")

const int maxn = 2e5+10;
const int mod = 1e9+7;
const ll inf = 1e18+10;
//const int N = 2e6+10;

int n, m, A, B;

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    cin>> n >> A >> B;
    m = A / __gcd(A,B+1);
    if(m <= inf/B) m *= B;
    else m = inf;

    vector<pair<int,int>> seg;
    for(int i = 1, l, r; i <= n; i++)
    {
        cin>> l >> r;
        if(r-l+1 >= m) return cout<< m, 0;
        l %= m; r %= m;
        if(l <= r)
            seg.push_back({l,r});            
        else
        {
            seg.push_back({l,m-1});
            seg.push_back({0,r});
        }
    }
    sort(seg.begin(), seg.end());

    ll ans = 0, mx = -1;
    for(int i = 0; i < seg.size(); i++)
    {
        int l = seg[i].F, r = seg[i].S;
        //cout<< l <<" "<< r <<"\n";
        mx = max(mx,l-1);
        ans += r-mx;
        mx = max(mx,r);
    }
    cout<< ans;
}
/*
3 3 3
4 4
7 9
17 18

3 5 10
1 20
50 68
89 98

2 16 13
2 5
18 18
*/

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:46:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < seg.size(); i++)
                    ~~^~~~~~~~~~~~
#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...