49472023-04-07 18:30:27TomaSajtSzínes szobák (50 pont)cpp17Accepted 50/5029ms6384 KiB
#include <bits/stdc++.h>
using namespace std;
// shamelessly "inspired by" (stolen) solution from SleepyOverlord on njudge

int main() {
  cin.tie(0), cin.sync_with_stdio(0);

  int n, k, m;
  cin >> n >> k >> m;

  vector<int> pos_color(n + 2);
  for (int i = 1; i <= n; i++)
    cin >> pos_color[i];

  vector<array<int, 2>> rqueries(m);
  for (int i = m - 1; i >= 0; i--)
    cin >> rqueries[i][0] >> rqueries[i][1];

  // calculates in reverse what was the position of the people
  // who reached their respective side last
  int left_pos = 0, right_pos = n + 1;
  for (auto &[c, x] : rqueries) {
    if (x == -1 && c == pos_color[left_pos + 1])
      left_pos++;
    if (x == 1 && c == pos_color[left_pos])
      left_pos--;
    if (x == 1 && c == pos_color[right_pos - 1])
      right_pos--;
    if (x == -1 && c == pos_color[right_pos])
      right_pos++;
  }
  cout << left_pos + (n + 1 - right_pos);
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1824 KiB
2Accepted0/029ms4400 KiB
3Accepted1/13ms2380 KiB
4Accepted1/13ms2584 KiB
5Accepted1/13ms2792 KiB
6Accepted1/13ms2644 KiB
7Accepted1/13ms2644 KiB
8Accepted1/13ms2900 KiB
9Accepted1/13ms2996 KiB
10Accepted1/13ms3356 KiB
11Accepted1/13ms3444 KiB
12Accepted1/13ms3636 KiB
13Accepted1/14ms3792 KiB
14Accepted1/14ms3732 KiB
15Accepted1/14ms4048 KiB
16Accepted1/14ms4292 KiB
17Accepted1/14ms4232 KiB
18Accepted1/14ms4380 KiB
19Accepted1/118ms5196 KiB
20Accepted1/129ms6232 KiB
21Accepted1/121ms5716 KiB
22Accepted1/124ms5724 KiB
23Accepted1/128ms5848 KiB
24Accepted1/129ms6244 KiB
25Accepted1/129ms6240 KiB
26Accepted1/129ms6240 KiB
27Accepted3/328ms6372 KiB
28Accepted3/328ms6384 KiB
29Accepted3/328ms6384 KiB
30Accepted3/328ms6384 KiB
31Accepted3/328ms6384 KiB
32Accepted3/328ms6384 KiB
33Accepted4/416ms4952 KiB
34Accepted4/425ms5860 KiB