/*
#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;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
468 KB |
Output is correct |
3 |
Correct |
4 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
43 ms |
1824 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 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 |
274 ms |
15904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
395 ms |
15920 KB |
Output is correct |
3 |
Correct |
368 ms |
15952 KB |
Output is correct |
4 |
Correct |
404 ms |
15952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
395 ms |
15920 KB |
Output is correct |
3 |
Correct |
368 ms |
15952 KB |
Output is correct |
4 |
Correct |
404 ms |
15952 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
357 ms |
15852 KB |
Output is correct |
7 |
Correct |
398 ms |
15948 KB |
Output is correct |
8 |
Correct |
360 ms |
16036 KB |
Output is correct |
9 |
Correct |
432 ms |
15932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
395 ms |
15920 KB |
Output is correct |
3 |
Correct |
368 ms |
15952 KB |
Output is correct |
4 |
Correct |
404 ms |
15952 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
39 ms |
1864 KB |
Output is correct |
7 |
Correct |
39 ms |
1788 KB |
Output is correct |
8 |
Correct |
39 ms |
1888 KB |
Output is correct |
9 |
Correct |
38 ms |
1800 KB |
Output is correct |
10 |
Correct |
40 ms |
1928 KB |
Output is correct |
11 |
Correct |
41 ms |
1884 KB |
Output is correct |
12 |
Correct |
38 ms |
1808 KB |
Output is correct |
13 |
Correct |
44 ms |
1876 KB |
Output is correct |
14 |
Correct |
36 ms |
1884 KB |
Output is correct |
15 |
Correct |
40 ms |
1864 KB |
Output is correct |
16 |
Correct |
48 ms |
1784 KB |
Output is correct |
17 |
Correct |
40 ms |
1980 KB |
Output is correct |
18 |
Correct |
380 ms |
15960 KB |
Output is correct |
19 |
Correct |
349 ms |
15968 KB |
Output is correct |
20 |
Correct |
442 ms |
16088 KB |
Output is correct |
21 |
Correct |
38 ms |
1864 KB |
Output is correct |
22 |
Correct |
36 ms |
1796 KB |
Output is correct |
23 |
Correct |
115 ms |
5580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
43 ms |
1864 KB |
Output is correct |
3 |
Correct |
41 ms |
1800 KB |
Output is correct |
4 |
Correct |
426 ms |
16004 KB |
Output is correct |
5 |
Correct |
38 ms |
1880 KB |
Output is correct |
6 |
Correct |
40 ms |
1792 KB |
Output is correct |
7 |
Correct |
42 ms |
1852 KB |
Output is correct |
8 |
Correct |
55 ms |
1784 KB |
Output is correct |
9 |
Correct |
40 ms |
1864 KB |
Output is correct |
10 |
Correct |
40 ms |
1820 KB |
Output is correct |
11 |
Correct |
39 ms |
1876 KB |
Output is correct |
12 |
Correct |
36 ms |
1900 KB |
Output is correct |
13 |
Correct |
40 ms |
1768 KB |
Output is correct |
14 |
Correct |
453 ms |
15928 KB |
Output is correct |
15 |
Correct |
37 ms |
1876 KB |
Output is correct |
16 |
Correct |
369 ms |
15876 KB |
Output is correct |
17 |
Correct |
366 ms |
16108 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
468 KB |
Output is correct |
3 |
Correct |
4 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
43 ms |
1824 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |