Submission #163996

# Submission time Handle Problem Language Result Execution time Memory
163996 2019-11-16T15:50:03 Z staniewzki Strange Device (APIO19_strange_device) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
 
ostream& operator<<(ostream &out, string str) {
	for(char c : str) out << c;
	return out;
}
 
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.first << ", " << p.second << ")";
}
 
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}
 
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}
 
#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
 
template<class T> int size(T && a) { return a.size(); }
 
using LL = long long;
using PII = pair<LL, LL>;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	LL A, B;
	cin >> n >> A >> B;
	LL d = gcd(A, B + 1);
	debug(d);
	LL q = -1;
	if(1e18 / A < B / d) q = 1e18 + 1;
	else q = A * B / d;
	debug(q);

	vector<PII> events;
	auto add_interval = [&](LL l, LL r) {
		events.emplace_back(l, +1);
		events.emplace_back(r + 1, -1);
	};

	REP(i, n) {
		LL l, r;
		cin >> l >> r;

		LL a = l / q, b = r / q;
		if(a != b) {
			if(a + 1 < b) {
				cout << q << "\n";
				return 0;
			}
			l %= q, r %= q;
			add_interval(l, q - 1);
			add_interval(0, r);
		}
		else add_interval(l % q, r % q);
	}

	LL ans = 0, last = 0, sum = 0;
	sort(events.begin(), events.end());
	for(auto &e : events) {
		if(sum) ans += (e.ST - last);
		sum += e.ND;
		last = e.ST;
	}

	cout << ans << "\n";
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:49:9: error: 'gcd' was not declared in this scope
  LL d = gcd(A, B + 1);
         ^~~
strange_device.cpp:49:9: note: suggested alternative: 'gcvt'
  LL d = gcd(A, B + 1);
         ^~~
         gcvt
strange_device.cpp:50:10: warning: statement has no effect [-Wunused-value]
  debug(d);
          ^
strange_device.cpp:54:10: warning: statement has no effect [-Wunused-value]
  debug(q);
          ^