QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#696650 | #7901. Basic Substring Structure | ucup-team3646# | TL | 843ms | 64188kb | C++20 | 22.9kb | 2024-11-01 00:06:18 | 2024-11-01 00:06:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define elif else if
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int,int>
#define repname(a, b, c, d, e, ...) e
#define rep(...) repname(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__)
#define rep0(x) for (int rep_counter = 0; rep_counter < (x); ++rep_counter)
#define rep1(i, x) for (int i = 0; i < (x); ++i)
#define rep2(i, l, r) for (int i = (l); i < (r); ++i)
#define rep3(i, l, r, c) for (int i = (l); i < (r); i += (c))
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
struct ScalarInput {
template<class T>
operator T(){
T ret;
cin >> ret;
return ret;
}
};
struct VectorInput {
size_t n;
VectorInput(size_t n): n(n) {}
template<class T>
operator vector<T>(){
vector<T> ret(n);
for(T &x : ret) cin >> x;
return ret;
}
};
ScalarInput input(){ return ScalarInput(); }
VectorInput input(size_t n){ return VectorInput(n); }
template<typename T>
void print(vector<T> a){
for(int i=0;i<a.size();i++){
cout<<a[i]<<" \n"[i+1==a.size()];
}
}
template<class T>
void print(T x){
cout << x << '\n';
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail){
cout << head << ' ';
print(forward<Tail>(tail)...);
}
#include <cassert>
#include <numeric>
#include <type_traits>
#ifdef _MSC_VER
#include <intrin.h>
#endif
#include <utility>
#ifdef _MSC_VER
#include <intrin.h>
#endif
namespace atcoder {
namespace internal {
constexpr long long safe_mod(long long x, long long m) {
x %= m;
if (x < 0) x += m;
return x;
}
struct barrett {
unsigned int _m;
unsigned long long im;
explicit barrett(unsigned int m) : _m(m), im((unsigned long long)(-1) / m + 1) {}
unsigned int umod() const { return _m; }
unsigned int mul(unsigned int a, unsigned int b) const {
unsigned long long z = a;
z *= b;
#ifdef _MSC_VER
unsigned long long x;
_umul128(z, im, &x);
#else
unsigned long long x =
(unsigned long long)(((unsigned __int128)(z)*im) >> 64);
#endif
unsigned long long y = x * _m;
return (unsigned int)(z - y + (z < y ? _m : 0));
}
};
constexpr long long pow_mod_constexpr(long long x, long long n, int m) {
if (m == 1) return 0;
unsigned int _m = (unsigned int)(m);
unsigned long long r = 1;
unsigned long long y = safe_mod(x, m);
while (n) {
if (n & 1) r = (r * y) % _m;
y = (y * y) % _m;
n >>= 1;
}
return r;
}
constexpr bool is_prime_constexpr(int n) {
if (n <= 1) return false;
if (n == 2 || n == 7 || n == 61) return true;
if (n % 2 == 0) return false;
long long d = n - 1;
while (d % 2 == 0) d /= 2;
constexpr long long bases[3] = {2, 7, 61};
for (long long a : bases) {
long long t = d;
long long y = pow_mod_constexpr(a, t, n);
while (t != n - 1 && y != 1 && y != n - 1) {
y = y * y % n;
t <<= 1;
}
if (y != n - 1 && t % 2 == 0) {
return false;
}
}
return true;
}
template <int n> constexpr bool is_prime = is_prime_constexpr(n);
constexpr std::pair<long long, long long> inv_gcd(long long a, long long b) {
a = safe_mod(a, b);
if (a == 0) return {b, 0};
long long s = b, t = a;
long long m0 = 0, m1 = 1;
while (t) {
long long u = s / t;
s -= t * u;
m0 -= m1 * u; // |m1 * u| <= |m1| * s <= b
auto tmp = s;
s = t;
t = tmp;
tmp = m0;
m0 = m1;
m1 = tmp;
}
if (m0 < 0) m0 += b / s;
return {s, m0};
}
constexpr int primitive_root_constexpr(int m) {
if (m == 2) return 1;
if (m == 167772161) return 3;
if (m == 469762049) return 3;
if (m == 754974721) return 11;
if (m == 998244353) return 3;
int divs[20] = {};
divs[0] = 2;
int cnt = 1;
int x = (m - 1) / 2;
while (x % 2 == 0) x /= 2;
for (int i = 3; (long long)(i)*i <= x; i += 2) {
if (x % i == 0) {
divs[cnt++] = i;
while (x % i == 0) {
x /= i;
}
}
}
if (x > 1) {
divs[cnt++] = x;
}
for (int g = 2;; g++) {
bool ok = true;
for (int i = 0; i < cnt; i++) {
if (pow_mod_constexpr(g, (m - 1) / divs[i], m) == 1) {
ok = false;
break;
}
}
if (ok) return g;
}
}
template <int m> constexpr int primitive_root = primitive_root_constexpr(m);
unsigned long long floor_sum_unsigned(unsigned long long n,
unsigned long long m,
unsigned long long a,
unsigned long long b) {
unsigned long long ans = 0;
while (true) {
if (a >= m) {
ans += n * (n - 1) / 2 * (a / m);
a %= m;
}
if (b >= m) {
ans += n * (b / m);
b %= m;
}
unsigned long long y_max = a * n + b;
if (y_max < m) break;
n = (unsigned long long)(y_max / m);
b = (unsigned long long)(y_max % m);
std::swap(m, a);
}
return ans;
}
} // namespace internal
} // namespace atcoder
#include <cassert>
#include <numeric>
#include <type_traits>
namespace atcoder {
namespace internal {
#ifndef _MSC_VER
template <class T>
using is_signed_int128 =
typename std::conditional<std::is_same<T, __int128_t>::value ||
std::is_same<T, __int128>::value,
std::true_type,
std::false_type>::type;
template <class T>
using is_unsigned_int128 =
typename std::conditional<std::is_same<T, __uint128_t>::value ||
std::is_same<T, unsigned __int128>::value,
std::true_type,
std::false_type>::type;
template <class T>
using make_unsigned_int128 =
typename std::conditional<std::is_same<T, __int128_t>::value,
__uint128_t,
unsigned __int128>;
template <class T>
using is_integral = typename std::conditional<std::is_integral<T>::value ||
is_signed_int128<T>::value ||
is_unsigned_int128<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using is_signed_int = typename std::conditional<(is_integral<T>::value &&
std::is_signed<T>::value) ||
is_signed_int128<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using is_unsigned_int =
typename std::conditional<(is_integral<T>::value &&
std::is_unsigned<T>::value) ||
is_unsigned_int128<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using to_unsigned = typename std::conditional<
is_signed_int128<T>::value,
make_unsigned_int128<T>,
typename std::conditional<std::is_signed<T>::value,
std::make_unsigned<T>,
std::common_type<T>>::type>::type;
#else
template <class T> using is_integral = typename std::is_integral<T>;
template <class T>
using is_signed_int =
typename std::conditional<is_integral<T>::value && std::is_signed<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using is_unsigned_int =
typename std::conditional<is_integral<T>::value &&
std::is_unsigned<T>::value,
std::true_type,
std::false_type>::type;
template <class T>
using to_unsigned = typename std::conditional<is_signed_int<T>::value,
std::make_unsigned<T>,
std::common_type<T>>::type;
#endif
template <class T>
using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>;
template <class T>
using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>;
template <class T> using to_unsigned_t = typename to_unsigned<T>::type;
} // namespace internal
} // namespace atcoder
namespace atcoder {
namespace internal {
struct modint_base {};
struct static_modint_base : modint_base {};
template <class T> using is_modint = std::is_base_of<modint_base, T>;
template <class T> using is_modint_t = std::enable_if_t<is_modint<T>::value>;
} // namespace internal
template <int m, std::enable_if_t<(1 <= m)>* = nullptr>
struct static_modint : internal::static_modint_base {
using mint = static_modint;
public:
static constexpr int mod() { return m; }
static mint raw(int v) {
mint x;
x._v = v;
return x;
}
static_modint() : _v(0) {}
template <class T, internal::is_signed_int_t<T>* = nullptr>
static_modint(T v) {
long long x = (long long)(v % (long long)(umod()));
if (x < 0) x += umod();
_v = (unsigned int)(x);
}
template <class T, internal::is_unsigned_int_t<T>* = nullptr>
static_modint(T v) {
_v = (unsigned int)(v % umod());
}
unsigned int val() const { return _v; }
mint& operator++() {
_v++;
if (_v == umod()) _v = 0;
return *this;
}
mint& operator--() {
if (_v == 0) _v = umod();
_v--;
return *this;
}
mint operator++(int) {
mint result = *this;
++*this;
return result;
}
mint operator--(int) {
mint result = *this;
--*this;
return result;
}
mint& operator+=(const mint& rhs) {
_v += rhs._v;
if (_v >= umod()) _v -= umod();
return *this;
}
mint& operator-=(const mint& rhs) {
_v -= rhs._v;
if (_v >= umod()) _v += umod();
return *this;
}
mint& operator*=(const mint& rhs) {
unsigned long long z = _v;
z *= rhs._v;
_v = (unsigned int)(z % umod());
return *this;
}
mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }
mint operator+() const { return *this; }
mint operator-() const { return mint() - *this; }
mint pow(long long n) const {
assert(0 <= n);
mint x = *this, r = 1;
while (n) {
if (n & 1) r *= x;
x *= x;
n >>= 1;
}
return r;
}
mint inv() const {
if (prime) {
assert(_v);
return pow(umod() - 2);
} else {
auto eg = internal::inv_gcd(_v, m);
assert(eg.first == 1);
return eg.second;
}
}
friend mint operator+(const mint& lhs, const mint& rhs) {
return mint(lhs) += rhs;
}
friend mint operator-(const mint& lhs, const mint& rhs) {
return mint(lhs) -= rhs;
}
friend mint operator*(const mint& lhs, const mint& rhs) {
return mint(lhs) *= rhs;
}
friend mint operator/(const mint& lhs, const mint& rhs) {
return mint(lhs) /= rhs;
}
friend bool operator==(const mint& lhs, const mint& rhs) {
return lhs._v == rhs._v;
}
friend bool operator!=(const mint& lhs, const mint& rhs) {
return lhs._v != rhs._v;
}
private:
unsigned int _v;
static constexpr unsigned int umod() { return m; }
static constexpr bool prime = internal::is_prime<m>;
};
template <int id> struct dynamic_modint : internal::modint_base {
using mint = dynamic_modint;
public:
static int mod() { return (int)(bt.umod()); }
static void set_mod(int m) {
assert(1 <= m);
bt = internal::barrett(m);
}
static mint raw(int v) {
mint x;
x._v = v;
return x;
}
dynamic_modint() : _v(0) {}
template <class T, internal::is_signed_int_t<T>* = nullptr>
dynamic_modint(T v) {
long long x = (long long)(v % (long long)(mod()));
if (x < 0) x += mod();
_v = (unsigned int)(x);
}
template <class T, internal::is_unsigned_int_t<T>* = nullptr>
dynamic_modint(T v) {
_v = (unsigned int)(v % mod());
}
unsigned int val() const { return _v; }
mint& operator++() {
_v++;
if (_v == umod()) _v = 0;
return *this;
}
mint& operator--() {
if (_v == 0) _v = umod();
_v--;
return *this;
}
mint operator++(int) {
mint result = *this;
++*this;
return result;
}
mint operator--(int) {
mint result = *this;
--*this;
return result;
}
mint& operator+=(const mint& rhs) {
_v += rhs._v;
if (_v >= umod()) _v -= umod();
return *this;
}
mint& operator-=(const mint& rhs) {
_v += mod() - rhs._v;
if (_v >= umod()) _v -= umod();
return *this;
}
mint& operator*=(const mint& rhs) {
_v = bt.mul(_v, rhs._v);
return *this;
}
mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }
mint operator+() const { return *this; }
mint operator-() const { return mint() - *this; }
mint pow(long long n) const {
assert(0 <= n);
mint x = *this, r = 1;
while (n) {
if (n & 1) r *= x;
x *= x;
n >>= 1;
}
return r;
}
mint inv() const {
auto eg = internal::inv_gcd(_v, mod());
assert(eg.first == 1);
return eg.second;
}
friend mint operator+(const mint& lhs, const mint& rhs) {
return mint(lhs) += rhs;
}
friend mint operator-(const mint& lhs, const mint& rhs) {
return mint(lhs) -= rhs;
}
friend mint operator*(const mint& lhs, const mint& rhs) {
return mint(lhs) *= rhs;
}
friend mint operator/(const mint& lhs, const mint& rhs) {
return mint(lhs) /= rhs;
}
friend bool operator==(const mint& lhs, const mint& rhs) {
return lhs._v == rhs._v;
}
friend bool operator!=(const mint& lhs, const mint& rhs) {
return lhs._v != rhs._v;
}
private:
unsigned int _v;
static internal::barrett bt;
static unsigned int umod() { return bt.umod(); }
};
template <int id> internal::barrett dynamic_modint<id>::bt(998244353);
using modint998244353 = static_modint<998244353>;
using modint1000000007 = static_modint<1000000007>;
using modint = dynamic_modint<-1>;
namespace internal {
template <class T>
using is_static_modint = std::is_base_of<internal::static_modint_base, T>;
template <class T>
using is_static_modint_t = std::enable_if_t<is_static_modint<T>::value>;
template <class> struct is_dynamic_modint : public std::false_type {};
template <int id>
struct is_dynamic_modint<dynamic_modint<id>> : public std::true_type {};
template <class T>
using is_dynamic_modint_t = std::enable_if_t<is_dynamic_modint<T>::value>;
} // namespace internal
} // namespace atcoder
#include <algorithm>
#include <cassert>
#include <functional>
#include <vector>
#ifdef _MSC_VER
#include <intrin.h>
#endif
#if __cplusplus >= 202002L
#include <bit>
#endif
namespace atcoder {
namespace internal {
#if __cplusplus >= 202002L
using std::bit_ceil;
#else
unsigned int bit_ceil(unsigned int n) {
unsigned int x = 1;
while (x < (unsigned int)(n)) x *= 2;
return x;
}
#endif
int countr_zero(unsigned int n) {
#ifdef _MSC_VER
unsigned long index;
_BitScanForward(&index, n);
return index;
#else
return __builtin_ctz(n);
#endif
}
constexpr int countr_zero_constexpr(unsigned int n) {
int x = 0;
while (!(n & (1 << x))) x++;
return x;
}
} // namespace internal
} // namespace atcoder
namespace atcoder {
#if __cplusplus >= 201703L
template <class S, auto op, auto e> struct segtree {
static_assert(std::is_convertible_v<decltype(op), std::function<S(S, S)>>,
"op must work as S(S, S)");
static_assert(std::is_convertible_v<decltype(e), std::function<S()>>,
"e must work as S()");
#else
template <class S, S (*op)(S, S), S (*e)()> struct segtree {
#endif
public:
segtree() : segtree(0) {}
explicit segtree(int n) : segtree(std::vector<S>(n, e())) {}
explicit segtree(const std::vector<S>& v) : _n(int(v.size())) {
size = (int)internal::bit_ceil((unsigned int)(_n));
log = internal::countr_zero((unsigned int)size);
d = std::vector<S>(2 * size, e());
for (int i = 0; i < _n; i++) d[size + i] = v[i];
for (int i = size - 1; i >= 1; i--) {
update(i);
}
}
void set(int p, S x) {
assert(0 <= p && p < _n);
p += size;
d[p] = x;
for (int i = 1; i <= log; i++) update(p >> i);
}
S get(int p) const {
assert(0 <= p && p < _n);
return d[p + size];
}
S prod(int l, int r) const {
assert(0 <= l && l <= r && r <= _n);
S sml = e(), smr = e();
l += size;
r += size;
while (l < r) {
if (l & 1) sml = op(sml, d[l++]);
if (r & 1) smr = op(d[--r], smr);
l >>= 1;
r >>= 1;
}
return op(sml, smr);
}
S all_prod() const { return d[1]; }
template <bool (*f)(S)> int max_right(int l) const {
return max_right(l, [](S x) { return f(x); });
}
template <class F> int max_right(int l, F f) const {
assert(0 <= l && l <= _n);
assert(f(e()));
if (l == _n) return _n;
l += size;
S sm = e();
do {
while (l % 2 == 0) l >>= 1;
if (!f(op(sm, d[l]))) {
while (l < size) {
l = (2 * l);
if (f(op(sm, d[l]))) {
sm = op(sm, d[l]);
l++;
}
}
return l - size;
}
sm = op(sm, d[l]);
l++;
} while ((l & -l) != l);
return _n;
}
template <bool (*f)(S)> int min_left(int r) const {
return min_left(r, [](S x) { return f(x); });
}
template <class F> int min_left(int r, F f) const {
assert(0 <= r && r <= _n);
assert(f(e()));
if (r == 0) return 0;
r += size;
S sm = e();
do {
r--;
while (r > 1 && (r % 2)) r >>= 1;
if (!f(op(d[r], sm))) {
while (r < size) {
r = (2 * r + 1);
if (f(op(d[r], sm))) {
sm = op(d[r], sm);
r--;
}
}
return r + 1 - size;
}
sm = op(d[r], sm);
} while ((r & -r) != r);
return 0;
}
private:
int _n, size, log;
std::vector<S> d;
void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
};
} // namespace atcoder
using namespace atcoder;
using mint=modint1000000007;
int B=100;
mint powB[201010];
using S=pair<mint,int>;
S op(S l,S r){
mint val=l.first*powB[r.second]+r.first;
return {val,l.second+r.second};
}
S e(){return {0,0};}
void solve(){
int n;
cin>>n;
vi a(n);
rep(i,n)cin>>a[i];
vector<S>init(n);
rep(i,n){
init[i]={a[i],1};
}
ll init_ans=0;
segtree<S,op,e>seg(init);
vll diff(n,0);
vector<unordered_map<int,ll>>mp(n);
vector<ll>X0(n+1),X1(n+1);
vector<S>cum(n+1,e());
rep(i,n){
cum[i+1]=op(cum[i],init[i]);
}
rep(l,n){
int ok=l;
int ng=n+1;
while(abs(ok-ng)>1){
int mid=(ok+ng)/2;
int len=mid-l;
if(seg.prod(l,mid)==cum[len])ok=mid;
else ng=mid;
}
int len=ok-l;
int l1=0;
int r1=len;
int l2=l;
int r2=l+len;
init_ans+=len;
if(l==0)continue;
// todo : 高速化
// ll tmp=len;
// rep(j,l1,min(r1,l2)){
// diff[j]-=tmp;
// tmp--;
// }
// tmp=len;
// rep(j,l2,r2){
// diff[j]-=tmp;
// tmp--;
// }
if(r1<=l2){
X0[l1]+=-len;
X1[l1]+=1;
X1[r1]-=1;
X0[l2]+=-len;
X1[l2]+=1;
X1[min(n,r2)]-=1;
}
else{
X0[l1]+=-len;
X1[l1]+=1;
X1[r2]-=1;
X0[l2]-=l2-l1;
}
if(l+len==n)continue;
if(a[len]!=a[l+len]){
// 増加する可能性があるやつ
// a[len] を a[l + len] に置き換える
seg.set(len,{a[l+len],1});
{
ok=l;
ng=n+1;
while(abs(ok-ng)>1){
int mid=(ok+ng)/2;
int len2=mid-l;
if(seg.prod(l,mid)==seg.prod(0,len2))ok=mid;
else ng=mid;
}
int len2=ok-l;
if(len2>len){
mp[len][a[l+len]]+=len2-len;
}
}
seg.set(len,{a[len],1});
// a[l+len] を a[len] に置き換える
seg.set(l+len,{a[len],1});
{
ok=l;
ng=n+1;
while(abs(ok-ng)>1){
int mid=(ok+ng)/2;
int len2=mid-l;
if(seg.prod(l,mid)==seg.prod(0,len2))ok=mid;
else ng=mid;
}
int len2=ok-l;
assert(len!=len2);
if(len2>len){
mp[l+len][a[len]]+=len2-len;
}
}
seg.set(l+len,{a[l+len],1});
}
}
vll diff2(n,0);
ll tmp0=0;
ll tmp1=0;
rep(i,n){
tmp0+=X0[i]+tmp1;
diff2[i]=tmp0;
tmp1+=X1[i];
}
// assert(diff==diff2);
vll ans(n);
rep(i,n){
ll mx=0;
for(auto [key,val]:mp[i]){
if(key!=a[i])mx=max(mx,val);
}
ans[i]=init_ans+diff2[i]+mx;
}
ll ANS=0;
rep(i,n){
ANS+=ans[i]^(i+1);
}
print(ANS);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
powB[0]=1;
rep(i,1,201010)powB[i]=powB[i-1]*B;
int T;
cin>>T;
rep(T)solve();
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 4300kb
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: 29ms
memory: 4380kb
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: 59ms
memory: 4548kb
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: 57ms
memory: 4376kb
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: 58ms
memory: 4636kb
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: 185ms
memory: 4520kb
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: 321ms
memory: 4748kb
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: 304ms
memory: 4744kb
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: 524ms
memory: 10024kb
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: 830ms
memory: 64188kb
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: 520ms
memory: 8660kb
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: 774ms
memory: 54192kb
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: 784ms
memory: 54292kb
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: 731ms
memory: 37648kb
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: 794ms
memory: 48136kb
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: 757ms
memory: 48880kb
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: 635ms
memory: 49604kb
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: 544ms
memory: 44832kb
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: 518ms
memory: 9340kb
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: 539ms
memory: 9088kb
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: 560ms
memory: 7432kb
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: 593ms
memory: 8824kb
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: 764ms
memory: 52628kb
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: 799ms
memory: 40748kb
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: 843ms
memory: 37648kb
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: -100
Time Limit Exceeded
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...