Submission #62814045


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<array<int, 3>> queries(q);
for (int i = 0; i < q; i++) {
cin >> queries[i][0] >> queries[i][1];
queries[i][2] = i;
}
sort(queries.begin(), queries.end(), [&](auto &one, auto &two) {
return one[0] < two[0];
});
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, q;
    cin >> n >> q;

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

    vector<array<int, 3>> queries(q);
    for (int i = 0; i < q; i++) {
        cin >> queries[i][0] >> queries[i][1];
        queries[i][2] = i;
    }
    sort(queries.begin(), queries.end(), [&](auto &one, auto &two) {
        return one[0] < two[0];
    });

    vector<int> res(q), lis;
    int completed = 0;
    for (auto [x, r, idx] : queries) {
        if (completed < x) {
            for (int i = completed; i < x; i++) {
                auto it = lower_bound(lis.begin(), lis.end(), a[i]);
                if (it == lis.end()) {
                    lis.push_back(a[i]);
                } else {
                    *it = a[i];
                }
                completed++;
            }
        }
        res[idx] = upper_bound(lis.begin(), lis.end(), r) - lis.begin();
    }

    for (int i = 0; i < q; i++) {
        cout << res[i] << "\n";
    }
    return 0;
}

Submission Info

Submission Time
Task F - Prefix LIS Query
User hemaprakash
Language C++ 20 (gcc 12.2)
Score 500
Code Size 1098 Byte
Status AC
Exec Time 174 ms
Memory 8184 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 37
Set Name Test Cases
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
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3492 KB
00_sample_01.txt AC 1 ms 3496 KB
01_random_00.txt AC 1 ms 3496 KB
01_random_01.txt AC 80 ms 6344 KB
01_random_02.txt AC 49 ms 4000 KB
01_random_03.txt AC 48 ms 3876 KB
01_random_04.txt AC 78 ms 5156 KB
01_random_05.txt AC 95 ms 5588 KB
01_random_06.txt AC 172 ms 7132 KB
01_random_07.txt AC 173 ms 7040 KB
01_random_08.txt AC 173 ms 7108 KB
01_random_09.txt AC 173 ms 7128 KB
01_random_10.txt AC 173 ms 7100 KB
01_random_11.txt AC 173 ms 7048 KB
01_random_12.txt AC 174 ms 7080 KB
01_random_13.txt AC 172 ms 7040 KB
01_random_14.txt AC 174 ms 7040 KB
02_random2_00.txt AC 160 ms 7104 KB
02_random2_01.txt AC 165 ms 7060 KB
02_random2_02.txt AC 163 ms 7100 KB
02_random2_03.txt AC 169 ms 7104 KB
02_random2_04.txt AC 172 ms 7088 KB
03_random3_00.txt AC 172 ms 8020 KB
03_random3_01.txt AC 157 ms 7100 KB
03_random3_02.txt AC 171 ms 8184 KB
03_random3_03.txt AC 158 ms 7044 KB
03_random3_04.txt AC 172 ms 8132 KB
03_random3_05.txt AC 160 ms 7100 KB
03_random3_06.txt AC 171 ms 8184 KB
03_random3_07.txt AC 162 ms 7180 KB
03_random3_08.txt AC 172 ms 8096 KB
03_random3_09.txt AC 165 ms 7128 KB
04_handmade_00.txt AC 158 ms 7132 KB
04_handmade_01.txt AC 131 ms 8104 KB
04_handmade_02.txt AC 144 ms 7028 KB
04_handmade_03.txt AC 137 ms 7100 KB
04_handmade_04.txt AC 124 ms 8180 KB


2025-04-05 (Sat)
10:49:23 +00:00