Submission #1100657

# Submission time Handle Problem Language Result Execution time Memory
1100657 2024-10-14T11:49:14 Z vjudge1 Strange Device (APIO19_strange_device) C++17
100 / 100
766 ms 195056 KB
//#pragma optimize ("g",on)
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define ll long long
#define db double
#define ld long double
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define len(x) (int)x.size()
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define vvi vector<vi>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define mii map<int,int>
#define y1 u_will_not_notice_this15
#define hash u_will_not_notice_this
#define tm (tl+tr>>1)
#define ls v<<1,tl,tm
#define rs v<<1|1,tm+1,tr
#define pii pair<int,int>
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define str string
#define ins insert
#define elif else if
using namespace std;
using namespace __gnu_pbds;
const int maxn=1e6+3020,mod=1e9+7,inf=1e18,bir=1,nol=0;
const bool TEST=0;
const str tch="+abcdefghijklmnopqrstuvwxyz",Tch="+ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const str Monday_14_10_24[5]={"NO\n","YES\n","-1\n","0\n","1\n"};
void at(int ok){cout<<Monday_14_10_24[ok];}
bool bit(int mask,int i){return ((bir<<i)&mask);}
int gcd(int a,int b){while(b){if(a>b) swap(a,b);b%=a;}return a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int rnd(){return (rand()<<15)^rand();}
int bpm(int a,int b){a%=mod;if(b==0) return 1;if(b&1)return bpm(a,b-1)*a%mod;int x=bpm(a,b>>1);return x*x%mod;}
int bp(int a,int b){if(b==0) return 1;if(b&1)return bp(a,b-1)*a;int x=bp(a,b>>1);return x*x;}
//CODE STARTS HERE:
//don't get stuck on one aproach
int n,a,b,l[maxn],r[maxn],lcc;
void whyareucopying(){
	cin>>n>>a>>b;
	int s=0;
	for(int i=1;i<=n;i++)cin>>l[i]>>r[i],s+=r[i]-l[i]+1;
	if(a/gcd(a,b+1)>inf/b){
		cout<<s<<'\n';return;
	}
	lcc=a/gcd(a,b+1)*b;
	if(lcc>inf){
		cout<<s<<'\n';return;
	}
	set<pii>st;
	for(int i=1;i<=n;i++){
		if(r[i]-l[i]+1>=lcc){
			cout<<lcc<<'\n';return;
		}
		if(l[i]%lcc<=r[i]%lcc)st.ins({l[i]%lcc+1,r[i]%lcc+1});
		else st.ins({1,r[i]%lcc+1}),st.ins({l[i]%lcc+1,lcc});
	}
	mii mp;
	for(auto [l,r]:st)mp[l]=r;	
	int mx=-inf,mn=inf;
	vpii v;
	for(auto [l,r]:mp){
		if(l>mx){
			if(mx!=-inf)v.pb({mn,mx});
			mn=l,mx=r;
		}
		mx=max(mx,r);
	}
	v.pb({mn,mx});
	int ans=0;
	for(auto [l,r]:v)ans+=r-l+1;
	cout<<ans<<'\n';
}
signed main(){
//	freopen("txt.in","r",stdin),freopen("txt.out","w",stdout);
	ios_base::sync_with_stdio(0),cin.tie(0);
	srand(time(0));
	int T=1;
	if(TEST)cin>>T;
	for(int i=1;i<=T;i++){
//		cout<<"Case "<<i<<": ";
		whyareucopying();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 6 ms 4232 KB Output is correct
3 Correct 6 ms 4176 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2552 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 6 ms 4176 KB Output is correct
17 Correct 56 ms 22488 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2552 KB Output is correct
2 Correct 1 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 1 ms 2640 KB Output is correct
5 Correct 165 ms 15996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 681 ms 159720 KB Output is correct
3 Correct 662 ms 159928 KB Output is correct
4 Correct 687 ms 194872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 681 ms 159720 KB Output is correct
3 Correct 662 ms 159928 KB Output is correct
4 Correct 687 ms 194872 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 680 ms 192688 KB Output is correct
7 Correct 715 ms 192512 KB Output is correct
8 Correct 697 ms 192696 KB Output is correct
9 Correct 721 ms 187912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 681 ms 159720 KB Output is correct
3 Correct 662 ms 159928 KB Output is correct
4 Correct 687 ms 194872 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 68 ms 25456 KB Output is correct
7 Correct 53 ms 25544 KB Output is correct
8 Correct 57 ms 25532 KB Output is correct
9 Correct 61 ms 26044 KB Output is correct
10 Correct 57 ms 26056 KB Output is correct
11 Correct 57 ms 25548 KB Output is correct
12 Correct 54 ms 26044 KB Output is correct
13 Correct 56 ms 25460 KB Output is correct
14 Correct 54 ms 26044 KB Output is correct
15 Correct 58 ms 25872 KB Output is correct
16 Correct 59 ms 26080 KB Output is correct
17 Correct 62 ms 26048 KB Output is correct
18 Correct 662 ms 195000 KB Output is correct
19 Correct 688 ms 195056 KB Output is correct
20 Correct 699 ms 188200 KB Output is correct
21 Correct 59 ms 26044 KB Output is correct
22 Correct 64 ms 25348 KB Output is correct
23 Correct 84 ms 22244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 62 ms 22412 KB Output is correct
3 Correct 61 ms 22256 KB Output is correct
4 Correct 665 ms 159976 KB Output is correct
5 Correct 60 ms 25424 KB Output is correct
6 Correct 60 ms 26080 KB Output is correct
7 Correct 62 ms 26044 KB Output is correct
8 Correct 61 ms 26044 KB Output is correct
9 Correct 62 ms 26044 KB Output is correct
10 Correct 65 ms 25896 KB Output is correct
11 Correct 63 ms 25976 KB Output is correct
12 Correct 60 ms 26056 KB Output is correct
13 Correct 65 ms 26044 KB Output is correct
14 Correct 710 ms 188088 KB Output is correct
15 Correct 60 ms 26044 KB Output is correct
16 Correct 712 ms 192696 KB Output is correct
17 Correct 696 ms 192724 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 6 ms 4232 KB Output is correct
3 Correct 6 ms 4176 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2552 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 6 ms 4176 KB Output is correct
17 Correct 56 ms 22488 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2384 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2552 KB Output is correct
25 Correct 1 ms 2640 KB Output is correct
26 Correct 2 ms 2640 KB Output is correct
27 Correct 1 ms 2640 KB Output is correct
28 Correct 165 ms 15996 KB Output is correct
29 Correct 1 ms 2384 KB Output is correct
30 Correct 681 ms 159720 KB Output is correct
31 Correct 662 ms 159928 KB Output is correct
32 Correct 687 ms 194872 KB Output is correct
33 Correct 1 ms 2384 KB Output is correct
34 Correct 680 ms 192688 KB Output is correct
35 Correct 715 ms 192512 KB Output is correct
36 Correct 697 ms 192696 KB Output is correct
37 Correct 721 ms 187912 KB Output is correct
38 Correct 1 ms 2384 KB Output is correct
39 Correct 68 ms 25456 KB Output is correct
40 Correct 53 ms 25544 KB Output is correct
41 Correct 57 ms 25532 KB Output is correct
42 Correct 61 ms 26044 KB Output is correct
43 Correct 57 ms 26056 KB Output is correct
44 Correct 57 ms 25548 KB Output is correct
45 Correct 54 ms 26044 KB Output is correct
46 Correct 56 ms 25460 KB Output is correct
47 Correct 54 ms 26044 KB Output is correct
48 Correct 58 ms 25872 KB Output is correct
49 Correct 59 ms 26080 KB Output is correct
50 Correct 62 ms 26048 KB Output is correct
51 Correct 662 ms 195000 KB Output is correct
52 Correct 688 ms 195056 KB Output is correct
53 Correct 699 ms 188200 KB Output is correct
54 Correct 59 ms 26044 KB Output is correct
55 Correct 64 ms 25348 KB Output is correct
56 Correct 84 ms 22244 KB Output is correct
57 Correct 1 ms 2384 KB Output is correct
58 Correct 62 ms 22412 KB Output is correct
59 Correct 61 ms 22256 KB Output is correct
60 Correct 665 ms 159976 KB Output is correct
61 Correct 60 ms 25424 KB Output is correct
62 Correct 60 ms 26080 KB Output is correct
63 Correct 62 ms 26044 KB Output is correct
64 Correct 61 ms 26044 KB Output is correct
65 Correct 62 ms 26044 KB Output is correct
66 Correct 65 ms 25896 KB Output is correct
67 Correct 63 ms 25976 KB Output is correct
68 Correct 60 ms 26056 KB Output is correct
69 Correct 65 ms 26044 KB Output is correct
70 Correct 710 ms 188088 KB Output is correct
71 Correct 60 ms 26044 KB Output is correct
72 Correct 712 ms 192696 KB Output is correct
73 Correct 696 ms 192724 KB Output is correct
74 Correct 1 ms 2384 KB Output is correct
75 Correct 1 ms 2384 KB Output is correct
76 Correct 1 ms 2384 KB Output is correct
77 Correct 1 ms 2556 KB Output is correct
78 Correct 1 ms 2384 KB Output is correct
79 Correct 6 ms 4432 KB Output is correct
80 Correct 705 ms 192696 KB Output is correct
81 Correct 682 ms 188136 KB Output is correct
82 Correct 699 ms 192696 KB Output is correct
83 Correct 766 ms 192736 KB Output is correct
84 Correct 751 ms 188088 KB Output is correct
85 Correct 707 ms 187992 KB Output is correct
86 Correct 84 ms 20552 KB Output is correct
87 Correct 1 ms 2384 KB Output is correct