이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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++)
{
while(rd < n)
{
if(s[rd + 1] == 'B')
break;
rd++;
}
while(bl < n)
{
if(s[n - bl] == 'R')
break;
bl++;
}
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';
}
if(numB >= a[i])
{
ll num = a[i];
while(num)
{
if(s[rd + 1] == 'B')
{
num--;
numR++;
numB--;
s[rd + 1] = 'R';
}
rd++;
}
}
else
{
ll num = n + 1 - a[i];
while(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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |