#include <bits/stdc++.h>
#define fastInput ios::sync_with_stdio(false); cin.tie(nullptr);
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pii;
typedef vector<pii> vp;
typedef vector<bool> vb;
typedef vector<vb> vvb;
ll A, B;
inline pii getTime(ll t) {
ll x = (t + (t / B)) % A;
ll y = t % B;
return { x,y };
}
inline void pushTime(pii p, ll mod, vp &points) {
if (p.first % mod <= p.second % mod) {
points.push_back({ p.first % mod, p.second % mod });
}
else {
points.push_back({ p.first % mod, mod - 1 });
points.push_back({ 0, p.second % mod });
}
}
ll gcd(ll a, ll b) {
if (b == 0) {
return a;
}
else {
return gcd(b, a % b);
}
}
const ll inf = 1e18 + 1;
int main() {
fastInput;
int n;
cin >> n >> A >> B;
ll mod = inf;
A /= gcd(A, B + 1);
if (A <= inf / B) {
mod = A * B;
}
vp times(n);
vp points;
ll l, r;
for (int i = 0; i < n; i++) {
cin >> l >> r;
times[i] = { l,r};
if (l - r + 1 >= mod) {
cout << mod;
return 0;
}
pushTime(times[i], mod, points);
}
sort(points.begin(), points.end());
ll count = 0;
ll last = points[0].second;
ll start = points[0].first;
for (int i = 1; i < points.size(); i++) {
if (points[i].first > last) {
ll amount = last - start + 1;
start = points[i].first;
count += amount;
}
last = max(last, points[i].second);
}
ll amount = last - start + 1;
count += amount;
cout << count;
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:72:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for (int i = 1; i < points.size(); i++) {
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
1236 KB |
Output is correct |
3 |
Correct |
5 ms |
1236 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 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 |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
1236 KB |
Output is correct |
17 |
Correct |
45 ms |
5856 KB |
Output is correct |
18 |
Correct |
0 ms |
320 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 |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
290 ms |
34296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
407 ms |
34628 KB |
Output is correct |
3 |
Correct |
389 ms |
34348 KB |
Output is correct |
4 |
Correct |
383 ms |
34392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
407 ms |
34628 KB |
Output is correct |
3 |
Correct |
389 ms |
34348 KB |
Output is correct |
4 |
Correct |
383 ms |
34392 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
399 ms |
34368 KB |
Output is correct |
7 |
Correct |
407 ms |
34512 KB |
Output is correct |
8 |
Correct |
404 ms |
34256 KB |
Output is correct |
9 |
Correct |
407 ms |
34352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
407 ms |
34628 KB |
Output is correct |
3 |
Correct |
389 ms |
34348 KB |
Output is correct |
4 |
Correct |
383 ms |
34392 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
45 ms |
5592 KB |
Output is correct |
7 |
Correct |
44 ms |
5240 KB |
Output is correct |
8 |
Correct |
40 ms |
5672 KB |
Output is correct |
9 |
Correct |
40 ms |
5448 KB |
Output is correct |
10 |
Correct |
41 ms |
5360 KB |
Output is correct |
11 |
Correct |
46 ms |
5316 KB |
Output is correct |
12 |
Correct |
44 ms |
5248 KB |
Output is correct |
13 |
Correct |
43 ms |
5436 KB |
Output is correct |
14 |
Correct |
40 ms |
5388 KB |
Output is correct |
15 |
Correct |
47 ms |
5328 KB |
Output is correct |
16 |
Correct |
49 ms |
5328 KB |
Output is correct |
17 |
Correct |
46 ms |
5432 KB |
Output is correct |
18 |
Correct |
384 ms |
34324 KB |
Output is correct |
19 |
Correct |
400 ms |
34372 KB |
Output is correct |
20 |
Correct |
421 ms |
34396 KB |
Output is correct |
21 |
Correct |
45 ms |
5376 KB |
Output is correct |
22 |
Correct |
41 ms |
5308 KB |
Output is correct |
23 |
Correct |
126 ms |
17052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
44 ms |
5288 KB |
Output is correct |
3 |
Correct |
44 ms |
5276 KB |
Output is correct |
4 |
Correct |
459 ms |
33644 KB |
Output is correct |
5 |
Correct |
43 ms |
5344 KB |
Output is correct |
6 |
Correct |
46 ms |
5436 KB |
Output is correct |
7 |
Correct |
44 ms |
5304 KB |
Output is correct |
8 |
Correct |
47 ms |
5440 KB |
Output is correct |
9 |
Correct |
46 ms |
5364 KB |
Output is correct |
10 |
Correct |
42 ms |
5284 KB |
Output is correct |
11 |
Correct |
44 ms |
5648 KB |
Output is correct |
12 |
Correct |
43 ms |
5356 KB |
Output is correct |
13 |
Correct |
50 ms |
5348 KB |
Output is correct |
14 |
Correct |
419 ms |
33456 KB |
Output is correct |
15 |
Correct |
43 ms |
5660 KB |
Output is correct |
16 |
Correct |
422 ms |
33376 KB |
Output is correct |
17 |
Correct |
385 ms |
33324 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
1236 KB |
Output is correct |
3 |
Correct |
5 ms |
1236 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 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 |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
1236 KB |
Output is correct |
17 |
Correct |
45 ms |
5856 KB |
Output is correct |
18 |
Correct |
0 ms |
320 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 |
- |