結果

問題 No.647 明太子
ユーザー merom686merom686
提出日時 2018-02-11 01:35:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 4,500 ms
コード長 2,036 bytes
コンパイル時間 1,133 ms
コンパイル使用メモリ 95,624 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-09 09:31:27
合計ジャッジ時間 2,246 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 6 ms
4,376 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 5 ms
4,380 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

void coco(vector<int>& v) {
    size_t n = v.size();
    vector<pair<int, int>> t(n);
    for (int i = 0; i < n; i++) {
        t[i] = { v[i], i };
    }
    sort(t.begin(), t.end());
    int k = 0;
    for (int i = 0; i < n; i++) {
        if (i > 0 && t[i].first != t[i - 1].first) k++;
        v[t[i].second] = k;
    }
}

struct BIT {
    BIT(int n) : b(n + 1), n(n) {}
    void add(int i, int v) {
        for (int k = i + 1; k <= n; k += k & -k) b[k] += v;
    }
    int sum(int k) {
        int s = 0;
        for (; k > 0; k -= k & -k) s += b[k];
        return s;
    }
    vector<int> b;
    int n;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }

    int m;
    cin >> m;

    a.resize(n + m);
    b.resize(n + m);
    for (int i = 0; i < m; i++) {
        cin >> a[n + i] >> b[n + i];
    }

    coco(a);
    coco(b);

    vector<pair<int, int>> p(n);
    vector<pair<pair<int, int>, int>> q(m);
    for (int i = 0; i < n; i++) {
        p[i] = { a[i], b[i] };
    }
    for (int j = 0; j < m; j++) {
        q[j].first = { a[n + j], b[n + j] };
        q[j].second = j;
    }
    sort(p.begin(), p.end(), greater<>());
    sort(q.begin(), q.end(), greater<>());

    int l = *max_element(b.begin(), b.begin() + n) + 1;
    BIT bt(l);
    vector<int> c(m);
    int i = 0;
    for (int j = 0; j < m; j++) {
        while (i < n && p[i].first >= q[j].first.first) {
            bt.add(p[i++].second, 1);
        }
        c[q[j].second] = bt.sum(min(l, q[j].first.second + 1));
    }

    int r = *max_element(c.begin(), c.end());
    if (r == 0) {
        cout << 0 << endl;
    } else {
        for (int j = 0; j < m; j++) {
            if (c[j] == r) cout << j + 1 << '\n';
        }
    }

    return 0;
}
0