結果
| 問題 |
No.3116 More and more teleporter
|
| コンテスト | |
| ユーザー |
Shibaken28
|
| 提出日時 | 2025-04-20 00:34:15 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 151 ms / 2,000 ms |
| コード長 | 3,493 bytes |
| コンパイル時間 | 2,429 ms |
| コンパイル使用メモリ | 212,176 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-04-20 00:34:21 |
| 合計ジャッジ時間 | 4,924 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
// #include <atcoder/dsu>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(a) a.begin(), a.end()
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T1, class T2>
std::ostream &operator<<(std::ostream &out, const pair<T1, T2> &A) {
cout << "{" << A.first << "," << A.second << "}";
return out;
}
template <class T1, class T2>
std::ostream &operator<<(std::ostream &out, const map<T1, T2> &M) {
for (const auto &A : M) {
cout << "{" << A.first << "," << A.second << "}";
}
return out;
}
template <class T1>
std::ostream &operator<<(std::ostream &out, const set<T1> &M) {
cout << "{";
for (const auto &A : M) {
cout << A << ", ";
}
cout << "}" << endl;
return out;
}
template <class T1>
std::ostream &operator<<(std::ostream &out, const multiset<T1> &M) {
cout << "{";
for (const auto &A : M) {
cout << A << ", ";
}
cout << "}" << endl;
return out;
}
template <class T>
std::ostream &operator<<(std::ostream &out, const vector<T> &A) {
for (const T &a : A) {
cout << a << " ";
}
return out;
}
void print() { cout << endl; }
template <typename Head, typename... Tail> void print(Head H, Tail... T) {
cout << H << " ";
print(T...);
}
template <class T> std::istream &operator>>(std::istream &in, vector<T> &A) {
for (T &a : A) {
std::cin >> a;
}
return in;
}
using ll = long long;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr ll LINF = numeric_limits<ll>::max() / 2;
void solve() {
// ここからスタート
int N, Q;
cin >> N >> Q;
map<ll, ll> mp;
mp[1] = 0;
auto f = [](ll x, const pair<ll, ll> p) {
return abs(p.first - x) + p.second;
};
while (Q--) {
int t;
cin >> t;
if (t == 1) {
int x;
cin >> x;
ll ans = LINF;
auto itr = mp.lower_bound(x);
if (itr != mp.end()) {
chmin(ans, f(x, *itr));
}
if (itr != mp.begin()) {
itr--;
chmin(ans, f(x, *itr));
}
cout << ans << endl;
} else {
int x, c;
cin >> x >> c;
ll ans = LINF;
auto itr = mp.lower_bound(x);
if (itr != mp.end()) {
chmin(ans, f(x, *itr));
}
if (itr != mp.begin()) {
itr--;
chmin(ans, f(x, *itr));
}
if (ans <= c)
continue;
// 右を削除
while (1) {
auto itr = mp.lower_bound(x);
if (mp.end() == itr)
break;
if (f((*itr).first, {x, c}) > (*itr).second)
break;
mp.erase(itr);
}
while (1) {
auto itr = mp.lower_bound(x);
if (itr == mp.begin())
break;
itr--;
if (mp.begin() == itr)
break;
if (f((*itr).first, {x, c}) > (*itr).second)
break;
mp.erase(itr);
}
mp[x] = c;
}
}
}
int main(void) {
std::cin.tie(0)->sync_with_stdio(0);
solve();
return 0;
}
Shibaken28