(https://www.luogu.org/problem/P3531) 注意编号 #include<cstdio> #include<algorithm> #include<cstring> #include<vector> #include<iostream> using namespace std; const int MAX = 1001001; int n; long long ans; int p[MAX], num[MAX], t…
这是一道字符串建模+图论的问题. 题目描述 Byteasar breeds hamsters. Each hamster has a unique name, consisting of lower case letters of the English alphabet. The hamsters have a vast and comfortable cage. Byteasar intends to place a display under the cage to visuali…
按照顺序依次找到b串每个字母最后的位置,然后求逆序对. #include<cstdio> #define N 1000010 int n,i,j,k,g[26],nxt[N],bit[N];char a[N],b[N];long long ans; int main(){ for(scanf("%d",&n),gets(a),gets(a+1),gets(b+1),i=1;i<=n;g[a[i]]=i++)nxt[i]=g[a[i]-='A']; for(i=…
处理数组A,A[i]表示字符串a的第i个字符排序后应去的位置,队列可. 对于多次出现的字符,其在a中的顺序和在b中的顺序应该是一一对应的. #include<cstdio> #include<queue> using namespace std; #define N 1000001 typedef long long ll; queue<int>qs[26]; ll ans; int n,A[N]; char a[N],b[N]; int d[N]; void Upda…