同一份代码通过过所有测试点
//P7470
#include <bits/stdc++.h>
using namespace std;
namespace FastIO {
#if __cplusplus > 201700
#define INLINE_V inline
#else
#define INLINE_V
#endif
#if (defined(LOCAL) || defined(_WIN32)) && !defined(DISABLE_MMAP)
#define DISABLE_MMAP
#endif
#ifndef DISABLE_MMAP
#include <sys/mman.h>
#endif
INLINE_V constexpr int _READ_SIZE = 1 << 18; INLINE_V static char _read_buffer[_READ_SIZE], *_read_ptr = nullptr, *_read_ptr_end = nullptr;
inline char gc() { if (__builtin_expect(_read_ptr == _read_ptr_end, false)) { _read_ptr = _read_buffer; _read_ptr_end = _read_buffer + fread(_read_buffer, 1, _READ_SIZE, stdin); if (__builtin_expect(_read_ptr == _read_ptr_end, false)) return EOF;} return *_read_ptr++; }
INLINE_V constexpr int _WRITE_SIZE = 1 << 18; INLINE_V static char _write_buffer[_WRITE_SIZE], *_write_ptr = _write_buffer; inline void pc(char c) { *_write_ptr++ = c; if (__builtin_expect(_write_buffer + _WRITE_SIZE == _write_ptr, false)) { fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout); _write_ptr = _write_buffer; } }
INLINE_V struct _auto_flush { ~_auto_flush() { fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout); } } _auto_flush; inline bool _isdigit(char c) { return (c & 16) && c != EOF; } inline bool _isgraph(char c) { return c > 32 && c != EOF; }
template <class T> INLINE_V constexpr bool _is_integer = numeric_limits<T>::is_integer; template <class T> INLINE_V constexpr bool _is_signed = numeric_limits<T>::is_signed; template <class T> INLINE_V constexpr bool _is_unsigned = _is_integer<T> && !_is_signed<T>;
template <> INLINE_V constexpr bool _is_integer<__int128> = true; template <> INLINE_V constexpr bool _is_integer<__uint128_t> = true; template <> INLINE_V constexpr bool _is_signed<__int128> = true; template <> INLINE_V constexpr bool _is_unsigned<__uint128_t> = true;
inline void read(char &c) { do c = gc(); while (!_isgraph(c)); } inline void read_cstr(char *s) { char c = gc(); while (!_isgraph(c)) c = gc(); while (_isgraph(c)) *s++ = c, c = gc(); *s = 0; } inline void read(string &s) { char c = gc(); s.clear(); while (!_isgraph(c)) c = gc(); while (_isgraph(c)) s.push_back(c), c = gc(); }
template <class T, enable_if_t<_is_signed<T>, int> = 0> inline void read(T &x) { char c = gc(); bool f = true; x = 0; while (!_isdigit(c)) { if (c == 45) f = false; c = gc(); }
if (f) while (_isdigit(c)) x = x * 10 + (c & 15), c = gc(); else while (_isdigit(c)) x = x * 10 - (c & 15), c = gc(); } template <class T, enable_if_t<_is_unsigned<T>, int> = 0> inline void read(T &x) { char c = gc(); while (!_isdigit(c)) c = gc(); x = 0; while (_isdigit(c)) x = x * 10 + (c & 15), c = gc(); }
inline void write(char c) { pc(c); } inline void write_cstr(const char *s) { while (*s) pc(*s++); } inline void write(const string &s) { for (char c : s) pc(c); } template <class T, enable_if_t<_is_signed<T>, int> = 0> inline void write(T x) { char buffer[numeric_limits<T>::digits10 + 1]; int digits = 0; if (x >= 0) do buffer[digits++] = (x % 10) | 48, x /= 10; while (x);
else { pc(45); do buffer[digits++] = -(x % 10) | 48, x /= 10; while (x); } while (digits) pc(buffer[--digits]); } template <class T, enable_if_t<_is_unsigned<T>, int> = 0> inline void write(T x) { char buffer[numeric_limits<T>::digits10 + 1]; int digits = 0; do buffer[digits++] = (x % 10) | 48, x /= 10; while (x); while (digits) pc(buffer[--digits]); }
template <int N> struct _tuple_io_helper { template <class... T> static inline void _read(tuple<T...> &x) { _tuple_io_helper<N - 1>::_read(x), read(get<N - 1>(x)); } template <class... T> static inline void _write(const tuple<T...> &x) { _tuple_io_helper<N - 1>::_write(x), pc(32), write(get<N - 1>(x)); } };
template <> struct _tuple_io_helper<1> { template <class... T> static inline void _read(tuple<T...> &x) { read(get<0>(x)); } template <class... T> static inline void _write(const tuple<T...> &x) { write(get<0>(x)); } };
template <class... T> inline void read(tuple<T...> &x) { _tuple_io_helper<sizeof...(T)>::_read(x); } template <class... T> inline void write(const tuple<T...> &x) { _tuple_io_helper<sizeof...(T)>::_write(x); }
template <class T1, class T2> inline void read(pair<T1, T2> &x) { read(x.first), read(x.second); } template <class T1, class T2> inline void write(const pair<T1, T2> &x) { write(x.first), pc(32), write(x.second); }
template <class T1, class... T2> inline void read(T1 &x, T2 &...y) { read(x), read(y...); } template <class... T> inline void read_cstr(char *x, T *...y) { read_cstr(x), read_cstr(y...); }
template <class T1, class... T2> inline void write(const T1 &x, const T2 &...y) { write(x), write(y...); } template <class... T> inline void write_cstr(const char *x, const T *...y) { write_cstr(x), write_cstr(y...); }
template <class T> inline void print(const T &x) { write(x); } inline void print_cstr(const char *x) { write_cstr(x); } template <class T1, class... T2> inline void print(const T1 &x, const T2 &...y) { print(x), pc(32), print(y...); }
template <class... T> inline void print_cstr(const char *x, const T *...y) { print_cstr(x), pc(32), print_cstr(y...); } inline void println() { pc(10); } inline void println_cstr() { pc(10); }
template <class... T> inline void println(const T &...x) { print(x...), pc(10); } template <class... T> inline void printk(const T &...x) { print(x...), pc(32); } template <class... T> inline void println_cstr(const T *...x) { print_cstr(x...), pc(10); } } using namespace FastIO;
const int N = 1e5 + 10, M = N * 24;
int n, q, a[N], b[N], l[N], r[N], c[N], d[N], ans[N];
struct cal{
int val, id;
} sl[N*2];
inline bool cmp(cal x, cal y){
if(x.val != y.val){
return x.val > y.val;
} else {
return x.id < y.id;
}
}
mt19937 rnd(1134);
struct treap{
int rt[M*2];
struct node{
int ch[2], val, siz, pri;
} t[M];
int tot;
inline int nnd(int v){
++ tot;
t[tot].val = v;
t[tot].siz = 1;
t[tot].pri = rnd();
return tot;
}
inline void upd(int x){
t[x].siz = t[t[x].ch[0]].siz + 1 + t[t[x].ch[1]].siz;
}
inline int mg(int x, int y){
if(!x || !y){
return x + y;
}
if(t[x].pri < t[y].pri){
t[x].ch[1] = mg(t[x].ch[1], y);
upd(x);
return x;
} else {
t[y].ch[0] = mg(x, t[y].ch[0]);
upd(y);
return y;
}
}
inline void sp(int p, int k, int &x, int &y){
if(!p){
x = y = 0;
return;
}
if(t[p].val <= k){
x = p;
sp(t[p].ch[1], k, t[p].ch[1], y);
} else {
y = p;
sp(t[p].ch[0], k, x, t[p].ch[0]);
}
upd(p);
}
inline void ins(int i, int k){
int x, y;
sp(rt[i], k, x, y);
rt[i] = mg(mg(x, nnd(k)), y);
}
inline int dfs(int p, int k){
if(!p){
return 0;
} else if(t[p].val > k){
return dfs(t[p].ch[0], k);
} else {
return t[t[p].ch[0]].siz + 1 + dfs(t[p].ch[1], k);
}
}
} t;
int tot = 0, ch[M][2];
inline int hav(int i, int l, int r){
return t.dfs(t.rt[i], r) - t.dfs(t.rt[i], l-1);
}
inline void add(int x, int id){
int p = 0;
for(int i = 23; i >= 0; -- i){
if(!ch[p][(x >> i) & 1]){
ch[p][(x >> i) & 1] = ++ tot;
}
p = ch[p][(x >> i) & 1];
t.ins(p*2, id);
}
}
inline void addd(int x, int id, int fx){
int p = 0;
for(int i = 23; i >= 0; -- i){
if(!ch[p][(x >> i) & 1]){
ch[p][(x >> i) & 1] = ++ tot;
}
p = ch[p][(x >> i) & 1];
t.ins(p*2+((fx>>i)&1), id);
}
}
inline int ask(int x, int l, int r, int mx){
int p = 0, sum = 0;
for(int i = 23; i >= 0; -- i){
if((mx >> i) & 1){
sum += hav(ch[p][(x >> i) & 1]*2, l, r);
p = ch[p][!((x >> i) & 1)];
} else {
p = ch[p][(x >> i) & 1];
}
if(!p){
break;
}
}
return sum + hav(p*2, l, r);
}
inline int askk(int x, int l, int r){
int p = 0, sum = 0;
for(int i = 23; i >= 0; -- i){
if((x >> i) & 1){
sum += hav(ch[p][0]*2+1, l, r);
p = ch[p][1];
} else {
sum += hav(ch[p][1]*2, l, r);
p = ch[p][0];
}
if(!p){
break;
}
}
return sum + hav(p*2, l, r) + hav(p*2+1, l, r);
}
int main(){
read(n, q);
for(int i = 1; i <= n; ++ i){
read(a[i], b[i]);
sl[i] = { b[i], -i };
}
for(int i = 1; i <= q; ++ i){
read(l[i], r[i], c[i], d[i]);
sl[i+n] = { d[i], i };
}
sort(sl + 1, sl + n + q + 1, cmp);
int xx = 0;
for(int i = 1; i <= n + q; ++ i){
int p = sl[i].id;
if(sl[i].id < 0){
p = -p;
add(a[p], p);
} else {
++ xx;
ans[p] += ask(c[p], l[p], r[p], d[p]);
}
if(xx == q) break;
}
memset(ch, 0, sizeof(ch));
memset(t.rt, 0, sizeof(t.rt));
memset(t.t, 0, sizeof(t.t));
t.tot = 0;
tot = 0;
xx = 0;
for(int i = n + q; i >= 1; -- i){
int p = sl[i].id;
if(sl[i].id < 0){
p = -p;
addd(a[p]^b[p], p, a[p]);
} else {
++ xx;
ans[p] += askk(c[p], l[p], r[p]);
}
if(xx == q) break;
}
for(int i = 1; i <= q; ++ i){
println(ans[i]);
}
return 0;
}