49342023-04-07 14:57:21SleepyOverlordSzínes szobák (50 pont)cpp17Wrong answer 16/50381ms11792 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, cnt;
VVI byColor;
VPII queries;

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

	queries.RS(q + 1);
	bool allSame = true;
	FOR(i, 1, q)
	{
		cin >> queries[i].X >> queries[i].Y;
		if (i > 1) allSame &= queries[i].Y == queries[i - 1].Y;
	}

	if (!allSame)
	{
		FOR(i, 1, q)
		{
			auto [color, delta] = queries[i];
			if (delta == -1)
				for (int i : byColor[color]) 
				{
					cnt[i + delta] += cnt[i];
					cnt[i] = 0;
				}
			else
				FORD(j, byColor[color].SZ - 1, 0)
				{
					int i = byColor[color][j];
					cnt[i + delta] += cnt[i];
					cnt[i] = 0;
				}
		}
		cout << cnt[0] + cnt[n + 1];
	}
	else
	{
		int ans = 0, j = q;
		if (queries[1].Y == -1)
		{
			FOR(i, 1, n)
			{
				while (j >= 1 && queries[j].X != color[i]) --j;
				++ans;
				--j;
				if (j == 0) break;
			}
		}
		else
		{
			FORD(i, n, 1)
			{
				while (j >= 1 && queries[j].X != color[i]) --j;
				++ans;
				--j;
				if (j == 0) break;
			}
		}
		cout << ans;
	}

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base16/50
1Accepted0/03ms1744 KiB
2Accepted0/093ms11792 KiB
3Wrong answer0/13ms2416 KiB
4Wrong answer0/13ms2628 KiB
5Wrong answer0/13ms2584 KiB
6Wrong answer0/13ms2896 KiB
7Wrong answer0/13ms2796 KiB
8Wrong answer0/13ms2688 KiB
9Wrong answer0/13ms3012 KiB
10Wrong answer0/14ms3268 KiB
11Accepted1/14ms3428 KiB
12Accepted1/14ms3436 KiB
13Accepted1/127ms3900 KiB
14Accepted1/112ms3968 KiB
15Accepted1/114ms4064 KiB
16Accepted1/137ms4192 KiB
17Accepted1/146ms4192 KiB
18Accepted1/146ms4260 KiB
19Accepted1/159ms7732 KiB
20Accepted1/190ms8900 KiB
21Accepted1/168ms8316 KiB
22Accepted1/174ms8644 KiB
23Accepted1/185ms8948 KiB
24Accepted1/190ms9296 KiB
25Accepted1/190ms9264 KiB
26Accepted1/190ms9264 KiB
27Time limit exceeded0/3347ms8332 KiB
28Time limit exceeded0/3368ms8344 KiB
29Time limit exceeded0/3352ms8392 KiB
30Time limit exceeded0/3372ms8284 KiB
31Time limit exceeded0/3324ms8336 KiB
32Time limit exceeded0/3352ms8596 KiB
33Time limit exceeded0/4356ms5920 KiB
34Time limit exceeded0/4381ms6376 KiB