Submission #266714

# Submission time Handle Problem Language Result Execution time Memory
266714 2020-08-15T12:23:00 Z anubhavdhar Strange Device (APIO19_strange_device) C++14
100 / 100
741 ms 49248 KB
#include<bits/stdc++.h>

#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first 
#define ss second
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define FOR(i,N) for(i=0;i<(N);++i)
#define FORe(i,N) for(i=1;i<=(N);++i)
#define FORr(i,a,b) for(i=(a);i<(b);++i)
#define FORrev(i,N) for(i=(N);i>=0;--i)
#define F0R(i,N) for(int i=0;i<(N);++i)
#define F0Re(i,N) for(int i=1;i<=(N);++i)
#define F0Rr(i,a,b) for(ll i=(a);i<(b);++i)
#define F0Rrev(i,N) for(int i=(N);i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define dbgLine cerr<<" LINE : "<<__LINE__<<"\n"
#define ldd long double

using namespace std;

const int Alp = 26;
const int __PRECISION = 9;
const int inf = 1e9 + 8;

const ldd PI = acos(-1);
const ldd EPS = 1e-7;

const ll MOD = 1e9 + 7;
const ll MAXN = 2e5 + 5;
const ll ROOTN = 320;
const ll LOGN = 18;
const ll INF = 1e18 + 1022;

ll n, A, B, l, r, sm, mxDiff, T;
vll V, ranges;

ll gcd(ll a, ll b)
{
	if(a > b)
		swap(a, b);
	if(b % a == 0)
		return a;
	return gcd(b%a, a);
}

inline void check_period()
{
	ll tmp = gcd(A, B+1);
	if(log2(A*1.0) + log(B*1.0) - log(1.0 * tmp) > 59.99)
	{
		cout<<sm<<'\n';
		exit(0);
	}
	T = B * (A / tmp);
	if(mxDiff >= T)
	{
		cout<<T<<'\n';
		exit(0);
	}
}

signed main()
{

	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	

	sm = mxDiff = 0;
	cin>>n>>A>>B;
	F0R(i, n)
	{
		cin>>l>>r;
		sm += r - l + 1;
		mxDiff = max(mxDiff, r-l+1);
		ranges.pb(mp(l, r));
	}

	check_period();
	sm = 0;
	F0R(i, n)
	{
		l = ranges[i].ff % T, r = ranges[i].ss % T;
		V.pb(mp(l, 0));
		V.pb(mp(r, 1));
		if(l > r)
			V.pb(mp(T-1, 1)),	V.pb(mp(0, 0));
	}

	// cerr<<"period = "<<T<<'\n';
	sort(all(V));

	// for(pll x : V)
		// cout<<"("<<x.ff<<','<<x.ss<<")\n";
	
	ll lst = -1, act = 0;

	for(pll pp : V)
	{
		if(act == 0 and pp.ss == 0)
			++sm;
		if(act > 0)
			sm += pp.ff - lst;
		if(pp.ss == 0)
			++act;
		else if(pp.ss == 1)
			--act;
		lst = pp.ff;
	}

	cout<<sm<<'\n';

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 6 ms 1148 KB Output is correct
3 Correct 9 ms 1148 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 6 ms 1180 KB Output is correct
17 Correct 65 ms 6124 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 288 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# 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 1 ms 384 KB Output is correct
5 Correct 427 ms 48988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 575 ms 49044 KB Output is correct
3 Correct 587 ms 49088 KB Output is correct
4 Correct 565 ms 49248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 575 ms 49044 KB Output is correct
3 Correct 587 ms 49088 KB Output is correct
4 Correct 565 ms 49248 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 617 ms 49148 KB Output is correct
7 Correct 582 ms 49044 KB Output is correct
8 Correct 591 ms 49032 KB Output is correct
9 Correct 685 ms 49116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 575 ms 49044 KB Output is correct
3 Correct 587 ms 49088 KB Output is correct
4 Correct 565 ms 49248 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 58 ms 6124 KB Output is correct
7 Correct 60 ms 6256 KB Output is correct
8 Correct 54 ms 6124 KB Output is correct
9 Correct 55 ms 6124 KB Output is correct
10 Correct 56 ms 6120 KB Output is correct
11 Correct 58 ms 6292 KB Output is correct
12 Correct 54 ms 6124 KB Output is correct
13 Correct 60 ms 6120 KB Output is correct
14 Correct 57 ms 6228 KB Output is correct
15 Correct 63 ms 6120 KB Output is correct
16 Correct 61 ms 6132 KB Output is correct
17 Correct 55 ms 6124 KB Output is correct
18 Correct 589 ms 48928 KB Output is correct
19 Correct 555 ms 48988 KB Output is correct
20 Correct 695 ms 49124 KB Output is correct
21 Correct 63 ms 6124 KB Output is correct
22 Correct 51 ms 6296 KB Output is correct
23 Correct 166 ms 22232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 61 ms 6248 KB Output is correct
3 Correct 60 ms 6124 KB Output is correct
4 Correct 713 ms 49004 KB Output is correct
5 Correct 73 ms 6124 KB Output is correct
6 Correct 62 ms 6280 KB Output is correct
7 Correct 60 ms 6120 KB Output is correct
8 Correct 67 ms 6176 KB Output is correct
9 Correct 62 ms 6124 KB Output is correct
10 Correct 69 ms 6120 KB Output is correct
11 Correct 62 ms 6120 KB Output is correct
12 Correct 55 ms 6120 KB Output is correct
13 Correct 64 ms 6120 KB Output is correct
14 Correct 671 ms 49088 KB Output is correct
15 Correct 64 ms 6120 KB Output is correct
16 Correct 542 ms 49000 KB Output is correct
17 Correct 585 ms 49148 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 6 ms 1148 KB Output is correct
3 Correct 9 ms 1148 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 6 ms 1180 KB Output is correct
17 Correct 65 ms 6124 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 288 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 427 ms 48988 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 575 ms 49044 KB Output is correct
31 Correct 587 ms 49088 KB Output is correct
32 Correct 565 ms 49248 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 617 ms 49148 KB Output is correct
35 Correct 582 ms 49044 KB Output is correct
36 Correct 591 ms 49032 KB Output is correct
37 Correct 685 ms 49116 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 58 ms 6124 KB Output is correct
40 Correct 60 ms 6256 KB Output is correct
41 Correct 54 ms 6124 KB Output is correct
42 Correct 55 ms 6124 KB Output is correct
43 Correct 56 ms 6120 KB Output is correct
44 Correct 58 ms 6292 KB Output is correct
45 Correct 54 ms 6124 KB Output is correct
46 Correct 60 ms 6120 KB Output is correct
47 Correct 57 ms 6228 KB Output is correct
48 Correct 63 ms 6120 KB Output is correct
49 Correct 61 ms 6132 KB Output is correct
50 Correct 55 ms 6124 KB Output is correct
51 Correct 589 ms 48928 KB Output is correct
52 Correct 555 ms 48988 KB Output is correct
53 Correct 695 ms 49124 KB Output is correct
54 Correct 63 ms 6124 KB Output is correct
55 Correct 51 ms 6296 KB Output is correct
56 Correct 166 ms 22232 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 61 ms 6248 KB Output is correct
59 Correct 60 ms 6124 KB Output is correct
60 Correct 713 ms 49004 KB Output is correct
61 Correct 73 ms 6124 KB Output is correct
62 Correct 62 ms 6280 KB Output is correct
63 Correct 60 ms 6120 KB Output is correct
64 Correct 67 ms 6176 KB Output is correct
65 Correct 62 ms 6124 KB Output is correct
66 Correct 69 ms 6120 KB Output is correct
67 Correct 62 ms 6120 KB Output is correct
68 Correct 55 ms 6120 KB Output is correct
69 Correct 64 ms 6120 KB Output is correct
70 Correct 671 ms 49088 KB Output is correct
71 Correct 64 ms 6120 KB Output is correct
72 Correct 542 ms 49000 KB Output is correct
73 Correct 585 ms 49148 KB Output is correct
74 Correct 1 ms 384 KB Output is correct
75 Correct 1 ms 384 KB Output is correct
76 Correct 0 ms 384 KB Output is correct
77 Correct 0 ms 384 KB Output is correct
78 Correct 1 ms 384 KB Output is correct
79 Correct 5 ms 1148 KB Output is correct
80 Correct 741 ms 48952 KB Output is correct
81 Correct 732 ms 48928 KB Output is correct
82 Correct 660 ms 48956 KB Output is correct
83 Correct 664 ms 49084 KB Output is correct
84 Correct 671 ms 48992 KB Output is correct
85 Correct 672 ms 48928 KB Output is correct
86 Correct 162 ms 22228 KB Output is correct
87 Correct 1 ms 384 KB Output is correct