Submission #250459

# Submission time Handle Problem Language Result Execution time Memory
250459 2020-07-18T04:08:33 Z DrumpfTheGodEmperor Strange Device (APIO19_strange_device) C++14
100 / 100
1002 ms 77500 KB
#include <bits/stdc++.h>
#define int long long
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int MAX = 4e18 + 1;
int n, A, B;
int mul(int x, int y) {
	if ((MAX + y - 1) / y < x) return MAX;
	return x * y;
}
map<int, int> mp;
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> A >> B;
	int d = A / __gcd(A, B + 1);
	//B * d is the cycle length.
	int cycleLen = mul(d, B);
	fw (i, 0, n) {
		int l, r;
		cin >> l >> r;
		if (r - l + 1 >= cycleLen) {
			cout << cycleLen << "\n";
			return 0;
		}
		//ELse it's either 1 or 2 segments.
		l %= cycleLen, r %= cycleLen;
		if (l > r) {
			//Divide into l to cycleLen - 1 and 0 to r.
			mp[l]++;
			mp[cycleLen]--;
			mp[0]++;
			mp[r + 1]--;
		} else {
			//Just 1 segment.
			mp[l]++;
			mp[r + 1]--;
		}
	}
	if (!mp.count(cycleLen)) mp[cycleLen] = 0;
	
	int curCnt = 0, lst = 0, ans = 0;
	fa (i, mp) {
		int coord = i.fi, cnt = i.se;
		if (curCnt > 0) ans += coord - lst;
		curCnt += cnt;
		lst = coord;
	}
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 8 ms 1408 KB Output is correct
3 Correct 8 ms 1408 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 7 ms 1408 KB Output is correct
17 Correct 79 ms 10488 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 331 ms 8696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 772 ms 73080 KB Output is correct
3 Correct 811 ms 75736 KB Output is correct
4 Correct 903 ms 77360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 772 ms 73080 KB Output is correct
3 Correct 811 ms 75736 KB Output is correct
4 Correct 903 ms 77360 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 833 ms 77500 KB Output is correct
7 Correct 837 ms 77304 KB Output is correct
8 Correct 812 ms 77404 KB Output is correct
9 Correct 883 ms 77304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 772 ms 73080 KB Output is correct
3 Correct 811 ms 75736 KB Output is correct
4 Correct 903 ms 77360 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 69 ms 10364 KB Output is correct
7 Correct 69 ms 10360 KB Output is correct
8 Correct 72 ms 10360 KB Output is correct
9 Correct 81 ms 10360 KB Output is correct
10 Correct 70 ms 10360 KB Output is correct
11 Correct 69 ms 10360 KB Output is correct
12 Correct 73 ms 10360 KB Output is correct
13 Correct 87 ms 10360 KB Output is correct
14 Correct 73 ms 10488 KB Output is correct
15 Correct 83 ms 10360 KB Output is correct
16 Correct 78 ms 10360 KB Output is correct
17 Correct 76 ms 10360 KB Output is correct
18 Correct 796 ms 77340 KB Output is correct
19 Correct 852 ms 77428 KB Output is correct
20 Correct 950 ms 77304 KB Output is correct
21 Correct 75 ms 10360 KB Output is correct
22 Correct 78 ms 10360 KB Output is correct
23 Correct 152 ms 12920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 87 ms 10324 KB Output is correct
3 Correct 83 ms 10360 KB Output is correct
4 Correct 924 ms 77304 KB Output is correct
5 Correct 85 ms 10360 KB Output is correct
6 Correct 97 ms 10360 KB Output is correct
7 Correct 85 ms 10360 KB Output is correct
8 Correct 80 ms 10360 KB Output is correct
9 Correct 88 ms 10368 KB Output is correct
10 Correct 76 ms 10360 KB Output is correct
11 Correct 76 ms 10360 KB Output is correct
12 Correct 76 ms 10360 KB Output is correct
13 Correct 87 ms 10360 KB Output is correct
14 Correct 982 ms 77432 KB Output is correct
15 Correct 69 ms 10360 KB Output is correct
16 Correct 768 ms 77176 KB Output is correct
17 Correct 768 ms 77304 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 8 ms 1408 KB Output is correct
3 Correct 8 ms 1408 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 7 ms 1408 KB Output is correct
17 Correct 79 ms 10488 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 331 ms 8696 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 772 ms 73080 KB Output is correct
31 Correct 811 ms 75736 KB Output is correct
32 Correct 903 ms 77360 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 833 ms 77500 KB Output is correct
35 Correct 837 ms 77304 KB Output is correct
36 Correct 812 ms 77404 KB Output is correct
37 Correct 883 ms 77304 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 69 ms 10364 KB Output is correct
40 Correct 69 ms 10360 KB Output is correct
41 Correct 72 ms 10360 KB Output is correct
42 Correct 81 ms 10360 KB Output is correct
43 Correct 70 ms 10360 KB Output is correct
44 Correct 69 ms 10360 KB Output is correct
45 Correct 73 ms 10360 KB Output is correct
46 Correct 87 ms 10360 KB Output is correct
47 Correct 73 ms 10488 KB Output is correct
48 Correct 83 ms 10360 KB Output is correct
49 Correct 78 ms 10360 KB Output is correct
50 Correct 76 ms 10360 KB Output is correct
51 Correct 796 ms 77340 KB Output is correct
52 Correct 852 ms 77428 KB Output is correct
53 Correct 950 ms 77304 KB Output is correct
54 Correct 75 ms 10360 KB Output is correct
55 Correct 78 ms 10360 KB Output is correct
56 Correct 152 ms 12920 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 87 ms 10324 KB Output is correct
59 Correct 83 ms 10360 KB Output is correct
60 Correct 924 ms 77304 KB Output is correct
61 Correct 85 ms 10360 KB Output is correct
62 Correct 97 ms 10360 KB Output is correct
63 Correct 85 ms 10360 KB Output is correct
64 Correct 80 ms 10360 KB Output is correct
65 Correct 88 ms 10368 KB Output is correct
66 Correct 76 ms 10360 KB Output is correct
67 Correct 76 ms 10360 KB Output is correct
68 Correct 76 ms 10360 KB Output is correct
69 Correct 87 ms 10360 KB Output is correct
70 Correct 982 ms 77432 KB Output is correct
71 Correct 69 ms 10360 KB Output is correct
72 Correct 768 ms 77176 KB Output is correct
73 Correct 768 ms 77304 KB Output is correct
74 Correct 1 ms 384 KB Output is correct
75 Correct 0 ms 308 KB Output is correct
76 Correct 0 ms 384 KB Output is correct
77 Correct 0 ms 384 KB Output is correct
78 Correct 0 ms 384 KB Output is correct
79 Correct 11 ms 1408 KB Output is correct
80 Correct 964 ms 75532 KB Output is correct
81 Correct 909 ms 75596 KB Output is correct
82 Correct 923 ms 75748 KB Output is correct
83 Correct 1002 ms 75508 KB Output is correct
84 Correct 991 ms 75620 KB Output is correct
85 Correct 876 ms 75768 KB Output is correct
86 Correct 146 ms 10232 KB Output is correct
87 Correct 1 ms 384 KB Output is correct