其实可以(逃
```cpp
fa[N]={-1};
```
by Nero_Claudius @ 2018-07-18 15:27:05
@[DARTH_VADER](/space/show?uid=38859) 大括号赋值只能赋值成0呀,否则只有第一个数是-1
另外好像memset赋值更快....吧
by WSEDSWZD @ 2018-07-18 15:28:48
@[gaoxiaochuan](/space/show?uid=75017) 第一,你的n是不是大于了数组大小,第二,由于memset是字节赋值,所以应该会快一点~~你要是循环展开了我当然没话说~~
by moye到碗里来 @ 2018-07-18 15:32:57
@[WSEDSWZD](/space/show?uid=66141) 难道我的dev是假的?(大雾
by Nero_Claudius @ 2018-07-18 15:44:46
@[DARTH_VADER](/space/show?uid=38859) 好吧的确是假的
by Nero_Claudius @ 2018-07-18 15:47:22
@[moye到碗里来](/space/show?uid=52576)
n肯定是没有大于数组大小的,我照着题面n的范围定义的数组。
memset确实比for快一点,可是我的程序显示的是MLE,为什么用for循环就会超空间?
by 言者 @ 2018-07-18 15:49:46
@[gaoxiaochuan](/space/show?uid=75017) 你能发下代码吗。。
by moye到碗里来 @ 2018-07-18 15:52:40
****MLE代码****
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,m,q,p;
int col[1000001],fa[1000001];
inline int get_father(int x)
{
return (fa[x]<0)?x:fa[x]=get_father(fa[x]);
}
int main()
{
scanf("%d%d%d%d",&n,&m,&p,&q);
// 这里是与AC代码唯一不同的地方
for(int i=1;i<=n;++i)
{
fa[i]=-1;
}
//memset(fa,-1,sizeof(fa));
for(int i=m;i>=1;--i)
{
int l=(i*p+q)%n+1,r=(i*q+p)%n+1;
if(l>r) swap(l,r);
l=get_father(l);
while(l<=r)
{
col[l]=i;
fa[l]=l+1;
l=get_father(l+1);
}
}
for(int i=1;i<=n;++i)
{
printf("%d\n",col[i]);
}
return 0;
}
by 言者 @ 2018-07-18 16:12:26
@[moye到碗里来](/space/show?uid=52576)
代码已发,
~~~~头文件忘加了#号~~~~
by 言者 @ 2018-07-18 16:14:15
好像头文件#号没粘过来...
by 言者 @ 2018-07-18 16:15:37