Guest User

Untitled

a guest
Mar 1st, 2020
239
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. Sviatoslav Bidzilia 2019
  4. CF: anakib1
  5.  
  6. */
  7.  
  8. #include <iostream>
  9. #include <cmath>
  10. #include <algorithm>
  11. #include <stdio.h>
  12. #include <cstring>
  13. #include <string>
  14. #include <cstdlib>
  15. #include <vector>
  16. #include <bitset>
  17. #include <map>
  18. #include <chrono>
  19. #include <unordered_set>
  20. #include <unordered_map>
  21. #include <numeric>
  22. #include <queue>
  23. #include <ctime>
  24. #include <stack>
  25. #include <set>
  26. #include <list>
  27. #include <deque>
  28. #include <iomanip>
  29. #include <sstream>
  30. #include <fstream>
  31. #include <stdarg.h>
  32. #include <functional>
  33. #include <utility>
  34.  
  35. using namespace std;
  36.  
  37. #define pb push_back
  38. #define mp make_pair
  39. #define ll long long
  40. #define ull unisgned long long
  41. #define ld long double
  42. #define all(a) a.begin(), a.end()
  43. #define SORT(a) sort(all(a))
  44. #define pii pair<int, int>
  45. #define tii triple<int, int, int>
  46. #define e 1e-7
  47. #define PI acos(-1)
  48. #define inf 1e17
  49. #define sz(a) (int)(a.size())
  50. #define vi vector<int>
  51. #define F first
  52. #define S second
  53. #define rng(x) for(int _ = 0; _ < (x); _++)
  54. #define rngi(i, x) for(int i = 0; i < (x); i++)
  55. #define rngsi(s, i, x) for(int i = (s); i <(x); i++)
  56. #define int long long
  57.  
  58. template<typename A, typename B, typename C>
  59. struct triple
  60. {
  61. A X;
  62. B Y;
  63. C Z;
  64. triple(A a = 0, B b = 0, C c = 0) :X(a), Y(b), Z(c) {}
  65. };
  66. template<typename A, typename B, typename C>
  67. triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0)
  68. {
  69. return triple<A, B, C>(a, b, c);
  70. }
  71. template<typename A, typename B, typename C>
  72. bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b)
  73. {
  74. if (a.X != b.X)
  75. return a.X < b.X;
  76. if (a.Y != b.Y)
  77. return a.Y < b.Y;
  78. return a.Z < b.Z;
  79. }
  80. template<typename T, typename SS>
  81. ostream& operator<<(ostream& ofs, const pair<T, SS>& p)
  82. {
  83. ofs << "( " << p.F << " , " << p.S << " )";
  84. return ofs;
  85. }
  86. template<typename T>
  87. void print(T a)
  88. {
  89. for (auto i : a)
  90. cout << i << ' ';
  91. cout << '\n';
  92. }
  93. template<typename T>
  94. T max(T a, T b, T c)
  95. {
  96. return max(a, max(b, c));
  97. }
  98. template<typename T>
  99. T min(T a, T b, T c)
  100. {
  101. return min(a, min(b, c));
  102. }
  103. struct custom_hash
  104. {
  105. static uint64_t splitmix64(uint64_t x)
  106. {
  107. x += 0x9e3779b97f4a7c15;
  108. x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
  109. x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
  110. return x ^ (x >> 31);
  111. }
  112.  
  113. size_t operator()(uint64_t x) const
  114. {
  115. static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
  116. return splitmix64(x + FIXED_RANDOM);
  117. }
  118. };
  119. signed main()
  120. {
  121. //freopen(".in", "r", stdin);
  122. //freopen(".out", "w", stdout);
  123. srand(time(NULL));
  124. cin.tie(0);
  125. cout.tie(0);
  126. ios_base::sync_with_stdio(false);
  127. int n, m, p;
  128. cin >> n >> m >> p;
  129. auto inp = [](int k){
  130. map<int, int> price;
  131. vi tmp;
  132. rng(k){
  133. int x, y; cin >> x >> y;
  134. tmp.pb(x);
  135. if (price.count(x)) price[x] = min(price[x], y);
  136. else price[x] = y;
  137. }
  138. SORT(tmp);
  139. vector<pii> a;
  140. int bst = inf;
  141. for (int i = k - 1; i >= 0; i--){
  142. if (price[tmp[i]] < bst)
  143. a.pb(mp(tmp[i], price[tmp[i]]));
  144. bst = min(bst, price[tmp[i]]);
  145. }
  146. return a;
  147. };
  148. auto a = inp(n), b = inp(m);
  149. map<int, int> p1, p2;
  150. for (auto x : a) p1[x.first] = x.second;
  151. for (auto x : b) p2[x.first] = x.second;
  152. vi x, y;
  153. for (auto xx : a) x.pb(xx.first);
  154. for (auto xy : b) y.pb(xy.first);
  155. vector<tii> mon(p); rngi(i, p) cin >> mon[i].X >> mon[i].Y >> mon[i].Z;
  156. SORT(mon);
  157. int now = 0;
  158. vi tree(4 * m, -inf), push(4 * m, 0);
  159. auto ps = [&](int v) {
  160. int& x = push[v];
  161. if (x) {
  162. tree[v << 1] += x;
  163. tree[v << 1 | 1] += x;
  164. push[v << 1] += x;
  165. push[v << 1 | 1] += x;
  166. x = 0;
  167. }
  168. };
  169. function<void(int, int, int, int, int)> st = [&](int v, int l, int r, int pos, int nv){
  170. if (l > r) return;
  171. if (l == r)return void(tree[v] = nv);
  172. int m = l + r >> 1;
  173. if (pos <= m) st(v << 1, l, m, pos, nv);
  174. else st(v << 1 | 1, m + 1, r, pos, nv);
  175. tree[v] = max(tree[v << 1], tree[v << 1 | 1]);
  176. };
  177. function<void(int, int, int, int, int, int)> ch = [&](int v, int l, int r, int _l, int _r, int xx){
  178. if (r < _l || _r < l) return;
  179. if (_l <= l && r <= _r)
  180. {
  181. tree[v] += xx;
  182. push[v] += xx;
  183. return;
  184. }
  185. int m = l + r >> 1;
  186. ps(v);
  187. ch(v << 1, l, m, _l, _r, xx);
  188. ch(v << 1 | 1, m + 1, r, _l, _r, xx);
  189. tree[v] = max(tree[v << 1], tree[v << 1 | 1]);
  190. };
  191. rngi(i, sz(y))
  192. st(1, 0, m - 1, i, -p2[y[i]]);
  193. int ans = -p1[x[0]] - p2[y[0]];
  194. for (auto r : mon){
  195. while (now < sz(x) && x[now] <= r.X) now++;
  196. if (now == sz(x)) break;
  197. int nw2 = upper_bound(all(y), r.Y) - y.begin();
  198. if (nw2 == sz(y)) break;
  199. ch(1, 0, m - 1, nw2, m - 1, r.Z);
  200. ans = max(ans, tree[1] - p1[x[now]]);
  201. }
  202. cout << ans << '\n';
  203. }
RAW Paste Data