[hihoCoder1236 Scores 2015BeijingOnline] Simple Rough sub-block + simple rough bitset

Source: Internet
Author: User
Tags bitset

Test instructions: 50,000 5-dimensional vectors, 50,000 queries each dimension is not much more than the number of vectors that have always been, forcing online.

Idea: Finish This problem only know bitset efficiency so high, own local test 1s can operate 1010 bit,orz simple Rough

    • S (i) represents the i-dimensional vector set of the current vector, the answer is count (∩s (i)), and 0≤i‹5
    • Each vector can be bound with an ID (take off the mark on the line), after the binding can consider bitset. Sorted by each dimension, bitset of the ID before the current position is preprocessed at each √n location
    • When querying, the maximum position is obtained for each dimension, then S (i) can be obtained with 1 preprocessing results + √n single bit insertion of up to two points. Then it's and and count.

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;}

[hihoCoder1236 Scores 2015BeijingOnline] Simple Rough sub-block + simple rough bitset

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.