Home > Back-end >  Have a timeout, please use the array, using a pointer is AC.
Have a timeout, please use the array, using a pointer is AC.

Time:12-06

 # include & lt; Bits/stdc++. H> 
using namespace std;
E6 const int N=2 + 5;
Char STR [N].
Int s [N], sa [N], fairly rk [N], [N], c _x [N], _y [N].
Int n, m;
/*
Void tree () {
for (int i=0; i <=m; [I] i++) c=0;
For (int I=1; i <=n; I++) c [x] [I] + +;
For (int I=1; i <=m; I++) [I] + c=c [I - 1);
For (int I=n; I & gt;=1; I -) sa [c [x/y [I]]] -]=y [I];
}
*/
Void SA () {
Int * x=_x;//use array is timeout, use AC pointer?
Int * y=_y;
M=n;
for (int i=0; i <=m; [I] i++) c=0;
For (int I=1; i <=n; I++) c [I] [x=s [I]] + +;
For (int I=1; i <=m; I++) [I] + c=c [I - 1);
For (int I=n; I & gt;=1; I -) sa [x] [I] - [c]=I;
//for (int I=1; i<=n; I++) x=s [I] [I], [I] y=I;
//tree ();
For (int k=1, p; K & lt;=n; K & lt; <=1, m=p) {
P=0;
For (int I=n; I & gt; N - k; I -) [+ + y p]=I;
For (int I=1; i <=n; I++)
If (sa [I] & gt; K)
Y [+ + p]=sa [I] - k;
for (int i=0; i <=m; [I] i++) c=0;
For (int I=1; i <=n; I++) c [x] [I] + +;
For (int I=1; i <=m; I++) [I] + c=c [I - 1);
For (int I=n; I & gt;=1; I -) sa [c [x/y [I]]] -]=y [I];
P=y/sa [1]=1;
For (int I=2, a, b; i <=n; I++) {
A=(sa [I] + k & gt; n ? 1: x [sa + k] [I]);
B=(sa [I - 1) + k & gt; n ? 1: x [sa] [I - 1) + k);
Y [sa [I]]=(x==[sa [I]] x [sa [I - 1]] & amp; & A==b)? P: + + p;
}
Swap (x, y);
}
}
Int main () {
While (~ the scanf (" % d ", & amp; N)) {
The scanf (" % s ", STR + 1);
Int pos [2]={1, 1};
For (int I=n; I & gt;=1; I -) {
If (~ pos [STR [I] - 'a'])
S=n - [I] (pos [STR [I] - 'a'] - I);
The else
S [I]=0;
Pos [STR [I] - 'a']=I;
}
SA ();
For (int I=1; i <=n; I++)
Printf (" % d ", sa [I]);
printf("\n");
}
return 0;
}

Here is the inside of the SA () int * x, int * y, if directly on the outside of the array x [N], [N] y will timeout, what circumstance, TLE one day,

CodePudding user response:

If use arrays, don't know where you array is defined, if it is on the stack, more than stack space size, using a pointer is ac is what mean?

CodePudding user response:

reference 1/f, Simple, Soft reply:
if use arrays, don't know where you array is defined, if it is on the stack, more than size of stack space, using a pointer is ac is what mean?
bosses, hello is int * x, int * y remove then use x [], [] y as global variables will be TLE, you see how be to return a responsibility

CodePudding user response:

Self-study memory debugging,

CodePudding user response:

The
reference reply: 3/f thousand dream life
memory debugging, self-study

Typo, breakpoint debugging, see memory,
Put the meaning of each line is clear, from state to state clearly

CodePudding user response:

 int * x=_x;//use array is timeout, use AC pointer? 
Int * y=_y;

The above code, if use array, there will be no direct assignment, with a circular element assignment individually, so will timeout

CodePudding user response:

But I directly defined outside x [N], [N] y, no assignment, does not increase the time ah, don't change the other code,

CodePudding user response:

Stick your topic

CodePudding user response:

  • Related