Submission #246143

# Submission time Handle Problem Language Result Execution time Memory
246143 2020-07-08T09:49:14 Z user202729 Strange Device (APIO19_strange_device) C++17
100 / 100
843 ms 28532 KB
//oj.uz/problem/view/APIO19_strange_device
//already.

#ifndef LOCAL
#define NDEBUG 1
#endif
#include<bits/stdc++.h>

int main(){
	std::ios::sync_with_stdio(0);std::cin.tie(0);
	int number; int64_t a, b;
	std::cin>>number>>a>>b;
	auto const c=a/std::gcd(a, b+1);
	int64_t const period=(double)b*(double)c>2e18 ? INT64_MAX: b*c;

	struct Event{
		bool open: 1;
		uint64_t position: 63;

		uint64_t key() const{
			uint64_t result=position<<1|open;
			assert(result==*(uint64_t*) this);
			return result;

			//return position;
		}
		bool operator<(Event it) const{
			return key()<it.key();
		}
	};
	std::vector<Event> events; events.reserve(number*4);

	auto const addSegment=[&](int64_t first, int64_t sec){
		assert(first<sec);
		events.push_back({true, (((uint64_t)1<<63)-1)&first});
		events.push_back({false, (((uint64_t)1<<63)-1)&sec});
	};
	for(int _=0; _<number; ++_){
		int64_t first, sec; std::cin>>first>>sec;
		++sec;
		if(sec-first>=period){
			std::cout<<period<<'\n';
			return 0;
		}
		first%=period; sec%=period;
		if(first<sec){
			addSegment(first, sec);
		}else{
			assert(first!=sec);
			addSegment(first, period);
			if(sec) addSegment(0, sec);
		}
	}

	std::sort(begin(events), end(events));
	int64_t result{};
	int degree{};
	for(auto [open, position]: events){
		if(open){
			if(degree==0) result-=position;
			++degree;
		}else{
			--degree;
			if(degree==0) result+=position;
			//assert(degree>=0);
			//actually this is not guaranteed because of how stuff are sorted...
		}
	}
	std::cout<<result<<'\n';


}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 11 ms 896 KB Output is correct
3 Correct 12 ms 896 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 11 ms 896 KB Output is correct
17 Correct 86 ms 5624 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 428 ms 17016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 682 ms 26164 KB Output is correct
3 Correct 726 ms 22648 KB Output is correct
4 Correct 691 ms 22624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 682 ms 26164 KB Output is correct
3 Correct 726 ms 22648 KB Output is correct
4 Correct 691 ms 22624 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 705 ms 22608 KB Output is correct
7 Correct 686 ms 22648 KB Output is correct
8 Correct 729 ms 22624 KB Output is correct
9 Correct 843 ms 22664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 682 ms 26164 KB Output is correct
3 Correct 726 ms 22648 KB Output is correct
4 Correct 691 ms 22624 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 70 ms 5624 KB Output is correct
7 Correct 73 ms 5624 KB Output is correct
8 Correct 69 ms 5624 KB Output is correct
9 Correct 76 ms 5624 KB Output is correct
10 Correct 71 ms 5628 KB Output is correct
11 Correct 75 ms 5624 KB Output is correct
12 Correct 69 ms 5756 KB Output is correct
13 Correct 80 ms 5624 KB Output is correct
14 Correct 73 ms 5624 KB Output is correct
15 Correct 90 ms 5624 KB Output is correct
16 Correct 82 ms 5624 KB Output is correct
17 Correct 83 ms 5624 KB Output is correct
18 Correct 732 ms 22696 KB Output is correct
19 Correct 673 ms 22776 KB Output is correct
20 Correct 828 ms 22764 KB Output is correct
21 Correct 82 ms 5624 KB Output is correct
22 Correct 61 ms 5624 KB Output is correct
23 Correct 219 ms 18276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 77 ms 5624 KB Output is correct
3 Correct 78 ms 5624 KB Output is correct
4 Correct 842 ms 18176 KB Output is correct
5 Correct 77 ms 5624 KB Output is correct
6 Correct 79 ms 5624 KB Output is correct
7 Correct 93 ms 5624 KB Output is correct
8 Correct 84 ms 5624 KB Output is correct
9 Correct 81 ms 5624 KB Output is correct
10 Correct 83 ms 5624 KB Output is correct
11 Correct 78 ms 5624 KB Output is correct
12 Correct 70 ms 5624 KB Output is correct
13 Correct 84 ms 5624 KB Output is correct
14 Correct 793 ms 18296 KB Output is correct
15 Correct 81 ms 5624 KB Output is correct
16 Correct 638 ms 22776 KB Output is correct
17 Correct 688 ms 22776 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 11 ms 896 KB Output is correct
3 Correct 12 ms 896 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 11 ms 896 KB Output is correct
17 Correct 86 ms 5624 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 6 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 428 ms 17016 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 682 ms 26164 KB Output is correct
31 Correct 726 ms 22648 KB Output is correct
32 Correct 691 ms 22624 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 705 ms 22608 KB Output is correct
35 Correct 686 ms 22648 KB Output is correct
36 Correct 729 ms 22624 KB Output is correct
37 Correct 843 ms 22664 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 70 ms 5624 KB Output is correct
40 Correct 73 ms 5624 KB Output is correct
41 Correct 69 ms 5624 KB Output is correct
42 Correct 76 ms 5624 KB Output is correct
43 Correct 71 ms 5628 KB Output is correct
44 Correct 75 ms 5624 KB Output is correct
45 Correct 69 ms 5756 KB Output is correct
46 Correct 80 ms 5624 KB Output is correct
47 Correct 73 ms 5624 KB Output is correct
48 Correct 90 ms 5624 KB Output is correct
49 Correct 82 ms 5624 KB Output is correct
50 Correct 83 ms 5624 KB Output is correct
51 Correct 732 ms 22696 KB Output is correct
52 Correct 673 ms 22776 KB Output is correct
53 Correct 828 ms 22764 KB Output is correct
54 Correct 82 ms 5624 KB Output is correct
55 Correct 61 ms 5624 KB Output is correct
56 Correct 219 ms 18276 KB Output is correct
57 Correct 5 ms 384 KB Output is correct
58 Correct 77 ms 5624 KB Output is correct
59 Correct 78 ms 5624 KB Output is correct
60 Correct 842 ms 18176 KB Output is correct
61 Correct 77 ms 5624 KB Output is correct
62 Correct 79 ms 5624 KB Output is correct
63 Correct 93 ms 5624 KB Output is correct
64 Correct 84 ms 5624 KB Output is correct
65 Correct 81 ms 5624 KB Output is correct
66 Correct 83 ms 5624 KB Output is correct
67 Correct 78 ms 5624 KB Output is correct
68 Correct 70 ms 5624 KB Output is correct
69 Correct 84 ms 5624 KB Output is correct
70 Correct 793 ms 18296 KB Output is correct
71 Correct 81 ms 5624 KB Output is correct
72 Correct 638 ms 22776 KB Output is correct
73 Correct 688 ms 22776 KB Output is correct
74 Correct 5 ms 384 KB Output is correct
75 Correct 4 ms 384 KB Output is correct
76 Correct 5 ms 384 KB Output is correct
77 Correct 5 ms 384 KB Output is correct
78 Correct 5 ms 384 KB Output is correct
79 Correct 10 ms 896 KB Output is correct
80 Correct 834 ms 25848 KB Output is correct
81 Correct 838 ms 26264 KB Output is correct
82 Correct 805 ms 26520 KB Output is correct
83 Correct 820 ms 28408 KB Output is correct
84 Correct 791 ms 28532 KB Output is correct
85 Correct 804 ms 25176 KB Output is correct
86 Correct 183 ms 18168 KB Output is correct
87 Correct 5 ms 384 KB Output is correct