結果

問題 No.2404 Vertical Throw Up
ユーザー 👑 獅子座じゃない人獅子座じゃない人
提出日時 2023-07-11 23:23:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 3,106 bytes
コンパイル時間 2,699 ms
コンパイル使用メモリ 173,184 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 20:50:35
合計ジャッジ時間 4,696 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

class cht {
    private:
    map<long long, long long> lines;
    long long tmax(long long a1, long long b1, long long a2, long long b2){
        assert(a1<a2);
        return (b1-b2)/(a2-a1);
    }
    bool need(long long a1, long long b1, long long a2, long long b2, long long a3, long long b3){
        assert(a1<a2 && a2<a3);
        return tmax(a1,b1,a2,b2)<tmax(a2,b2,a3,b3);
    }
    long long h(long long t, map<long long, long long>::iterator it){
        return it->first*t+it->second;
    }
    public:
    cht(){
        lines[0]=-2e18;
        lines[5e10]=-9e18;
    }
    void add(long long a, long long b){
        auto it_first=lines.begin();
        auto it_last=lines.end();
        --it_last;
        if(lines.count(a)){
            if(lines[a]>b){
                return;
            } else {
                lines.erase(a);
            }
        }
        auto it_next=lines.upper_bound(a);
        auto it_prev=it_next;
        --it_prev;
        if(!need(it_prev->first, it_prev->second, a, b, it_next->first, it_next->second)){
            return;
        }
        lines[a]=b;
        auto it=lines.find(a);
        auto it_n1=it;
        auto it_n2=it;
        if(it!=it_last){
            ++it_n1;
            ++it_n2;
            if(it_n1!=it_last){
                ++it_n2;
                while(!need(it->first, it->second, it_n1->first, it_n1->second, it_n2->first, it_n2->second)){
                    auto it_tmp=it_n2;
                    lines.erase(it_n1);
                    if(it_n2==it_last){
                        break;
                    } else {
                        it_n1=it_tmp;
                        ++it_n2;
                    }
                }
            }
        }
        auto it_p1=it;
        auto it_p2=it;
        if(it!=it_first){
            --it_p1;
            --it_p2;
            if(it_p1!=it_first){
                --it_p2;
                while(!need(it_p2->first, it_p2->second, it_p1->first, it_p1->second, it->first, it->second)){
                    auto it_tmp=it_p2;
                    lines.erase(it_p1);
                    if(it_p2==it_first){
                        break;
                    } else {
                        it_p1=it_tmp;
                        --it_p2;
                    }
                }
            }
        }
    }
    long long max(long long t){
        auto it=lines.begin();
        ++it;
        auto it_next=it;
        ++it_next;
        while(h(t,it)<h(t,it_next)){
            auto it_tmp=it_next;
            lines.erase(it);
            ++it_next;
            it=it_tmp;
        }
        return h(t,it);
    }
};

int main(void)
{
    int a;
    cin >> a;
    int q;
    cin >> q;
    cht l;
    while(q--){
        int e;
        cin >> e;
        if(e==1){
            long long s,t;
            cin >> s >> t;
            l.add(a*(s+t),-a*s*t);
        } else {
            long long t;
            cin >> t;
            long long lmax=l.max(t);
            cout << max(lmax-a*t*t,0LL) << endl;
        }
    }
    return 0;
}
0