結果

問題 No.1703 Much Matching
ユーザー ぷらぷら
提出日時 2021-10-08 22:13:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 590 ms / 2,000 ms
コード長 1,304 bytes
コンパイル時間 2,364 ms
コンパイル使用メモリ 214,224 KB
実行使用メモリ 7,832 KB
最終ジャッジ日時 2023-09-30 10:33:22
合計ジャッジ時間 7,362 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 156 ms
5,360 KB
testcase_07 AC 9 ms
4,376 KB
testcase_08 AC 167 ms
5,176 KB
testcase_09 AC 192 ms
5,292 KB
testcase_10 AC 26 ms
4,380 KB
testcase_11 AC 41 ms
4,376 KB
testcase_12 AC 9 ms
4,376 KB
testcase_13 AC 72 ms
4,380 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 35 ms
4,380 KB
testcase_16 AC 100 ms
4,808 KB
testcase_17 AC 117 ms
4,620 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 254 ms
6,792 KB
testcase_20 AC 29 ms
4,376 KB
testcase_21 AC 305 ms
7,684 KB
testcase_22 AC 116 ms
5,020 KB
testcase_23 AC 86 ms
4,592 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 12 ms
4,376 KB
testcase_26 AC 57 ms
4,380 KB
testcase_27 AC 127 ms
4,544 KB
testcase_28 AC 248 ms
5,612 KB
testcase_29 AC 45 ms
4,376 KB
testcase_30 AC 67 ms
4,380 KB
testcase_31 AC 7 ms
4,380 KB
testcase_32 AC 130 ms
4,652 KB
testcase_33 AC 87 ms
4,376 KB
testcase_34 AC 8 ms
4,376 KB
testcase_35 AC 23 ms
4,376 KB
testcase_36 AC 590 ms
7,832 KB
testcase_37 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int inf = 1001001001;

template <typename T>
struct SegmentTree {
    int n;
    vector<T> dat;
    SegmentTree() {}
    SegmentTree(int N) {
        n = 1;
        while(n < N) {
            n *= 2;
        }
        dat.resize(2*n-1,-inf);
    }
    void update(int x, T val) {
        x += (n-1);
        dat[x] = val;
        while(x > 0) {
            x = (x-1)/2;
            dat[x] = max(dat[2*x+1],dat[2*x+2]);
        }
    }
    T query(int a, int b, int k, int l, int r) {
        if(r <= a || b <= l) return -inf;
        if(a <= l && r <= b) return dat[k];
        T vl = query(a, b, 2*k+1, l, (l+r)/2);
        T vr = query(a, b, 2*k+2, (l+r)/2, r);
        return max(vl, vr);
    }
    T query(int a,int b) {//[a,b)
        return query(a,b,0,0,n);
    }
};

int main() {
    int N,M,Q;
    cin >> N >> M >> Q;
    map<int,vector<int>>tmp;
    for(int i = 0; i < Q; i++) {
        int a,b;
        cin >> a >> b;
        tmp[a].push_back(b);
    }
    SegmentTree<int>Seg(M+1);
    Seg.update(0,0);
    for(auto x:tmp) {
        sort(x.second.rbegin(),x.second.rend());
        for(int i = 0; i < x.second.size(); i++) {
            Seg.update(x.second[i],Seg.query(0,x.second[i])+1);
        }
    }
    cout << Seg.query(0,M+1) << endl;
}
0