93622024-02-21 09:36:40szilSzínes szobák (50 pont)cpp17Accepted 50/5037ms6824 KiB
#include <bits/stdc++.h>

using ll = long long;
using namespace std;

const int MAXN = 100'002;

int c[MAXN], n, k, m;
vector<pair<int, int>> v;

bool f(int pos, int border) {
    for (auto [a, b] : v) {
        if (c[pos] == a) pos += b;
        if (pos <= border && border == 0) return true;
        if (pos >= border && border == n+1) return true;
    }
    return false;
}

void solve() {
    cin >> n >> k >> m;
    v.resize(m);
    for (int i = 1; i <= n; i++) cin >> c[i];
    for (auto &[a, b] : v) {
        cin >> a >> b;
    }
    int ans = 0;
    {
        int lo = 0, hi = n;
        while (lo < hi) {
            int mid = (lo + hi + 1) / 2;
            if (f(mid, 0)) lo = mid;
            else hi = mid - 1;
        }
        ans += lo;
    }
    {
        int lo = 0, hi = n+1;
        while (lo < hi) {
            int mid = (lo + hi) / 2;
            if (f(mid, n+1)) hi = mid;
            else lo = mid + 1;
        }
        ans += n-lo+1;
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1896 KiB
2Accepted0/037ms4488 KiB
3Accepted1/13ms2476 KiB
4Accepted1/13ms2660 KiB
5Accepted1/13ms2864 KiB
6Accepted1/13ms2824 KiB
7Accepted1/13ms2828 KiB
8Accepted1/13ms2960 KiB
9Accepted1/13ms3176 KiB
10Accepted1/13ms3512 KiB
11Accepted1/13ms3728 KiB
12Accepted1/13ms3824 KiB
13Accepted1/14ms4096 KiB
14Accepted1/14ms4164 KiB
15Accepted1/14ms4088 KiB
16Accepted1/16ms4060 KiB
17Accepted1/16ms4072 KiB
18Accepted1/16ms4064 KiB
19Accepted1/121ms5024 KiB
20Accepted1/137ms6060 KiB
21Accepted1/127ms5544 KiB
22Accepted1/129ms5796 KiB
23Accepted1/134ms6100 KiB
24Accepted1/137ms6340 KiB
25Accepted1/137ms6600 KiB
26Accepted1/137ms6704 KiB
27Accepted3/335ms6560 KiB
28Accepted3/337ms6740 KiB
29Accepted3/335ms6824 KiB
30Accepted3/335ms6696 KiB
31Accepted3/335ms6696 KiB
32Accepted3/335ms6700 KiB
33Accepted4/418ms5532 KiB
34Accepted4/430ms6308 KiB