Submission #870859

# Submission time Handle Problem Language Result Execution time Memory
870859 2023-11-09T10:15:41 Z marvinthang Strange Device (APIO19_strange_device) C++17
100 / 100
360 ms 54000 KB
/*************************************
*    author: marvinthang             *
*    created: 09.11.2023 17:08:45    *
*************************************/

#include <bits/stdc++.h>

using namespace std;

#define                  fi  first
#define                  se  second
#define                left  ___left
#define               right  ___right
#define                TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define             MASK(i)  (1LL << (i))
#define           BIT(x, i)  ((x) >> (i) & 1)
#define  __builtin_popcount  __builtin_popcountll
#define              ALL(v)  (v).begin(), (v).end()
#define           REP(i, n)  for (int i = 0, _n = (n); i < _n; ++i)
#define          REPD(i, n)  for (int i = (n); i-- > 0; )
#define        FOR(i, a, b)  for (int i = (a), _b = (b); i < _b; ++i) 
#define       FORD(i, b, a)  for (int i = (b), _a = (a); --i >= _a; ) 
#define       FORE(i, a, b)  for (int i = (a), _b = (b); i <= _b; ++i) 
#define      FORDE(i, b, a)  for (int i = (b), _a = (a); i >= _a; --i) 
#define        scan_op(...)  istream & operator >> (istream &in, __VA_ARGS__ &u)
#define       print_op(...)  ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#ifdef LOCAL
    #include "debug.h"
#else
    #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
    #define DB(...) 23
    #define db(...) 23
    #define debug(...) 23
#endif

template <class U, class V> scan_op(pair <U, V>)  { return in >> u.first >> u.second; }
template <class T> scan_op(vector <T>)  { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class U, class V> print_op(pair <U, V>)  { return out << '(' << u.first << ", " << u.second << ')'; }
template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")";  else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); }
template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); }
template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; }

// end of template

const long long INF = (long long) 1e18 + 1;

void process(void) {
	int n; long long a, b; cin >> n >> a >> b;
	long long cycle = INF / a < b ? INF : a / gcd(a, b + 1) * b;
	vector <pair <long long, long long>> segments;
	while (n--) {
		long long l, r; cin >> l >> r;
		if (l / cycle < r / cycle) {
			segments.emplace_back(l % cycle, cycle - 1);
			segments.emplace_back(0, r % cycle);
		} else segments.emplace_back(l % cycle, r % cycle);
	}
	long long last = 0, res = 0;
	sort(ALL(segments));
	for (auto [l, r]: segments) {
		res += max(0LL, r - max(l, last) + 1);
		last = max(last, r + 1);
	}
	cout << res << '\n';
}

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); // cout.tie(nullptr);
	file("strange_device");
	// int t; cin >> t; while (t--)
	process();
	// cerr << "Time elapsed: " << TIME << " s.\n";
	return (0^0);
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:30:61: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:69:2: note: in expansion of macro 'file'
   69 |  file("strange_device");
      |  ^~~~
strange_device.cpp:30:94: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:69:2: note: in expansion of macro 'file'
   69 |  file("strange_device");
      |  ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 3 ms 1116 KB Output is correct
3 Correct 4 ms 1116 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 1112 KB Output is correct
17 Correct 34 ms 5836 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 209 ms 41340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 305 ms 53376 KB Output is correct
3 Correct 295 ms 53680 KB Output is correct
4 Correct 292 ms 53424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 305 ms 53376 KB Output is correct
3 Correct 295 ms 53680 KB Output is correct
4 Correct 292 ms 53424 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 302 ms 53364 KB Output is correct
7 Correct 314 ms 53148 KB Output is correct
8 Correct 314 ms 53564 KB Output is correct
9 Correct 333 ms 53344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 305 ms 53376 KB Output is correct
3 Correct 295 ms 53680 KB Output is correct
4 Correct 292 ms 53424 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 32 ms 5844 KB Output is correct
7 Correct 31 ms 5832 KB Output is correct
8 Correct 29 ms 5836 KB Output is correct
9 Correct 34 ms 5836 KB Output is correct
10 Correct 29 ms 5832 KB Output is correct
11 Correct 30 ms 5844 KB Output is correct
12 Correct 29 ms 5792 KB Output is correct
13 Correct 32 ms 5844 KB Output is correct
14 Correct 31 ms 6060 KB Output is correct
15 Correct 34 ms 5828 KB Output is correct
16 Correct 32 ms 5828 KB Output is correct
17 Correct 30 ms 5700 KB Output is correct
18 Correct 305 ms 53424 KB Output is correct
19 Correct 287 ms 53940 KB Output is correct
20 Correct 325 ms 53620 KB Output is correct
21 Correct 42 ms 5776 KB Output is correct
22 Correct 28 ms 5832 KB Output is correct
23 Correct 86 ms 19204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 32 ms 6084 KB Output is correct
3 Correct 32 ms 6088 KB Output is correct
4 Correct 344 ms 53284 KB Output is correct
5 Correct 33 ms 5836 KB Output is correct
6 Correct 40 ms 5956 KB Output is correct
7 Correct 35 ms 5832 KB Output is correct
8 Correct 34 ms 5836 KB Output is correct
9 Correct 33 ms 5836 KB Output is correct
10 Correct 35 ms 5808 KB Output is correct
11 Correct 34 ms 5840 KB Output is correct
12 Correct 30 ms 5828 KB Output is correct
13 Correct 32 ms 5832 KB Output is correct
14 Correct 343 ms 53604 KB Output is correct
15 Correct 39 ms 5832 KB Output is correct
16 Correct 295 ms 53680 KB Output is correct
17 Correct 296 ms 53428 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 3 ms 1116 KB Output is correct
3 Correct 4 ms 1116 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 1112 KB Output is correct
17 Correct 34 ms 5836 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 452 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 209 ms 41340 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 305 ms 53376 KB Output is correct
31 Correct 295 ms 53680 KB Output is correct
32 Correct 292 ms 53424 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 302 ms 53364 KB Output is correct
35 Correct 314 ms 53148 KB Output is correct
36 Correct 314 ms 53564 KB Output is correct
37 Correct 333 ms 53344 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 32 ms 5844 KB Output is correct
40 Correct 31 ms 5832 KB Output is correct
41 Correct 29 ms 5836 KB Output is correct
42 Correct 34 ms 5836 KB Output is correct
43 Correct 29 ms 5832 KB Output is correct
44 Correct 30 ms 5844 KB Output is correct
45 Correct 29 ms 5792 KB Output is correct
46 Correct 32 ms 5844 KB Output is correct
47 Correct 31 ms 6060 KB Output is correct
48 Correct 34 ms 5828 KB Output is correct
49 Correct 32 ms 5828 KB Output is correct
50 Correct 30 ms 5700 KB Output is correct
51 Correct 305 ms 53424 KB Output is correct
52 Correct 287 ms 53940 KB Output is correct
53 Correct 325 ms 53620 KB Output is correct
54 Correct 42 ms 5776 KB Output is correct
55 Correct 28 ms 5832 KB Output is correct
56 Correct 86 ms 19204 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 32 ms 6084 KB Output is correct
59 Correct 32 ms 6088 KB Output is correct
60 Correct 344 ms 53284 KB Output is correct
61 Correct 33 ms 5836 KB Output is correct
62 Correct 40 ms 5956 KB Output is correct
63 Correct 35 ms 5832 KB Output is correct
64 Correct 34 ms 5836 KB Output is correct
65 Correct 33 ms 5836 KB Output is correct
66 Correct 35 ms 5808 KB Output is correct
67 Correct 34 ms 5840 KB Output is correct
68 Correct 30 ms 5828 KB Output is correct
69 Correct 32 ms 5832 KB Output is correct
70 Correct 343 ms 53604 KB Output is correct
71 Correct 39 ms 5832 KB Output is correct
72 Correct 295 ms 53680 KB Output is correct
73 Correct 296 ms 53428 KB Output is correct
74 Correct 0 ms 344 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 1 ms 344 KB Output is correct
79 Correct 3 ms 1112 KB Output is correct
80 Correct 351 ms 53396 KB Output is correct
81 Correct 360 ms 53176 KB Output is correct
82 Correct 337 ms 54000 KB Output is correct
83 Correct 322 ms 53400 KB Output is correct
84 Correct 332 ms 53408 KB Output is correct
85 Correct 322 ms 53604 KB Output is correct
86 Correct 88 ms 19388 KB Output is correct
87 Correct 0 ms 344 KB Output is correct