結果
| 問題 |
No.2067 ±2^k operations
|
| コンテスト | |
| ユーザー |
Rubikun
|
| 提出日時 | 2022-09-02 23:18:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 2,000 ms |
| コード長 | 2,701 bytes |
| コンパイル時間 | 1,819 ms |
| コンパイル使用メモリ | 197,336 KB |
| 最終ジャッジ日時 | 2025-02-07 01:52:39 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;
// floor_sum
// from: https://gist.github.com/yosupo06/ddd51afb727600fd95d9d8ad6c3c80c9
// (based on AtCoder STL)
constexpr long long safe_mod(long long x, long long m) {
x %= m;
if (x < 0) x += m;
return x;
}
unsigned long long floor_sum_unsigned(unsigned long long n,
unsigned long long m,
unsigned long long a,
unsigned long long b) {
unsigned long long ans = 0;
while (true) {
if (a >= m) {
ans += n * (n - 1) / 2 * (a / m);
a %= m;
}
if (b >= m) {
ans += n * (b / m);
b %= m;
}
unsigned long long y_max = a * n + b;
if (y_max < m) break;
n = (unsigned long long)(y_max / m);
b = (unsigned long long)(y_max % m);
std::swap(m, a);
}
return ans;
}
long long floor_sum(long long n, long long m, long long a, long long b) {
assert(0 <= n && n < (1LL << 32));
assert(1 <= m && m < (1LL << 32));
unsigned long long ans = 0;
if (a < 0) {
unsigned long long a2 = safe_mod(a, m);
ans -= 1ULL * n * (n - 1) / 2 * ((a2 - a) / m);
a = a2;
}
if (b < 0) {
unsigned long long b2 = safe_mod(b, m);
ans -= 1ULL * n * ((b2 - b) / m);
b = b2;
}
return ans + floor_sum_unsigned(n, m, a, b);
}
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int QQ;cin>>QQ;
vector<ll> A={2,4,8},L={1,2,3},R={1,2,5};
for(int i=0;i<59;i++){
A.push_back(A.back()*2);
L.push_back(R.back()+1);
if(i%2==0){
R.push_back(R.back()*2);
}else{
R.push_back(R.back()*2+1);
}
}
//for(int i=0;i<si(A);i++) cout<<A[i]<<" "<<L[i]<<" "<<R[i]<<endl;
while(QQ--){
ll N;cin>>N;
ll ans=0;
for(int t=0;t<si(A);t++){
if(N<L[t]) break;
ll rem=N-L[t];
ans+=((rem+1)/A[t])*(R[t]-L[t]+1);
rem++;
rem%=A[t];
ans+=min(rem,R[t]-L[t]+1);
//cout<<ans<<" ";
}
cout<<ans<<"\n";
}
}
Rubikun