Submission #139514

# Submission time Handle Problem Language Result Execution time Memory
139514 2019-07-31T23:24:39 Z eriksuenderhauf Strange Device (APIO19_strange_device) C++11
100 / 100
687 ms 18512 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;

int main() {
	int n; ll a, b; scanf("%d %lld %lld", &n, &a, &b);
	ll k = a / __gcd(a,b+1), mx = 1, ans = 0;
	if (k > (INF+b-1) / b) mx = INF+1;
	else mx = k*b;
	vll act;
	for (int i = 0; i < n; i++) {
		ll l, r; scanf("%lld %lld", &l, &r);
		bool fl = (r-l+1 >= mx);
		if (fl) {
			act.pb(mp(0,mx-1));
			break;
		}
		l %= mx, r %= mx;
		if (l > r) {
			act.pb(mp(l,mx-1));
			act.pb(mp(0,r));
		} else {
			act.pb(mp(l,r));
		}
	}
	n = act.size();
	sort(act.begin(), act.end());
	for (int i = 0; i < n; i++) {
		int j = i;
		ll curmx = act[i].se;
		for (; j < n; j++) {
			if (curmx < act[j].fi)
				break;
			curmx = max(curmx, act[j].se);
		}
		ans += curmx - act[i].fi + 1;
		i = j-1;
	}
	prl(ans);
	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:39:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int n; ll a, b; scanf("%d %lld %lld", &n, &a, &b);
                  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:45:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   ll l, r; scanf("%lld %lld", &l, &r);
            ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 8 ms 1016 KB Output is correct
3 Correct 8 ms 1024 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 252 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 8 ms 1144 KB Output is correct
17 Correct 60 ms 3532 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
3 Correct 3 ms 408 KB Output is correct
4 Correct 3 ms 380 KB Output is correct
5 Correct 447 ms 18000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 533 ms 17624 KB Output is correct
3 Correct 535 ms 18272 KB Output is correct
4 Correct 535 ms 18384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 533 ms 17624 KB Output is correct
3 Correct 535 ms 18272 KB Output is correct
4 Correct 535 ms 18384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 534 ms 18360 KB Output is correct
7 Correct 530 ms 18228 KB Output is correct
8 Correct 539 ms 18356 KB Output is correct
9 Correct 603 ms 18512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 533 ms 17624 KB Output is correct
3 Correct 535 ms 18272 KB Output is correct
4 Correct 535 ms 18384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 54 ms 4844 KB Output is correct
7 Correct 57 ms 4840 KB Output is correct
8 Correct 49 ms 4812 KB Output is correct
9 Correct 58 ms 4820 KB Output is correct
10 Correct 54 ms 4812 KB Output is correct
11 Correct 57 ms 4856 KB Output is correct
12 Correct 55 ms 4712 KB Output is correct
13 Correct 67 ms 4588 KB Output is correct
14 Correct 55 ms 4588 KB Output is correct
15 Correct 64 ms 4608 KB Output is correct
16 Correct 59 ms 4584 KB Output is correct
17 Correct 60 ms 4568 KB Output is correct
18 Correct 531 ms 18256 KB Output is correct
19 Correct 520 ms 18316 KB Output is correct
20 Correct 610 ms 18160 KB Output is correct
21 Correct 60 ms 4044 KB Output is correct
22 Correct 54 ms 4032 KB Output is correct
23 Correct 208 ms 11464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 60 ms 4344 KB Output is correct
3 Correct 60 ms 4352 KB Output is correct
4 Correct 611 ms 18288 KB Output is correct
5 Correct 60 ms 4264 KB Output is correct
6 Correct 60 ms 4244 KB Output is correct
7 Correct 61 ms 4372 KB Output is correct
8 Correct 61 ms 4048 KB Output is correct
9 Correct 58 ms 4012 KB Output is correct
10 Correct 58 ms 3996 KB Output is correct
11 Correct 60 ms 4072 KB Output is correct
12 Correct 53 ms 3968 KB Output is correct
13 Correct 59 ms 4076 KB Output is correct
14 Correct 580 ms 18344 KB Output is correct
15 Correct 59 ms 4056 KB Output is correct
16 Correct 528 ms 18256 KB Output is correct
17 Correct 525 ms 18268 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 8 ms 1016 KB Output is correct
3 Correct 8 ms 1024 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 252 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 8 ms 1144 KB Output is correct
17 Correct 60 ms 3532 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 256 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 348 KB Output is correct
26 Correct 3 ms 408 KB Output is correct
27 Correct 3 ms 380 KB Output is correct
28 Correct 447 ms 18000 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 533 ms 17624 KB Output is correct
31 Correct 535 ms 18272 KB Output is correct
32 Correct 535 ms 18384 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 534 ms 18360 KB Output is correct
35 Correct 530 ms 18228 KB Output is correct
36 Correct 539 ms 18356 KB Output is correct
37 Correct 603 ms 18512 KB Output is correct
38 Correct 2 ms 256 KB Output is correct
39 Correct 54 ms 4844 KB Output is correct
40 Correct 57 ms 4840 KB Output is correct
41 Correct 49 ms 4812 KB Output is correct
42 Correct 58 ms 4820 KB Output is correct
43 Correct 54 ms 4812 KB Output is correct
44 Correct 57 ms 4856 KB Output is correct
45 Correct 55 ms 4712 KB Output is correct
46 Correct 67 ms 4588 KB Output is correct
47 Correct 55 ms 4588 KB Output is correct
48 Correct 64 ms 4608 KB Output is correct
49 Correct 59 ms 4584 KB Output is correct
50 Correct 60 ms 4568 KB Output is correct
51 Correct 531 ms 18256 KB Output is correct
52 Correct 520 ms 18316 KB Output is correct
53 Correct 610 ms 18160 KB Output is correct
54 Correct 60 ms 4044 KB Output is correct
55 Correct 54 ms 4032 KB Output is correct
56 Correct 208 ms 11464 KB Output is correct
57 Correct 2 ms 256 KB Output is correct
58 Correct 60 ms 4344 KB Output is correct
59 Correct 60 ms 4352 KB Output is correct
60 Correct 611 ms 18288 KB Output is correct
61 Correct 60 ms 4264 KB Output is correct
62 Correct 60 ms 4244 KB Output is correct
63 Correct 61 ms 4372 KB Output is correct
64 Correct 61 ms 4048 KB Output is correct
65 Correct 58 ms 4012 KB Output is correct
66 Correct 58 ms 3996 KB Output is correct
67 Correct 60 ms 4072 KB Output is correct
68 Correct 53 ms 3968 KB Output is correct
69 Correct 59 ms 4076 KB Output is correct
70 Correct 580 ms 18344 KB Output is correct
71 Correct 59 ms 4056 KB Output is correct
72 Correct 528 ms 18256 KB Output is correct
73 Correct 525 ms 18268 KB Output is correct
74 Correct 2 ms 376 KB Output is correct
75 Correct 5 ms 376 KB Output is correct
76 Correct 2 ms 256 KB Output is correct
77 Correct 2 ms 376 KB Output is correct
78 Correct 2 ms 348 KB Output is correct
79 Correct 7 ms 1140 KB Output is correct
80 Correct 687 ms 17708 KB Output is correct
81 Correct 607 ms 17484 KB Output is correct
82 Correct 582 ms 17348 KB Output is correct
83 Correct 609 ms 17408 KB Output is correct
84 Correct 586 ms 17532 KB Output is correct
85 Correct 605 ms 17360 KB Output is correct
86 Correct 209 ms 9168 KB Output is correct
87 Correct 2 ms 376 KB Output is correct