提出 #73302356
ソースコード 拡げる
// Best papa ikam template — Absolute Performance Limit
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std; using namespace __gnu_pbds;
// --- Types ---
using ll = long long; using ull = unsigned long long; using ld = long double;
using pii = pair<int,int>; using pll = pair<ll,ll>; using vi = vector<int>; using vll = vector<ll>;
template<class T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
// --- Constants ---
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e18 + 7;
const ld PI = acos(-1.0L);
const ld EPS = 1e-9;
// --- Macros ---
#define nn '\n'
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define each(x,a) for(auto& x:a)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
// --- RNG & Hash (SplitMix64 + Golden Ratio) ---
static mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count() ^ (ull)unique_ptr<char>(new char).get());
struct chash {
static ull sm64(ull x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(ull x) const {
static const ull R = rng(); return (size_t)sm64(x + R);
}
template<class A, class B> size_t operator()(const pair<A, B>& p) const {
static const ull R = rng();
return (size_t)(sm64((ull)p.fi + R) ^ (sm64((ull)p.se + R) >> 1));
}
};
// --- PBDS ---
template<class K, class V> using hash_map = gp_hash_table<K, V, chash>;
template<class K> using hash_set = gp_hash_table<K, null_type, chash>;
template<class T> using ord_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// --- Math & Modular ---
template<int M> struct mint {
int v; constexpr mint(ll x = 0) : v((int)(x % M < 0 ? x % M + M : x % M)) {}
mint& operator+=(mint o) { v += o.v; if (v >= M) v -= M; return *this; }
mint& operator-=(mint o) { v -= o.v; if (v < 0) v += M; return *this; }
mint& operator*=(mint o) { v = (int)((ll)v * o.v % M); return *this; }
mint pow(ll e) const { mint r = 1, a = *this; for (; e; e >>= 1, a *= a) if (e & 1) r *= a; return r; }
mint inv() const { return pow(M - 2); }
mint operator-() const { return v ? M - v : 0; }
mint& operator/=(mint o) { return *this *= o.inv(); }
friend mint operator+(mint a, mint b) { return a += b; }
friend mint operator-(mint a, mint b) { return a -= b; }
friend mint operator*(mint a, mint b) { return a *= b; }
friend mint operator/(mint a, mint b) { return a /= b; }
friend bool operator==(mint a, mint b) { return a.v == b.v; }
friend bool operator!=(mint a, mint b) { return a.v != b.v; }
friend istream& operator>>(istream& i, mint& x) { ll t; i >> t; x = t; return i; }
friend ostream& operator<<(ostream& o, mint x) { return o << x.v; }
};
using mint_t = mint<MOD>;
struct Combs {
vector<mint_t> f, i;
Combs(int n) : f(n + 1), i(n + 1) {
f[0] = 1; rep(j, 1, n + 1) f[j] = f[j - 1] * j;
i[n] = f[n].inv(); for (int j = n - 1; j >= 0; --j) i[j] = i[j + 1] * (j + 1);
}
mint_t nCr(int n, int r) { return (r < 0 || r > n) ? 0 : f[n] * i[r] * i[n - r]; }
};
// --- Bit & Math Utils ---
inline ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return a; }
inline ll binpow(ll a, ll e) {
ll r = 1; for (; e; e >>= 1, a = a * a) if (e & 1) r = r * a; return r;
}
inline ll mod_pow(ll a, ll e, ll m = MOD) {
ll r = 1; a %= m; for (; e; e >>= 1, a = (ll)((__int128)a * a % m)) if (e & 1) r = (ll)((__int128)r * a % m); return r;
}
#define popcnt __builtin_popcountll
inline int msb(ll x) { return x ? 63 - __builtin_clzll((ull)x) : -1; }
inline bool is_pow2(ull x) { return x && !(x & (x - 1)); }
void solve() {
int n;
cin >> n;
vi a(n); each(x, a) cin >> x;
vi ans(n);
for (int i=n-1; i>=0; --i) {
if (a[i]-1 == i) ans[i] = i+1;
else {
ans[i] = ans[a[i]-1];
}
}
each(x, ans) cout << x << ' ';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int T = 1;
// cin >> T;
while (T--) solve();
return 0;
}
提出情報
| 提出日時 |
|
| 問題 |
C - Sugoroku Destination |
| ユーザ |
ikam |
| 言語 |
C++23 (GCC 15.2.0) |
| 得点 |
300 |
| コード長 |
4564 Byte |
| 結果 |
AC |
| 実行時間 |
34 ms |
| メモリ |
7960 KiB |
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
300 / 300 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 00_sample_00.txt |
AC |
1 ms |
3596 KiB |
| 00_sample_01.txt |
AC |
1 ms |
3392 KiB |
| 00_sample_02.txt |
AC |
1 ms |
3400 KiB |
| 01_random_03.txt |
AC |
33 ms |
7952 KiB |
| 01_random_04.txt |
AC |
33 ms |
7956 KiB |
| 01_random_05.txt |
AC |
33 ms |
7960 KiB |
| 01_random_06.txt |
AC |
33 ms |
7956 KiB |
| 01_random_07.txt |
AC |
34 ms |
7952 KiB |
| 01_random_08.txt |
AC |
33 ms |
7956 KiB |
| 01_random_09.txt |
AC |
34 ms |
7960 KiB |
| 01_random_10.txt |
AC |
33 ms |
7952 KiB |
| 01_random_11.txt |
AC |
14 ms |
4800 KiB |
| 01_random_12.txt |
AC |
12 ms |
4576 KiB |
| 01_random_13.txt |
AC |
30 ms |
7244 KiB |
| 01_random_14.txt |
AC |
4 ms |
3840 KiB |
| 01_random_15.txt |
AC |
33 ms |
7952 KiB |
| 01_random_16.txt |
AC |
2 ms |
3500 KiB |
| 01_random_17.txt |
AC |
33 ms |
7952 KiB |