1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 | #include <bits/stdc++.h>
using namespace std;
#define LL long long int
LL merge_array(LL a[],LL temp[],LL low,LL mid,LL high)
{
LL i,j,k,count=0,p=mid-1;
for(i=low;i<=high;i++)
temp[i]=a[i];
i=low;
j=mid;
k=low;
while(i<=p && j<=high)
{
if(temp[i]<=temp[j])
a[k++]=temp[i++];
else
{
a[k++]=temp[j++];
count+=(mid-i);
}
}
while(i<=p)
a[k++]=temp[i++];
while(j<=high)
a[k++]=temp[j++];
return count;
}
LL merge_sort(LL a[],LL temp[],LL l,LL r)
{
LL mid,count=0;
if(l<r)
{
mid=(l+r)>>1;
count=merge_sort(a,temp,l,mid);
count+=merge_sort(a,temp,mid+1,r);
count+=merge_array(a,temp,l,mid+1,r);
}
return count;
}
LL _merge_sort(LL a[],LL n)
{
LL *temp=(LL *)malloc(sizeof(LL)*n);
return merge_sort(a,temp,0,n-1);
}
int main() {
LL t,n,i;
scanf("%lld",&t);
while(t--)
{
scanf("%lld",&n);
LL a[n];
for(i=0;i<n;i++)
scanf("%lld",&a[i]);
printf("%lld\n",_merge_sort(a,n));
}
return 0;
}
|
6 comments:
hey ive tried the brute force method but instead of getting TLE ,im getting an NZEC error.I know the right solution wont work either but im curious why Im getting Nzec instead of TLE.
thanks in advance :)
hey there may be some reason ............as below
1.its fullform is "non zero exit code''
2.Its essentially saying that your program ran into some error during execution. Mostly, it comes up when there is a Segmentation Fault.
The SegFault can be caused by many things, but experience says it is mainly through two causes:
(a) Infinite Recursion - or basically when you run out of stack memory.
(b) Incorrect Memory Access - or whenever there is some weird stuff happening with memory allocation / access. C++ isn't so friendly as Java, and it will not explicitly tell you that you have an "ArrayIndexOutOfBounds Exception", but will instead try to use the "supposed" memory even if it is outside the block. This makes things a bit hard to debug.
3.Everytime i got NZEC was because i forgot to return a 0 in int main()
Post a Comment