#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 |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
2 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
2 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
24 ms |
2396 KB |
Output is correct |
11 |
Correct |
12 ms |
2392 KB |
Output is correct |
12 |
Correct |
22 ms |
2396 KB |
Output is correct |
13 |
Correct |
41 ms |
2548 KB |
Output is correct |
14 |
Correct |
32 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
2 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
24 ms |
2396 KB |
Output is correct |
11 |
Correct |
12 ms |
2392 KB |
Output is correct |
12 |
Correct |
22 ms |
2396 KB |
Output is correct |
13 |
Correct |
41 ms |
2548 KB |
Output is correct |
14 |
Correct |
32 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2596 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Execution timed out |
3075 ms |
3136 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Execution timed out |
3059 ms |
3164 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Execution timed out |
3059 ms |
3164 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Execution timed out |
3059 ms |
3164 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2396 KB |
Output is correct |
6 |
Correct |
2 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
24 ms |
2396 KB |
Output is correct |
11 |
Correct |
12 ms |
2392 KB |
Output is correct |
12 |
Correct |
22 ms |
2396 KB |
Output is correct |
13 |
Correct |
41 ms |
2548 KB |
Output is correct |
14 |
Correct |
32 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2596 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Execution timed out |
3075 ms |
3136 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |