#include <iostream>
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
typedef long long int llo;
#define pb push_back
#define a first
#define b second
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <algorithm>
#include <vector>
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
llo n,aa,bb;
cin>>n>>aa>>bb;
pair<llo,llo> it[n];
for(llo i=0;i<n;i++){
cin>>it[i].a>>it[i].b;
}
if((bb+1)%aa==0){
while(true){
int kk=0;
}
vector<pair<llo,llo>> tt;
for(llo i=0;i<n;i++){
it[i].b%=bb;
it[i].a%=bb;
if(it[i].a<=it[i].b){
tt.pb(make_pair(it[i].a,it[i].b));
}
else{
tt.pb(make_pair(it[i].a,aa-1));
tt.pb(make_pair(0,it[i].b));
}
}
sort(tt.begin(),tt.end());
llo tot=0;
llo st,end;
for(llo i=0;i<tt.size();i++){
if(i==0){
st=tt[i].a;
end=tt[i].b;
}
else{
if(tt[i].a<=end){
end=max(end,tt[i].b);
}
else{
tot+=end-st+1;
st=tt[i].a;
end=tt[i].b;
}
}
}
tot+=end-st+1;
cout<<tot<<endl;
}
else{
vector<pair<llo,llo>> tt;
llo cc=aa*bb;
for(llo i=0;i<n;i++){
it[i].b%=cc;
it[i].a%=cc;
if(it[i].a<=it[i].b){
tt.pb(make_pair(it[i].a,it[i].b));
}
else{
tt.pb(make_pair(it[i].a,cc-1));
tt.pb(make_pair(0,it[i].b));
}
}
sort(tt.begin(),tt.end());
llo tot=0;
llo st,end;
for(llo i=0;i<tt.size();i++){
if(i==0){
st=tt[i].a;
end=tt[i].b;
}
else{
if(tt[i].a<=end){
end=max(end,tt[i].b);
}
else{
tot+=end-st+1;
st=tt[i].a;
end=tt[i].b;
}
}
}
tot+=end-st+1;
cout<<tot<<endl;
}
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:31:8: warning: unused variable 'kk' [-Wunused-variable]
int kk=0;
^~
strange_device.cpp:49:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(llo i=0;i<tt.size();i++){
~^~~~~~~~~~
strange_device.cpp:86:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(llo i=0;i<tt.size();i++){
~^~~~~~~~~~
strange_device.cpp:102:12: warning: 'end' may be used uninitialized in this function [-Wmaybe-uninitialized]
tot+=end-st+1;
~~~^~~
strange_device.cpp:102:12: warning: 'st' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5035 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5032 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5021 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5042 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5042 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5042 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5024 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5035 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |