結果
問題 |
No.3116 More and more teleporter
|
ユーザー |
![]() |
提出日時 | 2025-04-19 01:37:25 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 300 ms / 2,000 ms |
コード長 | 3,422 bytes |
コンパイル時間 | 13,681 ms |
コンパイル使用メモリ | 171,720 KB |
実行使用メモリ | 11,324 KB |
最終ジャッジ日時 | 2025-04-19 01:37:43 |
合計ジャッジ時間 | 7,566 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
#define _USE_MATH_DEFINES #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> //#include<unordered_set> //#include<random> //#include <array> //#include <complex> //#include<chrono> //#include<boost/multiprecision/cpp_int.hpp> //#include <atcoder/all> //using namespace boost::multiprecision; using namespace std; //using namespace atcoder; #define LP(I,S,G) for (long long int I = (S); I < (G); ++I) #define IN(X) for (int in = 0; in < X.size(); in++)cin >> X[in] #define OUT(X) for (int in = 0; in < X.size(); in++)cout << X[in]<<" " #define SORT(X) sort((X).begin(), (X).end()) #define CSORT(X,Y) sort(X.begin(), X.end(),Y) #define COPY(X,Y) copy(X.begin(), X.end(), Y.begin()) #define ALL(X,Y) for (auto &(X) :(Y)) #define FULL(a) (a).begin(),(a).end() #define BFS(Q,S) for(Q.push(S);Q.size()!=0;Q.pop()) typedef long long int ll; typedef unsigned long long int ull; long long int M = 998244353; chrono::system_clock::time_point starttime; using namespace std::chrono; inline float getTime() { return duration_cast<milliseconds>(system_clock::now() - starttime).count(); } int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 }; ll MAX(ll A, ll B) { return ((A) > (B) ? (A) : (B)); } ll MIN(ll A, ll B) { return ((A) < (B) ? (A) : (B)); } inline long long int xor128() { static long long int x = 123456789, y = 362436069, z = 521288629, w = 88675123; long long int t = (x ^ (x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))); } struct HashPair { //注意 constがいる template<class T1, class T2> size_t operator()(const pair<T1, T2>& p) const { //first分をハッシュ化する auto hash1 = hash<T1>{}(p.first); //second分をハッシュ化する auto hash2 = hash<T2>{}(p.second); //重複しないようにハッシュ処理 size_t seed = 0; seed ^= hash1 + 0x9e3779b9 + (seed << 6) + (seed >> 2); seed ^= hash2 + 0x9e3779b9 + (seed << 6) + (seed >> 2); return seed; } }; template< typename Monoid > struct SegmentTree { using F = function< Monoid(Monoid, Monoid) >; int sz; vector< Monoid > seg; const F f; const Monoid M1; SegmentTree(int n, const F f, const Monoid& M1) : f(f), M1(M1) { sz = 1; while (sz < n) sz <<= 1; seg.assign(2 * sz, M1); } void set(int k, const Monoid& x) { seg[k + sz] = x; } void build() { for (int k = sz - 1; k > 0; k--) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } void update(int k, const Monoid& x) { k += sz; seg[k] = x; while (k >>= 1) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, seg[a++]); if (b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int& k) const { return seg[k + sz]; } }; int main() { ll n,q; cin >> n >> q; SegmentTree<ll> t1(n, [](ll l, ll r) {return min(l, r); }, 0), t2(n, [](ll l, ll r) {return min(l, r); }, LLONG_MAX); LP(i, 0, n)t2.update(i, 2 * i); LP(_, 0, q) { ll k; cin >> k; if (k == 1) { ll x; cin >> x; --x; //cerr << t1.query(0, x + 1) << " " << t2.query(x, n) << "\n"; cout << min(t1.query(0, x + 1) + x, t2.query(x, n) - x) << "\n"; } else { ll x, c; cin >> x >> c; --x; t1.update(x, min(t1[x], c - x)); t2.update(x, min(t2[x], c + x)); } } }