#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 3;
int n;
long long a,b;
map<long long,int> ma;
set<long long> s;
int res[N];
vector<pair<long long,long long> > in;
long long rng[N],ans;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> a >> b;
for(int i = 0;i < n;i++)
{
long long x,y;
cin >> x >> y;
if(y-x+1LL>=a*b){ cout << a*b; return 0; }
y++;
x%=(a*b),y%=(a*b);
if(y<x) in.push_back({0LL,y}),in.push_back({x,a*b});
else in.push_back({x,y});
s.insert(x),s.insert(y);
}
s.insert(0),s.insert(a*b);
long long prev = 0;
int id = 0;
for(auto x : s) ma[x] = ++id,rng[id-1] = x-prev,prev = x;
for(auto x : in) res[ma[x.first]]++,res[ma[x.second]]--;
for(int i = 1;i < 10;i++) res[i]+=res[i-1];
for(int i = 1;i < N;i++) if(res[i]) ans+=rng[i];
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
20 ms |
2172 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
8 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
9 ms |
640 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1374 ms |
174584 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1374 ms |
174584 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1374 ms |
174584 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
140 ms |
17892 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
20 ms |
2172 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |