92872024-02-19 20:01:57UVinceSzínes szobák (50 pont)cpp17Accepted 50/5041ms8788 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

vector<int> v;
vector<pair<int, int>> q;

int check(int n)
{
    int side = 0;
    for (auto [c, x] : q)
    {
        if (v[n] == c)
            n += x;
        if (n < 0)
        {
            side = -1;
            break;
        }
        if (n >= v.size())
        {
            side = 1;
            break;
        }
    }
    return side;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k, m;
    cin >> n >> k >> m;
    v.resize(n);
    q.resize(m);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    for (int i = 0; i < m; i++)
    {
        cin >> q[i].first >> q[i].second;
    }
    int ans = 0;
    int l = -1, r = n;

    while (l + 1 < r)
    {
        int cur = (l + r) / 2;
        int side = check(cur);
        if (side == -1)
        {
            l = cur;
        }
        else
        {
            r = cur;
        }
    }
    ans += l + 1;

    l = -1;
    r = n;
    while (l + 1 < r)
    {
        int cur = (l + r) / 2;
        int side = check(cur);
        if (side == 1)
        {
            r = cur;
        }
        else
        {
            l = cur;
        }
    }
    ans += n - r;
    cout << ans;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1892 KiB
2Accepted0/041ms4460 KiB
3Accepted1/13ms2444 KiB
4Accepted1/13ms2524 KiB
5Accepted1/13ms2732 KiB
6Accepted1/13ms2708 KiB
7Accepted1/13ms2708 KiB
8Accepted1/13ms2836 KiB
9Accepted1/13ms2924 KiB
10Accepted1/13ms3204 KiB
11Accepted1/13ms3196 KiB
12Accepted1/13ms3548 KiB
13Accepted1/14ms3572 KiB
14Accepted1/14ms3780 KiB
15Accepted1/14ms3748 KiB
16Accepted1/16ms4068 KiB
17Accepted1/16ms4012 KiB
18Accepted1/16ms4004 KiB
19Accepted1/124ms5224 KiB
20Accepted1/141ms6216 KiB
21Accepted1/129ms5888 KiB
22Accepted1/132ms5892 KiB
23Accepted1/137ms6024 KiB
24Accepted1/141ms6420 KiB
25Accepted1/141ms6424 KiB
26Accepted1/141ms6424 KiB
27Accepted3/339ms6808 KiB
28Accepted3/339ms7192 KiB
29Accepted3/339ms7568 KiB
30Accepted3/339ms7880 KiB
31Accepted3/339ms8260 KiB
32Accepted3/339ms8788 KiB
33Accepted4/420ms7564 KiB
34Accepted4/434ms8596 KiB