为何全部RE?

P1908 逆序对

猹猹猹猹猹猹 @ 2019-03-19 21:45:57

include<stdio.h>

include<stdlib.h>

int n, a[5000100]; long long s=0; void merge_up(int i,int j,int m);

void merge(int i, int j){ int m=(i+j)/2; if(i>=j) return; merge(i,m); merge(m+1,j); //现在,对于当前数组(i到j),是两段有序数组; //开始把两端合成一段 merge_up(i,j,m); return; } void merge_up(int i,int j,int m){ //i,m m+1,j int p; p=malloc( (j-i+1)sizeof(int) ); int t=1, x=i, y=m+1; while(x<=m && y<=j){ if(a[x]>a[y]){ p[t++] = a[y++]; s += m-x+1; }else if(a[x]<a[y]){ p[t++] = a[x++]; }else{ p[t++] = a[x++]; p[t++] = a[y++]; } } if(x>m || y>j){ while(x<=m){ p[t++] = a[x++]; } while(y<=j){ p[t++] = a[y++]; } } int count = j-i+1; for(t=1 ;t <= count; t++,i++){ a[i] = p[t]; } free(p); return; }

int main() { scanf("%d",&n); for(int i=1 ;i <= n; i++){ scanf("%d",&a[i]); } merge(1,n); printf("%lld\n",s); return 0;

} 为啥么会全部RE? 下载测试数据,n大于1e9了,怎么回事?


by 猹猹猹猹猹猹 @ 2019-03-19 21:49:45

我去,malloc申请空间太小。。。


|