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;
int a[200100], b[200100], c[200100];
void solve(){
int n, m;
cin>>n>>m;
for(int i=1; i<=n; i++){
char c;
cin>>c;
if(c == 'R') a[i] = 1;
else a[i] = 0;
b[i] = a[i];
}
for(int i=1; i<=m; i++){
cin>>c[i];
}
int t;
cin>>t;
while(t--){
int l, r;
cin>>l>>r;
for(int i=1; i<=n; i++){
a[i] = b[i];
}
for(int j=l; j<=r; j++){
int d = c[j];
int c1=0, c2=0;
for(int i=1; i<d; i++){
if(a[i] == 1) c1 ++;
}
for(int i = d + 1; i<=n; i++){
if(a[i] == 0) c2 ++;
}
if(c1 < c2){
for(int i=d + 1, k=0; k < c1 + 1; i++){
if(a[i] == 0) k ++;
a[i] = 1;
}
for(int i=1; i<=d; i++) a[i] = 1;
}
else{
for(int i=d - 1, k=0; k<c2; i--){
if(a[i] == 1) k++;
a[i] = 0;
}
for(int i=n; i>=d; i--) a[i] = 0;
}
}
int ans = 0;
for(int i=1; i<=n; i++){
ans += a[i];
}
cout<<ans<<'\n';
}
}
int main(){
solve();
}
# | 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... |