#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define rep(i, n) for(int i = 1; i <= n; ++i)
#define forn(i, l, r) for(int i = l; i <= r; ++i)
#define ford(i, r, l) for(int i = r; i >= l; --i)
#define FOR(i, n) for(int i = 0; i < n; ++i)
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define endl "\n"
#define task ""
#define sz(a) int(a.size())
#define C(x, y) make_pair(x, y)
#define all(a) (a).begin(), (a).end()
#define bit(i, mask) (mask >> i & 1)
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
inline int readInt() {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();int n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline ll readLong() {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();ll n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline string readString() {char c;while(c=getchar(),c==' '||c=='\n'||c=='\t');string s({c});while(c=getchar(),c!=EOF&&c!=' '&&c!='\n'&&c!='\t')s+=c;return s;}
const int N = 2e5 + 10;
const int M = 1e3 + 3;
const int N1 = 2e3 + 10;
const int K = 1e2 + 1;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const ll LINF = 1e17 + 2;
const int block_size = 500;
const int LOG = 29;
const int offset = N;
const int LIM = 1e4 ;
const int AL = 26;
int n;
ll a, b;
vector<pii> p;
void add(int l, int r)
{
p.pb({l, 1});
p.pb({r + 1, -1});
}
void solve()
{
cin >> n >> a >> b;
ll period = a / __gcd(a, b + 1) / INF > b ? INF : a / __gcd(a, b + 1) * b;
rep(i, n)
{
ll l, r;
cin >> l >> r;
--l;
--r;
if(r - l + 1 >= period) return cout << period, void();
l %= period;
r %= period;
if(l > r)
add(0, r), add(l, period - 1);
else
add(l, r);
}
sort(all(p));
int cnt = 0;
ll last = 0;
ll res = 0;
for(int i = 0; i < sz(p); ++i)
{
int j = i;
if(i > 0 && cnt)
res += (p[i].fi - p[i - 1].fi);
while(j < sz(p) && p[i].fi == p[j].fi)
{
cnt += p[j].se;
++j;
}
i = j - 1;
}
cout << res;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int TC = 1;
while(TC--)
{
solve();
cout << endl;
}
return 0;
}
//ha
Compilation message
strange_device.cpp: In function 'void solve()':
strange_device.cpp:76:8: warning: unused variable 'last' [-Wunused-variable]
76 | ll last = 0;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
1248 KB |
Output is correct |
3 |
Correct |
6 ms |
1248 KB |
Output is correct |
4 |
Correct |
1 ms |
356 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
460 KB |
Output is correct |
9 |
Correct |
0 ms |
352 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
456 KB |
Output is correct |
12 |
Correct |
0 ms |
360 KB |
Output is correct |
13 |
Correct |
0 ms |
464 KB |
Output is correct |
14 |
Correct |
0 ms |
360 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
1252 KB |
Output is correct |
17 |
Correct |
48 ms |
7576 KB |
Output is correct |
18 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
452 KB |
Output is correct |
2 |
Correct |
1 ms |
352 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
1 ms |
352 KB |
Output is correct |
5 |
Incorrect |
347 ms |
89100 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
352 KB |
Output is correct |
2 |
Correct |
386 ms |
69556 KB |
Output is correct |
3 |
Correct |
413 ms |
68904 KB |
Output is correct |
4 |
Correct |
370 ms |
68772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
352 KB |
Output is correct |
2 |
Correct |
386 ms |
69556 KB |
Output is correct |
3 |
Correct |
413 ms |
68904 KB |
Output is correct |
4 |
Correct |
370 ms |
68772 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
424 ms |
69384 KB |
Output is correct |
7 |
Correct |
411 ms |
68792 KB |
Output is correct |
8 |
Correct |
434 ms |
70016 KB |
Output is correct |
9 |
Correct |
473 ms |
69344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
352 KB |
Output is correct |
2 |
Correct |
386 ms |
69556 KB |
Output is correct |
3 |
Correct |
413 ms |
68904 KB |
Output is correct |
4 |
Correct |
370 ms |
68772 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
39 ms |
8104 KB |
Output is correct |
7 |
Correct |
44 ms |
8668 KB |
Output is correct |
8 |
Correct |
42 ms |
9332 KB |
Output is correct |
9 |
Correct |
38 ms |
7876 KB |
Output is correct |
10 |
Correct |
40 ms |
8136 KB |
Output is correct |
11 |
Correct |
38 ms |
7620 KB |
Output is correct |
12 |
Correct |
51 ms |
8652 KB |
Output is correct |
13 |
Correct |
41 ms |
8696 KB |
Output is correct |
14 |
Correct |
39 ms |
9168 KB |
Output is correct |
15 |
Correct |
62 ms |
7348 KB |
Output is correct |
16 |
Correct |
59 ms |
7636 KB |
Output is correct |
17 |
Correct |
44 ms |
8128 KB |
Output is correct |
18 |
Correct |
404 ms |
69984 KB |
Output is correct |
19 |
Correct |
397 ms |
68528 KB |
Output is correct |
20 |
Correct |
595 ms |
67240 KB |
Output is correct |
21 |
Correct |
56 ms |
7900 KB |
Output is correct |
22 |
Correct |
44 ms |
7368 KB |
Output is correct |
23 |
Incorrect |
145 ms |
45212 KB |
Output isn't correct |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
46 ms |
8924 KB |
Output is correct |
3 |
Correct |
53 ms |
7720 KB |
Output is correct |
4 |
Correct |
609 ms |
69480 KB |
Output is correct |
5 |
Correct |
47 ms |
7496 KB |
Output is correct |
6 |
Correct |
59 ms |
7624 KB |
Output is correct |
7 |
Correct |
42 ms |
7536 KB |
Output is correct |
8 |
Correct |
63 ms |
9144 KB |
Output is correct |
9 |
Correct |
41 ms |
8144 KB |
Output is correct |
10 |
Correct |
49 ms |
7380 KB |
Output is correct |
11 |
Correct |
43 ms |
8404 KB |
Output is correct |
12 |
Correct |
39 ms |
7188 KB |
Output is correct |
13 |
Correct |
44 ms |
7372 KB |
Output is correct |
14 |
Correct |
490 ms |
69052 KB |
Output is correct |
15 |
Correct |
46 ms |
8400 KB |
Output is correct |
16 |
Correct |
358 ms |
68884 KB |
Output is correct |
17 |
Correct |
394 ms |
69420 KB |
Output is correct |
18 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
1248 KB |
Output is correct |
3 |
Correct |
6 ms |
1248 KB |
Output is correct |
4 |
Correct |
1 ms |
356 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
460 KB |
Output is correct |
9 |
Correct |
0 ms |
352 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
456 KB |
Output is correct |
12 |
Correct |
0 ms |
360 KB |
Output is correct |
13 |
Correct |
0 ms |
464 KB |
Output is correct |
14 |
Correct |
0 ms |
360 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
1252 KB |
Output is correct |
17 |
Correct |
48 ms |
7576 KB |
Output is correct |
18 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |