結果

問題 No.2404 Vertical Throw Up
ユーザー achapiachapi
提出日時 2023-08-04 22:33:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,255 bytes
コンパイル時間 5,057 ms
コンパイル使用メモリ 256,892 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 20:50:15
合計ジャッジ時間 5,706 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,248 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>
#include <atcoder/all>
using namespace std;

struct ConvexHullTrick{
  std::deque<std::pair<long long, long long> > dq; //(傾き、切片)

  void add(long long a, long long b){
    std::pair<long long, long long> p0=std::make_pair(a, b);
    while(dq.size()>=2){
      int sz=dq.size();
      std::pair<long long, long long> p1=dq[sz-1];
      std::pair<long long, long long> p2=dq[sz-2];
      if((p0.second-p1.second)*(p0.first-p2.first) > (p0.second-p2.second)*(p0.first-p1.first))break;//交点のx座標を比較
      dq.pop_back();
    }
    dq.push_back(p0);
  }

  long long query(long long x){
    while(dq.size()>=2){
      long long v1=dq[0].first*x+dq[0].second;
      long long v2=dq[1].first*x+dq[1].second;
      if(v1>=v2)break;
      dq.pop_front();
    }
    return dq[0].first*x+dq[0].second;
  }

};

int main() {
	long long a;
	cin >> a;
	int Q;
	cin >> Q;
	ConvexHullTrick cht;
	while (Q--){
		int T;
		cin >> T;
		if (T == 1){
			long long s, t;
			cin >> s >> t;
			long long b = a * (t * t - s * s);
			b /= t - s;
			long long c = s * (a * s - b);
			cht.add(b, c);
		}
		if (T == 2){
			long long t;
			cin >> t;
			long long c = cht.query(t) - a * t * t;
			cout << max(0LL, c) << '\n';
		}
	}
}
0