// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
#define fi first
#define se second
const int inf=1e18;
const int mod=998244353;
const int mod2=1e9+7;
const int maxn=200005;
const int maxq=500005;
const int maxl=20;
const int maxa=1000005;
int power(int a,int n){
int res=1;
while(n){
if(n&1) res=res*a%mod;
a=a*a%mod;n>>=1;
}
return res;
}
map<int,int> mp;
void solve(){
int n,a,b;cin >> n >> a >> b;
a=a/__gcd(a,b+1);
if(a>inf/b){
int ans=0;
for(int i=1;i<=n;i++){
int l,r;cin >> l >> r;
ans+=(r-l+1);
}
cout << ans << '\n';
return;
}
a*=b;
for(int i=1;i<=n;i++){
int l,r;cin >> l >> r;
if((r-l+1)>=a){
cout << a << '\n';
return;
}
l%=a;r%=a;
if(l<=r){mp[l]++;mp[r+1]--;}
else{mp[0]++;mp[r+1]--;mp[l]++;mp[a]--;}
}
int ans=0,cur=0,pre=-1;
for(auto x:mp){
if(cur) ans+=(x.first-pre);
cur+=x.second;pre=x.first;
}
cout << ans << '\n';
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int test=1;//cin >> test;
while(test--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
7 ms |
1236 KB |
Output is correct |
3 |
Correct |
8 ms |
1236 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
6 ms |
1308 KB |
Output is correct |
17 |
Correct |
70 ms |
10256 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
240 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
301 ms |
25428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
732 ms |
100116 KB |
Output is correct |
3 |
Correct |
737 ms |
100140 KB |
Output is correct |
4 |
Correct |
756 ms |
100020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
732 ms |
100116 KB |
Output is correct |
3 |
Correct |
737 ms |
100140 KB |
Output is correct |
4 |
Correct |
756 ms |
100020 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
780 ms |
100080 KB |
Output is correct |
7 |
Correct |
806 ms |
100044 KB |
Output is correct |
8 |
Correct |
731 ms |
100076 KB |
Output is correct |
9 |
Correct |
814 ms |
100140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
732 ms |
100116 KB |
Output is correct |
3 |
Correct |
737 ms |
100140 KB |
Output is correct |
4 |
Correct |
756 ms |
100020 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
64 ms |
10244 KB |
Output is correct |
7 |
Correct |
63 ms |
10220 KB |
Output is correct |
8 |
Correct |
67 ms |
10188 KB |
Output is correct |
9 |
Correct |
70 ms |
10188 KB |
Output is correct |
10 |
Correct |
65 ms |
10252 KB |
Output is correct |
11 |
Correct |
80 ms |
10248 KB |
Output is correct |
12 |
Correct |
72 ms |
10188 KB |
Output is correct |
13 |
Correct |
89 ms |
10288 KB |
Output is correct |
14 |
Correct |
75 ms |
10204 KB |
Output is correct |
15 |
Correct |
73 ms |
10272 KB |
Output is correct |
16 |
Correct |
67 ms |
10288 KB |
Output is correct |
17 |
Correct |
64 ms |
10240 KB |
Output is correct |
18 |
Correct |
762 ms |
100260 KB |
Output is correct |
19 |
Correct |
738 ms |
100144 KB |
Output is correct |
20 |
Correct |
792 ms |
100020 KB |
Output is correct |
21 |
Correct |
79 ms |
10268 KB |
Output is correct |
22 |
Correct |
73 ms |
10320 KB |
Output is correct |
23 |
Correct |
123 ms |
12852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
78 ms |
10292 KB |
Output is correct |
3 |
Correct |
68 ms |
10180 KB |
Output is correct |
4 |
Correct |
799 ms |
100140 KB |
Output is correct |
5 |
Correct |
73 ms |
10284 KB |
Output is correct |
6 |
Correct |
84 ms |
10268 KB |
Output is correct |
7 |
Correct |
72 ms |
10292 KB |
Output is correct |
8 |
Correct |
71 ms |
10272 KB |
Output is correct |
9 |
Correct |
76 ms |
10220 KB |
Output is correct |
10 |
Correct |
79 ms |
10252 KB |
Output is correct |
11 |
Correct |
85 ms |
10252 KB |
Output is correct |
12 |
Correct |
80 ms |
10260 KB |
Output is correct |
13 |
Correct |
76 ms |
10304 KB |
Output is correct |
14 |
Correct |
795 ms |
100076 KB |
Output is correct |
15 |
Correct |
79 ms |
10300 KB |
Output is correct |
16 |
Correct |
673 ms |
100128 KB |
Output is correct |
17 |
Correct |
722 ms |
100052 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
7 ms |
1236 KB |
Output is correct |
3 |
Correct |
8 ms |
1236 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
6 ms |
1308 KB |
Output is correct |
17 |
Correct |
70 ms |
10256 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
328 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
240 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
301 ms |
25428 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
732 ms |
100116 KB |
Output is correct |
31 |
Correct |
737 ms |
100140 KB |
Output is correct |
32 |
Correct |
756 ms |
100020 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
780 ms |
100080 KB |
Output is correct |
35 |
Correct |
806 ms |
100044 KB |
Output is correct |
36 |
Correct |
731 ms |
100076 KB |
Output is correct |
37 |
Correct |
814 ms |
100140 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
64 ms |
10244 KB |
Output is correct |
40 |
Correct |
63 ms |
10220 KB |
Output is correct |
41 |
Correct |
67 ms |
10188 KB |
Output is correct |
42 |
Correct |
70 ms |
10188 KB |
Output is correct |
43 |
Correct |
65 ms |
10252 KB |
Output is correct |
44 |
Correct |
80 ms |
10248 KB |
Output is correct |
45 |
Correct |
72 ms |
10188 KB |
Output is correct |
46 |
Correct |
89 ms |
10288 KB |
Output is correct |
47 |
Correct |
75 ms |
10204 KB |
Output is correct |
48 |
Correct |
73 ms |
10272 KB |
Output is correct |
49 |
Correct |
67 ms |
10288 KB |
Output is correct |
50 |
Correct |
64 ms |
10240 KB |
Output is correct |
51 |
Correct |
762 ms |
100260 KB |
Output is correct |
52 |
Correct |
738 ms |
100144 KB |
Output is correct |
53 |
Correct |
792 ms |
100020 KB |
Output is correct |
54 |
Correct |
79 ms |
10268 KB |
Output is correct |
55 |
Correct |
73 ms |
10320 KB |
Output is correct |
56 |
Correct |
123 ms |
12852 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
78 ms |
10292 KB |
Output is correct |
59 |
Correct |
68 ms |
10180 KB |
Output is correct |
60 |
Correct |
799 ms |
100140 KB |
Output is correct |
61 |
Correct |
73 ms |
10284 KB |
Output is correct |
62 |
Correct |
84 ms |
10268 KB |
Output is correct |
63 |
Correct |
72 ms |
10292 KB |
Output is correct |
64 |
Correct |
71 ms |
10272 KB |
Output is correct |
65 |
Correct |
76 ms |
10220 KB |
Output is correct |
66 |
Correct |
79 ms |
10252 KB |
Output is correct |
67 |
Correct |
85 ms |
10252 KB |
Output is correct |
68 |
Correct |
80 ms |
10260 KB |
Output is correct |
69 |
Correct |
76 ms |
10304 KB |
Output is correct |
70 |
Correct |
795 ms |
100076 KB |
Output is correct |
71 |
Correct |
79 ms |
10300 KB |
Output is correct |
72 |
Correct |
673 ms |
100128 KB |
Output is correct |
73 |
Correct |
722 ms |
100052 KB |
Output is correct |
74 |
Correct |
0 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
328 KB |
Output is correct |
76 |
Correct |
1 ms |
212 KB |
Output is correct |
77 |
Correct |
1 ms |
212 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
7 ms |
1280 KB |
Output is correct |
80 |
Correct |
736 ms |
100104 KB |
Output is correct |
81 |
Correct |
769 ms |
100100 KB |
Output is correct |
82 |
Correct |
783 ms |
100136 KB |
Output is correct |
83 |
Correct |
824 ms |
100088 KB |
Output is correct |
84 |
Correct |
763 ms |
100132 KB |
Output is correct |
85 |
Correct |
778 ms |
100200 KB |
Output is correct |
86 |
Correct |
121 ms |
12848 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |