답안 #641084

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
641084 2022-09-16T00:57:02 Z ymm 이상한 기계 (APIO19_strange_device) C++17
100 / 100
1364 ms 20316 KB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

set<pll> s;

void add(ll l, ll r)
{
	auto it = s.lower_bound(pll{l, -1});
	if (it != s.begin()) {
		--it;
		if (it->second >= r) {
			return;
		} else if (it->second >= l) {
			l = it->first;
			s.erase(it++);
		} else {
			++it;
		}
	}
	while (it != s.end() && r >= it->first) {
		r = max(r, it->second);
		s.erase(it++);
	}
	s.insert({l, r});
}

int main()
{
	ll n, A, B;
	cin >> n >> A >> B;
	__int128 p = (__int128)A * B / __gcd(A, B+1);
	if (p < LONG_LONG_MAX)
		p = p * B / __gcd((ll)p, B);
	Loop (i,0,n) {
		ll l, r;
		cin >> l >> r;
		if (r - l + 1 >= p) {
			l = 0;
			r = p;
		} else {
			l %= p;
			r %= p;
			++r;
		}
		if (l < r) {
			add(l, r);
		} else {
			add(l, p);
			add(0, r);
		}
	}
	ll ans = 0;
	for (auto [x, y] : s)
		ans += y - x;
	cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 13 ms 320 KB Output is correct
3 Correct 16 ms 520 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 14 ms 520 KB Output is correct
17 Correct 134 ms 432 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 304 KB Output is correct
5 Correct 970 ms 2724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1340 ms 308 KB Output is correct
3 Correct 1267 ms 292 KB Output is correct
4 Correct 1274 ms 284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1340 ms 308 KB Output is correct
3 Correct 1267 ms 292 KB Output is correct
4 Correct 1274 ms 284 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1292 ms 300 KB Output is correct
7 Correct 1291 ms 304 KB Output is correct
8 Correct 1325 ms 292 KB Output is correct
9 Correct 1282 ms 288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1340 ms 308 KB Output is correct
3 Correct 1267 ms 292 KB Output is correct
4 Correct 1274 ms 284 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 142 ms 296 KB Output is correct
7 Correct 132 ms 300 KB Output is correct
8 Correct 133 ms 296 KB Output is correct
9 Correct 136 ms 212 KB Output is correct
10 Correct 133 ms 296 KB Output is correct
11 Correct 128 ms 304 KB Output is correct
12 Correct 127 ms 212 KB Output is correct
13 Correct 128 ms 284 KB Output is correct
14 Correct 151 ms 212 KB Output is correct
15 Correct 133 ms 212 KB Output is correct
16 Correct 129 ms 212 KB Output is correct
17 Correct 128 ms 3980 KB Output is correct
18 Correct 1323 ms 11660 KB Output is correct
19 Correct 1332 ms 11688 KB Output is correct
20 Correct 1294 ms 11696 KB Output is correct
21 Correct 187 ms 3988 KB Output is correct
22 Correct 131 ms 3976 KB Output is correct
23 Correct 436 ms 12808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 145 ms 296 KB Output is correct
3 Correct 127 ms 296 KB Output is correct
4 Correct 1305 ms 308 KB Output is correct
5 Correct 147 ms 288 KB Output is correct
6 Correct 133 ms 288 KB Output is correct
7 Correct 126 ms 284 KB Output is correct
8 Correct 128 ms 212 KB Output is correct
9 Correct 129 ms 292 KB Output is correct
10 Correct 132 ms 296 KB Output is correct
11 Correct 127 ms 296 KB Output is correct
12 Correct 153 ms 288 KB Output is correct
13 Correct 136 ms 212 KB Output is correct
14 Correct 1295 ms 292 KB Output is correct
15 Correct 134 ms 288 KB Output is correct
16 Correct 1306 ms 4408 KB Output is correct
17 Correct 1315 ms 4336 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 13 ms 320 KB Output is correct
3 Correct 16 ms 520 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 14 ms 520 KB Output is correct
17 Correct 134 ms 432 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 212 KB Output is correct
26 Correct 2 ms 212 KB Output is correct
27 Correct 2 ms 304 KB Output is correct
28 Correct 970 ms 2724 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1340 ms 308 KB Output is correct
31 Correct 1267 ms 292 KB Output is correct
32 Correct 1274 ms 284 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1292 ms 300 KB Output is correct
35 Correct 1291 ms 304 KB Output is correct
36 Correct 1325 ms 292 KB Output is correct
37 Correct 1282 ms 288 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 142 ms 296 KB Output is correct
40 Correct 132 ms 300 KB Output is correct
41 Correct 133 ms 296 KB Output is correct
42 Correct 136 ms 212 KB Output is correct
43 Correct 133 ms 296 KB Output is correct
44 Correct 128 ms 304 KB Output is correct
45 Correct 127 ms 212 KB Output is correct
46 Correct 128 ms 284 KB Output is correct
47 Correct 151 ms 212 KB Output is correct
48 Correct 133 ms 212 KB Output is correct
49 Correct 129 ms 212 KB Output is correct
50 Correct 128 ms 3980 KB Output is correct
51 Correct 1323 ms 11660 KB Output is correct
52 Correct 1332 ms 11688 KB Output is correct
53 Correct 1294 ms 11696 KB Output is correct
54 Correct 187 ms 3988 KB Output is correct
55 Correct 131 ms 3976 KB Output is correct
56 Correct 436 ms 12808 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 145 ms 296 KB Output is correct
59 Correct 127 ms 296 KB Output is correct
60 Correct 1305 ms 308 KB Output is correct
61 Correct 147 ms 288 KB Output is correct
62 Correct 133 ms 288 KB Output is correct
63 Correct 126 ms 284 KB Output is correct
64 Correct 128 ms 212 KB Output is correct
65 Correct 129 ms 292 KB Output is correct
66 Correct 132 ms 296 KB Output is correct
67 Correct 127 ms 296 KB Output is correct
68 Correct 153 ms 288 KB Output is correct
69 Correct 136 ms 212 KB Output is correct
70 Correct 1295 ms 292 KB Output is correct
71 Correct 134 ms 288 KB Output is correct
72 Correct 1306 ms 4408 KB Output is correct
73 Correct 1315 ms 4336 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 1 ms 300 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 14 ms 596 KB Output is correct
80 Correct 1359 ms 20224 KB Output is correct
81 Correct 1343 ms 20076 KB Output is correct
82 Correct 1355 ms 20280 KB Output is correct
83 Correct 1364 ms 20120 KB Output is correct
84 Correct 1348 ms 20144 KB Output is correct
85 Correct 1334 ms 20316 KB Output is correct
86 Correct 433 ms 12808 KB Output is correct
87 Correct 1 ms 212 KB Output is correct