QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#435709#8795. Mysterious Sequenceucup-team180#AC ✓1ms4056kbC++2029.8kb2024-06-08 21:08:502024-06-08 21:08:50

Judging History

你现在查看的是最新测评结果

  • [2024-06-08 21:08:50]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:4056kb
  • [2024-06-08 21:08:50]
  • 提交

answer

#pragma region Macros
#ifdef noimi
#pragma comment(linker, "/stack:256000000")
#include "my_template.hpp"
#else
// #pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <immintrin.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <cfloat>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <immintrin.h>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <variant>

#ifdef noimi
#define oj_local(a, b) b
#else
#define oj_local(a, b) a
#endif

#define LOCAL if(oj_local(0, 1))
#define OJ if(oj_local(1, 0))

using namespace std;
using ll = long long;
using ull = unsigned long long int;
using i128 = __int128_t;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ld = long double;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vc<T>>;
template <typename T> using vvvc = vector<vvc<T>>;
using vi = vc<int>;
using vl = vc<ll>;
using vpi = vc<pii>;
using vpl = vc<pll>;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template <typename T> int si(const T &x) { return x.size(); }
template <class T, class S> inline bool chmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); }
template <class T, class S> inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); }
vi iota(int n) {
    vi a(n);
    return iota(a.begin(), a.end(), 0), a;
}
template <typename T> vi iota(const vector<T> &a, bool greater = false) {
    vi res(a.size());
    iota(res.begin(), res.end(), 0);
    sort(res.begin(), res.end(), [&](int i, int j) {
        if(greater) return a[i] > a[j];
        return a[i] < a[j];
    });
    return res;
}

// macros
#define overload5(a, b, c, d, e, name, ...) name
#define overload4(a, b, c, d, name, ...) name
#define endl '\n'
#define REP0(n) for(ll jidlsjf = 0; jidlsjf < n; ++jidlsjf)
#define REP1(i, n) for(ll i = 0; i < (n); ++i)
#define REP2(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP3(i, a, b, c) for(ll i = (a); i < (b); i += (c))
#define rep(...) overload4(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define per0(n) for(int jidlsjf = 0; jidlsjf < (n); ++jidlsjf)
#define per1(i, n) for(ll i = (n)-1; i >= 0; --i)
#define per2(i, a, b) for(ll i = (a)-1; i >= b; --i)
#define per3(i, a, b, c) for(ll i = (a)-1; i >= (b); i -= (c))
#define per(...) overload4(__VA_ARGS__, per3, per2, per1, per0)(__VA_ARGS__)
#define fore0(a) rep(a.size())
#define fore1(i, a) for(auto &&i : a)
#define fore2(a, b, v) for(auto &&[a, b] : v)
#define fore3(a, b, c, v) for(auto &&[a, b, c] : v)
#define fore4(a, b, c, d, v) for(auto &&[a, b, c, d] : v)
#define fore(...) overload5(__VA_ARGS__, fore4, fore3, fore2, fore1, fore0)(__VA_ARGS__)
#define setbits(j, n) for(ll iiiii = (n), j = lowbit(iiiii); iiiii; iiiii ^= 1 << j, j = lowbit(iiiii))
#define perm(v) for(bool permrepflag = true; (permrepflag ? exchange(permrepflag, false) : next_permutation(all(v)));)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define drop(s) cout << #s << endl, exit(0)
#define si(c) (int)(c).size()
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define lbg(c, x) distance((c).begin(), lower_bound(all(c), (x), greater{}))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define ubg(c, x) distance((c).begin(), upper_bound(all(c), (x), greater{}))
#define rng(v, l, r) v.begin() + (l), v.begin() + (r)
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define SORT(v) sort(all(v))
#define REV(v) reverse(all(v))
#define UNIQUE(x) SORT(x), x.erase(unique(all(x)), x.end())
template <typename T = ll, typename S> T SUM(const S &v) { return accumulate(all(v), T(0)); }
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define overload2(_1, _2, name, ...) name
#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)                                                                                                                         \
    vector<vector<vector<vector<type>>>> name(a, vector<vector<vector<type>>>(b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
constexpr pii dx4[4] = {pii{1, 0}, pii{0, 1}, pii{-1, 0}, pii{0, -1}};
constexpr pii dx8[8] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

namespace yesno_impl {
const string YESNO[2] = {"NO", "YES"};
const string YesNo[2] = {"No", "Yes"};
const string yesno[2] = {"no", "yes"};
const string firstsecond[2] = {"second", "first"};
const string FirstSecond[2] = {"Second", "First"};
const string possiblestr[2] = {"impossible", "possible"};
const string Possiblestr[2] = {"Impossible", "Possible"};
void YES(bool t = 1) { cout << YESNO[t] << endl; }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { cout << YesNo[t] << endl; }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { cout << yesno[t] << endl; }
void no(bool t = 1) { yes(!t); }
void first(bool t = 1) { cout << firstsecond[t] << endl; }
void First(bool t = 1) { cout << FirstSecond[t] << endl; }
void possible(bool t = 1) { cout << possiblestr[t] << endl; }
void Possible(bool t = 1) { cout << Possiblestr[t] << endl; }
}; // namespace yesno_impl
using namespace yesno_impl;

#define INT(...)                                                                                                                                               \
    int __VA_ARGS__;                                                                                                                                           \
    IN(__VA_ARGS__)
#define INTd(...)                                                                                                                                              \
    int __VA_ARGS__;                                                                                                                                           \
    IN2(__VA_ARGS__)
#define LL(...)                                                                                                                                                \
    ll __VA_ARGS__;                                                                                                                                            \
    IN(__VA_ARGS__)
#define LLd(...)                                                                                                                                               \
    ll __VA_ARGS__;                                                                                                                                            \
    IN2(__VA_ARGS__)
#define STR(...)                                                                                                                                               \
    string __VA_ARGS__;                                                                                                                                        \
    IN(__VA_ARGS__)
#define CHR(...)                                                                                                                                               \
    char __VA_ARGS__;                                                                                                                                          \
    IN(__VA_ARGS__)
#define DBL(...)                                                                                                                                               \
    double __VA_ARGS__;                                                                                                                                        \
    IN(__VA_ARGS__)
#define VEC(type, name, size)                                                                                                                                  \
    vector<type> name(size);                                                                                                                                   \
    IN(name)
#define VECd(type, name, size)                                                                                                                                 \
    vector<type> name(size);                                                                                                                                   \
    IN2(name)
#define VEC2(type, name1, name2, size)                                                                                                                         \
    vector<type> name1(size), name2(size);                                                                                                                     \
    for(int i = 0; i < size; i++) IN(name1[i], name2[i])
#define VEC2d(type, name1, name2, size)                                                                                                                        \
    vector<type> name1(size), name2(size);                                                                                                                     \
    for(int i = 0; i < size; i++) IN2(name1[i], name2[i])
#define VEC3(type, name1, name2, name3, size)                                                                                                                  \
    vector<type> name1(size), name2(size), name3(size);                                                                                                        \
    for(int i = 0; i < size; i++) IN(name1[i], name2[i], name3[i])
#define VEC3d(type, name1, name2, name3, size)                                                                                                                 \
    vector<type> name1(size), name2(size), name3(size);                                                                                                        \
    for(int i = 0; i < size; i++) IN2(name1[i], name2[i], name3[i])
#define VEC4(type, name1, name2, name3, name4, size)                                                                                                           \
    vector<type> name1(size), name2(size), name3(size), name4(size);                                                                                           \
    for(int i = 0; i < size; i++) IN(name1[i], name2[i], name3[i], name4[i]);
#define VEC4d(type, name1, name2, name3, name4, size)                                                                                                          \
    vector<type> name1(size), name2(size), name3(size), name4(size);                                                                                           \
    for(int i = 0; i < size; i++) IN2(name1[i], name2[i], name3[i], name4[i]);
#define VV(type, name, h, w)                                                                                                                                   \
    vector<vector<type>> name(h, vector<type>(w));                                                                                                             \
    IN(name)
#define VVd(type, name, h, w)                                                                                                                                  \
    vector<vector<type>> name(h, vector<type>(w));                                                                                                             \
    IN2(name)
int scan() { return getchar(); }
void scan(int &a) { cin >> a; }
void scan(long long &a) { cin >> a; }
void scan(char &a) { cin >> a; }
void scan(double &a) { cin >> a; }
void scan(string &a) { cin >> a; }
template <class T, class S> void scan(pair<T, S> &p) { scan(p.first), scan(p.second); }
template <class T> void scan(vector<T> &);
template <class T> void scan(vector<T> &a) {
    for(auto &i : a) scan(i);
}
template <class T> void scan(T &a) { cin >> a; }
void IN() {}
void IN2() {}
template <class Head, class... Tail> void IN(Head &head, Tail &...tail) {
    scan(head);
    IN(tail...);
}
template <class Head, class... Tail> void IN2(Head &head, Tail &...tail) {
    scan(head);
    --head;
    IN2(tail...);
}

template <int p = -1> void pat() {}
template <int p = -1, class Head, class... Tail> void pat(Head &h, Tail &...tail) {
    h += p;
    pat<p>(tail...);
}

template <typename T, typename S> T ceil(T x, S y) {
    assert(y);
    return (y < 0 ? ceil(-x, -y) : (x > 0 ? (x + y - 1) / y : x / y));
}

template <typename T, typename S> T floor(T x, S y) {
    assert(y);
    return (y < 0 ? floor(-x, -y) : (x > 0 ? x / y : x / y - (x % y == 0 ? 0 : 1)));
}
template <typename T, typename S, typename U> U bigmul(const T &x, const S &y, const U &lim) { // clamp(x * y, -lim, lim)
    if(x < 0 and y < 0) return bigmul(-x, -y, lim);
    if(x < 0) return -bigmul(-x, y, lim);
    if(y < 0) return -bigmul(x, -y, lim);
    return y == 0 or x <= lim / y ? x * y : lim;
}
template <class T> T POW(T x, int n) {
    T res = 1;
    for(; n; n >>= 1, x *= x)
        if(n & 1) res *= x;
    return res;
}
template <class T, class S> T POW(T x, S n, const ll &mod) {
    T res = 1;
    x %= mod;
    for(; n; n >>= 1, x = x * x % mod)
        if(n & 1) res = res * x % mod;
    return res;
}
vector<pll> factor(ll x) {
    vector<pll> ans;
    for(ll i = 2; i * i <= x; i++)
        if(x % i == 0) {
            ans.push_back({i, 1});
            while((x /= i) % i == 0) ans.back().second++;
        }
    if(x != 1) ans.push_back({x, 1});
    return ans;
}
template <class T> vector<T> divisor(T x) {
    vector<T> ans;
    for(T i = 1; i * i <= x; i++)
        if(x % i == 0) {
            ans.pb(i);
            if(i * i != x) ans.pb(x / i);
        }
    return ans;
}
template <typename T> void zip(vector<T> &x) {
    vector<T> y = x;
    UNIQUE(y);
    for(int i = 0; i < x.size(); ++i) { x[i] = lb(y, x[i]); }
}
template <class S> void fold_in(vector<S> &v) {}
template <typename Head, typename... Tail, class S> void fold_in(vector<S> &v, Head &&a, Tail &&...tail) {
    for(auto e : a) v.emplace_back(e);
    fold_in(v, tail...);
}
template <class S> void renumber(vector<S> &v) {}
template <typename Head, typename... Tail, class S> void renumber(vector<S> &v, Head &&a, Tail &&...tail) {
    for(auto &&e : a) e = lb(v, e);
    renumber(v, tail...);
}
template <class S, class... Args> vector<S> zip(vector<S> &head, Args &&...args) {
    vector<S> v;
    fold_in(v, head, args...);
    sort(all(v)), v.erase(unique(all(v)), v.end());
    renumber(v, head, args...);
    return v;
}

template <typename S> void rearrange(const vector<S> &id) {}
template <typename S, typename T> void rearrange_exec(const vector<S> &id, vector<T> &v) {
    vector<T> w(v.size());
    rep(i, si(id)) w[i] = v[id[i]];
    v.swap(w);
}
// 並び替える順番, 並び替える vector 達
template <typename S, typename Head, typename... Tail> void rearrange(const vector<S> &id, Head &a, Tail &...tail) {
    rearrange_exec(id, a);
    rearrange(id, tail...);
}

template <typename T> vector<T> RUI(const vector<T> &v) {
    vector<T> res(v.size() + 1);
    for(int i = 0; i < v.size(); i++) res[i + 1] = res[i] + v[i];
    return res;
}
template <typename T> void zeta_supersetsum(vector<T> &f) {
    int n = f.size();
    for(int i = 1; i < n; i <<= 1) rep(b, n) if(!(i & b)) f[b] += f[b | i];
}

template <typename T> void zeta_subsetsum(vector<T> &f) {
    int n = f.size();
    for(int i = 1; i < n; i <<= 1) rep(b, n) if(!(i & b)) f[b | i] += f[b];
}
template <typename T> void mobius_subset(vector<T> &f) {
    int n = f.size();
    for(int i = 1; i < n; i <<= 1) rep(b, n) if(!(i & b)) f[b] -= f[b | i];
}
template <typename T> void mobius_superset(vector<T> &f) {
    int n = f.size();
    for(int i = 1; i < n; i <<= 1) rep(b, n) if(!(i & b)) f[b | i] -= f[b];
}
// 反時計周りに 90 度回転
template <typename T> void rot(vector<vector<T>> &v) {
    if(empty(v)) return;
    int n = v.size(), m = v[0].size();
    vector<vector<T>> res(m, vector<T>(n));
    rep(i, n) rep(j, m) res[m - 1 - j][i] = v[i][j];
    v.swap(res);
}

vector<int> counter(const vector<int> &v, int max_num = -1) {
    if(max_num == -1) max_num = MAX(v);
    vector<int> res(max_num + 1);
    fore(e, v) res[e]++;
    return res;
}

// x in [l, r)
template <class T, class S> bool inc(const T &x, const S &l, const S &r) { return l <= x and x < r; }
template <class T, class S> bool inc(const T &x, const pair<S, S> &p) { return p.first <= x and x < p.second; }

// 便利関数
constexpr ll ten(int n) { return n == 0 ? 1 : ten(n - 1) * 10; }
constexpr ll tri(ll n) { return n * (n + 1) / 2; }
// l + ... + r
constexpr ll tri(ll l, ll r) { return (l + r) * (r - l + 1) / 2; }
ll max(int x, ll y) { return max((ll)x, y); }
ll max(ll x, int y) { return max(x, (ll)y); }
int min(int x, ll y) { return min((ll)x, y); }
int min(ll x, int y) { return min(x, (ll)y); }
// bit 演算系
#define bit(i) (1LL << i)       // (1 << i)
#define test(b, i) (b >> i & 1) // b の i bit 目が立っているか
ll pow2(int i) { return 1LL << i; }
int topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }
int topbit(ll t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }
// int lowbit(signed a) { return a == 0 ? 32 : __builtin_ctz(a); }
int lowbit(ull a) { return a == 0 ? 64 : __builtin_ctzll(a); }
// int allbit(int n) { return (1 << n) - 1; }
constexpr ll mask(int n) { return (1LL << n) - 1; }
// int popcount(signed t) { return __builtin_popcount(t); }
// int popcount(ll t) { return __builtin_popcountll(t); }
int popcount(uint64_t t) { return __builtin_popcountll(t); }
static inline uint64_t popcount64(uint64_t x) {
    uint64_t m1 = 0x5555555555555555ll;
    uint64_t m2 = 0x3333333333333333ll;
    uint64_t m4 = 0x0F0F0F0F0F0F0F0Fll;
    uint64_t h01 = 0x0101010101010101ll;

    x -= (x >> 1) & m1;
    x = (x & m2) + ((x >> 2) & m2);
    x = (x + (x >> 4)) & m4;

    return (x * h01) >> 56;
}
bool ispow2(int i) { return i && (i & -i) == i; }

ll rnd(ll l, ll r) { //[l, r)
#ifdef noimi
    static mt19937_64 gen;
#else
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
#endif
    return uniform_int_distribution<ll>(l, r - 1)(gen);
}
ll rnd(ll n) { return rnd(0, n); }

template <class t> void random_shuffle(vc<t> &a) { rep(i, si(a)) swap(a[i], a[rnd(0, i + 1)]); }

int in() {
    int x;
    cin >> x;
    return x;
}
ll lin() {
    unsigned long long x;
    cin >> x;
    return x;
}

template <class T, class S> pair<T, S> operator-(const pair<T, S> &x) { return pair<T, S>(-x.first, -x.second); }
template <class T, class S> pair<T, S> operator-(const pair<T, S> &x, const pair<T, S> &y) { return pair<T, S>(x.fi - y.fi, x.se - y.se); }
template <class T, class S> pair<T, S> operator+(const pair<T, S> &x, const pair<T, S> &y) { return pair<T, S>(x.fi + y.fi, x.se + y.se); }
template <class T> pair<T, T> operator&(const pair<T, T> &l, const pair<T, T> &r) { return pair<T, T>(max(l.fi, r.fi), min(l.se, r.se)); }
template <class T, class S> pair<T, S> operator+=(pair<T, S> &l, const pair<T, S> &r) { return l = l + r; }
template <class T, class S> pair<T, S> operator-=(pair<T, S> &l, const pair<T, S> &r) { return l = l - r; }
// 開閉
template <class T> bool intersect(const pair<T, T> &l, const pair<T, T> &r) { return (l.se < r.se ? r.fi < l.se : l.fi < r.se); }

template <class T> vector<T> &operator++(vector<T> &v) {
    fore(e, v) e++;
    return v;
}
template <class T> vector<T> operator++(vector<T> &v, int) {
    auto res = v;
    fore(e, v) e++;
    return res;
}
template <class T> vector<T> &operator--(vector<T> &v) {
    fore(e, v) e--;
    return v;
}
template <class T> vector<T> operator--(vector<T> &v, int) {
    auto res = v;
    fore(e, v) e--;
    return res;
}
template <class T> void connect(vector<T> &l, const vector<T> &r) { fore(e, r) l.eb(e); }
template <class T> vector<T> operator+(const vector<T> &l, const vector<T> &r) {
    vector<T> res(max(si(l), si(r)));
    rep(i, si(l)) res[i] += l[i];
    rep(i, si(r)) res[i] += r[i];
    return res;
}
template <class T> vector<T> operator-(const vector<T> &l, const vector<T> &r) {
    vector<T> res(max(si(l), si(r)));
    rep(i, si(l)) res[i] += l[i];
    rep(i, si(r)) res[i] -= r[i];
    return res;
}
template <class T> vector<T> &operator+=(const vector<T> &l, const vector<T> &r) {
    if(si(l) < si(r)) l.resize(si(r));
    rep(i, si(r)) l[i] += r[i];
    return l;
}
template <class T> vector<T> &operator-=(const vector<T> &l, const vector<T> &r) {
    if(si(l) < si(r)) l.resize(si(r));
    rep(i, si(r)) l[i] -= r[i];
    return l;
}
template <class T> vector<T> &operator+=(vector<T> &v, const T &x) {
    fore(e, v) e += x;
    return v;
}
template <class T> vector<T> &operator-=(vector<T> &v, const T &x) {
    fore(e, v) e -= x;
    return v;
}

template <typename T> struct edge {
    int from, to;
    T cost;
    int id;
    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
    edge(int from, int to, T cost, int id) : from(from), to(to), cost(cost), id(id) {}
    constexpr bool operator<(const edge<T> &rhs) const noexcept { return cost < rhs.cost; }
    edge &operator=(const int &x) {
        to = x;
        return *this;
    }
    operator int() const { return to; }
    friend ostream operator<<(ostream &os, const edge &e) { return os << e.to; }
};
template <typename T> using Edges = vector<edge<T>>;

template <typename T = int> Edges<T> read_edges(int m, bool weighted = false) {
    Edges<T> res;
    res.reserve(m);
    for(int i = 0; i < m; i++) {
        int u, v, c = 0;
        scan(u), scan(v), u--, v--;
        if(weighted) scan(c);
        res.eb(u, v, c, i);
    }
    return res;
}

using Tree = vector<vector<int>>;
using Graph = vector<vector<int>>;
template <class T> using Wgraph = vector<vector<edge<T>>>;
Graph getG(int n, int m = -1, bool directed = false, int margin = 1) {
    Tree res(n);
    if(m == -1) m = n - 1;
    while(m--) {
        int a, b;
        cin >> a >> b;
        a -= margin, b -= margin;
        res[a].emplace_back(b);
        if(!directed) res[b].emplace_back(a);
    }
    return res;
}
Graph getTreeFromPar(int n, int margin = 1) {
    Graph res(n);
    for(int i = 1; i < n; i++) {
        int a;
        cin >> a;
        res[a - margin].emplace_back(i);
    }
    return res;
}
template <class T> Wgraph<T> getWg(int n, int m = -1, bool directed = false, int margin = 1) {
    Wgraph<T> res(n);
    if(m == -1) m = n - 1;
    while(m--) {
        int a, b;
        T c;
        scan(a), scan(b), scan(c);
        a -= margin, b -= margin;
        res[a].emplace_back(b, c);
        if(!directed) res[b].emplace_back(a, c);
    }
    return res;
}
void add(Graph &G, int x, int y) { G[x].eb(y), G[y].eb(x); }
template <class S, class T> void add(Wgraph<S> &G, int x, int y, T c) { G[x].eb(y, c), G[y].eb(x, c); }

#define TEST                                                                                                                                                   \
    INT(testcases);                                                                                                                                            \
    while(testcases--)

i128 abs(const i128 &x) { return x > 0 ? x : -x; }
istream &operator>>(istream &is, i128 &v) {
    string s;
    is >> s;
    v = 0;
    for(int i = 0; i < (int)s.size(); i++) {
        if(isdigit(s[i])) { v = v * 10 + s[i] - '0'; }
    }
    if(s[0] == '-') { v *= -1; }
    return is;
}

ostream &operator<<(ostream &os, const i128 &v) {
    if(v == 0) { return (os << "0"); }
    i128 num = v;
    if(v < 0) {
        os << '-';
        num = -num;
    }
    string s;
    for(; num > 0; num /= 10) { s.push_back((char)(num % 10) + '0'); }
    reverse(s.begin(), s.end());
    return (os << s);
}
namespace aux {
template <typename T, unsigned N, unsigned L> struct tp {
    static void output(std::ostream &os, const T &v) {
        os << std::get<N>(v) << (&os == &cerr ? ", " : " ");
        tp<T, N + 1, L>::output(os, v);
    }
};
template <typename T, unsigned N> struct tp<T, N, N> {
    static void output(std::ostream &os, const T &v) { os << std::get<N>(v); }
};
} // namespace aux
template <typename... Ts> std::ostream &operator<<(std::ostream &os, const std::tuple<Ts...> &t) {
    if(&os == &cerr) { os << '('; }
    aux::tp<std::tuple<Ts...>, 0, sizeof...(Ts) - 1>::output(os, t);
    if(&os == &cerr) { os << ')'; }
    return os;
}
template <typename T, typename S, typename U> std::ostream &operator<<(std::ostream &os, const priority_queue<T, S, U> &_pq) {
    auto pq = _pq;
    vector<T> res;
    while(!empty(pq)) res.emplace_back(pq.top()), pq.pop();
    return os << res;
}
template <class T, class S> ostream &operator<<(ostream &os, const pair<T, S> &p) {
    if(&os == &cerr) { return os << "(" << p.first << ", " << p.second << ")"; }
    return os << p.first << " " << p.second;
}
template <class Ch, class Tr, class Container> std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, const Container &x) {
    bool f = true;
    if(&os == &cerr) os << "[";
    for(auto &y : x) {
        if(&os == &cerr)
            os << (f ? "" : ", ") << y;
        else
            os << (f ? "" : " ") << y;
        f = false;
    }
    if(&os == &cerr) os << "]";
    return os;
}

#define dump(...) static_cast<void>(0)
#define dbg(...) static_cast<void>(0)

void OUT() { cout << endl; }
template <class Head, class... Tail> void OUT(const Head &head, const Tail &...tail) {
    cout << head;
    if(sizeof...(tail)) cout << ' ';
    OUT(tail...);
}

template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
template <class T, class S> constexpr pair<T, S> inf<pair<T, S>> = {inf<T>, inf<S>};

template <class T> void OUT2(const T &t, T INF = inf<T>, T res = -1) { OUT(t != INF ? t : res); }
template <class T> void OUT2(vector<T> &v, T INF = inf<T>, T res = -1) {
    fore(e, v) if(e == INF) e = res;
    OUT(v);
    fore(e, v) if(e == res) e = INF;
}

template <class F> struct REC {
    F f;
    REC(F &&f_) : f(forward<F>(f_)) {}
    template <class... Args> auto operator()(Args &&...args) const { return f(*this, forward<Args>(args)...); }
};

template <class S> vector<pair<S, int>> runLength(const vector<S> &v) {
    vector<pair<S, int>> res;
    for(auto &e : v) {
        if(res.empty() or res.back().fi != e)
            res.eb(e, 1);
        else
            res.back().se++;
    }
    return res;
}
vector<pair<char, int>> runLength(const string &v) {
    vector<pair<char, int>> res;
    for(auto &e : v) {
        if(res.empty() or res.back().fi != e)
            res.eb(e, 1);
        else
            res.back().se++;
    }
    return res;
}

struct string_converter {
    char start = 0;
    char type(const char &c) const { return (islower(c) ? 'a' : isupper(c) ? 'A' : isdigit(c) ? '0' : 0); }
    int convert(const char &c) {
        if(!start) start = type(c);
        return c - start;
    }
    int convert(const char &c, const string &chars) { return chars.find(c); }
    template <typename T> auto convert(const T &v) {
        vector<decltype(convert(v[0]))> ret;
        ret.reserve(size(v));
        for(auto &&e : v) ret.emplace_back(convert(e));
        return ret;
    }
    template <typename T> auto convert(const T &v, const string &chars) {
        vector<decltype(convert(v[0], chars))> ret;
        ret.reserve(size(v));
        for(auto &&e : v) ret.emplace_back(convert(e, chars));
        return ret;
    }
    int operator()(const char &v, char s = 0) {
        start = s;
        return convert(v);
    }
    int operator()(const char &v, const string &chars) { return convert(v, chars); }
    template <typename T> auto operator()(const T &v, char s = 0) {
        start = s;
        return convert(v);
    }
    template <typename T> auto operator()(const T &v, const string &chars) { return convert(v, chars); }
} toint;

template <class T, class F> T bin_search(T ok, T ng, const F &f) {
    while(abs(ok - ng) > 1) {
        T mid = ok + ng >> 1;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}
template <class T, class F> T bin_search_double(T ok, T ng, const F &f, int iter = 80) {
    while(iter--) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

struct Setup_io {
    Setup_io() {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        cout << fixed << setprecision(11);
    }
} setup_io;

#endif

#pragma endregion

int main() {
    DBL(a, b);
    INT(n);
    INT(x1, xn);

    vector<double> dp1(n), dp2(n);
    dp1[1] = 1;
    dp2[0] = x1;

    rep(i, 2, n) {
        dp1[i] = dp1[i - 2] * b + dp1[i - 1] * a;
        dp2[i] = dp2[i - 2] * b + dp2[i - 1] * a;
    }

    double x = (xn - dp2[n - 1]) / dp1[n - 1];
    rep(i, n) { OUT(dp1[i] * x + dp2[i]); }
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3844kb

input:

1.0 1.0 10 1 10

output:

1.00000000000
-0.32352941176
0.67647058824
0.35294117647
1.02941176471
1.38235294118
2.41176470588
3.79411764706
6.20588235294
10.00000000000

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 0ms
memory: 4048kb

input:

1 1 2 1 100

output:

1.00000000000
100.00000000000

result:

ok 2 numbers

Test #3:

score: 0
Accepted
time: 0ms
memory: 3924kb

input:

1 1 5 50 100

output:

50.00000000000
0.00000000000
50.00000000000
50.00000000000
100.00000000000

result:

ok 5 numbers

Test #4:

score: 0
Accepted
time: 0ms
memory: 3892kb

input:

0.25 0.25 10 1 1

output:

1.00000000000
55.87553648069
14.21888412017
17.52360515021
7.93562231760
6.36480686695
3.57510729614
2.48497854077
1.51502145923
1.00000000000

result:

ok 10 numbers

Test #5:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

0.25 0.63 6 93 12

output:

93.00000000000
-14.20480795867
55.03879801033
4.81067048862
35.87711036867
12.00000000000

result:

ok 6 numbers

Test #6:

score: 0
Accepted
time: 0ms
memory: 3896kb

input:

0.25 0.80 10 5 63

output:

5.00000000000
78.76953618353
23.69238404588
68.93872495830
36.18858847628
64.19812708571
45.00040255245
62.60860230668
51.65247261863
63.00000000000

result:

ok 10 numbers

Test #7:

score: 0
Accepted
time: 0ms
memory: 3756kb

input:

0.25 0.99 3 18 30

output:

18.00000000000
48.72000000000
30.00000000000

result:

ok 3 numbers

Test #8:

score: 0
Accepted
time: 0ms
memory: 3928kb

input:

0.28 0.64 9 6 10

output:

6.00000000000
20.95040334851
9.70611293758
16.12596976557
10.72718381441
13.32423211800
10.59618263426
11.49443969311
10.00000000000

result:

ok 9 numbers

Test #9:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

0.31 0.40 7 10 49

output:

10.00000000000
240.11506399869
78.43566983959
120.36108324975
68.68620374326
69.43715646031
49.00000000000

result:

ok 7 numbers

Test #10:

score: 0
Accepted
time: 0ms
memory: 3964kb

input:

0.32 0.28 5 36 6

output:

36.00000000000
10.12137681159
13.31884057971
7.09601449275
6.00000000000

result:

ok 5 numbers

Test #11:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

0.35 0.65 10 86 82

output:

86.00000000000
79.53392478623
83.73687367518
81.00495689736
82.78070280294
81.62646796432
82.37672060942
81.88905639010
82.20603813266
82.00000000000

result:

ok 10 numbers

Test #12:

score: 0
Accepted
time: 0ms
memory: 3760kb

input:

0.36 0.68 8 72 59

output:

72.00000000000
38.23991864261
62.72637071134
48.58463813305
60.14440181161
54.68953858266
60.58642712165
59.00000000000

result:

ok 8 numbers

Test #13:

score: 0
Accepted
time: 0ms
memory: 3756kb

input:

0.43 0.61 2 93 84

output:

93.00000000000
84.00000000000

result:

ok 2 numbers

Test #14:

score: 0
Accepted
time: 1ms
memory: 3888kb

input:

0.46 0.96 6 65 35

output:

65.00000000000
-16.61742366282
54.75598511510
9.23502643664
56.81385787136
35.00000000000

result:

ok 6 numbers

Test #15:

score: 0
Accepted
time: 0ms
memory: 3964kb

input:

0.50 0.90 4 19 1

output:

19.00000000000
-6.56521739130
13.81739130435
1.00000000000

result:

ok 4 numbers

Test #16:

score: 0
Accepted
time: 0ms
memory: 4052kb

input:

0.54 0.35 3 16 22

output:

16.00000000000
30.37037037037
22.00000000000

result:

ok 3 numbers

Test #17:

score: 0
Accepted
time: 0ms
memory: 3896kb

input:

0.55 0.89 10 74 13

output:

74.00000000000
-48.32193707658
39.28293460788
-21.40090996382
23.19131132092
-6.29158864129
17.17989332290
3.84942743685
17.40729014765
13.00000000000

result:

ok 10 numbers

Test #18:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

0.56 0.36 3 31 88

output:

31.00000000000
137.21428571429
88.00000000000

result:

ok 3 numbers

Test #19:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

0.57 0.93 7 71 48

output:

71.00000000000
-34.08056536169
46.60407774384
-5.13060147238
40.41734946251
18.26642982432
48.00000000000

result:

ok 7 numbers

Test #20:

score: 0
Accepted
time: 0ms
memory: 3896kb

input:

0.58 0.41 8 30 69

output:

30.00000000000
89.43212168281
64.17063057603
73.88613562405
69.16391719812
70.40838758077
69.19407084808
69.00000000000

result:

ok 8 numbers

Test #21:

score: 0
Accepted
time: 0ms
memory: 3800kb

input:

0.58 0.49 6 31 96

output:

31.00000000000
99.55761353842
72.93341585228
91.08461182815
88.56644862794
96.00000000000

result:

ok 6 numbers

Test #22:

score: 0
Accepted
time: 1ms
memory: 3844kb

input:

0.61 0.29 8 62 25

output:

62.00000000000
34.40765125713
38.96866726685
33.74910589735
31.88786810477
29.23884025414
27.08317430541
25.00000000000

result:

ok 8 numbers

Test #23:

score: 0
Accepted
time: 0ms
memory: 4048kb

input:

0.63 0.89 9 37 85

output:

37.00000000000
-5.88785330218
29.22065241963
13.16882158543
34.30273825229
33.33097630997
51.52795211982
62.12717875136
85.00000000000

result:

ok 9 numbers

Test #24:

score: 0
Accepted
time: 0ms
memory: 3892kb

input:

0.64 0.67 2 74 42

output:

74.00000000000
42.00000000000

result:

ok 2 numbers

Test #25:

score: 0
Accepted
time: 0ms
memory: 3896kb

input:

0.65 0.56 2 94 96

output:

94.00000000000
96.00000000000

result:

ok 2 numbers

Test #26:

score: 0
Accepted
time: 0ms
memory: 3884kb

input:

0.65 0.90 10 97 23

output:

97.00000000000
-61.70357627912
47.19267541857
-24.85797962913
26.31572111778
-5.26696293966
20.26062309522
8.42913836620
23.71350072373
23.00000000000

result:

ok 10 numbers

Test #27:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

0.67 0.88 4 70 42

output:

70.00000000000
0.54782150651
61.96704040936
42.00000000000

result:

ok 4 numbers

Test #28:

score: 0
Accepted
time: 0ms
memory: 4056kb

input:

0.69 0.39 10 2 27

output:

2.00000000000
22.36590768702
16.21247630404
19.90931264772
20.06029148551
21.60623305761
22.73181448910
24.11138288995
25.50226184481
27.00000000000

result:

ok 10 numbers

Test #29:

score: 0
Accepted
time: 1ms
memory: 4044kb

input:

0.69 0.57 4 88 47

output:

88.00000000000
11.84360959755
58.33209062231
47.00000000000

result:

ok 4 numbers

Test #30:

score: 0
Accepted
time: 0ms
memory: 3940kb

input:

0.71 0.89 8 4 41

output:

4.00000000000
6.83889036269
8.41561215751
12.06169705463
16.05369972897
22.13303718619
30.00224916098
41.00000000000

result:

ok 8 numbers

Test #31:

score: 0
Accepted
time: 1ms
memory: 3812kb

input:

0.72 0.49 8 21 48

output:

21.00000000000
19.94044236994
24.64711850636
27.51674208585
31.88914236993
36.44338612841
41.86491777372
48.00000000000

result:

ok 8 numbers

Test #32:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

0.74 0.58 3 57 29

output:

57.00000000000
-5.48648648649
29.00000000000

result:

ok 3 numbers

Test #33:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

0.76 0.70 2 91 18

output:

91.00000000000
18.00000000000

result:

ok 2 numbers

Test #34:

score: 0
Accepted
time: 0ms
memory: 4048kb

input:

0.77 0.36 10 31 25

output:

31.00000000000
5.21497208503
15.17552850547
13.56254689982
15.90635137483
17.13040744256
18.91670022571
20.73280585312
22.77427258815
25.00000000000

result:

ok 10 numbers

Test #35:

score: 0
Accepted
time: 0ms
memory: 3896kb

input:

0.77 0.96 8 78 68

output:

78.00000000000
-40.09755700760
44.00488110414
-4.60989627711
38.69506572660
25.36970018346
56.68193223880
68.00000000000

result:

ok 8 numbers

Test #36:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

0.78 0.52 7 73 77

output:

73.00000000000
8.72754750605
44.76748705472
39.45696460583
54.05552566100
62.68093161061
77.00000000000

result:

ok 7 numbers

Test #37:

score: 0
Accepted
time: 0ms
memory: 3944kb

input:

0.78 0.69 4 42 97

output:

42.00000000000
57.29790511399
73.67236598891
97.00000000000

result:

ok 4 numbers

Test #38:

score: 0
Accepted
time: 0ms
memory: 3760kb

input:

0.78 0.70 10 54 99

output:

54.00000000000
-13.01288635090
27.64994864630
12.45793949848
29.07215686123
31.39684000069
44.84004500340
56.95302310314
75.81138952283
99.00000000000

result:

ok 10 numbers

Test #39:

score: 0
Accepted
time: 0ms
memory: 3940kb

input:

0.78 0.76 10 97 83

output:

97.00000000000
-43.73473695904
39.60690517195
-2.34501405475
28.27213696798
20.27005615341
37.29746789532
44.49726763494
63.05394435570
83.00000000000

result:

ok 10 numbers

Test #40:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

0.78 0.95 10 100 32

output:

100.00000000000
-63.26957881736
45.64972852246
-24.49931162898
24.25777902573
-4.35327840746
19.64933291662
11.19086518787
27.39574111733
32.00000000000

result:

ok 10 numbers

Test #41:

score: 0
Accepted
time: 0ms
memory: 3820kb

input:

0.79 0.90 10 98 42

output:

98.00000000000
-58.24691462804
42.18493744385
-19.09612258460
22.88050685763
0.88909009139
21.29483734407
17.62310258406
33.08760465107
42.00000000000

result:

ok 10 numbers

Test #42:

score: 0
Accepted
time: 0ms
memory: 3804kb

input:

0.81 0.48 10 97 1

output:

97.00000000000
-38.25750168160
15.57142363790
-5.75074766046
2.81617774122
-0.47925490664
0.96356884141
0.55044840636
0.90837625302
1.00000000000

result:

ok 10 numbers

Test #43:

score: 0
Accepted
time: 0ms
memory: 3928kb

input:

0.81 0.86 10 20 100

output:

20.00000000000
-3.33284286965
14.50039727558
8.87907692532
19.66239396651
23.56254526865
35.99532047881
49.41999851887
70.98617441206
100.00000000000

result:

ok 10 numbers

Test #44:

score: 0
Accepted
time: 0ms
memory: 3820kb

input:

0.84 0.85 10 74 95

output:

74.00000000000
-36.29080487710
32.41572390324
-3.61797606681
24.51426542163
17.51670329738
35.55115637818
44.75216916044
67.81030501622
95.00000000000

result:

ok 10 numbers

Test #45:

score: 0
Accepted
time: 0ms
memory: 4040kb

input:

0.88 0.37 10 3 96

output:

3.00000000000
29.02182849038
26.64920907153
34.18938052439
39.94686221793
47.80330954580
56.84725142094
67.71280578237
80.62075211423
96.00000000000

result:

ok 10 numbers

Test #46:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

0.91 0.50 10 100 98

output:

100.00000000000
-22.58685785448
29.44595935242
15.50239408346
28.83015829216
33.98664108759
45.34292253579
58.25538005136
75.68385711464
98.00000000000

result:

ok 10 numbers

Test #47:

score: 0
Accepted
time: 0ms
memory: 3892kb

input:

0.94 0.48 10 44 97

output:

44.00000000000
-1.58274343872
19.63222116761
17.69457104696
26.05636294460
32.98637527046
43.51424696764
56.73685227941
74.21947968711
97.00000000000

result:

ok 10 numbers

Test #48:

score: 0
Accepted
time: 0ms
memory: 3952kb

input:

0.94 0.54 10 28 95

output:

28.00000000000
0.45254630715
15.54539352872
14.85704492285
22.36013473299
29.04133090735
39.37332380872
52.69324307017
70.79324334267
95.00000000000

result:

ok 10 numbers

Test #49:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

0.95 0.57 10 2 94

output:

2.00000000000
9.22728417416
9.90591996545
14.67017594645
19.58304152944
26.96588974244
36.77992892710
50.31148963394
68.76047464069
94.00000000000

result:

ok 10 numbers

Test #50:

score: 0
Accepted
time: 0ms
memory: 4048kb

input:

0.98 0.90 10 21 99

output:

21.00000000000
-8.21319348497
10.85107038473
3.24217484056
12.94329469001
15.60238615271
26.93930365066
40.44266511509
63.87918509839
99.00000000000

result:

ok 10 numbers

Extra Test:

score: 0
Extra Test Passed