Submission #250334

# Submission time Handle Problem Language Result Execution time Memory
250334 2020-07-17T12:36:24 Z _7_7_ Strange Device (APIO19_strange_device) C++14
100 / 100
797 ms 45168 KB
#include <bits/stdc++.h>                                           
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 

using namespace std;
using namespace __gnu_pbds;
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 

 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 2e5 + 11;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


int n, a, b, l, r;
vpii v;


main () {
	fastio
	scanf("%lld%lld%lld", &n, &a, &b);

	int g = __gcd(a, b + 1);
	a /= g;
	if (a <= 2*INF / b)
		a *= b;
	else
		a = 2*INF;

	while (n--) {
		scanf("%lld%lld", &l, &r);
		if (r - l + 1 >= a) {
			cout << a << endl;
			return 0;
		}

		l %= a;
		r %= a;
		if (l > r) {
			v.pb({0ll, 1ll});
			v.pb({r + 1, -1ll});
			v.pb({l, 1ll});
			v.pb({a, -1ll});
		} else {
			v.pb({l, 1ll});
			v.pb({r + 1, -1ll});
		}
	}
	
	sort(all(v));


	int ans = 0, cur = 0;
	for (int i = 0; i < sz(v); ++i) {
		if (cur > 0) 
			ans += v[i].f - v[i - 1].f;			
		cur += v[i].s;
	}

	cout << ans << endl;
}

Compilation message

strange_device.cpp:50:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
strange_device.cpp: In function 'int main()':
strange_device.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld%lld", &n, &a, &b);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:62:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &l, &r);
   ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 7 ms 1408 KB Output is correct
3 Correct 7 ms 1408 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 7 ms 1408 KB Output is correct
17 Correct 70 ms 7396 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 476 ms 38720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 634 ms 40784 KB Output is correct
3 Correct 658 ms 43508 KB Output is correct
4 Correct 649 ms 44992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 634 ms 40784 KB Output is correct
3 Correct 658 ms 43508 KB Output is correct
4 Correct 649 ms 44992 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 647 ms 45120 KB Output is correct
7 Correct 648 ms 45168 KB Output is correct
8 Correct 640 ms 44992 KB Output is correct
9 Correct 719 ms 44992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 634 ms 40784 KB Output is correct
3 Correct 658 ms 43508 KB Output is correct
4 Correct 649 ms 44992 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 63 ms 7276 KB Output is correct
7 Correct 69 ms 7272 KB Output is correct
8 Correct 59 ms 7292 KB Output is correct
9 Correct 62 ms 7280 KB Output is correct
10 Correct 60 ms 7276 KB Output is correct
11 Correct 64 ms 7276 KB Output is correct
12 Correct 59 ms 7276 KB Output is correct
13 Correct 67 ms 7276 KB Output is correct
14 Correct 62 ms 7280 KB Output is correct
15 Correct 71 ms 7268 KB Output is correct
16 Correct 70 ms 7268 KB Output is correct
17 Correct 61 ms 7276 KB Output is correct
18 Correct 669 ms 42176 KB Output is correct
19 Correct 625 ms 42048 KB Output is correct
20 Correct 797 ms 42208 KB Output is correct
21 Correct 73 ms 7276 KB Output is correct
22 Correct 56 ms 7276 KB Output is correct
23 Correct 221 ms 22740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 72 ms 7272 KB Output is correct
3 Correct 73 ms 7396 KB Output is correct
4 Correct 790 ms 43880 KB Output is correct
5 Correct 67 ms 7276 KB Output is correct
6 Correct 68 ms 7276 KB Output is correct
7 Correct 67 ms 7276 KB Output is correct
8 Correct 71 ms 7276 KB Output is correct
9 Correct 69 ms 7276 KB Output is correct
10 Correct 77 ms 7276 KB Output is correct
11 Correct 69 ms 7340 KB Output is correct
12 Correct 59 ms 7276 KB Output is correct
13 Correct 69 ms 7284 KB Output is correct
14 Correct 730 ms 43928 KB Output is correct
15 Correct 72 ms 7272 KB Output is correct
16 Correct 624 ms 42576 KB Output is correct
17 Correct 706 ms 42556 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 7 ms 1408 KB Output is correct
3 Correct 7 ms 1408 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 7 ms 1408 KB Output is correct
17 Correct 70 ms 7396 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 476 ms 38720 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 634 ms 40784 KB Output is correct
31 Correct 658 ms 43508 KB Output is correct
32 Correct 649 ms 44992 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 647 ms 45120 KB Output is correct
35 Correct 648 ms 45168 KB Output is correct
36 Correct 640 ms 44992 KB Output is correct
37 Correct 719 ms 44992 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 63 ms 7276 KB Output is correct
40 Correct 69 ms 7272 KB Output is correct
41 Correct 59 ms 7292 KB Output is correct
42 Correct 62 ms 7280 KB Output is correct
43 Correct 60 ms 7276 KB Output is correct
44 Correct 64 ms 7276 KB Output is correct
45 Correct 59 ms 7276 KB Output is correct
46 Correct 67 ms 7276 KB Output is correct
47 Correct 62 ms 7280 KB Output is correct
48 Correct 71 ms 7268 KB Output is correct
49 Correct 70 ms 7268 KB Output is correct
50 Correct 61 ms 7276 KB Output is correct
51 Correct 669 ms 42176 KB Output is correct
52 Correct 625 ms 42048 KB Output is correct
53 Correct 797 ms 42208 KB Output is correct
54 Correct 73 ms 7276 KB Output is correct
55 Correct 56 ms 7276 KB Output is correct
56 Correct 221 ms 22740 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 72 ms 7272 KB Output is correct
59 Correct 73 ms 7396 KB Output is correct
60 Correct 790 ms 43880 KB Output is correct
61 Correct 67 ms 7276 KB Output is correct
62 Correct 68 ms 7276 KB Output is correct
63 Correct 67 ms 7276 KB Output is correct
64 Correct 71 ms 7276 KB Output is correct
65 Correct 69 ms 7276 KB Output is correct
66 Correct 77 ms 7276 KB Output is correct
67 Correct 69 ms 7340 KB Output is correct
68 Correct 59 ms 7276 KB Output is correct
69 Correct 69 ms 7284 KB Output is correct
70 Correct 730 ms 43928 KB Output is correct
71 Correct 72 ms 7272 KB Output is correct
72 Correct 624 ms 42576 KB Output is correct
73 Correct 706 ms 42556 KB Output is correct
74 Correct 1 ms 384 KB Output is correct
75 Correct 0 ms 384 KB Output is correct
76 Correct 0 ms 384 KB Output is correct
77 Correct 1 ms 384 KB Output is correct
78 Correct 0 ms 384 KB Output is correct
79 Correct 7 ms 1408 KB Output is correct
80 Correct 751 ms 41632 KB Output is correct
81 Correct 761 ms 41664 KB Output is correct
82 Correct 769 ms 41792 KB Output is correct
83 Correct 740 ms 41796 KB Output is correct
84 Correct 694 ms 41792 KB Output is correct
85 Correct 704 ms 41888 KB Output is correct
86 Correct 217 ms 23892 KB Output is correct
87 Correct 0 ms 384 KB Output is correct