提交记录 3639


用户 题目 状态 得分 用时 内存 语言 代码长度
WAAutoMaton 1006. 【模板题】后缀排序 Accepted 100 267.785 ms 3608 KB C++11 2.71 KB
提交时间 评测时间
2018-07-17 12:30:01 2020-07-31 21:21:06
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
void iopen()
{
    static bool isOpen = false;
    if (!isOpen) {
        isOpen = true;
#ifdef MDEBUG
        freopen("in.txt", "r", stdin);
#endif
    }
}
template <size_t _I_Buffer_Size = 1 << 23, size_t _O_Buffer_Size = 1 << 23>
struct IO_Tp
{
    char _I_Buffer[_I_Buffer_Size];
    char *_I_pos;

    char _O_Buffer[_O_Buffer_Size];
    char *_O_pos;

    IO_Tp()
        : _I_pos(_I_Buffer)
        , _O_pos(_O_Buffer)
    {
        iopen();
        fread(_I_Buffer, 1, _I_Buffer_Size, stdin);
    }

    ~IO_Tp() { fwrite(_O_Buffer, 1, _O_pos - _O_Buffer, stdout); }

    inline bool is_digit(const char ch) { return '0' <= ch && ch <= '9'; }

    template<typename Int>
    inline IO_Tp &operator>>(Int &res)
    {
        res = 0;
		int k=1;
		while (!is_digit(*_I_pos)) {
			if (*_I_pos=='-')
				k=-1;
            _I_pos++;
		}
        do
            (res *= 10) += (*_I_pos++) & 15;
        while (is_digit(*_I_pos));
		res*=k;
        return *this;
    }


    inline char getop()
    {
        while (!is_digit(*_I_pos))
            _I_pos++;
        return (*_I_pos++) & 15;
    }

    template<typename Int>
    inline IO_Tp &operator<<(Int n)
    {
        if (n < 0) {
            *_O_pos++ = '-';
            n = -n;
        }
        static char _buf[20];
        char *_pos(_buf);
        do
            *_pos++ = '0' + n % 10;
        while (n /= 10);
        while (_pos != _buf)
            *_O_pos++ = *--_pos;
        return *this;
    }

    inline IO_Tp &operator<<(char ch)
    {
        *_O_pos++ = ch;
        return *this;
    }
};
// IO_Tp<> IO;
#define MAXN 100000
struct Data
{
	int a,b,id;
}x[MAXN+10];
bool comp(const Data& a,const Data& b)
{
	if (a.a==b.a && a.b==b.b) return a.id<b.id;
	if (a.a==b.a) return a.b<b.b;
	return a.a<b.a;
}
int n;
char a[MAXN+10];
int sa[MAXN+10],rk[2*MAXN+10];
void calcSA()
{
	for(int i=1; i<=n; ++i) {
		x[i].a=a[i];
		x[i].b=0;
		x[i].id=i;
	}
	int p=0;
	for(int i=1;p<n;i*=2) {
		p=0;
		sort(x+1,x+1+n,comp);
		Data t={0,0,0};
		for(int j=1; j<=n; ++j) {
			if (x[j].a!=t.a || x[j].b!=t.b) {
				++p;
				t=x[j];
			}
			rk[x[j].id]=p;
		}
		for(int j=1; j<=n; ++j) {
			x[j].a=rk[j];
			x[j].b=rk[j+i];
			x[j].id=j;
		}
	}
	for(int i=1; i<=n; ++i) {
		sa[rk[i]]=i;
	}
}
int height[MAXN+10];
void calcHeight()
{
	int k=0;
	for(int i=1; i<=n; ++i) {
		k=max(k-1,0);
		int j=sa[rk[i]-1];
		while(a[i+k]==a[j+k]) ++k;
		height[rk[i]]=k;
	}
}
int main()
{
	iopen();
	scanf("%s",a+1);
	n=strlen(a+1);
	calcSA();
	calcHeight();
	for(int i=1; i<=n; ++i) {
		printf("%d ",sa[i]);
	}
	puts("");
	for(int i=2; i<=n; ++i) {
		printf("%d ",height[i]);
	}
	puts("");
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #111.09 us36 KBAcceptedScore: 0

Subtask #1 Testcase #215.23 us36 KBAcceptedScore: 100

Subtask #1 Testcase #315.17 us36 KBAcceptedScore: 0

Subtask #1 Testcase #419.05 us36 KBAcceptedScore: 0

Subtask #1 Testcase #517.73 us36 KBAcceptedScore: 0

Subtask #1 Testcase #619.12 us36 KBAcceptedScore: 0

Subtask #1 Testcase #766.093 ms3 MB + 156 KBAcceptedScore: 0

Subtask #1 Testcase #8178.58 ms3 MB + 344 KBAcceptedScore: 0

Subtask #1 Testcase #985.628 ms3 MB + 208 KBAcceptedScore: 0

Subtask #1 Testcase #1054.807 ms2 MB + 112 KBAcceptedScore: 0

Subtask #1 Testcase #1159.529 ms2 MB + 152 KBAcceptedScore: 0

Subtask #1 Testcase #12267.785 ms3 MB + 536 KBAcceptedScore: 0

Subtask #1 Testcase #13202.499 ms3 MB + 504 KBAcceptedScore: 0

Subtask #1 Testcase #1492.026 ms3 MB + 236 KBAcceptedScore: 0

Subtask #1 Testcase #1592.87 ms3 MB + 252 KBAcceptedScore: 0

Subtask #1 Testcase #16136.954 ms3 MB + 536 KBAcceptedScore: 0

Subtask #1 Testcase #17165.809 ms3 MB + 536 KBAcceptedScore: 0

Subtask #1 Testcase #18179.469 ms3 MB + 536 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2024-11-22 17:56:01 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠