結果

問題 No.2404 Vertical Throw Up
ユーザー HaaHaa
提出日時 2023-08-04 22:52:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,537 bytes
コンパイル時間 1,970 ms
コンパイル使用メモリ 172,860 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-22 21:12:53
合計ジャッジ時間 3,713 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T& x, const T& y){return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T& x, const T& y){return (x>y)?(x=y,true):false;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

int main(){
    ll a; cin >> a;
    int q; cin >> q;
    int idx=0;
    vector<P> bc;
    set<P> st;
    ll r, s, t;
    REP(_,q){
        cin >> r;
        if(r==1){
            cin >> s >> t;
            ll x=-a*s*s, y=-a*t*t;
            ll b=(x-y)/(t-s);
            ll c=-(x+b*s);
            bc.push_back({b,c});
            if(st.empty()){
                st.insert({s+t,idx});
                idx++;
                continue;
            }
            auto it=st.lower_bound({s+t,0});
            bool ok=0;
            if(it!=st.end()){
                int i=(*it).second;
                ll ib=bc[i].first, ic=bc[i].second;
                ll m=(s+t)/2;
                ll h=-a*m*m+b*m+c;
                ll ih=-a*m*m+ib*m+ic;
                if(h>ih)
                    ok=1;
            }
            if(it!=st.begin()){
                int i=(*prev(it)).second;
                ll ib=bc[i].first, ic=bc[i].second;
                ll m=(s+t+1)/2;
                ll h=-a*m*m+b*m+c;
                ll ih=-a*m*m+ib*m+ic;
                if(h>ih)
                    ok=1;
            }
            if(ok){
                it=st.lower_bound({s+t,0});
                while(it!=st.end()){
                    int i=(*it).second;
                    ll ib=bc[i].first, ic=bc[i].second;
                    ll m=(s+t)/2;
                    ll h=-a*m*m+b*m+c;
                    ll ih=-a*m*m+ib*m+ic;
                    it++;
                    if(h>ih)
                        st.erase(prev(it));
                    else
                        break;
                }
                it=st.lower_bound({s+t,0});
                if(!(st.empty()||it==st.begin())){
                    it--;
                    while(1){
                        int i=(*it).second;
                        ll ib=bc[i].first, ic=bc[i].second;
                        ll m=(s+t+1)/2;
                        ll h=-a*m*m+b*m+c;
                        ll ih=-a*m*m+ib*m+ic;
                        if(it==st.begin()){
                            if(h>ih)
                                st.erase(it);
                            break;
                        }
                        else{
                            it--;
                            if(h>ih)
                                st.erase(next(it));
                            else
                                break;
                        }
                    }
                }
                st.insert({s+t,idx});
            }
            idx++;
        }
        else{
            cin >> t;
            auto it=st.lower_bound({t+t,0});
            ll ans=0;
            if(it!=st.end()){
                int i=(*it).second;
                ll ib=bc[i].first, ic=bc[i].second;
                ll ih=-a*t*t+ib*t+ic;
                chmax(ans,ih);
            }
            if(it!=st.begin()){
                int i=(*prev(it)).second;
                ll ib=bc[i].first, ic=bc[i].second;
                ll ih=-a*t*t+ib*t+ic;
                chmax(ans,ih);
            }
            cout << ans << endl;
        }
    }
    return 0;
}
0