Created
May 6, 2013 16:08
-
-
Save jamiees2/5526109 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cmath> | |
#include <cstdio> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
#include <map> | |
using namespace std; | |
int count(unsigned int u) | |
{ | |
unsigned int uCount; | |
uCount = u - ((u >> 1) & 033333333333) - ((u >> 2) & 011111111111); | |
return ((uCount + (uCount >> 3)) & 030707070707) % 63; | |
} | |
void complement(int a, int b){ | |
static map<int,unsigned int> memo; | |
long total = 0; | |
for(int i = a; i <= b;++i){ | |
if(memo.count(i)>0){ | |
total += memo[i]; | |
} | |
else | |
{ | |
memo[i] = count(i); | |
total += memo[i]; | |
} | |
} | |
cout << total << endl; | |
} | |
int main() { | |
/* Enter your code here. Read input from STDIN. Print output to STDOUT */ | |
cin.sync_with_stdio(false); | |
int _ar_size; | |
cin >> _ar_size; | |
for(int _ar_i=0; _ar_i<_ar_size; _ar_i++) { | |
int a, b; | |
cin >> a >> b; | |
complement(a,b); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment