49402023-04-07 16:59:04SleepyOverlordSzínes szobák (50 pont)cpp17Accepted 50/5082ms7380 KiB
#include <vector>
#include <string> 
#include <set> 
#include <map> 
#include <unordered_set>
#include <unordered_map>
#include <queue> 
#include <bitset> 
#include <stack>
#include <list>

#include <numeric> 
#include <algorithm> 
#include <random>
#include <chrono>

#include <cstdio>
#include <fstream>
#include <iostream> 
#include <sstream> 
#include <iomanip>
#include <climits>

#include <cctype>
#include <cmath> 
#include <ctime>
#include <cassert>

using namespace std;

#define ULL unsigned long long
#define LL long long
#define PII pair <int, int>
#define VB vector <bool>
#define VI vector <int>
#define VLL vector <LL>
#define VD vector <double>
#define VS vector <string>
#define VPII vector <pair <int, int> >
#define VVI vector < VI >
#define VVB vector < VB >
#define SI set < int >
#define USI unordered_set <int>
#define MII map <int, int>
#define UMII unordered_map <int, int>
#define MS multiset
#define US unordered_set
#define UM unordered_map
#define UMS unordered_multiset
#define UMM unordered_multimap

#define FORN(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)

#define SZ size()
#define BG begin() 
#define EN end() 
#define CL clear()
#define X first
#define Y second
#define RS resize
#define PB push_back
#define MP make_pair
#define ALL(x) x.begin(), x.end()
#define INS insert
#define ER erase
#define CNT count

int n, c, q;
VI color;
VPII queries;

int main()
{
	cin >> n >> c >> q;
	color.RS(n + 2);
	FOR(i, 1, n) 
	{
		cin >> color[i];
	}

	queries.RS(q + 1);
	FOR(i, 1, q)
	{
		cin >> queries[i].X >> queries[i].Y;
	}

	int leftOut = 0;
	FORD(i, q, 1)
	{
		if (queries[i].X == color[leftOut] && queries[i].Y == 1)
		{
			--leftOut;
		}
		if (queries[i].X == color[leftOut + 1] && queries[i].Y == -1)
		{
			++leftOut;
		}
	}
	int rightOut = 0;
	FORD(i, q, 1)
	{
		if (queries[i].X == color[n + 1 - rightOut] && queries[i].Y == -1)
		{
			--rightOut;
		}
		if (queries[i].X == color[n - rightOut] && queries[i].Y == 1)
		{
			++rightOut;
		}
	}

	cout << leftOut + rightOut << endl;
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1880 KiB
2Accepted0/082ms4500 KiB
3Accepted1/13ms2296 KiB
4Accepted1/13ms2500 KiB
5Accepted1/13ms2708 KiB
6Accepted1/13ms2932 KiB
7Accepted1/13ms3012 KiB
8Accepted1/13ms3140 KiB
9Accepted1/13ms3496 KiB
10Accepted1/14ms3584 KiB
11Accepted1/13ms3684 KiB
12Accepted1/14ms3764 KiB
13Accepted1/18ms3844 KiB
14Accepted1/14ms3784 KiB
15Accepted1/16ms3924 KiB
16Accepted1/19ms4240 KiB
17Accepted1/18ms4468 KiB
18Accepted1/18ms4420 KiB
19Accepted1/148ms5800 KiB
20Accepted1/178ms6752 KiB
21Accepted1/157ms5980 KiB
22Accepted1/164ms6332 KiB
23Accepted1/172ms6648 KiB
24Accepted1/178ms7004 KiB
25Accepted1/176ms7052 KiB
26Accepted1/178ms6968 KiB
27Accepted3/371ms6948 KiB
28Accepted3/372ms6956 KiB
29Accepted3/371ms6952 KiB
30Accepted3/372ms7120 KiB
31Accepted3/371ms7132 KiB
32Accepted3/371ms7380 KiB
33Accepted4/437ms6184 KiB
34Accepted4/461ms7004 KiB