QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#826748#4283. Power of XORZi_GaoWA 1ms5636kbC++204.5kb2024-12-22 15:51:432024-12-22 15:51:43

Judging History

你现在查看的是最新测评结果

  • [2024-12-22 15:51:43]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5636kb
  • [2024-12-22 15:51:43]
  • 提交

answer

#include<bits/stdc++.h>
// #define ONLINE_JUDGE
#define INPUT_DATA_TYPE int
#define OUTPUT_DATA_TYPE int
inline __attribute((always_inline)) INPUT_DATA_TYPE read(){register INPUT_DATA_TYPE x=0;register char f=0,c=getchar();while(c<'0'||'9'<c)f=(c=='-'),c=getchar();while('0'<=c&&c<='9')x=(x<<3)+(x<<1)+(c&15),c=getchar();return f?-x:x;}void print(OUTPUT_DATA_TYPE x){if(x<0)x=-x,putchar('-');if(x>9)print(x/10);putchar(x%10^48);return;}

template <uint32_t mod>
struct LazyMontgomeryModInt {
  using mint = LazyMontgomeryModInt;
  using i32 = int32_t;
  using u32 = uint32_t;
  using u64 = uint64_t;

  static constexpr u32 get_r() {
    u32 ret = mod;
    for (i32 i = 0; i < 4; ++i) ret *= 2 - mod * ret;
    return ret;
  }

  static constexpr u32 r = get_r();
  static constexpr u32 n2 = -u64(mod) % mod;
  static_assert(mod < (1 << 30), "invalid, mod >= 2 ^ 30");
  static_assert((mod & 1) == 1, "invalid, mod % 2 == 0");
  static_assert(r * mod == 1, "this code has bugs.");

  u32 a;

  constexpr LazyMontgomeryModInt() : a(0) {}
  constexpr LazyMontgomeryModInt(const int64_t &b)
      : a(reduce(u64(b % mod + mod) * n2)){};

  static constexpr u32 reduce(const u64 &b) {
    return (b + u64(u32(b) * u32(-r)) * mod) >> 32;
  }

  constexpr mint &operator+=(const mint &b) {
    if (i32(a += b.a - 2 * mod) < 0) a += 2 * mod;
    return *this;
  }

  constexpr mint &operator-=(const mint &b) {
    if (i32(a -= b.a) < 0) a += 2 * mod;
    return *this;
  }

  constexpr mint &operator*=(const mint &b) {
    a = reduce(u64(a) * b.a);
    return *this;
  }

  constexpr mint &operator/=(const mint &b) {
    *this *= b.inverse();
    return *this;
  }

  constexpr mint operator+(const mint &b) const { return mint(*this) += b; }
  constexpr mint operator-(const mint &b) const { return mint(*this) -= b; }
  constexpr mint operator*(const mint &b) const { return mint(*this) *= b; }
  constexpr mint operator/(const mint &b) const { return mint(*this) /= b; }
  constexpr bool operator==(const mint &b) const {
    return (a >= mod ? a - mod : a) == (b.a >= mod ? b.a - mod : b.a);
  }
  constexpr bool operator!=(const mint &b) const {
    return (a >= mod ? a - mod : a) != (b.a >= mod ? b.a - mod : b.a);
  }
  constexpr mint operator-() const { return mint() - mint(*this); }
  constexpr mint operator+() const { return mint(*this); }

  constexpr mint pow(u64 n) const {
    mint ret(1), mul(*this);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  constexpr mint inverse() const {
    int x = get(), y = mod, u = 1, v = 0, t = 0, tmp = 0;
    while (y > 0) {
      t = x / y;
      x -= t * y, u -= t * v;
      tmp = x, x = y, y = tmp;
      tmp = u, u = v, v = tmp;
    }
    return mint{u};
  }

  constexpr u32 get() const {
    u32 ret = reduce(a);
    return ret >= mod ? ret - mod : ret;
  }

  static constexpr u32 get_mod() { return mod; }
};

using mint=LazyMontgomeryModInt<1000'000'007>;

const int W=44;

mint pw2=1;

struct LBASE{
	long long p[W];
	void insert(long long x){
		register int i;
		for(i=W-1;~i;--i) if((x>>i)&1){
			if(p[i]) x^=p[i];
			else return p[i]=x,void();
		}
		pw2*=2;
	}
	void solve(){
		register int i,j;
		for(i=0;i<W;++i) if(p[i]) for(j=i+1;j<W;++j) if((p[j]>>i)&1) p[j]^=p[i];
	}
}lb;

const int Bs=17;
const int Bb=W-Bs;

int pos[W];
long long val[1<<Bs],num[Bb];

mint pw[W],dp[Bb][1<<Bs];

int main(){
	#ifndef ONLINE_JUDGE
	freopen("name.in", "r", stdin);
	freopen("name.out", "w", stdout);
	#endif

    register int i,j,cnt=0,s,maxs,ctz;
	register mint res=0;
    int n=read();
    int k=read();

	for(i=1;i<W;++i) pw[i]=mint(i).pow(k);

	for(i=1;i<=n;++i)
		lb.insert(read());

	for(i=0;i<W;++i) if(lb.p[i]) pos[cnt++]=i;

	if(cnt<=Bs){
		maxs=1<<cnt;
		for(s=1;s<maxs;++s){
			ctz=__builtin_ctz(s);
			val[s]=val[s^(1<<ctz)]^lb.p[pos[ctz]];
			res+=pw[__builtin_popcountll(val[s])];
		}
	}else{
		for(i=0;i<cnt;++i){
			num[i]=lb.p[pos[i]];
			for(j=i-1;~j;--j) num[i]|=(num[i]>>(pos[j]+1))<<pos[j];
		}
		maxs=1<<(W-cnt);
		dp[0][0]=1;
		for(i=0;i<cnt;++i){
			for(s=0;s<maxs;++s){
				for(j=0;j<i;++j){
					dp[j+1][s^val[i]]+=dp[j][s];
				}
			}
		}
		for(i=1;i<=cnt;++i)
			for(s=0;s<maxs;++s)
				res+=dp[i][s]*(i+__builtin_popcountll(s));
	}

	print((res*pw2).get());

	#ifndef ONLINE_JUDGE
	fclose(stdin);
	fclose(stdout);
	#endif
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 5516kb

input:

3 2
1 2 3

output:

12

result:

ok 1 number(s): "12"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5636kb

input:

2 1000000000
1 2

output:

140625003

result:

ok 1 number(s): "140625003"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

3 4
21 31 15

output:

1076

result:

ok 1 number(s): "1076"

Test #4:

score: 0
Accepted
time: 0ms
memory: 5624kb

input:

4 10
21 16 23 30

output:

3504120

result:

ok 1 number(s): "3504120"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

5 795325759
23 18 18 15 24

output:

398580583

result:

ok 1 number(s): "398580583"

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 3600kb

input:

6 425010546
15190825693299 11021868218180 10853490476696 16489831131502 15731786397897 1859285400474

output:

192394777

result:

wrong answer 1st numbers differ - expected: '226806798', found: '192394777'