QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#137027 | #241. Chiaki Sequence Revisited | pssxx | 0 | 0ms | 0kb | C++23 | 2.1kb | 2023-08-09 17:00:02 | 2023-08-09 17:00:02 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mem(a,b) memset((a),(b),sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
#define int long long
#define db long double
const double eps = 1e-6;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
int a[maxn], pow2[100];
int lowbit(int x) {
return x & (-x);
}
int qpow(int base, int pow) {
int ans = 1;
while(pow) {
if(pow & 1) ans = ans * base % mod;
base = base * base % mod;
pow >>= 1;
}
return ans;
}
void init() {
pow2[0] = 1;
for(int i = 1; i <= 63; i++) {
pow2[i] = pow2[i - 1] * 2;
}
}
int n, ans;
int cnt[100];
int pos = 0;
bool check(int x) {
int now = 1, pre = 0;
for (int i = pos; i >= 0; i--) {
cnt[i] = (x / pow2[i] - pre);
now += (i + 1) * (x / pow2[i] - pre);
pre += cnt[i];
}
if (now >= n) {
return false;
} else {
return true;
}
}
void solve() {
cin >> n;
int l = 1, r = n;
pos = 0;
int now = n;
while(now != 0) {
pos++;
now /= 2;
}
while (l <= r) {
int mid = (l + r) >> 1;
if (check(mid)) {
l = mid + 1;
} else {
r = mid - 1;
}
}
int an = l - 1;
int ans = 1;
int pre = 1;
int inv = (1e9 + 8) / 2;
for(int i = 0; i <= pos; i++) {
int cnt1 = 0;
if(pos != 63) cnt1 = (an + 1) / pow2[i] - (an + 1) / pow2[i + 1];
else cnt1 = (an + 1) / pow2[i];
int beg = pow2[i] % mod;
int end = (((cnt1 - 1) % mod * pow2[i] * 2 % mod) % mod + pow2[i]) % mod;
ans = (ans + (i + 1) % mod * ((beg + end) % mod * cnt1 % mod * inv % mod) % mod) % mod;
pre += cnt1 * (i + 1);
}
ans = (ans - ((pre - n) * ((an + 1) % mod)) % mod + mod) % mod;
cout << ans << '\n';
}
signed main(){
io;
init();
int T = 1;
// T = read();
cin >> T;
while(T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
100000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
1 2 4 6 9 13 17 21 26 32 38 45 53 61 69 77 86 96 106 117 129 141 153 166 180 194 209 225 241 257 273 289 306 324 342 361 381 401 421 442 464 486 509 533 557 581 605 630 656 682 709 737 765 793 822 852 882 913 945 977 1009 1041 1073 1105 1138 1172 1206 1241 1277 1313 1349 1386 1424 1462 1501 1541 158...