#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n,a,b;
cin>>n>>a>>b;
ll period=-1;
if(a/__gcd(a,b+1)>2e18/b) period=1e18+10;
period=a/__gcd(a,b+1)*b;
map<ll,ll> ev;
for(int i=0;i<n;i++){
ll l,r;
cin>>l>>r;
if(r-l+1>=period){
ev[0]++;
ev[period]--;
continue;
}
l%=period;
r%=period;
if(l<=r){
ev[l]++;
ev[r+1]--;
}else{
ev[0]++;
ev[r+1]--;
ev[l]++;
ev[period]--;
}
}
ll res=0;
ll tren=0;
ll prosli=-1;
for(auto i:ev){
tren+=i.second;
if(tren>0){
if(prosli==-1) prosli=i.first;
}else{
if(res!=-1) res+=i.first-prosli;
prosli=-1;
}
}
cout<<res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
16 ms |
1224 KB |
Output is correct |
3 |
Correct |
17 ms |
1236 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
15 ms |
1244 KB |
Output is correct |
17 |
Correct |
162 ms |
10240 KB |
Output is correct |
18 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
925 ms |
25348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1596 ms |
83100 KB |
Output is correct |
3 |
Correct |
1670 ms |
75440 KB |
Output is correct |
4 |
Correct |
1642 ms |
71968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1596 ms |
83100 KB |
Output is correct |
3 |
Correct |
1670 ms |
75440 KB |
Output is correct |
4 |
Correct |
1642 ms |
71968 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1598 ms |
71888 KB |
Output is correct |
7 |
Correct |
1584 ms |
72496 KB |
Output is correct |
8 |
Correct |
1611 ms |
71960 KB |
Output is correct |
9 |
Correct |
1632 ms |
72020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1596 ms |
83100 KB |
Output is correct |
3 |
Correct |
1670 ms |
75440 KB |
Output is correct |
4 |
Correct |
1642 ms |
71968 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
152 ms |
10228 KB |
Output is correct |
7 |
Correct |
152 ms |
10248 KB |
Output is correct |
8 |
Correct |
165 ms |
10424 KB |
Output is correct |
9 |
Correct |
162 ms |
10316 KB |
Output is correct |
10 |
Correct |
148 ms |
10268 KB |
Output is correct |
11 |
Correct |
151 ms |
10188 KB |
Output is correct |
12 |
Correct |
160 ms |
10368 KB |
Output is correct |
13 |
Correct |
163 ms |
10216 KB |
Output is correct |
14 |
Correct |
147 ms |
10192 KB |
Output is correct |
15 |
Correct |
159 ms |
10264 KB |
Output is correct |
16 |
Correct |
161 ms |
10260 KB |
Output is correct |
17 |
Correct |
163 ms |
10204 KB |
Output is correct |
18 |
Correct |
1534 ms |
72016 KB |
Output is correct |
19 |
Correct |
1598 ms |
72408 KB |
Output is correct |
20 |
Correct |
1641 ms |
72080 KB |
Output is correct |
21 |
Correct |
176 ms |
10292 KB |
Output is correct |
22 |
Correct |
150 ms |
10172 KB |
Output is correct |
23 |
Correct |
417 ms |
12812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
167 ms |
10312 KB |
Output is correct |
3 |
Correct |
163 ms |
10252 KB |
Output is correct |
4 |
Correct |
1650 ms |
75428 KB |
Output is correct |
5 |
Correct |
167 ms |
10316 KB |
Output is correct |
6 |
Correct |
168 ms |
10224 KB |
Output is correct |
7 |
Correct |
154 ms |
10152 KB |
Output is correct |
8 |
Correct |
158 ms |
10280 KB |
Output is correct |
9 |
Correct |
162 ms |
10280 KB |
Output is correct |
10 |
Correct |
153 ms |
10188 KB |
Output is correct |
11 |
Correct |
156 ms |
10244 KB |
Output is correct |
12 |
Correct |
153 ms |
10228 KB |
Output is correct |
13 |
Correct |
168 ms |
10320 KB |
Output is correct |
14 |
Correct |
1647 ms |
75420 KB |
Output is correct |
15 |
Correct |
147 ms |
10272 KB |
Output is correct |
16 |
Correct |
1581 ms |
71860 KB |
Output is correct |
17 |
Correct |
1512 ms |
72144 KB |
Output is correct |
18 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
16 ms |
1224 KB |
Output is correct |
3 |
Correct |
17 ms |
1236 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
15 ms |
1244 KB |
Output is correct |
17 |
Correct |
162 ms |
10240 KB |
Output is correct |
18 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |