Submission #361925

# Submission time Handle Problem Language Result Execution time Memory
361925 2021-02-01T08:15:56 Z RohamIzadidoost Strange Device (APIO19_strange_device) C++14
100 / 100
1083 ms 64236 KB
#pragma GCC optimize("Ofast,unroll-loops,fast-math")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
#define pll pair<ll , ll >
#define all(x) (x).begin(),(x).end()
#define SZ(x) (ll)(x).size()
#define X   first
#define Y   second
#define mp  make_pair
#define pii pair<int , int>
#define vec vector
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
ll gcd(ll a, ll b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}
const int maxn = 1000*1000+5 ;
const ll inf = 4223372036854775807 ;
const ll mod = 1e9 + 7 ;
const int lg = 20 ;
ll n , a  , b  , l , r , L , R , ans , p , w, k ; 
set<pll> s ; 
int main()
{
	migmig ;
	cin>>n>>a>>b ; 
	if(a/gcd(a , b + 1) > inf / b) p = inf ; 
	else p =  a / gcd(a , b + 1) * b ; 
	//cout<<"p : " << p << endl ; 
	while(n--){
		cin>>l>>r ;
		if(k) continue ;
		if(r - l + 1 >= p ){
			k = 1 ;
			ans = p ; 
			continue ; 
		} 
		l = l % p ; 
		r = r % p ; 
	//	cout<<n <<" : " << endl ; 
		if(r >= l){
			s.insert({l , r}) ; 
		//	cout<<l<<","<<r << endl ; 
		}else{
			s.insert({0 , r}) ; 
			s.insert({l , p - 1}) ; 
		//	cout<<0 <<","<<r <<" & " <<l <<","<<p-1 << endl ; 
		}
	} 
	if(k){
		cout<<ans ; 
		return 0; 
	}
	s.insert({inf + 1 , inf  + 1}) ; 
	L = s.begin() -> X , R = s.begin() -> Y ; 
	auto it = next(s.begin()) ;
	while(it != s.end()){
		if(it -> X > R){
			ans += R - L + 1 ; 
			//cout<<" ad " << L <<" , " << R << endl ; 
			L = it -> X , R = it -> Y ; 
		}else{
			R = max(R , it -> Y) ; 
		}
		it++ ; 
	} 
	cout<<ans << endl ; 
}








# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 7 ms 1388 KB Output is correct
3 Correct 7 ms 1388 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 7 ms 1388 KB Output is correct
17 Correct 63 ms 7660 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 293 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 658 ms 63084 KB Output is correct
3 Correct 705 ms 64008 KB Output is correct
4 Correct 701 ms 64140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 658 ms 63084 KB Output is correct
3 Correct 705 ms 64008 KB Output is correct
4 Correct 701 ms 64140 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 707 ms 64108 KB Output is correct
7 Correct 672 ms 64192 KB Output is correct
8 Correct 675 ms 63960 KB Output is correct
9 Correct 707 ms 64152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 658 ms 63084 KB Output is correct
3 Correct 705 ms 64008 KB Output is correct
4 Correct 701 ms 64140 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 61 ms 7788 KB Output is correct
7 Correct 72 ms 7788 KB Output is correct
8 Correct 65 ms 7660 KB Output is correct
9 Correct 64 ms 7660 KB Output is correct
10 Correct 61 ms 7660 KB Output is correct
11 Correct 62 ms 7660 KB Output is correct
12 Correct 63 ms 7660 KB Output is correct
13 Correct 66 ms 7660 KB Output is correct
14 Correct 62 ms 7672 KB Output is correct
15 Correct 66 ms 7660 KB Output is correct
16 Correct 68 ms 7788 KB Output is correct
17 Correct 63 ms 7660 KB Output is correct
18 Correct 659 ms 64068 KB Output is correct
19 Correct 706 ms 64144 KB Output is correct
20 Correct 716 ms 64124 KB Output is correct
21 Correct 76 ms 7660 KB Output is correct
22 Correct 64 ms 7660 KB Output is correct
23 Correct 127 ms 1260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 77 ms 7788 KB Output is correct
3 Correct 69 ms 7660 KB Output is correct
4 Correct 694 ms 63980 KB Output is correct
5 Correct 64 ms 7660 KB Output is correct
6 Correct 67 ms 7660 KB Output is correct
7 Correct 68 ms 7660 KB Output is correct
8 Correct 68 ms 7692 KB Output is correct
9 Correct 65 ms 7660 KB Output is correct
10 Correct 63 ms 7660 KB Output is correct
11 Correct 64 ms 7660 KB Output is correct
12 Correct 64 ms 7660 KB Output is correct
13 Correct 84 ms 7660 KB Output is correct
14 Correct 681 ms 63852 KB Output is correct
15 Correct 64 ms 7660 KB Output is correct
16 Correct 701 ms 64048 KB Output is correct
17 Correct 658 ms 64036 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 7 ms 1388 KB Output is correct
3 Correct 7 ms 1388 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 7 ms 1388 KB Output is correct
17 Correct 63 ms 7660 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 0 ms 364 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 293 ms 1388 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 658 ms 63084 KB Output is correct
31 Correct 705 ms 64008 KB Output is correct
32 Correct 701 ms 64140 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 707 ms 64108 KB Output is correct
35 Correct 672 ms 64192 KB Output is correct
36 Correct 675 ms 63960 KB Output is correct
37 Correct 707 ms 64152 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 61 ms 7788 KB Output is correct
40 Correct 72 ms 7788 KB Output is correct
41 Correct 65 ms 7660 KB Output is correct
42 Correct 64 ms 7660 KB Output is correct
43 Correct 61 ms 7660 KB Output is correct
44 Correct 62 ms 7660 KB Output is correct
45 Correct 63 ms 7660 KB Output is correct
46 Correct 66 ms 7660 KB Output is correct
47 Correct 62 ms 7672 KB Output is correct
48 Correct 66 ms 7660 KB Output is correct
49 Correct 68 ms 7788 KB Output is correct
50 Correct 63 ms 7660 KB Output is correct
51 Correct 659 ms 64068 KB Output is correct
52 Correct 706 ms 64144 KB Output is correct
53 Correct 716 ms 64124 KB Output is correct
54 Correct 76 ms 7660 KB Output is correct
55 Correct 64 ms 7660 KB Output is correct
56 Correct 127 ms 1260 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 77 ms 7788 KB Output is correct
59 Correct 69 ms 7660 KB Output is correct
60 Correct 694 ms 63980 KB Output is correct
61 Correct 64 ms 7660 KB Output is correct
62 Correct 67 ms 7660 KB Output is correct
63 Correct 68 ms 7660 KB Output is correct
64 Correct 68 ms 7692 KB Output is correct
65 Correct 65 ms 7660 KB Output is correct
66 Correct 63 ms 7660 KB Output is correct
67 Correct 64 ms 7660 KB Output is correct
68 Correct 64 ms 7660 KB Output is correct
69 Correct 84 ms 7660 KB Output is correct
70 Correct 681 ms 63852 KB Output is correct
71 Correct 64 ms 7660 KB Output is correct
72 Correct 701 ms 64048 KB Output is correct
73 Correct 658 ms 64036 KB Output is correct
74 Correct 1 ms 364 KB Output is correct
75 Correct 1 ms 364 KB Output is correct
76 Correct 1 ms 364 KB Output is correct
77 Correct 1 ms 364 KB Output is correct
78 Correct 1 ms 364 KB Output is correct
79 Correct 7 ms 1388 KB Output is correct
80 Correct 739 ms 63628 KB Output is correct
81 Correct 725 ms 63644 KB Output is correct
82 Correct 1083 ms 64108 KB Output is correct
83 Correct 931 ms 63108 KB Output is correct
84 Correct 775 ms 64236 KB Output is correct
85 Correct 689 ms 64192 KB Output is correct
86 Correct 129 ms 1528 KB Output is correct
87 Correct 1 ms 364 KB Output is correct