답안 #238387

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
238387 2020-06-11T00:16:53 Z luciocf 이상한 기계 (APIO19_strange_device) C++14
100 / 100
1760 ms 158176 KB
#include <bits/stdc++.h>

#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef pair<ll, 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);

	if (l <= r)
	{
		event.push_back({l, 0});
		event.push_back({r, 1});
	}
	else
	{
		event.push_back({l, 0});
		event.push_back({p*B-1ll, 1});

		event.push_back({0, 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;

	bool flag = 0;

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

		if ((r-l+1)/p >= B)
			flag = 1;

		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);
		}
	}

	if (flag)
	{
		printf("%lld\n", p*B);
		return 0;
	}

	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

strange_device.cpp: In function 'int main()':
strange_device.cpp:41: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:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld", &l, &r);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 11 ms 1020 KB Output is correct
3 Correct 12 ms 1020 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 12 ms 1020 KB Output is correct
17 Correct 81 ms 4584 KB Output is correct
18 Correct 4 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 908 ms 131796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 715 ms 33316 KB Output is correct
3 Correct 1437 ms 131924 KB Output is correct
4 Correct 1516 ms 157904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 715 ms 33316 KB Output is correct
3 Correct 1437 ms 131924 KB Output is correct
4 Correct 1516 ms 157904 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 1513 ms 158104 KB Output is correct
7 Correct 727 ms 69012 KB Output is correct
8 Correct 1342 ms 157908 KB Output is correct
9 Correct 1611 ms 158176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 715 ms 33316 KB Output is correct
3 Correct 1437 ms 131924 KB Output is correct
4 Correct 1516 ms 157904 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 97 ms 11488 KB Output is correct
7 Correct 133 ms 20304 KB Output is correct
8 Correct 131 ms 20304 KB Output is correct
9 Correct 129 ms 20304 KB Output is correct
10 Correct 94 ms 11748 KB Output is correct
11 Correct 129 ms 20340 KB Output is correct
12 Correct 120 ms 20304 KB Output is correct
13 Correct 141 ms 20304 KB Output is correct
14 Correct 72 ms 7272 KB Output is correct
15 Correct 117 ms 11232 KB Output is correct
16 Correct 82 ms 7392 KB Output is correct
17 Correct 125 ms 20304 KB Output is correct
18 Correct 1459 ms 157972 KB Output is correct
19 Correct 1372 ms 158056 KB Output is correct
20 Correct 1760 ms 157908 KB Output is correct
21 Correct 179 ms 20304 KB Output is correct
22 Correct 104 ms 20432 KB Output is correct
23 Correct 348 ms 45040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 80 ms 4612 KB Output is correct
3 Correct 76 ms 4584 KB Output is correct
4 Correct 1050 ms 86296 KB Output is correct
5 Correct 93 ms 7528 KB Output is correct
6 Correct 77 ms 7520 KB Output is correct
7 Correct 75 ms 7520 KB Output is correct
8 Correct 89 ms 8028 KB Output is correct
9 Correct 79 ms 7900 KB Output is correct
10 Correct 79 ms 7268 KB Output is correct
11 Correct 77 ms 7268 KB Output is correct
12 Correct 70 ms 7268 KB Output is correct
13 Correct 84 ms 7644 KB Output is correct
14 Correct 834 ms 52824 KB Output is correct
15 Correct 83 ms 7268 KB Output is correct
16 Correct 689 ms 68964 KB Output is correct
17 Correct 958 ms 94940 KB Output is correct
18 Correct 4 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 11 ms 1020 KB Output is correct
3 Correct 12 ms 1020 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 12 ms 1020 KB Output is correct
17 Correct 81 ms 4584 KB Output is correct
18 Correct 4 ms 256 KB Output is correct
19 Correct 5 ms 256 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 4 ms 256 KB Output is correct
22 Correct 4 ms 256 KB Output is correct
23 Correct 5 ms 256 KB Output is correct
24 Correct 4 ms 256 KB Output is correct
25 Correct 6 ms 512 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 908 ms 131796 KB Output is correct
29 Correct 5 ms 256 KB Output is correct
30 Correct 715 ms 33316 KB Output is correct
31 Correct 1437 ms 131924 KB Output is correct
32 Correct 1516 ms 157904 KB Output is correct
33 Correct 5 ms 256 KB Output is correct
34 Correct 1513 ms 158104 KB Output is correct
35 Correct 727 ms 69012 KB Output is correct
36 Correct 1342 ms 157908 KB Output is correct
37 Correct 1611 ms 158176 KB Output is correct
38 Correct 4 ms 256 KB Output is correct
39 Correct 97 ms 11488 KB Output is correct
40 Correct 133 ms 20304 KB Output is correct
41 Correct 131 ms 20304 KB Output is correct
42 Correct 129 ms 20304 KB Output is correct
43 Correct 94 ms 11748 KB Output is correct
44 Correct 129 ms 20340 KB Output is correct
45 Correct 120 ms 20304 KB Output is correct
46 Correct 141 ms 20304 KB Output is correct
47 Correct 72 ms 7272 KB Output is correct
48 Correct 117 ms 11232 KB Output is correct
49 Correct 82 ms 7392 KB Output is correct
50 Correct 125 ms 20304 KB Output is correct
51 Correct 1459 ms 157972 KB Output is correct
52 Correct 1372 ms 158056 KB Output is correct
53 Correct 1760 ms 157908 KB Output is correct
54 Correct 179 ms 20304 KB Output is correct
55 Correct 104 ms 20432 KB Output is correct
56 Correct 348 ms 45040 KB Output is correct
57 Correct 5 ms 384 KB Output is correct
58 Correct 80 ms 4612 KB Output is correct
59 Correct 76 ms 4584 KB Output is correct
60 Correct 1050 ms 86296 KB Output is correct
61 Correct 93 ms 7528 KB Output is correct
62 Correct 77 ms 7520 KB Output is correct
63 Correct 75 ms 7520 KB Output is correct
64 Correct 89 ms 8028 KB Output is correct
65 Correct 79 ms 7900 KB Output is correct
66 Correct 79 ms 7268 KB Output is correct
67 Correct 77 ms 7268 KB Output is correct
68 Correct 70 ms 7268 KB Output is correct
69 Correct 84 ms 7644 KB Output is correct
70 Correct 834 ms 52824 KB Output is correct
71 Correct 83 ms 7268 KB Output is correct
72 Correct 689 ms 68964 KB Output is correct
73 Correct 958 ms 94940 KB Output is correct
74 Correct 4 ms 256 KB Output is correct
75 Correct 5 ms 384 KB Output is correct
76 Correct 4 ms 256 KB Output is correct
77 Correct 5 ms 384 KB Output is correct
78 Correct 5 ms 384 KB Output is correct
79 Correct 13 ms 1276 KB Output is correct
80 Correct 858 ms 69564 KB Output is correct
81 Correct 978 ms 94016 KB Output is correct
82 Correct 1619 ms 158032 KB Output is correct
83 Correct 1576 ms 158084 KB Output is correct
84 Correct 1701 ms 157880 KB Output is correct
85 Correct 1595 ms 158036 KB Output is correct
86 Correct 349 ms 44860 KB Output is correct
87 Correct 5 ms 384 KB Output is correct