Submission #122791

#TimeUsernameProblemLanguageResultExecution timeMemory
122791abacabaStrange Device (APIO19_strange_device)C++14
35 / 100
892 ms39916 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 15;
int n;
long long t, a, b, l, r, ans;
vector <pair <long long, int> > temp;
stack <long long> st;

int main() {
	scanf("%d%lld%lld", &n, &a, &b);
	if((b + 1) % a == 0)
		t = b;
	else {
		t = a / __gcd(a, b + 1);
		t *= b;
	}
	while(n--) {
		scanf("%lld%lld", &l, &r);
		if(r - l + 1 >= t)
			return cout << t, 0;
		l %= t, r %= t;
		if(l > r) {
			temp.push_back({l, -1});
			temp.push_back({t, 1});
			temp.push_back({0, -1});
			temp.push_back({r + 1, 1});
		}
		else {
			temp.push_back({l, -1});
			temp.push_back({r + 1, 1});
		}
	}
	sort(temp.begin(), temp.end());
	for(auto i : temp) {
		if(i.second == 1) {
			if(st.size() == 1)
				ans += i.first - st.top();
			st.pop();
		}
		else
			st.push(i.first);
	}
	printf("%lld", ans);
	return 0;
}

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%lld%lld", &n, &a, &b);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &l, &r);
   ~~~~~^~~~~~~~~~~~~~~~~~~~
#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...