Submission #361931

# Submission time Handle Problem Language Result Execution time Memory
361931 2021-02-01T09:17:55 Z Return_0 Strange Device (APIO19_strange_device) C++17
100 / 100
968 ms 114796 KB
#pragma GCC optimize("Ofast,unroll-loops")
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;

#ifdef SINA
#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << std::endl; }
template <typename Arg1, typename... Args> void __f (const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); }
#define dbg2(x, j, n) cout<< #x << " : "; output((j), (n), x, 1);
#else
#define dbg(...) 0
#define dbg2(x, j, n) 0
#endif
#define SZ(x) ((ll)((x).size()))
#define File(s, t) freopen(s ".txt", "r", stdin); freopen(t ".txt", "w", stdout);
#define input(j, n, a) for (int _i = (j); _i < (n)+(j); _i++) cin>> a[_i];
#define output(j, n, a, t) for (int _i = (j); _i < (n)+(j); _i++) cout<< a[_i] << (((t) && _i != (n)+(j)-1)? ' ' : '\n');
#define kill(x) return cout<< x << endl, 0
#define cl const ll
#define fr first
#define sc second
// #define lc (v << 1)
// #define rc (lc | 1)
#define mid ((l + r) >> 1)
#define All(x) (x).begin(), (x).end()

cl inf = sizeof(ll) == 4 ? (1000000010) : (1000000000000000001LL), mod = 1e9 + 7, MOD = 998244353;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << '(' << a.first << ", " << a.second << ')';    }
template <class A> ostream& operator << (ostream& out, const vector<A> &a) {
	if(a.empty())return out<<"[]";out<< '[' << a[0]; for (int i = 0; ++i < (int)(a.size());) out<< ", " << a[i];out<< ']';  }
template <class T, typename _t = less <T> > using Tree = tree <T, null_type, _t, rb_tree_tag, tree_order_statistics_node_update>;

ll n, A, B, md, ans, cnt, L, t;
map <ll, vector <ll>> mp;

inline void add (cl &l, cl &r) { mp[l].push_back(1), mp[r + 1].push_back(-1); }

int main ()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	cin>> n >> A >> B;

	md = A / __gcd(A, B + 1);
	if (inf / B < md)	md = inf;
	else md = md * B;

	for (ll l, r; n--;) {
		cin>> l >> r;
		if (r - l + 1 >= md)	t = md;
		l %= md, r %= md;
		if (l <= r)	add(l, r);
		else add(0, r), add(l, md - 1); 
	}

	for (auto &x : mp) {
		if (cnt)	ans += x.fr - L;
		L = x.fr;
		for (auto &y : x.sc)	cnt += y;
	}

	cout<< max(ans, t) << endl;

	return 0;
}
/*
3 3 3
4 4
7 9
17 18

3 5 10
1 20
50 68
89 98

2 16 13
2 5
18 18

*/

Compilation message

strange_device.cpp: In function 'std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)':
strange_device.cpp:44:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   44 |  if(a.empty())return out<<"[]";out<< '[' << a[0]; for (int i = 0; ++i < (int)(a.size());) out<< ", " << a[i];out<< ']';  }
      |  ^~
strange_device.cpp:44:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   44 |  if(a.empty())return out<<"[]";out<< '[' << a[0]; for (int i = 0; ++i < (int)(a.size());) out<< ", " << a[i];out<< ']';  }
      |                                ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 380 KB Output is correct
2 Correct 8 ms 1516 KB Output is correct
3 Correct 8 ms 1516 KB Output is correct
4 Correct 1 ms 384 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 384 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 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 8 ms 1516 KB Output is correct
17 Correct 101 ms 11372 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 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 1 ms 492 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 313 ms 16172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 862 ms 109932 KB Output is correct
3 Correct 873 ms 113936 KB Output is correct
4 Correct 912 ms 114752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 862 ms 109932 KB Output is correct
3 Correct 873 ms 113936 KB Output is correct
4 Correct 912 ms 114752 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 880 ms 114796 KB Output is correct
7 Correct 946 ms 114772 KB Output is correct
8 Correct 864 ms 114720 KB Output is correct
9 Correct 955 ms 114588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 862 ms 109932 KB Output is correct
3 Correct 873 ms 113936 KB Output is correct
4 Correct 912 ms 114752 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 79 ms 15084 KB Output is correct
7 Correct 78 ms 15084 KB Output is correct
8 Correct 80 ms 15084 KB Output is correct
9 Correct 86 ms 14956 KB Output is correct
10 Correct 93 ms 15212 KB Output is correct
11 Correct 79 ms 15084 KB Output is correct
12 Correct 81 ms 15084 KB Output is correct
13 Correct 86 ms 14956 KB Output is correct
14 Correct 79 ms 15084 KB Output is correct
15 Correct 92 ms 15084 KB Output is correct
16 Correct 92 ms 15000 KB Output is correct
17 Correct 81 ms 15084 KB Output is correct
18 Correct 885 ms 114648 KB Output is correct
19 Correct 945 ms 113960 KB Output is correct
20 Correct 915 ms 114540 KB Output is correct
21 Correct 82 ms 15196 KB Output is correct
22 Correct 84 ms 14956 KB Output is correct
23 Correct 133 ms 10320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 112 ms 11372 KB Output is correct
3 Correct 86 ms 11372 KB Output is correct
4 Correct 900 ms 113944 KB Output is correct
5 Correct 86 ms 15084 KB Output is correct
6 Correct 94 ms 15172 KB Output is correct
7 Correct 91 ms 15084 KB Output is correct
8 Correct 89 ms 15084 KB Output is correct
9 Correct 87 ms 15084 KB Output is correct
10 Correct 83 ms 15084 KB Output is correct
11 Correct 85 ms 15084 KB Output is correct
12 Correct 85 ms 14956 KB Output is correct
13 Correct 88 ms 15084 KB Output is correct
14 Correct 968 ms 113772 KB Output is correct
15 Correct 84 ms 15136 KB Output is correct
16 Correct 846 ms 114156 KB Output is correct
17 Correct 852 ms 114040 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 380 KB Output is correct
2 Correct 8 ms 1516 KB Output is correct
3 Correct 8 ms 1516 KB Output is correct
4 Correct 1 ms 384 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 384 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 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 8 ms 1516 KB Output is correct
17 Correct 101 ms 11372 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 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 1 ms 492 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 313 ms 16172 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 862 ms 109932 KB Output is correct
31 Correct 873 ms 113936 KB Output is correct
32 Correct 912 ms 114752 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 880 ms 114796 KB Output is correct
35 Correct 946 ms 114772 KB Output is correct
36 Correct 864 ms 114720 KB Output is correct
37 Correct 955 ms 114588 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 79 ms 15084 KB Output is correct
40 Correct 78 ms 15084 KB Output is correct
41 Correct 80 ms 15084 KB Output is correct
42 Correct 86 ms 14956 KB Output is correct
43 Correct 93 ms 15212 KB Output is correct
44 Correct 79 ms 15084 KB Output is correct
45 Correct 81 ms 15084 KB Output is correct
46 Correct 86 ms 14956 KB Output is correct
47 Correct 79 ms 15084 KB Output is correct
48 Correct 92 ms 15084 KB Output is correct
49 Correct 92 ms 15000 KB Output is correct
50 Correct 81 ms 15084 KB Output is correct
51 Correct 885 ms 114648 KB Output is correct
52 Correct 945 ms 113960 KB Output is correct
53 Correct 915 ms 114540 KB Output is correct
54 Correct 82 ms 15196 KB Output is correct
55 Correct 84 ms 14956 KB Output is correct
56 Correct 133 ms 10320 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 112 ms 11372 KB Output is correct
59 Correct 86 ms 11372 KB Output is correct
60 Correct 900 ms 113944 KB Output is correct
61 Correct 86 ms 15084 KB Output is correct
62 Correct 94 ms 15172 KB Output is correct
63 Correct 91 ms 15084 KB Output is correct
64 Correct 89 ms 15084 KB Output is correct
65 Correct 87 ms 15084 KB Output is correct
66 Correct 83 ms 15084 KB Output is correct
67 Correct 85 ms 15084 KB Output is correct
68 Correct 85 ms 14956 KB Output is correct
69 Correct 88 ms 15084 KB Output is correct
70 Correct 968 ms 113772 KB Output is correct
71 Correct 84 ms 15136 KB Output is correct
72 Correct 846 ms 114156 KB Output is correct
73 Correct 852 ms 114040 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 11 ms 1900 KB Output is correct
80 Correct 922 ms 113260 KB Output is correct
81 Correct 913 ms 113260 KB Output is correct
82 Correct 945 ms 113284 KB Output is correct
83 Correct 910 ms 110220 KB Output is correct
84 Correct 930 ms 113004 KB Output is correct
85 Correct 937 ms 112808 KB Output is correct
86 Correct 139 ms 9424 KB Output is correct
87 Correct 1 ms 364 KB Output is correct