众所周知,异或是不进位的加法,也就是\(a^b\le a+b\).
所以要最大化答案就全加起来好了.\(Code:\)
#include#include #include #define rint read #define int long longtemplate < class T > inline T read () { T x = 0 , f = 1 ; char ch = getchar () ; while ( ch < '0' || ch > '9' ) { if ( ch == '-' ) f = - 1 ; ch = getchar () ; } while ( ch >= '0' && ch <= '9' ) { x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ; ch = getchar () ; } return f * x ; }const int N = 1e6 + 100 ;int n , ans ;signed main () { n = rint () ; for (int i = 1 ; i <= n ; ++ i) ans += rint () ; printf ("%lld\n" , ans ) ; return 0 ;}