#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mset(d,val) memset((d),val,sizeof(d))
#define forn(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define fore(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> pbds;
#define MAXN 1000005
int n;
ll A,B;
ll l[MAXN],r[MAXN];
unordered_map<ll,unordered_set<ll>> tpairs;
ll cnt=0;
void S1()
{
forn(it,0,n){
ll L=l[it], R=r[it];
fore(i,L,R){
ll x=(i+(i/B))%A;
ll y=i%B;
if(tpairs[x].find(y)==tpairs[x].end()){
tpairs[x].insert(y);
cnt++;
}
}
}
cout<<cnt<<'\n';
}
void S2()
{
cout<<min(r[0]-l[0]+1, A*B)<<'\n';
}
/*void S4()
{
forn(i,0,n){
ll d=r[i]-l[i];
if(A%2==0){
cout<<max((d/2)+1, A/2)<<'\n';
}
else{
cout<<max((d/2)+1, A)<<'\n';
}
}
}
void S3()
{
ll ans[A][B];
ll prev[A][B],preh[A][B];
forn(i,0,n){
ll Lx=(l[i]+l[i]/B)%A;
ll Ly=l[i]%B;
ll Rx=(R[i]+R[i]/B)%A;
ll Ry=R[i]%B;
cout<<1<<'\n';
}
}*/
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>A>>B;
forn(i,0,n){
cin>>l[i]>>r[i];
}
if(n==1) S2();
//else if(A*B<=1000000) S3();
//else if(B==1) S4();
else S1();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Execution timed out |
5079 ms |
256760 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Execution timed out |
5097 ms |
39544 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Execution timed out |
5081 ms |
204240 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Execution timed out |
5081 ms |
204240 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Execution timed out |
5081 ms |
204240 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Runtime error |
3685 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Execution timed out |
5079 ms |
256760 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |