网页设计优化网站建设可以吗Wordpress可以卸载吗
https://ac.nowcoder.com/acm/contest/103151/C
思路:这道题·,总是感觉自己能够做出来,但是有一些细节没有处理好,我们可以开一个数组sum[][],记录字母i和字母j能够产生多少逆序对,然后在查询的时候一种一种的加起来即可
#include<bits/stdc++.h>
using namespace std;typedef long long ll;
typedef pair<int, int>PII;
const int N=1e6+10;
const int MOD = 9901;
const int INF=0X3F3F3F3F;
const int dx[]={-1,1,0,0,-1,-1,+1,+1};
const int dy[]={0,0,-1,1,-1,+1,-1,+1};
const int M = 1e9 + 7;//哎哎要敢写啊,明明自己能做出来的
int sum[500][500];//字母a与字母b产生的逆序对
int cnt[N];
int main()
{int n, q;cin >> n >> q;string s;cin >> s;for(int i = 0; i < n; i ++){for(int j = 0; j <= 25; j ++){sum[s[i] - 'a'][j] += cnt[j];//左小右大,这只是初始的大小,你并不知道他们以后的大小//因此要都给存起来}cnt[s[i] - 'a'] ++;}while(q --){string o;cin >> o;ll s = 0;for(int i = 0; i < o.size(); i ++){for(int j = 0; j < i; j ++){s += sum[o[j] - 'a'][o[i] - 'a'];}}cout << s << endl;}return 0;
}