結果
問題 | No.2422 regisys? |
ユーザー | drken1215 |
提出日時 | 2023-08-13 15:09:06 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 419 ms / 2,000 ms |
コード長 | 7,223 bytes |
コンパイル時間 | 2,758 ms |
コンパイル使用メモリ | 220,812 KB |
実行使用メモリ | 24,544 KB |
最終ジャッジ日時 | 2024-05-01 08:01:18 |
合計ジャッジ時間 | 11,819 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,944 KB |
testcase_12 | AC | 2 ms
6,948 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,944 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,940 KB |
testcase_18 | AC | 2 ms
6,940 KB |
testcase_19 | AC | 2 ms
6,944 KB |
testcase_20 | AC | 2 ms
6,940 KB |
testcase_21 | AC | 2 ms
6,940 KB |
testcase_22 | AC | 2 ms
6,940 KB |
testcase_23 | AC | 2 ms
6,944 KB |
testcase_24 | AC | 2 ms
6,940 KB |
testcase_25 | AC | 2 ms
6,940 KB |
testcase_26 | AC | 2 ms
6,940 KB |
testcase_27 | AC | 2 ms
6,940 KB |
testcase_28 | AC | 2 ms
6,940 KB |
testcase_29 | AC | 2 ms
6,940 KB |
testcase_30 | AC | 2 ms
6,940 KB |
testcase_31 | AC | 127 ms
13,048 KB |
testcase_32 | AC | 192 ms
9,764 KB |
testcase_33 | AC | 111 ms
12,984 KB |
testcase_34 | AC | 81 ms
6,536 KB |
testcase_35 | AC | 129 ms
13,412 KB |
testcase_36 | AC | 138 ms
9,040 KB |
testcase_37 | AC | 201 ms
13,776 KB |
testcase_38 | AC | 140 ms
7,024 KB |
testcase_39 | AC | 97 ms
6,664 KB |
testcase_40 | AC | 74 ms
8,320 KB |
testcase_41 | AC | 97 ms
6,696 KB |
testcase_42 | AC | 215 ms
22,772 KB |
testcase_43 | AC | 141 ms
9,152 KB |
testcase_44 | AC | 250 ms
22,848 KB |
testcase_45 | AC | 205 ms
22,528 KB |
testcase_46 | AC | 251 ms
22,912 KB |
testcase_47 | AC | 179 ms
13,468 KB |
testcase_48 | AC | 220 ms
22,932 KB |
testcase_49 | AC | 224 ms
14,216 KB |
testcase_50 | AC | 188 ms
22,656 KB |
testcase_51 | AC | 346 ms
23,960 KB |
testcase_52 | AC | 106 ms
13,056 KB |
testcase_53 | AC | 267 ms
23,004 KB |
testcase_54 | AC | 332 ms
24,148 KB |
testcase_55 | AC | 252 ms
23,340 KB |
testcase_56 | AC | 226 ms
14,460 KB |
testcase_57 | AC | 419 ms
24,540 KB |
testcase_58 | AC | 415 ms
24,544 KB |
testcase_59 | AC | 416 ms
24,508 KB |
testcase_60 | AC | 416 ms
24,484 KB |
testcase_61 | AC | 2 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using pint = pair<int, int>; using pll = pair<long long, long long>; // Segment Tree template<class Monoid> struct SegTree { using Func = function<Monoid(Monoid, Monoid)>; // core member int SIZE; Func F; Monoid IDENTITY; // data int offset; vector<Monoid> dat; // constructor SegTree() {} SegTree(int n, const Func &f, const Monoid &identity) : SIZE(n), F(f), IDENTITY(identity) { offset = 1; while (offset < n) offset *= 2; dat.assign(offset * 2, IDENTITY); } void init(int n, const Func &f, const Monoid &identity) { SIZE = n; F = f; IDENTITY = identity; offset = 1; while (offset < n) offset *= 2; dat.assign(offset * 2, IDENTITY); } int size() const { return SIZE; } // set, a is 0-indexed // // build(): O(N) void set(int a, const Monoid &v) { dat[a + offset] = v; } void build() { for (int k = offset - 1; k > 0; --k) dat[k] = F(dat[k*2], dat[k*2+1]); } void build(const vector<Monoid> &vec) { for (int a = 0; a < vec.size() && a + offset < dat.size(); ++a) set(a, vec[a]); build(); } // update a, a is 0-indexed, O(log N) void update(int a, const Monoid &v) { int k = a + offset; dat[k] = v; while (k >>= 1) dat[k] = F(dat[k*2], dat[k*2+1]); } // get [a, b), a and b are 0-indexed, O(log N) Monoid get(int a, int b) { Monoid vleft = IDENTITY, vright = IDENTITY; for (int left = a + offset, right = b + offset; left < right; left >>= 1, right >>= 1) { if (left & 1) vleft = F(vleft, dat[left++]); if (right & 1) vright = F(dat[--right], vright); } return F(vleft, vright); } Monoid get_all() { return dat[1]; } Monoid operator [] (int a) const { return dat[a + offset]; } // get max r that f(get(l, r)) = True (0-indexed), O(log N) // f(IDENTITY) need to be True int max_right(const function<bool(Monoid)> f, int l = 0) { if (l == SIZE) return SIZE; l += offset; Monoid sum = IDENTITY; do { while (l % 2 == 0) l >>= 1; if (!f(F(sum, dat[l]))) { while (l < offset) { l = l * 2; if (f(F(sum, dat[l]))) { sum = F(sum, dat[l]); ++l; } } return l - offset; } sum = F(sum, dat[l]); ++l; } while ((l & -l) != l); // stop if l = 2^e return SIZE; } // get min l that f(get(l, r)) = True (0-indexed), O(log N) // f(IDENTITY) need to be True int min_left(const function<bool(Monoid)> f, int r = -1) { if (r == 0) return 0; if (r == -1) r = SIZE; r += offset; Monoid sum = IDENTITY; do { --r; while (r > 1 && (r % 2)) r >>= 1; if (!f(F(dat[r], sum))) { while (r < offset) { r = r * 2 + 1; if (f(F(dat[r], sum))) { sum = F(dat[r], sum); --r; } } return r + 1 - offset; } sum = F(dat[r], sum); } while ((r & -r) != r); return 0; } // debug friend ostream& operator << (ostream &s, const SegTree &seg) { for (int i = 0; i < seg.size(); ++i) { s << seg[i]; if (i != seg.size()-1) s << " "; } return s; } }; #define REP(i, n) for (long long i = 0; i < (long long)(n); ++i) #define REP2(i, a, b) for (long long i = a; i < (long long)(b); ++i) #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) { return s << '<' << P.first << ", " << P.second << '>'; } template<class T> ostream& operator << (ostream &s, vector<T> P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template<class T> ostream& operator << (ostream &s, deque<T> P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) { for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; } template<class T> ostream& operator << (ostream &s, set<T> P) { for(auto it : P) { s << "<" << it << "> "; } return s; } template<class T> ostream& operator << (ostream &s, multiset<T> P) { for(auto it : P) { s << "<" << it << "> "; } return s; } template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) { for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s; } const long long INF = 1LL<<60; int main() { int N, M; cin >> N >> M; vector<pll> items(N); // {A[i], B[i]} vector<long long> gen, mma; for (int i = 0; i < N; ++i) cin >> items[i].first; for (int i = 0; i < N; ++i) cin >> items[i].second; for (int i = 0; i < M; ++i) { long long T, C; cin >> T >> C; if (T == 0) gen.push_back(C); else mma.push_back(C); } sort(items.begin(), items.end()); sort(gen.begin(), gen.end()); sort(mma.begin(), mma.end()); // 特定区間の B の最大値・最小値を求めるためのセグ木 using Node = pair<long long, int>; // {最大値 or 最小値, index} SegTree<Node> seg_max(N, [&](Node a, Node b){ return max(a, b); }, Node(-INF, -1)); SegTree<Node> seg_min(N, [&](Node a, Node b){ return min(a, b); }, Node(INF, -1)); for (int i = 0; i < N; ++i) { seg_max.set(i, pll(items[i].second, i)); seg_min.set(i, pll(items[i].second, i)); } seg_max.build(), seg_min.build(); // gen -> mma のそれぞれ所持金が小さい順に見ていく int match = 0; for (auto v : gen) { // まだ購入されていない商品のうち、A[i] <= v である範囲内で B[i] が最大の i を選ぶ int right = upper_bound(items.begin(), items.end(), pll(v, INF)) - items.begin(); auto [max_cost, index] = seg_max.get(0, right); // 購入済みにする if (index == -1) continue; ++match; seg_max.update(index, pll(-INF, -1)); seg_min.update(index, pll(INF, -1)); } for (auto v : mma) { // まだ購入されていない商品のうち、B[i] <= v であるような i を選ぶ (ここでは最小をとる) auto [min_cost, index] = seg_min.get(0, N); // 購入済みにする if (index == -1 || v < min_cost) continue; ++match; seg_max.update(index, pll(-INF, -1)); seg_min.update(index, pll(INF, -1)); } cout << N - match << endl; }