P3809 求调!悬赏关注,不知道与最后一个测试点哪里对不上。
查看原帖
P3809 求调!悬赏关注,不知道与最后一个测试点哪里对不上。
797354
Ferdina_zcjb楼主2023/8/26 08:59
#include <bits/stdc++.h>

#define int long long

using namespace std;

const int MAXN = 1e6+5;

struct node{
	int fst = 0, snd = 0, k;//947 6 -1009
	
}a[MAXN], b[MAXN];

int sa[MAXN << 1];

void solve(char s[]);
bool cmp(node a, node b);

signed main(){
	//freopen("T.in", "r", stdin);
	//freopen("T.out", "w", stdout);
	
	char s[MAXN];
	cin >> s;
	
	solve(s);
	
	int l = strlen(s);
	for(int i = 0; i < l; ++i) {
		sa[i] = a[i].k+1;
		cout << sa[i] << " ";
		
		//maxx = max(maxx, sa[i]);
	}
	//cout << maxx;
	return 0;
} 

void solve(char s[]) {
	int len = strlen(s);
	
	for(int i = 0; i < len; ++i) {
		a[i].fst = (int)s[i];
		a[i].k = i;
	}
	
	for(int k = 1; k <= len; k <<= 1) {
		int jump = k / 2;
		
		for(int i = 0; i < len; ++i){
			if(a[i].k+jump < len) a[i].snd = b[a[i].k+jump].fst; 
			else a[i].snd = 0;
		}
		
		sort(a, a+len, cmp);
		
		b[a[0].k].fst = 1;
		for(int i = 1; i < len; ++i) {
			
			if(a[i].fst == a[i-1].fst && a[i].snd == a[i-1].snd)b[a[i].k].fst = b[a[i-1].k].fst;
			else b[a[i].k].fst = b[a[i-1].k].fst+1;
			
		}
		for(int i = 0; i < len;++i){
			a[i].fst = b[a[i].k].fst;
		}
		
		bool b = true;
		for(int i = 1; i < len; ++i){
			if(a[i].fst == a[i-1].fst){
				b = false;
				break;
			}
		}
		if(b==true){
			return ;
		}
	}
	
	return ;
}

bool cmp(node a, node b){
	if(a.fst == b.fst)return a.snd < b.snd;
	return a.fst < b.fst;
}
2023/8/26 08:59
加载中...