1 2 3 4 5 6 7 8 9101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 7071727374757677787980 |
#include <bits/stdc++.h>using namespace std;#ifndef Online_judge #include "Local.h"#endif#define X First#define Y Second#define PB (x) push_back (x)#define MP (x, y) make_pair (x, y)#define ALL (a) (a). Begin (), (a). End ()#define MSET (A, X) memset (A, X, sizeof (a))#define MCPY (A, B) memcpy (A, B, sizeof (a))typedef Long Long ll;Template<TypeName T>BOOL Umax (T&A, Const T&b) {return b<=a?false:(A=b,true);}Template<TypeName T>BOOL Umin (T&A, Const T&b) {return b>=a?false:(A=b,true);}int K;struct Node { int a[5]; int ID; void Read() { for (int I = 0; I < 5; I ++) { scanf ("%d", a + i); } } BOOL operator < (Const Node &That ) Const { return A[k] < That.a[k]; }};Node stu[1 << -];int r[5][1 << -], id[5][1 << -];Bitset<1 << -> bs[5][1 << 8];int Main() {#ifndef Online_judge Freopen ("In.txt", "R", stdin); //freopen ("OUT.txt", "w", stdout);#endif//Online_judge int T, N, Q, m; Cin >> T; while (T --) { Cin >> N >> m; for (int I = 0; I < N; I ++) { Stu[i].read (); stu[i].id = i; } int L = sqrt (n + 0.5); for (int I = 0; I < 5; I ++) { k = i; sort (Stu, Stu + n); Bitset<1 << -> BBS; for (int J = 0; J < N; J ++) { R[i][j] = Stu[j].a[i]; Id[i][j] = stu[j].id; Bbs[stu[j].id] = 1; if (J % L == L - 1 || J == N - 1) { bs[i][j / L] = BBS; } } } int Lastans = 0; Cin >> Q; while (q --) { Node qry; Qry.read (); Bitset<1 << -> ans; for (int I = 0; I < 5; I ++) { Qry.a[i] ^= Lastans; Bitset<1 << -> buf; int POS = Upper_bound (R[i], R[i] + N, Qry.a[i]) - R[i]; if (POS / L) buf = Bs[i][pos / L - 1]; while (POS % L) buf[id[i][-- POS]] = 1; if (i) ans &= buf; Else ans = buf; } printf ("%d\ n", Lastans = Ans.count ()); } } return 0;} |