結果

問題 No.2404 Vertical Throw Up
ユーザー 👑 amentorimaruamentorimaru
提出日時 2023-07-12 00:44:28
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 2,345 bytes
コンパイル時間 1,089 ms
コンパイル使用メモリ 128,896 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 20:51:27
合計ジャッジ時間 3,059 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 91 ms
5,248 KB
testcase_04 AC 75 ms
5,376 KB
testcase_05 AC 116 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 113 ms
5,376 KB
testcase_08 AC 94 ms
5,376 KB
testcase_09 AC 72 ms
5,376 KB
testcase_10 AC 20 ms
5,376 KB
testcase_11 AC 20 ms
5,376 KB
testcase_12 AC 14 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 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 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <tuple>
#include <numeric>

using namespace std;
using ll = long long;

bool check(ll a1, ll b1, ll a2, ll b2, ll a3, ll b3) {
  ll c = 1e9;
  ll a21 = a2 - a1;
  ll a32 = a3 - a2;
  ll b21 = b2 - b1;
  ll b32 = b3 - b2;
  ll le9 = b32 / c * a21 + b32 % c * a21 / c;
  ll re9 = b21 / c * a32 + b21 % c * a32 / c;
  if (le9 < re9)
    return true;
  if (le9 > re9)
    return false;
  return b32 % c * a21 % c < b21% c* a32% c;
  return (a2 - a1) * (b3 - b2) < (b2 - b1) * (a3 - a2);
}

int main() {
  ll a, q;
  cin >> a >> q;
  set<pair<ll, ll>> ch;
  for (ll qs = 0; qs < q; qs++) {
    ll qq;
    cin >> qq;
    if (qq == 1) {
      ll s, t;
      cin >> s >> t;
      pair<ll, ll> add = make_pair(s + t, - s * t);
      //pair<ll, ll> add = make_pair(s, t);
      auto it = ch.lower_bound(add);
      if (it != ch.begin() && it != ch.end()) {
        auto ita = it;
        ita--;
        if (!check(ita->first, ita->second, add.first, add.second, it->first, it->second)) {
          continue;
        }
      }
      it = ch.insert(add).first;
      while (1) {
        auto it2 = it;
        auto it3 = it;
        it2++;
        it3++;
        if (it2 == ch.end())
          break;
        it3++;
        if (it3 == ch.end())
          break;
        if (check(it->first, it->second, it2->first, it2->second, it3->first, it3->second))
          break;
        ch.erase(it2);
      }
      while (1) {
        auto it2 = it;
        auto it3 = it;
        if (it == ch.begin())
          break;
        it2--;
        it3--;
        if (it2 == ch.begin())
          break;
        it3--;
        if (check(it3->first, it3->second, it2->first, it2->second, it->first, it->second))
          break;
        ch.erase(it2);
      }
    }
    else {
      ll t;
      cin >> t;
      while (!ch.empty()) {
        auto it = ch.begin();
        auto it2 = it;
        it2++;
        if (it2 == ch.end())
          break;
        if (t * it->first + it->second <= t * it2->first + it2->second)
          ch.erase(it);
        else
          break;
      }
      if (ch.empty()) {
        cout << "0\n";
      }
      else {
        auto it = ch.begin();
        ll ans = a * (-t * t + it->first * t + it->second);
        cout << max(ans, 0LL) << "\n";
      }
    }
  }
  return 0;
}
0