/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
// lethal option
#include<bits/stdc++.h>
using namespace std;
#define all(flg) flg.begin(), flg.end()
#define int long long
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define eb emplace_back
#define ii pair<int, int>
#define PI 3.141592653589793238462643383279502884
#define ll long long
#define for1(i, ff, gg) for(int i = ff; i <= gg; ++i)
#define for2(i, ff, gg) for(int i = ff; i >= gg; --i)
const ll mod = 1e9 + 7;
const int maxN = 1000005;
const ll oo = 2e18 + 7;
int n, a[maxN];
int x, y, z, k;
ii pr[maxN];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> x >> y;
x = (x / __gcd(x, y + 1));
z = y * x;
if(x < y) swap(x, y);
if(oo / x <= y) z = oo;
assert(z >= 0);
set<ii> st;
for1(i, 1, n){
cin >> x >> y;
pr[i].fi = x % z;
pr[i].se = y % z;
}
for1(i, 1, n){
if(pr[i].fi > pr[i].se){
++n;
pr[n].se = pr[i].se;
pr[n].fi = 0;
pr[i].se = z - 1;
}
}
int lmx = -oo;
sort(pr + 1, pr + n + 1);
int ans = 0;
for1(i, 1, n){
lmx = max(lmx, pr[i].fi - 1);
ans += max(0ll, pr[i].se - lmx);
lmx = max(lmx, pr[i].se);
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
444 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
468 KB |
Output is correct |
17 |
Correct |
39 ms |
1820 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
287 ms |
15932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
385 ms |
15912 KB |
Output is correct |
3 |
Correct |
411 ms |
15932 KB |
Output is correct |
4 |
Correct |
438 ms |
15912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
385 ms |
15912 KB |
Output is correct |
3 |
Correct |
411 ms |
15932 KB |
Output is correct |
4 |
Correct |
438 ms |
15912 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
405 ms |
16008 KB |
Output is correct |
7 |
Correct |
381 ms |
15924 KB |
Output is correct |
8 |
Correct |
372 ms |
15848 KB |
Output is correct |
9 |
Correct |
453 ms |
16040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
385 ms |
15912 KB |
Output is correct |
3 |
Correct |
411 ms |
15932 KB |
Output is correct |
4 |
Correct |
438 ms |
15912 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
40 ms |
1864 KB |
Output is correct |
7 |
Correct |
42 ms |
1784 KB |
Output is correct |
8 |
Correct |
52 ms |
1888 KB |
Output is correct |
9 |
Correct |
38 ms |
1888 KB |
Output is correct |
10 |
Correct |
36 ms |
1804 KB |
Output is correct |
11 |
Correct |
37 ms |
1888 KB |
Output is correct |
12 |
Correct |
36 ms |
1880 KB |
Output is correct |
13 |
Correct |
40 ms |
1816 KB |
Output is correct |
14 |
Correct |
40 ms |
1864 KB |
Output is correct |
15 |
Correct |
45 ms |
1868 KB |
Output is correct |
16 |
Correct |
48 ms |
1876 KB |
Output is correct |
17 |
Correct |
54 ms |
1876 KB |
Output is correct |
18 |
Correct |
380 ms |
16012 KB |
Output is correct |
19 |
Correct |
377 ms |
15924 KB |
Output is correct |
20 |
Correct |
437 ms |
15868 KB |
Output is correct |
21 |
Correct |
53 ms |
1828 KB |
Output is correct |
22 |
Correct |
36 ms |
1836 KB |
Output is correct |
23 |
Correct |
120 ms |
5592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
42 ms |
1812 KB |
Output is correct |
3 |
Correct |
50 ms |
1776 KB |
Output is correct |
4 |
Correct |
447 ms |
16028 KB |
Output is correct |
5 |
Correct |
64 ms |
1772 KB |
Output is correct |
6 |
Correct |
46 ms |
1816 KB |
Output is correct |
7 |
Correct |
41 ms |
1884 KB |
Output is correct |
8 |
Correct |
39 ms |
1884 KB |
Output is correct |
9 |
Correct |
37 ms |
1888 KB |
Output is correct |
10 |
Correct |
40 ms |
1784 KB |
Output is correct |
11 |
Correct |
45 ms |
1868 KB |
Output is correct |
12 |
Correct |
37 ms |
1884 KB |
Output is correct |
13 |
Correct |
39 ms |
1836 KB |
Output is correct |
14 |
Correct |
396 ms |
15864 KB |
Output is correct |
15 |
Correct |
42 ms |
1888 KB |
Output is correct |
16 |
Correct |
372 ms |
15932 KB |
Output is correct |
17 |
Correct |
392 ms |
15872 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
444 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
468 KB |
Output is correct |
17 |
Correct |
39 ms |
1820 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |