IOPC1207 - GM plants

int x1,x2,y1,y2,z1,z2;
			scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);
			ll r1 = range_query(1,0,nx-1,x1,x2,0);
			ll r2 = range_query(1,0,ny-1,y1,y2,1);
			ll r3 = range_query(1,0,nz-1,z1,z2,2);
			ll g1 = (x2-x1+1) - r1;
			ll g2 = (y2-y1+1) - r2;
			ll g3 = (z2-z1+1) - r3;
			ll ans = 1ll*r1*r2*r3;
			ans += 1ll*r1*g2*g3;
			ans += 1ll*g1*r2*g3;
			ans += 1ll*g1*g2*r3;
			printf("%lld\n",ans);

Note able to understand the logic for finding the red’s
link to problem: SPOJ.com - Problem IOPC1207

i read this already,i did not understand the explanation for this problem