QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#344253 | #7998. 矩阵 | georgeyucjr | 100 ✓ | 2259ms | 75724kb | C++20 | 45.1kb | 2024-03-03 20:54:09 | 2024-03-03 20:54:09 |
Judging History
answer
/**
* @file Luogu_P_10061.cpp
* @author georgeyucjr ([email protected])
* @brief
* @version 998244353.1145141919810
* @date 2024-02-13
*
* @copyright Copyright (c) 2024
*
*/
# include <bits/stdc++.h>
# ifndef ONLINE_JUDGE
# define LOCAL
# endif
# if __cplusplus >= 201100LL
# else
# error Please use C++11 Or Higher CPP version
# endif
using ll = long long;
using ull = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using arr3 = std :: array < int, 3 >;
using arr4 = std :: array < int, 4 >;
using pii = std :: pair < int, int >;
# if __cplusplus >= 201400LL
# define rep(i, f, t, ...) for ( std :: decay < decltype ( f + t ) > :: type i = f, _END_##i = t, ##__VA_ARGS__; i <= _END_##i; ++i )
# define per(i, f, t, ...) for ( std :: decay < decltype ( f + t ) > :: type i = f, _END_##i = t, ##__VA_ARGS__; i >= _END_##i; --i )
# else
# define rep(i, f, t, ...) for ( decltype ( f + t ) i = f, _END_##i = t, ##__VA_ARGS__; i <= _END_##i; ++i )
# define per(i, f, t, ...) for ( decltype ( f + t ) i = f, _END_##i = t, ##__VA_ARGS__; i >= _END_##i; --i )
# endif
# define emb emplace_back
# define pb push_back
# define mkp make_pair
# define FILEIO(filename) freopen(filename ".in", "r", stdin), freopen(filename ".out", "w", stdout)
# ifndef INLINE_V
# if __cplusplus >= 201700LL
# define INLINE_V inline
# else
# define INLINE_V
# endif
# endif
# if __cplusplus >= 201400LL
# define EXPR constexpr
# else
# define EXPR
# endif
# if __cplusplus >= 201400LL
template < class T, class U >
inline constexpr auto ceil ( T && x, U && y ) {
return ( x > 0 ? ( x + y - 1 ) / y : x / y );
}
template < class T, class U >
inline constexpr auto floor ( T && x, U && y ) {
return ( x > 0 ? x / y : ( x - y + 1 ) / y );
}
template < class T, class U >
inline constexpr auto divmod ( T && x, U && y ) {
auto && q = floor ( x, y );
return std :: make_pair ( q, x - q * y );
}
# else
template < class T, class U >
inline T ceil ( T && x, U && y ) {
return ( x > 0 ? ( x + y - 1 ) / y : x / y );
}
template < class T, class U >
inline T floor ( T && x, U && y ) {
return ( x > 0 ? x / y : ( x - y + 1 ) / y );
}
template < class T, class U >
inline pair < T, T > divmod ( T && x, U && y ) {
T && q = floor ( x, y );
return std :: pair { q, x - q * y };
}
# endif
# define ALL(vc) std :: begin ( vc ), std :: end ( vc )
# if __cplusplus >= 202000LL
template < class T >
requires ( std :: is_signed_v < T > || std :: is_unsigned_v < T > )
INLINE_V constexpr static T inf = std :: numeric_limits < T > :: max ( ) >> 1;
template <std :: ranges :: forward_range R>
inline constexpr auto Sum ( R && r ) {
return std :: accumulate ( std :: ranges :: begin ( r ), std :: ranges :: end ( r ), 0 );
}
template < std :: ranges :: forward_range R, typename T >
inline constexpr auto Sum ( R && r, T init) {
return std :: accumulate ( std :: ranges :: begin ( r ), std :: ranges :: end ( r ), init );
}
template < std :: ranges :: forward_range R >
inline constexpr int SZ ( R && x ) { return std :: size ( x ); }
# else
template < class R >
inline EXPR auto Sum ( R && r ) {
return std :: accumulate ( ALL ( r ), 0);
}
template < class R, typename T >
inline EXPR auto Sum( R && r, T init ) {
return std :: accumulate ( ALL ( r ), init );
}
template < class R >
inline EXPR auto Sum ( R f, R t ) {
return std ::accumulate ( f, t );
}
template < class R, typename T >
inline EXPR auto Sum ( R f, R t, T init ) {
return std :: accumulate ( f, t, init );
}
template < class T >
inline EXPR int SZ ( T && x ) { return static_cast < int > ( x.size ( ) ) ; }
template < class T >
INLINE_V constexpr static T inf = std :: numeric_limits < T > :: max ( ) >> 1;
# endif
template < class Os, class T >
inline Os & operator << ( Os & os, T & t ) {
for ( auto ele : t )
os << ele << " ";
os << "\n";
return os;
}
# ifndef __GEORGEYUCJR_READ__
# define __GEORGEYUCJR_READ__
# if __cplusplus >= 202000LL && !defined(MACOS) && defined(__unix__)
# define CHECK_EOF 0
# if CHECK_EOF
# define ECHK0 *ptr ? *ptr++ : -1
# define ECHK1 \
if (ch == -1) \
return set(false), *this;
# define ECHK2 \
if (!*ptr) \
return set(false), *this;
# define ECHK3 and ch != -1
# define ECHK4 and*ptr
# else
# define ECHK0 *ptr++
# define ECHK1
# define ECHK2
# define ECHK3
# define ECHK4
# endif
# if !defined(MACOS)
# define USE_MMAP
# include <sys/mman.h>
# include <sys/stat.h>
# endif
# if __cpluspls >= 202000LL && !defined(MACOS)
# define DISABLE_RANGE
# endif
# if CHECK_EOF || !defined(USE_MMAP)
# define EV -1
# else
# define EV 0
# endif
namespace FastIO {
template <typename T> struct make_unsigned : public std :: make_unsigned<T> {};
template <> struct make_unsigned<i128> {
using type = u128;
};
template <typename T>
concept tupleLike = requires(T t) { std :: tuple_size_v<decltype(std :: tuple_cat(t))>; };
inline constexpr ull pw10(int t) { return t == 0 ? 1 : pw10(t - 1) * 10; }
std :: mt19937 mrand(std :: random_device{}());
std :: mt19937_64 mrand64(std :: random_device{}());
inline constexpr static std :: size_t bufSize = 1 << 20;
class IO;
class In {
friend class IO;
private:
FILE *inFile;
bool status = true;
# ifdef USE_MMAP
struct stat st;
char *ptr;
int fd;
# elif !defined(LOCAL)
char buf[bufSize], *p1, *p2;
# endif
public:
# ifdef LOCAL
inline int getch() { return fgetc_unlocked(inFile); }
inline void input(FILE *f) { inFile = f, set(); }
# elif defined(USE_MMAP)
inline int getch() { return ECHK0; }
inline void input(FILE *f) {
inFile = f;
if (inFile)
fd = fileno(inFile), fstat(fd, &st), ptr = (char *)mmap(nullptr, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0), set();
}
static constexpr auto n = []() {
std :: array<uint32_t, 0x10000> n{};
for (int i = 0; i != 0x10000; ++i)
n[i] = -1;
constexpr uint32_t e0 = 0x01, e1 = 0x100;
int x = 0;
for (uint32_t i = 0, c0 = 0x3030; i != 10; i++, c0 += e0)
for (uint32_t j = 0, c1 = c0; j != 10; j++, c1 += e1)
n[c1] = x++;
return n;
}();
# else
inline int getch() { return (p1 == p2 ? (p2 = (p1 = buf) + fread(buf, 1, bufSize, inFile)) : 0), p1 == p2 ? -1 : *p1++; }
inline void input(FILE *f) { inFile = f, p1 = p2 = buf, set(); }
# endif
inline void input(const char *s) { input(fopen(s, "rb")); }
inline void set(bool s = true) { status = s; }
inline bool get() const { return status; }
};
class Out {
friend class IO;
public:
FILE *outFile;
# ifndef LOCAL
char pbuf[bufSize], *pp;
# endif
public:
# ifdef LOCAL
inline void flush() { outFile ? fflush(outFile) : 0; }
inline void putch(char c) { fputc_unlocked(c, outFile); }
# else
inline void flush() { (outFile ? fwrite(pbuf, 1, pp - pbuf, outFile), fflush(outFile) : 0), pp = pbuf; }
inline void putch(char c) { ((pp - pbuf == bufSize) ? fwrite(pbuf, 1, bufSize, outFile), pp = pbuf : 0), *pp++ = c; }
# endif
inline void output(const char *s) { flush(), outFile = fopen(s, "wb"); }
inline void output(FILE *f) { flush(), outFile = f; }
};
class IO : public In, public Out {
private:
std :: size_t precision = 12;
public:
IO(FILE * = nullptr, FILE * = nullptr);
~IO() { flush(); }
static constexpr bool blank(char);
template <typename... Args>
requires(sizeof...(Args) > 1)
IO &read(Args &...);
template <typename T>
requires(std :: is_signed_v<T> && std :: is_integral_v<T>) || std :: is_same_v<std :: decay_t<T>, i128>
IO &read(T &);
template <typename T>
requires(std :: is_unsigned_v<T> && std :: is_integral_v<T>) || std :: is_same_v<std :: decay_t<T>, u128>
IO &read(T &);
template <typename T>
requires std :: is_floating_point_v<T>
IO &read(T &);
template <typename T> T read();
IO &read(char &);
IO &read(char *);
IO &read(std :: string &);
IO &readline(char *);
IO &readline(std :: string &);
template <tupleLike T> IO &read(T &&);
template <std :: ranges::input_range R> IO &read(R &&r) { return readArray(std :: forward<R>(r)); }
void setprecision(std :: size_t n = 6u) { precision = n; }
template <typename... Args>
requires(sizeof...(Args) > 1)
void write(Args &&...);
inline void write() const {}
template <typename T>
requires(std :: is_signed_v<T> && std :: is_integral_v<T>) || std :: is_same_v<std :: decay_t<T>, i128>
void write(T);
template <typename T>
requires(std :: is_unsigned_v<T> && std :: is_integral_v<T>)
void write(T);
void write(u128);
inline void write(char);
template <typename T>
requires std :: is_floating_point_v<T>
void write(T);
inline void write(bool);
void write(char *);
void write(const char *);
void write(const std :: string &);
template <typename T> void write(std :: initializer_list<T>);
template <tupleLike T> void write(T &&);
template <std :: ranges::input_range R> void write(R &&);
template <typename... Args> void writeln(Args &&...);
template <typename T> inline void writespc(T && x);
operator bool() const { return get(); }
} io(stdin, stdout);
template <typename... Args> inline void writeln(Args &&...x) { io.writeln(std :: forward<Args>(x)...); }
template <typename T> inline void writeln(std :: initializer_list<T> x) { io.writeln(x); }
#pragma endregion
# define isdigit(x) ((x) >= '0' && (x) <= '9')
IO::IO(FILE *in, FILE *out) { input(in), output(out); }
constexpr bool IO::blank(char c) { return c == ' ' || c == '\n' || c == '\r'; }
template <typename... Args>
requires(sizeof...(Args) > 1)
IO &IO::read(Args &...args) {
if constexpr (CHECK_EOF)
(read(args) && ...);
else
(read(args), ...);
return *this;
}
template <typename T>
requires(std :: is_signed_v<T> && std :: is_integral_v<T>) || std :: is_same_v<std :: decay_t<T>, i128>
IO &IO::read(T &x) {
x = 0;
static typename make_unsigned<T>::type t;
bool sign = false;
# ifndef USE_MMAP
int ch = getch();
while (!isdigit(ch) ECHK3)
sign = (ch == '-'), ch = getch();
ECHK1
t = 0;
while (isdigit(ch))
t = t * 10 + (ch ^ 48), ch = getch();
# else
while (!isdigit(*ptr) ECHK4)
sign = *ptr++ == '-';
ECHK2
t = *ptr++ ^ 48;
while (~n[*reinterpret_cast<std :: uint16_t *&>(ptr)])
t = t * 100 + n[*reinterpret_cast<std :: uint16_t *&>(ptr)++];
if (isdigit(*ptr))
t = t * 10 + (*ptr++ ^ 48);
# endif
x = sign ? (~t + 1) : t;
return *this;
}
template <typename T>
requires(std :: is_unsigned_v<T> && std :: is_integral_v<T>) || std :: is_same_v<std :: decay_t<T>, u128>
IO &IO::read(T &x) {
x = 0;
# ifndef USE_MMAP
int ch = getch();
while (!isdigit(ch) ECHK3)
ch = getch();
ECHK1
while (isdigit(ch))
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getch();
# else
while (!isdigit(*ptr) ECHK4)
ptr++;
ECHK2
x = *ptr++ ^ 48;
while (~n[*reinterpret_cast<std :: uint16_t *&>(ptr)])
x = x * 100 + n[*reinterpret_cast<std :: uint16_t *&>(ptr)++];
if (isdigit(*ptr))
x = x * 10 + (*ptr++ ^ 48);
# endif
return *this;
}
template <typename T>
requires std :: is_floating_point_v<T>
IO &IO::read(T &x) {
x = 0;
T t = 1;
bool sign = false;
int ch = getch();
while (!isdigit(ch) ECHK3)
sign = (ch == '-'), ch = getch();
ECHK1
while (isdigit(ch))
x = x * 10 + (ch ^ 48), ch = getch();
if (ch == '.')
for (ch = getch(); isdigit(ch); ch = getch())
x += (t /= 10) * (ch ^ 48);
x = sign ? -x : x;
return *this;
}
template <typename T> T IO::read() {
static std :: decay_t<T> x;
return read(x), x;
}
IO &IO::read(char &ch) {
do
ch = getch();
while (blank(ch));
ECHK1
return *this;
}
IO &IO::read(char *s) {
int ch = getch();
while (blank(ch))
ch = getch();
ECHK1
while (!blank(ch) && ch != EV)
*s++ = ch, ch = getch();
*s = 0;
return *this;
}
IO &IO::read(std :: string &s) {
int ch = getch();
while (blank(ch))
ch = getch();
ECHK1
s.erase();
while (!blank(ch) && ch != EV)
s.append(1, ch), ch = getch();
return *this;
}
IO &IO::readline(char *s) {
char *t = s;
int ch = getch();
while (ch != '\n' && ch != EV)
*s++ = ch, ch = getch();
*s = 0;
if (s == t && ch != '\n')
set(false);
return *this;
}
IO &IO::readline(std :: string &s) {
s.erase();
int ch = getch();
while (ch != '\n' && ch != EV)
s.append(1, ch), ch = getch();
if (s.empty() && ch != '\n')
set(false);
return *this;
}
template <tupleLike T> IO &IO::read(T &&t) {
std :: apply([&](auto & ...t) { (read(t), ...); }, t);
return *this;
}
template <typename... Args>
requires(sizeof...(Args) > 1)
void IO::write(Args &&...args) {
(write(std :: forward<Args>(args)), ...);
}
template <typename T>
requires(std :: is_signed_v<T> && std :: is_integral_v<T>) || std :: is_same_v<std :: decay_t<T>, i128>
void IO::write(T x) {
static typename make_unsigned<T>::type y;
y = x;
if (x < 0)
putch('-'), write(~y + 1);
else
write(y);
}
constexpr auto D = []() {
constexpr uint32_t e0 = 0x1, e1 = 0x100, e2 = 0x10000, e3 = 0x1000000;
std :: array<uint32_t, 10000> m{};
int x = 0;
for (uint32_t i = 0, c0 = 0x30303030; i != 10; i++, c0 += e0)
for (uint32_t j = 0, c1 = c0; j != 10; j++, c1 += e1)
for (uint32_t k = 0, c2 = c1; k != 10; k++, c2 += e2)
for (uint32_t l = 0, c3 = c2; l != 10; l++, c3 += e3)
m[x++] = c3;
return m;
}();
template <typename T>
requires(std :: is_unsigned_v<T> && std :: is_integral_v<T>)
void IO::write(T x) {
# ifndef LOCAL
if (std :: end(pbuf) - pp < 64)
flush();
auto L = [&](int x) { return x == 1 ? 0 : pw10(x - 1); };
auto R = [&](int x) { return pw10(x) - 1; };
# define de(t) \
case L(t)... R(t): \
*reinterpret_cast<uint32_t *>(pp) = D[x / pw10((t)-4)]; \
pp += 4; \
x %= pw10((t)-4);
ull y = x;
switch (y) {
de(18);
de(14);
de(10);
de(6);
case L(2)... R(2):
*reinterpret_cast<uint32_t *>(pp) = D[x * 100];
pp += 2;
break;
de(17);
de(13);
de(9);
de(5);
case L(1)... R(1):
*pp = static_cast<char>('0' + x);
pp += 1;
break;
default:
*reinterpret_cast<uint32_t *>(pp) = D[x / pw10(16)];
pp += 4;
x %= pw10(16);
de(16);
de(12);
de(8);
case L(4)... R(4):
*reinterpret_cast<uint32_t *>(pp) = D[x];
pp += 4;
break;
de(19);
de(15);
de(11);
de(7);
case L(3)... R(3):
*reinterpret_cast<uint32_t *>(pp) = D[x * 10];
pp += 3;
break;
}
# else
write(u128(x));
# endif
}
constexpr u128 _pw10(int x) { return x == 0 ? 1 : _pw10(x - 1) * 10; }
void IO::write(u128 x) {
if (std :: end(pbuf) - pp < 64)
flush();
constexpr auto pw10 = _pw10;
auto L = [&](int x) { return x == 1 ? 0 : pw10(x - 1); };
auto R = [&](int x) { return pw10(x) - 1; };
# define de(t) \
case L(t)... R(t): \
*reinterpret_cast<uint32_t *>(pp) = D[x / pw10((t)-4)]; \
pp += 4; \
x %= pw10((t)-4);
switch (x) {
de(38);
de(34);
de(30);
de(26);
de(22);
de(18);
de(14);
de(10);
de(6);
case L(2)... R(2):
*reinterpret_cast<uint32_t *>(pp) = D[x * 100];
pp += 2;
break;
de(37);
de(33);
de(29);
de(25);
de(21);
de(17);
de(13);
de(9);
de(5);
case L(1)... R(1):
*pp = static_cast<char>('0' + x);
pp += 1;
break;
de(36);
de(32);
de(28);
de(24);
de(20);
de(16);
de(12);
de(8);
case L(4)... R(4):
*reinterpret_cast<uint32_t *>(pp) = D[x];
pp += 4;
break;
default:
*reinterpret_cast<uint32_t *>(pp) = D[x / pw10(35)];
pp += 4;
x %= pw10(35);
de(35);
de(31);
de(27);
de(23);
de(19);
de(15);
de(11);
de(7);
case L(3)... R(3):
*reinterpret_cast<uint32_t *>(pp) = D[x * 10];
pp += 3;
break;
}
}
void IO::write(bool x) { putch(x ^ 48); }
void IO::write(char c) { putch(c); }
template <typename T>
requires std :: is_floating_point_v<T>
void IO::write(T x) {
static char buf[512];
*std :: to_chars(buf, buf + 512, x, std :: chars_format::fixed, precision).ptr = 0;
write(buf);
}
void IO::write(char *s) {
while (*s)
putch(*s++);
}
void IO::write(const char *s) {
while (*s)
putch(*s++);
}
void IO::write(const std :: string &s) { write(s.data()); }
template <typename T> void IO::write(std :: initializer_list<T> t) {
auto first = std :: begin(t), last = std :: end(t);
if (first != last)
for (write(*first++); first != last; ++first) {
putch(' ');
write(*first);
}
}
template <tupleLike T> void IO::write(T &&t) {
[&]<std :: size_t... I>(std :: index_sequence<I...>) {
(..., (I == 0 ? void(0) : putch(' '), write(std :: get<I>(t))));
}(std :: make_index_sequence<std :: tuple_size_v<std :: remove_reference_t<T>>>());
}
template <std :: ranges::input_range R> void IO::write(R &&r) {
if constexpr (std :: is_same_v<std :: decay_t<R>, std :: string>)
return write(r.data());
auto first = std :: ranges::begin(r), last = std :: ranges::end(r);
if (first != last)
for (write(*first++); first != last; ++first) {
putch(' ');
write(*first);
}
}
template <typename... Args> void IO::writeln(Args &&...x) { write(std :: forward<Args>(x)...), putch('\n'); }
template <typename T> inline void IO::writespc(T && x) { write(x), putch('\n'); }
} // namespace FastIO
using namespace FastIO;
# else
# ifndef LUOGU
# define auto_att __attribute__((target("avx2"), optimize(3, "Ofast", "unroll-loops", "inline")))
# else
# define auto_att
# endif
namespace FastIO {
# define endl '\n'
INLINE_V static constexpr size_t buf_size = 1 << 18;
INLINE_V static constexpr size_t integer_size = 20;
INLINE_V static constexpr size_t block_size = 10000;
static char inbuf[buf_size + 1] = {};
static char outbuf[buf_size + 1] = {};
static char block_str[block_size * 4 + 1] = {};
static constexpr uint64_t power10[] = {1,
10,
100,
1000,
10000,
100000,
1000000,
10000000,
100000000,
1000000000,
10000000000,
100000000000,
1000000000000,
10000000000000,
100000000000000,
1000000000000000,
10000000000000000,
100000000000000000,
1000000000000000000,
10000000000000000000u
};
struct Scanner {
# ifndef LOCAL
private:
size_t pos, end;
inline void load() {
end = fread(inbuf, 1, buf_size, stdin);
inbuf[end] = '\0';
}
inline void reload() {
size_t len = end - pos;
memmove(inbuf, inbuf + pos, len);
end = len + fread(inbuf + len, 1, buf_size - len, stdin);
inbuf[end] = '\0';
pos = 0;
}
inline void skip_space() {
while (inbuf[pos] <= ' ') {
if (__builtin_expect(++pos == end, 0))
reload();
}
}
inline char get_next() { return inbuf[pos++]; }
inline char get_next_nonspace() {
skip_space();
return inbuf[pos++];
}
public:
Scanner() { load(); }
auto_att inline void read(char &c) { c = get_next_nonspace(); }
auto_att inline void read(std :: string &s) {
skip_space();
s = "";
do {
size_t start = pos;
while (inbuf[pos] > ' ')
++pos;
s += std :: string(inbuf + start, inbuf + pos);
if (inbuf[pos] != '\0')
break;
reload();
} while (true);
}
template <class T> typename std :: enable_if<std :: is_integral<T>::value, void>::type read(T &x) {
char c = get_next_nonspace();
if (__builtin_expect(pos + integer_size >= end, 0))
reload();
bool neg = false;
if (c == '-')
neg = true, x = 0;
else
x = c & 15;
while ((c = get_next()) >= '0')
x = (x << 3) + (x << 1) + (c & 15);
if (neg)
x = -x;
}
# else
template <typename _Tp> inline void read(_Tp &x) {
char ch = getchar();
int f = 1;
x = 0;
for (; ch < '0' || ch > '9'; ch = getchar())
f = ch == '-' ? -1 : 1;
for (; ch >= '0' && ch <= '9'; ch = getchar())
x = (x << 3) + (x << 1) + (ch ^ 48);
x *= f;
}
inline void read(char &c) { c = getchar(); }
inline void read(char *x) {
int i = 0;
char c = ' ';
for (; c <= ' ';)
c = getchar();
for (; c > ' ';)
x[i++] = c, c = getchar();
x[i] = 0;
}
inline void read(std :: string &x) {
x.clear();
char c = ' ';
for (; c <= ' ';)
c = getchar();
for (; c > ' ';)
x += c, c = getchar();
}
# endif
template <class Head, class... Others> void read(Head &head, Others &...others) {
read(head);
read(others...);
}
template <class T1, class T2> inline void read(std :: pair<T1, T2> &x) { read(x.first), read(x.second); }
} is;
struct Printer {
# ifndef LOCAL
private:
size_t pos = 0;
auto_att inline void flush() {
fwrite(outbuf, 1, pos, stdout);
pos = 0;
}
inline void pre_calc() {
for (size_t i = 0; i < block_size; ++i) {
size_t j = 4, k = i;
while (j--) {
block_str[i * 4 + j] = k % 10 | 48;
k /= 10;
}
}
}
static EXPR size_t get_integer_size(uint64_t n) {
if (n >= power10[10]) {
if (n >= power10[19])
return 20;
if (n >= power10[18])
return 19;
if (n >= power10[17])
return 18;
if (n >= power10[16])
return 17;
if (n >= power10[15])
return 16;
if (n >= power10[14])
return 15;
if (n >= power10[13])
return 14;
if (n >= power10[12])
return 13;
if (n >= power10[11])
return 12;
return 11;
} else {
if (n >= power10[9])
return 10;
if (n >= power10[8])
return 9;
if (n >= power10[7])
return 8;
if (n >= power10[6])
return 7;
if (n >= power10[5])
return 6;
if (n >= power10[4])
return 5;
if (n >= power10[3])
return 4;
if (n >= power10[2])
return 3;
if (n >= power10[1])
return 2;
return 1;
}
}
public:
Printer() { pre_calc(); }
~Printer() { flush(); }
inline void write(char c) {
outbuf[pos++] = c;
if (__builtin_expect(pos == buf_size, 0))
flush();
}
inline void write(const char *s) {
while (*s != 0) {
outbuf[pos++] = *s++;
if (__builtin_expect(pos == buf_size, 0))
flush();
}
}
inline void write(const std :: string &s) {
for (auto c : s) {
outbuf[pos++] = c;
if (__builtin_expect(pos == buf_size, 0))
flush();
}
}
template <class T> typename std :: enable_if<std :: is_integral<T>::value, void>::type write(T x) {
if (__builtin_expect(pos + integer_size >= buf_size, 0))
flush();
if (x < 0)
write('-'), x = -x;
size_t digit = get_integer_size(x);
size_t len = digit;
while (len >= 4) {
len -= 4;
memcpy(outbuf + pos + len, block_str + ((x % block_size) << 2), 4);
x /= block_size;
}
memcpy(outbuf + pos, block_str + (x << 2) + (4 - len), len);
pos += digit;
}
# else
inline void write(char c) { putchar(c); }
inline void write(const char *x) {
for (int i = 0; x[i]; ++i)
write(x[i]);
}
inline void write(std::string s) {
for (auto c : s)
write(c);
}
template <typename _Tp> inline void write(_Tp x) {
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
write(x / 10);
putchar(x % 10 ^ 48);
}
# endif
template <class Head, class... Others> void write(const Head &head, const Others &...others) {
write(head);
write(' ');
write(others...);
}
template <class... Args> void writeln(const Args &...args) {
write(args...);
write('\n');
}
template < class T >
inline void writespc ( const T & x ) {
write ( x );
write ( " " );
}
template <class T1, class T2> inline void write(const std :: pair<T1, T2> &x) { write(x.first, x.second); }
} os;
struct IO : public Scanner, public Printer {
} io;
}; // namespace FastIO
using namespace FastIO;
# endif
# endif
using namespace std;
# warning Do not use debug.hpp.
#ifndef ATCODER_MODINT_HPP
#define ATCODER_MODINT_HPP 1
#include <type_traits>
#ifdef _MSC_VER
#include <intrin.h>
#endif
#ifndef ATCODER_INTERNAL_MATH_HPP
#define ATCODER_INTERNAL_MATH_HPP 1
#include <utility>
#ifdef _MSC_VER
#include <intrin.h>
#endif
namespace atcoder {
namespace internal {
// @param m `1 <= m`
// @return x mod m
constexpr long long safe_mod(long long x, long long m) {
x %= m;
if (x < 0)
x += m;
return x;
}
// Fast modular multiplication by barrett reduction
// Reference: https://en.wikipedia.org/wiki/Barrett_reduction
// NOTE: reconsider after Ice Lake
struct barrett {
unsigned int _m;
unsigned long long im;
// @param m `1 <= m < 2^31`
barrett(unsigned int m) : _m(m), im((unsigned long long)(-1) / m + 1) {}
// @return m
unsigned int umod() const { return _m; }
// @param a `0 <= a < m`
// @param b `0 <= b < m`
// @return `a * b % m`
unsigned int mul(unsigned int a, unsigned int b) const {
// [1] m = 1
// a = b = im = 0, so okay
// [2] m >= 2
// im = ceil(2^64 / m)
// -> im * m = 2^64 + r (0 <= r < m)
// let z = a*b = c*m + d (0 <= c, d < m)
// a*b * im = (c*m + d) * im = c*(im*m) + d*im = c*2^64 + c*r + d*im
// c*r + d*im < m * m + m * im < m * m + 2^64 + m <= 2^64 + m * (m + 1) <
// 2^64 * 2
// ((ab * im) >> 64) == c or c + 1
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 int v = (unsigned int)(z - x * _m);
if (_m <= v)
v += _m;
return v;
}
};
// @param n `0 <= n`
// @param m `1 <= m`
// @return `(x ** n) % m`
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;
}
// Reference:
// M. Forisek and J. Jancina,
// Fast Primality Testing for Integers That Fit into a Machine Word
// @param n `0 <= n`
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);
// @param b `1 <= b`
// @return pair(g, x) s.t. g = gcd(a, b), xa = g (mod b), 0 <= x < b/g
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};
// Contracts:
// [1] s - m0 * a = 0 (mod b)
// [2] t - m1 * a = 0 (mod b)
// [3] s * |m1| + t * |m0| <= b
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
// [3]:
// (s - t * u) * |m1| + t * |m0 - m1 * u|
// <= s * |m1| - t * u * |m1| + t * (|m0| + |m1| * u)
// = s * |m1| + t * |m0| <= b
auto tmp = s;
s = t;
t = tmp;
tmp = m0;
m0 = m1;
m1 = tmp;
}
// by [3]: |m0| <= b/g
// by g != b: |m0| < b/g
if (m0 < 0)
m0 += b / s;
return {s, m0};
}
// Compile time primitive root
// @param m must be prime
// @return primitive root (and minimum in now)
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);
} // namespace internal
} // namespace atcoder
#endif // ATCODER_INTERNAL_MATH_HPP
#ifndef ATCODER_INTERNAL_TYPE_TRAITS_HPP
#define ATCODER_INTERNAL_TYPE_TRAITS_HPP 1
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
#endif // ATCODER_INTERNAL_TYPE_TRAITS_HPP
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
#endif // ATCODER_MODINT_HPP
using mint = atcoder :: modint1000000007;
# define x1 Daniel1234
# define y1 AK_IOI
INLINE_V constexpr static int N = 3e3 + 5;
INLINE_V constexpr static int B = 55;
int n, q;
mint a[2][N][N];
struct Query {
int opt, x1, y1, x2, y2; mint d;
inline void rd() { io.read(opt, x1, y1, x2, y2); if (opt == 2) { int x; io.read(x); d = x; } }
} que[N];
struct Trans {
short xx = 1, xy = 0, xB = 0, yx = 0, yy = 1, yB = 0;
mint sm = 0;
inline void rtt(const Query & qry) {
// cerr << xx << " " << xy << " " << yx << " " << yy << "\n";
int _xx = xx, _xy = xy, _xB = xB;
xx = -yx, xy = -yy, xB = qry.x2 + qry.y1 - yB;
yx = _xx, yy = _xy, yB = qry.y1 - qry.x1 + _xB;
// cerr << xx << " " << xy << " " << yx << " " << yy << " " << xB << " " << yB << "\n";
// cerr << qry.x1 << " " << qry.y1 << " " << qry.x2 << " " << qry.y2 << " " << xB << " " << yB << " " << xx << " " << xy << " " << yx << " " << yy << "\n";
}
inline void add(const Query & qry) { sm += qry.d; }
inline void cfg(int &x, int &y) {
int _x = x; x = xx * x + xy * y + xB, y = yx * _x + yy * y + yB;
// cerr << "cfg : " << x << " " << y << "\n";
}
inline void wrk(short &x, short &y) {
// cerr << "x = " << x << ", y = " << y << ", xx = " << xx << ", yy = " << yy << "\n";
if (!xy && !yx) x = (x - xB) / xx, y = (y - yB) / yy;
else if (!xx && !yy) { int _x = x; x = (y - yB) / yx, y = (_x - xB) / xy; }
else assert(false);
// cerr << "wrk : " << x << " " << y << "\n";
}
// inline void dbg() {
// cerr << "xx = " << xx << ", xy = " << xy << ", yx = " << yx << ", yy = " << yy << "\n";
// }
};
struct BLK {
short xl, xr, yl, yr;
template < class T >
requires ( std :: is_signed_v < T > || std :: is_unsigned_v < T > )
BLK (T _xl, T _xr, T _yl, T _yr) : xl(_xl), xr(_xr), yl(_yl), yr(_yr) {}
// inline void dbg() {
// cerr << "xl = " << xl << ", xr = " << xr << ", yl = " << yl << ", yr = " << yr << "\n";
// }
};
vector<pair<BLK, Trans>>vc[2];
signed main() {
io.read(n, q);
rep(i, 1, n) rep(j, 1, n, t = 1) a[0][i][j] = t = 1ll * t * (i + 1) % 998244353;
// rep(i, 1, n) rep(j, 1, n) cerr << a[0][i][j].val() << (j == n ? "\n" : " ");
rep(i, 1, q)que[i].rd();
for (int bll = 1, blr; bll <= q; bll += B) {
blr = min (bll + B - 1, q);
vc[0].emb(BLK(1, n, 1, n), Trans());
rep(i, bll, blr) {
for (auto [blk, trs] : vc[0]) {
vector<pair<short, short>> vx, vy;
if (que[i].x2 < blk.xl || blk.xr < que[i].x1 || (que[i].x1 <= blk.xl && blk.xr <= que[i].x2))
vx.emb(blk.xl, blk.xr);
else if (que[i].x1 <= blk.xl && que[i].x2 < blk.xr)
vx.emb(blk.xl, que[i].x2), vx.emb(que[i].x2 + 1, blk.xr);
else if (blk.xl < que[i].x1 && blk.xr <= que[i].x2)
vx.emb(blk.xl, que[i].x1 - 1), vx.emb(que[i].x1, blk.xr);
else vx.emb(que[i].x1, que[i].x2),
vx.emb(blk.xl, que[i].x1 - 1), vx.emb(que[i].x2 + 1, blk.xr);
if (que[i].y2 < blk.yl || blk.yr < que[i].y1 || (que[i].y1 <= blk.yl && blk.yr <= que[i].y2))
vy.emb(blk.yl, blk.yr);
else if (que[i].y1 <= blk.yl && que[i].y2 < blk.yr)
vy.emb(blk.yl, que[i].y2), vy.emb(que[i].y2 + 1, blk.yr);
else if (blk.yl < que[i].y1 && blk.yr <= que[i].y2)
vy.emb(blk.yl, que[i].y1 - 1), vy.emb(que[i].y1, blk.yr);
else vy.emb(que[i].y1, que[i].y2),
vy.emb(blk.yl, que[i].y1 - 1), vy.emb(que[i].y2 + 1, blk.yr);
for (auto xi : vx) for (auto yi : vy) {
BLK _blk = BLK(xi.first, xi.second, yi.first, yi.second);
Trans _trs = trs;
if (que[i].x1 <= _blk.xl && _blk.xr <= que[i].x2 &&
que[i].y1 <= _blk.yl && _blk.yr <= que[i].y2) {
if (que[i].opt == 1) {
_trs.rtt(que[i]);
_blk.xl = que[i].x2 + que[i].y1 - _blk.yr, _blk.xr = que[i].x2 + que[i].y1 - _blk.yl;
_blk.yl = que[i].y1 - que[i].x1 + xi.first, _blk.yr = que[i].y1 - que[i].x1 + xi.second;
} else _trs.add(que[i]);
}
vc[1].emb(_blk, _trs);
}
}
vc[0].clear(), swap(vc[0], vc[1]);
}
// for (auto [blk, trs] : vc[0])
// blk.dbg();
// trs.dbg();
for (auto [blk, trs] : vc[0]) {
// cerr << blk.xl << " " << blk.xr << " " << blk.yl << " " << blk.yr << "\n";
trs.wrk(blk.xl, blk.yl), trs.wrk(blk.xr, blk.yr);
if (blk.xl > blk.xr) swap(blk.xl, blk.xr);
if (blk.yl > blk.yr) swap(blk.yl, blk.yr);
// cerr << blk.xl << " " << blk.xr << " " << blk.yl << " " << blk.yr << "\n";
rep(i, blk.xl, blk.xr)rep(j, blk.yl, blk.yr) {
int x = i, y = j; trs.cfg(x, y); a[1][x][y] = a[0][i][j] + trs.sm;
// cerr << x << " " << y << " " << i << " " << j << "\n";
}
}
vc[0].clear(), swap(a[0], a[1]);
}
mint ans = 0, t = 1;
// rep(i, 1, n) rep(j, 1, n) cerr << a[0][i][j].val() << (j == n ? "\n" : " ");
rep (i, 1, n) rep (j, 1, n) ans += a[0][i][j] * (t *= 12345);
io.writeln(ans.val());
# if defined(LOCAL) && !defined(CPH)
cerr << "Spend time : " << clock ( ) * 1. / CLOCKS_PER_SEC * 1000. << "ms\n";
# endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 473ms
memory: 75460kb
input:
100 3000 1 4 3 100 99 1 3 8 83 88 1 4 7 96 99 1 2 7 90 95 2 6 5 98 98 762240996 1 9 8 98 97 1 3 3 100 100 2 18 7 97 84 230446266 1 2 5 94 97 1 2 18 82 98 1 9 2 100 93 1 3 9 91 97 1 1 2 99 100 1 7 6 98 97 1 2 4 98 100 1 3 2 99 98 1 4 2 100 98 2 9 74 28 83 703323901 1 6 4 100 98 2 2 6 99 93 882702932 ...
output:
535773693
result:
ok 1 number(s): "535773693"
Test #2:
score: 10
Accepted
time: 1600ms
memory: 74536kb
input:
3000 3000 2 40 215 2496 2298 67590963 2 100 211 2684 2855 670656770 2 417 399 2612 2930 826127245 2 116 779 2407 2596 977282152 2 512 366 2768 2949 737671139 2 191 594 2671 2978 404448620 2 3 11 2720 2633 516813112 2 95 294 2553 2820 112269230 2 284 58 2934 2754 225336228 2 306 53 2815 2984 49218367...
output:
343427775
result:
ok 1 number(s): "343427775"
Test #3:
score: 10
Accepted
time: 1576ms
memory: 75724kb
input:
3000 2000 1 853 610 2674 2431 1 24 415 2490 2881 1 19 150 2842 2973 1 597 79 2977 2459 1 307 408 2397 2498 1 292 316 2907 2931 1 7 42 2953 2988 1 36 30 2953 2947 1 55 438 2609 2992 1 97 204 2664 2771 1 607 254 2803 2450 1 59 159 2808 2908 1 58 12 2991 2945 1 287 400 2506 2619 1 105 143 2949 2987 1 2...
output:
743809971
result:
ok 1 number(s): "743809971"
Test #4:
score: 10
Accepted
time: 1557ms
memory: 74712kb
input:
3000 2000 1 646 55 2815 2224 1 47 78 2964 2995 1 48 7 2882 2841 1 9 8 2999 2998 1 128 36 2984 2892 1 14 5 2990 2981 1 52 81 2934 2963 1 231 317 2612 2698 1 33 7 2960 2934 1 111 165 2732 2786 1 9 2 2994 2987 1 131 224 2866 2959 1 19 49 2917 2947 1 46 44 2997 2995 1 1 14 2969 2982 1 69 49 2975 2955 1 ...
output:
517390609
result:
ok 1 number(s): "517390609"
Test #5:
score: 10
Accepted
time: 2241ms
memory: 74576kb
input:
3000 3000 1 6 5 2997 2996 1 14 362 2624 2972 1 657 108 2405 1856 1 20 27 2983 2990 1 245 236 2903 2894 1 184 100 2957 2873 1 61 47 2954 2940 1 39 89 2935 2985 1 43 49 2956 2962 1 132 138 2763 2769 1 4 4 2998 2998 1 16 59 2752 2795 1 30 24 2997 2991 1 143 11 2959 2827 1 57 44 2887 2874 1 40 17 2991 2...
output:
632994577
result:
ok 1 number(s): "632994577"
Test #6:
score: 10
Accepted
time: 2235ms
memory: 74564kb
input:
3000 3000 1 544 5 2907 2368 1 60 63 2978 2981 1 228 310 2881 2963 1 57 71 2958 2972 1 101 565 2467 2931 1 979 1004 2882 2907 1 37 3 2913 2879 1 418 427 2922 2931 1 30 62 2937 2969 1 83 104 2979 3000 1 4 18 2939 2953 1 67 203 2834 2970 1 357 882 1000 1525 1 34 10 2991 2967 1 8 4 2997 2993 1 2 4 2991 ...
output:
275056325
result:
ok 1 number(s): "275056325"
Test #7:
score: 10
Accepted
time: 1507ms
memory: 74724kb
input:
3000 2000 1 82 42 2883 2843 1 2 48 2939 2985 2 188 176 2376 2976 715286463 1 15 24 2984 2993 1 106 50 2811 2755 2 45 132 2745 2432 339749026 1 5 100 2779 2874 1 343 134 2478 2269 1 106 227 2820 2941 2 10 206 2947 2798 365598855 2 560 106 2582 2903 92795190 1 74 100 2960 2986 1 5 33 2944 2972 2 873 3...
output:
191562107
result:
ok 1 number(s): "191562107"
Test #8:
score: 10
Accepted
time: 1541ms
memory: 74672kb
input:
3000 2000 1 20 5 2990 2975 1 14 10 2999 2995 1 192 89 2950 2847 2 547 646 2654 2940 439095457 1 18 16 3000 2998 1 35 105 2754 2824 1 17 52 2942 2977 2 356 121 2384 2963 959830720 2 76 78 2412 1842 361763869 2 199 46 2624 2931 743439747 2 180 320 2981 2964 772483137 2 173 122 2732 2901 759079379 1 47...
output:
787136396
result:
ok 1 number(s): "787136396"
Test #9:
score: 10
Accepted
time: 2259ms
memory: 75376kb
input:
3000 3000 1 220 131 2785 2696 2 1443 1396 2159 2850 578335729 1 536 1184 1545 2193 1 26 23 2999 2996 1 43 56 2881 2894 1 29 4 2872 2847 2 69 155 2681 2931 88398671 1 66 44 2945 2923 1 53 512 2515 2974 2 402 58 2752 2782 641047796 2 458 36 2859 2756 694998888 2 145 192 2995 2973 483103477 1 117 315 2...
output:
973923858
result:
ok 1 number(s): "973923858"
Test #10:
score: 10
Accepted
time: 2242ms
memory: 74804kb
input:
3000 3000 2 7 47 2887 2544 535526356 2 160 639 2988 2995 343766215 1 122 40 2985 2903 2 62 240 2858 2177 841981272 1 169 18 2682 2531 1 61 286 2729 2954 1 180 27 2994 2841 1 238 330 2881 2973 2 57 188 2880 2914 203515190 1 28 61 2903 2936 2 102 269 2876 2397 681849386 1 3 53 2896 2946 1 101 56 2985 ...
output:
328382756
result:
ok 1 number(s): "328382756"