Submission #382993

# Submission time Handle Problem Language Result Execution time Memory
382993 2021-03-28T16:45:33 Z Kalashnikov Strange Device (APIO19_strange_device) C++17
100 / 100
746 ms 35876 KB
#include <bits/stdc++.h>
 
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
 
using namespace std;
using ll = long long;
 
const int N = 2e5+5 , inf = 2e9 + 7;
const ll INF = 1e18 ,   mod = 1e9+7 , P = 6547;

void solve() {
	ll n, A , B , l , r , ans = 0 , cur = 0;
	cin >> n >> A >> B;
	ll L = A / __gcd(A , B+1);
	if(L > 1e18/B) {
		for(int i = 1; i <= n; i ++) {cin >> l >> r; ans += r-l+1;}
		cout << ans;
		return;
	}
	L *= B;
	vector<pair<ll,ll>> v;
	for(int i = 1; i <= n; i ++) {
		cin >> l >> r;
		if(r-l+1 > L) {
			cout << L;
			return;
		}

		l %= L;
		r %= L;
		if(l > r) {
			v.push_back({0 , 1});
			v.push_back({r+1 , -1});
			v.push_back({l , 1});
			v.push_back({L , -1});
		}
		else {
			v.push_back({l , 1});
			v.push_back({r+1 , -1});
		}
	}
	sort(all(v));
	for(int i = 0; i < v.size(); i ++) {
		while(i+1 < v.size() && v[i].F == v[i+1].F) {
			cur += v[i].S;
			i ++;
		}
		cur += v[i].S;
		if(cur) ans += v[i+1].F - v[i].F;
	}
	cout << ans;
}
/*
*/
main() {
    ios;
    int tt = 1;
    //cin >> tt;
    while(tt --) {
        solve();
    }
    return 0;
}

Compilation message

strange_device.cpp: In function 'void solve()':
strange_device.cpp:47:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |  for(int i = 0; i < v.size(); i ++) {
      |                 ~~^~~~~~~~~~
strange_device.cpp:48:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |   while(i+1 < v.size() && v[i].F == v[i+1].F) {
      |         ~~~~^~~~~~~~~~
strange_device.cpp: At global scope:
strange_device.cpp:59:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   59 | main() {
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 6 ms 1008 KB Output is correct
3 Correct 7 ms 1008 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 7 ms 1008 KB Output is correct
17 Correct 66 ms 4580 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 418 ms 33340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 583 ms 33360 KB Output is correct
3 Correct 605 ms 33468 KB Output is correct
4 Correct 574 ms 33340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 583 ms 33360 KB Output is correct
3 Correct 605 ms 33468 KB Output is correct
4 Correct 574 ms 33340 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 614 ms 33280 KB Output is correct
7 Correct 577 ms 33340 KB Output is correct
8 Correct 582 ms 33340 KB Output is correct
9 Correct 696 ms 33340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 583 ms 33360 KB Output is correct
3 Correct 605 ms 33468 KB Output is correct
4 Correct 574 ms 33340 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 62 ms 4724 KB Output is correct
7 Correct 70 ms 4580 KB Output is correct
8 Correct 57 ms 4580 KB Output is correct
9 Correct 58 ms 4580 KB Output is correct
10 Correct 69 ms 4580 KB Output is correct
11 Correct 59 ms 4580 KB Output is correct
12 Correct 61 ms 4580 KB Output is correct
13 Correct 62 ms 4580 KB Output is correct
14 Correct 55 ms 4580 KB Output is correct
15 Correct 65 ms 4580 KB Output is correct
16 Correct 64 ms 4732 KB Output is correct
17 Correct 56 ms 4580 KB Output is correct
18 Correct 606 ms 33340 KB Output is correct
19 Correct 565 ms 33340 KB Output is correct
20 Correct 703 ms 33340 KB Output is correct
21 Correct 66 ms 4580 KB Output is correct
22 Correct 50 ms 4580 KB Output is correct
23 Correct 164 ms 16848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 65 ms 4580 KB Output is correct
3 Correct 62 ms 4580 KB Output is correct
4 Correct 746 ms 33340 KB Output is correct
5 Correct 62 ms 4580 KB Output is correct
6 Correct 64 ms 4580 KB Output is correct
7 Correct 63 ms 4580 KB Output is correct
8 Correct 65 ms 4580 KB Output is correct
9 Correct 61 ms 4580 KB Output is correct
10 Correct 65 ms 4580 KB Output is correct
11 Correct 64 ms 4708 KB Output is correct
12 Correct 56 ms 4580 KB Output is correct
13 Correct 65 ms 4580 KB Output is correct
14 Correct 690 ms 33340 KB Output is correct
15 Correct 66 ms 4580 KB Output is correct
16 Correct 564 ms 33596 KB Output is correct
17 Correct 597 ms 33596 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 6 ms 1008 KB Output is correct
3 Correct 7 ms 1008 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 7 ms 1008 KB Output is correct
17 Correct 66 ms 4580 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 418 ms 33340 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 583 ms 33360 KB Output is correct
31 Correct 605 ms 33468 KB Output is correct
32 Correct 574 ms 33340 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 614 ms 33280 KB Output is correct
35 Correct 577 ms 33340 KB Output is correct
36 Correct 582 ms 33340 KB Output is correct
37 Correct 696 ms 33340 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 62 ms 4724 KB Output is correct
40 Correct 70 ms 4580 KB Output is correct
41 Correct 57 ms 4580 KB Output is correct
42 Correct 58 ms 4580 KB Output is correct
43 Correct 69 ms 4580 KB Output is correct
44 Correct 59 ms 4580 KB Output is correct
45 Correct 61 ms 4580 KB Output is correct
46 Correct 62 ms 4580 KB Output is correct
47 Correct 55 ms 4580 KB Output is correct
48 Correct 65 ms 4580 KB Output is correct
49 Correct 64 ms 4732 KB Output is correct
50 Correct 56 ms 4580 KB Output is correct
51 Correct 606 ms 33340 KB Output is correct
52 Correct 565 ms 33340 KB Output is correct
53 Correct 703 ms 33340 KB Output is correct
54 Correct 66 ms 4580 KB Output is correct
55 Correct 50 ms 4580 KB Output is correct
56 Correct 164 ms 16848 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 65 ms 4580 KB Output is correct
59 Correct 62 ms 4580 KB Output is correct
60 Correct 746 ms 33340 KB Output is correct
61 Correct 62 ms 4580 KB Output is correct
62 Correct 64 ms 4580 KB Output is correct
63 Correct 63 ms 4580 KB Output is correct
64 Correct 65 ms 4580 KB Output is correct
65 Correct 61 ms 4580 KB Output is correct
66 Correct 65 ms 4580 KB Output is correct
67 Correct 64 ms 4708 KB Output is correct
68 Correct 56 ms 4580 KB Output is correct
69 Correct 65 ms 4580 KB Output is correct
70 Correct 690 ms 33340 KB Output is correct
71 Correct 66 ms 4580 KB Output is correct
72 Correct 564 ms 33596 KB Output is correct
73 Correct 597 ms 33596 KB Output is correct
74 Correct 1 ms 364 KB Output is correct
75 Correct 1 ms 364 KB Output is correct
76 Correct 1 ms 364 KB Output is correct
77 Correct 1 ms 364 KB Output is correct
78 Correct 1 ms 364 KB Output is correct
79 Correct 7 ms 1392 KB Output is correct
80 Correct 726 ms 35816 KB Output is correct
81 Correct 743 ms 35876 KB Output is correct
82 Correct 685 ms 34620 KB Output is correct
83 Correct 681 ms 34876 KB Output is correct
84 Correct 688 ms 33596 KB Output is correct
85 Correct 679 ms 34072 KB Output is correct
86 Correct 165 ms 19936 KB Output is correct
87 Correct 1 ms 364 KB Output is correct