結果
| 問題 | No.3396 ChRisTmas memory |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-03 06:44:09 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 3,208 bytes |
| コンパイル時間 | 8,948 ms |
| コンパイル使用メモリ | 528,496 KB |
| 実行使用メモリ | 508,912 KB |
| 最終ジャッジ日時 | 2025-12-03 06:45:02 |
| 合計ジャッジ時間 | 48,778 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 MLE * 10 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
// using mint = modint1000000007;
// using mint = double;
#endif
//define
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long , long long>;
using vi = vector<int>;
using vll = vector<long long>;
#define rep(i,l,r) for (int i = (int)(l); i < (int)(r); i++)
#define rrep(i,l,r) for (int i = (int)(r-1); i >= (int)(l); i--)
#define len(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define elif else if
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int inf = 1e9;
const long long infl = 1LL<<60;
const int mod = 998244353;
ll pow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
template<class T, class U> bool chmin(T& a, const U& b){ if(a > T(b)){ a = b; return 1; } return 0; }
template<class T, class U> bool chmax(T& a, const U& b){ if(a < T(b)){ a = b; return 1; } return 0; }
template <class T>
using spq = priority_queue<T, vector<T>, greater<T>>;
template<class T>istream& operator>>(istream& i, vector<T>& v) {for(int j = 0; j < (int)(v).size(); j++) i >> v[j]; return i;}
struct IoSetup {
IoSetup() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
cerr << fixed << setprecision(15);
}
} iosetup;
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
using Int = cpp_int;
Int extgcd(Int a, Int b, Int &x, Int &y) {
Int r0 = a, r1 = b;
Int x0 = 1, x1 = 0;
Int y0 = 0, y1 = 1;
while (r1 != 0) {
Int q = r0 / r1;
Int r_next = r0 % r1;
Int x_next = x0 - q * x1;
Int y_next = y0 - q * y1;
r0 = r1; r1 = r_next;
x0 = x1; x1 = x_next;
y0 = y1; y1 = y_next;
}
x = x0;
y = y0;
return r0;
}
pair<Int, Int> crt(Int r1, Int m1, Int r2, Int m2) {
Int p, q;
Int g = extgcd(m1, m2, p, q);
if ((r2 - r1) % g != 0) {
return {0, 0};
}
Int lcm = (m1 / g) * m2;
Int m2_div_g = m2 / g;
Int tmp = (r2 - r1) / g;
Int k = (tmp * p) % m2_div_g;
Int r = (r1 + m1 * k) % lcm;
if (r < 0) r += lcm;
return {r, lcm};
}
int main() {
int Q; cin >> Q;
vector<pair<Int, Int>> st;
st.pb({0, 1});
int idx = 1;
rep(i, 0, Q) {
int t; cin >> t;
if (t == 1) {
ll m, r; cin >> m >> r;
const auto& [pr, pm] = st.back();
if (pm != 0) {
pair<Int, Int> res = crt(pr, pm, r, m);
st.pb(move(res));
} else {
st.eb(0, 0);
}
} else if (t == 2) {
int k; cin >> k; idx -= k;
st.resize(st.size() - k);
} else {
ll m; cin >> m;
const auto& [nr, nm] = st.back();
if (nm != 0) {
cout << (nr % m) << "\n";
} else {
cout << "-1\n";
}
}
}
return 0;
}