Submission #363983

# Submission time Handle Problem Language Result Execution time Memory
363983 2021-02-07T19:22:18 Z MahdiBahramian Strange Device (APIO19_strange_device) C++11
100 / 100
2016 ms 106888 KB
#include<bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define int ll
using namespace std;
typedef long long ll;
const ll INF = 2e18 + 1000;
const int Max = 4e6 + 10;


ll L[Max] , R[Max];
vector<ll> compress;
unordered_map<ll , int> cnv;
int ps[Max];
int val[Max];
int32_t main()
{
	ll n , A , B; cin >> n >> A >> B;
	ll SUM = 0;
	for(int i = 1 ; i <= n ; i++)
	{
		cin >> L[i] >> R[i];
		SUM += R[i] - L[i] + 1;
	}
	if(A / __gcd(A , B + 1) > INF / B)
	{
		cout << SUM << '\n';
		return 0;
	}
	ll md = A * B / __gcd(A , B + 1);
	vector<pair<int , int>> vec;
	for(int i = 1 ; i <= n ; i++)
	{
		if(R[i] - L[i] + 1 >= md)
		{
			cout << md << '\n';
			return 0;
		}
		R[i] %= md;
		L[i] %= md;

		compress.pb(L[i]);
		compress.pb(R[i] + 1);
		if(R[i] < L[i])
		{
			vec.pb(mp(0 , R[i]));
			vec.pb(mp(L[i] , md - 1));
		}
		else vec.pb(mp(L[i] , R[i]));
	}
	compress.pb(0);
	compress.pb(md);
	sort(compress.begin() , compress.end());
	compress.resize(unique(compress.begin() , compress.end()) - compress.begin());
	for(int i = 0 ; i < compress.size() ; i++) cnv[compress[i]] = i;

	for(int i = 0 ; i < vec.size() ; i++)
	{
		//cout << vec[i].F << ',' << vec[i].S << '\n';
		val[cnv[vec[i].F]]++;
		val[cnv[vec[i].S + 1]]--;
	}
	for(int i = 1 ; i < compress.size() ; i++) val[i] += val[i - 1];
	ll res = 0;
	for(int i = 0 ; i < compress.size() - 1 ; i++)
	{
		if(val[i] >= 1)
		{
			res += compress[i + 1] - compress[i];
		}
	}
	cout << '\n';
	cout << res << '\n';
}

Compilation message

strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:57:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |  for(int i = 0 ; i < compress.size() ; i++) cnv[compress[i]] = i;
      |                  ~~^~~~~~~~~~~~~~~~~
strange_device.cpp:59:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |  for(int i = 0 ; i < vec.size() ; i++)
      |                  ~~^~~~~~~~~~~~
strange_device.cpp:65:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |  for(int i = 1 ; i < compress.size() ; i++) val[i] += val[i - 1];
      |                  ~~^~~~~~~~~~~~~~~~~
strange_device.cpp:67:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |  for(int i = 0 ; i < compress.size() - 1 ; i++)
      |                  ~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 19 ms 1384 KB Output is correct
3 Correct 19 ms 1384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 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 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 17 ms 1300 KB Output is correct
17 Correct 180 ms 9936 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 1135 ms 47584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1713 ms 94904 KB Output is correct
3 Correct 1890 ms 94824 KB Output is correct
4 Correct 1864 ms 101920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1713 ms 94904 KB Output is correct
3 Correct 1890 ms 94824 KB Output is correct
4 Correct 1864 ms 101920 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1864 ms 102020 KB Output is correct
7 Correct 1708 ms 101824 KB Output is correct
8 Correct 1892 ms 102020 KB Output is correct
9 Correct 1998 ms 102664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1713 ms 94904 KB Output is correct
3 Correct 1890 ms 94824 KB Output is correct
4 Correct 1864 ms 101920 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 173 ms 13776 KB Output is correct
7 Correct 178 ms 13648 KB Output is correct
8 Correct 172 ms 13776 KB Output is correct
9 Correct 182 ms 13776 KB Output is correct
10 Correct 168 ms 13648 KB Output is correct
11 Correct 178 ms 13776 KB Output is correct
12 Correct 174 ms 13648 KB Output is correct
13 Correct 183 ms 13648 KB Output is correct
14 Correct 170 ms 13648 KB Output is correct
15 Correct 185 ms 13660 KB Output is correct
16 Correct 183 ms 13872 KB Output is correct
17 Correct 177 ms 13672 KB Output is correct
18 Correct 1734 ms 102520 KB Output is correct
19 Correct 1903 ms 106552 KB Output is correct
20 Correct 1943 ms 102764 KB Output is correct
21 Correct 184 ms 13648 KB Output is correct
22 Correct 178 ms 13648 KB Output is correct
23 Correct 513 ms 25416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 182 ms 9936 KB Output is correct
3 Correct 181 ms 10064 KB Output is correct
4 Correct 1910 ms 95620 KB Output is correct
5 Correct 184 ms 13776 KB Output is correct
6 Correct 185 ms 13680 KB Output is correct
7 Correct 184 ms 13680 KB Output is correct
8 Correct 184 ms 13648 KB Output is correct
9 Correct 179 ms 13776 KB Output is correct
10 Correct 185 ms 13904 KB Output is correct
11 Correct 179 ms 13648 KB Output is correct
12 Correct 173 ms 13748 KB Output is correct
13 Correct 188 ms 13776 KB Output is correct
14 Correct 1835 ms 102092 KB Output is correct
15 Correct 181 ms 13776 KB Output is correct
16 Correct 1717 ms 102632 KB Output is correct
17 Correct 1713 ms 102696 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 19 ms 1384 KB Output is correct
3 Correct 19 ms 1384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 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 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 17 ms 1300 KB Output is correct
17 Correct 180 ms 9936 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 0 ms 364 KB Output is correct
21 Correct 0 ms 364 KB Output is correct
22 Correct 0 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 0 ms 364 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 1135 ms 47584 KB Output is correct
29 Correct 0 ms 364 KB Output is correct
30 Correct 1713 ms 94904 KB Output is correct
31 Correct 1890 ms 94824 KB Output is correct
32 Correct 1864 ms 101920 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1864 ms 102020 KB Output is correct
35 Correct 1708 ms 101824 KB Output is correct
36 Correct 1892 ms 102020 KB Output is correct
37 Correct 1998 ms 102664 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 173 ms 13776 KB Output is correct
40 Correct 178 ms 13648 KB Output is correct
41 Correct 172 ms 13776 KB Output is correct
42 Correct 182 ms 13776 KB Output is correct
43 Correct 168 ms 13648 KB Output is correct
44 Correct 178 ms 13776 KB Output is correct
45 Correct 174 ms 13648 KB Output is correct
46 Correct 183 ms 13648 KB Output is correct
47 Correct 170 ms 13648 KB Output is correct
48 Correct 185 ms 13660 KB Output is correct
49 Correct 183 ms 13872 KB Output is correct
50 Correct 177 ms 13672 KB Output is correct
51 Correct 1734 ms 102520 KB Output is correct
52 Correct 1903 ms 106552 KB Output is correct
53 Correct 1943 ms 102764 KB Output is correct
54 Correct 184 ms 13648 KB Output is correct
55 Correct 178 ms 13648 KB Output is correct
56 Correct 513 ms 25416 KB Output is correct
57 Correct 0 ms 364 KB Output is correct
58 Correct 182 ms 9936 KB Output is correct
59 Correct 181 ms 10064 KB Output is correct
60 Correct 1910 ms 95620 KB Output is correct
61 Correct 184 ms 13776 KB Output is correct
62 Correct 185 ms 13680 KB Output is correct
63 Correct 184 ms 13680 KB Output is correct
64 Correct 184 ms 13648 KB Output is correct
65 Correct 179 ms 13776 KB Output is correct
66 Correct 185 ms 13904 KB Output is correct
67 Correct 179 ms 13648 KB Output is correct
68 Correct 173 ms 13748 KB Output is correct
69 Correct 188 ms 13776 KB Output is correct
70 Correct 1835 ms 102092 KB Output is correct
71 Correct 181 ms 13776 KB Output is correct
72 Correct 1717 ms 102632 KB Output is correct
73 Correct 1713 ms 102696 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 17 ms 1768 KB Output is correct
80 Correct 2016 ms 102956 KB Output is correct
81 Correct 1928 ms 103052 KB Output is correct
82 Correct 1910 ms 103236 KB Output is correct
83 Correct 1943 ms 103996 KB Output is correct
84 Correct 1961 ms 106756 KB Output is correct
85 Correct 1917 ms 106888 KB Output is correct
86 Correct 510 ms 25928 KB Output is correct
87 Correct 1 ms 364 KB Output is correct