QOJ.ac
QOJ
QOJ is currently under a maintenance. It might be unavailable in the following a few hours.
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#947883 | #10010. Kids And Sequence Game | hungry# | WA | 35ms | 5488kb | C++26 | 4.2kb | 2025-03-22 18:01:05 | 2025-03-22 18:01:06 |
Judging History
answer
#include<bits/stdc++.h>
#include<bits/extc++.h>
#define IOS std::ios::sync_with_stdio(false);std::cin.tie(nullptr);std::cout.tie(nullptr);
#define all(x) (x).begin(),(x).end()
#define quchong(x) (x).erase(unique(all(x)),(x).end())
#define Yes(x,y) cout<<((x)?"Yes":"No")<<y
#define yes(x,y) cout<<((x)?"yes":"no")<<y
#define YES(x,y) cout<<((x)?"YES":"NO")<<y
#define ls ((u)<<1)
#define rs ((u)<<1|1)
#define mid (((l)+(r))>>1)
#define lowbit(x) ((x)&(-(x)))
#define itn int
#define asn ans
#define reisze resize
#define pdd pair<double,double>
#define pll pair<LL,LL>
#define pii pair<int,int>
#define tll tuple<LL,LL,LL>
#define tii tuple<int,int,int>
#define plll pair<LLL,LLL>
#define ULL unsigned long long
#define LL long long
#define LLL __int128
#define ld long double
#define ui64 uint64_t
#define ui32 uint32_t
using namespace std;
template<typename T>
T fang(const T& a){
return a*a;
}
template<typename T,typename Q>
bool chmax(T& u1,T& u2,const Q& v){
if(v>u1) { u2 = u1, u1 = v;return true;}
if(v>u2){u2=v;return true;}
return false;
}
template<typename T,typename Q>
bool chmin(T& u1,T& u2,const Q& v){
if(v<u1) { u2 = u1, u1 = v;return true;}
if(v<u2){u2=v;return true;}
return false;
}
template<typename T,typename Q>
bool chmin(T& a,const Q& b){
return a > b && (a = b, true);
}
template<typename T,typename Q>
bool chmax(T& a,const Q& b){
return a<b&&(a=b,true);
}
template<typename t1,typename t2>
istream& operator>>(istream& in,pair<t1,t2>& pa){
in>>pa.first>>pa.second;
return in;
}
template<typename t1,typename t2>
ostream& operator<<(ostream& out,const pair<t1,t2>& pa){
out<<pa.first<<' '<<pa.second;
return out;
}
template<typename T>
istream& operator>>(istream& in,vector<T>& arr){
for(auto& v:arr)in>>v;
return in;
}
template<typename T>
ostream& operator<<(ostream& out,const vector<T>& arr){
for(auto& v:arr)out<<v<<' ';
return out;
}
int rand(int l,int r){
static mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
return uniform_int_distribution<int>(l, r)(rng);
}
const ld eps=1e-9;
const int NN=2e6+5;
const int SIZ=1e7;
const LL inf=1e17;
int pre=0;
int nxt=0;
vector<vector<int>> G;
void calc(LL x){
vector<int> bt;
while(x)bt.emplace_back(x&1),x>>=1;
vector<pii> t;
for(int i:bt){
if(t.empty()||i!=t.back().first)t.emplace_back(i,0);
t.back().second++;
}
vector<int> q;
for(auto [l,r]:t){
if(l==0){
for(int j=0;j<r;j++)q.push_back(0);
}else{
if(r%2){
q.back()=1;
}
}
}
t.clear();
for(int i:q){
if(t.empty()||t.back().first!=i)t.emplace_back(i,0);
t.back().second++;
}
vector<pii> T;
for(auto [l,r]:t){
if(l==0){
if(r%2)T.emplace_back(0,1);
}else{
if(!T.empty()&&T.back().first==1)T.back().second+=r;
else T.emplace_back(l,r);
}
}
if(T.empty())return;
if(T[0].first==0){
T.erase(T.begin());
pre++;
}
if(!T.empty()&&T.back().first==1){
nxt+=T.back().second;
T.pop_back();
}
if(T.empty())return;
G.emplace_back();
for(int i=0;i<T.size();i+=2)G.back().emplace_back(T[i].second);
}
LL getans(){
int n=G.size();
if(G.empty())return -nxt;
priority_queue<pll> q;
for(int i=0;i<n;i++)q.emplace(-G[i][0],i);
vector<int> now(n);
LL ans=0;
int op=0;
while(!q.empty()){
auto it=q.top();q.pop();
if(!op)ans+=it.first;
else ans-=it.first;
now[it.second]++;
if(now[it.second]<G[it.second].size())q.emplace(-G[it.second][now[it.second]],it.second);
op^=1;
}
if(op)ans+=nxt;
else ans-=nxt;
return ans;
}
void solve(){
int n;
cin>>n;
vector<LL> A(n);
cin>>A;
LL pr=0;
for(LL v:A){
while(v&1)v>>=1,pr++;
if(v){
calc(v);
}
}
LL ar=getans();
if(pre%2)ar=-ar;
if(pr%2)ar=1-ar;
cout<<ar;
}
signed main(){
IOS;
int _=1;
while(_--)solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
input:
5 13 29 10 1 26
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: -100
Wrong Answer
time: 35ms
memory: 5488kb
input:
21417 7840302172680170307 5321573529083198387 8214462622877325148 1143008495081213578 6262491513147717806 5039611704168873788 8094944116872031972 2567428672066144766 6056648091050202450 3565740003036766392 2925999037919145749 5542147304038247878 862707825558040953 4471890990246559484 263325942648568...
output:
42498
result:
wrong answer 1st numbers differ - expected: '67086', found: '42498'