QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#136810#241. Chiaki Sequence RevisitedOrange_JuiCE#0 391ms3572kbC++201.4kb2023-08-09 11:58:342023-08-09 11:58:37

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-09 11:58:37]
  • 评测
  • 测评结果:0
  • 用时:391ms
  • 内存:3572kb
  • [2023-08-09 11:58:34]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef __int128_t int128;
#define ll long long
#define int ll

int128 read(){
    int128 red=0, f_f=1; char c=getchar();
    while (c<'0'||c>'9'){if (c=='-')f_f=-1;c=getchar();}
    while (c>='0'&&c<='9'){red=(red<<1)+(red<<3)+(c^48);c=getchar();}
    return f_f*red;
}

const int N = 1e5+5;

int128 n, a, r, q;
int128 ans;

int128 calc(int128 x) {
    int128 re = x;
    while(x) {
        x >>= 1ll;
        re += x;
    }
    return re;
}

int128 find(int128 x) {
    int128 l = 1ll, r = 1e18, re = 0;
    while(l <= r) {
        int128 mid = (l+r)>>1ll, cc = calc(mid);
        if(cc == x) return mid;
        if(cc < x) re = mid, l = mid+1;
        else r = mid-1;
    }
    return re;
}

inline void write(int128 x) {
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}

void solve() {
    n = read();
    n--, ans=1, r=1, q=1;
    if(!n) {
        printf("1\n");
        return;
    }
    a = find(n);
    // printf("%lld\n", a);
    // return;
    ans += (n-calc(a))*(a+1);
    // printf("a--%lld %lld\n", a, calc(a));
    while(a) {
        ans += q*r*((a+1)/2)*((a+1)/2);
        r <<= 1ll, a >>= 1ll, q++;
    }
    write(ans);
    printf("\n");
}


signed main() {
    int128 T = read();
    while (T--) {
        solve();
    }
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 391ms
memory: 3572kb

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...

result:

wrong answer 10001st lines differ - expected: '550345233', found: '250000000000000014630611391714623654'