LuoguP5390 [Cnoi2019]数学作业(数论)

2022-10-15,,,

转进制,然后发现贡献只有\(1_{(2)}\),取奇数个的子集方案是\(2^{n-1}\)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++a)
#define nR(a,b,c) for(register int a = (b); a >= (c); --a)
#define Fill(a,b) memset(a, b, sizeof(a))
#define Swap(a,b) ((a) ^= (b) ^= (a) ^= (b))
#define QWQ
#ifdef QWQ
#define D_e_Line printf("\n---------------\n")
#define D_e(x) cout << (#x) << " : " << x << "\n"
#define Pause() system("pause")
#define FileOpen() freopen("in.txt", "r", stdin)
#define FileSave() freopen("out.txt", "w", stdout)
#define TIME() fprintf(stderr, "\nTIME : %.3lfms\n", clock() * 1000.0 / CLOCKS_PER_SEC)
#else
#define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ;
#define FileSave() ;
#define TIME() ;
#endif
struct ios {
template<typename ATP> inline ios& operator >> (ATP &x) {
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <='9') x = x * 10 + (c ^ '0'), c = getchar();
x *= f;
return *this;
}
}io;
using namespace std;
template<typename ATP> inline ATP Max(ATP a, ATP b) {
return a > b ? a : b;
}
template<typename ATP> inline ATP Min(ATP a, ATP b) {
return a < b ? a : b;
}
template<typename ATP> inline ATP Abs(ATP a) {
return a < 0 ? -a : a;
} const int mod = 998244353; long long mul(long long a, long long b) {
long long l = a * (b >> 25ll) % mod * (1ll << 25) % mod;
long long r = a * (b & ((1ll << 25) - 1)) % mod;
return (l + r) % mod;
}
inline long long Pow(int a, long long b) {
long long s = 1;
while(b){
if(b & 1) s = mul(s, a);//s * a % mod;
a = mul(a, a), b >>= 1;//a = a * a % mod, b >>= 1;
}
return s;
}
int main() {
int Tasks;
io >> Tasks;
while(Tasks--){
int n;
io >> n;
long long ans = 0;
R(i,1,n){
int x;
io >> x;
ans |= x;
}
printf("%lld\n", ans * Pow(2, n - 1) % mod); }
return 0;
}

LuoguP5390 [Cnoi2019]数学作业(数论)的相关教程结束。

《LuoguP5390 [Cnoi2019]数学作业(数论).doc》

下载本文的Word格式文档,以方便收藏与打印。