Submission #794244

# Submission time Handle Problem Language Result Execution time Memory
794244 2023-07-26T11:23:44 Z denniskim Modern Machine (JOI23_ho_t5) C++17
3 / 100
3000 ms 1252 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())

ll n, m;
char s[120010], s2[120010];
ll a[120010];
ll q;
ll L, R;
ll rd, bl;
ll numR, numB;

int main(void)
{
	fastio
	
	cin >> n >> m;
	
	for(ll i = 1 ; i <= n ; i++)
	{
		cin >> s[i];
		s2[i] = s[i];
	}
	
	for(ll i = 1 ; i <= m ; i++)
		cin >> a[i];
	
	cin >> q;
	
	while(q--)
	{
		cin >> L >> R;
		
		rd = bl = 0;
		numR = numB = 0;
		
		for(ll i = 1 ; i <= n ; i++)
			s[i] = s2[i];
		
		for(ll i = 1 ; i <= n ; i++)
		{
			if(s[i] == 'R')
				numR++;
			else
				numB++;
		}
		
		for(ll i = 1 ; i <= n ; i++)
		{
			if(s[i] == 'R')
				rd++;
			else
				break;
		}
		
		for(ll i = n ; i >= 1 ; i--)
		{
			if(s[i] == 'B')
				bl++;
			else
				break;
		}
		
		for(ll i = L ; i <= R ; i++)
		{
			if(rd + bl >= n)
			{
				if(a[i] <= numR)
					numR = (numR + a[i]) % (n + 1);
				else
					numR = (numR + a[i] + 1) % (n + 1);
			}
			
			else
			{
				if(s[a[i]] == 'B')
				{
					numR++;
					numB--;
					s[a[i]] = 'R';
				}
				
				while(rd < n)
				{
					if(s[rd + 1] == 'B')
						break;
					
					rd++;
				}
				
				while(bl < n)
				{
					if(s[n - bl] == 'R')
						break;
					
					bl++;
				}
				
				if(numB >= a[i])
				{
					ll num = a[i];
					
					while(rd < n && num)
					{
						if(s[rd + 1] == 'B')
						{
							num--;
							numR++;
							numB--;
							s[rd + 1] = 'R';
						}
						
						rd++;
					}
				}
				
				else
				{
					ll num = n + 1 - a[i];
					
					while(bl < n && num)
					{
						if(s[n - bl] == 'R')
						{
							num--;
							numB++;
							numR--;
							s[n - bl] = 'B';
						}
						
						bl++;
					}
				}
			}
		}
		
		cout << numR en;
	}
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 3056 ms 1252 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 3056 ms 1252 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 3056 ms 1252 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -