Hihocoder 1236 (2015 Beijing online game j) Sub-block Bitset puzzle

Source: Internet
Author: User
Tags bitset

Main topic:

Each person has five class grades, initially given a portion of the student's grade, and then each time asked to give a student's grade, hoping to know that the number of students in a given pile is lower or equal than the student's per door

Because of the forced request online inquiry, so the title requirements, each time the current given student scores are different or the last answer

First, the students are ranked by each score

Here the students are divided into blocks of sqrt (n), and then the Bitset container is used in the current block to record the state of the student.

Here you can record the status of the prefix and, because better than the results of the previous students will certainly be better

When querying, just find out which one of the students is exactly taller than him, so as long as you visit sqrt (n) times.

Finally, 5 times the answers are done and manipulated.

1#include <bits/stdc++.h>2 using namespacestd;3 #defineN 500014 #definePII pair<int,int>5 intN, M, q, Block;6Bitset<n> bs[5][ -];//record prefixes or values and7PII val[5][n];8 9 voidRead ()Ten { Onescanf"%d%d", &n, &m); A      for(intI=0; I<n; i++){ -          for(intj=0; j<5; J + +){ -scanf"%d", &Val[j][i].first); theVal[j][i].second =i; -         } -     } -      for(intI=0; i<5; i++) sort (val[i], val[i]+n); +  -Block = (int) sqrt (n+0.5); +     intI, J, K, index; A      for(i=0; i<5; i++){ at          for(j=0, index=0; J<n; J+=block, index++){ -             intlast = min (j+block,n); - Bs[i][index].reset (); -              for(k=j; k<last; k++){ -Bs[i][index].Set(Val[i][k].second); -             } in             if(index) Bs[i][index] |= bs[i][index-1]; -           //cout<<i<< "<<j<<" "<<bs[i][index].to_string () <<endl; to         } +     } - } the  * intFind_pos (intKintx) $ {Panax Notoginseng     intL=0, r=n-1, ans=-1; -      while(r>=l) { the         intM= (l+r) >>1; +         if(val[k][m].first<=x) l=m+1, ans=m; A         Elser=m-1; the     } +     returnans; - } $  $Bitset<n> GetStatus (intKintx) - { -     intpos =Find_pos (k, x); theBitset<n>ans; -     if(pos<0)returnAns.reset ();Wuyi     intLen = (pos+1)/Block; the     intSt = block*Len; -     if(len>=1) ans = bs[k][len-1]; Wu     ElseAns.reset (); -      for(inti=st; I<=pos; i++) AboutAns.Set(Val[k][i].second); $     returnans; - } -  - voidquery () A { +     intX, last=0; theBitset<n> ans[5]; -scanf"%d", &q); $      while(q--){ the          for(intI=0; i<5; i++) Ans[i].reset (); the          for(intI=0; i<5; i++){ thescanf"%d", &x); theX ^=Last ; -Ans[i] =GetStatus (i, x); in             if(i) ans[i] &= ans[i-1]; the           //cout<<i<< "<<x<<" "<<ans[i].to_string () <<endl; the         } AboutLast = ans[4].count (); theprintf"%d\n", last); the     } the } +  - intMain () the {Bayi   //freopen ("a.in", "R", stdin); the     intT; thescanf"%d", &T); -      while(t--){ - read (); the query (); the     } the     return 0; the}

Hihocoder 1236 (2015 Beijing online game j) Sub-block Bitset puzzle

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.