// region standard #include <bits/stdc++.h> #define guard(x) if (!(x)) using namespace std; #define _CAT(A, B) A ## B #define CAT(A, B) _CAT(A, B) #define _STR(...) #__VA_ARGS__ #define STR(...) _STR(__VA_ARGS__) #define _FIRST(F, ...) F #define FIRST(...) _FIRST(__VA_ARGS__, ) #define SKIP1(F, ...) __VA_ARGS__ #define SKIP2(F, ...) SKIP1(__VA_ARGS__, ) #define SKIP3(F, ...) SKIP2(__VA_ARGS__, ) #define SKIP4(F, ...) SKIP3(__VA_ARGS__, ) #define SKIP5(F, ...) SKIP4(__VA_ARGS__, ) #define SKIP6(F, ...) SKIP5(__VA_ARGS__, ) #define SKIP7(F, ...) SKIP6(__VA_ARGS__, ) #define SKIP8(F, ...) SKIP7(__VA_ARGS__, ) #define SKIP9(F, ...) SKIP8(__VA_ARGS__, ) #define SKIP10(F, ...) SKIP9(__VA_ARGS__, ) #define SKIP11(F, ...) SKIP10(__VA_ARGS__, ) #define SKIP12(F, ...) SKIP11(__VA_ARGS__, ) #define SKIP(N, ...) CAT(SKIP, N)(__VA_ARGS__, ) #define COUNT(...) FIRST(SKIP12(__VA_ARGS__, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, )) #ifdef DEBUG #define MAGIC do { std::clog << boolalpha; } while(0) #define PRINT(msg) do { std::clog << "DBG:" << __LINE__ << "> " << msg << std::endl; } while(0) #else #define MAGIC do { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } while(0) #define PRINT(msg) do { } while(0) #endif #define _DBG1(x, ...) STR(x) << ": " << (x) #define _DBG2(x, ...) STR(x) << ": " << (x) << " \t" << _DBG1(__VA_ARGS__) #define _DBG3(x, ...) STR(x) << ": " << (x) << " \t" << _DBG2(__VA_ARGS__) #define _DBG4(x, ...) STR(x) << ": " << (x) << " \t" << _DBG3(__VA_ARGS__) #define _DBG5(x, ...) STR(x) << ": " << (x) << " \t" << _DBG4(__VA_ARGS__) #define _DBG6(x, ...) STR(x) << ": " << (x) << " \t" << _DBG5(__VA_ARGS__) #define _DBG7(x, ...) STR(x) << ": " << (x) << " \t" << _DBG6(__VA_ARGS__) #define _DBG8(x, ...) STR(x) << ": " << (x) << " \t" << _DBG7(__VA_ARGS__) #define _DBG9(x, ...) STR(x) << ": " << (x) << " \t" << _DBG8(__VA_ARGS__) #define _DBG10(x, ...) STR(x) << ": " << (x) << " \t" << _DBG9(__VA_ARGS__) #define _DBG11(x, ...) STR(x) << ": " << (x) << " \t" << _DBG10(__VA_ARGS__) #define _DBG12(x, ...) STR(x) << ": " << (x) << " \t" << _DBG11(__VA_ARGS__) #define _DBG(...) CAT(_DBG, COUNT(__VA_ARGS__))(__VA_ARGS__, ) #define DBG(...) PRINT(_DBG(__VA_ARGS__)) #define PDBG(msg, ...) PRINT(msg << _DBG(__VA_ARGS__)) #define ST first #define ND second #define EM emplace #define EB emplace_back #define IN insert #define PB push_back using ll = long long; using ull = unsigned long long; using ld = long double; using VI = vector<int>; using VLL = vector<ll>; #define ALL(x) (x).begin(), (x).end() #define PAL(p) p.first, p.second #define FI(e, v) for (auto const & e : v) #define RP(n) FR(CAT(i_, CAT(n, _i)), n) #define FV(i, s, n) for (int i = s; i > (int)(n); --i) #define FS(i, s, n) for (int i = s; i < (int)(n); ++i) #define FR(i, n) FS(i, 0, n) #define RV(i, s, n) for (int i = s; i >= (int)(n); --i) #define RS(i, s, n) for (int i = s; i <= (int)(n); ++i) #define RR(i, n) RS(i, 1, n) template<typename T> inline T mini(T & a, T const & b) { return a = min(a, b); } template<typename T> inline T maxi(T & a, T const & b) { return a = max(a, b); } template<typename T, typename... Args> ostream & operator << (ostream & os, vector<T, Args...> const & V) { bool f = false; FI(e, V) { if (f) { os << ", "; } f = true; os << e; } return os; } template<typename T, typename... Args> ostream & operator << (ostream & os, set<T, Args...> const & S) { bool f = false; FI(e, S) { if (f) { os << ", "; } f = true; os << e; } return os; } // endregion struct Input { int n = 0, m = 0; VLL T {}; VLL D {}; friend istream & operator >> (istream & is, Input & self) { auto & n = self.n; auto & m = self.m; auto & T = self.T; auto & D = self.D; is >> n >> m; T.resize(n); FR(i, n) { is >> T[i]; } D.resize(m); FR(i, m) { is >> D[i]; } return is; } }; struct Output { VLL V; Output (VLL && _V) : V(move(_V)) { } friend ostream & operator << (ostream & os, Output const & self) { auto const & V = self.V; FI(e, V) { os << e << "\n"; } return os; } }; using TP = tuple<ll, ll, ll>; ostream & operator << (ostream & os, TP const & t) { ll a, b, c; tie(a, b, c) = t; return os << "(" << a << ", " << b << ", " << c << ")"; } Output algo(Input && input) { auto const & n = input.n; auto const & T = input.T; auto const & D = input.D; DBG(T); DBG(D); VLL R; R.reserve(n); ll prev = 0; FI(t, T) { R.EB(t - prev); prev = t; } sort(ALL(R)); DBG(R); set<TP> S; ll off = 0; ll step = 0; prev = 0; FR(i, n) { auto const & r = R[i]; off += (r-prev)*step; step += 1; prev = r; if (i == n-1 || r != R[i+1]) { S.emplace_hint(S.end(), r, off, step); } } S.EM(0, 0, 0); DBG(S); VLL V; FI(d, D) { auto it = --S.upper_bound(TP(d, 0, 0)); ll r; tie(r, off, step) = *it; V.EB(off + (d-r)*step); } return {move(V)}; } #if __INCLUDE_LEVEL__ == 0 int main() { MAGIC; Input input; cin >> input; cout << algo(move(input)); } #endif
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | // region standard #include <bits/stdc++.h> #define guard(x) if (!(x)) using namespace std; #define _CAT(A, B) A ## B #define CAT(A, B) _CAT(A, B) #define _STR(...) #__VA_ARGS__ #define STR(...) _STR(__VA_ARGS__) #define _FIRST(F, ...) F #define FIRST(...) _FIRST(__VA_ARGS__, ) #define SKIP1(F, ...) __VA_ARGS__ #define SKIP2(F, ...) SKIP1(__VA_ARGS__, ) #define SKIP3(F, ...) SKIP2(__VA_ARGS__, ) #define SKIP4(F, ...) SKIP3(__VA_ARGS__, ) #define SKIP5(F, ...) SKIP4(__VA_ARGS__, ) #define SKIP6(F, ...) SKIP5(__VA_ARGS__, ) #define SKIP7(F, ...) SKIP6(__VA_ARGS__, ) #define SKIP8(F, ...) SKIP7(__VA_ARGS__, ) #define SKIP9(F, ...) SKIP8(__VA_ARGS__, ) #define SKIP10(F, ...) SKIP9(__VA_ARGS__, ) #define SKIP11(F, ...) SKIP10(__VA_ARGS__, ) #define SKIP12(F, ...) SKIP11(__VA_ARGS__, ) #define SKIP(N, ...) CAT(SKIP, N)(__VA_ARGS__, ) #define COUNT(...) FIRST(SKIP12(__VA_ARGS__, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, )) #ifdef DEBUG #define MAGIC do { std::clog << boolalpha; } while(0) #define PRINT(msg) do { std::clog << "DBG:" << __LINE__ << "> " << msg << std::endl; } while(0) #else #define MAGIC do { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } while(0) #define PRINT(msg) do { } while(0) #endif #define _DBG1(x, ...) STR(x) << ": " << (x) #define _DBG2(x, ...) STR(x) << ": " << (x) << " \t" << _DBG1(__VA_ARGS__) #define _DBG3(x, ...) STR(x) << ": " << (x) << " \t" << _DBG2(__VA_ARGS__) #define _DBG4(x, ...) STR(x) << ": " << (x) << " \t" << _DBG3(__VA_ARGS__) #define _DBG5(x, ...) STR(x) << ": " << (x) << " \t" << _DBG4(__VA_ARGS__) #define _DBG6(x, ...) STR(x) << ": " << (x) << " \t" << _DBG5(__VA_ARGS__) #define _DBG7(x, ...) STR(x) << ": " << (x) << " \t" << _DBG6(__VA_ARGS__) #define _DBG8(x, ...) STR(x) << ": " << (x) << " \t" << _DBG7(__VA_ARGS__) #define _DBG9(x, ...) STR(x) << ": " << (x) << " \t" << _DBG8(__VA_ARGS__) #define _DBG10(x, ...) STR(x) << ": " << (x) << " \t" << _DBG9(__VA_ARGS__) #define _DBG11(x, ...) STR(x) << ": " << (x) << " \t" << _DBG10(__VA_ARGS__) #define _DBG12(x, ...) STR(x) << ": " << (x) << " \t" << _DBG11(__VA_ARGS__) #define _DBG(...) CAT(_DBG, COUNT(__VA_ARGS__))(__VA_ARGS__, ) #define DBG(...) PRINT(_DBG(__VA_ARGS__)) #define PDBG(msg, ...) PRINT(msg << _DBG(__VA_ARGS__)) #define ST first #define ND second #define EM emplace #define EB emplace_back #define IN insert #define PB push_back using ll = long long; using ull = unsigned long long; using ld = long double; using VI = vector<int>; using VLL = vector<ll>; #define ALL(x) (x).begin(), (x).end() #define PAL(p) p.first, p.second #define FI(e, v) for (auto const & e : v) #define RP(n) FR(CAT(i_, CAT(n, _i)), n) #define FV(i, s, n) for (int i = s; i > (int)(n); --i) #define FS(i, s, n) for (int i = s; i < (int)(n); ++i) #define FR(i, n) FS(i, 0, n) #define RV(i, s, n) for (int i = s; i >= (int)(n); --i) #define RS(i, s, n) for (int i = s; i <= (int)(n); ++i) #define RR(i, n) RS(i, 1, n) template<typename T> inline T mini(T & a, T const & b) { return a = min(a, b); } template<typename T> inline T maxi(T & a, T const & b) { return a = max(a, b); } template<typename T, typename... Args> ostream & operator << (ostream & os, vector<T, Args...> const & V) { bool f = false; FI(e, V) { if (f) { os << ", "; } f = true; os << e; } return os; } template<typename T, typename... Args> ostream & operator << (ostream & os, set<T, Args...> const & S) { bool f = false; FI(e, S) { if (f) { os << ", "; } f = true; os << e; } return os; } // endregion struct Input { int n = 0, m = 0; VLL T {}; VLL D {}; friend istream & operator >> (istream & is, Input & self) { auto & n = self.n; auto & m = self.m; auto & T = self.T; auto & D = self.D; is >> n >> m; T.resize(n); FR(i, n) { is >> T[i]; } D.resize(m); FR(i, m) { is >> D[i]; } return is; } }; struct Output { VLL V; Output (VLL && _V) : V(move(_V)) { } friend ostream & operator << (ostream & os, Output const & self) { auto const & V = self.V; FI(e, V) { os << e << "\n"; } return os; } }; using TP = tuple<ll, ll, ll>; ostream & operator << (ostream & os, TP const & t) { ll a, b, c; tie(a, b, c) = t; return os << "(" << a << ", " << b << ", " << c << ")"; } Output algo(Input && input) { auto const & n = input.n; auto const & T = input.T; auto const & D = input.D; DBG(T); DBG(D); VLL R; R.reserve(n); ll prev = 0; FI(t, T) { R.EB(t - prev); prev = t; } sort(ALL(R)); DBG(R); set<TP> S; ll off = 0; ll step = 0; prev = 0; FR(i, n) { auto const & r = R[i]; off += (r-prev)*step; step += 1; prev = r; if (i == n-1 || r != R[i+1]) { S.emplace_hint(S.end(), r, off, step); } } S.EM(0, 0, 0); DBG(S); VLL V; FI(d, D) { auto it = --S.upper_bound(TP(d, 0, 0)); ll r; tie(r, off, step) = *it; V.EB(off + (d-r)*step); } return {move(V)}; } #if __INCLUDE_LEVEL__ == 0 int main() { MAGIC; Input input; cin >> input; cout << algo(move(input)); } #endif |