主要是不懂怎么优化
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e7+5;
int q,op,l,r,score,a[maxn],all;
string str;
int main(){
score=0;
cin>>q;
while (q--){
cin>>str;
int size=str.size();
for (int i = 0;i<size;i++){
if (str[i]=='P') a[i]=3;
else if (str[i]=='p') a[i]=2;
else if (str[i]=='G') a[i]=1;
else a[i]=0;
}
cin>>op;
while (op--){
int l,r;
cin>>l>>r;
l--;r--;
for (int i = l;i<=r;i++){
score+=a[i];
}
cout<<score<<endl;
score=0;
}
}
return 0;
}