Submission #238380

#TimeUsernameProblemLanguageResultExecution timeMemory
238380luciocfStrange Device (APIO19_strange_device)C++14
0 / 100
1050 ms92476 KiB
#include <bits/stdc++.h>

#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 3e6+10;
const ll inf = 1e18;

int n;
ll A, B, p;

vector<pii> event;

void add_event(ll l, ll r)
{
	if (p <= inf/B)
		l %= (p*B), r %= (p*B);

	event.push_back({l, 0}); event.push_back({r, 1});
}

int main(void)
{
	scanf("%d %lld %lld", &n, &A, &B);

	ll g = __gcd(A, B+1);
	p = A/g;

	for (int i = 1; i <= n; i++)
	{
		ll l, r;
		scanf("%lld %lld", &l, &r);

		if (l/B == r/B) add_event(l, r);
		else
		{
			add_event(l, (l/B + 1ll)*B - 1ll);

			if (l/B != r/B - 1ll)
				add_event((l/B + 1ll)*B, (r/B)*B - 1ll);

			add_event((r/B)*B, r);
		}
	}

	ll prev, ans = 0;
	int open = 0;

	sort(event.begin(), event.end());

	for (auto E: event)
	{
		ll x = E.ff, type = E.ss;

		if (open == 0) prev = x;

		if (type == 0) open++;
		else open--;

		if (open == 0) ans += (x-prev+1ll);
	}

	printf("%lld\n", ans);
}

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:29: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:37: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...