提出 #62787094


ソースコード 拡げる

#include <bits/stdc++.h>

using namespace std;

struct BIT {
    int n;
    vector<int> t;
    BIT(int n): n(n) { t.assign(n+1, 0); }
    int lowbit(int x) { return x&-x; }
    void modify(int x, int d) {
        for (; x <= n; x+=lowbit(x)) { t[x] = max(t[x], d); }
    }
    int query(int x) {
        int res = 0;
        for (; x; x -= lowbit(x)) { res = max(res, t[x]); }
        return res;
    }
};

void solve()
{
	int n, q;
    cin >> n >> q;
    vector<int> a(n), b, ans(q);
    vector<array<int,3>> qu(q);
    for (auto &x: a) { cin >> x; b.push_back(x); }
    for (int i = 0; i < q; ++i) {
        cin >> qu[i][0] >> qu[i][1];
        qu[i][2] = i;
        b.push_back(qu[i][1]);
    }
    sort(qu.begin(), qu.end());
    sort(b.begin(), b.end());
    b.erase(unique(b.begin(), b.end()), b.end());
    BIT t(b.size());
    int now = 0;
    for (auto [r, x, id]: qu) {
        while (now < r) {
            int pos = lower_bound(b.begin(), b.end(), a[now])-b.begin()+1;
            int res = 1;
            if (pos-1) { res = t.query(pos-1) + 1; }
            t.modify(pos, res);
            ++now;
        }
        int ask = lower_bound(b.begin(), b.end(), x)-b.begin()+1;
        ans[id] = t.query(ask);
    }
    for (auto x: ans) { cout << x << "\n"; }
}

int main()
{
	cin.tie(nullptr)->sync_with_stdio(false);
	int t = 1;
	while (t--) { solve(); }
}

提出情報

提出日時
問題 F - Prefix LIS Query
ユーザ LittleDrinks
言語 C++ 20 (gcc 12.2)
得点 500
コード長 1424 Byte
結果 AC
実行時間 140 ms
メモリ 10580 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 2
AC × 37
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 03_random3_04.txt, 03_random3_05.txt, 03_random3_06.txt, 03_random3_07.txt, 03_random3_08.txt, 03_random3_09.txt, 04_handmade_00.txt, 04_handmade_01.txt, 04_handmade_02.txt, 04_handmade_03.txt, 04_handmade_04.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3480 KiB
00_sample_01.txt AC 1 ms 3508 KiB
01_random_00.txt AC 1 ms 3504 KiB
01_random_01.txt AC 66 ms 8000 KiB
01_random_02.txt AC 26 ms 5676 KiB
01_random_03.txt AC 39 ms 5112 KiB
01_random_04.txt AC 58 ms 6372 KiB
01_random_05.txt AC 71 ms 7112 KiB
01_random_06.txt AC 140 ms 10420 KiB
01_random_07.txt AC 139 ms 10476 KiB
01_random_08.txt AC 139 ms 10416 KiB
01_random_09.txt AC 139 ms 10396 KiB
01_random_10.txt AC 139 ms 10500 KiB
01_random_11.txt AC 139 ms 10448 KiB
01_random_12.txt AC 139 ms 10580 KiB
01_random_13.txt AC 139 ms 10448 KiB
01_random_14.txt AC 139 ms 10476 KiB
02_random2_00.txt AC 111 ms 10448 KiB
02_random2_01.txt AC 120 ms 10404 KiB
02_random2_02.txt AC 129 ms 10580 KiB
02_random2_03.txt AC 133 ms 10420 KiB
02_random2_04.txt AC 137 ms 10428 KiB
03_random3_00.txt AC 123 ms 10400 KiB
03_random3_01.txt AC 117 ms 10440 KiB
03_random3_02.txt AC 124 ms 10452 KiB
03_random3_03.txt AC 118 ms 10332 KiB
03_random3_04.txt AC 123 ms 10412 KiB
03_random3_05.txt AC 121 ms 10388 KiB
03_random3_06.txt AC 122 ms 10328 KiB
03_random3_07.txt AC 121 ms 10476 KiB
03_random3_08.txt AC 125 ms 10400 KiB
03_random3_09.txt AC 124 ms 10392 KiB
04_handmade_00.txt AC 63 ms 9080 KiB
04_handmade_01.txt AC 101 ms 9360 KiB
04_handmade_02.txt AC 87 ms 9332 KiB
04_handmade_03.txt AC 78 ms 9272 KiB
04_handmade_04.txt AC 95 ms 10328 KiB