結果
問題 | No.2939 Sigma Popcount Problem |
ユーザー |
|
提出日時 | 2024-12-11 01:17:42 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 293 ms / 2,000 ms |
コード長 | 1,117 bytes |
コンパイル時間 | 1,611 ms |
コンパイル使用メモリ | 164,496 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-11 01:17:48 |
合計ジャッジ時間 | 5,439 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdint> #include <cstring> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> int main() { int t; std::cin >> t; while (t--) { long long n; std::cin >> n; int maxBits = 60; std::vector<long long> bitCounts(maxBits, 0); for (int i = 0; i < maxBits; i++) { long long blockSize = (1LL << (i + 1)); // 2^(i+1) long long fullBlocks = n / blockSize; long long remainder = n % blockSize; long long count = fullBlocks * (1LL << i); long long limit = (1LL << i); if (remainder >= limit) { count += (remainder - limit + 1); // 0 based, so + 1 } bitCounts[i] = count; } long long result = std::accumulate(bitCounts.begin(), bitCounts.end(), 0LL); std::cout << result << '\n'; } }