답안 #1037889

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1037889 2024-07-29T09:48:47 Z javotaz Party (INOI20_party) C++17
23 / 100
53 ms 448 KB
// In the Name of Allah

#include<bits/stdc++.h>
using namespace std;

#pragma GCC optimize("Ofast,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,avx,avx2,sse4.2,popcnt,tune=native")

typedef long long ll;

#define F first
#define S second
#define pii pair<int, int>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(), x.end()
#define int long long

const int N = 64;

const int mod = 1'000'000'000 + 7;
int ans[N];

ll bp(int x, ll y) {
	if (y < 2) return y? x : 1;
	ll tmp = bp(x, y / 2);
	tmp = tmp * tmp % mod;
	return (y & 1)? tmp * x % mod : tmp;
}

int solve(ll n) {
	ll ans = 0;
	int k = 0;
	for (int i = 0; i < 62; i++)
		if ((1ll << i) - 1 == n)
			k = i;
	ll mk = bp(bp(2, n) - 1, mod - 2);
	for (int i = 0; i < k; i++) {
		vector<ll> v;
		v.pb(1);
		for (int j = 1; j <= 2 * k; ++j) {
			ll cnt = (i + j < k)? (1ll << j) : 0;
			for (int z = i - 1; z >= 0; z--)
				if (j == (i - z))
					cnt++;
				else if (j > (i - z) && z + j - (i - z) < k)
					cnt += (1ll << (j - (i - z) - 1));
			if (!cnt)
				break;
			v.pb(cnt);
		}
		ll c = 1, res = 0;
		for (int j = 1; j < v.size(); ++j) {
			c += v[j];
			res = (res + (bp(2, v[j]) - 1) * bp(2, n - c) % mod * j % mod * mk) % mod;
		}
		ans = (ans + res * ((1ll << i) % mod)) % mod;
	}
	return ans;
}

int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	for (int i = 0; i < 62; i++)
		ans[i] = solve((1ll << i) - 1);
	int t;
	cin >> t;
	while (t--) {
		int x;
		cin >> x;
		cout << ans[__lg(x) + 1] << '\n';
	}
	return 0;
}

Compilation message

Main.cpp: In function 'long long int solve(ll)':
Main.cpp:53:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for (int j = 1; j < v.size(); ++j) {
      |                   ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 49 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 432 KB Output is correct
2 Correct 51 ms 344 KB Output is correct
3 Correct 50 ms 428 KB Output is correct
4 Correct 50 ms 348 KB Output is correct
5 Correct 49 ms 348 KB Output is correct
6 Correct 50 ms 344 KB Output is correct
7 Correct 53 ms 432 KB Output is correct
8 Correct 51 ms 448 KB Output is correct
9 Correct 49 ms 348 KB Output is correct
10 Correct 49 ms 348 KB Output is correct
11 Correct 49 ms 348 KB Output is correct
12 Correct 49 ms 348 KB Output is correct
13 Correct 49 ms 448 KB Output is correct
14 Correct 50 ms 444 KB Output is correct
15 Correct 51 ms 348 KB Output is correct
16 Correct 50 ms 348 KB Output is correct
17 Correct 49 ms 444 KB Output is correct
18 Correct 50 ms 348 KB Output is correct
19 Correct 50 ms 348 KB Output is correct
20 Correct 52 ms 444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 49 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 49 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -