#include #include #include

using namespace std;

typedef long long dint; #ifdef WIN32

define lld “%I64d”

#else

define lld “%lld”

#endif #define _l (long long int)

struct kdnode { int p[2], r[2][2], v; dint h; kdnode *ch[2]; inline void update(); }; struct candy { int a[2], v; void read() { scanf("%d%d%d", a, a + 1, &v); } };

typedef struct biobj { double x, y; biobj() {} biobj(double xo, double yo) { x = xo, y = yo; } } point, vect; inline biobj operator +(const biobj& a, const biobj& b) { return biobj(a. x + b. x, a. y + b. y); } inline biobj operator -(const biobj& a, const biobj& b) { return biobj(a. x - b. x, a. y - b. y); } inline double operator *(const biobj& a, const biobj& b) { return a. x * b. y - a. y * b. x; }

const double eps = 1e-7; inline int sgn(const double x) { return (x > eps) - (x < -eps); }

const int maxn = 50003;

int n, m, ki; dint qs; candy p[maxn]; point pa; vect pv; kdnode knbuf_arr[maxn], *knbuf(knbuf_arr), *krt;

inline bool kCmp(const candy& a, const candy& b) { if (a. a[ki] == b. a[ki]) return a. a[ki ^ 1] < b. a[ki ^ 1]; else return a. a[ki] < b. a[ki]; }

#define upMin(a,b) {
if (a > b)
a = b;
} #define upMax(a,b) {
if (a < b)
a = b;
}

inline void kdnode :: update() { r[0][0] = r[0][1] = p[0]; r[1][0] = r[1][1] = p[1]; h = v; if (ch[0]) { upMin(r[0][0], ch[0]-> r[0][0]); upMin(r[1][0], ch[0]-> r[1][0]); upMax(r[0][1], ch[0]-> r[0][1]); upMax(r[1][1], ch[0]-> r[1][1]); h += ch[0]-> h; } if (ch[1]) { upMin(r[0][0], ch[1]-> r[0][0]); upMin(r[1][0], ch[1]-> r[1][0]); upMax(r[0][1], ch[1]-> r[0][1]); upMax(r[1][1], ch[1]-> r[1][1]); h += ch[1]-> h; } }

kdnode* kdBuild(int l, int r) { if (l >= r) return 0; ki ^= 1; int md((l + r) » 1); nth_element(p + l, p + md, p + r, kCmp); kdnode* u(knbuf ++); u-> p[0] = p[md]. a[0], u-> p[1] = p[md]. a[1], u-> v = p[md]. v; u-> ch[0] = kdBuild(l, md), u-> ch[1] = kdBuild(md + 1, r); u-> update(); ki ^= 1; return u; }

void kdQry(kdnode* p) { if (!p) return; int s00(sgn((point(p-> r[0][0], p-> r[1][0]) - pa) * pv)); int s01(sgn((point(p-> r[0][0], p-> r[1][1]) - pa) * pv)); int s10(sgn((point(p-> r[0][1], p-> r[1][0]) - pa) * pv)); int s11(sgn((point(p-> r[0][1], p-> r[1][1]) - pa) * pv)); if (s00 > 0 && s01 > 0 && s10 > 0 && s11 > 0) { qs += p-> h; } else if (s00 <= 0 && s01 <= 0 && s10 <= 0 && s11 <= 0) { return; } else { if (sgn((point(p-> p[0], p-> p[1]) - pa) * pv) > 0) qs += p-> v; kdQry(p-> ch[0]), kdQry(p-> ch[1]); } }

int main() { #ifdef LAEKOV_LOCAL freopen(".in", “r”, stdin); #endif

scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++ i)
	p[i]. read();
ki = 0;
krt = kdBuild(0, n);
while (m --) {
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if (a || b) {
		if (b == 0)
			pa = point((double)c / a, 0);
		else
			pa = point(0, (double)c / b);
		pv = vect(b, -a);
		qs = 0;
		kdQry(krt);
	}
	else
		qs = (c > 0) ? krt-> h : 0;
	printf(lld "\n", qs);
}

}