QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#640021 | #7901. Basic Substring Structure | maspy | AC ✓ | 408ms | 74936kb | C++20 | 24.2kb | 2024-10-14 01:43:15 | 2024-10-14 01:43:15 |
Judging History
answer
#line 1 "/home/maspy/compro/library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("Ofast,unroll-loops")
// いまの CF だとこれ入れると動かない?
// #pragma GCC target("avx2,popcnt")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;
template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'010'000'000;
template <>
constexpr ll infty<ll> = 2'020'000'000'000'000'000;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * 2'000'000'000'000'000'000;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
using pi = pair<ll, ll>;
using vi = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
#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__))))
// https://trap.jp/post/1224/
#define FOR1(a) for (ll _ = 0; _ < ll(a); ++_)
#define FOR2(i, a) for (ll i = 0; i < ll(a); ++i)
#define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i)
#define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c))
#define FOR1_R(a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR2_R(i, a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR3_R(i, a, b) for (ll i = (b)-1; i >= ll(a); --i)
#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) overload3(__VA_ARGS__, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)
#define FOR_subset(t, s) for (ll t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define elif else if
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define stoi stoll
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
int popcnt_mod_2(int x) { return __builtin_parity(x); }
int popcnt_mod_2(u32 x) { return __builtin_parity(x); }
int popcnt_mod_2(ll x) { return __builtin_parityll(x); }
int popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
template <typename T>
T floor(T a, T b) {
return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
T q = floor(x, y);
return {q, x - q * y};
}
template <typename T, typename U>
T SUM(const vector<U> &A) {
T sm = 0;
for (auto &&a: A) sm += a;
return sm;
}
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()
template <typename T>
T POP(deque<T> &que) {
T a = que.front();
que.pop_front();
return a;
}
template <typename T>
T POP(pq<T> &que) {
T a = que.top();
que.pop();
return a;
}
template <typename T>
T POP(pqg<T> &que) {
T a = que.top();
que.pop();
return a;
}
template <typename T>
T POP(vc<T> &que) {
T a = que.back();
que.pop_back();
return a;
}
template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
if (check_ok) assert(check(ok));
while (abs(ok - ng) > 1) {
auto x = (ng + ok) / 2;
(check(x) ? ok : ng) = x;
}
return ok;
}
template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 100) {
FOR(iter) {
double x = (ok + ng) / 2;
(check(x) ? ok : ng) = x;
}
return (ok + ng) / 2;
}
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);
}
// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
vc<int> A(S.size());
FOR(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
return A;
}
template <typename T, typename U>
vector<T> cumsum(vector<U> &A, int off = 1) {
int N = A.size();
vector<T> B(N + 1);
FOR(i, N) { B[i + 1] = B[i] + A[i]; }
if (off == 0) B.erase(B.begin());
return B;
}
// stable sort
template <typename T>
vector<int> argsort(const vector<T> &A) {
vector<int> ids(len(A));
iota(all(ids), 0);
sort(all(ids), [&](int i, int j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
return ids;
}
// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
vc<T> B(len(I));
FOR(i, len(I)) B[i] = A[I[i]];
return B;
}
template <typename T, typename... Vectors>
void concat(vc<T> &first, const Vectors &... others) {
vc<T> &res = first;
(res.insert(res.end(), others.begin(), others.end()), ...);
}
#endif
#line 1 "/home/maspy/compro/library/other/io.hpp"
#define FASTIO
#include <unistd.h>
// https://judge.yosupo.jp/submission/21623
namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf
uint32_t pil = 0, pir = 0, por = 0;
struct Pre {
char num[10000][4];
constexpr Pre() : num() {
for (int i = 0; i < 10000; i++) {
int n = i;
for (int j = 3; j >= 0; j--) {
num[i][j] = n % 10 | '0';
n /= 10;
}
}
}
} constexpr pre;
inline void load() {
memcpy(ibuf, ibuf + pil, pir - pil);
pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
pil = 0;
if (pir < SZ) ibuf[pir++] = '\n';
}
inline void flush() {
fwrite(obuf, 1, por, stdout);
por = 0;
}
void rd(char &c) {
do {
if (pil + 1 > pir) load();
c = ibuf[pil++];
} while (isspace(c));
}
void rd(string &x) {
x.clear();
char c;
do {
if (pil + 1 > pir) load();
c = ibuf[pil++];
} while (isspace(c));
do {
x += c;
if (pil == pir) load();
c = ibuf[pil++];
} while (!isspace(c));
}
template <typename T>
void rd_real(T &x) {
string s;
rd(s);
x = stod(s);
}
template <typename T>
void rd_integer(T &x) {
if (pil + 100 > pir) load();
char c;
do
c = ibuf[pil++];
while (c < '-');
bool minus = 0;
if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
if (c == '-') { minus = 1, c = ibuf[pil++]; }
}
x = 0;
while ('0' <= c) { x = x * 10 + (c & 15), c = ibuf[pil++]; }
if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
if (minus) x = -x;
}
}
void rd(int &x) { rd_integer(x); }
void rd(ll &x) { rd_integer(x); }
void rd(i128 &x) { rd_integer(x); }
void rd(u32 &x) { rd_integer(x); }
void rd(u64 &x) { rd_integer(x); }
void rd(u128 &x) { rd_integer(x); }
void rd(double &x) { rd_real(x); }
void rd(long double &x) { rd_real(x); }
void rd(f128 &x) { rd_real(x); }
template <class T, class U>
void rd(pair<T, U> &p) {
return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T>
void rd_tuple(T &t) {
if constexpr (N < std::tuple_size<T>::value) {
auto &x = std::get<N>(t);
rd(x);
rd_tuple<N + 1>(t);
}
}
template <class... T>
void rd(tuple<T...> &tpl) {
rd_tuple(tpl);
}
template <size_t N = 0, typename T>
void rd(array<T, N> &x) {
for (auto &d: x) rd(d);
}
template <class T>
void rd(vc<T> &x) {
for (auto &d: x) rd(d);
}
void read() {}
template <class H, class... T>
void read(H &h, T &... t) {
rd(h), read(t...);
}
void wt(const char c) {
if (por == SZ) flush();
obuf[por++] = c;
}
void wt(const string s) {
for (char c: s) wt(c);
}
void wt(const char *s) {
size_t len = strlen(s);
for (size_t i = 0; i < len; i++) wt(s[i]);
}
template <typename T>
void wt_integer(T x) {
if (por > SZ - 100) flush();
if (x < 0) { obuf[por++] = '-', x = -x; }
int outi;
for (outi = 96; x >= 10000; outi -= 4) {
memcpy(out + outi, pre.num[x % 10000], 4);
x /= 10000;
}
if (x >= 1000) {
memcpy(obuf + por, pre.num[x], 4);
por += 4;
} else if (x >= 100) {
memcpy(obuf + por, pre.num[x] + 1, 3);
por += 3;
} else if (x >= 10) {
int q = (x * 103) >> 10;
obuf[por] = q | '0';
obuf[por + 1] = (x - q * 10) | '0';
por += 2;
} else
obuf[por++] = x | '0';
memcpy(obuf + por, out + outi + 4, 96 - outi);
por += 96 - outi;
}
template <typename T>
void wt_real(T x) {
ostringstream oss;
oss << fixed << setprecision(15) << double(x);
string s = oss.str();
wt(s);
}
void wt(int x) { wt_integer(x); }
void wt(ll x) { wt_integer(x); }
void wt(i128 x) { wt_integer(x); }
void wt(u32 x) { wt_integer(x); }
void wt(u64 x) { wt_integer(x); }
void wt(u128 x) { wt_integer(x); }
void wt(double x) { wt_real(x); }
void wt(long double x) { wt_real(x); }
void wt(f128 x) { wt_real(x); }
template <class T, class U>
void wt(const pair<T, U> val) {
wt(val.first);
wt(' ');
wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
if constexpr (N < std::tuple_size<T>::value) {
if constexpr (N > 0) { wt(' '); }
const auto x = std::get<N>(t);
wt(x);
wt_tuple<N + 1>(t);
}
}
template <class... T>
void wt(tuple<T...> tpl) {
wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) wt(' ');
wt(val[i]);
}
}
template <class T>
void wt(const vector<T> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) wt(' ');
wt(val[i]);
}
}
void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
wt(head);
if (sizeof...(Tail)) wt(' ');
print(forward<Tail>(tail)...);
}
// gcc expansion. called automaticall after main.
void __attribute__((destructor)) _d() { flush(); }
} // namespace fastio
using fastio::read;
using fastio::print;
using fastio::flush;
#if defined(LOCAL)
#define SHOW(...) SHOW_IMPL(__VA_ARGS__, SHOW6, SHOW5, SHOW4, SHOW3, SHOW2, SHOW1)(__VA_ARGS__)
#define SHOW_IMPL(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define SHOW1(x) print(#x, "=", (x)), flush()
#define SHOW2(x, y) print(#x, "=", (x), #y, "=", (y)), flush()
#define SHOW3(x, y, z) print(#x, "=", (x), #y, "=", (y), #z, "=", (z)), flush()
#define SHOW4(x, y, z, w) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w)), flush()
#define SHOW5(x, y, z, w, v) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v)), flush()
#define SHOW6(x, y, z, w, v, u) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v), #u, "=", (u)), flush()
#else
#define SHOW(...)
#endif
#define INT(...) \
int __VA_ARGS__; \
read(__VA_ARGS__)
#define LL(...) \
ll __VA_ARGS__; \
read(__VA_ARGS__)
#define U32(...) \
u32 __VA_ARGS__; \
read(__VA_ARGS__)
#define U64(...) \
u64 __VA_ARGS__; \
read(__VA_ARGS__)
#define STR(...) \
string __VA_ARGS__; \
read(__VA_ARGS__)
#define CHAR(...) \
char __VA_ARGS__; \
read(__VA_ARGS__)
#define DBL(...) \
double __VA_ARGS__; \
read(__VA_ARGS__)
#define VEC(type, name, size) \
vector<type> name(size); \
read(name)
#define VV(type, name, h, w) \
vector<vector<type>> name(h, vector<type>(w)); \
read(name)
void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 3 "main.cpp"
#line 2 "/home/maspy/compro/library/string/zalgorithm.hpp"
template <typename STRING> // string, vector どちらでも
vector<int> zalgorithm(const STRING& s) {
int n = int(s.size());
if (n == 0) return {};
vector<int> z(n);
z[0] = 0;
for (int i = 1, j = 0; i < n; i++) {
int& k = z[i];
k = (j + z[j] <= i) ? 0 : min(j + z[j] - i, z[i - j]);
while (i + k < n && s[k] == s[i + k]) k++;
if (j + z[j] < i + z[i]) j = i;
}
z[0] = n;
return z;
}
#line 2 "/home/maspy/compro/library/string/suffix_array.hpp"
#line 2 "/home/maspy/compro/library/alg/monoid/min.hpp"
template <typename E>
struct Monoid_Min {
using X = E;
using value_type = X;
static constexpr X op(const X &x, const X &y) noexcept { return min(x, y); }
static constexpr X unit() { return infty<E>; }
static constexpr bool commute = true;
};
#line 2 "/home/maspy/compro/library/ds/sparse_table/sparse_table.hpp"
// 冪等なモノイドであることを仮定。disjoint sparse table より x 倍高速
template <class Monoid>
struct Sparse_Table {
using MX = Monoid;
using X = typename MX::value_type;
int n, log;
vvc<X> dat;
Sparse_Table() {}
Sparse_Table(int n) { build(n); }
template <typename F>
Sparse_Table(int n, F f) {
build(n, f);
}
Sparse_Table(const vc<X>& v) { build(v); }
void build(int m) {
build(m, [](int i) -> X { return MX::unit(); });
}
void build(const vc<X>& v) {
build(len(v), [&](int i) -> X { return v[i]; });
}
template <typename F>
void build(int m, F f) {
n = m, log = 1;
while ((1 << log) < n) ++log;
dat.resize(log);
dat[0].resize(n);
FOR(i, n) dat[0][i] = f(i);
FOR(i, log - 1) {
dat[i + 1].resize(len(dat[i]) - (1 << i));
FOR(j, len(dat[i]) - (1 << i)) {
dat[i + 1][j] = MX::op(dat[i][j], dat[i][j + (1 << i)]);
}
}
}
X prod(int L, int R) {
if (L == R) return MX::unit();
if (R == L + 1) return dat[0][L];
int k = topbit(R - L - 1);
return MX::op(dat[k][L], dat[k][R - (1 << k)]);
}
template <class F>
int max_right(const F check, int L) {
assert(0 <= L && L <= n && check(MX::unit()));
if (L == n) return n;
int ok = L, ng = n + 1;
while (ok + 1 < ng) {
int k = (ok + ng) / 2;
bool bl = check(prod(L, k));
if (bl) ok = k;
if (!bl) ng = k;
}
return ok;
}
template <class F>
int min_left(const F check, int R) {
assert(0 <= R && R <= n && check(MX::unit()));
if (R == 0) return 0;
int ok = R, ng = -1;
while (ng + 1 < ok) {
int k = (ok + ng) / 2;
bool bl = check(prod(k, R));
if (bl) ok = k;
if (!bl) ng = k;
}
return ok;
}
};
#line 5 "/home/maspy/compro/library/string/suffix_array.hpp"
// 辞書順 i 番目の suffix が j 文字目始まりであるとき、
// SA[i] = j, ISA[j] = i
// |S|>0 を前提(そうでない場合 dummy 文字を追加して利用せよ)
struct Suffix_Array {
vc<int> SA;
vc<int> ISA;
vc<int> LCP;
Sparse_Table<Monoid_Min<int>> seg;
bool build_seg;
Suffix_Array(string& s) {
build_seg = 0;
assert(len(s) > 0);
char first = 127, last = 0;
for (auto&& c: s) {
chmin(first, c);
chmax(last, c);
}
SA = calc_suffix_array(s, first, last);
calc_LCP(s);
}
Suffix_Array(vc<int>& s) {
build_seg = 0;
assert(len(s) > 0);
SA = calc_suffix_array(s);
calc_LCP(s);
}
// lcp(S[i:], S[j:])
int lcp(int i, int j) {
if (!build_seg) {
build_seg = true;
seg.build(LCP);
}
int n = len(SA);
if (i == n || j == n) return 0;
if (i == j) return n - i;
i = ISA[i], j = ISA[j];
if (i > j) swap(i, j);
return seg.prod(i, j);
}
// S[i:] との lcp が n 以上であるような半開区間
pair<int, int> lcp_range(int i, int n) {
if (!build_seg) {
build_seg = true;
seg.build(LCP);
}
i = ISA[i];
int a = seg.min_left([&](auto e) -> bool { return e >= n; }, i);
int b = seg.max_right([&](auto e) -> bool { return e >= n; }, i);
return {a, b + 1};
}
// -1: S[L1:R1) < S[L2, R2)
// 0: S[L1:R1) = S[L2, R2)
// +1: S[L1:R1) > S[L2, R2)
int compare(int L1, int R1, int L2, int R2) {
int n1 = R1 - L1, n2 = R2 - L2;
int n = lcp(L1, L2);
if (n == n1 && n == n2) return 0;
if (n == n1) return -1;
if (n == n2) return 1;
return (ISA[L1 + n] > ISA[L2 + n] ? 1 : -1);
}
private:
void induced_sort(const vc<int>& vect, int val_range, vc<int>& SA,
const vc<bool>& sl, const vc<int>& lms_idx) {
vc<int> l(val_range, 0), r(val_range, 0);
for (int c: vect) {
if (c + 1 < val_range) ++l[c + 1];
++r[c];
}
partial_sum(l.begin(), l.end(), l.begin());
partial_sum(r.begin(), r.end(), r.begin());
fill(SA.begin(), SA.end(), -1);
for (int i = (int)lms_idx.size() - 1; i >= 0; --i)
SA[--r[vect[lms_idx[i]]]] = lms_idx[i];
for (int i: SA)
if (i >= 1 && sl[i - 1]) SA[l[vect[i - 1]]++] = i - 1;
fill(r.begin(), r.end(), 0);
for (int c: vect) ++r[c];
partial_sum(r.begin(), r.end(), r.begin());
for (int k = (int)SA.size() - 1, i = SA[k]; k >= 1; --k, i = SA[k])
if (i >= 1 && !sl[i - 1]) { SA[--r[vect[i - 1]]] = i - 1; }
}
vc<int> SA_IS(const vc<int>& vect, int val_range) {
const int n = vect.size();
vc<int> SA(n), lms_idx;
vc<bool> sl(n);
sl[n - 1] = false;
for (int i = n - 2; i >= 0; --i) {
sl[i] = (vect[i] > vect[i + 1] || (vect[i] == vect[i + 1] && sl[i + 1]));
if (sl[i] && !sl[i + 1]) lms_idx.push_back(i + 1);
}
reverse(lms_idx.begin(), lms_idx.end());
induced_sort(vect, val_range, SA, sl, lms_idx);
vc<int> new_lms_idx(lms_idx.size()), lms_vec(lms_idx.size());
for (int i = 0, k = 0; i < n; ++i)
if (!sl[SA[i]] && SA[i] >= 1 && sl[SA[i] - 1]) {
new_lms_idx[k++] = SA[i];
}
int cur = 0;
SA[n - 1] = cur;
for (size_t k = 1; k < new_lms_idx.size(); ++k) {
int i = new_lms_idx[k - 1], j = new_lms_idx[k];
if (vect[i] != vect[j]) {
SA[j] = ++cur;
continue;
}
bool flag = false;
for (int a = i + 1, b = j + 1;; ++a, ++b) {
if (vect[a] != vect[b]) {
flag = true;
break;
}
if ((!sl[a] && sl[a - 1]) || (!sl[b] && sl[b - 1])) {
flag = !((!sl[a] && sl[a - 1]) && (!sl[b] && sl[b - 1]));
break;
}
}
SA[j] = (flag ? ++cur : cur);
}
for (size_t i = 0; i < lms_idx.size(); ++i) lms_vec[i] = SA[lms_idx[i]];
if (cur + 1 < (int)lms_idx.size()) {
auto lms_SA = SA_IS(lms_vec, cur + 1);
for (size_t i = 0; i < lms_idx.size(); ++i) {
new_lms_idx[i] = lms_idx[lms_SA[i]];
}
}
induced_sort(vect, val_range, SA, sl, new_lms_idx);
return SA;
}
vc<int> calc_suffix_array(const string& s, const char first = 'a',
const char last = 'z') {
vc<int> vect(s.size() + 1);
copy(begin(s), end(s), begin(vect));
for (auto& x: vect) x -= (int)first - 1;
vect.back() = 0;
auto ret = SA_IS(vect, (int)last - (int)first + 2);
ret.erase(ret.begin());
return ret;
}
vc<int> calc_suffix_array(const vc<int>& s) {
vc<int> ss = s;
UNIQUE(ss);
vc<int> vect(s.size() + 1);
copy(all(s), vect.begin());
for (auto& x: vect) x = LB(ss, x) + 1;
vect.back() = 0;
auto ret = SA_IS(vect, MAX(vect) + 2);
ret.erase(ret.begin());
return ret;
}
template <typename STRING>
void calc_LCP(const STRING& s) {
int n = s.size(), k = 0;
ISA.resize(n);
LCP.resize(n);
for (int i = 0; i < n; i++) ISA[SA[i]] = i;
for (int i = 0; i < n; i++, k ? k-- : 0) {
if (ISA[i] == n - 1) {
k = 0;
continue;
}
int j = SA[ISA[i] + 1];
while (i + k < n && j + k < n && s[i + k] == s[j + k]) k++;
LCP[ISA[i]] = k;
}
LCP.resize(n - 1);
}
};
#line 6 "main.cpp"
/*
何かが変わる可能性があるところ
lcp になっている文字が変わる → 答は小さくなる
lcp の末尾が変わると得するパターンがある
この変化を全部調べればよい
different にする義務がある!
*/
void solve() {
LL(N);
VEC(int, A, N);
vc<int> Z = zalgorithm(A);
Suffix_Array X(A);
vi F(N, Z[0]);
vc<map<int, int>> G(N);
vi ANS(N);
// iP[i]+Q[i]
vi P(N + 1), Q(N + 1);
auto add = [&](int L, int R, int a, int b) -> void { P[L] += a, P[R] -= a, Q[L] += b, Q[R] -= b; };
auto calc = [&](int i, int x, int j) -> int {
vc<int> cut;
cut.eb(i);
if (j <= i) cut.eb(i - j);
auto at = [&](int p) -> int {
if (p == N) return -1;
return (p == i ? x : A[p]);
};
UNIQUE(cut);
int n = Z[j];
chmin(n, cut[0]);
if (n < cut[0]) return n;
if (at(n) != at(j + n)) return n;
n = n + 1 + X.lcp(n + 1, j + n + 1);
if (len(cut) == 1) return n;
chmin(n, cut[1]);
if (n < cut[1]) return n;
if (at(n) != at(j + n)) return n;
return n + 1 + X.lcp(n + 1, j + n + 1);
};
FOR(j, 1, N) {
int n = Z[j];
// 特殊 n, j, j+n
vc<int> cut;
for (int i: {0, n, int(j), int(j + n), int(N), int(j) + Z[j]}) { cut.eb(max(i - 1, 0)), cut.eb(i), cut.eb(min<int>(i + 1, N)); }
UNIQUE(cut);
FOR(p, len(cut) - 1) {
int L = cut[p], R = cut[p + 1];
if (R == L + 1) {
F[L] += calc(L, infty<int>, j);
vc<int> cand;
for (auto& i: {L - j, L + j}) {
if (0 <= i && i < N) { cand.eb(A[i]); }
}
UNIQUE(cand);
for (auto& x: cand) {
int add = calc(L, x, j) - calc(L, infty<int>, j);
SHOW(j, L, add);
G[L][x] += add;
}
continue;
}
if (L < Z[j] && L < j) {
add(L, R, 1, 0);
// FOR(i, L, R) F[i] += i;
}
if (L < Z[j] && j < L) {
// FOR(i, L, R) F[i] += i - j;
add(L, R, 1, -j);
}
if (Z[j] < L && L < j) {
// FOR(i, L, R) F[i] += Z[j];
add(L, R, 0, Z[j]);
}
if (Z[j] < L && j < L) {
if (Z[j] < L - j) {
// FOR(i, L, R) F[i] += min<int>(Z[j], i - j);
add(L, R, 0, Z[j]);
} else {
// FOR(i, L, R) F[i] += min<int>(Z[j], i - j);
add(L, R, 1, -j);
}
}
}
}
P = cumsum<ll>(P, 0);
Q = cumsum<ll>(Q, 0);
FOR(i, N) F[i] += i * P[i] + Q[i];
SHOW(F);
FOR(i, N) {
ll ans = F[i];
for (auto& [a, b]: G[i])
if (a != A[i]) {
SHOW(i, a, b, F[i] + b);
chmax(ans, F[i] + b);
}
ANS[i] = ans;
}
ll ans = 0;
FOR(i, N) ans += (ANS[i] ^ (1 + i));
print(ans);
}
signed main() {
INT(T);
FOR(T) solve();
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4016kb
input:
2 4 2 1 1 2 12 1 1 4 5 1 4 1 9 1 9 8 10
output:
15 217
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 86ms
memory: 4180kb
input:
10000 8 2 1 2 1 1 1 2 2 9 2 2 1 2 1 2 1 2 1 15 2 1 2 1 1 1 1 2 2 1 2 1 2 2 1 2 1 1 10 2 1 1 1 2 2 1 1 2 2 3 2 1 2 11 1 2 2 1 1 2 1 2 2 1 1 14 2 1 1 1 1 2 1 1 1 2 2 1 2 1 12 2 2 2 1 2 2 2 1 1 2 1 2 4 2 1 1 2 8 1 2 2 2 1 2 1 1 8 1 1 2 1 2 1 1 1 6 2 1 1 1 2 2 14 2 2 1 1 1 1 2 2 2 1 2 2 1 1 10 1 2 2 1 1...
output:
94 128 347 3 211 9 265 363 278 15 95 114 58 348 225 3 335 364 377 316 3 19 122 66 15 83 36 258 11 63 28 90 85 103 252 191 21 48 303 63 102 20 24 68 316 362 266 309 355 281 326 281 231 312 3 330 54 328 3 69 32 147 322 39 338 90 242 3 165 346 245 20 155 3 404 393 392 81 269 360 20 54 21 279 3 17 351 3...
result:
ok 10000 lines
Test #3:
score: 0
Accepted
time: 156ms
memory: 3948kb
input:
10000 17 1 2 2 2 2 2 2 2 1 1 2 2 1 2 1 2 2 17 2 1 1 1 1 2 2 2 1 1 1 1 1 2 2 2 2 13 2 2 2 1 2 2 2 2 1 1 1 1 1 12 2 2 1 2 1 2 2 1 1 1 1 1 13 2 2 2 1 1 1 1 2 2 2 2 1 1 20 2 1 2 2 1 2 2 2 2 2 2 1 2 2 2 2 1 2 1 1 13 1 2 1 2 2 2 1 2 1 2 1 1 1 20 2 1 1 2 2 1 2 2 1 1 2 1 2 2 2 2 2 1 2 2 12 2 1 2 1 1 2 2 1 2...
output:
392 434 308 252 302 895 343 867 282 249 717 194 252 350 230 427 439 279 340 384 380 292 218 312 271 810 275 211 460 388 365 342 773 203 238 857 720 497 514 443 618 777 372 242 337 232 324 837 289 480 366 681 358 281 320 529 451 309 250 326 315 744 307 841 133 214 411 788 332 365 488 157 760 278 421 ...
result:
ok 10000 lines
Test #4:
score: 0
Accepted
time: 148ms
memory: 3884kb
input:
10000 10 3 3 1 2 2 3 3 3 2 3 13 1 2 1 2 1 1 3 1 2 2 1 3 1 14 1 2 1 2 3 3 2 3 1 2 2 2 3 3 10 1 1 1 1 1 1 3 2 1 2 19 1 3 3 3 1 3 3 2 1 1 1 3 2 2 1 2 1 3 2 12 1 3 1 3 1 1 3 2 3 3 2 3 11 1 1 1 2 2 3 1 1 3 1 1 12 3 2 2 1 3 3 2 1 1 3 3 2 11 2 2 3 2 3 1 3 1 2 1 1 20 3 1 2 2 3 1 3 3 1 3 3 2 3 3 3 2 3 1 1 2 ...
output:
191 285 325 207 420 281 215 280 151 754 365 199 94 418 318 377 414 285 373 362 111 358 332 117 185 326 89 404 229 386 307 285 421 232 321 329 506 372 386 364 153 582 313 356 152 129 424 366 382 280 363 370 273 294 388 389 807 388 459 280 114 310 211 368 150 166 793 211 793 393 102 427 399 408 584 38...
result:
ok 10000 lines
Test #5:
score: 0
Accepted
time: 145ms
memory: 3896kb
input:
10000 14 9 9 13 6 3 8 7 10 5 9 14 2 12 5 15 9 12 2 2 8 4 2 11 4 4 8 3 8 13 15 19 5 7 1 2 9 2 16 9 15 8 19 9 3 18 8 8 1 12 6 14 9 8 2 11 7 2 12 5 14 14 10 5 7 2 11 4 4 2 9 9 11 10 3 3 2 2 14 8 2 9 10 10 11 6 9 12 5 5 4 9 2 20 4 5 3 13 15 18 12 6 2 8 11 12 6 10 14 14 10 14 13 12 14 11 9 7 5 12 12 5 3 ...
output:
307 362 380 107 97 137 380 108 135 299 312 265 99 362 379 361 332 380 129 367 97 380 97 107 363 107 132 367 97 88 363 314 100 382 354 349 383 95 359 306 340 133 382 106 395 361 374 105 292 385 360 359 365 381 378 107 374 111 357 105 365 319 379 102 364 89 107 374 128 101 360 115 363 107 106 116 92 3...
result:
ok 10000 lines
Test #6:
score: 0
Accepted
time: 217ms
memory: 4356kb
input:
1331 128 1 1 2 1 1 1 1 1 1 1 1 1 1 2 2 2 1 1 2 1 2 2 1 1 2 1 2 1 2 1 2 2 1 2 1 2 2 2 1 2 1 2 2 2 2 2 1 2 1 2 2 1 1 2 2 1 1 1 1 2 2 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 2 2 2 2 2 1 2 1 2 1 2 2 1 1 2 1 1 2 2 2 1 1 2 2 2 1 2 2 2 1 2 1 1 1 2 2 1 1 1 2 1 1 1 1 1 1 1 2 2 2 2 115 1 2 2 1 2 2 1 2 2 1 2 1 2 2 2 1...
output:
41073 22779 19964 77764 77960 62759 68522 21651 24781 42049 74437 19840 74378 68878 20605 34809 20231 20004 50820 29156 52217 53156 23540 67367 57400 46500 19870 60423 66032 51371 59540 51300 48277 22751 77712 65779 21946 37124 65635 40091 27911 55656 54005 18564 25013 64077 46260 21753 62329 69899 ...
result:
ok 1331 lines
Test #7:
score: 0
Accepted
time: 198ms
memory: 4176kb
input:
131 1471 2 3 2 3 1 2 2 1 1 1 1 2 1 3 2 1 1 1 2 2 2 2 2 2 3 1 3 2 1 2 3 2 3 1 3 1 2 1 3 1 3 1 3 2 2 1 3 3 3 1 1 1 3 2 2 2 1 2 1 3 1 3 3 1 2 2 1 2 3 1 3 1 3 3 2 1 3 3 2 3 2 2 2 1 3 2 1 2 2 1 3 1 1 3 2 3 1 1 2 1 2 3 2 1 3 3 2 2 2 2 1 1 1 2 3 1 1 3 3 2 3 2 1 3 1 3 3 2 2 1 2 1 1 2 1 3 2 1 2 2 3 2 2 1 1 3...
output:
4103972 1822893 4056671 4581950 1797128 5452459 5578024 6135700 4325429 1769997 1239977 1589696 5346072 1818448 5380837 3882106 3814365 1823901 4911982 5946018 5208392 4261893 1767953 5781183 4624024 1795249 1600563 1677098 4679442 4113663 1685240 1576241 5128042 1618422 4440641 4326472 5703872 3748...
result:
ok 131 lines
Test #8:
score: 0
Accepted
time: 183ms
memory: 4256kb
input:
131 1104 15 10 15 18 8 16 25 26 11 19 4 5 9 15 20 8 8 1 5 12 6 15 15 9 19 6 20 8 9 10 12 1 7 26 9 15 26 14 18 24 25 4 9 20 16 18 25 10 8 2 15 14 26 19 22 17 8 7 23 19 22 26 23 4 26 8 16 6 19 5 17 4 9 25 7 14 19 26 9 21 23 7 20 2 12 22 23 24 20 11 23 23 7 13 6 26 25 10 8 17 23 15 14 20 16 7 21 8 11 1...
output:
1585911 1671116 2074604 2071604 2066710 1571959 1699180 1597972 1573443 2062834 1968749 1670339 1696389 1700722 1574014 1673122 6093159 1965764 1966052 2084891 1597710 1989656 2054890 1659456 1601397 1982947 1675608 2075393 1694022 1992153 6012239 1675824 1987812 1589514 2063346 1986943 1571712 1671...
result:
ok 131 lines
Test #9:
score: 0
Accepted
time: 255ms
memory: 9352kb
input:
14 554 232 178 169 417 93 38 93 537 212 211 313 227 432 269 475 489 459 286 318 534 118 160 223 534 275 382 482 331 3 279 73 513 403 277 34 497 462 397 280 218 395 498 201 548 8 520 495 397 545 528 401 58 418 3 494 260 251 496 212 552 243 151 78 385 441 73 271 337 283 39 162 1 501 357 126 452 416 34...
output:
394027 127388087 408947528 132597056 403149770 403022905 410881136 404226176 134192573 106965642 108543004 108541542 109002658 408924618
result:
ok 14 lines
Test #10:
score: 0
Accepted
time: 408ms
memory: 68112kb
input:
1 200000 86045 57533 29508 181370 17680 186294 134595 82393 109229 189798 133533 194579 11412 112604 572 32659 76824 177596 106427 60375 98302 93821 34541 125615 108609 22507 166292 195457 151376 54630 166314 85832 192590 85410 149595 46737 54738 198246 56457 189628 135013 63949 28359 65601 162502 4...
output:
32219923494
result:
ok single line: '32219923494'
Test #11:
score: 0
Accepted
time: 195ms
memory: 7968kb
input:
14 11651 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 1 2...
output:
638847269 762853260 1772624286 1459420676 912238973 902965748 1461240613 1591772671 978996498 1450864204 913255377 276655999 898402422 1129219843
result:
ok 14 lines
Test #12:
score: 0
Accepted
time: 204ms
memory: 53912kb
input:
1 200000 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 1 2...
output:
241162217617
result:
ok single line: '241162217617'
Test #13:
score: 0
Accepted
time: 205ms
memory: 56656kb
input:
1 200000 1 2 3 2 3 1 3 1 2 2 3 1 3 1 2 1 2 3 3 1 2 1 2 3 2 3 1 2 3 1 3 1 2 1 2 3 3 1 2 1 2 3 2 3 1 1 2 3 2 3 1 3 1 2 3 1 2 1 2 3 2 3 1 1 2 3 2 3 1 3 1 2 2 3 1 3 1 2 1 2 3 2 3 1 3 1 2 1 2 3 3 1 2 1 2 3 2 3 1 1 2 3 2 3 1 3 1 2 3 1 2 1 2 3 2 3 1 1 2 3 2 3 1 3 1 2 2 3 1 3 1 2 1 2 3 1 2 3 2 3 1 3 1 2 2 3...
output:
179830061352
result:
ok single line: '179830061352'
Test #14:
score: 0
Accepted
time: 222ms
memory: 39416kb
input:
2 147441 101973 109734 101973 101973 109734 101973 109734 101973 101973 109734 101973 101973 109734 101973 109734 101973 101973 109734 101973 109734 101973 101973 109734 101973 101973 109734 101973 109734 101973 101973 109734 101973 101973 109734 101973 109734 101973 101973 109734 101973 109734 1019...
output:
319151712710 36323502547
result:
ok 2 lines
Test #15:
score: 0
Accepted
time: 224ms
memory: 52524kb
input:
1 200000 90579 86359 90579 90579 86359 90579 86359 90579 90579 86359 90579 90579 86359 90579 86359 90579 90579 86359 90579 86359 90579 90579 86359 90579 90579 86359 90579 86359 90579 90579 86359 90579 90579 86359 90579 86359 90579 90579 86359 90579 86359 90579 90579 86359 90579 90579 86359 90579 863...
output:
605969434886
result:
ok single line: '605969434886'
Test #16:
score: 0
Accepted
time: 206ms
memory: 52716kb
input:
1 200000 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 2 1...
output:
142983226845641
result:
ok single line: '142983226845641'
Test #17:
score: 0
Accepted
time: 190ms
memory: 54508kb
input:
1 200000 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2...
output:
666704973725917
result:
ok single line: '666704973725917'
Test #18:
score: 0
Accepted
time: 168ms
memory: 54012kb
input:
1 200000 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 23 24 ...
output:
1000022503780497
result:
ok single line: '1000022503780497'
Test #19:
score: 0
Accepted
time: 193ms
memory: 8380kb
input:
15 13418 7463 7463 7463 7463 9685 7463 1028 1028 9685 7463 9685 9685 7463 9685 7463 9685 9685 7463 7463 9685 7463 7463 7463 9685 7606 9685 1028 1028 9685 9685 9685 7463 1028 9685 9685 9685 9685 7463 3766 3766 7463 9685 9685 7132 7132 9685 1028 7463 3766 1028 7463 1028 9685 9685 1028 3766 9685 9685 3...
output:
310854214 1449822 411519250 114103279 422847646 111080594 345051865 115761752 373321070 416817676 270343906 133687081 436456350 116337980 244991146
result:
ok 15 lines
Test #20:
score: 0
Accepted
time: 218ms
memory: 8768kb
input:
13 14791 2035 8168 8168 2035 2035 2035 8168 2035 2035 8168 2035 2035 2035 2035 2035 2035 2035 2035 2035 8168 2035 2035 2035 2035 2035 2035 2035 2035 2035 8168 2035 2035 2035 2035 2035 2035 2035 2035 2035 8168 2035 2035 8168 2035 2812 2035 8168 2035 8168 2035 8168 2035 2035 8168 8168 9546 2035 2035 2...
output:
371530128 851134952 1442447610 1086437389 1314950262 1069313993 1418963743 58759634 413581446 389752815 405059048 222613748 292855398
result:
ok 13 lines
Test #21:
score: 0
Accepted
time: 239ms
memory: 7988kb
input:
15 12956 1461 1461 1461 1461 1461 1461 12553 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 12553 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 1461 12553 1461 1461 146...
output:
949186410 1955289437 1313255408 642243147 6111494 1702549476 1650717366 1049298027 1087170445 1259299037 3413417858 1529936217 776579634 1552800994 1881266475
result:
ok 15 lines
Test #22:
score: 0
Accepted
time: 231ms
memory: 7916kb
input:
15 14395 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 13111 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 12206 122...
output:
2957212969 1012208565 4531357191 3436243590 1743046033 9523735 500043796 2288646068 1429987616 2528370581 2183643497 375636659 2556639949 4614333790 7205785399
result:
ok 15 lines
Test #23:
score: 0
Accepted
time: 217ms
memory: 55404kb
input:
1 200000 70309 96346 70309 70309 70309 92160 96346 70309 70309 96346 92160 70309 171045 70309 96346 96346 92160 96346 96346 190333 190333 70309 96346 127508 96346 92160 92160 70309 70309 70309 70309 92160 92160 70309 70309 70309 70309 127508 70309 92160 92160 70309 70309 70309 125471 96346 127508 12...
output:
118752316928
result:
ok single line: '118752316928'
Test #24:
score: 0
Accepted
time: 255ms
memory: 50788kb
input:
1 200000 94840 94840 94840 94840 94840 94840 94840 94840 61989 61989 94840 94840 94840 94840 94840 94840 94840 61989 61989 61989 94840 94840 94840 61989 94840 94840 137895 94840 94840 137895 94840 61989 94840 94840 94840 94840 137895 94840 94840 94840 94840 94840 94840 61989 94840 61989 94840 94840 ...
output:
181441989888
result:
ok single line: '181441989888'
Test #25:
score: 0
Accepted
time: 254ms
memory: 49504kb
input:
1 200000 127581 127581 127581 127581 127581 127581 127581 127581 127581 127581 127581 127581 127581 127581 127581 127581 127581 127581 106778 127581 127581 126279 127581 127581 127581 127581 127581 127581 127581 127581 127581 127581 127581 106778 127581 127581 127581 127581 127581 127581 127581 1275...
output:
342833548104
result:
ok single line: '342833548104'
Test #26:
score: 0
Accepted
time: 240ms
memory: 49496kb
input:
1 200000 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 108121 1081...
output:
324538309517137
result:
ok single line: '324538309517137'
Test #27:
score: 0
Accepted
time: 179ms
memory: 8724kb
input:
15 10201 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9678 7129 9678 6735 9...
output:
66439462066 251506268492 47876221702 360857682629 170540379619 372628422983 120664261073 90488919597 131928493181 245296890810 147831394137 71074052989 200069312998 99252210523 114381508405
result:
ok 15 lines
Test #28:
score: 0
Accepted
time: 205ms
memory: 8448kb
input:
14 16198 7198 10333 7198 8585 7198 10333 7198 11443 7198 10333 7198 8585 7198 10333 7198 7479 7198 10333 7198 8585 7198 10333 7198 11443 7198 10333 7198 8585 7198 10333 7198 15505 7198 10333 7198 8585 7198 10333 7198 11443 7198 10333 7198 8585 7198 10333 7198 7479 7198 10333 7198 8585 7198 10333 719...
output:
33797343297 22554529801 20751677835 62270648577 32014149216 12021999751 12471359017 41454739199 39883 8044814272 40206190585 57228063674 55271122747 21989607289
result:
ok 14 lines
Test #29:
score: 0
Accepted
time: 204ms
memory: 8192kb
input:
15 10719 3676 2811 3676 4133 3676 2811 3676 9001 3676 2811 3676 4133 3676 2811 3676 9153 3676 2811 3676 4133 3676 2811 3676 9001 3676 2811 3676 4133 3676 2811 3676 3616 3676 2811 3676 4133 3676 2811 3676 9001 3676 2811 3676 4133 3676 2811 3676 9153 3676 2811 3676 4133 3676 2811 3676 9001 3676 2811 3...
output:
839203489 1583465103 1267108649 1161524911 983492553 1703733329 2346605125 1321148771 2395175732 1794419616 9621305 1338471889 2718202141 2229391426 2130319327
result:
ok 15 lines
Test #30:
score: 0
Accepted
time: 170ms
memory: 53932kb
input:
1 200000 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062 146800 55062...
output:
1000022503780497
result:
ok single line: '1000022503780497'
Test #31:
score: 0
Accepted
time: 188ms
memory: 55264kb
input:
1 200000 72765 178599 72765 75116 72765 178599 72765 75116 72765 178599 72765 75116 72765 178599 72765 75116 72765 178599 72765 75116 72765 178599 72765 75116 72765 178599 72765 75116 72765 178599 72765 75116 72765 178599 72765 75116 72765 178599 72765 75116 72765 178599 72765 75116 72765 178599 727...
output:
500036262654563
result:
ok single line: '500036262654563'
Test #32:
score: 0
Accepted
time: 211ms
memory: 57328kb
input:
1 200000 27791 128643 27791 193841 27791 128643 27791 133709 27791 128643 27791 193841 27791 128643 27791 119129 27791 128643 27791 193841 27791 128643 27791 133709 27791 128643 27791 193841 27791 128643 27791 50096 27791 128643 27791 193841 27791 128643 27791 133709 27791 128643 27791 193841 27791 ...
output:
2142743374731
result:
ok single line: '2142743374731'
Test #33:
score: 0
Accepted
time: 204ms
memory: 57396kb
input:
1 200000 5270 20262 5270 159584 5270 20262 5270 79361 5270 20262 5270 159584 5270 20262 5270 85380 5270 20262 5270 159584 5270 20262 5270 79361 5270 20262 5270 159584 5270 20262 5270 88540 5270 20262 5270 159584 5270 20262 5270 79361 5270 20262 5270 159584 5270 20262 5270 85380 5270 20262 5270 15958...
output:
333618035630
result:
ok single line: '333618035630'
Test #34:
score: 0
Accepted
time: 79ms
memory: 18856kb
input:
1 65535 3747 3747 3747 10894 3747 3747 3747 10894 3747 3747 3747 10894 3747 3747 3747 26741 3747 3747 3747 10894 3747 3747 3747 10894 3747 3747 3747 10894 3747 3747 3747 26741 3747 3747 3747 10894 3747 3747 3747 10894 3747 3747 3747 10894 3747 3747 3747 26741 3747 3747 3747 10894 3747 3747 3747 1089...
output:
47438786836
result:
ok single line: '47438786836'
Test #35:
score: 0
Accepted
time: 38ms
memory: 12264kb
input:
1 35279 8061 20053 8061 20053 8061 7600 8061 20053 8061 20053 8061 7600 8061 20053 8061 20053 8061 7600 8061 20053 8061 20053 8061 3625 8061 20053 8061 20053 8061 7600 8061 20053 8061 20053 8061 7600 8061 20053 8061 20053 8061 7600 8061 20053 8061 20053 8061 3625 8061 20053 8061 20053 8061 7600 8061...
output:
14553907525
result:
ok single line: '14553907525'
Test #36:
score: 0
Accepted
time: 54ms
memory: 14056kb
input:
1 46655 16305 16305 16305 16305 16305 25259 16305 16305 16305 16305 16305 25259 16305 16305 16305 16305 16305 25259 16305 16305 16305 16305 16305 25259 16305 16305 16305 16305 16305 25259 16305 16305 16305 16305 16305 44685 16305 16305 16305 16305 16305 25259 16305 16305 16305 16305 16305 25259 1630...
output:
29457295223
result:
ok single line: '29457295223'
Test #37:
score: 0
Accepted
time: 1ms
memory: 4084kb
input:
1 446 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 276 27...
output:
22257618
result:
ok single line: '22257618'
Test #38:
score: 0
Accepted
time: 102ms
memory: 23640kb
input:
1 88199 42997 42997 42997 42997 17665 42997 42997 42997 42997 17665 42997 42997 42997 42997 17665 42997 42997 42997 42997 17665 42997 42997 42997 42997 17665 42997 42997 42997 42997 17665 42997 42997 42997 42997 2010 42997 42997 42997 42997 17665 42997 42997 42997 42997 17665 42997 42997 42997 42997...
output:
109207566120
result:
ok single line: '109207566120'
Test #39:
score: 0
Accepted
time: 88ms
memory: 24932kb
input:
1 89999 85746 85746 17901 85746 85746 82896 85746 85746 17901 85746 85746 82896 85746 85746 17901 85746 85746 82896 85746 85746 17901 85746 85746 82896 85746 85746 17901 85746 85746 82896 85746 85746 17901 85746 85746 82896 85746 85746 17901 85746 85746 82896 85746 85746 17901 85746 85746 82896 8574...
output:
30384952146665
result:
ok single line: '30384952146665'
Test #40:
score: 0
Accepted
time: 81ms
memory: 23340kb
input:
1 79999 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 36820 52225 3682...
output:
45337130318924
result:
ok single line: '45337130318924'
Test #41:
score: 0
Accepted
time: 10ms
memory: 5284kb
input:
1 8199 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 2353 1489 235...
output:
68933371983
result:
ok single line: '68933371983'
Test #42:
score: 0
Accepted
time: 20ms
memory: 7684kb
input:
1 19999 17486 17486 17486 17486 17486 17486 17486 17486 17486 13014 17486 17486 17486 17486 17486 17486 17486 17486 17486 13014 17486 17486 17486 17486 17486 17486 17486 17486 17486 13014 17486 17486 17486 17486 17486 17486 17486 17486 17486 13014 17486 17486 17486 17486 17486 17486 17486 17486 1748...
output:
5406246293
result:
ok single line: '5406246293'
Test #43:
score: 0
Accepted
time: 338ms
memory: 74936kb
input:
1 200000 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 60522 605...
output:
750042248291481
result:
ok single line: '750042248291481'
Extra Test:
score: 0
Extra Test Passed