网站推广需要数据整改吗,想自己做一个网站应该怎么弄,如何快速建设网站,成功的wordpress网站传送门 文章目录题意#xff1a;思路#xff1a;题意#xff1a;
给你一个只有ANTOANTOANTO四个字母的字符串#xff0c;你每次可以交换相邻两个#xff0c;花费为111#xff0c;让后让你打乱字符串#xff0c;使得将打乱的字符串还原为原来的字符串的花费最小。 n≤1e…传送门
文章目录题意思路题意
给你一个只有ANTOANTOANTO四个字母的字符串你每次可以交换相邻两个花费为111让后让你打乱字符串使得将打乱的字符串还原为原来的字符串的花费最小。 n≤1e5n\le1e5n≤1e5
思路
打了这么长时间acmacmacm了还能因为没开LLLLLL挂题赛后又交了将近一页真是越来越菜了。 首先这个题通过打表以及第六感可以发现将所有相同的字母放在一起是最优的所以可以4!4!4!枚举所有位置让后checkcheckcheck一下取最大的花费即可现在瓶颈就是在怎么快速求出花费来。 我们假设原来的串为aaa现在的串为bbb首先我们可以从头遍历aaa让后对于aaa的每一个字符我们肯定都找其在bbb中第一次出现的位置用完之后删掉这个位置。可是我们将某一个删除的时候他们的某些位置可能会变化比如aaa从111开始初始的时候bbb的位置是1,2,3,4,51,2,3,4,51,2,3,4,5现在将444这个位置删掉花费为333那么现在bbb变为1,2,3,51,2,3,51,2,3,5下次需要选333这里删掉的时候就会出现问题了因为按照上面的话花费应该是3−213-213−21但是实际花费是222问题也很明显了我们将444删掉后应该让444前面的所有位置都111即变成2,3,4,52,3,4,52,3,4,5即可这个就很好维护了用线段树实现区间加即可。 代码写的丑的一批。
// Problem: D. Kill Anton
// Contest: Codeforces - Codeforces Round #723 (Div. 2)
// URL: https://codeforces.com/contest/1526/problem/D
// Memory Limit: 512 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize(Ofast,no-stack-protector,unroll-loops,fast-math)
//#pragma GCC target(sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tunenative)
//#pragma GCC optimize(2)
#includecstdio
#includeiostream
#includestring
#includecstring
#includemap
#includecmath
#includecctype
#includevector
#includeset
#includequeue
#includealgorithm
#includesstream
#includectime
#includecstdlib
#define X first
#define Y second
#define L (u1)
#define R (u1|1)
#define pb push_back
#define mk make_pair
#define Mid (tr[u].ltr[u].r1)
#define Len(u) (tr[u].r-tr[u].l1)
#define random(a,b) ((a)rand()%((b)-(a)1))
#define db puts(---)
#define int long long
using namespace std;//void rd_cre() { freopen(d://dp//data.txt,w,stdout); srand(time(NULL)); }
//void rd_ac() { freopen(d://dp//data.txt,r,stdin); freopen(d://dp//AC.txt,w,stdout); }
//void rd_wa() { freopen(d://dp//data.txt,r,stdin); freopen(d://dp//WA.txt,w,stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pairint,int PII;const int N1000010,mod1e97,INF0x3f3f3f3f;
const double eps1e-6;string s,ps;
string mp[10];
int a[20];
vectorintv[20];
struct Node {int l,r;int cnt,lazy;
}tr[N2];void pushup(int u) {tr[u].cnttr[L].cnttr[R].cnt;
}void pushdown(int u) {if(!tr[u].lazy) return;int lazytr[u].lazy; tr[u].lazy0;tr[L].lazylazy; tr[R].lazylazy;tr[L].cntlazy; tr[R].cntlazy;
}void build(int u,int l,int r) {tr[u]{l,r,1,0};if(lr) {tr[u].cntl;return;}build(L,l,Mid); build(R,Mid1,r);pushup(u);
} void change(int u,int l,int r,int c) {if(tr[u].lltr[u].rr) {tr[u].cntc;tr[u].lazyc;return;}if(lMid) change(L,l,r,c);if(rMid) change(R,l,r,c);pushup(u);
}int query(int u,int l,int r) {if(tr[u].lltr[u].rr) return tr[u].cnt;int ans0;pushdown(u);if(lMid) ansquery(L,l,r);if(rMid) ansquery(R,l,r);return ans;
}int check(string ps) {int ans0;build(1,1,ps.length());for(int i0;i4;i) v[i].clear();for(int is.length()-1;i0;i--) {if(ps[i]A) v[0].pb(i1);else if(ps[i]N) v[1].pb(i1);else if(ps[i]O) v[2].pb(i1);else v[3].pb(i1);}for(int i0;is.length();i) {int pos;if(s[i]A) posv[0].back(),v[0].pop_back();else if(s[i]N) posv[1].back(),v[1].pop_back();else if(s[i]O) posv[2].back(),v[2].pop_back();else posv[3].back(),v[3].pop_back();int nowquery(1,pos,pos);//couti1 now posendl;ansabs(now-(i1));change(1,1,pos-1,1);}return ans;
}signed main()
{ios::sync_with_stdio(false);cin.tie(0);int _; cin_;while(_--) {for(int i0;i4;i) mp[i],a[i]i;cinps; sps;for(int i0;ips.length();i) {if(ps[i]A) mp[0]A;else if(ps[i]N) mp[1]N;else if(ps[i]O) mp[2]O;else mp[3]T;}int ans-1;string res;do {string now;for(int i0;i4;i) nowmp[a[i]];int xcheck(now);if(xans) ansx,resnow;}while(next_permutation(a,a4));coutresendl;}return 0;
}
/**/