比赛 |
4043级2023省选模拟赛6 |
评测结果 |
AAATTTTTTTTTTTT |
题目名称 |
Tractor Paths |
最终得分 |
20 |
用户昵称 |
op_组撒头屯 |
运行时间 |
49.568 s |
代码语言 |
C++ |
内存使用 |
19.95 MiB |
提交时间 |
2023-03-28 09:01:47 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define si set<int>
#define unsi unordered_set<int>
#define qi queue<int>
#define sti stack<int>
#define pqi priority_queue<int>
#define mii map<int,int>
#define unmii unordered_map<int,int>
#define fi first
#define se second
#define pb push_back
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))
const int N=200000+5;
int n,m,lgn;
int anc[N][20];
char s[N<<1];
int query(int l,int r){
if (l==r)return 0;
int ans=0;
for (int i=lgn;i>=0;i--){
if (anc[l][i]&&anc[l][i]<r)l=anc[l][i],ans|=(1<<i);
}
return ans+1;
}
int main(){
freopen ("tuolapath.in","r",stdin);
freopen ("tuolapath.out","w",stdout);
scanf("%d%d",&n,&m);scanf("%s",s+1);lgn=1.0*log(n)/log(2);
int lst=0,cntl=0,cntr=0;
for (int i=1;i<=2*n;i++){
if (s[i]=='L')lst=++cntl;
else anc[++cntr][0]=lst;
}
for (int i=1;i<=lgn;i++){
for (int j=1;j<=n;j++)anc[j][i]=anc[anc[j][i-1]][i-1];
}
scanf("%s",s+1);
for (int i=1;i<=m;i++){
int l,r,ans1,ans2=0;scanf("%d%d",&l,&r);
if (l>r)swap(l,r);
ans1=query(l,r);
printf("%d ",ans1);
for (int i=l;i<=r;i++){
if (s[i]=='0')continue;
if (query(l,i)+query(i,r)==ans1)ans2++;
}
printf("%d\n",ans2);
}
}