49412023-04-07 17:03:41SleepyOverlordSzínes szobák (50 pont)cpp17Accepted 50/5082ms6888 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, rightOut = 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;
	}
	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/03ms1876 KiB
2Accepted0/082ms4508 KiB
3Accepted1/13ms2292 KiB
4Accepted1/13ms2652 KiB
5Accepted1/13ms2728 KiB
6Accepted1/13ms2760 KiB
7Accepted1/13ms2964 KiB
8Accepted1/13ms3196 KiB
9Accepted1/13ms3260 KiB
10Accepted1/14ms3404 KiB
11Accepted1/13ms3472 KiB
12Accepted1/14ms3608 KiB
13Accepted1/18ms3776 KiB
14Accepted1/14ms3716 KiB
15Accepted1/16ms3724 KiB
16Accepted1/18ms3776 KiB
17Accepted1/18ms3788 KiB
18Accepted1/18ms3784 KiB
19Accepted1/148ms5020 KiB
20Accepted1/178ms6096 KiB
21Accepted1/157ms5336 KiB
22Accepted1/163ms5688 KiB
23Accepted1/174ms5816 KiB
24Accepted1/179ms6212 KiB
25Accepted1/178ms6204 KiB
26Accepted1/176ms6204 KiB
27Accepted3/371ms6544 KiB
28Accepted3/372ms6752 KiB
29Accepted3/372ms6752 KiB
30Accepted3/371ms6828 KiB
31Accepted3/371ms6880 KiB
32Accepted3/371ms6888 KiB
33Accepted4/437ms5404 KiB
34Accepted4/461ms6580 KiB