제출 #984297

#제출 시각아이디문제언어결과실행 시간메모리
984297Tsagana이상한 기계 (APIO19_strange_device)C++14
0 / 100
373 ms33648 KiB
#include<bits/stdc++.h>

#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define int long long
#define pi pair<int, int >
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define mset multiset
#define F first
#define S second

using namespace std;

int n, A, B, range;
vector<pair<int, int>> v;
int gcd(int a, int b) {return (!a ? b : gcd(b % a, a));}
void build() {
	int L = gcd(B+1, A); // (a/l * b)
	range = (1e18 / B > A / L ? (A / L) * B : 1e18);
}
void calc(int l, int r) {
	if (r - l > range) {v.pb({1, range}); return ;}
	int s = l / range;
	l %= range ;
	r -= s * range;
	if (r > range) r -= range;
	v.pb({l, 1});
	v.pb({r, 2});
}
int count() {
	sort(all(v));
	int ans = 0, se = 0, si = 0;
	for (auto i: v) {
		if (i.S & 1) {
			if (i.F > 0 && i.F <= se) ans += i.F - si + 1;
		}
		else {
			se = i.F;
			ans += i.F - si + 1;
		}
		si = i.F;
	}
	return ans;
}
void solve ()
{
	cin >> n >> A >> B;
	build();
	for (int i = 1; i <= n; i++) {
		int l, r; cin >> l >> r;
		calc(l, r);
	}
	cout << count();
}
signed main(){IOS solve(); return 0;}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...