AtCoder Beginner Contest 424

D - 2x2 Erasing 2

状压

E - Cut in Half

暴力,O(nlogK)

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define pii pair<int,int>
#define ll long long
#define pb push_back
#define ft first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define int long long
#define pdi pair<double,int>
int n,k,x;
double a[100010];
/*

*/
void solve(){
cin>>n>>k>>x;

priority_queue<pdi,vector<pdi>> pq;
for(int i=1;i<=n;i++){cin>>a[i];pq.push({a[i],1});}
int cur=0;
while(!pq.empty()){
    auto [v,c]=pq.top();pq.pop();
    if(cur+c>=k){
        int t=cur+c-k;
        pq.push({v/2,(c-t)*2});pq.push({v,t});
        break;
    }cur+=c;
    pq.push({v/2,c*2});
}

int cnt=0;
while(!pq.empty()){
auto [v,c]=pq.top();pq.pop();
if(cnt+c>=x){
    cout<<fixed<<setprecision(10)<<v<<'\n';return ;
}
cnt+=c;
}
}
signed main(){
    std::ios::sync_with_stdio(false);
    int T=1;cin>>T;
    while(T--){
        solve();
    }
}

AT_abc424_f [ABC424F] Adding Chords

给区间左端点+t,右端点-t,如果区间和为0,就可以
t随机化
1.为什么是%1e6?肯定得>3e5,再算冲突概率

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define pii pair<int,int>
#define ll long long
#define pb push_back
#define ft first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define int long long
int n,q;
int tr[1000010];
int lowbit(int x){return x&(-x);}
void add(int x,int k){
    for(int i=x;i<=n;i+=lowbit(i))tr[i]+=k;
}
int sum(int x){
    int res=0;for(int i=x;i>0;i-=lowbit(i))res+=tr[i];return res;
}
void solve(){
cin>>n>>q;
    mt19937_64 num(time(0));

    while(q--){
        int x,y;cin>>x>>y;
        if(x>y){
            swap(x,y);
        }
        
        if(sum(y)-sum(x-1)!=0){
            no;
        }else {
            yes;
            int t=num()%1000000;
            add(x,t);add(y,-t);
        }
    }

}
signed main(){
    std::ios::sync_with_stdio(false);
    int T=1;
    while(T--){
        solve();
    }
}
posted @ 2025-10-29 22:48  arin876  阅读(5)  评论(0)    收藏  举报