結果
| 問題 |
No.3116 More and more teleporter
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-18 20:39:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 279 ms / 2,000 ms |
| コード長 | 1,730 bytes |
| コンパイル時間 | 2,181 ms |
| コンパイル使用メモリ | 196,992 KB |
| 実行使用メモリ | 8,832 KB |
| 最終ジャッジ日時 | 2025-04-18 20:39:24 |
| 合計ジャッジ時間 | 5,436 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
//#include<atcoder/all>
//using namespace atcoder;
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
constexpr ll MAX = 2000000000000000000;
constexpr ld PI = 3.14159265358979;
constexpr ll MOD = 0;//2024948111;
ld dotorad(ld K){ return PI * K / 180.0; }
ld radtodo(ld K){ return K * 180.0 / PI; }
mt19937 mt;
void randinit(){ srand((unsigned)time(NULL));mt = mt19937(rand()); }
struct Segtree{
ll n;
const ll base = MAX;
ll op(ll a,ll b){
return min(a,b);
}
ll co(ll a,ll b){
return min(a,b);
}
vector<ll> A;
Segtree(ll N): A(N << 1,base) { n = N; }
void update(ll i,ll a){
i += n;
A[i] = op(A[i],a);
while(i >> 1 > 0){
i >>= 1;
A[i] = co(A[i << 1],A[i << 1 | 1]);
}
}
ll query(ll l,ll r){
ll L = base,R = base;
l += n;
r += n;
while(l < r){
if(l & 1){
L = co(L,A[l]);
l++;
}
if(r & 1){
r--;
R = co(A[r],R);
}
l >>= 1;
r >>= 1;
}
return co(L,R);
}
};
int main(){
ll N,Q;
cin >> N >> Q;
Segtree S1(N),S2(N);
S1.update(0,0);
S2.update(0,0);
for(ll q = 0;q < Q;q++){
ll t;
cin >> t;
if(t == 1){
ll x;
cin >> x;
x--;
cout << min(S1.query(0,x + 1) + x,S2.query(x,N) - x) << endl;
}
else{
ll x,c;
cin >> x >> c;
x--;
S1.update(x,c - x);
S2.update(x,c + x);
}
}
}