#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define sz(a) (int)a.size()
#define all(x) (x).begin(), (x).end()
int main() {
ll n, a, b; cin >> n >> a >> b;
map<ll, ll> mp;
while(n--){
ll l, r; cin >> l >> r;
if(r-l+1>=a*b){
cout << a*b << endl;
return 0;
}
l%=a*b;
r%=a*b;
if(l>r){
mp[l]++;
mp[a*b]--;
mp[0]++;
mp[r+1]--;
}
else{
mp[l]++;
mp[r+1]--;
}
}
// 1 0 1 -1 -1 0 1 0 -1
// 1 1 2 1 0 0 1 1 0
ll cnt=0, nw=0, ans=0, pcnt=0;
for(auto& u : mp){
cnt+=u.S;
// cout << "[" << u.first << ',' << u.second << ']' << cnt << endl;
if(!pcnt) nw=u.F;
if(!cnt) ans+=u.F-nw;
pcnt=cnt;
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
22 ms |
1216 KB |
Output is correct |
3 |
Correct |
16 ms |
1212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
312 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
1006 ms |
416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
1777 ms |
65420 KB |
Output is correct |
3 |
Incorrect |
1775 ms |
63400 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
1777 ms |
65420 KB |
Output is correct |
3 |
Incorrect |
1775 ms |
63400 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
1777 ms |
65420 KB |
Output is correct |
3 |
Incorrect |
1775 ms |
63400 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
183 ms |
9984 KB |
Output is correct |
3 |
Correct |
165 ms |
9892 KB |
Output is correct |
4 |
Correct |
1694 ms |
63372 KB |
Output is correct |
5 |
Correct |
158 ms |
10052 KB |
Output is correct |
6 |
Correct |
161 ms |
9924 KB |
Output is correct |
7 |
Correct |
175 ms |
9960 KB |
Output is correct |
8 |
Correct |
170 ms |
9876 KB |
Output is correct |
9 |
Correct |
181 ms |
9960 KB |
Output is correct |
10 |
Correct |
152 ms |
9916 KB |
Output is correct |
11 |
Correct |
170 ms |
10088 KB |
Output is correct |
12 |
Correct |
154 ms |
9904 KB |
Output is correct |
13 |
Correct |
157 ms |
9932 KB |
Output is correct |
14 |
Correct |
1678 ms |
63440 KB |
Output is correct |
15 |
Incorrect |
222 ms |
10192 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
22 ms |
1216 KB |
Output is correct |
3 |
Correct |
16 ms |
1212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |