結果

問題 No.2404 Vertical Throw Up
ユーザー SSRSSSRS
提出日時 2023-08-04 21:41:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,719 bytes
コンパイル時間 1,913 ms
コンパイル使用メモリ 177,912 KB
実行使用メモリ 7,484 KB
最終ジャッジ日時 2024-04-22 20:03:22
合計ジャッジ時間 3,682 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 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;
const long long INF = 1000000000000000000;
template <typename T>
struct li_chao_tree{
  struct line{
    T a, b;
    line(): a(0), b(INF){
    }
    line(T a, T b): a(a), b(b){
    }
    T get(T x){
      return a * x + b;
    }
  };
  int N;
  vector<T> x;
  vector<line> ST;
  li_chao_tree(){
  }
  li_chao_tree(const vector<T> &x2){
    x = x2;
    sort(x.begin(), x.end());
    int N2 = x.size();
    N = 1;
    while (N < N2){
      N *= 2;
    }
    x.resize(N);
    for (int i = N2; i < N; i++){
      x[i] = x[N2 - 1];
    }
    ST = vector<line>(N * 2 - 1);
  }
  void line_add(line L, int i, int l, int r){
    T la = L.get(x[l]);
    T lb = ST[i].get(x[l]);
    T ra = L.get(x[r - 1]);
    T rb = ST[i].get(x[r - 1]);
    if (la >= lb && ra >= rb){
      return;
    } else if (la <= lb && ra <= rb){
      ST[i] = L;
    } else {
      int m = (l + r) / 2;
      T ma = L.get(x[m]);
      T mb = ST[i].get(x[m]);
      if (ma < mb){
        swap(L, ST[i]);
        swap(la, lb);
        swap(ra, rb);
      }
      if (la < lb){
        line_add(L, i * 2 + 1, l, m);
      }
      if (ra < rb){
        line_add(L, i * 2 + 2, m, r);
      }
    }
  }
  void line_add(T a, T b){
    line_add(line(a, b), 0, 0, N);
  }
  void segment_add(int L, int R, line S, int i, int l, int r){
    if (r <= L || R <= l){
      return;
    } else if (L <= l && r <= R){
      line_add(S, i, l, r);
    } else {
      int m = (l + r) / 2;
      segment_add(L, R, S, i * 2 + 1, l, m);
      segment_add(L, R, S, i * 2 + 2, m, r);
    }
  }
  void segment_add(T l, T r, T a, T b){
    int pl = lower_bound(x.begin(), x.end(), l) - x.begin();
    int pr = lower_bound(x.begin(), x.end(), r) - x.begin();
    segment_add(pl, pr, line(a, b), 0, 0, N);
  }
  T get(T x2){
    int p = lower_bound(x.begin(), x.end(), x2) - x.begin();
    p += N - 1;
    T ans = INF;
    ans = min(ans, ST[p].get(x2));
    while (p > 0){
      p = (p - 1) / 2;
      ans = min(ans, ST[p].get(x2));
    }
    return ans;
  }
};
int main(){
  int a;
  cin >> a;
  int Q;
  cin >> Q;
  vector<int> T(Q);
  vector<int> s(Q), t(Q);
  for (int i = 0; i < Q; i++){
    cin >> T[i];
    if (T[i] == 1){
      cin >> s[i] >> t[i];
    }
    if (T[i] == 2){
      cin >> t[i];
    }
  }
  vector<long long> X;
  for (int i = 0; i < Q; i++){
    if (T[i] == 2){
      X.push_back(i);
    }
  }
  li_chao_tree<long long> LCT(X);
  for (int i = 0; i < Q; i++){
    if (T[i] == 1){
      long long b = s[i] + t[i];
      long long c = (long long) -s[i] * t[i];
      LCT.line_add(-b, -c);
    }
    if (T[i] == 2){
      cout << max((long long) - t[i] * t[i] - LCT.get(t[i]), (long long) 0) * a << endl;
    }
  }
}
0