Submission #362276

# Submission time Handle Problem Language Result Execution time Memory
362276 2021-02-02T13:53:57 Z soroush Strange Device (APIO19_strange_device) C++14
100 / 100
846 ms 67308 KB
/*
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma")
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;
typedef pair<int , int> pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 3e6;
const ll mod = 1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) cout << x , exit(0)
#define migmig ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(x , y) memset(x , y , sizeof x)
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n , m , a , b;
map < int , int > mp;

int32_t main(){
	migmig;
	cin >> n >> a >> b;
	int ans = 0;
	m = a / __gcd(a , b + 1) > 1e18 / (b + 1) ? int(1e18 + 1) : a / __gcd(a , b + 1) * b;
	while(n -- ){
		int l , r;
		cin >> l >> r;
		int L = l % m , R = r % m;
		if( r- l >= m) ans = m;
		else if ( L < R ) mp[L] ++ , mp[R + 1]--;
		else if ( L > R ) mp[L] ++ , mp[m]-- , mp[0] ++ , mp[R + 1]--;
		else if (l == r) mp[L] ++ , mp[L + 1] --;
		else ans = m;
	}
	int s = 0 , f = 1 , l;
	if(ans ^ m){
		for(auto i : mp){
			s += i.second;
			if(s and f)
				l = i.first , f = 0;
			else if (!s)
				ans += i.first - l , f = 1;
		}
	}
	cout << ans;
	return(0);
}

Compilation message

strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:54:20: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
   54 |     ans += i.first - l , f = 1;
      |            ~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 7 ms 1388 KB Output is correct
3 Correct 7 ms 1388 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 512 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 7 ms 1408 KB Output is correct
17 Correct 97 ms 10368 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 384 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 2 ms 492 KB Output is correct
3 Correct 2 ms 560 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 306 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 755 ms 66284 KB Output is correct
3 Correct 760 ms 66536 KB Output is correct
4 Correct 796 ms 67308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 755 ms 66284 KB Output is correct
3 Correct 760 ms 66536 KB Output is correct
4 Correct 796 ms 67308 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 766 ms 67052 KB Output is correct
7 Correct 769 ms 67052 KB Output is correct
8 Correct 775 ms 67240 KB Output is correct
9 Correct 826 ms 67180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 755 ms 66284 KB Output is correct
3 Correct 760 ms 66536 KB Output is correct
4 Correct 796 ms 67308 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 66 ms 10324 KB Output is correct
7 Correct 68 ms 10220 KB Output is correct
8 Correct 69 ms 10220 KB Output is correct
9 Correct 75 ms 10220 KB Output is correct
10 Correct 68 ms 10220 KB Output is correct
11 Correct 75 ms 10372 KB Output is correct
12 Correct 71 ms 10220 KB Output is correct
13 Correct 74 ms 10220 KB Output is correct
14 Correct 67 ms 10092 KB Output is correct
15 Correct 77 ms 10028 KB Output is correct
16 Correct 80 ms 9964 KB Output is correct
17 Correct 72 ms 9964 KB Output is correct
18 Correct 730 ms 66156 KB Output is correct
19 Correct 771 ms 65388 KB Output is correct
20 Correct 815 ms 66028 KB Output is correct
21 Correct 72 ms 9836 KB Output is correct
22 Correct 73 ms 9708 KB Output is correct
23 Correct 129 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 80 ms 9452 KB Output is correct
3 Correct 76 ms 9452 KB Output is correct
4 Correct 795 ms 65516 KB Output is correct
5 Correct 77 ms 9580 KB Output is correct
6 Correct 76 ms 9452 KB Output is correct
7 Correct 76 ms 9580 KB Output is correct
8 Correct 79 ms 9580 KB Output is correct
9 Correct 74 ms 9580 KB Output is correct
10 Correct 69 ms 9708 KB Output is correct
11 Correct 70 ms 9580 KB Output is correct
12 Correct 73 ms 9580 KB Output is correct
13 Correct 84 ms 9580 KB Output is correct
14 Correct 812 ms 65768 KB Output is correct
15 Correct 90 ms 9964 KB Output is correct
16 Correct 738 ms 66196 KB Output is correct
17 Correct 731 ms 66028 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 7 ms 1388 KB Output is correct
3 Correct 7 ms 1388 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 512 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 7 ms 1408 KB Output is correct
17 Correct 97 ms 10368 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 384 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 2 ms 492 KB Output is correct
26 Correct 2 ms 560 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 306 ms 876 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 755 ms 66284 KB Output is correct
31 Correct 760 ms 66536 KB Output is correct
32 Correct 796 ms 67308 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 766 ms 67052 KB Output is correct
35 Correct 769 ms 67052 KB Output is correct
36 Correct 775 ms 67240 KB Output is correct
37 Correct 826 ms 67180 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 66 ms 10324 KB Output is correct
40 Correct 68 ms 10220 KB Output is correct
41 Correct 69 ms 10220 KB Output is correct
42 Correct 75 ms 10220 KB Output is correct
43 Correct 68 ms 10220 KB Output is correct
44 Correct 75 ms 10372 KB Output is correct
45 Correct 71 ms 10220 KB Output is correct
46 Correct 74 ms 10220 KB Output is correct
47 Correct 67 ms 10092 KB Output is correct
48 Correct 77 ms 10028 KB Output is correct
49 Correct 80 ms 9964 KB Output is correct
50 Correct 72 ms 9964 KB Output is correct
51 Correct 730 ms 66156 KB Output is correct
52 Correct 771 ms 65388 KB Output is correct
53 Correct 815 ms 66028 KB Output is correct
54 Correct 72 ms 9836 KB Output is correct
55 Correct 73 ms 9708 KB Output is correct
56 Correct 129 ms 2668 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 80 ms 9452 KB Output is correct
59 Correct 76 ms 9452 KB Output is correct
60 Correct 795 ms 65516 KB Output is correct
61 Correct 77 ms 9580 KB Output is correct
62 Correct 76 ms 9452 KB Output is correct
63 Correct 76 ms 9580 KB Output is correct
64 Correct 79 ms 9580 KB Output is correct
65 Correct 74 ms 9580 KB Output is correct
66 Correct 69 ms 9708 KB Output is correct
67 Correct 70 ms 9580 KB Output is correct
68 Correct 73 ms 9580 KB Output is correct
69 Correct 84 ms 9580 KB Output is correct
70 Correct 812 ms 65768 KB Output is correct
71 Correct 90 ms 9964 KB Output is correct
72 Correct 738 ms 66196 KB Output is correct
73 Correct 731 ms 66028 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 1388 KB Output is correct
80 Correct 810 ms 66028 KB Output is correct
81 Correct 802 ms 65976 KB Output is correct
82 Correct 804 ms 66068 KB Output is correct
83 Correct 819 ms 66036 KB Output is correct
84 Correct 846 ms 66008 KB Output is correct
85 Correct 788 ms 65980 KB Output is correct
86 Correct 127 ms 3308 KB Output is correct
87 Correct 1 ms 364 KB Output is correct