Advertisement
aqibm

randome

Feb 27th, 2025
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. vector<unsigned long long> findOneIndices() {
  2. vector<unsigned long long> result;
  3. unsigned long long L = 1; // assuming 1-indexing
  4. const unsigned long long M = (1ULL << 62) - 1; // size of the array
  5.  
  6. // Continue searching as long as there is at least one '1' from L to M.
  7. while (L <= M && query(L, M) == 1) {
  8. unsigned long long lo = L, hi = M;
  9. // Binary search for the leftmost '1' in the range [L, M].
  10. while (lo < hi) {
  11. unsigned long long mid = lo + (hi - lo) / 2;
  12. if (query(L, mid) == 1) {
  13. hi = mid; // there's a '1' in [L, mid]
  14. } else {
  15. lo = mid + 1;
  16. }
  17. }
  18. // 'lo' is now the index of the leftmost '1'
  19. result.push_back(lo);
  20. L = lo + 1; // Move past this found '1'
  21. }
  22. return result;
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement