#include "bits/stdc++.h"
#define ll long long int
#define pb push_back
#define pii pair<ll,ll>
#define ff first
#define ss second
#define sz size()
const int N = 2e5 + 1;
using namespace std;
ll n, a, b, ans = 0;
set <pii> s;
vector <pii> v;
int main(){
cin >> n >> a >> b;
for(int i = 1; i <= n; i++){
ll x, y;
cin >> x >> y;
if(b == 1){
if(y - x + 1 >= a) return cout << a,0;
ll san = (2*x) % a, san1 = (2*y) % a;
if(san <= san1){
v.pb({san,1});
v.pb({san1,0});
}
else{
v.pb({0,1});
v.pb({san1,0});
v.pb({san,1});
v.pb({a-1,0});
}
continue;
}
for(ll j = x; j <= y; j++){
ll san = j + j/b;
san %= a;
int san1 = j % b;
s.insert({san,san1});
}
ans = (int)s.sz;
}
if(b == 1){
ll ac = 0, bas = 1e18;
for(auto i: v){
if(i.ss == 1){
ac++;
bas = min(bas,i.ff);
}
else{
ac--;
if(ac == 0){
ans += i.ff - bas + 1;
bas = 1e18;
}
}
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
68 ms |
12660 KB |
Output is correct |
3 |
Correct |
49 ms |
18256 KB |
Output is correct |
4 |
Correct |
3 ms |
856 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
9 ms |
1112 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1677 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
90 ms |
32336 KB |
Output is correct |
3 |
Correct |
161 ms |
32096 KB |
Output is correct |
4 |
Correct |
78 ms |
30628 KB |
Output is correct |
5 |
Execution timed out |
5060 ms |
62544 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
820 ms |
68912 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
820 ms |
68912 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
820 ms |
68912 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Runtime error |
894 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
68 ms |
12660 KB |
Output is correct |
3 |
Correct |
49 ms |
18256 KB |
Output is correct |
4 |
Correct |
3 ms |
856 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
9 ms |
1112 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |