Submission #940892

# Submission time Handle Problem Language Result Execution time Memory
940892 2024-03-08T01:19:24 Z LittleOrange Collecting Stamps 3 (JOI20_ho_t3) C++17
0 / 100
0 ms 348 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
struct BIT{
    ll n;
    vector<ll> a;
    BIT(ll N):n(N),a(N+1,0){}
    void add(ll i, ll v){
        for(;i<=n;i+=i&-i) a[i] += v;
    }
    ll get(ll i){
        ll r = 0;
        for(;i;i-=i&-i) r += a[i];
        return r;
    }
    ll get(ll l, ll r){
        if(l>r) return 0;
        return get(r)-get(l-1);
    }
};
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    ll n,l;
    cin >> n >> l;
    vector<ll> x(n),t(n);
    for(ll &i : x) cin >> i;
    for(ll &i : t) cin >> i;
    vector<ll> rx(n),rt(n);
    for(ll i = 0;i<n;i++){
        rx[i] = l-x[n-1-i];
        rt[i] = t[n-1-i];
    }
    vector<ll> xs;
    for(ll i = 0;i<n;i++){
        if(t[i]>=x[i]) xs.push_back(t[i]-x[i]);
        if(rt[i]>=rx[i]) xs.push_back(rt[i]-rx[i]);
        xs.push_back(x[i]*2);
        xs.push_back(rx[i]*2);
    }
    sort(xs.begin(),xs.end());
    xs.erase(unique(xs.begin(),xs.end()),xs.end());
    ll sz = xs.size();
    //for(ll i = 0;i<n;i++) cout << rx[i] << " \n"[i+1==n];
    //for(ll i = 0;i<n;i++) cout << rt[i] << " \n"[i+1==n];
    ll ans = 0;
    for(ll zz = 0;zz<2;zz++){
        ll cur = 0;
        for(ll i = 0;i<n;i++) if(t[i]>=x[i]) cur++;
        ans = max(ans,cur);
        BIT tr(sz);
        for(ll i = n-1;i>=0;i--){
            ll qur = lower_bound(xs.begin(),xs.end(),x[i]*2)-xs.begin()+1;
            ans = max(ans,cur+tr.get(qur,sz));
            //cout << i << " " << cur << " " << tr.get(qur,sz) << "\n";
            if(t[i]>=x[i]) cur--;
            if(rt[n-1-i]>=rx[n-1-i]) {
                ll pos = rt[n-1-i]-rx[n-1-i];
                tr.add(lower_bound(xs.begin(),xs.end(),pos)-xs.begin()+1,1);
            }
        }
        x.swap(rx);
        t.swap(rt);
        //cout << "reverse\n";
    }
    cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -