Hihocoder 1236 Scores【分块+bitset】

来源:互联网 发布:剑三花爹数据 编辑:程序博客网 时间:2024/06/06 00:19

对于每一个分数,我们对其进行排序。
然后分成n块,每一块用一个bitset统计有多少人属于这个分数段。
然后对于每一次查询,我们用lowerbound搜出它属于那一块分数段,取出之前分数段的得分情况,然后暴力维护这一分数段。
每一个成绩统计出来的bitset,&到最后就是有多少人输了。count一下就好。

注意,每一次的答案都要和上一次异或,强制在线。

//      whn6325689//      Mr.Phoebe//      http://blog.csdn.net/u013007900#include <algorithm>#include <iostream>#include <iomanip>#include <cstring>#include <climits>#include <complex>#include <fstream>#include <cassert>#include <cstdio>#include <bitset>#include <vector>#include <deque>#include <queue>#include <stack>#include <ctime>#include <set>#include <map>#include <cmath>#include <functional>#include <numeric>#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;#define eps 1e-9#define PI acos(-1.0)#define INF 0x3f3f3f3f#define LLINF 1LL<<50#define speed std::ios::sync_with_stdio(false);typedef long long ll;typedef unsigned long long ull;typedef long double ld;typedef pair<ll, ll> pll;typedef complex<ld> point;typedef pair<int, int> pii;typedef pair<pii, int> piii;typedef vector<int> vi;#define CLR(x,y) memset(x,y,sizeof(x))#define CPY(x,y) memcpy(x,y,sizeof(x))#define clr(a,x,size) memset(a,x,sizeof(a[0])*(size))#define cpy(a,x,size) memcpy(a,x,sizeof(a[0])*(size))#define debug(a) cout << #a" = " << (a) << endl;#define debugarry(a, n) for (int i = 0; i < (n); i++) { cout << #a"[" << i << "] = " << (a)[i] << endl; }#define mp(x,y) make_pair(x,y)#define pb(x) push_back(x)#define lowbit(x) (x&(-x))#define MID(x,y) (x+((y-x)>>1))#define getidx(l,r) (l+r | l!=r)#define ls getidx(l,mid)#define rs getidx(mid+1,r)#define lson l,mid#define rson mid+1,rtemplate<class T>inline bool read(T &n){    T x = 0, tmp = 1;    char c = getchar();    while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();    if(c == EOF) return false;    if(c == '-') c = getchar(), tmp = -1;    while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar();    n = x*tmp;    return true;}template <class T>inline void write(T n){    if(n < 0)    {        putchar('-');        n = -n;    }    int len = 0,data[20];    while(n)    {        data[len++] = n%10;        n /= 10;    }    if(!len) data[len++] = 0;    while(len--) putchar(data[len]+48);}//-----------------------------------const int MAXN=50005;struct Node{    int val,id;    Node(int val,int id):val(val),id(id) {}    Node() {}    bool operator < (const Node &b) const    {        if(val==b.val) return id<b.id;        return val<b.val;    }} a[6][MAXN];int n,m,q;bitset<MAXN> bs[5][250];int block_num;int per_block;int main(){    int T;    read(T);    while(T--)    {        read(n),read(m);        for(int i=0; i<n; i++)        {            for(int j=0; j<5; j++)            {                read(a[j][i].val);                a[j][i].id=i;            }        }        for(int i=0; i<5; i++) sort(a[i],a[i]+n);        block_num=sqrt(n+0.0);        per_block=ceil(n/(block_num+0.0));        for(int i=0; i<5; i++)            for(int k=0; k<block_num; k++)                bs[i][k].reset();        for(int i=0; i<5; i++)            for(int j=0; j<n; j++)                bs[i][j/per_block].set(a[i][j].id);        for(int i=0; i<5; i++)            for(int j=0; j<block_num; j++)                if(j)                    bs[i][j]|=bs[i][j-1];        read(q);        int ans=0;        bitset<MAXN> res,tmp;        int d;        while(q--)        {            res.set();            for(int k=0; k<5; k++)            {                tmp.reset();                read(d);                d^=ans;                int index=upper_bound(a[k],a[k]+n,Node(d,n+1))-a[k]-1;                if(index<0)                {                    res.reset();                    continue;                }                if(index / per_block)                    tmp=bs[k][index/per_block-1];                int start=(index / per_block)*per_block;                int end=index;                for(int i=start; i<=end; i++)                    tmp.set(a[k][i].id);                res&=tmp;            }            ans=res.count();            printf("%d\n",ans);        }    }    return 0;}
0 0
原创粉丝点击