求助 ABC E
  • 板块学术版
  • 楼主ShunpowerSHUN理成张
  • 当前回复9
  • 已保存回复9
  • 发布时间2023/9/9 21:49
  • 上次更新2023/11/2 21:46:09
查看原帖
求助 ABC E
399150
ShunpowerSHUN理成张楼主2023/9/9 21:49

不是很懂整体二分为什么复杂度不对。一直 TLE 一车,最后五分钟翻盘失败。

求问顺便 How E。

代码(有点急所以比较丑):

//Author:Leftist_G / Shunpower
//Spade Su & Xiao Bao
//Hey Left
//Just enjoy the loneliness
//Open a personal party always stay
#include <bits/stdc++.h>
#define ET return 0
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define ll long long
#define ull unsigned long long
#define inf INT_MAX
#define uinf INT_MIN
#define pii pair<int,int>
#define pll pair<ll,ll>
#define debug puts("--------Chery AK IOI--------");
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define pt puts("")
#define fr1(i,a,b) for(int i=a;i<=b;i++)
#define fr2(i,a,b) for(int i=a;i>=b;i--)
#define fv(i,p) for(int i=0;i<p.size();i++)
#define ld long double
#define il inline
#define ptc putchar
#define int ll
using namespace std;
const int N=1e5+10;
namespace Shun{
    int lowbit(int x){
        return x&-x;
    }
    template <typename T>
    inline void read(T &x){
       T s=0,w=1;
       char ch=getchar();
       while(ch<'0'||ch>'9'){
            if(ch=='-'){
                w=-1;
            }
            ch=getchar();
        }
       while(ch>='0'&&ch<='9'){
            s=s*10+ch-'0';
            ch=getchar();
       }
       x=s*w;
    }
    template <typename T>
    inline void write(T x){
        if(x<0){
            putchar('-');
            x=-x;
        }
        if(x>9){
            write(x/10);
        }
        putchar(x%10+'0');
    }
}
using namespace Shun;
int n,x,y;
int q;
pii bus[N];
vector <pii> query;
ll ans[N<<1];
void binary(vector <pii> p,ll l,ll r){
    if(!p.size()||l>r){
        return;
    }
    if(l==r){
        fv(i,p){
            // cout<<p[i].fi<<" "<<l<<endl;
            ans[p[i].se]=1ll*l*bus[n].fi+bus[n].se+y;
        }
        return;
    }
    ll mid=(l+r)>>1;
    ll fn=1ll*mid*bus[n].fi;
    // fn-=y;
    // cout<<fn<<"!"<<endl;
    fr2(i,n-1,2){
        fn-=(fn-bus[i].se)%bus[i].fi;
        fn-=bus[i].se;
        // cout<<fn<<endl;
        if(fn<0){
            break;
        }
    }
    fn-=x;
    // cout<<"!"<<fn<<" "<<l<<" "<<r<<endl;
    // system("pause");
    vector <pii> p1,p2;
    fv(i,p){
        if(p[i].fi<=fn){
            p1.pb(p[i]);
        }
        else{
            p2.pb(p[i]);
        }
    }
    binary(p1,l,mid);
    binary(p2,mid+1,r);
}
signed main(){
    ios::sync_with_stdio(false);
    cin>>n>>x>>y;
    fr1(i,2,n){
        cin>>bus[i].fi>>bus[i].se;
    }
    cin>>q;
    fr1(i,1,q){
        int u;
        cin>>u;
        query.pb(mp(u,i));
    }
    binary(query,1,1e15);
    fr1(i,1,q){
        cout<<ans[i]<<'\n';
    }
    ET;
}
//ETERNAL LOVE FOR Zhang Junhao, Mu Zhicheng and Zuo Hang.
//ALL FOR Zhang Junhao.
2023/9/9 21:49
加载中...