Links: https://ac.nowcoder.com/acm/contest/887/H
Source: Cattle-off network
Title Description
Given three integers A, B, C. Count the number of pairs <
x ,y> (with 1≤x≤Aand1≤y≤B)
such that at least one of the following is true:
- (x and y) > C
- (x xor y) < C
("and", "xor" are bit operators)
such that at least one of the following is true:
- (x and y) > C
- (x xor y) < C
("and", "xor" are bit operators)
Enter a description:
The first line of the input gives the number of test cases,T(T≤100). T test cases follow.
For each test case, the only line contains three integers A, B and C.
1≤A,B,C≤10^9
Output Description:
For each test case, the only line contains an integer that is the number of pairs satisfying the condition given in the problem statement.
Example 1
Entry
3 3 4 2 4 5 2 7 8 5
Export
5 7 31
Digital dp request x & y <= c && x ^ y> = number c is then cut with all program
details, see Code
#include <bits/stdc++.h> #define ll long long using namespace std; int T,A,B,C; int a[35],b[35],c[35]; ll f[35][2][2][2][2]; void cal(int x,int v[]) { for (int i=0;i<=30;i++) v[i]=(x>>i)&1; } ll dfs(int pos,boolLima, BOOL limb of, BOOL limand, BOOL limxor) // bit <a y<b x&y<cx^y> C X { IF (POS == - . 1 ) return . 1 ; IF (F [POS] [Lima] [limb of] [limand] [limxor] = -! 1 ) return f [POS] [lima] [limb] [limand] [limxor]; int AA = lima A [POS]:? 1 ; // been equal before lima Description = 1 to take this bit <= a, otherwise described before <a disorder can take the current position int BB = limb of B [POS]:? . 1 ; int C1 limand = C [POS]:? . 1 ; //Similarly, if before x & y has been equal to c then the current position to x & y <= c, otherwise you can get messy int c2 = limxor c [POS]:? 0 ; LL & RET = f [POS] [Lima] [limb] [limand] [limxor]; RET = 0 ; for ( int I = 0 ; I <= AA; I ++ ) for ( int J = 0 ; J <= BB; J ++ ) { IF ((I & J)> C1) Continue ; IF (( I ^ J) <C2) Continue ; RET + = DFS (POS- . 1 , Lima && I == AA, limb of && J == BB, limand && (I & J) == C1, limxor && (I ^ J) == C2); } return ret; } int main() { scanf("%d",&T); while(T--) { scanf("%d%d%d",&A,&B,&C); memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); memset(f,-1,sizeof(f)); cal(A,a); cal(B,b); cal(C,c); LL ANS = DFS ( 30 , . 1 , . 1 , . 1 , . 1 ); ANS - = max ( 0 , A-C + . 1 ); ANS - = max ( 0 , B-C + . 1 ); // subtract x, y is 0 the printf ( " % LLD \ n- " , (LL) a * the B- ANS); } return 0 ; }