#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
//*AC BERSAMA ALLAH FORTIS FORTUNA ADIUVAT
//# nyampah
ll sz;
vector<pair<ll,bool> > lr;
vector<pair<ll,ll> > lr1;
ll n,a,b;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n>>a>>b;
if((b+1)%a==0) sz=b+1;
else sz = a*b;
for(int i=0;i<n;i++){
ll l,r; cin>>l>>r;
l%=sz; r%=sz;
if(l>r){
lr.pb(make_pair(0,0)); lr.pb(make_pair(r,1));
lr.pb(make_pair(l,0)); lr.pb(make_pair(sz-1,1));
// cout<<"-"<<0<<" "<<r<<'\n';
// cout<<"--"<<l<<" "<<sz-1<<'\n';
}
else {
lr.pb(make_pair(l,0)); lr.pb(make_pair(r,1));
}
}
sort(lr.begin(),lr.end());
ll cnt=0, l, r;
for(auto i : lr){
if(i.se == 0){
if(cnt==0) l=i.fi;
cnt++;
}
else cnt--;
if(cnt==0){
r = i.fi;
lr1.pb(make_pair(l,r));
}
}
cout<<'\n';
ll ans=0;
for(auto i : lr1){
ans+=(i.second-i.first+1);
}
cout<<ans<<'\n';
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:46:33: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
46 | lr1.pb(make_pair(l,r));
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
1128 KB |
Output is correct |
3 |
Correct |
5 ms |
1364 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
324 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 |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
276 ms |
36468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
430 ms |
72736 KB |
Output is correct |
3 |
Incorrect |
431 ms |
71876 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
430 ms |
72736 KB |
Output is correct |
3 |
Incorrect |
431 ms |
71876 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
430 ms |
72736 KB |
Output is correct |
3 |
Incorrect |
431 ms |
71876 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
50 ms |
9868 KB |
Output is correct |
3 |
Correct |
44 ms |
10680 KB |
Output is correct |
4 |
Correct |
582 ms |
70924 KB |
Output is correct |
5 |
Correct |
53 ms |
10788 KB |
Output is correct |
6 |
Correct |
44 ms |
10744 KB |
Output is correct |
7 |
Correct |
44 ms |
10756 KB |
Output is correct |
8 |
Correct |
46 ms |
10908 KB |
Output is correct |
9 |
Correct |
50 ms |
10744 KB |
Output is correct |
10 |
Correct |
46 ms |
10712 KB |
Output is correct |
11 |
Correct |
52 ms |
10928 KB |
Output is correct |
12 |
Correct |
39 ms |
10740 KB |
Output is correct |
13 |
Correct |
56 ms |
10804 KB |
Output is correct |
14 |
Correct |
494 ms |
70920 KB |
Output is correct |
15 |
Incorrect |
47 ms |
10676 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
1128 KB |
Output is correct |
3 |
Correct |
5 ms |
1364 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |