Submission #172107

# Submission time Handle Problem Language Result Execution time Memory
172107 2019-12-31T06:52:08 Z super_j6 Strange Device (APIO19_strange_device) C++14
100 / 100
662 ms 24600 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define pi pair<long long, long long>
 
const long long inf = 2000000000000000000;
const int maxn = 2000001;
long long n, m, a, b;
pi p[maxn];
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> a >> b;
	m = min(inf / b, a / __gcd(a, b % a + 1)) * b;
	
	for(int i = 0; i < n; i++){
		cin >> p[i].first >> p[i].second;
		if(p[i].second - p[i].first >= m) p[i] = {0, m - 1};
		p[i].first %= m, p[i].second %= m;
		if(p[i].second < p[i].first){
			p[i + 1] = {p[i].first, m - 1};
			p[i].first = 0;
			i++, n++;
		}
	} 
	
	p[n] = {m, m};
	sort(p, p + n);
	
	long long ret = 0;
	for(long long i = 0, j = p[0].second, k = p[0].first; i < n; i++){
		j = max(j, p[i].second);
		if(j < p[i + 1].first){
			ret += j - k + 1;
			k = p[i + 1].first;
		}
	}
	
	cout << ret << endl;
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 636 KB Output is correct
3 Correct 8 ms 636 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 8 ms 504 KB Output is correct
17 Correct 66 ms 1912 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 431 ms 16172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 588 ms 17048 KB Output is correct
3 Correct 589 ms 17052 KB Output is correct
4 Correct 590 ms 17584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 588 ms 17048 KB Output is correct
3 Correct 589 ms 17052 KB Output is correct
4 Correct 590 ms 17584 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 591 ms 20728 KB Output is correct
7 Correct 597 ms 18540 KB Output is correct
8 Correct 589 ms 18692 KB Output is correct
9 Correct 643 ms 18744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 588 ms 17048 KB Output is correct
3 Correct 589 ms 17052 KB Output is correct
4 Correct 590 ms 17584 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 66 ms 4840 KB Output is correct
7 Correct 63 ms 4344 KB Output is correct
8 Correct 60 ms 4856 KB Output is correct
9 Correct 62 ms 3160 KB Output is correct
10 Correct 59 ms 5624 KB Output is correct
11 Correct 61 ms 3956 KB Output is correct
12 Correct 59 ms 5624 KB Output is correct
13 Correct 65 ms 5624 KB Output is correct
14 Correct 59 ms 5624 KB Output is correct
15 Correct 66 ms 5624 KB Output is correct
16 Correct 65 ms 5580 KB Output is correct
17 Correct 62 ms 5652 KB Output is correct
18 Correct 595 ms 24600 KB Output is correct
19 Correct 587 ms 24440 KB Output is correct
20 Correct 644 ms 23800 KB Output is correct
21 Correct 64 ms 5624 KB Output is correct
22 Correct 58 ms 5624 KB Output is correct
23 Correct 211 ms 9708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 63 ms 3320 KB Output is correct
3 Correct 64 ms 2040 KB Output is correct
4 Correct 653 ms 19352 KB Output is correct
5 Correct 63 ms 1912 KB Output is correct
6 Correct 64 ms 3192 KB Output is correct
7 Correct 64 ms 3492 KB Output is correct
8 Correct 65 ms 1912 KB Output is correct
9 Correct 63 ms 2936 KB Output is correct
10 Correct 63 ms 1912 KB Output is correct
11 Correct 63 ms 2680 KB Output is correct
12 Correct 58 ms 4088 KB Output is correct
13 Correct 64 ms 4088 KB Output is correct
14 Correct 644 ms 23128 KB Output is correct
15 Correct 63 ms 4088 KB Output is correct
16 Correct 583 ms 18040 KB Output is correct
17 Correct 579 ms 17884 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 636 KB Output is correct
3 Correct 8 ms 636 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 8 ms 504 KB Output is correct
17 Correct 66 ms 1912 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 380 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 431 ms 16172 KB Output is correct
29 Correct 2 ms 380 KB Output is correct
30 Correct 588 ms 17048 KB Output is correct
31 Correct 589 ms 17052 KB Output is correct
32 Correct 590 ms 17584 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 591 ms 20728 KB Output is correct
35 Correct 597 ms 18540 KB Output is correct
36 Correct 589 ms 18692 KB Output is correct
37 Correct 643 ms 18744 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 66 ms 4840 KB Output is correct
40 Correct 63 ms 4344 KB Output is correct
41 Correct 60 ms 4856 KB Output is correct
42 Correct 62 ms 3160 KB Output is correct
43 Correct 59 ms 5624 KB Output is correct
44 Correct 61 ms 3956 KB Output is correct
45 Correct 59 ms 5624 KB Output is correct
46 Correct 65 ms 5624 KB Output is correct
47 Correct 59 ms 5624 KB Output is correct
48 Correct 66 ms 5624 KB Output is correct
49 Correct 65 ms 5580 KB Output is correct
50 Correct 62 ms 5652 KB Output is correct
51 Correct 595 ms 24600 KB Output is correct
52 Correct 587 ms 24440 KB Output is correct
53 Correct 644 ms 23800 KB Output is correct
54 Correct 64 ms 5624 KB Output is correct
55 Correct 58 ms 5624 KB Output is correct
56 Correct 211 ms 9708 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 63 ms 3320 KB Output is correct
59 Correct 64 ms 2040 KB Output is correct
60 Correct 653 ms 19352 KB Output is correct
61 Correct 63 ms 1912 KB Output is correct
62 Correct 64 ms 3192 KB Output is correct
63 Correct 64 ms 3492 KB Output is correct
64 Correct 65 ms 1912 KB Output is correct
65 Correct 63 ms 2936 KB Output is correct
66 Correct 63 ms 1912 KB Output is correct
67 Correct 63 ms 2680 KB Output is correct
68 Correct 58 ms 4088 KB Output is correct
69 Correct 64 ms 4088 KB Output is correct
70 Correct 644 ms 23128 KB Output is correct
71 Correct 63 ms 4088 KB Output is correct
72 Correct 583 ms 18040 KB Output is correct
73 Correct 579 ms 17884 KB Output is correct
74 Correct 2 ms 376 KB Output is correct
75 Correct 2 ms 376 KB Output is correct
76 Correct 2 ms 376 KB Output is correct
77 Correct 2 ms 376 KB Output is correct
78 Correct 2 ms 376 KB Output is correct
79 Correct 8 ms 888 KB Output is correct
80 Correct 650 ms 20344 KB Output is correct
81 Correct 657 ms 20120 KB Output is correct
82 Correct 650 ms 19664 KB Output is correct
83 Correct 642 ms 19828 KB Output is correct
84 Correct 662 ms 19064 KB Output is correct
85 Correct 642 ms 19084 KB Output is correct
86 Correct 200 ms 8420 KB Output is correct
87 Correct 2 ms 376 KB Output is correct