Submission #249889

# Submission time Handle Problem Language Result Execution time Memory
249889 2020-07-16T10:11:22 Z Evirir Strange Device (APIO19_strange_device) C++17
100 / 100
774 ms 67272 KB
#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 watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#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
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";}
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(2e18);
const int MOD = 998244353;

const bool DEBUG = 0;
const int MAXN = 1000005;

bool cmp(ii a, ii b){
	if(a.F!=b.F) return a.F<b.F;
	return a.S>b.S;
}

ll n,A,B,P;
ii a[MAXN];
vii v,tmp;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin>>n>>A>>B;
	if(A/__gcd(A,B+1)>=INF/B) P=INF;
	else P=A/__gcd(A,B+1)*B;
	
	forn(i,0,n){
		cin>>a[i].F>>a[i].S;
		if(a[i].S-a[i].F+1>=P){
			cout<<P<<'\n';
			return 0;
		}
		a[i].F%=P;
		a[i].S%=P;
		if(a[i].F<=a[i].S){
			v.pb({a[i].F,a[i].S});
		}
		else{
			v.pb({a[i].F,P-1});
			v.pb({0,a[i].S});
		}
	}
	
	sort(v.begin(), v.end(), cmp);
	forn(i,0,v.size()){
		if(tmp.size() && tmp.back().F<=v[i].F && v[i].S<=tmp.back().S) continue;
		tmp.pb(v[i]);
	}
	v = tmp;
	tmp.clear();
	
	ll ans=0, L=v[0].F;
	forn(i,1,v.size())
	{
		if(v[i-1].S<v[i].F){
			ans+=v[i-1].S-L+1;
			L=v[i].F;
		}
	}
	ans+=v[v.size()-1].S-L+1;
	
	cout<<ans<<'\n';
	
	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:10:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define forn(i,a,b) for(int i=(a);i<(b);i++)
                                    ^
strange_device.cpp:69:2: note: in expansion of macro 'forn'
  forn(i,0,v.size()){
  ^~~~
strange_device.cpp:10:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define forn(i,a,b) for(int i=(a);i<(b);i++)
                                    ^
strange_device.cpp:77:2: note: in expansion of macro 'forn'
  forn(i,1,v.size())
  ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 6 ms 1024 KB Output is correct
3 Correct 7 ms 1024 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 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 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1024 KB Output is correct
17 Correct 71 ms 6504 KB Output is correct
18 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 0 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 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 413 ms 36420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 643 ms 56256 KB Output is correct
3 Correct 625 ms 65748 KB Output is correct
4 Correct 621 ms 67264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 643 ms 56256 KB Output is correct
3 Correct 625 ms 65748 KB Output is correct
4 Correct 621 ms 67264 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 612 ms 67136 KB Output is correct
7 Correct 634 ms 67136 KB Output is correct
8 Correct 621 ms 67132 KB Output is correct
9 Correct 730 ms 67272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 643 ms 56256 KB Output is correct
3 Correct 625 ms 65748 KB Output is correct
4 Correct 621 ms 67264 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 59 ms 10324 KB Output is correct
7 Correct 74 ms 10344 KB Output is correct
8 Correct 62 ms 10216 KB Output is correct
9 Correct 62 ms 10212 KB Output is correct
10 Correct 61 ms 10284 KB Output is correct
11 Correct 75 ms 10220 KB Output is correct
12 Correct 73 ms 10216 KB Output is correct
13 Correct 73 ms 10216 KB Output is correct
14 Correct 61 ms 10220 KB Output is correct
15 Correct 81 ms 10216 KB Output is correct
16 Correct 67 ms 10220 KB Output is correct
17 Correct 65 ms 10360 KB Output is correct
18 Correct 642 ms 67136 KB Output is correct
19 Correct 632 ms 67144 KB Output is correct
20 Correct 750 ms 67252 KB Output is correct
21 Correct 66 ms 10220 KB Output is correct
22 Correct 58 ms 10276 KB Output is correct
23 Correct 190 ms 23692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 68 ms 10216 KB Output is correct
3 Correct 68 ms 10216 KB Output is correct
4 Correct 739 ms 67160 KB Output is correct
5 Correct 69 ms 10212 KB Output is correct
6 Correct 70 ms 10216 KB Output is correct
7 Correct 70 ms 10212 KB Output is correct
8 Correct 70 ms 10216 KB Output is correct
9 Correct 68 ms 10216 KB Output is correct
10 Correct 69 ms 10220 KB Output is correct
11 Correct 69 ms 10216 KB Output is correct
12 Correct 59 ms 10216 KB Output is correct
13 Correct 71 ms 10216 KB Output is correct
14 Correct 738 ms 67272 KB Output is correct
15 Correct 68 ms 10216 KB Output is correct
16 Correct 630 ms 66964 KB Output is correct
17 Correct 630 ms 67068 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 6 ms 1024 KB Output is correct
3 Correct 7 ms 1024 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 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 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1024 KB Output is correct
17 Correct 71 ms 6504 KB Output is correct
18 Correct 1 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 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 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 413 ms 36420 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 643 ms 56256 KB Output is correct
31 Correct 625 ms 65748 KB Output is correct
32 Correct 621 ms 67264 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 612 ms 67136 KB Output is correct
35 Correct 634 ms 67136 KB Output is correct
36 Correct 621 ms 67132 KB Output is correct
37 Correct 730 ms 67272 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 59 ms 10324 KB Output is correct
40 Correct 74 ms 10344 KB Output is correct
41 Correct 62 ms 10216 KB Output is correct
42 Correct 62 ms 10212 KB Output is correct
43 Correct 61 ms 10284 KB Output is correct
44 Correct 75 ms 10220 KB Output is correct
45 Correct 73 ms 10216 KB Output is correct
46 Correct 73 ms 10216 KB Output is correct
47 Correct 61 ms 10220 KB Output is correct
48 Correct 81 ms 10216 KB Output is correct
49 Correct 67 ms 10220 KB Output is correct
50 Correct 65 ms 10360 KB Output is correct
51 Correct 642 ms 67136 KB Output is correct
52 Correct 632 ms 67144 KB Output is correct
53 Correct 750 ms 67252 KB Output is correct
54 Correct 66 ms 10220 KB Output is correct
55 Correct 58 ms 10276 KB Output is correct
56 Correct 190 ms 23692 KB Output is correct
57 Correct 0 ms 384 KB Output is correct
58 Correct 68 ms 10216 KB Output is correct
59 Correct 68 ms 10216 KB Output is correct
60 Correct 739 ms 67160 KB Output is correct
61 Correct 69 ms 10212 KB Output is correct
62 Correct 70 ms 10216 KB Output is correct
63 Correct 70 ms 10212 KB Output is correct
64 Correct 70 ms 10216 KB Output is correct
65 Correct 68 ms 10216 KB Output is correct
66 Correct 69 ms 10220 KB Output is correct
67 Correct 69 ms 10216 KB Output is correct
68 Correct 59 ms 10216 KB Output is correct
69 Correct 71 ms 10216 KB Output is correct
70 Correct 738 ms 67272 KB Output is correct
71 Correct 68 ms 10216 KB Output is correct
72 Correct 630 ms 66964 KB Output is correct
73 Correct 630 ms 67068 KB Output is correct
74 Correct 0 ms 384 KB Output is correct
75 Correct 0 ms 384 KB Output is correct
76 Correct 1 ms 384 KB Output is correct
77 Correct 0 ms 384 KB Output is correct
78 Correct 0 ms 384 KB Output is correct
79 Correct 7 ms 1408 KB Output is correct
80 Correct 774 ms 66992 KB Output is correct
81 Correct 747 ms 66984 KB Output is correct
82 Correct 722 ms 67064 KB Output is correct
83 Correct 722 ms 67052 KB Output is correct
84 Correct 733 ms 67068 KB Output is correct
85 Correct 724 ms 66880 KB Output is correct
86 Correct 184 ms 23636 KB Output is correct
87 Correct 1 ms 384 KB Output is correct