結果
問題 | No.3116 More and more teleporter |
ユーザー |
![]() |
提出日時 | 2025-04-19 18:06:31 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 299 ms / 2,000 ms |
コード長 | 2,664 bytes |
コンパイル時間 | 1,742 ms |
コンパイル使用メモリ | 165,628 KB |
実行使用メモリ | 11,564 KB |
最終ジャッジ日時 | 2025-04-19 18:06:37 |
合計ジャッジ時間 | 6,009 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- #define def infl template<class V, int NV> struct SegTree { //[l,r) V comp(V& l, V& r) { return min(l, r); }; vector<V> val; SegTree() { val = vector<V>(NV * 2, def); } V get(int x, int y, int l = 0, int r = NV, int k = 1) { if (r <= x || y <= l)return def; if (x <= l && r <= y)return val[k]; auto a = get(x, y, l, (l + r) / 2, k * 2); auto b = get(x, y, (l + r) / 2, r, k * 2 + 1); return comp(a, b); } void update(int i, V v) { i += NV; val[i] = v; while (i>1) i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]); } void add(int i, V v) { update(i, val[i + NV] + v); } V operator[](int x) { return get(x, x + 1); } }; /*--------------------------------------------------------------------------------------------------- ∧_∧ ∧_∧ (´<_` ) Welcome to My Coding Space! ( ´_ゝ`) / ⌒i @hamayanhamayan / \ | | / / ̄ ̄ ̄ ̄/ | __(__ニつ/ _/ .| .|____ \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int N, Q; SegTree<ll, 1<<18> lft; SegTree<ll, 1<<18> rht; void _main() { cin >> N >> Q; rep(_, 0, Q) { int t; cin >> t; if (t == 1) { int x; cin >> x; x--; ll ans = x; chmin(ans, lft.get(0, x) + x); // 左側のテレポーターを使った場合 chmin(ans, rht.get(x, N) - x); // 右側のテレポーターを使った場合 cout << ans << endl; } else { int x, c; cin >> x >> c; x--; // lft ll cost = -x + c; if (cost < lft.get(x, x + 1)) lft.update(x, cost); // rht cost = x + c; if (cost < rht.get(x, x + 1)) rht.update(x, cost); } } }