結果
問題 | No.2404 Vertical Throw Up |
ユーザー | siro53 |
提出日時 | 2023-08-05 01:30:06 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 81 ms / 2,000 ms |
コード長 | 6,137 bytes |
コンパイル時間 | 2,726 ms |
コンパイル使用メモリ | 218,028 KB |
実行使用メモリ | 8,092 KB |
最終ジャッジ日時 | 2024-10-14 23:18:34 |
合計ジャッジ時間 | 4,347 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 64 ms
6,272 KB |
testcase_04 | AC | 53 ms
6,016 KB |
testcase_05 | AC | 81 ms
8,092 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 81 ms
7,992 KB |
testcase_08 | AC | 64 ms
6,548 KB |
testcase_09 | AC | 50 ms
5,856 KB |
testcase_10 | AC | 15 ms
5,248 KB |
testcase_11 | AC | 15 ms
5,248 KB |
testcase_12 | AC | 11 ms
5,248 KB |
testcase_13 | AC | 2 ms
5,248 KB |
testcase_14 | AC | 3 ms
5,248 KB |
testcase_15 | AC | 3 ms
5,248 KB |
testcase_16 | AC | 2 ms
5,248 KB |
testcase_17 | AC | 2 ms
5,248 KB |
testcase_18 | AC | 3 ms
5,248 KB |
testcase_19 | AC | 3 ms
5,248 KB |
testcase_20 | AC | 2 ms
5,248 KB |
testcase_21 | AC | 3 ms
5,248 KB |
testcase_22 | AC | 2 ms
5,248 KB |
testcase_23 | AC | 2 ms
5,248 KB |
testcase_24 | AC | 3 ms
5,248 KB |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | AC | 3 ms
5,248 KB |
testcase_27 | AC | 2 ms
5,248 KB |
testcase_28 | AC | 2 ms
5,248 KB |
testcase_29 | AC | 2 ms
5,248 KB |
testcase_30 | AC | 2 ms
5,248 KB |
testcase_31 | AC | 2 ms
5,248 KB |
testcase_32 | AC | 2 ms
5,248 KB |
ソースコード
#line 1 "combined.cpp" #pragma region Macros #include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; } #ifdef DEBUG template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; for(int i = 0; i < (int)v.size(); i++) { if(i) { os << ','; } os << v[i]; } os << '}'; return os; } void debugg() { cerr << endl; } template <class T, class... Args> void debugg(const T &x, const Args &... args) { cerr << " " << x; debugg(args...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif struct Setup { Setup() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } __Setup; using ll = long long; #define OVERLOAD3(_1, _2, _3, name, ...) name #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define REP1(i, n) for(int i = 0; i < int(n); i++) #define REP2(i, a, b) for(int i = (a); i < int(b); i++) #define REP(...) OVERLOAD3(__VA_ARGS__, REP2, REP1)(__VA_ARGS__) #define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end()) #define REVERSE(v) reverse(ALL(v)) #define SZ(v) ((int)(v).size()) const int INF = 1 << 30; const ll LLINF = 1LL << 60; constexpr int MOD = 1000000007; constexpr int MOD2 = 998244353; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; void Case(int i) { cout << "Case #" << i << ": "; } int popcount(int x) { return __builtin_popcount(x); } ll popcount(ll x) { return __builtin_popcountll(x); } #pragma endregion Macros #line 2 "/Users/siro53/kyo-pro/compro_library/data-structure/segtree/li-chao-tree.hpp" #line 7 "/Users/siro53/kyo-pro/compro_library/data-structure/segtree/li-chao-tree.hpp" template <typename T, T inf> class LiChaoTree { public: LiChaoTree() = default; explicit LiChaoTree(const std::vector<T>& x): xs(x) { std::sort(xs.begin(), xs.end()); xs.erase(std::unique(xs.begin(), xs.end()), xs.end()); n = (int)xs.size(); sz = 1; while(sz < n) sz <<= 1; while((int)xs.size() < sz) xs.emplace_back(xs.back() + 1); node.resize(sz * 2, Line(T(0), inf)); } // 直線 ax + b を追加 void add_line(T a, T b) { update(a, b, 0, sz, 1); } // 線分 ax + b (x_l <= x < x_r) を追加 void add_segment(T a, T b, T x_l, T x_r) { int l = std::lower_bound(xs.begin(), xs.end(), x_l) - xs.begin(); int r = std::lower_bound(xs.begin(), xs.end(), x_r) - xs.begin(); l += sz; r += sz; int width = 1, seg_idx_left = sz; while(l < r) { if(l & 1) { int L = (l - seg_idx_left) * width; int R = L + width; update(a, b, L, R, l); l++; } if(r & 1) { r--; int L = (r - seg_idx_left) * width; int R = L + width; update(a, b, L, R, r); } l >>= 1; r >>= 1; width <<= 1; seg_idx_left >>= 1; } } // min_{i} (a_i * x + b) を求める T get_min(T x) { int pos = std::lower_bound(xs.begin(), xs.end(), x) - xs.begin(); assert(0 <= pos and pos < sz); pos += sz; T ret = node[pos].eval(x); while(pos > 1) { pos >>= 1; ret = std::min(ret, node[pos].eval(x)); } return ret; } private: struct Line { T a, b; Line(T a, T b): a(a), b(b) {} inline T eval(T x) const { return (a * x + b); } }; std::vector<T> xs; std::vector<Line> node; int n, sz; void update(T a, T b, int l, int r, int pos) { Line new_line(a, b); while(1) { bool is_over_l = (new_line.eval(xs[l]) >= node[pos].eval(xs[l])); bool is_over_r = (new_line.eval(xs[r-1]) >= node[pos].eval(xs[r-1])); if(is_over_l == is_over_r) { if(!is_over_l) node[pos] = new_line; break; } int mid = (l + r) >> 1; bool is_over_mid = (new_line.eval(xs[mid]) >= node[pos].eval(xs[mid])); if(!is_over_l and is_over_r) { if(is_over_mid) { r = mid; pos = (pos << 1); } else { std::swap(new_line, node[pos]); l = mid; pos = (pos << 1) | 1; } } else { if(is_over_mid) { l = mid; pos = (pos << 1) | 1; } else { std::swap(new_line, node[pos]); r = mid; pos = (pos << 1); } } } } }; #line 78 "combined.cpp" int main() { ll a; int Q; cin >> a >> Q; vector<tuple<int, ll, ll>> qs(Q); vector<ll> xs; REP(i, Q) { int type; cin >> type; if(type == 1) { ll S, T; cin >> S >> T; qs[i] = {1, S, T}; } else { ll T; cin >> T; qs[i] = {2, T, -1}; xs.push_back(T); } } LiChaoTree<ll, LLINF * 2> seg(xs); for(const auto& [type, S, T] : qs) { if(type == 1) { seg.add_line(-a * (S + T), a * S * T); } else { ll ans = -seg.get_min(S) - a * S * S; chmax(ans, 0LL); cout << ans << endl; } } }