/*{{{ author: ryota2357 */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace ryota2357 { template inline std::istream& operator>>(std::istream& is, std::pair& P) noexcept { return is >> P.first >> P.second; } template inline std::istream& operator>>(std::istream& is, std::vector& V) noexcept { for (auto& v : V) is >> v; return is; } template inline std::ostream& operator<<(std::ostream& os, const std::vector& V) noexcept { const auto n = V.size() - 1; for (int i = 0; i < n; ++i) os << V[i] << ' '; return os << V.back(); } inline void IN(void) noexcept { return; } template inline void IN(T& t, U&... u) noexcept { std::cin >> t; IN(u...); } template inline void OUT(const T& x) noexcept { std::cout << x << '\n'; } template inline bool chmax(T& a, const T& b) noexcept { return a < b ? a = b, true : false; } template inline bool chmin(T& a, const T& b) noexcept { return a > b ? a = b, true : false; } template inline T read(void) { T ret = 0; char c = getchar(); while ((c < '0' || '9' < c) && c != '-') c = getchar(); const bool f = (c == '-') && (c = getchar()); while ('0' <= c && c <= '9') { ret = 10 * ret + c - '0'; c = getchar(); } return f ? -ret : ret; } template inline T ceil_div(const T& a, const T& b) { assert(b != 0); return (a + (b - 1)) / b; } template inline T max(const std::vector& v) { return *max_element(v.begin(), v.end()); } template inline T min(const std::vector& v) { return *min_element(v.begin(), v.end()); } template inline constexpr decltype(auto) recursive(F&& f) { return [f = std::forward(f)](auto&&... args) { return f(f, std::forward(args)...); }; } } // namespace ryota2357 using ll = long long; using pint = std::pair; #define rep(i, a, b) for (ll i = (a); i < ll(b); ++i) #define repr(i, a, b) for (ll i = (a); i >= ll(b); --i) #define each(x, v) for (auto& x : v) #define All(x) (x).begin(), (x).end() #define AllR(x) (x).rbegin(), (x).rend() #define Sort(x) (sort((x).begin(), (x).end())) #define SortR(x) (sort((x).rbegin(), (x).rend())) #define Unique(x) (x.erase(unique((x).begin(), (x).end()), (x).end())) #define Fill(v, n) (fill((v), (v) + sizeof(v) / sizeof(*(v)), (v))) #define INF (1073741823) #define INFL (2305843009213693951ll) using namespace std; using namespace ryota2357; /*}}}*/ int solve(int n, int m, vector ab, vector t0, vector t1) { Sort(t0); Sort(t1); priority_queue, greater<>> small; priority_queue large; rep(i, 0, n) { small.emplace(ab[i]); } each(x, t0) { while(small.size() && small.top().first <= x) { auto [a, b] = small.top(); small.pop(); large.emplace(min(a, b)); } if (large.empty()) { continue; } large.pop(); } vector min_v; while (small.size()) { auto [a, b] = small.top(); small.pop(); min_v.push_back(min(a, b)); } while (large.size()) { min_v.push_back(large.top()); large.pop(); } SortR(min_v); each(x, t1) { if (min_v.empty()) { break; } if (min_v.back() <= x) { min_v.pop_back(); } } return min_v.size(); } // only n == m int expect(int n, int m, vector ab, vector t0, vector t1) { int ans = n; vector idx(m); rep(i, 0, m) idx[i] = i; do { int cnt = 0; rep(i, 0, n) { auto [a, b] = ab[idx[i]]; if (i < t0.size()) { if (a <= t0[i]) { cnt += 1; } } else { if (min(a, b) <= t1[i - t0.size()]) { cnt += 1; } } } chmin(ans, n - cnt); } while(next_permutation(All(idx))); return ans; } int main() { int n, m; IN(n, m); vector ab(n); rep(i, 0, n) ab[i].first = read(); rep(i, 0, n) ab[i].second = read(); vector t0, t1; rep(i, 0, m) { if (read() == 0) { t0.push_back(read()); } else { t1.push_back(read()); } } OUT(solve(n, m, ab, t0, t1)); // rep(_, 0, 100) { // int n = (rand() % 5) + 1, m = n; // vector ab(n); // vector t0, t1; // rep(i, 0, n) { // ab[i] = {rand() % 100, rand() % 100}; // if (rand() % 2) { // t0.push_back(rand() % 100); // } else { // t1.push_back(rand() % 100); // } // } // int res = solve(n, m, ab, t0, t1); // int ans = expect(n, m, ab, t0, t1); // if (res != ans) { // cout << n << ' ' << m << endl; // rep(i, 0, n) cout << ab[i].first << " \n"[i == n-1]; // rep(i, 0, n) cout << ab[i].second << " \n"[i == n-1]; // rep(i, 0, t0.size()) cout << "0 " << t0[i] << endl; // rep(i, 0, t1.size()) cout << "1 " << t1[i] << endl; // // cout << endl; // cout << res << " / " << ans << endl; // break; // } // } return 0; }