結果

問題 No.3116 More and more teleporter
ユーザー srjywrdnprkt
提出日時 2025-08-26 03:35:54
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 225 ms / 2,000 ms
コード長 1,083 bytes
コンパイル時間 2,852 ms
コンパイル使用メモリ 281,716 KB
実行使用メモリ 12,772 KB
最終ジャッジ日時 2025-08-26 03:36:01
合計ジャッジ時間 7,167 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/segtree>

using namespace std;
using namespace atcoder;
using ll = long long;
//using mint = modint998244353;

ll op(ll a, ll b){
    return min(a, b);
}
ll e(){
    return 1e18;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    /*
       クエリ1でzが与えられた時、
       答えはzか
       min c_i+|z-x_i|
       
       c_i+|z-x_i|は
       
       z>x_iのとき
       (c_i-x_i)+z (t1)

       z<=x_iのとき
       (c_i+x_i)-z (t2)

       よってセグメント木を2本持っておけば良い。
    */

    ll N, Q;
    cin >> N >> Q;
    segtree<ll, op, e> t1(N), t2(N);
    while(Q--){
        int t;
        cin >> t;
        if (t == 1){
            ll z;
            cin >> z;
            z--;
            cout << min({t1.prod(0, z)+z, t2.prod(z, N)-z, z}) << endl;
        }
        else{
            ll x, c;
            cin >> x >> c;
            x--;
            t1.set(x, min(t1.get(x), c-x));
            t2.set(x, min(t2.get(x), c+x));
        }
    }

    return 0;
}
0