This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
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... |