Submission #187027

# Submission time Handle Problem Language Result Execution time Memory
187027 2020-01-12T12:07:58 Z KCSC Strange Device (APIO19_strange_device) C++14
100 / 100
3228 ms 48512 KB
#include <bits/stdc++.h>
using namespace std;

const int DIM = 2e6 + 5;

int psm[DIM];

vector<pair<long long, long long>> seg;
vector<long long> crd;

long long gcd(long long a, long long b) {
	return !b ? a : gcd(b, a % b);
}

int main(void) {
#ifdef HOME
	freopen("device.in", "r", stdin);
	freopen("device.out", "w", stdout);
#endif
	int n; long long A, B;
	cin >> n >> A >> B;
	long long _A = A, _B = B;
	long long g = gcd(A, B + 1); A /= g;
	long long p;
	if ((1LL << 61) / A >= B)
		p = A * B;
	else
		p = 1LL << 61;
	#ifdef HOME
	for (int i = 0; i <= p * 10; ++i) {
		if (i % p == 0)
			cout << endl;
		cout << (i + i / _B) % _A << " " << i % B << " ";
	}
	#endif
	for (int i = 1; i <= n; ++i) {
		long long le, ri;
		cin >> le >> ri;
		if (ri - le + 1 >= p) {
			cout << p << endl;
			return 0; 
		} else 
		if (ri / p * p == le / p * p) 
			seg.push_back(make_pair(le % p, ri % p));
		else {
			seg.push_back(make_pair(le % p, p - 1));
			seg.push_back(make_pair(0, ri % p));
		}
	}
	for (pair<long long, long long> sg : seg) {
		crd.push_back(sg.first);
		crd.push_back(sg.second + 1);
	}
	sort(crd.begin(), crd.end());
	crd.resize(unique(crd.begin(), crd.end()) - crd.begin());
	for (pair<long long, long long> sg : seg) {
		int p1 = lower_bound(crd.begin(), crd.end(), sg.first) - crd.begin() + 1,
				p2 = lower_bound(crd.begin(), crd.end(), sg.second + 1) - crd.begin() + 1;
		++psm[p1]; --psm[p2];
	}
	long long ans = 0;
	for (int i = 1; i < crd.size(); ++i) {
		psm[i] += psm[i - 1];
		if (psm[i] > 0) 
			ans += crd[i] - crd[i - 1];
	}
	cout << ans << endl;	
	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:62:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 1; i < crd.size(); ++i) {
                  ~~^~~~~~~~~~~~
strange_device.cpp:22:12: warning: unused variable '_A' [-Wunused-variable]
  long long _A = A, _B = B;
            ^~
strange_device.cpp:22:20: warning: unused variable '_B' [-Wunused-variable]
  long long _A = A, _B = B;
                    ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 31 ms 1268 KB Output is correct
3 Correct 34 ms 1268 KB Output is correct
4 Correct 5 ms 348 KB Output is correct
5 Correct 2 ms 352 KB Output is correct
6 Correct 2 ms 368 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 244 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 5 ms 380 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 408 KB Output is correct
16 Correct 31 ms 1356 KB Output is correct
17 Correct 297 ms 8636 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 448 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 296 KB Output is correct
4 Correct 2 ms 372 KB Output is correct
5 Correct 2 ms 404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 1945 ms 45628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 368 KB Output is correct
2 Correct 2890 ms 48400 KB Output is correct
3 Correct 2929 ms 48512 KB Output is correct
4 Correct 2893 ms 48336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 368 KB Output is correct
2 Correct 2890 ms 48400 KB Output is correct
3 Correct 2929 ms 48512 KB Output is correct
4 Correct 2893 ms 48336 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2981 ms 48484 KB Output is correct
7 Correct 2902 ms 48476 KB Output is correct
8 Correct 2905 ms 48396 KB Output is correct
9 Correct 3004 ms 48480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 368 KB Output is correct
2 Correct 2890 ms 48400 KB Output is correct
3 Correct 2929 ms 48512 KB Output is correct
4 Correct 2893 ms 48336 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 289 ms 8524 KB Output is correct
7 Correct 299 ms 8852 KB Output is correct
8 Correct 288 ms 8676 KB Output is correct
9 Correct 296 ms 8664 KB Output is correct
10 Correct 270 ms 8676 KB Output is correct
11 Correct 292 ms 8780 KB Output is correct
12 Correct 293 ms 8692 KB Output is correct
13 Correct 302 ms 8672 KB Output is correct
14 Correct 287 ms 8732 KB Output is correct
15 Correct 289 ms 8688 KB Output is correct
16 Correct 302 ms 8828 KB Output is correct
17 Correct 294 ms 8628 KB Output is correct
18 Correct 2916 ms 48384 KB Output is correct
19 Correct 2878 ms 48256 KB Output is correct
20 Correct 2994 ms 48328 KB Output is correct
21 Correct 303 ms 8900 KB Output is correct
22 Correct 284 ms 8712 KB Output is correct
23 Correct 895 ms 30536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 299 ms 8688 KB Output is correct
3 Correct 298 ms 8760 KB Output is correct
4 Correct 3046 ms 48456 KB Output is correct
5 Correct 299 ms 8724 KB Output is correct
6 Correct 295 ms 8848 KB Output is correct
7 Correct 299 ms 8728 KB Output is correct
8 Correct 306 ms 8696 KB Output is correct
9 Correct 296 ms 8648 KB Output is correct
10 Correct 300 ms 8764 KB Output is correct
11 Correct 298 ms 8648 KB Output is correct
12 Correct 294 ms 8844 KB Output is correct
13 Correct 304 ms 8648 KB Output is correct
14 Correct 3004 ms 48496 KB Output is correct
15 Correct 293 ms 8672 KB Output is correct
16 Correct 2870 ms 48208 KB Output is correct
17 Correct 2905 ms 48164 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 31 ms 1268 KB Output is correct
3 Correct 34 ms 1268 KB Output is correct
4 Correct 5 ms 348 KB Output is correct
5 Correct 2 ms 352 KB Output is correct
6 Correct 2 ms 368 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 244 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 5 ms 380 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 408 KB Output is correct
16 Correct 31 ms 1356 KB Output is correct
17 Correct 297 ms 8636 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 ms 448 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 296 KB Output is correct
22 Correct 2 ms 372 KB Output is correct
23 Correct 2 ms 404 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 3 ms 432 KB Output is correct
27 Correct 5 ms 380 KB Output is correct
28 Correct 1945 ms 45628 KB Output is correct
29 Correct 2 ms 368 KB Output is correct
30 Correct 2890 ms 48400 KB Output is correct
31 Correct 2929 ms 48512 KB Output is correct
32 Correct 2893 ms 48336 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2981 ms 48484 KB Output is correct
35 Correct 2902 ms 48476 KB Output is correct
36 Correct 2905 ms 48396 KB Output is correct
37 Correct 3004 ms 48480 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 289 ms 8524 KB Output is correct
40 Correct 299 ms 8852 KB Output is correct
41 Correct 288 ms 8676 KB Output is correct
42 Correct 296 ms 8664 KB Output is correct
43 Correct 270 ms 8676 KB Output is correct
44 Correct 292 ms 8780 KB Output is correct
45 Correct 293 ms 8692 KB Output is correct
46 Correct 302 ms 8672 KB Output is correct
47 Correct 287 ms 8732 KB Output is correct
48 Correct 289 ms 8688 KB Output is correct
49 Correct 302 ms 8828 KB Output is correct
50 Correct 294 ms 8628 KB Output is correct
51 Correct 2916 ms 48384 KB Output is correct
52 Correct 2878 ms 48256 KB Output is correct
53 Correct 2994 ms 48328 KB Output is correct
54 Correct 303 ms 8900 KB Output is correct
55 Correct 284 ms 8712 KB Output is correct
56 Correct 895 ms 30536 KB Output is correct
57 Correct 2 ms 256 KB Output is correct
58 Correct 299 ms 8688 KB Output is correct
59 Correct 298 ms 8760 KB Output is correct
60 Correct 3046 ms 48456 KB Output is correct
61 Correct 299 ms 8724 KB Output is correct
62 Correct 295 ms 8848 KB Output is correct
63 Correct 299 ms 8728 KB Output is correct
64 Correct 306 ms 8696 KB Output is correct
65 Correct 296 ms 8648 KB Output is correct
66 Correct 300 ms 8764 KB Output is correct
67 Correct 298 ms 8648 KB Output is correct
68 Correct 294 ms 8844 KB Output is correct
69 Correct 304 ms 8648 KB Output is correct
70 Correct 3004 ms 48496 KB Output is correct
71 Correct 293 ms 8672 KB Output is correct
72 Correct 2870 ms 48208 KB Output is correct
73 Correct 2905 ms 48164 KB Output is correct
74 Correct 2 ms 256 KB Output is correct
75 Correct 2 ms 376 KB Output is correct
76 Correct 2 ms 256 KB Output is correct
77 Correct 0 ms 364 KB Output is correct
78 Correct 2 ms 376 KB Output is correct
79 Correct 30 ms 1268 KB Output is correct
80 Correct 3023 ms 48220 KB Output is correct
81 Correct 3018 ms 48276 KB Output is correct
82 Correct 2977 ms 45936 KB Output is correct
83 Correct 3030 ms 48400 KB Output is correct
84 Correct 3228 ms 47056 KB Output is correct
85 Correct 2998 ms 47144 KB Output is correct
86 Correct 905 ms 25792 KB Output is correct
87 Correct 4 ms 400 KB Output is correct