| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1107610 | arnavsrivastava0123 | Strange Device (APIO19_strange_device) | C++17 | 350 ms | 54188 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 7;
 
void solve(){
   long long n, A, B; cin >> n >> A >> B;
   A = A / gcd(A, B + 1);
   long long MOD = A * B;
   long long ans = 0;
   vector<pair<long long, long long>> intervals;
   for(int i = 0; i < n;i++){
      long long L, R; cin >> L >> R;
      if(L / MOD == R / MOD){
        intervals.push_back({L % MOD, R % MOD});
      }else if(L / MOD + 1 == R / MOD){
        intervals.push_back({L % MOD, MOD - 1});
        intervals.push_back({0, R % MOD});
      }else if(R / MOD >= L / MOD + 2){
        cout << MOD << '\n';
        return;
      }
   }
   sort(intervals.begin(), intervals.end());
   long long last = intervals[0].second + 1;
   ans = intervals[0].second - intervals[0].first + 1;
   for(int i = 1; i < intervals.size();i++){
      ans += max(0LL, intervals[i].second - max(intervals[i].first, last) + 1);
      last = max(last, intervals[i].second + 1);
   }
   cout << ans << '\n';
}
 
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
 
int T = 1; //cin >> T;
while(T--){
  solve();
}
}
/*
how many unique  pairs (t + t / B % A, t % B)
*/
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
