submission_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
3 values
code
stringlengths
1
522k
compiler_output
stringlengths
43
10.2k
s913429016
p04022
C++
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <sstream> #include <iomanip> #include <cstdio> #include <cstdlib> #include <cmath> #include <cctype> #include <cstring> #include <vector> #include <list> #include <queue> #include <deque> #include <stack> #include <map> #include <set> #include <algorithm> #include <iterator> #include <bitset> #include <ctime> #include<complex> using namespace std; #define FOR(i,a,b) for (int i = (a); i < (b); i++) #define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--) #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++) #define FILL(a,value) memset(a, value, sizeof(a)) #define SZ(a) (int)a.size() #define ALL(a) a.begin(), a.end() #define PB push_back #define MP make_pair typedef long long LL; typedef vector<int> VI; typedef pair<int, int> PII; const double PI = acos(-1.0); const int INF = 1000 * 1000 * 1000 + 7; const LL LINF = INF * (LL)INF; const int MAX = 1000 * 100 + 47; const LL MAX1 = MAX * (LL)MAX; unsigned long long abs(unsigned long long n) { return n; } //! Возвращает true, если n четное template <class T> bool even(const T & n) { // return n % 2 == 0; return (n & 1) == 0; } //! Делит число на 2 template <class T> void bisect(T & n) { // n /= 2; n >>= 1; } //! Умножает число на 2 template <class T> void redouble(T & n) { // n *= 2; n <<= 1; } //! Возвращает true, если n - точный квадрат простого числа template <class T> bool perfect_square(const T & n) { T sq = (T)ceil(sqrt((double)n)); return sq*sq == n; } //! Вычисляет корень из числа, округляя его вниз template <class T> T sq_root(const T & n) { return (T)floor(sqrt((double)n)); } //! Возвращает количество бит в числе (т.е. минимальное количество бит, которыми можно представить данное число) template <class T> unsigned bits_in_number(T n) { if (n == 0) return 1; unsigned result = 0; while (n) { bisect(n); ++result; } return result; } //! Возвращает значение k-го бита числа (биты нумеруются с нуля) template <class T> bool test_bit(const T & n, unsigned k) { return (n & (T(1) << k)) != 0; } //! Умножает a *= b (mod n) template <class T> void mulmod(T & a, T b, const T & n) { // наивная версия, годится только для длинной арифметики a *= b; a %= n; } template <> void mulmod(int & a, int b, const int & n) { a = int((((long long)a) * b) % n); } template <> void mulmod(unsigned & a, unsigned b, const unsigned & n) { a = unsigned((((unsigned long long)a) * b) % n); } template <> void mulmod(unsigned long long & a, unsigned long long b, const unsigned long long & n) { // сложная версия, основанная на бинарном разложении произведения в сумму if (a >= n) a %= n; if (b >= n) b %= n; unsigned long long res = 0; while (b) if (!even(b)) { res += a; while (res >= n) res -= n; --b; } else { redouble(a); while (a >= n) a -= n; bisect(b); } a = res; } template <> void mulmod(long long & a, long long b, const long long & n) { bool neg = false; if (a < 0) { neg = !neg; a = -a; } if (b < 0) { neg = !neg; b = -b; } unsigned long long aa = a; mulmod<unsigned long long>(aa, (unsigned long long)b, (unsigned long long)n); a = (long long)aa * (neg ? -1 : 1); } //! Вычисляет a^k (mod n). Использует бинарное возведение в степень template <class T, class T2> T powmod(T a, T2 k, const T & n) { T res = 1; while (k) if (!even(k)) { mulmod(res, a, n); --k; } else { mulmod(a, a, n); bisect(k); } return res; } //! Переводит число n в форму q*2^p template <class T> void transform_num(T n, T & p, T & q) { T p_res = 0; while (even(n)) { ++p_res; bisect(n); } p = p_res; q = n; } //! Алгоритм Евклида template <class T, class T2> T gcd(const T & a, const T2 & b) { return (a == 0) ? b : gcd(b % a, a); } //! Вычисляет jacobi(a,b) template <class T> T jacobi(T a, T b) { #pragma warning (push) #pragma warning (disable: 4146) if (a == 0) return 0; if (a == 1) return 1; if (a < 0) if ((b & 2) == 0) return jacobi(-a, b); else return -jacobi(-a, b); T e, a1; transform_num(a, e, a1); T s; if (even(e) || (b & 7) == 1 || (b & 7) == 7) s = 1; else s = -1; if ((b & 3) == 3 && (a1 & 3) == 3) s = -s; if (a1 == 1) return s; return s * jacobi(b % a1, a1); #pragma warning (pop) } //! Вычисляет pi(b) первых простых чисел. Возвращает ссылку на вектор с простыми (в векторе может оказаться больше простых, чем надо) и в pi - pi(b) template <class T, class T2> const std::vector<T> & get_primes(const T & b, T2 & pi) { static std::vector<T> primes; static T counted_b; // если результат уже был вычислен ранее, возвращаем его, иначе довычисляем простые if (counted_b >= b) pi = T2(std::upper_bound(primes.begin(), primes.end(), b) - primes.begin()); else { // число 2 обрабатываем отдельно if (counted_b == 0) { primes.push_back(2); counted_b = 2; } // теперь обрабатываем все нечётные, пока не наберём нужное количество простых T first = counted_b == 2 ? 3 : primes.back() + 2; for (T cur = first; cur <= b; ++++cur) { bool cur_is_prime = true; ITER(const_iterator iter, primes) //for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); iter != end; ++iter) { const T & div = *iter; if (div * div > cur) break; if (cur % div == 0) { cur_is_prime = false; break; } } if (cur_is_prime) primes.push_back(cur); } counted_b = b; pi = (T2)primes.size(); } return primes; } //! Тривиальная проверка n на простоту, перебираются все делители до m. Результат: 1 - если n точно простое, p - его найденный делитель, 0 - если неизвестно, является ли n простым или нет template <class T, class T2> T2 prime_div_trivial(const T & n, T2 m) { // сначала проверяем тривиальные случаи if (n == 2 || n == 3) return 1; if (n < 2) return 0; if (even(n)) return 2; // генерируем простые от 3 до m T2 pi; const vector<T2> & primes = get_primes(m, pi); // делим на все простые for (std::vector<T2>::const_iterator iter = primes.begin(), end = primes.end(); iter != end; ++iter) { const T2 & div = *iter; if (div * div > n) break; else if (n % div == 0) return div; } if (n < m*m) return 1; return 0; } //! Усиленный алгоритм Миллера-Рабина проверки n на простоту по базису b template <class T, class T2> bool miller_rabin(T n, T2 b) { // сначала проверяем тривиальные случаи if (n == 2) return true; if (n < 2 || even(n)) return false; // проверяем, что n и b взаимно просты (иначе это приведет к ошибке) // если они не взаимно просты, то либо n не просто, либо нужно увеличить b if (b < 2) b = 2; for (T g; (g = gcd(n, b)) != 1; ++b) if (n > g) return false; // разлагаем n-1 = q*2^p T n_1 = n; --n_1; T p, q; transform_num(n_1, p, q); // вычисляем b^q mod n, если оно равно 1 или n-1, то n, вероятно, простое T rem = powmod(T(b), q, n); if (rem == 1 || rem == n_1) return true; // теперь вычисляем b^2q, b^4q, ... , b^((n-1)/2) // если какое-либо из них равно n-1, то n, вероятно, простое for (T i = 1; i<p; i++) { mulmod(rem, rem, n); if (rem == n_1) return true; } return false; } //! Усиленный алгоритм Лукаса-Селфриджа проверки n на простоту. Используется усиленный алгоритм Лукаса с параметрами Селфриджа. Работает только с знаковыми типами!!! Второй параметр unused не используется, он только дает тип template <class T, class T2> bool lucas_selfridge(const T & n, T2 unused) { // сначала проверяем тривиальные случаи if (n == 2) return true; if (n < 2 || even(n)) return false; // проверяем, что n не является точным квадратом, иначе алгоритм даст ошибку if (perfect_square(n)) return false; // алгоритм Селфриджа: находим первое число d такое, что: // jacobi(d,n)=-1 и оно принадлежит ряду { 5,-7,9,-11,13,... } T2 dd; for (T2 d_abs = 5, d_sign = 1; ; d_sign = -d_sign, ++++d_abs) { dd = d_abs * d_sign; T g = gcd(n, d_abs); if (1 < g && g < n) // нашли делитель - d_abs return false; if (jacobi(T(dd), n) == -1) break; } // параметры Селфриджа T2 p = 1, q = (p*p - dd) / 4; // разлагаем n+1 = d*2^s T n_1 = n; ++n_1; T s, d; transform_num(n_1, s, d); // алгоритм Лукаса T u = 1, v = p, u2m = 1, v2m = p, qm = q, qm2 = q * 2, qkd = q; for (unsigned bit = 1, bits = bits_in_number(d); bit < bits; bit++) { mulmod(u2m, v2m, n); mulmod(v2m, v2m, n); while (v2m < qm2) v2m += n; v2m -= qm2; mulmod(qm, qm, n); qm2 = qm; redouble(qm2); if (test_bit(d, bit)) { T t1, t2; t1 = u2m; mulmod(t1, v, n); t2 = v2m; mulmod(t2, u, n); T t3, t4; t3 = v2m; mulmod(t3, v, n); t4 = u2m; mulmod(t4, u, n); mulmod(t4, (T)dd, n); u = t1 + t2; if (!even(u)) u += n; bisect(u); u %= n; v = t3 + t4; if (!even(v)) v += n; bisect(v); v %= n; mulmod(qkd, qm, n); } } // точно простое (или псевдо-простое) if (u == 0 || v == 0) return true; // дополнительные проверки, иначе некоторые составные числа "превратятся" в простые T qkd2 = qkd; redouble(qkd2); for (T2 r = 1; r < s; ++r) { mulmod(v, v, n); v -= qkd2; if (v < 0) v += n; if (v < 0) v += n; if (v >= n) v -= n; if (v >= n) v -= n; if (v == 0) return true; if (r < s - 1) { mulmod(qkd, qkd, n); qkd2 = qkd; redouble(qkd2); } } return false; } //! Алгоритм Бэйли-Померанс-Селфридж-Вагстафф (BPSW) проверки n на простоту template <class T> bool baillie_pomerance_selfridge_wagstaff(T n) { // сначала проверяем на тривиальные делители - до 29 int div = prime_div_trivial(n, 29); if (div == 1) return true; if (div > 1) return false; // если div == 0, то на тривиальные делители n не делится // тест Миллера-Рабина по базису 2 if (!miller_rabin(n, 2)) return false; // усиленный тест Лукаса-Селфриджа return lucas_selfridge(n, 0); } //! Алгоритм Бэйли-Померанс-Селфридж-Вагстафф (BPSW) проверки n на простоту template <class T> bool isprime(T n) { return baillie_pomerance_selfridge_wagstaff(n); } //! Метод Полларда p-1 факторизации числа. Функция возвращает найденный делитель числа или 1, если ничего не найдено template <class T> T pollard_p_1(T n) { // параметры алгоритма, существенно влияют на производительность и качество поиска const T b = 13; const T q[] = { 2, 3, 5, 7, 11, 13 }; // несколько попыток алгоритма T a = 5 % n; for (int j = 0; j<10; j++) { // ищем такое a, которое взаимно просто с n while (gcd(a, n) != 1) { mulmod(a, a, n); a += 3; a %= n; } // вычисляем a^M for (size_t i = 0; i < sizeof q / sizeof q[0]; i++) { T qq = q[i]; T e = (T)floor(log((double)b) / log((double)qq)); T aa = powmod(a, powmod(qq, e, n), n); if (aa == 0) continue; // проверяем, не найден ли ответ T g = gcd(aa - 1, n); if (1 < g && g < n) return g; } } // если ничего не нашли return 1; } //! Метод Полларда RHO факторизации числа. Возвращает его найденный делитель или 1, если ничего не было найдено template <class T> T pollard_rho(T n, unsigned iterations_count = 100000) { T b0 = rand() % n, b1 = b0, g; mulmod(b1, b1, n); if (++b1 == n) b1 = 0; g = gcd(abs(b1 - b0), n); for (unsigned count = 0; count<iterations_count && (g == 1 || g == n); count++) { mulmod(b0, b0, n); if (++b0 == n) b0 = 0; mulmod(b1, b1, n); ++b1; mulmod(b1, b1, n); if (++b1 == n) b1 = 0; g = gcd(abs(b1 - b0), n); } return g; } //! Метод Полларда-Бента факторизации числа. Возвращает его найденный делитель или 1, если ничего не было найдено template <class T> T pollard_bent(T n, unsigned iterations_count = 19) { T b0 = rand() % n, b1 = (b0*b0 + 2) % n, a = b1; for (unsigned iteration = 0, series_len = 1; iteration<iterations_count; iteration++, series_len *= 2) { T g = gcd(b1 - b0, n); for (unsigned len = 0; len<series_len && (g == 1 && g == n); len++) { b1 = (b1*b1 + 2) % n; g = gcd(abs(b1 - b0), n); } b0 = a; a = b1; if (g != 1 && g != n) return g; } return 1; } //! Метод Полларда Monte-Carlo факторизации числа. Возвращает его найденный делитель или 1, если ничего не было найдено template <class T> T pollard_monte_carlo(T n, unsigned m = 100) { T b = rand() % (m - 2) + 2; static std::vector<T> primes; static T m_max; if (primes.empty()) primes.push_back(3); if (m_max < m) { m_max = m; for (T prime = 5; prime <= m; ++++prime) { bool is_prime = true; ITER(const_iterator iter, primes) //for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); iter != end; ++iter) { T div = *iter; if (div*div > prime) break; if (prime % div == 0) { is_prime = false; break; } } if (is_prime) primes.push_back(prime); } } T g = 1; for (size_t i = 0; i<primes.size() && g == 1; i++) { T cur = primes[i]; while (cur <= n) cur *= primes[i]; cur /= primes[i]; b = powmod(b, cur, n); g = gcd(abs(b - 1), n); if (g == n) g = 1; } return g; } //! Метод Ферма факторизации числа. Работает в худшем случае за O(sqrt(n)). Возвращает найденный делитель. Второй параметр должен быть того же типа, что и первый, только signed template <class T, class T2> T ferma(const T & n, T2 unused) { T2 x = sq_root(n), y = 0, r = x*x - y*y - n; for (;;) if (r == 0) return x != y ? x - y : x + y; else if (r > 0) { r -= y + y + 1; ++y; } else { r += x + x + 1; ++x; } } //! Рекурсивная факторизация числа. Последний параметр должен быть того же типа, что и первый, только signed. Использует тест BPSW, метод Ферма, метод Полларда RHO, метод Полларда-Бента, метод Полларда Monte-Carlo template <class T, class T2> void factorize(const T & n, std::map<T, unsigned> & result, T2 unused) { if (n == 1) ; else // проверяем, не простое ли число if (isprime(n)) ++result[n]; else // если число достаточно маленькое, то его разлагаем простым перебором if (n < 1000 * 1000) { T div = prime_div_trivial(n, 1000); ++result[div]; factorize(n / div, result, unused); } else { // число большое, запускаем на нем алгоритмы факторизации T div; // сначала идут быстрые алгоритмы Полларда div = pollard_monte_carlo(n); if (div == 1) div = pollard_rho(n); if (div == 1) div = pollard_p_1(n); if (div == 1) div = pollard_bent(n); // если алгоритмы Полларда ничего не дали, то запускаем алгоритм Ферма, который гарантированно находит делитель if (div == 1) div = ferma(n, unused); // рекурсивно обрабатываем найденные множители factorize(div, result, unused); factorize(n / div, result, unused); } } LL A[MAX]; int P[MAX]; LL L[MAX]; int sz; pair<LL, LL> E[MAX]; int esz; map<LL, int> mapp; pair<LL,LL> get(LL a) { LL r1 = 1; LL r2 = 1; map <LL, unsigned> mapp; //cout << a << ":" << endl; factorize(a, mapp, (long long)0); for (map <LL, unsigned>::iterator i = mapp.begin(); i != mapp.end(); ++i) { LL p = i->first; int cnt = i->second % 3; //cout << p << " " << cnt << endl; cnt %= 3; FOR(k, 0, cnt) r1 *= p; cnt = (cnt * 2) % 3; FOR(k, 0, cnt) { if (r2 >= MAX1) continue; r2 *= p; } } return MP(r1, r2); } int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); ios::sync_with_stdio(false); cin.tie(0); FOR(i, 2, MAX) { if (!P[i]) { L[sz++] = i; int j = i; while (j < MAX) { if (P[j] == 0) P[j] = i; j += i; } } } int n; cin >> n; FOR(i, 0, n) { cin >> A[i]; } int ans = 0; FOR(i, 0, n) { E[i] = get(A[i]); mapp[E[i].first]++; //cout << "??" << A[i] << endl; } sort(E, E + n); LL tmp = 0; FOR(i, 0, n) { if (i && E[i] == E[i - 1]) continue; int a = E[i].first; int b = E[i].second; // cout << a << " " << b << " " << mapp[a] << " " << mapp[b] << endl; if (a == 1) { ans++; continue; } int cnt1 = mapp[a]; int cnt2 = mapp[b]; if (cnt1 > cnt2) { ans += cnt1; continue; } if (cnt1 == cnt2) tmp += cnt1; } cout << ans + tmp / 2 << endl; }
a.cc: In function 'const std::vector<_Tp>& get_primes(const T&, T2&)': a.cc:282:45: error: expected ';' before 'iter' 282 | ITER(const_iterator iter, primes) | ^~~~ a.cc:26:45: note: in definition of macro 'ITER' 26 | #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++) | ^~ a.cc:282:45: error: 'iter' was not declared in this scope 282 | ITER(const_iterator iter, primes) | ^~~~ a.cc:26:45: note: in definition of macro 'ITER' 26 | #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++) | ^~ a.cc:282:45: error: expected ')' before 'iter' 282 | ITER(const_iterator iter, primes) | ^~~~ a.cc:26:61: note: in definition of macro 'ITER' 26 | #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++) | ^~ a.cc:26:24: note: to match this '(' 26 | #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++) | ^ a.cc:282:25: note: in expansion of macro 'ITER' 282 | ITER(const_iterator iter, primes) | ^~~~ a.cc:282:30: error: 'const_iterator' was not declared in this scope 282 | ITER(const_iterator iter, primes) | ^~~~~~~~~~~~~~ a.cc:26:76: note: in definition of macro 'ITER' 26 | #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++) | ^~ a.cc:284:48: error: 'iter' was not declared in this scope 284 | iter != end; ++iter) | ^~~~ a.cc: In function 'T2 prime_div_trivial(const T&, T2)': a.cc:326:14: error: need 'typename' before 'std::vector<_ValT>::const_iterator' because 'std::vector<_ValT>' is a dependent scope 326 | for (std::vector<T2>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~ a.cc:326:45: error: expected ';' before 'iter' 326 | for (std::vector<T2>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~ | ; a.cc:327:17: error: 'iter' was not declared in this scope 327 | iter != end; ++iter) | ^~~~ a.cc: In function 'T pollard_monte_carlo(T, unsigned int)': a.cc:643:45: error: expected ';' before 'iter' 643 | ITER(const_iterator iter, primes) | ^~~~ a.cc:26:45: note: in definition of macro 'ITER' 26 | #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++) | ^~ a.cc:643:45: error: 'iter' was not declared in this scope 643 | ITER(const_iterator iter, primes) | ^~~~ a.cc:26:45: note: in definition of macro 'ITER' 26 | #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++) | ^~ a.cc:643:45: error: expected ')' before 'iter' 643 | ITER(const_iterator iter, primes) | ^~~~ a.cc:26:61: note: in definition of macro 'ITER' 26 | #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++) | ^~ a.cc:26:24: note: to match this '(' 26 | #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++) | ^ a.cc:643:25: note: in expansion of macro 'ITER' 643 | ITER(const_iterator iter, primes) | ^~~~ a.cc:643:30: error: 'const_iterator' was not declared in this scope 643 | ITER(const_iterator iter, primes) | ^~~~~~~~~~~~~~ a.cc:26:76: note: in definition of macro 'ITER' 26 | #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++) | ^~ a.cc:645:48: error: 'iter' was not declared in this scope 645 | iter != end; ++iter) | ^~~~ a.cc: In instantiation of 'T2 prime_div_trivial(const T&, T2) [with T = long long int; T2 = int]': a.cc:715:30: required from 'void factorize(const T&, std::map<T, unsigned int>&, T2) [with T = long long int; T2 = long long int]' 715 | T div = prime_div_trivial(n, 1000); | ~~~~~~~~~~~~~~~~~^~~~~~~~~ a.cc:754:11: required from here 754 | factorize(a, mapp, (long long)0); | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ a.cc:326:31: error: dependent-name 'std::vector<_ValT>::const_iterator' is parsed as a non-type, but instantiation yields a type 326 | for (std::vector<T2>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~~~~~~~~~~ a.cc:326:31: note: say 'typename std::vector<_ValT>::const_iterator' if a type is meant a.cc: In instantiation of 'T pollard_monte_carlo(T, unsigned int) [with T = long long int]': a.cc:724:30: required from 'void factorize(const T&, std::map<T, unsigned int>&, T2) [with T = long long int; T2 = long long int]' 724 | div = pollard_monte_carlo(n); | ~~~~~~~~~~~~~~~~~~~^~~ a.cc:754:11: required from here 754 | factorize(a, mapp, (long long)0); | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ a.cc:643:30: error: use of local variable with automatic storage from containing function 643 | ITER(const_iterator iter, primes) | ^~~~~~~~~~~~~~ a.cc:26:61: note: in definition of macro 'ITER' 26 | #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++) | ^~ a.cc:643:30: note: 'std::vector<long long int, std::allocator<long long int> >::iterator const_iterator' declared here 643 | ITER(const_iterator iter, primes) | ^~~~~~~~~~~~~~ a.cc:26:45: note: in definition of macro 'ITER' 26 | #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++) | ^~ a.cc: In instantiation of 'const std::vector<_Tp>& get_primes(const T&, T2&) [with T = int; T2 = int]': a.cc:323:40: required from 'T2 prime_div_trivial(const T&, T2) [with T = long long int; T2 = int]' 323 | const vector<T2> & primes = get_primes(m, pi); | ~~~~~~~~~~^~~~~~~ a.cc:715:30: required from 'void factorize(const T&, std::map<T, unsigned int>&, T2) [with T = long long int; T2 = long long int]' 715 | T div = prime_div_trivial(n, 1000); | ~~~~~~~~~~~~~~~~~^~~~~~~~~ a.cc:754:11: required from here 754 | factorize(a, mapp, (long long)0); | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ a.cc:282:30: error: use of local variable with automatic storage from containing function 282 | ITER(const_iterator iter, primes) | ^~~~~~~~~~~~~~ a.cc:26:61: note: in definition of macro 'ITER' 26 | #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++) | ^~ a.cc:282:30: note: 'std::vector<int>::iterator const_iterator' declared here 282 | ITER(const_iterator iter, primes) | ^~~~~~~~~~~~~~ a.cc:26:45: note: in definition of macro 'ITER' 26 | #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++) | ^~
s832717393
p04022
C++
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <sstream> #include <iomanip> #include <cstdio> #include <cstdlib> #include <cmath> #include <cctype> #include <cstring> #include <vector> #include <list> #include <queue> #include <deque> #include <stack> #include <map> #include <set> #include <algorithm> #include <iterator> #include <bitset> #include <ctime> #include<complex> using namespace std; #define FOR(i,a,b) for (int i = (a); i < (b); i++) #define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--) #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++) #define FILL(a,value) memset(a, value, sizeof(a)) #define SZ(a) (int)a.size() #define ALL(a) a.begin(), a.end() #define PB push_back #define MP make_pair typedef long long LL; typedef vector<int> VI; typedef pair<int, int> PII; const double PI = acos(-1.0); const int INF = 1000 * 1000 * 1000 + 7; const LL LINF = INF * (LL)INF; const int MAX = 1000 * 100 + 47; const LL MAX1 = MAX * (LL)MAX; unsigned long long abs(unsigned long long n) { return n; } //! Возвращает true, если n четное template <class T> bool even(const T & n) { // return n % 2 == 0; return (n & 1) == 0; } //! Делит число на 2 template <class T> void bisect(T & n) { // n /= 2; n >>= 1; } //! Умножает число на 2 template <class T> void redouble(T & n) { // n *= 2; n <<= 1; } //! Возвращает true, если n - точный квадрат простого числа template <class T> bool perfect_square(const T & n) { T sq = (T)ceil(sqrt((double)n)); return sq*sq == n; } //! Вычисляет корень из числа, округляя его вниз template <class T> T sq_root(const T & n) { return (T)floor(sqrt((double)n)); } //! Возвращает количество бит в числе (т.е. минимальное количество бит, которыми можно представить данное число) template <class T> unsigned bits_in_number(T n) { if (n == 0) return 1; unsigned result = 0; while (n) { bisect(n); ++result; } return result; } //! Возвращает значение k-го бита числа (биты нумеруются с нуля) template <class T> bool test_bit(const T & n, unsigned k) { return (n & (T(1) << k)) != 0; } //! Умножает a *= b (mod n) template <class T> void mulmod(T & a, T b, const T & n) { // наивная версия, годится только для длинной арифметики a *= b; a %= n; } template <> void mulmod(int & a, int b, const int & n) { a = int((((long long)a) * b) % n); } template <> void mulmod(unsigned & a, unsigned b, const unsigned & n) { a = unsigned((((unsigned long long)a) * b) % n); } template <> void mulmod(unsigned long long & a, unsigned long long b, const unsigned long long & n) { // сложная версия, основанная на бинарном разложении произведения в сумму if (a >= n) a %= n; if (b >= n) b %= n; unsigned long long res = 0; while (b) if (!even(b)) { res += a; while (res >= n) res -= n; --b; } else { redouble(a); while (a >= n) a -= n; bisect(b); } a = res; } template <> void mulmod(long long & a, long long b, const long long & n) { bool neg = false; if (a < 0) { neg = !neg; a = -a; } if (b < 0) { neg = !neg; b = -b; } unsigned long long aa = a; mulmod<unsigned long long>(aa, (unsigned long long)b, (unsigned long long)n); a = (long long)aa * (neg ? -1 : 1); } //! Вычисляет a^k (mod n). Использует бинарное возведение в степень template <class T, class T2> T powmod(T a, T2 k, const T & n) { T res = 1; while (k) if (!even(k)) { mulmod(res, a, n); --k; } else { mulmod(a, a, n); bisect(k); } return res; } //! Переводит число n в форму q*2^p template <class T> void transform_num(T n, T & p, T & q) { T p_res = 0; while (even(n)) { ++p_res; bisect(n); } p = p_res; q = n; } //! Алгоритм Евклида template <class T, class T2> T gcd(const T & a, const T2 & b) { return (a == 0) ? b : gcd(b % a, a); } //! Вычисляет jacobi(a,b) template <class T> T jacobi(T a, T b) { #pragma warning (push) #pragma warning (disable: 4146) if (a == 0) return 0; if (a == 1) return 1; if (a < 0) if ((b & 2) == 0) return jacobi(-a, b); else return -jacobi(-a, b); T e, a1; transform_num(a, e, a1); T s; if (even(e) || (b & 7) == 1 || (b & 7) == 7) s = 1; else s = -1; if ((b & 3) == 3 && (a1 & 3) == 3) s = -s; if (a1 == 1) return s; return s * jacobi(b % a1, a1); #pragma warning (pop) } //! Вычисляет pi(b) первых простых чисел. Возвращает ссылку на вектор с простыми (в векторе может оказаться больше простых, чем надо) и в pi - pi(b) template <class T, class T2> const std::vector<T> & get_primes(const T & b, T2 & pi) { static std::vector<T> primes; static T counted_b; // если результат уже был вычислен ранее, возвращаем его, иначе довычисляем простые if (counted_b >= b) pi = T2(std::upper_bound(primes.begin(), primes.end(), b) - primes.begin()); else { // число 2 обрабатываем отдельно if (counted_b == 0) { primes.push_back(2); counted_b = 2; } // теперь обрабатываем все нечётные, пока не наберём нужное количество простых T first = counted_b == 2 ? 3 : primes.back() + 2; for (T cur = first; cur <= b; ++++cur) { bool cur_is_prime = true; for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); iter != end; ++iter) { const T & div = *iter; if (div * div > cur) break; if (cur % div == 0) { cur_is_prime = false; break; } } if (cur_is_prime) primes.push_back(cur); } counted_b = b; pi = (T2)primes.size(); } return primes; } //! Тривиальная проверка n на простоту, перебираются все делители до m. Результат: 1 - если n точно простое, p - его найденный делитель, 0 - если неизвестно, является ли n простым или нет template <class T, class T2> T2 prime_div_trivial(const T & n, T2 m) { // сначала проверяем тривиальные случаи if (n == 2 || n == 3) return 1; if (n < 2) return 0; if (even(n)) return 2; // генерируем простые от 3 до m T2 pi; const vector<T2> & primes = get_primes(m, pi); // делим на все простые for (std::vector<T2>::const_iterator iter = primes.begin(), end = primes.end(); iter != end; ++iter) { const T2 & div = *iter; if (div * div > n) break; else if (n % div == 0) return div; } if (n < m*m) return 1; return 0; } //! Усиленный алгоритм Миллера-Рабина проверки n на простоту по базису b template <class T, class T2> bool miller_rabin(T n, T2 b) { // сначала проверяем тривиальные случаи if (n == 2) return true; if (n < 2 || even(n)) return false; // проверяем, что n и b взаимно просты (иначе это приведет к ошибке) // если они не взаимно просты, то либо n не просто, либо нужно увеличить b if (b < 2) b = 2; for (T g; (g = gcd(n, b)) != 1; ++b) if (n > g) return false; // разлагаем n-1 = q*2^p T n_1 = n; --n_1; T p, q; transform_num(n_1, p, q); // вычисляем b^q mod n, если оно равно 1 или n-1, то n, вероятно, простое T rem = powmod(T(b), q, n); if (rem == 1 || rem == n_1) return true; // теперь вычисляем b^2q, b^4q, ... , b^((n-1)/2) // если какое-либо из них равно n-1, то n, вероятно, простое for (T i = 1; i<p; i++) { mulmod(rem, rem, n); if (rem == n_1) return true; } return false; } //! Усиленный алгоритм Лукаса-Селфриджа проверки n на простоту. Используется усиленный алгоритм Лукаса с параметрами Селфриджа. Работает только с знаковыми типами!!! Второй параметр unused не используется, он только дает тип template <class T, class T2> bool lucas_selfridge(const T & n, T2 unused) { // сначала проверяем тривиальные случаи if (n == 2) return true; if (n < 2 || even(n)) return false; // проверяем, что n не является точным квадратом, иначе алгоритм даст ошибку if (perfect_square(n)) return false; // алгоритм Селфриджа: находим первое число d такое, что: // jacobi(d,n)=-1 и оно принадлежит ряду { 5,-7,9,-11,13,... } T2 dd; for (T2 d_abs = 5, d_sign = 1; ; d_sign = -d_sign, ++++d_abs) { dd = d_abs * d_sign; T g = gcd(n, d_abs); if (1 < g && g < n) // нашли делитель - d_abs return false; if (jacobi(T(dd), n) == -1) break; } // параметры Селфриджа T2 p = 1, q = (p*p - dd) / 4; // разлагаем n+1 = d*2^s T n_1 = n; ++n_1; T s, d; transform_num(n_1, s, d); // алгоритм Лукаса T u = 1, v = p, u2m = 1, v2m = p, qm = q, qm2 = q * 2, qkd = q; for (unsigned bit = 1, bits = bits_in_number(d); bit < bits; bit++) { mulmod(u2m, v2m, n); mulmod(v2m, v2m, n); while (v2m < qm2) v2m += n; v2m -= qm2; mulmod(qm, qm, n); qm2 = qm; redouble(qm2); if (test_bit(d, bit)) { T t1, t2; t1 = u2m; mulmod(t1, v, n); t2 = v2m; mulmod(t2, u, n); T t3, t4; t3 = v2m; mulmod(t3, v, n); t4 = u2m; mulmod(t4, u, n); mulmod(t4, (T)dd, n); u = t1 + t2; if (!even(u)) u += n; bisect(u); u %= n; v = t3 + t4; if (!even(v)) v += n; bisect(v); v %= n; mulmod(qkd, qm, n); } } // точно простое (или псевдо-простое) if (u == 0 || v == 0) return true; // дополнительные проверки, иначе некоторые составные числа "превратятся" в простые T qkd2 = qkd; redouble(qkd2); for (T2 r = 1; r < s; ++r) { mulmod(v, v, n); v -= qkd2; if (v < 0) v += n; if (v < 0) v += n; if (v >= n) v -= n; if (v >= n) v -= n; if (v == 0) return true; if (r < s - 1) { mulmod(qkd, qkd, n); qkd2 = qkd; redouble(qkd2); } } return false; } //! Алгоритм Бэйли-Померанс-Селфридж-Вагстафф (BPSW) проверки n на простоту template <class T> bool baillie_pomerance_selfridge_wagstaff(T n) { // сначала проверяем на тривиальные делители - до 29 int div = prime_div_trivial(n, 29); if (div == 1) return true; if (div > 1) return false; // если div == 0, то на тривиальные делители n не делится // тест Миллера-Рабина по базису 2 if (!miller_rabin(n, 2)) return false; // усиленный тест Лукаса-Селфриджа return lucas_selfridge(n, 0); } //! Алгоритм Бэйли-Померанс-Селфридж-Вагстафф (BPSW) проверки n на простоту template <class T> bool isprime(T n) { return baillie_pomerance_selfridge_wagstaff(n); } //! Метод Полларда p-1 факторизации числа. Функция возвращает найденный делитель числа или 1, если ничего не найдено template <class T> T pollard_p_1(T n) { // параметры алгоритма, существенно влияют на производительность и качество поиска const T b = 13; const T q[] = { 2, 3, 5, 7, 11, 13 }; // несколько попыток алгоритма T a = 5 % n; for (int j = 0; j<10; j++) { // ищем такое a, которое взаимно просто с n while (gcd(a, n) != 1) { mulmod(a, a, n); a += 3; a %= n; } // вычисляем a^M for (size_t i = 0; i < sizeof q / sizeof q[0]; i++) { T qq = q[i]; T e = (T)floor(log((double)b) / log((double)qq)); T aa = powmod(a, powmod(qq, e, n), n); if (aa == 0) continue; // проверяем, не найден ли ответ T g = gcd(aa - 1, n); if (1 < g && g < n) return g; } } // если ничего не нашли return 1; } //! Метод Полларда RHO факторизации числа. Возвращает его найденный делитель или 1, если ничего не было найдено template <class T> T pollard_rho(T n, unsigned iterations_count = 100000) { T b0 = rand() % n, b1 = b0, g; mulmod(b1, b1, n); if (++b1 == n) b1 = 0; g = gcd(abs(b1 - b0), n); for (unsigned count = 0; count<iterations_count && (g == 1 || g == n); count++) { mulmod(b0, b0, n); if (++b0 == n) b0 = 0; mulmod(b1, b1, n); ++b1; mulmod(b1, b1, n); if (++b1 == n) b1 = 0; g = gcd(abs(b1 - b0), n); } return g; } //! Метод Полларда-Бента факторизации числа. Возвращает его найденный делитель или 1, если ничего не было найдено template <class T> T pollard_bent(T n, unsigned iterations_count = 19) { T b0 = rand() % n, b1 = (b0*b0 + 2) % n, a = b1; for (unsigned iteration = 0, series_len = 1; iteration<iterations_count; iteration++, series_len *= 2) { T g = gcd(b1 - b0, n); for (unsigned len = 0; len<series_len && (g == 1 && g == n); len++) { b1 = (b1*b1 + 2) % n; g = gcd(abs(b1 - b0), n); } b0 = a; a = b1; if (g != 1 && g != n) return g; } return 1; } //! Метод Полларда Monte-Carlo факторизации числа. Возвращает его найденный делитель или 1, если ничего не было найдено template <class T> T pollard_monte_carlo(T n, unsigned m = 100) { T b = rand() % (m - 2) + 2; static std::vector<T> primes; static T m_max; if (primes.empty()) primes.push_back(3); if (m_max < m) { m_max = m; for (T prime = 5; prime <= m; ++++prime) { bool is_prime = true; for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); iter != end; ++iter) { T div = *iter; if (div*div > prime) break; if (prime % div == 0) { is_prime = false; break; } } if (is_prime) primes.push_back(prime); } } T g = 1; for (size_t i = 0; i<primes.size() && g == 1; i++) { T cur = primes[i]; while (cur <= n) cur *= primes[i]; cur /= primes[i]; b = powmod(b, cur, n); g = gcd(abs(b - 1), n); if (g == n) g = 1; } return g; } //! Метод Ферма факторизации числа. Работает в худшем случае за O(sqrt(n)). Возвращает найденный делитель. Второй параметр должен быть того же типа, что и первый, только signed template <class T, class T2> T ferma(const T & n, T2 unused) { T2 x = sq_root(n), y = 0, r = x*x - y*y - n; for (;;) if (r == 0) return x != y ? x - y : x + y; else if (r > 0) { r -= y + y + 1; ++y; } else { r += x + x + 1; ++x; } } //! Рекурсивная факторизация числа. Последний параметр должен быть того же типа, что и первый, только signed. Использует тест BPSW, метод Ферма, метод Полларда RHO, метод Полларда-Бента, метод Полларда Monte-Carlo template <class T, class T2> void factorize(const T & n, std::map<T, unsigned> & result, T2 unused) { if (n == 1) ; else // проверяем, не простое ли число if (isprime(n)) ++result[n]; else // если число достаточно маленькое, то его разлагаем простым перебором if (n < 1000 * 1000) { T div = prime_div_trivial(n, 1000); ++result[div]; factorize(n / div, result, unused); } else { // число большое, запускаем на нем алгоритмы факторизации T div; // сначала идут быстрые алгоритмы Полларда div = pollard_monte_carlo(n); if (div == 1) div = pollard_rho(n); if (div == 1) div = pollard_p_1(n); if (div == 1) div = pollard_bent(n); // если алгоритмы Полларда ничего не дали, то запускаем алгоритм Ферма, который гарантированно находит делитель if (div == 1) div = ferma(n, unused); // рекурсивно обрабатываем найденные множители factorize(div, result, unused); factorize(n / div, result, unused); } } LL A[MAX]; int P[MAX]; LL L[MAX]; int sz; pair<LL, LL> E[MAX]; int esz; map<LL, int> mapp; pair<LL,LL> get(LL a) { LL r1 = 1; LL r2 = 1; map <LL, unsigned> mapp; //cout << a << ":" << endl; factorize(a, mapp, (long long)0); for (map <LL, unsigned>::iterator i = mapp.begin(); i != mapp.end(); ++i) { LL p = i->first; int cnt = i->second % 3; //cout << p << " " << cnt << endl; cnt %= 3; FOR(k, 0, cnt) r1 *= p; cnt = (cnt * 2) % 3; FOR(k, 0, cnt) { if (r2 >= MAX1) continue; r2 *= p; } } return MP(r1, r2); } int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); ios::sync_with_stdio(false); cin.tie(0); FOR(i, 2, MAX) { if (!P[i]) { L[sz++] = i; int j = i; while (j < MAX) { if (P[j] == 0) P[j] = i; j += i; } } } int n; cin >> n; FOR(i, 0, n) { cin >> A[i]; } int ans = 0; FOR(i, 0, n) { E[i] = get(A[i]); mapp[E[i].first]++; //cout << "??" << A[i] << endl; } sort(E, E + n); LL tmp = 0; FOR(i, 0, n) { if (i && E[i] == E[i - 1]) continue; int a = E[i].first; int b = E[i].second; // cout << a << " " << b << " " << mapp[a] << " " << mapp[b] << endl; if (a == 1) { ans++; continue; } int cnt1 = mapp[a]; int cnt2 = mapp[b]; if (cnt1 > cnt2) { ans += cnt1; continue; } if (cnt1 == cnt2) tmp += cnt1; } cout << ans + tmp / 2 << endl; }
a.cc: In function 'const std::vector<_Tp>& get_primes(const T&, T2&)': a.cc:282:30: error: need 'typename' before 'std::vector<_Tp>::const_iterator' because 'std::vector<_Tp>' is a dependent scope 282 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~ a.cc:282:60: error: expected ';' before 'iter' 282 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~ | ; a.cc:283:33: error: 'iter' was not declared in this scope 283 | iter != end; ++iter) | ^~~~ a.cc: In function 'T2 prime_div_trivial(const T&, T2)': a.cc:325:14: error: need 'typename' before 'std::vector<_ValT>::const_iterator' because 'std::vector<_ValT>' is a dependent scope 325 | for (std::vector<T2>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~ a.cc:325:45: error: expected ';' before 'iter' 325 | for (std::vector<T2>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~ | ; a.cc:326:17: error: 'iter' was not declared in this scope 326 | iter != end; ++iter) | ^~~~ a.cc: In function 'T pollard_monte_carlo(T, unsigned int)': a.cc:642:30: error: need 'typename' before 'std::vector<_Tp>::const_iterator' because 'std::vector<_Tp>' is a dependent scope 642 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~ a.cc:642:60: error: expected ';' before 'iter' 642 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~ | ; a.cc:643:33: error: 'iter' was not declared in this scope 643 | iter != end; ++iter) | ^~~~ a.cc: In instantiation of 'T2 prime_div_trivial(const T&, T2) [with T = long long int; T2 = int]': a.cc:713:30: required from 'void factorize(const T&, std::map<T, unsigned int>&, T2) [with T = long long int; T2 = long long int]' 713 | T div = prime_div_trivial(n, 1000); | ~~~~~~~~~~~~~~~~~^~~~~~~~~ a.cc:752:11: required from here 752 | factorize(a, mapp, (long long)0); | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ a.cc:325:31: error: dependent-name 'std::vector<_ValT>::const_iterator' is parsed as a non-type, but instantiation yields a type 325 | for (std::vector<T2>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~~~~~~~~~~ a.cc:325:31: note: say 'typename std::vector<_ValT>::const_iterator' if a type is meant a.cc: In instantiation of 'T pollard_monte_carlo(T, unsigned int) [with T = long long int]': a.cc:722:30: required from 'void factorize(const T&, std::map<T, unsigned int>&, T2) [with T = long long int; T2 = long long int]' 722 | div = pollard_monte_carlo(n); | ~~~~~~~~~~~~~~~~~~~^~~ a.cc:752:11: required from here 752 | factorize(a, mapp, (long long)0); | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ a.cc:642:46: error: dependent-name 'std::vector<_Tp>::const_iterator' is parsed as a non-type, but instantiation yields a type 642 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~~~~~~~~~~ a.cc:642:46: note: say 'typename std::vector<_Tp>::const_iterator' if a type is meant a.cc: In instantiation of 'const std::vector<_Tp>& get_primes(const T&, T2&) [with T = int; T2 = int]': a.cc:322:40: required from 'T2 prime_div_trivial(const T&, T2) [with T = long long int; T2 = int]' 322 | const vector<T2> & primes = get_primes(m, pi); | ~~~~~~~~~~^~~~~~~ a.cc:713:30: required from 'void factorize(const T&, std::map<T, unsigned int>&, T2) [with T = long long int; T2 = long long int]' 713 | T div = prime_div_trivial(n, 1000); | ~~~~~~~~~~~~~~~~~^~~~~~~~~ a.cc:752:11: required from here 752 | factorize(a, mapp, (long long)0); | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ a.cc:282:46: error: dependent-name 'std::vector<_Tp>::const_iterator' is parsed as a non-type, but instantiation yields a type 282 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~~~~~~~~~~ a.cc:282:46: note: say 'typename std::vector<_Tp>::const_iterator' if a type is meant
s450631881
p04022
C++
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <sstream> #include <iomanip> #include <cstdio> #include <cstdlib> #include <cmath> #include <cctype> #include <cstring> #include <vector> #include <list> #include <queue> #include <deque> #include <stack> #include <map> #include <set> #include <algorithm> #include <iterator> #include <bitset> #include <ctime> #include<complex> using namespace std; #define FOR(i,a,b) for (int i = (a); i < (b); i++) #define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--) #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++) #define FILL(a,value) memset(a, value, sizeof(a)) #define SZ(a) (int)a.size() #define ALL(a) a.begin(), a.end() #define PB push_back #define MP make_pair typedef long long LL; typedef vector<int> VI; typedef pair<int, int> PII; const double PI = acos(-1.0); const int INF = 1000 * 1000 * 1000 + 7; const LL LINF = INF * (LL)INF; const int MAX = 1000 * 100 + 47; const int MAX1 = MAX * (LL)MAX; unsigned long long abs(unsigned long long n) { return n; } //! Возвращает true, если n четное template <class T> bool even(const T & n) { // return n % 2 == 0; return (n & 1) == 0; } //! Делит число на 2 template <class T> void bisect(T & n) { // n /= 2; n >>= 1; } //! Умножает число на 2 template <class T> void redouble(T & n) { // n *= 2; n <<= 1; } //! Возвращает true, если n - точный квадрат простого числа template <class T> bool perfect_square(const T & n) { T sq = (T)ceil(sqrt((double)n)); return sq*sq == n; } //! Вычисляет корень из числа, округляя его вниз template <class T> T sq_root(const T & n) { return (T)floor(sqrt((double)n)); } //! Возвращает количество бит в числе (т.е. минимальное количество бит, которыми можно представить данное число) template <class T> unsigned bits_in_number(T n) { if (n == 0) return 1; unsigned result = 0; while (n) { bisect(n); ++result; } return result; } //! Возвращает значение k-го бита числа (биты нумеруются с нуля) template <class T> bool test_bit(const T & n, unsigned k) { return (n & (T(1) << k)) != 0; } //! Умножает a *= b (mod n) template <class T> void mulmod(T & a, T b, const T & n) { // наивная версия, годится только для длинной арифметики a *= b; a %= n; } template <> void mulmod(int & a, int b, const int & n) { a = int((((long long)a) * b) % n); } template <> void mulmod(unsigned & a, unsigned b, const unsigned & n) { a = unsigned((((unsigned long long)a) * b) % n); } template <> void mulmod(unsigned long long & a, unsigned long long b, const unsigned long long & n) { // сложная версия, основанная на бинарном разложении произведения в сумму if (a >= n) a %= n; if (b >= n) b %= n; unsigned long long res = 0; while (b) if (!even(b)) { res += a; while (res >= n) res -= n; --b; } else { redouble(a); while (a >= n) a -= n; bisect(b); } a = res; } template <> void mulmod(long long & a, long long b, const long long & n) { bool neg = false; if (a < 0) { neg = !neg; a = -a; } if (b < 0) { neg = !neg; b = -b; } unsigned long long aa = a; mulmod<unsigned long long>(aa, (unsigned long long)b, (unsigned long long)n); a = (long long)aa * (neg ? -1 : 1); } //! Вычисляет a^k (mod n). Использует бинарное возведение в степень template <class T, class T2> T powmod(T a, T2 k, const T & n) { T res = 1; while (k) if (!even(k)) { mulmod(res, a, n); --k; } else { mulmod(a, a, n); bisect(k); } return res; } //! Переводит число n в форму q*2^p template <class T> void transform_num(T n, T & p, T & q) { T p_res = 0; while (even(n)) { ++p_res; bisect(n); } p = p_res; q = n; } //! Алгоритм Евклида template <class T, class T2> T gcd(const T & a, const T2 & b) { return (a == 0) ? b : gcd(b % a, a); } //! Вычисляет jacobi(a,b) template <class T> T jacobi(T a, T b) { #pragma warning (push) #pragma warning (disable: 4146) if (a == 0) return 0; if (a == 1) return 1; if (a < 0) if ((b & 2) == 0) return jacobi(-a, b); else return -jacobi(-a, b); T e, a1; transform_num(a, e, a1); T s; if (even(e) || (b & 7) == 1 || (b & 7) == 7) s = 1; else s = -1; if ((b & 3) == 3 && (a1 & 3) == 3) s = -s; if (a1 == 1) return s; return s * jacobi(b % a1, a1); #pragma warning (pop) } //! Вычисляет pi(b) первых простых чисел. Возвращает ссылку на вектор с простыми (в векторе может оказаться больше простых, чем надо) и в pi - pi(b) template <class T, class T2> const std::vector<T> & get_primes(const T & b, T2 & pi) { static std::vector<T> primes; static T counted_b; // если результат уже был вычислен ранее, возвращаем его, иначе довычисляем простые if (counted_b >= b) pi = T2(std::upper_bound(primes.begin(), primes.end(), b) - primes.begin()); else { // число 2 обрабатываем отдельно if (counted_b == 0) { primes.push_back(2); counted_b = 2; } // теперь обрабатываем все нечётные, пока не наберём нужное количество простых T first = counted_b == 2 ? 3 : primes.back() + 2; for (T cur = first; cur <= b; ++++cur) { bool cur_is_prime = true; for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); iter != end; ++iter) { const T & div = *iter; if (div * div > cur) break; if (cur % div == 0) { cur_is_prime = false; break; } } if (cur_is_prime) primes.push_back(cur); } counted_b = b; pi = (T2)primes.size(); } return primes; } //! Тривиальная проверка n на простоту, перебираются все делители до m. Результат: 1 - если n точно простое, p - его найденный делитель, 0 - если неизвестно, является ли n простым или нет template <class T, class T2> T2 prime_div_trivial(const T & n, T2 m) { // сначала проверяем тривиальные случаи if (n == 2 || n == 3) return 1; if (n < 2) return 0; if (even(n)) return 2; // генерируем простые от 3 до m T2 pi; const vector<T2> & primes = get_primes(m, pi); // делим на все простые for (std::vector<T2>::const_iterator iter = primes.begin(), end = primes.end(); iter != end; ++iter) { const T2 & div = *iter; if (div * div > n) break; else if (n % div == 0) return div; } if (n < m*m) return 1; return 0; } //! Усиленный алгоритм Миллера-Рабина проверки n на простоту по базису b template <class T, class T2> bool miller_rabin(T n, T2 b) { // сначала проверяем тривиальные случаи if (n == 2) return true; if (n < 2 || even(n)) return false; // проверяем, что n и b взаимно просты (иначе это приведет к ошибке) // если они не взаимно просты, то либо n не просто, либо нужно увеличить b if (b < 2) b = 2; for (T g; (g = gcd(n, b)) != 1; ++b) if (n > g) return false; // разлагаем n-1 = q*2^p T n_1 = n; --n_1; T p, q; transform_num(n_1, p, q); // вычисляем b^q mod n, если оно равно 1 или n-1, то n, вероятно, простое T rem = powmod(T(b), q, n); if (rem == 1 || rem == n_1) return true; // теперь вычисляем b^2q, b^4q, ... , b^((n-1)/2) // если какое-либо из них равно n-1, то n, вероятно, простое for (T i = 1; i<p; i++) { mulmod(rem, rem, n); if (rem == n_1) return true; } return false; } //! Усиленный алгоритм Лукаса-Селфриджа проверки n на простоту. Используется усиленный алгоритм Лукаса с параметрами Селфриджа. Работает только с знаковыми типами!!! Второй параметр unused не используется, он только дает тип template <class T, class T2> bool lucas_selfridge(const T & n, T2 unused) { // сначала проверяем тривиальные случаи if (n == 2) return true; if (n < 2 || even(n)) return false; // проверяем, что n не является точным квадратом, иначе алгоритм даст ошибку if (perfect_square(n)) return false; // алгоритм Селфриджа: находим первое число d такое, что: // jacobi(d,n)=-1 и оно принадлежит ряду { 5,-7,9,-11,13,... } T2 dd; for (T2 d_abs = 5, d_sign = 1; ; d_sign = -d_sign, ++++d_abs) { dd = d_abs * d_sign; T g = gcd(n, d_abs); if (1 < g && g < n) // нашли делитель - d_abs return false; if (jacobi(T(dd), n) == -1) break; } // параметры Селфриджа T2 p = 1, q = (p*p - dd) / 4; // разлагаем n+1 = d*2^s T n_1 = n; ++n_1; T s, d; transform_num(n_1, s, d); // алгоритм Лукаса T u = 1, v = p, u2m = 1, v2m = p, qm = q, qm2 = q * 2, qkd = q; for (unsigned bit = 1, bits = bits_in_number(d); bit < bits; bit++) { mulmod(u2m, v2m, n); mulmod(v2m, v2m, n); while (v2m < qm2) v2m += n; v2m -= qm2; mulmod(qm, qm, n); qm2 = qm; redouble(qm2); if (test_bit(d, bit)) { T t1, t2; t1 = u2m; mulmod(t1, v, n); t2 = v2m; mulmod(t2, u, n); T t3, t4; t3 = v2m; mulmod(t3, v, n); t4 = u2m; mulmod(t4, u, n); mulmod(t4, (T)dd, n); u = t1 + t2; if (!even(u)) u += n; bisect(u); u %= n; v = t3 + t4; if (!even(v)) v += n; bisect(v); v %= n; mulmod(qkd, qm, n); } } // точно простое (или псевдо-простое) if (u == 0 || v == 0) return true; // дополнительные проверки, иначе некоторые составные числа "превратятся" в простые T qkd2 = qkd; redouble(qkd2); for (T2 r = 1; r < s; ++r) { mulmod(v, v, n); v -= qkd2; if (v < 0) v += n; if (v < 0) v += n; if (v >= n) v -= n; if (v >= n) v -= n; if (v == 0) return true; if (r < s - 1) { mulmod(qkd, qkd, n); qkd2 = qkd; redouble(qkd2); } } return false; } //! Алгоритм Бэйли-Померанс-Селфридж-Вагстафф (BPSW) проверки n на простоту template <class T> bool baillie_pomerance_selfridge_wagstaff(T n) { // сначала проверяем на тривиальные делители - до 29 int div = prime_div_trivial(n, 29); if (div == 1) return true; if (div > 1) return false; // если div == 0, то на тривиальные делители n не делится // тест Миллера-Рабина по базису 2 if (!miller_rabin(n, 2)) return false; // усиленный тест Лукаса-Селфриджа return lucas_selfridge(n, 0); } //! Алгоритм Бэйли-Померанс-Селфридж-Вагстафф (BPSW) проверки n на простоту template <class T> bool isprime(T n) { return baillie_pomerance_selfridge_wagstaff(n); } //! Метод Полларда p-1 факторизации числа. Функция возвращает найденный делитель числа или 1, если ничего не найдено template <class T> T pollard_p_1(T n) { // параметры алгоритма, существенно влияют на производительность и качество поиска const T b = 13; const T q[] = { 2, 3, 5, 7, 11, 13 }; // несколько попыток алгоритма T a = 5 % n; for (int j = 0; j<10; j++) { // ищем такое a, которое взаимно просто с n while (gcd(a, n) != 1) { mulmod(a, a, n); a += 3; a %= n; } // вычисляем a^M for (size_t i = 0; i < sizeof q / sizeof q[0]; i++) { T qq = q[i]; T e = (T)floor(log((double)b) / log((double)qq)); T aa = powmod(a, powmod(qq, e, n), n); if (aa == 0) continue; // проверяем, не найден ли ответ T g = gcd(aa - 1, n); if (1 < g && g < n) return g; } } // если ничего не нашли return 1; } //! Метод Полларда RHO факторизации числа. Возвращает его найденный делитель или 1, если ничего не было найдено template <class T> T pollard_rho(T n, unsigned iterations_count = 100000) { T b0 = rand() % n, b1 = b0, g; mulmod(b1, b1, n); if (++b1 == n) b1 = 0; g = gcd(abs(b1 - b0), n); for (unsigned count = 0; count<iterations_count && (g == 1 || g == n); count++) { mulmod(b0, b0, n); if (++b0 == n) b0 = 0; mulmod(b1, b1, n); ++b1; mulmod(b1, b1, n); if (++b1 == n) b1 = 0; g = gcd(abs(b1 - b0), n); } return g; } //! Метод Полларда-Бента факторизации числа. Возвращает его найденный делитель или 1, если ничего не было найдено template <class T> T pollard_bent(T n, unsigned iterations_count = 19) { T b0 = rand() % n, b1 = (b0*b0 + 2) % n, a = b1; for (unsigned iteration = 0, series_len = 1; iteration<iterations_count; iteration++, series_len *= 2) { T g = gcd(b1 - b0, n); for (unsigned len = 0; len<series_len && (g == 1 && g == n); len++) { b1 = (b1*b1 + 2) % n; g = gcd(abs(b1 - b0), n); } b0 = a; a = b1; if (g != 1 && g != n) return g; } return 1; } //! Метод Полларда Monte-Carlo факторизации числа. Возвращает его найденный делитель или 1, если ничего не было найдено template <class T> T pollard_monte_carlo(T n, unsigned m = 100) { T b = rand() % (m - 2) + 2; static std::vector<T> primes; static T m_max; if (primes.empty()) primes.push_back(3); if (m_max < m) { m_max = m; for (T prime = 5; prime <= m; ++++prime) { bool is_prime = true; for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); iter != end; ++iter) { T div = *iter; if (div*div > prime) break; if (prime % div == 0) { is_prime = false; break; } } if (is_prime) primes.push_back(prime); } } T g = 1; for (size_t i = 0; i<primes.size() && g == 1; i++) { T cur = primes[i]; while (cur <= n) cur *= primes[i]; cur /= primes[i]; b = powmod(b, cur, n); g = gcd(abs(b - 1), n); if (g == n) g = 1; } return g; } //! Метод Ферма факторизации числа. Работает в худшем случае за O(sqrt(n)). Возвращает найденный делитель. Второй параметр должен быть того же типа, что и первый, только signed template <class T, class T2> T ferma(const T & n, T2 unused) { T2 x = sq_root(n), y = 0, r = x*x - y*y - n; for (;;) if (r == 0) return x != y ? x - y : x + y; else if (r > 0) { r -= y + y + 1; ++y; } else { r += x + x + 1; ++x; } } //! Рекурсивная факторизация числа. Последний параметр должен быть того же типа, что и первый, только signed. Использует тест BPSW, метод Ферма, метод Полларда RHO, метод Полларда-Бента, метод Полларда Monte-Carlo template <class T, class T2> void factorize(const T & n, std::map<T, unsigned> & result, T2 unused) { if (n == 1) ; else // проверяем, не простое ли число if (isprime(n)) ++result[n]; else // если число достаточно маленькое, то его разлагаем простым перебором if (n < 1000 * 1000) { T div = prime_div_trivial(n, 1000); ++result[div]; factorize(n / div, result, unused); } else { // число большое, запускаем на нем алгоритмы факторизации T div; // сначала идут быстрые алгоритмы Полларда div = pollard_monte_carlo(n); if (div == 1) div = pollard_rho(n); if (div == 1) div = pollard_p_1(n); if (div == 1) div = pollard_bent(n); // если алгоритмы Полларда ничего не дали, то запускаем алгоритм Ферма, который гарантированно находит делитель if (div == 1) div = ferma(n, unused); // рекурсивно обрабатываем найденные множители factorize(div, result, unused); factorize(n / div, result, unused); } } LL A[MAX]; int P[MAX]; LL L[MAX]; int sz; pair<LL, LL> E[MAX]; int esz; map<LL, int> mapp; pair<LL,LL> get(LL a) { LL r1 = 1; LL r2 = 1; map <LL, unsigned> mapp; //cout << a << ":" << endl; factorize(a, mapp, (long long)0); for (map <LL, unsigned>::iterator i = mapp.begin(); i != mapp.end(); ++i) { LL p = i->first; int cnt = i->second % 3; //cout << p << " " << cnt << endl; cnt %= 3; FOR(k, 0, cnt) r1 *= p; cnt = (cnt * 2) % 3; FOR(k, 0, cnt) { if (r2 >= MAX1) continue; r2 *= p; } } return MP(r1, r2); } int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); ios::sync_with_stdio(false); cin.tie(0); FOR(i, 2, MAX) { if (!P[i]) { L[sz++] = i; int j = i; while (j < MAX) { if (P[j] == 0) P[j] = i; j += i; } } } int n; cin >> n; FOR(i, 0, n) { cin >> A[i]; } int ans = 0; FOR(i, 0, n) { E[i] = get(A[i]); mapp[E[i].first]++; //cout << "??" << A[i] << endl; } sort(E, E + n); LL tmp = 0; FOR(i, 0, n) { if (i && E[i] == E[i - 1]) continue; int a = E[i].first; int b = E[i].second; // cout << a << " " << b << " " << mapp[a] << " " << mapp[b] << endl; if (a == 1) { ans++; continue; } int cnt1 = mapp[a]; int cnt2 = mapp[b]; if (cnt1 > cnt2) { ans += cnt1; continue; } if (cnt1 == cnt2) tmp += cnt1; } cout << ans + tmp / 2 << endl; }
a.cc:43:22: warning: overflow in conversion from 'LL' {aka 'long long int'} to 'int' changes value from '10009402209' to '1419467617' [-Woverflow] 43 | const int MAX1 = MAX * (LL)MAX; | ~~~~^~~~~~~~~ a.cc: In function 'const std::vector<_Tp>& get_primes(const T&, T2&)': a.cc:282:30: error: need 'typename' before 'std::vector<_Tp>::const_iterator' because 'std::vector<_Tp>' is a dependent scope 282 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~ a.cc:282:60: error: expected ';' before 'iter' 282 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~ | ; a.cc:283:33: error: 'iter' was not declared in this scope 283 | iter != end; ++iter) | ^~~~ a.cc: In function 'T2 prime_div_trivial(const T&, T2)': a.cc:325:14: error: need 'typename' before 'std::vector<_ValT>::const_iterator' because 'std::vector<_ValT>' is a dependent scope 325 | for (std::vector<T2>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~ a.cc:325:45: error: expected ';' before 'iter' 325 | for (std::vector<T2>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~ | ; a.cc:326:17: error: 'iter' was not declared in this scope 326 | iter != end; ++iter) | ^~~~ a.cc: In function 'T pollard_monte_carlo(T, unsigned int)': a.cc:642:30: error: need 'typename' before 'std::vector<_Tp>::const_iterator' because 'std::vector<_Tp>' is a dependent scope 642 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~ a.cc:642:60: error: expected ';' before 'iter' 642 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~ | ; a.cc:643:33: error: 'iter' was not declared in this scope 643 | iter != end; ++iter) | ^~~~ a.cc: In instantiation of 'T2 prime_div_trivial(const T&, T2) [with T = long long int; T2 = int]': a.cc:713:30: required from 'void factorize(const T&, std::map<T, unsigned int>&, T2) [with T = long long int; T2 = long long int]' 713 | T div = prime_div_trivial(n, 1000); | ~~~~~~~~~~~~~~~~~^~~~~~~~~ a.cc:752:11: required from here 752 | factorize(a, mapp, (long long)0); | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ a.cc:325:31: error: dependent-name 'std::vector<_ValT>::const_iterator' is parsed as a non-type, but instantiation yields a type 325 | for (std::vector<T2>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~~~~~~~~~~ a.cc:325:31: note: say 'typename std::vector<_ValT>::const_iterator' if a type is meant a.cc: In instantiation of 'T pollard_monte_carlo(T, unsigned int) [with T = long long int]': a.cc:722:30: required from 'void factorize(const T&, std::map<T, unsigned int>&, T2) [with T = long long int; T2 = long long int]' 722 | div = pollard_monte_carlo(n); | ~~~~~~~~~~~~~~~~~~~^~~ a.cc:752:11: required from here 752 | factorize(a, mapp, (long long)0); | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ a.cc:642:46: error: dependent-name 'std::vector<_Tp>::const_iterator' is parsed as a non-type, but instantiation yields a type 642 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~~~~~~~~~~ a.cc:642:46: note: say 'typename std::vector<_Tp>::const_iterator' if a type is meant a.cc: In instantiation of 'const std::vector<_Tp>& get_primes(const T&, T2&) [with T = int; T2 = int]': a.cc:322:40: required from 'T2 prime_div_trivial(const T&, T2) [with T = long long int; T2 = int]' 322 | const vector<T2> & primes = get_primes(m, pi); | ~~~~~~~~~~^~~~~~~ a.cc:713:30: required from 'void factorize(const T&, std::map<T, unsigned int>&, T2) [with T = long long int; T2 = long long int]' 713 | T div = prime_div_trivial(n, 1000); | ~~~~~~~~~~~~~~~~~^~~~~~~~~ a.cc:752:11: required from here 752 | factorize(a, mapp, (long long)0); | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ a.cc:282:46: error: dependent-name 'std::vector<_Tp>::const_iterator' is parsed as a non-type, but instantiation yields a type 282 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~~~~~~~~~~ a.cc:282:46: note: say 'typename std::vector<_Tp>::const_iterator' if a type is meant
s268623034
p04022
C++
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <sstream> #include <iomanip> #include <cstdio> #include <cstdlib> #include <cmath> #include <cctype> #include <cstring> #include <vector> #include <list> #include <queue> #include <deque> #include <stack> #include <map> #include <set> #include <algorithm> #include <iterator> #include <bitset> #include <ctime> #include<complex> using namespace std; #define FOR(i,a,b) for (int i = (a); i < (b); i++) #define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--) #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++) #define FILL(a,value) memset(a, value, sizeof(a)) #define SZ(a) (int)a.size() #define ALL(a) a.begin(), a.end() #define PB push_back #define MP make_pair typedef long long LL; typedef vector<int> VI; typedef pair<int, int> PII; const double PI = acos(-1.0); const int INF = 1000 * 1000 * 1000 + 7; const LL LINF = INF * (LL)INF; const int MAX = 1000 * 100 + 47; const int MAX1 = MAX * (LL)MAX; unsigned long long abs(unsigned long long n) { return n; } //! Возвращает true, если n четное template <class T> bool even(const T & n) { // return n % 2 == 0; return (n & 1) == 0; } //! Делит число на 2 template <class T> void bisect(T & n) { // n /= 2; n >>= 1; } //! Умножает число на 2 template <class T> void redouble(T & n) { // n *= 2; n <<= 1; } //! Возвращает true, если n - точный квадрат простого числа template <class T> bool perfect_square(const T & n) { T sq = (T)ceil(sqrt((double)n)); return sq*sq == n; } //! Вычисляет корень из числа, округляя его вниз template <class T> T sq_root(const T & n) { return (T)floor(sqrt((double)n)); } //! Возвращает количество бит в числе (т.е. минимальное количество бит, которыми можно представить данное число) template <class T> unsigned bits_in_number(T n) { if (n == 0) return 1; unsigned result = 0; while (n) { bisect(n); ++result; } return result; } //! Возвращает значение k-го бита числа (биты нумеруются с нуля) template <class T> bool test_bit(const T & n, unsigned k) { return (n & (T(1) << k)) != 0; } //! Умножает a *= b (mod n) template <class T> void mulmod(T & a, T b, const T & n) { // наивная версия, годится только для длинной арифметики a *= b; a %= n; } template <> void mulmod(int & a, int b, const int & n) { a = int((((long long)a) * b) % n); } template <> void mulmod(unsigned & a, unsigned b, const unsigned & n) { a = unsigned((((unsigned long long)a) * b) % n); } template <> void mulmod(unsigned long long & a, unsigned long long b, const unsigned long long & n) { // сложная версия, основанная на бинарном разложении произведения в сумму if (a >= n) a %= n; if (b >= n) b %= n; unsigned long long res = 0; while (b) if (!even(b)) { res += a; while (res >= n) res -= n; --b; } else { redouble(a); while (a >= n) a -= n; bisect(b); } a = res; } template <> void mulmod(long long & a, long long b, const long long & n) { bool neg = false; if (a < 0) { neg = !neg; a = -a; } if (b < 0) { neg = !neg; b = -b; } unsigned long long aa = a; mulmod<unsigned long long>(aa, (unsigned long long)b, (unsigned long long)n); a = (long long)aa * (neg ? -1 : 1); } //! Вычисляет a^k (mod n). Использует бинарное возведение в степень template <class T, class T2> T powmod(T a, T2 k, const T & n) { T res = 1; while (k) if (!even(k)) { mulmod(res, a, n); --k; } else { mulmod(a, a, n); bisect(k); } return res; } //! Переводит число n в форму q*2^p template <class T> void transform_num(T n, T & p, T & q) { T p_res = 0; while (even(n)) { ++p_res; bisect(n); } p = p_res; q = n; } //! Алгоритм Евклида template <class T, class T2> T gcd(const T & a, const T2 & b) { return (a == 0) ? b : gcd(b % a, a); } //! Вычисляет jacobi(a,b) template <class T> T jacobi(T a, T b) { #pragma warning (push) #pragma warning (disable: 4146) if (a == 0) return 0; if (a == 1) return 1; if (a < 0) if ((b & 2) == 0) return jacobi(-a, b); else return -jacobi(-a, b); T e, a1; transform_num(a, e, a1); T s; if (even(e) || (b & 7) == 1 || (b & 7) == 7) s = 1; else s = -1; if ((b & 3) == 3 && (a1 & 3) == 3) s = -s; if (a1 == 1) return s; return s * jacobi(b % a1, a1); #pragma warning (pop) } //! Вычисляет pi(b) первых простых чисел. Возвращает ссылку на вектор с простыми (в векторе может оказаться больше простых, чем надо) и в pi - pi(b) template <class T, class T2> const std::vector<T> & get_primes(const T & b, T2 & pi) { static std::vector<T> primes; static T counted_b; // если результат уже был вычислен ранее, возвращаем его, иначе довычисляем простые if (counted_b >= b) pi = T2(std::upper_bound(primes.begin(), primes.end(), b) - primes.begin()); else { // число 2 обрабатываем отдельно if (counted_b == 0) { primes.push_back(2); counted_b = 2; } // теперь обрабатываем все нечётные, пока не наберём нужное количество простых T first = counted_b == 2 ? 3 : primes.back() + 2; for (T cur = first; cur <= b; ++++cur) { bool cur_is_prime = true; for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); iter != end; ++iter) { const T & div = *iter; if (div * div > cur) break; if (cur % div == 0) { cur_is_prime = false; break; } } if (cur_is_prime) primes.push_back(cur); } counted_b = b; pi = (T2)primes.size(); } return primes; } //! Тривиальная проверка n на простоту, перебираются все делители до m. Результат: 1 - если n точно простое, p - его найденный делитель, 0 - если неизвестно, является ли n простым или нет template <class T, class T2> T2 prime_div_trivial(const T & n, T2 m) { // сначала проверяем тривиальные случаи if (n == 2 || n == 3) return 1; if (n < 2) return 0; if (even(n)) return 2; // генерируем простые от 3 до m T2 pi; const vector<T2> & primes = get_primes(m, pi); // делим на все простые for (std::vector<T2>::const_iterator iter = primes.begin(), end = primes.end(); iter != end; ++iter) { const T2 & div = *iter; if (div * div > n) break; else if (n % div == 0) return div; } if (n < m*m) return 1; return 0; } //! Усиленный алгоритм Миллера-Рабина проверки n на простоту по базису b template <class T, class T2> bool miller_rabin(T n, T2 b) { // сначала проверяем тривиальные случаи if (n == 2) return true; if (n < 2 || even(n)) return false; // проверяем, что n и b взаимно просты (иначе это приведет к ошибке) // если они не взаимно просты, то либо n не просто, либо нужно увеличить b if (b < 2) b = 2; for (T g; (g = gcd(n, b)) != 1; ++b) if (n > g) return false; // разлагаем n-1 = q*2^p T n_1 = n; --n_1; T p, q; transform_num(n_1, p, q); // вычисляем b^q mod n, если оно равно 1 или n-1, то n, вероятно, простое T rem = powmod(T(b), q, n); if (rem == 1 || rem == n_1) return true; // теперь вычисляем b^2q, b^4q, ... , b^((n-1)/2) // если какое-либо из них равно n-1, то n, вероятно, простое for (T i = 1; i<p; i++) { mulmod(rem, rem, n); if (rem == n_1) return true; } return false; } //! Усиленный алгоритм Лукаса-Селфриджа проверки n на простоту. Используется усиленный алгоритм Лукаса с параметрами Селфриджа. Работает только с знаковыми типами!!! Второй параметр unused не используется, он только дает тип template <class T, class T2> bool lucas_selfridge(const T & n, T2 unused) { // сначала проверяем тривиальные случаи if (n == 2) return true; if (n < 2 || even(n)) return false; // проверяем, что n не является точным квадратом, иначе алгоритм даст ошибку if (perfect_square(n)) return false; // алгоритм Селфриджа: находим первое число d такое, что: // jacobi(d,n)=-1 и оно принадлежит ряду { 5,-7,9,-11,13,... } T2 dd; for (T2 d_abs = 5, d_sign = 1; ; d_sign = -d_sign, ++++d_abs) { dd = d_abs * d_sign; T g = gcd(n, d_abs); if (1 < g && g < n) // нашли делитель - d_abs return false; if (jacobi(T(dd), n) == -1) break; } // параметры Селфриджа T2 p = 1, q = (p*p - dd) / 4; // разлагаем n+1 = d*2^s T n_1 = n; ++n_1; T s, d; transform_num(n_1, s, d); // алгоритм Лукаса T u = 1, v = p, u2m = 1, v2m = p, qm = q, qm2 = q * 2, qkd = q; for (unsigned bit = 1, bits = bits_in_number(d); bit < bits; bit++) { mulmod(u2m, v2m, n); mulmod(v2m, v2m, n); while (v2m < qm2) v2m += n; v2m -= qm2; mulmod(qm, qm, n); qm2 = qm; redouble(qm2); if (test_bit(d, bit)) { T t1, t2; t1 = u2m; mulmod(t1, v, n); t2 = v2m; mulmod(t2, u, n); T t3, t4; t3 = v2m; mulmod(t3, v, n); t4 = u2m; mulmod(t4, u, n); mulmod(t4, (T)dd, n); u = t1 + t2; if (!even(u)) u += n; bisect(u); u %= n; v = t3 + t4; if (!even(v)) v += n; bisect(v); v %= n; mulmod(qkd, qm, n); } } // точно простое (или псевдо-простое) if (u == 0 || v == 0) return true; // дополнительные проверки, иначе некоторые составные числа "превратятся" в простые T qkd2 = qkd; redouble(qkd2); for (T2 r = 1; r < s; ++r) { mulmod(v, v, n); v -= qkd2; if (v < 0) v += n; if (v < 0) v += n; if (v >= n) v -= n; if (v >= n) v -= n; if (v == 0) return true; if (r < s - 1) { mulmod(qkd, qkd, n); qkd2 = qkd; redouble(qkd2); } } return false; } //! Алгоритм Бэйли-Померанс-Селфридж-Вагстафф (BPSW) проверки n на простоту template <class T> bool baillie_pomerance_selfridge_wagstaff(T n) { // сначала проверяем на тривиальные делители - до 29 int div = prime_div_trivial(n, 29); if (div == 1) return true; if (div > 1) return false; // если div == 0, то на тривиальные делители n не делится // тест Миллера-Рабина по базису 2 if (!miller_rabin(n, 2)) return false; // усиленный тест Лукаса-Селфриджа return lucas_selfridge(n, 0); } //! Алгоритм Бэйли-Померанс-Селфридж-Вагстафф (BPSW) проверки n на простоту template <class T> bool isprime(T n) { return baillie_pomerance_selfridge_wagstaff(n); } //! Метод Полларда p-1 факторизации числа. Функция возвращает найденный делитель числа или 1, если ничего не найдено template <class T> T pollard_p_1(T n) { // параметры алгоритма, существенно влияют на производительность и качество поиска const T b = 13; const T q[] = { 2, 3, 5, 7, 11, 13 }; // несколько попыток алгоритма T a = 5 % n; for (int j = 0; j<10; j++) { // ищем такое a, которое взаимно просто с n while (gcd(a, n) != 1) { mulmod(a, a, n); a += 3; a %= n; } // вычисляем a^M for (size_t i = 0; i < sizeof q / sizeof q[0]; i++) { T qq = q[i]; T e = (T)floor(log((double)b) / log((double)qq)); T aa = powmod(a, powmod(qq, e, n), n); if (aa == 0) continue; // проверяем, не найден ли ответ T g = gcd(aa - 1, n); if (1 < g && g < n) return g; } } // если ничего не нашли return 1; } //! Метод Полларда RHO факторизации числа. Возвращает его найденный делитель или 1, если ничего не было найдено template <class T> T pollard_rho(T n, unsigned iterations_count = 100000) { T b0 = rand() % n, b1 = b0, g; mulmod(b1, b1, n); if (++b1 == n) b1 = 0; g = gcd(abs(b1 - b0), n); for (unsigned count = 0; count<iterations_count && (g == 1 || g == n); count++) { mulmod(b0, b0, n); if (++b0 == n) b0 = 0; mulmod(b1, b1, n); ++b1; mulmod(b1, b1, n); if (++b1 == n) b1 = 0; g = gcd(abs(b1 - b0), n); } return g; } //! Метод Полларда-Бента факторизации числа. Возвращает его найденный делитель или 1, если ничего не было найдено template <class T> T pollard_bent(T n, unsigned iterations_count = 19) { T b0 = rand() % n, b1 = (b0*b0 + 2) % n, a = b1; for (unsigned iteration = 0, series_len = 1; iteration<iterations_count; iteration++, series_len *= 2) { T g = gcd(b1 - b0, n); for (unsigned len = 0; len<series_len && (g == 1 && g == n); len++) { b1 = (b1*b1 + 2) % n; g = gcd(abs(b1 - b0), n); } b0 = a; a = b1; if (g != 1 && g != n) return g; } return 1; } //! Метод Полларда Monte-Carlo факторизации числа. Возвращает его найденный делитель или 1, если ничего не было найдено template <class T> T pollard_monte_carlo(T n, unsigned m = 100) { T b = rand() % (m - 2) + 2; static std::vector<T> primes; static T m_max; if (primes.empty()) primes.push_back(3); if (m_max < m) { m_max = m; for (T prime = 5; prime <= m; ++++prime) { bool is_prime = true; for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); iter != end; ++iter) { T div = *iter; if (div*div > prime) break; if (prime % div == 0) { is_prime = false; break; } } if (is_prime) primes.push_back(prime); } } T g = 1; for (size_t i = 0; i<primes.size() && g == 1; i++) { T cur = primes[i]; while (cur <= n) cur *= primes[i]; cur /= primes[i]; b = powmod(b, cur, n); g = gcd(abs(b - 1), n); if (g == n) g = 1; } return g; } //! Метод Ферма факторизации числа. Работает в худшем случае за O(sqrt(n)). Возвращает найденный делитель. Второй параметр должен быть того же типа, что и первый, только signed template <class T, class T2> T ferma(const T & n, T2 unused) { T2 x = sq_root(n), y = 0, r = x*x - y*y - n; for (;;) if (r == 0) return x != y ? x - y : x + y; else if (r > 0) { r -= y + y + 1; ++y; } else { r += x + x + 1; ++x; } } //! Рекурсивная факторизация числа. Последний параметр должен быть того же типа, что и первый, только signed. Использует тест BPSW, метод Ферма, метод Полларда RHO, метод Полларда-Бента, метод Полларда Monte-Carlo template <class T, class T2> void factorize(const T & n, std::map<T, unsigned> & result, T2 unused) { if (n == 1) ; else // проверяем, не простое ли число if (isprime(n)) ++result[n]; else // если число достаточно маленькое, то его разлагаем простым перебором if (n < 1000 * 1000) { T div = prime_div_trivial(n, 1000); ++result[div]; factorize(n / div, result, unused); } else { // число большое, запускаем на нем алгоритмы факторизации T div; // сначала идут быстрые алгоритмы Полларда div = pollard_monte_carlo(n); if (div == 1) div = pollard_rho(n); if (div == 1) div = pollard_p_1(n); if (div == 1) div = pollard_bent(n); // если алгоритмы Полларда ничего не дали, то запускаем алгоритм Ферма, который гарантированно находит делитель if (div == 1) div = ferma(n, unused); // рекурсивно обрабатываем найденные множители factorize(div, result, unused); factorize(n / div, result, unused); } } LL A[MAX]; int P[MAX]; LL L[MAX]; int sz; pair<LL, LL> E[MAX]; int esz; map<LL, int> mapp; pair<LL,LL> get(LL a) { LL r1 = 1; LL r2 = 1; map <LL, unsigned> mapp; //cout << a << ":" << endl; factorize(a, mapp, (long long)0); for (map <LL, unsigned>::iterator i = mapp.begin(); i != mapp.end(); ++i) { LL p = i->first; int cnt = i->second % 3; //cout << p << " " << cnt << endl; cnt %= 3; FOR(k, 0, cnt) r1 *= p; cnt = (cnt * 2) % 3; FOR(k, 0, cnt) { if (r2 >= MAX1) continue; r2 *= p; } } return MP(r1, r2); } int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); ios::sync_with_stdio(false); cin.tie(0); FOR(i, 2, MAX) { if (!P[i]) { L[sz++] = i; int j = i; while (j < MAX) { if (P[j] == 0) P[j] = i; j += i; } } } int n; cin >> n; FOR(i, 0, n) { cin >> A[i]; } int ans = 0; FOR(i, 0, n) { E[i] = get(A[i]); mapp[E[i].first]++; //cout << "??" << A[i] << endl; } sort(E, E + n); LL tmp = 0; FOR(i, 0, n) { if (i && E[i] == E[i - 1]) continue; int a = E[i].first; int b = E[i].second; // cout << a << " " << b << " " << mapp[a] << " " << mapp[b] << endl; if (a == 1) { ans++; continue; } int cnt1 = mapp[a]; int cnt2 = mapp[b]; if (cnt1 > cnt2) { ans += cnt1; continue; } if (cnt1 == cnt2) tmp += cnt1; } cout << ans + tmp / 2 << endl; }
a.cc:43:22: warning: overflow in conversion from 'LL' {aka 'long long int'} to 'int' changes value from '10009402209' to '1419467617' [-Woverflow] 43 | const int MAX1 = MAX * (LL)MAX; | ~~~~^~~~~~~~~ a.cc: In function 'const std::vector<_Tp>& get_primes(const T&, T2&)': a.cc:282:30: error: need 'typename' before 'std::vector<_Tp>::const_iterator' because 'std::vector<_Tp>' is a dependent scope 282 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~ a.cc:282:60: error: expected ';' before 'iter' 282 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~ | ; a.cc:283:33: error: 'iter' was not declared in this scope 283 | iter != end; ++iter) | ^~~~ a.cc: In function 'T2 prime_div_trivial(const T&, T2)': a.cc:325:14: error: need 'typename' before 'std::vector<_ValT>::const_iterator' because 'std::vector<_ValT>' is a dependent scope 325 | for (std::vector<T2>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~ a.cc:325:45: error: expected ';' before 'iter' 325 | for (std::vector<T2>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~ | ; a.cc:326:17: error: 'iter' was not declared in this scope 326 | iter != end; ++iter) | ^~~~ a.cc: In function 'T pollard_monte_carlo(T, unsigned int)': a.cc:642:30: error: need 'typename' before 'std::vector<_Tp>::const_iterator' because 'std::vector<_Tp>' is a dependent scope 642 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~ a.cc:642:60: error: expected ';' before 'iter' 642 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~ | ; a.cc:643:33: error: 'iter' was not declared in this scope 643 | iter != end; ++iter) | ^~~~ a.cc: In instantiation of 'T2 prime_div_trivial(const T&, T2) [with T = long long int; T2 = int]': a.cc:713:30: required from 'void factorize(const T&, std::map<T, unsigned int>&, T2) [with T = long long int; T2 = long long int]' 713 | T div = prime_div_trivial(n, 1000); | ~~~~~~~~~~~~~~~~~^~~~~~~~~ a.cc:752:11: required from here 752 | factorize(a, mapp, (long long)0); | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ a.cc:325:31: error: dependent-name 'std::vector<_ValT>::const_iterator' is parsed as a non-type, but instantiation yields a type 325 | for (std::vector<T2>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~~~~~~~~~~ a.cc:325:31: note: say 'typename std::vector<_ValT>::const_iterator' if a type is meant a.cc: In instantiation of 'T pollard_monte_carlo(T, unsigned int) [with T = long long int]': a.cc:722:30: required from 'void factorize(const T&, std::map<T, unsigned int>&, T2) [with T = long long int; T2 = long long int]' 722 | div = pollard_monte_carlo(n); | ~~~~~~~~~~~~~~~~~~~^~~ a.cc:752:11: required from here 752 | factorize(a, mapp, (long long)0); | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ a.cc:642:46: error: dependent-name 'std::vector<_Tp>::const_iterator' is parsed as a non-type, but instantiation yields a type 642 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~~~~~~~~~~ a.cc:642:46: note: say 'typename std::vector<_Tp>::const_iterator' if a type is meant a.cc: In instantiation of 'const std::vector<_Tp>& get_primes(const T&, T2&) [with T = int; T2 = int]': a.cc:322:40: required from 'T2 prime_div_trivial(const T&, T2) [with T = long long int; T2 = int]' 322 | const vector<T2> & primes = get_primes(m, pi); | ~~~~~~~~~~^~~~~~~ a.cc:713:30: required from 'void factorize(const T&, std::map<T, unsigned int>&, T2) [with T = long long int; T2 = long long int]' 713 | T div = prime_div_trivial(n, 1000); | ~~~~~~~~~~~~~~~~~^~~~~~~~~ a.cc:752:11: required from here 752 | factorize(a, mapp, (long long)0); | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ a.cc:282:46: error: dependent-name 'std::vector<_Tp>::const_iterator' is parsed as a non-type, but instantiation yields a type 282 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~~~~~~~~~~ a.cc:282:46: note: say 'typename std::vector<_Tp>::const_iterator' if a type is meant
s374069309
p04022
C++
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <sstream> #include <iomanip> #include <cstdio> #include <cstdlib> #include <cmath> #include <cctype> #include <cstring> #include <vector> #include <list> #include <queue> #include <deque> #include <stack> #include <map> #include <set> #include <algorithm> #include <iterator> #include <bitset> #include <ctime> #include<complex> using namespace std; #define FOR(i,a,b) for (int i = (a); i < (b); i++) #define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--) #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++) #define FILL(a,value) memset(a, value, sizeof(a)) #define SZ(a) (int)a.size() #define ALL(a) a.begin(), a.end() #define PB push_back #define MP make_pair typedef long long LL; typedef vector<int> VI; typedef pair<int, int> PII; const double PI = acos(-1.0); const int INF = 1000 * 1000 * 1000 + 7; const LL LINF = INF * (LL)INF; const int MAX = 1000 * 100 + 47; const int MAX1 = MAX * (LL)MAX; unsigned long long abs(unsigned long long n) { return n; } //! Возвращает true, если n четное template <class T> bool even(const T & n) { // return n % 2 == 0; return (n & 1) == 0; } //! Делит число на 2 template <class T> void bisect(T & n) { // n /= 2; n >>= 1; } //! Умножает число на 2 template <class T> void redouble(T & n) { // n *= 2; n <<= 1; } //! Возвращает true, если n - точный квадрат простого числа template <class T> bool perfect_square(const T & n) { T sq = (T)ceil(sqrt((double)n)); return sq*sq == n; } //! Вычисляет корень из числа, округляя его вниз template <class T> T sq_root(const T & n) { return (T)floor(sqrt((double)n)); } //! Возвращает количество бит в числе (т.е. минимальное количество бит, которыми можно представить данное число) template <class T> unsigned bits_in_number(T n) { if (n == 0) return 1; unsigned result = 0; while (n) { bisect(n); ++result; } return result; } //! Возвращает значение k-го бита числа (биты нумеруются с нуля) template <class T> bool test_bit(const T & n, unsigned k) { return (n & (T(1) << k)) != 0; } //! Умножает a *= b (mod n) template <class T> void mulmod(T & a, T b, const T & n) { // наивная версия, годится только для длинной арифметики a *= b; a %= n; } template <> void mulmod(int & a, int b, const int & n) { a = int((((long long)a) * b) % n); } template <> void mulmod(unsigned & a, unsigned b, const unsigned & n) { a = unsigned((((unsigned long long)a) * b) % n); } template <> void mulmod(unsigned long long & a, unsigned long long b, const unsigned long long & n) { // сложная версия, основанная на бинарном разложении произведения в сумму if (a >= n) a %= n; if (b >= n) b %= n; unsigned long long res = 0; while (b) if (!even(b)) { res += a; while (res >= n) res -= n; --b; } else { redouble(a); while (a >= n) a -= n; bisect(b); } a = res; } template <> void mulmod(long long & a, long long b, const long long & n) { bool neg = false; if (a < 0) { neg = !neg; a = -a; } if (b < 0) { neg = !neg; b = -b; } unsigned long long aa = a; mulmod<unsigned long long>(aa, (unsigned long long)b, (unsigned long long)n); a = (long long)aa * (neg ? -1 : 1); } //! Вычисляет a^k (mod n). Использует бинарное возведение в степень template <class T, class T2> T powmod(T a, T2 k, const T & n) { T res = 1; while (k) if (!even(k)) { mulmod(res, a, n); --k; } else { mulmod(a, a, n); bisect(k); } return res; } //! Переводит число n в форму q*2^p template <class T> void transform_num(T n, T & p, T & q) { T p_res = 0; while (even(n)) { ++p_res; bisect(n); } p = p_res; q = n; } //! Алгоритм Евклида template <class T, class T2> T gcd(const T & a, const T2 & b) { return (a == 0) ? b : gcd(b % a, a); } //! Вычисляет jacobi(a,b) template <class T> T jacobi(T a, T b) { #pragma warning (push) #pragma warning (disable: 4146) if (a == 0) return 0; if (a == 1) return 1; if (a < 0) if ((b & 2) == 0) return jacobi(-a, b); else return -jacobi(-a, b); T e, a1; transform_num(a, e, a1); T s; if (even(e) || (b & 7) == 1 || (b & 7) == 7) s = 1; else s = -1; if ((b & 3) == 3 && (a1 & 3) == 3) s = -s; if (a1 == 1) return s; return s * jacobi(b % a1, a1); #pragma warning (pop) } //! Вычисляет pi(b) первых простых чисел. Возвращает ссылку на вектор с простыми (в векторе может оказаться больше простых, чем надо) и в pi - pi(b) template <class T, class T2> const std::vector<T> & get_primes(const T & b, T2 & pi) { static std::vector<T> primes; static T counted_b; // если результат уже был вычислен ранее, возвращаем его, иначе довычисляем простые if (counted_b >= b) pi = T2(std::upper_bound(primes.begin(), primes.end(), b) - primes.begin()); else { // число 2 обрабатываем отдельно if (counted_b == 0) { primes.push_back(2); counted_b = 2; } // теперь обрабатываем все нечётные, пока не наберём нужное количество простых T first = counted_b == 2 ? 3 : primes.back() + 2; for (T cur = first; cur <= b; ++++cur) { bool cur_is_prime = true; for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); iter != end; ++iter) { const T & div = *iter; if (div * div > cur) break; if (cur % div == 0) { cur_is_prime = false; break; } } if (cur_is_prime) primes.push_back(cur); } counted_b = b; pi = (T2)primes.size(); } return primes; } //! Тривиальная проверка n на простоту, перебираются все делители до m. Результат: 1 - если n точно простое, p - его найденный делитель, 0 - если неизвестно, является ли n простым или нет template <class T, class T2> T2 prime_div_trivial(const T & n, T2 m) { // сначала проверяем тривиальные случаи if (n == 2 || n == 3) return 1; if (n < 2) return 0; if (even(n)) return 2; // генерируем простые от 3 до m T2 pi; const vector<T2> & primes = get_primes(m, pi); // делим на все простые for (std::vector<T2>::const_iterator iter = primes.begin(), end = primes.end(); iter != end; ++iter) { const T2 & div = *iter; if (div * div > n) break; else if (n % div == 0) return div; } if (n < m*m) return 1; return 0; } //! Усиленный алгоритм Миллера-Рабина проверки n на простоту по базису b template <class T, class T2> bool miller_rabin(T n, T2 b) { // сначала проверяем тривиальные случаи if (n == 2) return true; if (n < 2 || even(n)) return false; // проверяем, что n и b взаимно просты (иначе это приведет к ошибке) // если они не взаимно просты, то либо n не просто, либо нужно увеличить b if (b < 2) b = 2; for (T g; (g = gcd(n, b)) != 1; ++b) if (n > g) return false; // разлагаем n-1 = q*2^p T n_1 = n; --n_1; T p, q; transform_num(n_1, p, q); // вычисляем b^q mod n, если оно равно 1 или n-1, то n, вероятно, простое T rem = powmod(T(b), q, n); if (rem == 1 || rem == n_1) return true; // теперь вычисляем b^2q, b^4q, ... , b^((n-1)/2) // если какое-либо из них равно n-1, то n, вероятно, простое for (T i = 1; i<p; i++) { mulmod(rem, rem, n); if (rem == n_1) return true; } return false; } //! Усиленный алгоритм Лукаса-Селфриджа проверки n на простоту. Используется усиленный алгоритм Лукаса с параметрами Селфриджа. Работает только с знаковыми типами!!! Второй параметр unused не используется, он только дает тип template <class T, class T2> bool lucas_selfridge(const T & n, T2 unused) { // сначала проверяем тривиальные случаи if (n == 2) return true; if (n < 2 || even(n)) return false; // проверяем, что n не является точным квадратом, иначе алгоритм даст ошибку if (perfect_square(n)) return false; // алгоритм Селфриджа: находим первое число d такое, что: // jacobi(d,n)=-1 и оно принадлежит ряду { 5,-7,9,-11,13,... } T2 dd; for (T2 d_abs = 5, d_sign = 1; ; d_sign = -d_sign, ++++d_abs) { dd = d_abs * d_sign; T g = gcd(n, d_abs); if (1 < g && g < n) // нашли делитель - d_abs return false; if (jacobi(T(dd), n) == -1) break; } // параметры Селфриджа T2 p = 1, q = (p*p - dd) / 4; // разлагаем n+1 = d*2^s T n_1 = n; ++n_1; T s, d; transform_num(n_1, s, d); // алгоритм Лукаса T u = 1, v = p, u2m = 1, v2m = p, qm = q, qm2 = q * 2, qkd = q; for (unsigned bit = 1, bits = bits_in_number(d); bit < bits; bit++) { mulmod(u2m, v2m, n); mulmod(v2m, v2m, n); while (v2m < qm2) v2m += n; v2m -= qm2; mulmod(qm, qm, n); qm2 = qm; redouble(qm2); if (test_bit(d, bit)) { T t1, t2; t1 = u2m; mulmod(t1, v, n); t2 = v2m; mulmod(t2, u, n); T t3, t4; t3 = v2m; mulmod(t3, v, n); t4 = u2m; mulmod(t4, u, n); mulmod(t4, (T)dd, n); u = t1 + t2; if (!even(u)) u += n; bisect(u); u %= n; v = t3 + t4; if (!even(v)) v += n; bisect(v); v %= n; mulmod(qkd, qm, n); } } // точно простое (или псевдо-простое) if (u == 0 || v == 0) return true; // дополнительные проверки, иначе некоторые составные числа "превратятся" в простые T qkd2 = qkd; redouble(qkd2); for (T2 r = 1; r < s; ++r) { mulmod(v, v, n); v -= qkd2; if (v < 0) v += n; if (v < 0) v += n; if (v >= n) v -= n; if (v >= n) v -= n; if (v == 0) return true; if (r < s - 1) { mulmod(qkd, qkd, n); qkd2 = qkd; redouble(qkd2); } } return false; } //! Алгоритм Бэйли-Померанс-Селфридж-Вагстафф (BPSW) проверки n на простоту template <class T> bool baillie_pomerance_selfridge_wagstaff(T n) { // сначала проверяем на тривиальные делители - до 29 int div = prime_div_trivial(n, 29); if (div == 1) return true; if (div > 1) return false; // если div == 0, то на тривиальные делители n не делится // тест Миллера-Рабина по базису 2 if (!miller_rabin(n, 2)) return false; // усиленный тест Лукаса-Селфриджа return lucas_selfridge(n, 0); } //! Алгоритм Бэйли-Померанс-Селфридж-Вагстафф (BPSW) проверки n на простоту template <class T> bool isprime(T n) { return baillie_pomerance_selfridge_wagstaff(n); } //! Метод Полларда p-1 факторизации числа. Функция возвращает найденный делитель числа или 1, если ничего не найдено template <class T> T pollard_p_1(T n) { // параметры алгоритма, существенно влияют на производительность и качество поиска const T b = 13; const T q[] = { 2, 3, 5, 7, 11, 13 }; // несколько попыток алгоритма T a = 5 % n; for (int j = 0; j<10; j++) { // ищем такое a, которое взаимно просто с n while (gcd(a, n) != 1) { mulmod(a, a, n); a += 3; a %= n; } // вычисляем a^M for (size_t i = 0; i < sizeof q / sizeof q[0]; i++) { T qq = q[i]; T e = (T)floor(log((double)b) / log((double)qq)); T aa = powmod(a, powmod(qq, e, n), n); if (aa == 0) continue; // проверяем, не найден ли ответ T g = gcd(aa - 1, n); if (1 < g && g < n) return g; } } // если ничего не нашли return 1; } //! Метод Полларда RHO факторизации числа. Возвращает его найденный делитель или 1, если ничего не было найдено template <class T> T pollard_rho(T n, unsigned iterations_count = 100000) { T b0 = rand() % n, b1 = b0, g; mulmod(b1, b1, n); if (++b1 == n) b1 = 0; g = gcd(abs(b1 - b0), n); for (unsigned count = 0; count<iterations_count && (g == 1 || g == n); count++) { mulmod(b0, b0, n); if (++b0 == n) b0 = 0; mulmod(b1, b1, n); ++b1; mulmod(b1, b1, n); if (++b1 == n) b1 = 0; g = gcd(abs(b1 - b0), n); } return g; } //! Метод Полларда-Бента факторизации числа. Возвращает его найденный делитель или 1, если ничего не было найдено template <class T> T pollard_bent(T n, unsigned iterations_count = 19) { T b0 = rand() % n, b1 = (b0*b0 + 2) % n, a = b1; for (unsigned iteration = 0, series_len = 1; iteration<iterations_count; iteration++, series_len *= 2) { T g = gcd(b1 - b0, n); for (unsigned len = 0; len<series_len && (g == 1 && g == n); len++) { b1 = (b1*b1 + 2) % n; g = gcd(abs(b1 - b0), n); } b0 = a; a = b1; if (g != 1 && g != n) return g; } return 1; } //! Метод Полларда Monte-Carlo факторизации числа. Возвращает его найденный делитель или 1, если ничего не было найдено template <class T> T pollard_monte_carlo(T n, unsigned m = 100) { T b = rand() % (m - 2) + 2; static std::vector<T> primes; static T m_max; if (primes.empty()) primes.push_back(3); if (m_max < m) { m_max = m; for (T prime = 5; prime <= m; ++++prime) { bool is_prime = true; for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); iter != end; ++iter) { T div = *iter; if (div*div > prime) break; if (prime % div == 0) { is_prime = false; break; } } if (is_prime) primes.push_back(prime); } } T g = 1; for (size_t i = 0; i<primes.size() && g == 1; i++) { T cur = primes[i]; while (cur <= n) cur *= primes[i]; cur /= primes[i]; b = powmod(b, cur, n); g = gcd(abs(b - 1), n); if (g == n) g = 1; } return g; } //! Метод Ферма факторизации числа. Работает в худшем случае за O(sqrt(n)). Возвращает найденный делитель. Второй параметр должен быть того же типа, что и первый, только signed template <class T, class T2> T ferma(const T & n, T2 unused) { T2 x = sq_root(n), y = 0, r = x*x - y*y - n; for (;;) if (r == 0) return x != y ? x - y : x + y; else if (r > 0) { r -= y + y + 1; ++y; } else { r += x + x + 1; ++x; } } //! Рекурсивная факторизация числа. Последний параметр должен быть того же типа, что и первый, только signed. Использует тест BPSW, метод Ферма, метод Полларда RHO, метод Полларда-Бента, метод Полларда Monte-Carlo template <class T, class T2> void factorize(const T & n, std::map<T, unsigned> & result, T2 unused) { if (n == 1) ; else // проверяем, не простое ли число if (isprime(n)) ++result[n]; else // если число достаточно маленькое, то его разлагаем простым перебором if (n < 1000 * 1000) { T div = prime_div_trivial(n, 1000); ++result[div]; factorize(n / div, result, unused); } else { // число большое, запускаем на нем алгоритмы факторизации T div; // сначала идут быстрые алгоритмы Полларда div = pollard_monte_carlo(n); if (div == 1) div = pollard_rho(n); if (div == 1) div = pollard_p_1(n); if (div == 1) div = pollard_bent(n); // если алгоритмы Полларда ничего не дали, то запускаем алгоритм Ферма, который гарантированно находит делитель if (div == 1) div = ferma(n, unused); // рекурсивно обрабатываем найденные множители factorize(div, result, unused); factorize(n / div, result, unused); } } LL A[MAX]; int P[MAX]; LL L[MAX]; int sz; pair<LL, LL> E[MAX]; int esz; map<LL, int> mapp; pair<LL,LL> get(LL a) { LL r1 = 1; LL r2 = 1; typedef long long base; base n; cin >> n; map <base, unsigned> mapp; //cout << a << ":" << endl; factorize(a, mapp, (long long)0); for (map <base, unsigned>::iterator i = mapp.begin(); i != mapp.end(); ++i) { LL p = i->first; int cnt = i->second % 3; //cout << p << " " << cnt << endl; cnt %= 3; FOR(k, 0, cnt) r1 *= p; cnt = (cnt * 2) % 3; FOR(k, 0, cnt) { if (r2 >= MAX1) continue; r2 *= p; } } return MP(r1, r2); } int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); ios::sync_with_stdio(false); cin.tie(0); FOR(i, 2, MAX) { if (!P[i]) { L[sz++] = i; int j = i; while (j < MAX) { if (P[j] == 0) P[j] = i; j += i; } } } int n; cin >> n; FOR(i, 0, n) { cin >> A[i]; } int ans = 0; FOR(i, 0, n) { E[i] = get(A[i]); mapp[E[i].first]++; //cout << "??" << A[i] << endl; } sort(E, E + n); LL tmp = 0; FOR(i, 0, n) { if (i && E[i] == E[i - 1]) continue; int a = E[i].first; int b = E[i].second; // cout << a << " " << b << " " << mapp[a] << " " << mapp[b] << endl; if (a == 1) { ans++; continue; } int cnt1 = mapp[a]; int cnt2 = mapp[b]; if (cnt1 > cnt2) { ans += cnt1; continue; } if (cnt1 == cnt2) tmp += cnt1; } cout << ans + tmp / 2 << endl; }
a.cc:43:22: warning: overflow in conversion from 'LL' {aka 'long long int'} to 'int' changes value from '10009402209' to '1419467617' [-Woverflow] 43 | const int MAX1 = MAX * (LL)MAX; | ~~~~^~~~~~~~~ a.cc: In function 'const std::vector<_Tp>& get_primes(const T&, T2&)': a.cc:282:30: error: need 'typename' before 'std::vector<_Tp>::const_iterator' because 'std::vector<_Tp>' is a dependent scope 282 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~ a.cc:282:60: error: expected ';' before 'iter' 282 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~ | ; a.cc:283:33: error: 'iter' was not declared in this scope 283 | iter != end; ++iter) | ^~~~ a.cc: In function 'T2 prime_div_trivial(const T&, T2)': a.cc:325:14: error: need 'typename' before 'std::vector<_ValT>::const_iterator' because 'std::vector<_ValT>' is a dependent scope 325 | for (std::vector<T2>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~ a.cc:325:45: error: expected ';' before 'iter' 325 | for (std::vector<T2>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~ | ; a.cc:326:17: error: 'iter' was not declared in this scope 326 | iter != end; ++iter) | ^~~~ a.cc: In function 'T pollard_monte_carlo(T, unsigned int)': a.cc:642:30: error: need 'typename' before 'std::vector<_Tp>::const_iterator' because 'std::vector<_Tp>' is a dependent scope 642 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~ a.cc:642:60: error: expected ';' before 'iter' 642 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~ | ; a.cc:643:33: error: 'iter' was not declared in this scope 643 | iter != end; ++iter) | ^~~~ a.cc: In instantiation of 'T2 prime_div_trivial(const T&, T2) [with T = long long int; T2 = int]': a.cc:713:30: required from 'void factorize(const T&, std::map<T, unsigned int>&, T2) [with T = long long int; T2 = long long int]' 713 | T div = prime_div_trivial(n, 1000); | ~~~~~~~~~~~~~~~~~^~~~~~~~~ a.cc:757:11: required from here 757 | factorize(a, mapp, (long long)0); | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ a.cc:325:31: error: dependent-name 'std::vector<_ValT>::const_iterator' is parsed as a non-type, but instantiation yields a type 325 | for (std::vector<T2>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~~~~~~~~~~ a.cc:325:31: note: say 'typename std::vector<_ValT>::const_iterator' if a type is meant a.cc: In instantiation of 'T pollard_monte_carlo(T, unsigned int) [with T = long long int]': a.cc:722:30: required from 'void factorize(const T&, std::map<T, unsigned int>&, T2) [with T = long long int; T2 = long long int]' 722 | div = pollard_monte_carlo(n); | ~~~~~~~~~~~~~~~~~~~^~~ a.cc:757:11: required from here 757 | factorize(a, mapp, (long long)0); | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ a.cc:642:46: error: dependent-name 'std::vector<_Tp>::const_iterator' is parsed as a non-type, but instantiation yields a type 642 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~~~~~~~~~~ a.cc:642:46: note: say 'typename std::vector<_Tp>::const_iterator' if a type is meant a.cc: In instantiation of 'const std::vector<_Tp>& get_primes(const T&, T2&) [with T = int; T2 = int]': a.cc:322:40: required from 'T2 prime_div_trivial(const T&, T2) [with T = long long int; T2 = int]' 322 | const vector<T2> & primes = get_primes(m, pi); | ~~~~~~~~~~^~~~~~~ a.cc:713:30: required from 'void factorize(const T&, std::map<T, unsigned int>&, T2) [with T = long long int; T2 = long long int]' 713 | T div = prime_div_trivial(n, 1000); | ~~~~~~~~~~~~~~~~~^~~~~~~~~ a.cc:757:11: required from here 757 | factorize(a, mapp, (long long)0); | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ a.cc:282:46: error: dependent-name 'std::vector<_Tp>::const_iterator' is parsed as a non-type, but instantiation yields a type 282 | for (std::vector<T>::const_iterator iter = primes.begin(), end = primes.end(); | ^~~~~~~~~~~~~~ a.cc:282:46: note: say 'typename std::vector<_Tp>::const_iterator' if a type is meant
s534921281
p04022
C++
#include <stdio.h> #include <iostream> #include <algorithm> #include <memory.h> #include <vector> using namespace std; typedef long long LL; const int maxn = 100005; LL a[maxn],t[maxn];int n,cnt,m,ans; int prm[maxn],tot,is[maxn],ord[maxn]; void predo(int n) { for (int i=2;i<=n;i++) { if (!is[i]) prm[++tot]=i; for (int j=1;j<=tot;j++) { int num=prm[j]*i; if (num>n) break; if (i%prm[j]) is[num]=1; else {is[num]=1;break;} } } } void solve(LL n) { LL u=1ll,v=1ll; for (int i=1;i<=tot;i++) if (n%prm[i]==0) { int cnt=0,x=prm[i]; while (n%x==0) n/=x,++cnt; cnt%=3; if (cnt==1) u*=x,v*=x*x; if (cnt==2) u*=x*x,v*=x; } LL n_=sqrt(n); if (n_*n_==n) u*=n,v*=n_; else if (n>(int)1e5) {ans++;return ;} else {u*=n;v*=n*n;} if (u==1) ++cnt; else {t[++m]=min(u,v);a[m]=v;} } bool comp(int x,int y) {return t[x]<t[y];} int main() { #ifdef Amberframe freopen("agc003d.in","r",stdin); freopen("agc003d.out","w",stdout); #endif scanf("%d",&n);predo((int)2200); for (int i=1;i<=n;i++) scanf("%lld",&a[i]); for (int i=1;i<=n;i++) solve(a[i]); for (int i=1;i<=m;i++) ord[i]=i; sort(ord+1,ord+m+1,comp); for (int i=1;i<=m;) { int pos=i,c1=0,c2=0; while (pos<=n&&t[ord[pos]]==t[ord[i]]) { a[ord[pos]]==a[ord[i]]?c1++:c2++;++pos; } ans+=max(c1,c2);i=pos; } printf("%d",ans+(cnt?1:0)); return 0; }
a.cc: In function 'void solve(LL)': a.cc:38:15: error: 'sqrt' was not declared in this scope 38 | LL n_=sqrt(n); | ^~~~
s199157557
p04022
C++
#include <iostream> #include <vector> #include <map> #include <bitset> #include <cmath> using namespace std; const int kMax = 2200; const int kMaxPr = 500; bitset < kMax > used; void Init(vector < int > &prime) { int index = 0; for (int pr = 2; pr < kMax; pr ++) { if (used[pr]) { continue; } prime[++ index] = pr; for (int j = pr * 2; j < kMax; j += pr) { used[j] = true; } } prime[0] = index; } int main(int argc, char const *argv[]) { vector < int > prime(kMaxPr); Init(prime); int n; cin >> n; map < long long, long long > hash; map < long long, long long > comp; vector < long long > element(n + 1); for (int i = 1; i <= n; i ++) { cin >> element[i]; long long k = element[i]; hash[k] = 1ll; comp[k] = 1ll; if (k == 1ll) { continue; } for (int j = 1; j <= prime[0] and k != 1 and prime[j] <= k; j ++) { if (k % prime[j] != 0) { continue; } int elExp = 0; while (k % prime[j] == 0) { elExp ++; k /= prime[j]; } elExp %= 3; if (elExp == 0) { continue; } if (elExp == 1) { hash[element[i]] *= 1ll * prime[j]; comp[element[i]] *= 1ll * prime[j] * prime[j]; } else { hash[element[i]] *= 1ll * prime[j] * prime[j]; comp[element[i]] *= 1ll * prime[j]; } } if (k != 1) { hash[element[i]] *= 1ll * k * k; comp[element[i]] *= 1ll * k; } map < long long, int > frecv; for (int i = 1; i <= n; i ++) { frecv[hash[element[i]]] ++; } int to_remove = 0; for (auto x : frecv) { if (x.second == 0) { continue; } if (x.first == 1) { to_remove += x.second - 1; x.second = 0; continue; } int k = x.first; int c = frecv[comp[k]]; if (c == 0) { continue; } if (x.second >= c) { to_remove += c; } else { to_remove += x.second; } frecv[comp[k]] = 0; } cout << n - to_remove << '\n'; }
a.cc: In function 'int main(int, const char**)': a.cc:118:2: error: expected '}' at end of input 118 | } | ^ a.cc:31:40: note: to match this '{' 31 | int main(int argc, char const *argv[]) { | ^
s180064377
p04022
C++
10 1 10 100 1000000007 10000000000 1000000009 999999999 999 999 999
a.cc:1:1: error: expected unqualified-id before numeric constant 1 | 10 | ^~
s583045985
p04022
C++
#include <bits/stdc++.h> #define FI(i,a,b) for(int i=(a);i<=(b);i++) #define FD(i,a,b) for(int i=(a);i>=(b);i--) #define LL long long #define Ldouble long double #define PI 3.14159265358979323846264338327950288419 #define PII pair<int,int> #define PLL pair<LL,LL> #define mp make_pair #define fi first #define se second #define LIM 10000000001LL using namespace std; int n, pr[2005], p, ans; LL s[100005], pal[100005]; map<LL, int> M, M_pal; bool isp(int x){ FI(i, 1, p) if(x % pr[i] == 0) return false; return true; } int main(){ FI(i, 2, 2200) if(isp(i)) pr[++p] = i; scanf("%d", &n); FI(i, 1, n){ scanf("%lld", &s[i]); FI(j, 1, p){ LL u = 1LL * pr[j] * pr[j] * pr[j]; while(s[i] % u == 0) s[i] /= u; } //Now s[i] is p^3-free LL tmp = s[i]; pal[i] = 1; FI(j, 1, p){ if(tmp % pr[j] == 0){ LL u = 1LL * pr[j] * pr[j] * pr[j]; while(tmp % pr[j] == 0){ tmp /= pr[j]; u /= pr[j]; } if(pal[i] <= LIM / u + 1) pal[i] *= u; else pal[i] = LIM; } } if(tmp > 1){ LL rt = sqrt(tmp); if(rt * rt == tmp && pal[i] <= LIM / rt + 1) pal[i] *= rt; else if(pal[i] <= LIM / tmp / tmp + 1) pal[i] *= tmp * tmp; else pal[i] = LIM; } } FI(i, 1, n){ M[s[i]]++; if(!M.count(s[i])) M_pal[s[i]] = pal[i]; else M[s[i]]++; } for(auto pi: M){ LL u = pi.fi, cnt = pi.se; LL pa = M_pal[u]; if(pa == INF) assert(!M.count(pa)); if(pa == u) ans++; //only if u == 1 else if(!M.count(pa)) ans += cnt; else if(u > pa) ans += max(cnt, (LL)M[pa]); } printf("%d\n", ans); return 0; }
a.cc: In function 'int main()': a.cc:69:26: error: 'INF' was not declared in this scope 69 | if(pa == INF) assert(!M.count(pa)); | ^~~
s003921556
p04022
C++
#include<iostream> #include<vector> #include<algorithm> using namespace std; long long n, s[100000], t[100000], K, ret, inf = (1LL << 40), num[2]; vector<pair<long long, int>>vec; bool used[100000]; long long solve(long long I) { long long ret = 1; for (long long i = 2; i <= 2500; i++) { long long U = 0; while (I%i == 0) { I /= i; U++; U %= 3; } for (int j = 0; j < (3 - U % 3) % 3; j++) { if (ret*i <= inf)ret *= i; else ret = inf; } } long long G = sqrtl(1.0L*I); if (G*G == I) { ret *= G; } else { if ((inf / I) <= ret)ret *= I; else ret = inf; } return min(ret, inf); } void dfs(int pos, int depth) { if (used[pos] == true)return; num[depth]++; used[pos] = true; for (int i = 1; i <= 2000; i++) { long long P = 1LL * i*i*i*t[pos]; int pos1 = lower_bound(vec.begin(), vec.end(), make_pair(P, 0)) - vec.begin(); if (pos1 >= vec.size() || vec[pos1].first != P)continue; while (pos1 < vec.size() && vec[pos1].first == P) { dfs(vec[pos1].second, depth ^ 1); pos1++; } } } int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> s[i]; t[i] = solve(s[i]); if (t[i] != 1)vec.push_back(make_pair(s[i], i)); else K = 1; } sort(vec.begin(), vec.end()); for (int i = 0; i < n; i++) { if (t[i] == 1 || used[i] == true)continue; num[0] = 0; num[1] = 0; dfs(i, 0); ret += max(num[0], num[1]); } cout << ret + K << endl; return 0; }
a.cc: In function 'long long int solve(long long int)': a.cc:15:23: error: 'sqrtl' was not declared in this scope; did you mean 'strtol'? 15 | long long G = sqrtl(1.0L*I); if (G*G == I) { ret *= G; } | ^~~~~ | strtol
s757851961
p04022
C++
#include<iostream> #include<vector> #include<map> #include<algorithm> using namespace std; long long n, s[100000], t[100000], col[100000], cnt, num[100000]; vector<pair<long long, int>>F; map<long long, bool>M; void dfs(int pos, int depth) { if (col[pos] != -1)return; col[pos] = depth; num[depth]++; if (t[pos] == -1)return; for (long long i = 1; i <= 3000; i++) { long long I = 1LL * i*i*i*t[pos]; if (I > 1e10 || M[I] == true)break; int pos1 = lower_bound(F.begin(), F.end(), make_pair(I, 0)) - F.begin(); int pos2 = lower_bound(F.begin(), F.end(), make_pair(I + 1, 0)) - F.begin(); for (int j = pos1; j < pos2; j++) { dfs(F[j].second, cnt * 2 + ((col[pos] - cnt * 2) ^ 1)); } M[pos] = true; } } int main() { cin >> n; for (int i = 0; i < n; i++)t[i] = 1; for (int i = 0; i < n; i++) { cin >> s[i]; F.push_back(make_pair(s[i], i)); vector<long long>E; long long I = s[i]; for (int j = 2; j <= 3000; j++) { while (I%j == 0) { E.push_back(j); I /= j; } } if (I >= 2) { long long H = sqrtl(1.0L*I); if (H*H == I) { E.push_back(H); E.push_back(H); } else { E.push_back(I); } } if (s[i] == 1) { E.clear(); E.push_back(1); } sort(E.begin(), E.end()); map<long long, int>M; for (int j = 0; j < E.size(); j++)M[E[j]]++; for (int j = 0; j < E.size(); j++) { if ((j == 0 || (E[j - 1] != E[j])) && t[i] != -1) { long long F = M[E[j]]; if (F % 3 == 2) { if ((1LL << 35) / t[i] >= E[j])t[i] *= E[j]; else t[i] = -1; } if (F % 3 == 1) { if (((1LL << 35) / E[j]) / E[j] >= t[i])t[i] *= E[j] * E[j]; else t[i] = -1; } } } } for (int i = 0; i < n; i++)col[i] = -1; sort(F.begin(), F.end()); int ret = 0, K = 0; for (int i = 0; i < n; i++) { if (t[i] == 1) { K = 1; continue; } if (col[i] >= 0)continue; dfs(i, cnt * 2 + 1); ret += max(num[cnt * 2], num[cnt * 2 + 1]); cnt++; } ret += K; cout << ret << endl; return 0; }
a.cc: In function 'int main()': a.cc:32:39: error: 'sqrtl' was not declared in this scope; did you mean 'strtol'? 32 | long long H = sqrtl(1.0L*I); | ^~~~~ | strtol
s338243926
p04022
C++
#include <cstdio> #include <cstring> #include <cassert> #include <iostream> #include <algorithm> #include <vector> #include <set> #include <map> #define a first #define b second #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR (i, 0, n) #define _ << " _ " << #define TRACE(x) cerr << #x << " = " << x << endl #define debug(...) fprintf(stderr, __VA_ARGS__) #define debug #define TRACE(x) using namespace std; using llint = long long; using pii = pair<llint, llint>; const int MAXN = 100010; const int MAXP = 2200; bool isprime(int n) { for (int x = 2; x < n; ++x) if (n % x == 0) return false; return true; } vector<int> p; vector<int> pp[3]; map<llint, int> tot; pii get_class(llint x) { llint ret1 = 1, ret2 = 1; REP(i, (int)p.size()) { int cnt = 0; while (x % p[i] == 0) { x /= p[i]; ++cnt; } cnt %= 3; ret1 *= pp[cnt][i]; ret2 *= pp[(3 - cnt) % 3][i]; } if (x > 1) { llint root = sqrt(x); if (root * root == x) { ret1 *= root * root; ret2 *= root; } else { ret1 *= x; ret2 *= x * x; } } return {ret1, ret2}; } int n, sol; llint a[MAXN]; pii s[MAXN]; int main(void) { scanf("%d",&n); REP(i, n) scanf("%lld",&a[i]); FOR(pr, 2, MAXP) if (isprime(pr)) { p.push_back(pr); pp[0].push_back(1); pp[1].push_back(pr); pp[2].push_back(pr*pr); } TRACE((int)p.size()); REP(i, n) { auto c = get_class(a[i]); s[i] = c; ++tot[c.a]; TRACE(c.a _ c.b); } sort(s, s + n); REP(i, n) { if (s[i].b == -1) { ++sol; continue; } if (i > 0 && s[i-1] == s[i]) continue; if (s[i].a == 1) sol += 1; else { if (tot[s[i].a] > tot[s[i].b] || (tot[s[i].a] == tot[s[i].b] && s[i].a < s[i].b)) sol += tot[s[i].a]; } } printf("%d\n",sol); return 0; }
a.cc:17:9: warning: "debug" redefined 17 | #define debug | ^~~~~ a.cc:16:9: note: this is the location of the previous definition 16 | #define debug(...) fprintf(stderr, __VA_ARGS__) | ^~~~~ a.cc:18:9: warning: "TRACE" redefined 18 | #define TRACE(x) | ^~~~~ a.cc:15:9: note: this is the location of the previous definition 15 | #define TRACE(x) cerr << #x << " = " << x << endl | ^~~~~ a.cc: In function 'pii get_class(llint)': a.cc:52:18: error: 'sqrt' was not declared in this scope 52 | llint root = sqrt(x); | ^~~~
s617810457
p04022
C++
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define si(X) scanf("%d", &(X)) #define sll(X) scanf("%lld",&(X)) #define INFL 0x3f3f3f3f3f3f3f3fLL const int mod = 1e9+7; ll gcd(ll a,ll b){ if(b==0) return a;return gcd(b,a%b); } ll expo(ll base,ll pow){ ll ans = 1; while(pow!=0){ if(pow&1==1){ ans = ans*base; ans = ans%mod; } base *= base;base%=mod; pow/=2; }return ans; } ll inv(ll x){ return expo(x,mod-2); } double pi = 3.141592653589793238462643; double error = 0.0000001; int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1}; // last 4 diagonal int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1}; /* -------Template ends here-------- */ const ll M = 2222; const int M2 = 100011; const ll lim = 1e12; vector<ll> cubes , prime; bool is_p(int x) { for (int i = 2; i * i <= x; i++) if (x % i == 0) return false; return true; } void sieve_type() { for (int i = 2; i < M; i++) { if (is_p(i)) cubes.push_back(1ll * i * i * i); } for (int i = 2; i < M2; i++) { if (is_p(i)) prime.push_back(i); } } ll divfac(ll x) { for (ll q : cubes) { if (q > x)break; while (x % q == 0) x /= q; } return x; } ll cal(ll a, ll b) { if (lim / b < a) return lim; return a * b; } ll complement(ll x) { ll y = 1; for (int p : prime) { if (1ll * p * p > x) break; if (x % p == 0) { if (((x / p) % p) == 0) y = mul(y, p), x /= p, x /= p; else y = mul(y, mul(p, p)), x /= p; } } if (x != 1) y = mul(y, mul(x, x)); return y; } map<ll, int> look; set<ll> done; int main() { int n; scanf("%d", &n); sieve_type(); for (int i = 1 ; i <= n ; i++) { ll x; scanf("%lld", &x); x = divfac(x); look[x]++; } int ans = 0; for (auto pr : look) { ll x = pr.first; int c = pr.second; ll y = complement(x); if (used.count(x))continue; if (x == y) { ans++; continue; } if (cnt.count(y)) { ans += max(c, divfac[y]); done.insert(y); done.insert(x); } else { done.insert(x); ans += c; } } printf("%d\n", ans); }
a.cc: In function 'long long int complement(long long int)': a.cc:76:21: error: 'mul' was not declared in this scope; did you mean 'fmul'? 76 | y = mul(y, p), x /= p, x /= p; | ^~~ | fmul a.cc:78:28: error: 'mul' was not declared in this scope; did you mean 'fmul'? 78 | y = mul(y, mul(p, p)), x /= p; | ^~~ | fmul a.cc:78:21: error: 'mul' was not declared in this scope; did you mean 'fmul'? 78 | y = mul(y, mul(p, p)), x /= p; | ^~~ | fmul a.cc:81:28: error: 'mul' was not declared in this scope; did you mean 'fmul'? 81 | if (x != 1) y = mul(y, mul(x, x)); | ^~~ | fmul a.cc:81:21: error: 'mul' was not declared in this scope; did you mean 'fmul'? 81 | if (x != 1) y = mul(y, mul(x, x)); | ^~~ | fmul a.cc: In function 'int main()': a.cc:104:13: error: 'used' was not declared in this scope 104 | if (used.count(x))continue; | ^~~~ a.cc:110:14: error: 'cnt' was not declared in this scope; did you mean 'int'? 110 | if (cnt.count(y)) { | ^~~ | int a.cc:111:39: warning: pointer to a function used in arithmetic [-Wpointer-arith] 111 | ans += max(c, divfac[y]); | ^ a.cc:111:27: error: no matching function for call to 'max(int&, long long int (&)(long long int))' 111 | ans += max(c, divfac[y]); | ~~~^~~~~~~~~~~~~~ In file included from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)' 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed: a.cc:111:27: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int(long long int)') 111 | ans += max(c, divfac[y]); | ~~~^~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)' 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61: /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)' 5706 | max(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)' 5716 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed: a.cc:111:27: note: mismatched types 'std::initializer_list<_Tp>' and 'int' 111 | ans += max(c, divfac[y]); | ~~~^~~~~~~~~~~~~~
s357054328
p04022
C++
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define si(X) scanf("%d", &(X)) #define sll(X) scanf("%lld",&(X)) #define INFL 0x3f3f3f3f3f3f3f3fLL const int mod = 1e9+7; ll gcd(ll a,ll b){ if(b==0) return a;return gcd(b,a%b); } ll expo(ll base,ll pow){ ll ans = 1; while(pow!=0){ if(pow&1==1){ ans = ans*base; ans = ans%mod; } base *= base;base%=mod; pow/=2; }return ans; } ll inv(ll x){ return expo(x,mod-2); } double pi = 3.141592653589793238462643; double error = 0.0000001; int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1}; // last 4 diagonal int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1}; /* -------Template ends here-------- */ const int M = 100001; vector<ll> prime; bool isP[M]; void sieve(){ isP[1] = 1; for(int i = 2 ; i < M ; i++){ if(isP[i]) continue; prime.push_back(i); for(ll j = i * 1LL * i ; j < M ; j += i){ isP[j] = 1; } } } ll fin(ll x){ ll res = x; for(int i = 0 ; i < prime.size() ; i++){ ll ex = prime[i] * prime[i] * prime[i]; if(ex > res) break; while(res%ex == 0) res /= ex; } return res; } ll complement(ll x){ ll res = 1; for(int i = 0 ; i < prime.size() ; i++){ if(prime[i] * prime[i] > x) break; ll ex = prime[i]; if(x%ex == 0){ x/=ex; if(x%ex == 0){ x/=ex; res *= ex; } else{ res *= ex; res *= ex; } } } if(x > 1){ res *= x; res *= x; } return res; } unordered_map<ll , int> divfac; unordered_set<ll> done; int main(){ //freopen("input.txt", "rt", stdin); //freopen("output.txt", "wt", stdout); sieve(); int n; si(n); for(int i = 1 ; i <= n ; i++){ ll el; sll(el); ll ex = fin(el); //cout<<el <<" "<<ex<<endl; divfac[ex]++; } map<ll , int> :: iterator it; int ans = 0; for(it = divfac.begin() ; it != divfac.end() ; it++){ ll el = it->first; int times = it->second; if(el == 1){ ans++; continue; } ll c_el = complement(el); if(done.count(el)) continue; ans += max(times , divfac[c_el]); done.insert(el); done.insert(c_el); } printf("%d\n" , ans); }
a.cc: In function 'int main()': a.cc:106:27: error: no match for 'operator=' (operand types are 'std::map<long long int, int>::iterator' {aka 'std::_Rb_tree<long long int, std::pair<const long long int, int>, std::_Select1st<std::pair<const long long int, int> >, std::less<long long int>, std::allocator<std::pair<const long long int, int> > >::iterator'} and 'std::unordered_map<long long int, int>::iterator' {aka 'std::__detail::_Insert_base<long long int, std::pair<const long long int, int>, std::allocator<std::pair<const long long int, int> >, std::__detail::_Select1st, std::equal_to<long long int>, std::hash<long long int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator'}) 106 | for(it = divfac.begin() ; it != divfac.end() ; it++){ | ^ In file included from /usr/include/c++/14/map:62, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152, from a.cc:1: /usr/include/c++/14/bits/stl_tree.h:252:12: note: candidate: 'constexpr std::_Rb_tree_iterator<std::pair<const long long int, int> >& std::_Rb_tree_iterator<std::pair<const long long int, int> >::operator=(const std::_Rb_tree_iterator<std::pair<const long long int, int> >&)' 252 | struct _Rb_tree_iterator | ^~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_tree.h:252:12: note: no known conversion for argument 1 from 'std::unordered_map<long long int, int>::iterator' {aka 'std::__detail::_Insert_base<long long int, std::pair<const long long int, int>, std::allocator<std::pair<const long long int, int> >, std::__detail::_Select1st, std::equal_to<long long int>, std::hash<long long int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator'} to 'const std::_Rb_tree_iterator<std::pair<const long long int, int> >&' /usr/include/c++/14/bits/stl_tree.h:252:12: note: candidate: 'constexpr std::_Rb_tree_iterator<std::pair<const long long int, int> >& std::_Rb_tree_iterator<std::pair<const long long int, int> >::operator=(std::_Rb_tree_iterator<std::pair<const long long int, int> >&&)' /usr/include/c++/14/bits/stl_tree.h:252:12: note: no known conversion for argument 1 from 'std::unordered_map<long long int, int>::iterator' {aka 'std::__detail::_Insert_base<long long int, std::pair<const long long int, int>, std::allocator<std::pair<const long long int, int> >, std::__detail::_Select1st, std::equal_to<long long int>, std::hash<long long int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator'} to 'std::_Rb_tree_iterator<std::pair<const long long int, int> >&&' a.cc:106:34: error: no match for 'operator!=' (operand types are 'std::map<long long int, int>::iterator' {aka 'std::_Rb_tree<long long int, std::pair<const long long int, int>, std::_Select1st<std::pair<const long long int, int> >, std::less<long long int>, std::allocator<std::pair<const long long int, int> > >::iterator'} and 'std::unordered_map<long long int, int>::iterator' {aka 'std::__detail::_Insert_base<long long int, std::pair<const long long int, int>, std::allocator<std::pair<const long long int, int> >, std::__detail::_Select1st, std::equal_to<long long int>, std::hash<long long int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator'}) 106 | for(it = divfac.begin() ; it != divfac.end() ; it++){ | ~~ ^~ ~~~~~~~~~~~~ | | | | | std::unordered_map<long long int, int>::iterator {aka std::__detail::_Insert_base<long long int, std::pair<const long long int, int>, std::allocator<std::pair<const long long int, int> >, std::__detail::_Select1st, std::equal_to<long long int>, std::hash<long long int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator} | std::map<long long int, int>::iterator {aka std::_Rb_tree<long long int, std::pair<const long long int, int>, std::_Select1st<std::pair<const long long int, int> >, std::less<long long int>, std::allocator<std::pair<const long long int, int> > >::iterator} In file included from /usr/include/c++/14/regex:68, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:181: /usr/include/c++/14/bits/regex.h:1132:5: note: candidate: 'template<class _BiIter> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, const sub_match<_BiIter>&)' 1132 | operator!=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs) | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1132:5: note: template argument deduction/substitution failed: a.cc:106:48: note: 'std::map<long long int, int>::iterator' {aka 'std::_Rb_tree<long long int, std::pair<const long long int, int>, std::_Select1st<std::pair<const long long int, int> >, std::less<long long int>, std::allocator<std::pair<const long long int, int> > >::iterator'} is not derived from 'const std::__cxx11::sub_match<_BiIter>' 106 | for(it = divfac.begin() ; it != divfac.end() ; it++){ | ^ /usr/include/c++/14/bits/regex.h:1212:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator!=(__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&, const sub_match<_BiIter>&)' 1212 | operator!=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1212:5: note: template argument deduction/substitution failed: a.cc:106:48: note: 'std::map<long long int, int>::iterator' {aka 'std::_Rb_tree<long long int, std::pair<const long long int, int>, std::_Select1st<std::pair<const long long int, int> >, std::less<long long int>, std::allocator<std::pair<const long long int, int> > >::iterator'} is not derived from 'std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>' 106 | for(it = divfac.begin() ; it != divfac.end() ; it++){ | ^ /usr/include/c++/14/bits/regex.h:1305:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)' 1305 | operator!=(const sub_match<_Bi_iter>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1305:5: note: template argument deduction/substitution failed: a.cc:106:48: note: 'std::map<long long int, int>::iterator' {aka 'std::_Rb_tree<long long int, std::pair<const long long int, int>, std::_Select1st<std::pair<const long long int, int> >, std::less<long long int>, std::allocator<std::pair<const long long int, int> > >::iterator'} is not derived from 'const std::__cxx11::sub_match<_BiIter>' 106 | for(it = divfac.begin() ; it != divfac.end() ; it++){ | ^ /usr/include/c++/14/bits/regex.h:1379:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const typename std::iterator_traits<_Iter>::value_type*, const sub_match<_BiIter>&)' 1379 | operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1379:5: note: template argument deduction/substitution failed: a.cc:106:48: note: 'std::unordered_map<long long int, int>::iterator' {aka 'std::__detail::_Insert_base<long long int, std::pair<const long long int, int>, std::allocator<std::pair<const long long int, int> >, std::__detail::_Select1st, std::equal_to<long long int>, std::hash<long long int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator'} is not derived from 'const std::__cxx11::sub_match<_BiIter>' 106 | for(it = divfac.begin() ; it != divfac.end() ; it++){ | ^ /usr/include/c++/14/bits/regex.h:1473:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type*)' 1473 | operator!=(const sub_match<_Bi_iter>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1473:5: note: template argument deduction/substitution failed: a.cc:106:48: note: 'std::map<long long int, int>::iterator' {aka 'std::_Rb_tree<long long int, std::pair<const long long int, int>, std::_Select1st<std::pair<const long long int, int> >, std::less<long long int>, std::allocator<std::pair<const long long int, int> > >::iterator'} is not derived from 'const std::__cxx11::sub_match<_BiIter>' 106 | for(it = divfac.begin() ; it != divfac.end() ; it++){ | ^ /usr/include/c++/14/bits/regex.h:1547:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const typename std::iterator_traits<_Iter>::value_type&, const sub_match<_BiIter>&)' 1547 | operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1547:5: note: template argument deduction/substitution failed: a.cc:106:48: note: 'std::unordered_map<long long int, int>::iterator' {aka 'std::__detail::_Insert_base<long long int, std::pair<const long long int, int>, std::allocator<std::pair<const long long int, int> >, std::__detail::_Select1st, std::equal_to<long long int>, std::hash<long long int>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::iterator'} is not derived from
s201039094
p04022
C++
#include<bits/stdc++.h> #define lim 2154 #define ll long long using namespace std; ll a[100010]; ll b[100010]; ll p[100010]; map<ll,ll> vis; map<ll,ll> cnt1; map<ll,ll> sqr; map<ll,ll> root; vector<ll> v; void sieve() { ll i,j,k,l; sqr[1]=1; root[1]=1; for(i=2;i<=100000;i++) { if(p[i]) continue; sqr[i*i]=1; root[i*i]=i; v.push_back(i); // cout<<v.size()<<' '; for(j=i*i;j<=100000;j+=i) { p[j]=1; } } } ll x,y; void get1(ll s) { ll i,j,k,l; x=y=1; for(i=0;i<v.size()&&v[i]<lim;i++) { k=0; ll u=v[i]; while(s%u==0) { s/=u; k++; k%=3; } l=(3-k)%3; while(k--) x*=u; while(l--) y*=u; } if(s!=1) { if(sqr[s]) { x*=s; y*=root[s]; } else { x*=s; y*=s*s; } } } int main() { ll n; sieve(); cin>>n; ll ans=0; for(int i=0;i<n;i++) { cin>>a[i]; get1(a[i]); // cout<<a[i]<<' '<<x<<' '<<y<<'\n'; a[i]=x; b[i]=y; cnt1[x]++; } for(int i=0;i<n;i++) { if(vis[a[i]]) continue; if(a[i]==1) ans++; else ans+=max(cnt1[a[i]],cnt1[b[i]]); vis[a[i]]=vis[b[i]]=1; } cout<<ans; } //6 //1 1 2 2 4 4 //ans: 3 //10 //1 1 2 2 4 4 4 4 4 4 //ans: 7 //10 //1 1 2 2 2 2 2 2 4 4 #include<bits/stdc++.h> #define lim 2154 #define ll long long using namespace std; ll a[100010]; ll b[100010]; ll p[100010]; map<ll,ll> vis; map<ll,ll> cnt1; map<ll,ll> sqr; map<ll,ll> root; vector<ll> v; void sieve() { ll i,j,k,l; sqr[1]=1; root[1]=1; for(i=2;i<=100000;i++) { if(p[i]) continue; sqr[i*i]=1; root[i*i]=i; v.push_back(i); // cout<<v.size()<<' '; for(j=i*i;j<=100000;j+=i) { p[j]=1; } } } ll x,y; void get1(ll s) { ll i,j,k,l; x=y=1; for(i=0;i<v.size()&&v[i]<lim;i++) { k=0; ll u=v[i]; while(s%u==0) { s/=u; k++; k%=3; } l=(3-k)%3; while(k--) x*=u; while(l--) y*=u; } if(s!=1) { if(sqr[s]) { x*=s; y*=root[s]; } else { x*=s; y*=s*s; } } } int main() { ll n; sieve(); cin>>n; ll ans=0; for(int i=0;i<n;i++) { cin>>a[i]; get1(a[i]); // cout<<a[i]<<' '<<x<<' '<<y<<'\n'; a[i]=x; b[i]=y; cnt1[x]++; } for(int i=0;i<n;i++) { if(vis[a[i]]) continue; if(a[i]==1) ans++; else ans+=max(cnt1[a[i]],cnt1[b[i]]); vis[a[i]]=vis[b[i]]=1; } cout<<ans; } //6 //1 1 2 2 4 4 //ans: 3 //10 //1 1 2 2 4 4 4 4 4 4 //ans: 7 //10 //1 1 2 2 2 2 2 2 4 4
a.cc:111:4: error: redefinition of 'long long int a [100010]' 111 | ll a[100010]; | ^ a.cc:5:4: note: 'long long int a [100010]' previously declared here 5 | ll a[100010]; | ^ a.cc:112:4: error: redefinition of 'long long int b [100010]' 112 | ll b[100010]; | ^ a.cc:6:4: note: 'long long int b [100010]' previously declared here 6 | ll b[100010]; | ^ a.cc:113:4: error: redefinition of 'long long int p [100010]' 113 | ll p[100010]; | ^ a.cc:7:4: note: 'long long int p [100010]' previously declared here 7 | ll p[100010]; | ^ a.cc:114:12: error: redefinition of 'std::map<long long int, long long int> vis' 114 | map<ll,ll> vis; | ^~~ a.cc:8:12: note: 'std::map<long long int, long long int> vis' previously declared here 8 | map<ll,ll> vis; | ^~~ a.cc:115:12: error: redefinition of 'std::map<long long int, long long int> cnt1' 115 | map<ll,ll> cnt1; | ^~~~ a.cc:9:12: note: 'std::map<long long int, long long int> cnt1' previously declared here 9 | map<ll,ll> cnt1; | ^~~~ a.cc:116:12: error: redefinition of 'std::map<long long int, long long int> sqr' 116 | map<ll,ll> sqr; | ^~~ a.cc:10:12: note: 'std::map<long long int, long long int> sqr' previously declared here 10 | map<ll,ll> sqr; | ^~~ a.cc:117:12: error: redefinition of 'std::map<long long int, long long int> root' 117 | map<ll,ll> root; | ^~~~ a.cc:11:12: note: 'std::map<long long int, long long int> root' previously declared here 11 | map<ll,ll> root; | ^~~~ a.cc:118:12: error: redefinition of 'std::vector<long long int> v' 118 | vector<ll> v; | ^ a.cc:12:12: note: 'std::vector<long long int> v' previously declared here 12 | vector<ll> v; | ^ a.cc:120:6: error: redefinition of 'void sieve()' 120 | void sieve() | ^~~~~ a.cc:14:6: note: 'void sieve()' previously defined here 14 | void sieve() | ^~~~~ a.cc:139:4: error: redefinition of 'long long int x' 139 | ll x,y; | ^ a.cc:33:4: note: 'long long int x' previously declared here 33 | ll x,y; | ^ a.cc:139:6: error: redefinition of 'long long int y' 139 | ll x,y; | ^ a.cc:33:6: note: 'long long int y' previously declared here 33 | ll x,y; | ^ a.cc:140:6: error: redefinition of 'void get1(long long int)' 140 | void get1(ll s) | ^~~~ a.cc:34:6: note: 'void get1(long long int)' previously defined here 34 | void get1(ll s) | ^~~~ a.cc:174:5: error: redefinition of 'int main()' 174 | int main() | ^~~~ a.cc:68:5: note: 'int main()' previously defined here 68 | int main() | ^~~~
s194981116
p04022
C++
#define _USE_MATH_DEFINES #include <vector> #include <string> #include <iostream> #include <fstream> #include <sstream> #include <list> #include <algorithm> #include <sstream> #include <set> #include <math.h> #include <cmath> #include <map> #include <stack> #include <queue> #include <stdio.h> #include <string.h> #include <numeric> using namespace std; typedef unsigned long long ll; int N,NP; ll S[100000]; ll prime[100000]; bool is_prime[100001]; map <ll, ll> mp; map <ll,ll>::iterator it; set <ll> st; int sieve(int n){ int p=0; for(int i=0; i<=n; i++) is_prime[i]=true; is_prime[0]=is_prime[1]=false; for(int i=2; i<=n; i++){ if(is_prime[i]){ prime[p++]=i; for(int j=2*i; j<=n; j+=i) is_prime[j]=false; } } return p; } ll dv(ll x){ for(int i=0; i<NP; i++){ ll q=prime[i]; //if(q>1000) break; ll t=q*q*q; if(t>x) break; while(x%t==0) x/=t; } return x; } ll tp(ll x){ ll A=1,B=1; for(ll i=2;;i++){ if(i*i*i>x) break; int cnt=0; while(x%i==0) { x/=i; cnt++; } if(cnt==1) A*=i; else if(cnt==2) B*=i; } ll dt=(ll) floor(sqrt(x)+0.5); if(dt*dt==x) return A*A*sqrt(B)*dt; else return A*A*sqrt(B)*x*x; } int main(){ scanf("%d",&N); NP=sieve(100000); for(int i=0; i<N; i++){ scanf("%lld",&S[i]); ll x=dv(S[i]); mp[x]++; //cout<<x<<endl; } int ans=0; //cout<<tp(1027243729)<<endl; for(it=mp.begin();it!=mp.end();it++){ ll x=it->first; //cout<<x<<endl; ll y=tp(x); if(st.count(x)) continue; if(x!=1) ans+=max(mp[x],mp[y]); else ans++; st.insert(y); } cout<<ans<<endl; return 0;
a.cc: In function 'int main()': a.cc:114:11: error: expected '}' at end of input 114 | return 0; | ^ a.cc:82:11: note: to match this '{' 82 | int main(){ | ^
s609636674
p04022
C++
#include <iostream> #include <vector> #include <map> #include <cmath> using namespace std; typedef long long int LL; bool same_cube = 1, czy_jest_cube = 0; int n; LL pom, wynik; const int stala = 2155, stala_1 = 100007; const LL reszta = 1000000000000000007LL, wspolczynnikPoczatkowy = 20000000009LL; bool zajete[stala], odw[stala_1]; LL hasz[stala_1]; map<LL, int> hasz_uzup; map<LL, int>::iterator it; vector<LL> liczby; vector<LL> liczbyPierwsze; struct potega { LL wys; LL co; }; potega dod; vector<potega> rozklad[stala_1]; vector<potega> nowyRozklad[stala_1]; vector<int> ileRazy; vector<int> kolejnosc; LL pomnoz(LL alfa, LL beta) { if(alfa == 1) return beta; if(alfa%2 == 0) return (2*pomnoz(alfa/2, beta))%reszta; return (beta+2*pomnoz(alfa/2,beta))%reszta; } void sprawdzHasz(int nr) { LL wyn = 0, wspol = wspolczynnikPoczatkowy; odw[nr] = 1; for(int j = 0; j < nowyRozklad[nr].size(); j++) { wyn += pomnoz(wspol, nowyRozklad[nr][j].co*(3-nowyRozklad[nr][j].wys)); wyn %= reszta; wspol = pomnoz(wspol, wspolczynnikPoczatkowy); } it = hasz_uzup.find(wyn); if(it == hasz_uzup.end()) wynik += ileRazy[nr]; else { odw[ it->second ] = 1; wynik += max(ileRazy[nr], ileRazy[ it->second ]); } } void policzHaszUzupelniajacy(int nr) { LL wyn = 0, wspol = wspolczynnikPoczatkowy; for(int j = 0; j < nowyRozklad[nr].size(); j++) { wyn += pomnoz(wspol, nowyRozklad[nr][j].co*nowyRozklad[nr][j].wys); wyn %= reszta; wspol = pomnoz(wspol, wspolczynnikPoczatkowy); } hasz_uzup[wyn] = nr; } bool rowne(int k1, int k2) { if(rozklad[k1].size() != rozklad[k2].size()) return 0; for(int j = 0; j < rozklad[k1].size(); j++) { if(rozklad[k1][j].co != rozklad[k2][j].co) return 0; if(rozklad[k1][j].wys != rozklad[k2][j].wys) return 0; } return 1; } bool sort_kolejnosc(int k1, int k2) { for(int j = 0; j < min(rozklad[k1].size(), rozklad[k2].size()); j++) { if(rozklad[k1][j].co != rozklad[k2][j].co) return rozklad[k1][j].co < rozklad[k2][j].co; if(rozklad[k1][j].wys != rozklad[k2][j].wys) return rozklad[k1][j].wys < rozklad[k2][j].wys; } if(rozklad[k2].size() < rozklad[k1].size()) return 0; return 1; } void rozloz(int nr) { for(int j = 0; j < liczbyPierwsze.size() && liczby[nr] > 1; j++) { dod.co = liczbyPierwsze[j]; dod.wys = 0; while(liczby[nr]%dod.co == 0) { dod.wys = (dod.wys+1)%3; liczby[nr] /= dod.co; } if(dod.wys > 0) rozklad[nr].push_back(dod); } if(liczby[nr] > 1) { LL sq = sqrt(liczby[nr]); if(sq*sq == liczby[nr]) { dod.co = sq; dod.wys = 2; } else { dod.co = liczby[nr]; dod.wys = 1; } rozklad[nr].push_back(dod); } } void sito() { for(int i = 2; i < stala; i++) { if(!zajete[i]) { liczbyPierwsze.push_back(i); for(int j = i*i; j < stala; j += i) zajete[j] = 1; } } } LL znajdz_pierwiastek(LL co) { LL a = 1, b = 2155, sr; while(a != b) { sr = (a+b)/2; if(sr*sr*sr == co) return sr; if(sr*sr*sr > co) { b = sr; } else a = sr+1; } return a; } bool czy_szescian(LL co) { LL gdzie = znajdz_pierwiastek(co); if(gdzie*gdzie*gdzie == co) return 1; return 0; } int main() { ios_base::sync_with_stdio(0); cin >> n; for(int i = 0; i < n; i++) { cin >> pom; if(czy_szescian(pom)) { czy_jest_cube = 1; } else { same_cube = 0; liczby.push_back(pom); } } if(same_cube) { cout << 1 << "\n"; return 0; } if(czy_jest_cube) wynik++; sito(); for(int i = 0; i < liczby.size(); i++) { rozloz(i); for(int j = 0; j < rozklad[i].size()/2; j++) { swap(rozklad[i][j], rozklad[i][ rozklad[i].size()-1-j ]); } kolejnosc.push_back(i); } sort(kolejnosc.begin(), kolejnosc.end(), sort_kolejnosc); //WYPISZ ROZKLAD /* for(int i = 0; i < kolejnosc.size(); i++) { cout << "i == " << i << endl; for(int j = 0; j < rozklad[kolejnosc[i]].size(); j++) { cout << "(" << rozklad[kolejnosc[i]][j].co << " -> " << rozklad[kolejnosc[i]][j].wys << " razy); "; } cout << endl; } */ //KONIEC WYPISYWANIA for(int i = 0; i < rozklad[ kolejnosc[0] ].size(); i++) nowyRozklad[0].push_back( rozklad[ kolejnosc[0] ][i] ); ileRazy.push_back(1); for(int i = 1; i < kolejnosc.size(); i++) { if(rowne(kolejnosc[i], kolejnosc[i-1]) ) { ileRazy[ ileRazy.size()-1 ]++; } else { for(int j = 0; j < rozklad[ kolejnosc[i] ].size(); j++) { nowyRozklad[ ileRazy.size() ].push_back( rozklad[ kolejnosc[i] ][j] ); } ileRazy.push_back(1); } } for(int i = 0; i < ileRazy.size(); i++) { policzHaszUzupelniajacy(i); } for(int i = 0; i < ileRazy.size(); i++) { if(!odw[i]) { sprawdzHasz(i); } } cout << wynik << "\n"; return 0; }
a.cc: In function 'int main()': a.cc:165:9: error: 'sort' was not declared in this scope; did you mean 'sqrt'? 165 | sort(kolejnosc.begin(), kolejnosc.end(), sort_kolejnosc); | ^~~~ | sqrt
s044531389
p04022
C++
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef long long ll; int main() { cout << numeric_limits<__int128>::max() << endl; int n; cin >> n; vector<ll> a(n); for (auto& x : a) cin >> x; vector<int> is_prime(3000001, 1); vector<ll> primes; primes.reserve(is_prime.size()); is_prime[0] = 0; is_prime[1] = 0; for (int i = 2; i * i < is_prime.size(); ++i) { if (is_prime[i]) { primes.push_back(i); for (int j = i * i; j < is_prime.size(); j += i) { is_prime[j] = 0; } } } map<ll, int> cnt; for (int i = 0; i < n; ++i) { for (int j = 0; j < primes.size(); ++j) { if (primes[j] * primes[j] * primes[j] > a[i]) break; while (a[i] % (primes[j] * primes[j] * primes[j]) == 0) { a[i] /= primes[j] * primes[j] * primes[j]; } } cnt[a[i]]++; } int ans = 0; if (cnt[1] > 0) ans++; for (auto& x : cnt) { if (x.first == 1) continue; auto y = __int128(x.first) * x.first; for (int j = 0; j < primes.size(); ++j) { auto divide = __int128(primes[j]) * primes[j] * primes[j]; if (y < divide) break; while (y % divide == 0) { y /= divide; } } if (!cnt.count(y)) { ans += x.second; } else if (x.first > y) { ans += max(x.second, cnt[y]); } } cout << ans << endl; }
a.cc: In function 'int main()': a.cc:26:10: error: ambiguous overload for 'operator<<' (operand types are 'std::ostream' {aka 'std::basic_ostream<char>'} and '__int128') 26 | cout << numeric_limits<__int128>::max() << endl; | ~~~~ ^~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | __int128 | std::ostream {aka std::basic_ostream<char>} In file included from /usr/include/c++/14/istream:41, from /usr/include/c++/14/sstream:40, from /usr/include/c++/14/complex:45, from a.cc:5: /usr/include/c++/14/ostream:174:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 174 | operator<<(long __n) | ^~~~~~~~ /usr/include/c++/14/ostream:178:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 178 | operator<<(unsigned long __n) | ^~~~~~~~ /usr/include/c++/14/ostream:182:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 182 | operator<<(bool __n) | ^~~~~~~~ In file included from /usr/include/c++/14/ostream:1022: /usr/include/c++/14/bits/ostream.tcc:96:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]' 96 | basic_ostream<_CharT, _Traits>:: | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/ostream:189:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 189 | operator<<(unsigned short __n) | ^~~~~~~~ /usr/include/c++/14/bits/ostream.tcc:110:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]' 110 | basic_ostream<_CharT, _Traits>:: | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/ostream:200:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 200 | operator<<(unsigned int __n) | ^~~~~~~~ /usr/include/c++/14/ostream:211:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 211 | operator<<(long long __n) | ^~~~~~~~ /usr/include/c++/14/ostream:215:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 215 | operator<<(unsigned long long __n) | ^~~~~~~~ /usr/include/c++/14/ostream:231:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 231 | operator<<(double __f) | ^~~~~~~~ /usr/include/c++/14/ostream:235:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 235 | operator<<(float __f) | ^~~~~~~~ /usr/include/c++/14/ostream:243:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 243 | operator<<(long double __f) | ^~~~~~~~ /usr/include/c++/14/ostream:573:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, char) [with _CharT = char; _Traits = char_traits<char>]' 573 | operator<<(basic_ostream<_CharT, _Traits>& __out, char __c) | ^~~~~~~~ /usr/include/c++/14/ostream:579:5: note: candidate: 'std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, char) [with _Traits = char_traits<char>]' 579 | operator<<(basic_ostream<char, _Traits>& __out, char __c) | ^~~~~~~~ /usr/include/c++/14/ostream:590:5: note: candidate: 'std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, signed char) [with _Traits = char_traits<char>]' 590 | operator<<(basic_ostream<char, _Traits>& __out, signed char __c) | ^~~~~~~~ /usr/include/c++/14/ostream:595:5: note: candidate: 'std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, unsigned char) [with _Traits = char_traits<char>]' 595 | operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c) | ^~~~~~~~
s601060547
p04022
C++
#include <bits/stdc++.h> using namespace std; map<long long, long long> cnt; long long arr[100050]; bool isPrime[100050]; vector<long long> prime; long long Slove(long long n) { for(vector<long long>::size_type i = 0; i < prime.size(); ++i) { if(prime[i] * prime[i] * prime[i] > n) break; while(n % (prime[i] * prime[i] * prime[i]) == 0) n /= prime[i] * prime[i] * prime[i]; } return n; } int main() { memset(isPrime, true, sizeof(isPrime)); for(long long i = 2; i <= 100000; ++i) { if(!isPrime[i]) continue; prime.push_back(i); for(long long j = i + i; j <= 100000; j += i) isPrime[j] = false; } long long n; scanf("%lld", &n); for(long long i = 1; i <= n; ++i) scanf("%lld", &arr[i]); for(long long i = 1; i <= n; ++i) ++cnt[ Slove(arr[i]) ]; long long ans; if(cnt.find(1) != cnt.end()) ans = 1; else ans = 0; for(auto &it = cnt.begin(); it != cnt.end(); ++it) { if(it->first == 1) continue; long long a = it->first; long long b = Slove(a * a); ans += max(cnt[a], cnt[b]); cnt[a] = 0; cnt[b] = 0; } printf("%lld\n", ans); return 0; }
a.cc: In function 'int main()': a.cc:41:29: error: cannot bind non-const lvalue reference of type 'std::_Rb_tree_iterator<std::pair<const long long int, long long int> >&' to an rvalue of type 'std::map<long long int, long long int>::iterator' {aka 'std::_Rb_tree<long long int, std::pair<const long long int, long long int>, std::_Select1st<std::pair<const long long int, long long int> >, std::less<long long int>, std::allocator<std::pair<const long long int, long long int> > >::iterator'} 41 | for(auto &it = cnt.begin(); it != cnt.end(); ++it) | ~~~~~~~~~^~
s355385618
p04022
C++
#include <bits/stdc++.h> using namespace std; map<long long, long long> cnt; long long arr[100050]; bool isPrime[100050]; vector<long long> prime; long long Slove(long long n) { for(vector<long long>::size_type i = 0; i < prime.size(); ++i) { if(prime[i] * prime[i] * prime[i] > n) break; while(n % (prime[i] * prime[i] * prime[i]) == 0) n /= prime[i] * prime[i] * prime[i]; } return n; } int main() { memset(isPrime, true, sizeof(isPrime)); for(long long i = 2; i <= 100000; ++i) { if(!isPrime[i]) continue; prime.push_back(i); for(long long j = i + i; j <= 100000; j += i) isPrime[j] = false; } long long n; scanf("%lld", &n); for(long long i = 1; i <= n; ++i) scanf("%lld", &arr[i]); for(long long i = 1; i <= n; ++i) ++cnt[ Slove(arr[i]) ]; long long ans; if(cnt.find(1) != cnt.end()) ans = 1; else ans = 0; for(auto it = cnt.begin(); it != cnt.end(); ++it) { long long a = cnt->first; long long b = Slove(a * a); ans += max(cnt[a], cnt[b]); cnt[a] = 0; cnt[b] = 0; } printf("%lld\n", ans); return 0; }
a.cc: In function 'int main()': a.cc:43:26: error: base operand of '->' has non-pointer type 'std::map<long long int, long long int>' 43 | long long a = cnt->first; | ^~
s342883147
p04022
C++
#include <bits/stdc++.h> using namespace std; map<__int64, __int64> match; map<__int64, __int64> cnt; __int64 arr[100050]; bool isPrime[100050]; vector<__int64> prime; __int64 Slove(__int64 n) { for(vector<__int64>::size_type i = 0; i < prime.size(); ++i) { while(n % (prime[i] * prime[i] * prime[i]) == 0) n /= prime[i] * prime[i] * prime[i]; } return n; } int main() { memset(isPrime, true, sizeof(isPrime)); for(__int64 i = 2; i <= 100000; ++i) { if(!isPrime[i]) continue; prime.push_back(i); for(__int64 j = i + i; j <= 100000; j += i) isPrime[j] = false; } __int64 n; scanf("%I64d", &n); for(__int64 i = 1; i <= n; ++i) scanf("%I64d", &arr[i]); __int64 ans = 0; for(__int64 i = 1; i <= n; ++i) { if(arr[i] == 1) ++cnt[1]; else { __int64 b; __int64 a = Slove(arr[i]); if(a > 100000000) b = 0; else b = Slove(a * a); ++cnt[a]; if(a > b) swap(a, b); if(a != 1) match[a] = b; } } if(cnt.find(1) != cnt.end()) ans = 1; for(auto it = match.begin(); it != match.end(); ++it) { __int64 a, b; a = it->first; b = it->second; ans += max(cnt[a], cnt[b]); cnt[a] = 0; cnt[b] = 0; } printf("%I64d\n", ans); return 0; }
a.cc:4:5: error: '__int64' was not declared in this scope; did you mean '__ynf64'? 4 | map<__int64, __int64> match; | ^~~~~~~ | __ynf64 a.cc:4:14: error: '__int64' was not declared in this scope; did you mean '__ynf64'? 4 | map<__int64, __int64> match; | ^~~~~~~ | __ynf64 a.cc:4:21: error: template argument 1 is invalid 4 | map<__int64, __int64> match; | ^ a.cc:4:21: error: template argument 2 is invalid a.cc:4:21: error: template argument 3 is invalid a.cc:4:21: error: template argument 4 is invalid a.cc:5:5: error: '__int64' was not declared in this scope; did you mean '__ynf64'? 5 | map<__int64, __int64> cnt; | ^~~~~~~ | __ynf64 a.cc:5:14: error: '__int64' was not declared in this scope; did you mean '__ynf64'? 5 | map<__int64, __int64> cnt; | ^~~~~~~ | __ynf64 a.cc:5:21: error: template argument 1 is invalid 5 | map<__int64, __int64> cnt; | ^ a.cc:5:21: error: template argument 2 is invalid a.cc:5:21: error: template argument 3 is invalid a.cc:5:21: error: template argument 4 is invalid a.cc:6:1: error: '__int64' does not name a type; did you mean '__int64_t'? 6 | __int64 arr[100050]; | ^~~~~~~ | __int64_t a.cc:8:8: error: '__int64' was not declared in this scope; did you mean '__ynf64'? 8 | vector<__int64> prime; | ^~~~~~~ | __ynf64 a.cc:8:15: error: template argument 1 is invalid 8 | vector<__int64> prime; | ^ a.cc:8:15: error: template argument 2 is invalid a.cc:9:1: error: '__int64' does not name a type; did you mean '__int64_t'? 9 | __int64 Slove(__int64 n) | ^~~~~~~ | __int64_t a.cc: In function 'int main()': a.cc:21:9: error: '__int64' was not declared in this scope; did you mean '__ynf64'? 21 | for(__int64 i = 2; i <= 100000; ++i) | ^~~~~~~ | __ynf64 a.cc:21:24: error: 'i' was not declared in this scope 21 | for(__int64 i = 2; i <= 100000; ++i) | ^ a.cc:25:15: error: request for member 'push_back' in 'prime', which is of non-class type 'int' 25 | prime.push_back(i); | ^~~~~~~~~ a.cc:26:20: error: expected ';' before 'j' 26 | for(__int64 j = i + i; j <= 100000; j += i) | ^~ | ; a.cc:26:32: error: 'j' was not declared in this scope; did you mean 'jn'? 26 | for(__int64 j = i + i; j <= 100000; j += i) | ^ | jn a.cc:29:5: error: '__int64' was not declared in this scope; did you mean '__ynf64'? 29 | __int64 n; | ^~~~~~~ | __ynf64 a.cc:30:21: error: 'n' was not declared in this scope; did you mean 'yn'? 30 | scanf("%I64d", &n); | ^ | yn a.cc:31:16: error: expected ';' before 'i' 31 | for(__int64 i = 1; i <= n; ++i) | ^~ | ; a.cc:31:24: error: 'i' was not declared in this scope 31 | for(__int64 i = 1; i <= n; ++i) | ^ a.cc:32:25: error: 'arr' was not declared in this scope 32 | scanf("%I64d", &arr[i]); | ^~~ a.cc:33:12: error: expected ';' before 'ans' 33 | __int64 ans = 0; | ^~~~ | ; a.cc:34:16: error: expected ';' before 'i' 34 | for(__int64 i = 1; i <= n; ++i) | ^~ | ; a.cc:34:24: error: 'i' was not declared in this scope 34 | for(__int64 i = 1; i <= n; ++i) | ^ a.cc:36:12: error: 'arr' was not declared in this scope 36 | if(arr[i] == 1) | ^~~ a.cc:37:18: error: invalid types 'int[int]' for array subscript 37 | ++cnt[1]; | ^ a.cc:40:20: error: expected ';' before 'b' 40 | __int64 b; | ^~ | ; a.cc:41:20: error: expected ';' before 'a' 41 | __int64 a = Slove(arr[i]); | ^~ | ; a.cc:42:16: error: 'a' was not declared in this scope 42 | if(a > 100000000) | ^ a.cc:43:17: error: 'b' was not declared in this scope 43 | b = 0; | ^ a.cc:45:17: error: 'b' was not declared in this scope 45 | b = Slove(a * a); | ^ a.cc:45:21: error: 'Slove' was not declared in this scope 45 | b = Slove(a * a); | ^~~~~ a.cc:46:19: error: 'a' was not declared in this scope 46 | ++cnt[a]; | ^ a.cc:47:20: error: 'b' was not declared in this scope 47 | if(a > b) | ^ a.cc:50:28: error: 'b' was not declared in this scope 50 | match[a] = b; | ^ a.cc:53:12: error: request for member 'find' in 'cnt', which is of non-class type 'int' 53 | if(cnt.find(1) != cnt.end()) | ^~~~ a.cc:53:27: error: request for member 'end' in 'cnt', which is of non-class type 'int' 53 | if(cnt.find(1) != cnt.end()) | ^~~ a.cc:54:9: error: 'ans' was not declared in this scope; did you mean 'abs'? 54 | ans = 1; | ^~~ | abs a.cc:55:25: error: request for member 'begin' in 'match', which is of non-class type 'int' 55 | for(auto it = match.begin(); it != match.end(); ++it) | ^~~~~ a.cc:55:46: error: request for member 'end' in 'match', which is of non-class type 'int' 55 | for(auto it = match.begin(); it != match.end(); ++it) | ^~~ a.cc:57:16: error: expected ';' before 'a' 57 | __int64 a, b; | ^~ | ; a.cc:58:9: error: 'a' was not declared in this scope 58 | a = it->first; | ^ a.cc:59:9: error: 'b' was not declared in this scope 59 | b = it->second; | ^ a.cc:60:9: error: 'ans' was not declared in this scope; did you mean 'abs'? 60 | ans += max(cnt[a], cnt[b]); | ^~~ | abs a.cc:64:23: error: 'ans' was not declared in this scope; did you mean 'abs'? 64 | printf("%I64d\n", ans); | ^~~ | abs
s243245228
p04022
C++
#include <iostream> #include <vector> #define NMAX 100000 #define REP(i, a, n) for(int i = a; i < n; i++) using namespace std; typedef long long ll; int N; ll s[NMAX]; vector<int> prime; pair< pair<ll, ll>, bool > norm[NMAX]; int main(void) { cin >> N; REP(i, 0, N) cin >> s[i]; bool ptable[NMAX] = {false}; ptable[0] = true; REP(i, 0, NMAX) { if(!ptable[i]) { prime.push_back(i + 1); for(int j = (i + 1) * 2; j < NMAX; j += i + 1) { ptable[j - 1] = true; } } } REP(i, 0, N) { norm[i].first.first = s[i]; for(ll p:prime) { ll pcube = p * p * p; while(norm[i].first.first % pcube == 0) norm[i].first.first /= pcube; } norm[i].first.second = norm[i].first.first * norm[i].first.first; for(ll p:prime) { ll pcube = p * p * p; while(norm[i].first.second % pcube == 0) norm[i].first.second /= pcube; } if(norm[i].first.first > norm[i].first.second) { ll temp = norm[i].first.first; norm[i].first.first = norm[i].first.second; norm[i].first.second = temp; norm[i].second = true; } else { norm[i].second = false; } } std::sort(norm, norm + N); ll ans = 0; for(ll i = 0; i < N;) { ll x = 0, y = 0, n; for(n = norm[i].first.first; i < N && norm[i].first.first == n; i++) { norm[i].second ? x++ : y++; } ans += (n == 1 ? 1 : max(x, y)); } cout << ans << endl; // REP(i, 0, N) { // cout << norm[i].first.first << ", " << norm[i].first.second << ", " << norm[i].second << endl; // } return 0; }
a.cc: In function 'int main()': a.cc:52:8: error: 'sort' is not a member of 'std'; did you mean 'qsort'? 52 | std::sort(norm, norm + N); | ^~~~ | qsort
s336906346
p04022
C++
#include <iostream> #include <vector> #define NMAX 100000 #define REP(i, a, n) for(int i = a; i < n; i++) using namespace std; typedef long long ll; int N; ll s[NMAX]; vector<int> prime; pair< pair<ll, ll>, bool > norm[NMAX]; int main(void) { cin >> N; REP(i, 0, N) cin >> s[i]; bool ptable[NMAX] = {false}; ptable[0] = true; REP(i, 0, NMAX) { if(!ptable[i]) { prime.push_back(i + 1); for(int j = (i + 1) * 2; j < NMAX; j += i + 1) { ptable[j - 1] = true; } } } REP(i, 0, N) { norm[i].first.first = s[i]; for(ll p:prime) { ll pcube = p * p * p; while(norm[i].first.first % pcube == 0) norm[i].first.first /= pcube; } norm[i].first.second = norm[i].first.first * norm[i].first.first; for(ll p:prime) { ll pcube = p * p * p; while(norm[i].first.second % pcube == 0) norm[i].first.second /= pcube; } if(norm[i].first.first > norm[i].first.second) { ll temp = norm[i].first.first; norm[i].first.first = norm[i].first.second; norm[i].first.second = temp; norm[i].second = true; } else { norm[i].second = false; } } sort(norm, norm + N); ll ans = 0; for(ll i = 0; i < N;) { ll x = 0, y = 0, n; for(n = norm[i].first.first; i < N && norm[i].first.first == n; i++) { norm[i].second ? x++ : y++; } ans += (n == 1 ? 1 : max(x, y)); } cout << ans << endl; // REP(i, 0, N) { // cout << norm[i].first.first << ", " << norm[i].first.second << ", " << norm[i].second << endl; // } return 0; }
a.cc: In function 'int main()': a.cc:52:3: error: 'sort' was not declared in this scope; did you mean 'short'? 52 | sort(norm, norm + N); | ^~~~ | short
s990825613
p04022
Java
import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.OutputStream; import java.util.HashMap; import java.util.HashSet; import java.util.ArrayList; import java.util.Collections; public class Main { public static long[] primes = new long[9592]; public static long[] squares = new long[9592]; public static long[] cubes = new long[9592]; private static class Pair implements Comparable<Pair> { long red; int a; public Pair(long v) { red = v; a = 1; } public int compareTo(Pair p) { return p.a-a; } } public static void main(String args[]) { Sc sc = new Sc(System.in); int n = sc.nI(); int ind = 0; primes[ind] = 2; squares[ind] = 4; cubes[ind++] = 8; for(long i = 3; i<=100000; i+=2) { long sqrt = (long) Math.sqrt(i); boolean prime = true; for(int j = 1; j<ind; j++) { long p = primes[j]; if(p>sqrt) break; if(i%p == 0) { prime = false; break; } } if(prime) { primes[ind] = i; squares[ind] = i*i; cubes[ind++] = i*i*i; } } FHMap map = new FHMap(); ArrayList<Pair> pairs = new ArrayList<>(); for(int i = 0; i<n; i++) { long v = reduce(sc.nL()); try { Pair p = map.get(v); if(p!=null) { p.a++; } else { p = new Pair(v); map.put(new P(v,p)); pairs.add(p); } } catch(Exception e) {} } HashSet<Long> set = new HashSet<>(); int picked = 0; for(Pair p:pairs) { if(p.red == 1) { picked++; continue; } try { if(!set.contains(p.red)) { long inv = inv(p.red); int max = p.a; if(inv != -1) { Pair pp = map.get(inv); if(pp != null) { max = Math.max(max,pp.a); set.add(inv); } } picked+=max; } catch (Exception e){} } System.out.println(picked); } public static long inv(long v) { long ret = 1; for(int i = 0; i<primes.length; i++) { long p = primes[i]; long sq = squares[i]; if(sq>v) break; if(v%sq == 0) { ret *= p; v /= sq; } else if(v%p == 0) { ret *= sq; v /= p; } if(ret>10000000000L) return -1; } return (v>100000) ? -1 : ret*v*v; } public static long reduce(long v) { for(int i = 0; i<primes.length; i++) { long cube = cubes[i]; if(cube>v) break; while(v%cube == 0) { v /= cube; } } return v; } private static class FHMap { P[] map = new P[320009]; long mod = 320009; int size = 0; public FHMap(){} public void put(P p) { int w = (int) (p.k%mod); while(true) { if(map[w] == null) { map[w] = p; size++; return; } else if(map[w].k == p.k) { map[w] = p; return; } w = (int) ((w + 1)%mod); } } public Pair get(long k) { int w = (int) (k%mod); while(true) { if(map[w] == null) { return null; } else if(map[w].k == k) { return map[w].v; } w = (int)((w + 1)%mod); } } } private static class P { long k; Pair v; public P(long k, Pair v) { this.k = k; this.v = v; } } } class Sc { public Sc(InputStream i) { r = new BufferedReader(new InputStreamReader(i)); } public boolean hasM() { return peekToken() != null; } public int nI() { return Integer.parseInt(nextToken()); } public double nD() { return Double.parseDouble(nextToken()); } public long nL() { return Long.parseLong(nextToken()); } public String n() { return nextToken(); } private BufferedReader r; private String line; private StringTokenizer st; private String token; private String peekToken() { if (token == null) try { while (st == null || !st.hasMoreTokens()) { line = r.readLine(); if (line == null) return null; st = new StringTokenizer(line); } token = st.nextToken(); } catch (IOException e) { } return token; } private String nextToken() { String ans = peekToken(); token = null; return ans; } }
Main.java:90: error: 'catch' without 'try' catch (Exception e){} ^ Main.java:77: error: 'try' without 'catch', 'finally' or resource declarations try { ^ Main.java:94: error: illegal start of expression public static long inv(long v) { ^ 3 errors
s381934263
p04022
Java
import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.OutputStream; import java.util.HashMap; import java.util.HashSet; import java.util.ArrayList; import java.util.Collections; public class Main { public static ArrayList<Long> primes = new ArrayList<>(); public static ArrayList<Long> squares = new ArrayList<>(); public static ArrayList<Long> cubes = new ArrayList<>(); private static class Pair implements Comparable<Pair> { long red; int a; public Pair(long v) { red = v; a = 1; } public int compareTo(Pair p) { return p.a-a; } } public static void main(String args[]) { Sc sc = new Sc(System.in); int n = sc.nI(); primes.add(2L); squares.add(4L); cubes.add(8L); for(long i = 3; i<=100000; i+=2) { long sqrt = (long) Math.sqrt(i); boolean prime = true; for(int j = 1; j<primes.size(); j++) { long p = primes.get(j); if(p>sqrt) break; if(i%p == 0) { prime = false; break; } } if(prime) { primes.add(i); squares.add(i*i); cubes.add(i*i*i); } } HashMap<Long,Pair> map = new HashMap<>(); ArrayList<Pair> pairs = new ArrayList<>(); for(int i = 0; i<n; i++) { long v = sc.nL(); if(map.containsKey(v)) { Pair p = map.get(v); p.a++; } else { Pair p = new Pair(v); map.put(v,p); pairs.add(p); } } HashMap<Long,Pair> map2 = new HashMap<>(); ArrayList<Pair> redpairs = new ArrayList<>(); for(Pair p: pairs) { long red = red(p.red); if(map2.contains(red)) { Pair pp = map2.get(red); pp.a += p.a; } else { Pair pp = new Pair(red); pp.a = p.a; map2.put(red,pp); redpairs.add(pp); } } Collections.sort(redpairs); HashSet<Long> set = new HashSet<>(); int picked = 0; for(Pair p:redpairs) { if(p.red == 1) { picked++; continue; } if(!set.contains(p.red)) { picked+=p.a; long inv = inv(p.red); if(inv != -1) { if(!set.contains(inv)) set.add(inv); } } } System.out.println(picked); } public static long inv(long v) { long ret = 1; for(int i = 0; i<primes.size() ; i++) { long p = primes.get(i); long sq = squares.get(i); if(sq>v) break; if(v%sq == 0) { ret *= p; v /= sq; } else if(v%p == 0) { ret *= sq; v /= p; } if(ret>10000000000L) return -1; } return (v>100000) ? -1 : ret*v*v; } public static long reduce(long v) { for(int i = 0; i<primes.size(); i++) { long cube = cubes.get(i); if(cube>v) break; while(v%cube == 0) { v /= cube; } } return v; } } class Sc { public Sc(InputStream i) { r = new BufferedReader(new InputStreamReader(i)); } public boolean hasM() { return peekToken() != null; } public int nI() { return Integer.parseInt(nextToken()); } public double nD() { return Double.parseDouble(nextToken()); } public long nL() { return Long.parseLong(nextToken()); } public String n() { return nextToken(); } private BufferedReader r; private String line; private StringTokenizer st; private String token; private String peekToken() { if (token == null) try { while (st == null || !st.hasMoreTokens()) { line = r.readLine(); if (line == null) return null; st = new StringTokenizer(line); } token = st.nextToken(); } catch (IOException e) { } return token; } private String nextToken() { String ans = peekToken(); token = null; return ans; } }
Main.java:73: error: illegal character: '\u00a0' if(map2.contains(red))?{ ^ Main.java:76: error: 'else' without 'if' } else { ^ 2 errors
s923179776
p04022
Java
import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.OutputStream; import java.util.HashMap; import java.util.HashSet; import java.util.ArrayList; import java.util.Collections; public class Main { public static ArrayList<Long> primes = new ArrayList<>(); private static class Pair implements Comparable<Pair> { long red; int a; public Pair(long v) { red = v; a = 1; } public int compareTo(Pair p) { return p.a-a; } } public static void main(String args[]) { Sc sc = new Sc(System.in); int n = sc.nI(); HashMap<Long,Pair> map = new HashMap<>(); ArrayList<Pair> pairs = new ArrayList<>(); primes.add(2L); for(long i = 3; i<=100000; i+=2) { long sqrt = (long) Math.sqrt(i); boolean prime = true; for(int j = 1; j<primes.size(); j++) { long p = primes.get(j); if(p>sqrt) break; if(i%p == 0) { prime = false; break; } } if(prime) primes.add(i); } for(int i = 0; i<n; i++) { long v = reduce(sc.nL()); if(map.containsKey(v)) { Pair p = map.get(v); p.a++; } else { Pair p = new Pair(v); map.put(v,p); pairs.add(p); } } Collections.sort(pairs); HashSet<Long> set = new HashSet<>(); int picked = 0; boolean pickedc = false; for(Pair p:pairs) { if(p.red == 1) { if(!pickedc) picked++; pickedc = true; continue; } if(!set.contains(p.red)) { picked+=p.a; long inv = inv(p.red); if(inv != -1) { if(!set.contains(inv)) set.add(inv); } } } System.out.println(picked); public static long inv(long v) { long ret = 1; for(int i = 0; i<primes.size() ; i++) { long p = primes.get(i); long sq = p*p; if(sq>v) break; if(v%sq == 0) { ret *= p; v /= sq; } else if(v%p == 0) { ret *= sq; v /= p; } if(ret>10000000000L) return -1; } return (v>100000) ? -1 : ret*v*v; } public static long reduce(long v) { for(int i = 0; i<primes.size(); i++) { long p = primes.get(i); long cube = p*p*p; if(cube>v) break; while(v%cube == 0) { v /= cube; } } return v; } } class Sc { public Sc(InputStream i) { r = new BufferedReader(new InputStreamReader(i)); } public boolean hasM() { return peekToken() != null; } public int nI() { return Integer.parseInt(nextToken()); } public double nD() { return Double.parseDouble(nextToken()); } public long nL() { return Long.parseLong(nextToken()); } public String n() { return nextToken(); } private BufferedReader r; private String line; private StringTokenizer st; private String token; private String peekToken() { if (token == null) try { while (st == null || !st.hasMoreTokens()) { line = r.readLine(); if (line == null) return null; st = new StringTokenizer(line); } token = st.nextToken(); } catch (IOException e) { } return token; } private String nextToken() { String ans = peekToken(); token = null; return ans; } }
Main.java:78: error: illegal start of expression public static long inv(long v) { ^ 1 error
s324740225
p04022
C++
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<n;i++) #define rep(i,n) for(int i=0;i<n;i++) #define INF 1<<29 #define LINF LLONG_MAX/3 #define MP make_pair #define PB push_back #define EB emplace_back #define ALL(v) (v).begin(),(v).end() #define debug(x) cerr<<#x<<":"<<x<<endl #define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; } typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<vi> vvi; #define MAX_P 100000 ll N; vector<ll> primes; map<ll,ll> prime2; void getPrime(ll n){ vector<bool> p(n+10,true); for(ll i=2;i<=n;i++){ if(!p[i]) continue; if(p[i]) primes.push_back(i); for(ll j=2;i*j<=n;j++) p[i*j] = false; } } int main(){ bool f=false; getPrime(MAX_P+10); for(ll p : primes) prime2[p*p]=p; cin>>N; vector<ll> S(N); for(int i=0;i<N;i++) cin>>S[i]; // Norm[t] : Norm(t) // NN[t] : Norm(t) の個数 // Pair[t] : Pair(t) map<ll,ll> Norm,NN,Pair; for(int i=0;i<N;i++){ ll s = S[i]; ll n = 1; // norm(s) ll r = 1; // pair(s) for(ll p : primes){ if(p>s) break; ll cnt=0; ll x=0; while(s%p==0){ x++; assert(x<100); cnt++; s/=p; } cnt%=3; if(cnt==1){ n *= p; r *= p*p; }else if(cnt==2){ n *= p*p; r *= p; } } if(s > 1){ if(prime2.count(s)){ //sは素数の2乗 n *= s; r *= prime2[s]; }else{ n *= s; r *= s*s; } } NN[n]++; Norm[S[i]]=n; Pair[S[i]]=r; if(n==1){ assert(n==p); } if(n==1) f=true; } ll ans = 0; if(f) ans++; map<ll,bool> used; for(int i=0;i<N;i++){ ll n = Norm[S[i]]; ll p = Pair[S[i]]; if(n==1) continue; if(used[n]){ if(used[p]) continue; ans += NN[p]; }else if(used[p]){ if(used[n]) continue; ans += NN[n]; }else{ if(NN[n] >= NN[p]){ ans += NN[n]; }else{ ans += NN[p]; } } used[n]=used[p]=true; } cout << ans << endl; }
In file included from /usr/include/c++/14/cassert:44, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:106, from a.cc:1: a.cc: In function 'int main()': a.cc:92:23: error: 'p' was not declared in this scope 92 | assert(n==p); | ^
s874061555
p04022
C++
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<n;i++) #define rep(i,n) for(int i=0;i<n;i++) #define INF 1<<29 #define LINF LLONG_MAX/3 #define MP make_pair #define PB push_back #define EB emplace_back #define ALL(v) (v).begin(),(v).end() #define debug(x) cerr<<#x<<":"<<x<<endl #define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; } typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<vi> vvi; #define MAX_P 3000 ll N; vector<ll> primes; map<ll,ll> prime2; void getPrime(ll n){ vector<bool> p(n+10,true); for(ll i=2;i<=n;i++){ if(!p[i]) continue; if(p[i]) primes.push_back(i); for(ll j=2;i*j<=n;j++) p[i*j] = false; } } int main(){ bool f=false; getPrime(MAX_P); for(ll p : primes) prime2[p*p]=p; cin>>N; vector<ll> S(N); for(int i=0;i<N;i++) cin>>S[i]; // Norm[t] : Norm(t) // NN[t] : Norm(t) の個数 // Pair[t] : Pair(t) map<ll,ll> Norm,NN,Pair; for(int i=0;i<N;i++){ ll s = S[i]; ll n = 1; // norm(s) ll r = 1; // pair(s) for(ll p : primes){ if(p>s) break; ll cnt=0; ll x=0; while(s%p==0){ x++; assert(x<100); cnt++; s/=p; } cnt%=3; if(cnt==1){ n *= p; r *= p*p; }else if(cnt==2){ n *= p*p; r *= p; } } if(s > 1){ if(prime2.count(s)){ //sは素数の2乗 n *= s; r *= prime2[s]; }else{ n *= s; r *= s*s; } } NN[n]++; Norm[S[i]]=n; Pair[S[i]]=r; if(n==1){ assert(n==p); } if(n==1) f=true; } ll ans = 0; if(f) ans++; map<ll,bool> used; for(int i=0;i<N;i++){ ll n = Norm[S[i]]; ll p = Pair[S[i]]; if(n==1) continue; if(used[n]){ if(used[p]) continue; ans += NN[p]; }else if(used[p]){ if(used[n]) continue; ans += NN[n]; }else{ if(NN[n] >= NN[p]){ ans += NN[n]; }else{ ans += NN[p]; } } used[n]=used[p]=true; } cout << ans << endl; }
In file included from /usr/include/c++/14/cassert:44, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:106, from a.cc:1: a.cc: In function 'int main()': a.cc:92:23: error: 'p' was not declared in this scope 92 | assert(n==p); | ^
s607684663
p04022
C++
#include <iostream> #include <queue> #include <map> #include <list> #include <vector> #include <string> #include <stack> #include <limits> #include <cassert> #include <fstream> #include <cstring> #include <bitset> #include <iomanip> #include <algorithm> #include <functional> #include <cstdio> #include <ciso646> using namespace std; #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) for (int i=0;i<(n);i++) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #define inf 0x3f3f3f3f #define INF INT_MAX/3 #define PB push_back #define MP make_pair #define ALL(a) (a).begin(),(a).end() #define SET(a,c) memset(a,c,sizeof a) #define CLR(a) memset(a,0,sizeof a) #define pii pair<int,int> #define pcc pair<char,char> #define pic pair<int,char> #define pci pair<char,int> #define VS vector<string> #define VI vector<int> #define DEBUG(x) cout<<#x<<": "<<x<<endl #define MIN(a,b) (a>b?b:a) #define MAX(a,b) (a>b?a:b) #define pi 2*acos(0.0) #define INFILE() freopen("in0.txt","r",stdin) #define OUTFILE()freopen("out0.txt","w",stdout) #define in scanf #define out printf #define ll long long #define ull unsigned long long #define eps 1e-14 #define FST first #define SEC second class prime { private: public: std::vector<ull> primes; std::vector<bool> isPrime; prime(ull num) { isPrime.resize(num + 1); fill(isPrime.begin(), isPrime.end(), true); ull ma = sqrt(num) + 1; isPrime[0] = isPrime[1] = false; ull cnt = 0; for (ull i = 2; i <= ma; ++i) if (isPrime[i]) { for (ull j = 2; i*j <= num; ++j) { isPrime[i*j] = false; cnt++; } } primes.reserve(cnt); for (ull i = 0; i<isPrime.size(); ++i) if (isPrime[i]) { primes.push_back(i); } } bool IsPrime(ull num) { if (num < isPrime.size()) return isPrime[num]; for (auto p : primes) { if (num%p == 0) return false; } ull ma = sqrt(num) + 1; for (ull i = primes.back(); i <= ma; i += 2) { if (num%i == 0) return false; } return true; } std::vector<ull> GetFactor(ull num) { std::vector<ull> res; ull ma = sqrt(num) + 1; ull sma = std::min(ma, (ull)isPrime.size() - 1); while (num != 1) { for (auto a : primes) { if (num % a == 0) { res.push_back(a); num /= a; } } break; } assert(num); return res; } std::map<ull, ull> GetFactorMap(ull num) { std::map<ull, ull> res; ull ma = sqrt(num) + 1; ull sma = std::min(ma, (ull)isPrime.size() - 1); ull index = 0; while (num >= primes[index]*primes[index]) { ull a = primes[index]; if (num%a == 0) { res[a]++; num /= a; } else { ++index; } } if (num != 1) res[num]++; return res; } }; int main() { int N; cin >> N; prime p(sqrt(1e10)); vector<ull> S(N); for (auto &a : S) cin >> a; int res = 0; map<ull, pair<ull, ull> > cnt; //first: norm, second: pair for (auto &s : S) { auto fac = p.GetFactorMap(s); ull norm = 1, pair = 1; for (auto f : fac) { int n = f.first; int c = f.second % 3; if (c == 1) { norm *= n; pair *= n*n; } else if (c == 2) { norm *= n*n; pair *= n; } } if (norm == 1) res = 1; else { if (norm < pair) cnt[norm].first++; else cnt[pair].second++; } } for (auto c : cnt) { res += max(c.second.first, c.second.second); } cout << res << endl; return 0; }
a.cc: In constructor 'prime::prime(long long unsigned int)': a.cc:61:26: error: 'sqrt' was not declared in this scope 61 | ull ma = sqrt(num) + 1; | ^~~~ a.cc: In member function 'bool prime::IsPrime(long long unsigned int)': a.cc:81:26: error: 'sqrt' was not declared in this scope 81 | ull ma = sqrt(num) + 1; | ^~~~ a.cc: In member function 'std::vector<long long unsigned int> prime::GetFactor(long long unsigned int)': a.cc:90:26: error: 'sqrt' was not declared in this scope 90 | ull ma = sqrt(num) + 1; | ^~~~ a.cc: In member function 'std::map<long long unsigned int, long long unsigned int> prime::GetFactorMap(long long unsigned int)': a.cc:107:26: error: 'sqrt' was not declared in this scope 107 | ull ma = sqrt(num) + 1; | ^~~~ a.cc: In function 'int main()': a.cc:127:17: error: 'sqrt' was not declared in this scope 127 | prime p(sqrt(1e10)); | ^~~~
s518532184
p04022
C++
#include <iostream> #include <vector> #include <algorithm> #include <queue> #include <stack> #include <tuple> #include <set> #include <map> #include <string> #include <iomanip> // #include <cmath> #include <cassert> using namespace std; typedef __int128_t ll; const int MAX_SIZE = 4000; bool isprime[MAX_SIZE]; vector<ll> prime_num; vector<ll> squered; vector<ll> cubed; // const ll infty = 10000000010; void init() { fill(isprime, isprime+MAX_SIZE, true); isprime[0] = isprime[1] = false; for (auto i=2; i<MAX_SIZE; i++) { if (isprime[i]) { ll x = i; prime_num.push_back(x); squered.push_back(x*x); cubed.push_back(x*x*x); for (auto j=2; i*j<MAX_SIZE; j++) { isprime[i*j] = false; } } } } bool prime(long long x) { // 2 \leq x \leq MAX_SIZE^2 if (x < MAX_SIZE) { return isprime[x]; } for (auto e : prime_num) { if (x%e == 0) return false; } return true; } int N; ll s[100010]; map<ll, int> M; ll conj(ll k) { ll l = k; ll A = 1; ll B = 1; for (auto x : prime_num) { int t = 0; while (l % x == 0) { l /= x; t++; } if (t == 1) { A *= x; } else if (t == 2) { B *= x; } } ll red = k / (A * B * B); ll sq = sqrt(red); long long t = static_cast<long long>(sq); t = floor(t); // cerr << "red = " << red << " , sq = " << sq << endl; if (red == t * t) { B *= red; } else { A *= red; } return A * A * B; } int main() { init(); cin >> N; int ans = 0; for (auto i = 0; i < N; i++) { cin >> s[i]; for (auto x : cubed) { while (s[i]%x == 0) s[i] /= x; } if (M.find(s[i]) == M.end()) { M[s[i]] = 1; } else { M[s[i]]++; } } for (auto x : M) { ll k = x.first; int num = x.second; // cerr << k << " " << num << endl; if (k == 1 && num > 0) { ans += 1; continue; } ll c = conj(k); // cerr << "conj(" << k << ") = " << c << endl; if (M.find(c) == M.end()) { ans += num; } else { ans += max(num, M[c]); M[k] = 0; M[c] = 0; } } cout << ans << endl; }
a.cc: In function 'll conj(ll)': a.cc:73:11: error: 'sqrt' was not declared in this scope; did you mean 'sq'? 73 | ll sq = sqrt(red); | ^~~~ | sq a.cc:75:7: error: 'floor' was not declared in this scope 75 | t = floor(t); | ^~~~~ a.cc: In function 'int main()': a.cc:90:9: error: no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'll' {aka '__int128'}) 90 | cin >> s[i]; | ~~~ ^~ ~~~~ | | | | | ll {aka __int128} | std::istream {aka std::basic_istream<char>} In file included from /usr/include/c++/14/iostream:42, from a.cc:1: /usr/include/c++/14/istream:170:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match) 170 | operator>>(bool& __n) | ^~~~~~~~ /usr/include/c++/14/istream:170:7: note: conversion of argument 1 would be ill-formed: a.cc:90:15: error: cannot bind non-const lvalue reference of type 'bool&' to a value of type 'll' {aka '__int128'} 90 | cin >> s[i]; | ~~~^ /usr/include/c++/14/istream:174:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match) 174 | operator>>(short& __n); | ^~~~~~~~ /usr/include/c++/14/istream:174:7: note: conversion of argument 1 would be ill-formed: a.cc:90:15: error: cannot bind non-const lvalue reference of type 'short int&' to a value of type 'll' {aka '__int128'} 90 | cin >> s[i]; | ~~~^ /usr/include/c++/14/istream:177:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match) 177 | operator>>(unsigned short& __n) | ^~~~~~~~ /usr/include/c++/14/istream:177:7: note: conversion of argument 1 would be ill-formed: a.cc:90:15: error: cannot bind non-const lvalue reference of type 'short unsigned int&' to a value of type 'll' {aka '__int128'} 90 | cin >> s[i]; | ~~~^ /usr/include/c++/14/istream:181:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match) 181 | operator>>(int& __n); | ^~~~~~~~ /usr/include/c++/14/istream:181:7: note: conversion of argument 1 would be ill-formed: a.cc:90:15: error: cannot bind non-const lvalue reference of type 'int&' to a value of type 'll' {aka '__int128'} 90 | cin >> s[i]; | ~~~^ /usr/include/c++/14/istream:184:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match) 184 | operator>>(unsigned int& __n) | ^~~~~~~~ /usr/include/c++/14/istream:184:7: note: conversion of argument 1 would be ill-formed: a.cc:90:15: error: cannot bind non-const lvalue reference of type 'unsigned int&' to a value of type 'll' {aka '__int128'} 90 | cin >> s[i]; | ~~~^ /usr/include/c++/14/istream:188:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match) 188 | operator>>(long& __n) | ^~~~~~~~ /usr/include/c++/14/istream:188:7: note: conversion of argument 1 would be ill-formed: a.cc:90:15: error: cannot bind non-const lvalue reference of type 'long int&' to a value of type 'll' {aka '__int128'} 90 | cin >> s[i]; | ~~~^ /usr/include/c++/14/istream:192:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match) 192 | operator>>(unsigned long& __n) | ^~~~~~~~ /usr/include/c++/14/istream:192:7: note: conversion of argument 1 would be ill-formed: a.cc:90:15: error: cannot bind non-const lvalue reference of type 'long unsigned int&' to a value of type 'll' {aka '__int128'} 90 | cin >> s[i]; | ~~~^ /usr/include/c++/14/istream:199:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match) 199 | operator>>(long long& __n) | ^~~~~~~~ /usr/include/c++/14/istream:199:7: note: conversion of argument 1 would be ill-formed: a.cc:90:15: error: cannot bind non-const lvalue reference of type 'long long int&' to a value of type 'll' {aka '__int128'} 90 | cin >> s[i]; | ~~~^ /usr/include/c++/14/istream:203:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match) 203 | operator>>(unsigned long long& __n) | ^~~~~~~~ /usr/include/c++/14/istream:203:7: note: conversion of argument 1 would be ill-formed: a.cc:90:15: error: cannot bind non-const lvalue reference of type 'long long unsigned int&' to a value of type 'll' {aka '__int128'} 90 | cin >> s[i]; | ~~~^ /usr/include/c++/14/istream:219:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match) 219 | operator>>(float& __f) | ^~~~~~~~ /usr/include/c++/14/istream:219:7: note: conversion of argument 1 would be ill-formed: a.cc:90:15: error: cannot bind non-const lvalue reference of type 'float&' to a value of type 'll' {aka '__int128'} 90 | cin >> s[i]; | ~~~^ /usr/include/c++/14/istream:223:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match) 223 | operator>>(double& __f) | ^~~~~~~~ /usr/include/c++/14/istream:223:7: note: conversion of argument 1 would be ill-formed: a.cc:90:15: error: cannot bind non-const lvalue reference of type 'double&' to a value of type 'll' {aka '__int128'} 90 | cin >> s[i]; | ~~~^ /usr/include/c++/14/istream:227:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match) 227 | operator>>(long double& __f) | ^~~~~~~~ /usr/include/c++/14/istream:227:7: note: conversion of argument 1 would be ill-formed: a.cc:90:15: error: cannot bind non-const lvalue reference of type 'long double&' to a value of type 'll' {aka '__int128'} 90 | cin >> s[i]; | ~~~^ /usr/include/c++/14/istream:328:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match) 328 | operator>>(void*& __p) | ^~~~~~~~ /usr/include/c++/14/istream:328:7: note: conversion of argument 1 would be ill-formed: a.cc:90:15: error: invalid conversion from 'll' {aka '__int128'} to 'void*' [-fpermissive] 90 | cin >> s[i]; | ~~~^ | | | ll {aka __int128} a.cc:90:15: error: cannot bind rvalue '(void*)((long int)s[i])' to 'void*&' /usr/include/c++/14/istream:122:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(__istream_type& (*)(__istream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match) 122 | operator>>(__istream_type& (*__pf)(__istream_type&)) | ^~~~~~~~ /usr/include/c++/14/istream:122:7: note: conversion of argument 1 would be ill-formed: a.cc:90:15: error: invalid conversion from 'll' {aka '__int128'} to 'std::basic_istream<char>::__istream_type& (*)(std::basic_istream<char>::__istream_type&)' {aka 'std::basic_istream<char>& (*)(std::basic_istream<char>&)'} [-fpermissive] 90 | cin >> s[i]; | ~~~^ | | | ll {aka __int128} /usr/include/c++/14/istream:126:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>; __ios_type = std::basic_ios<char>]' (near match) 126 | operator>>(__ios_type& (*__pf)(__ios_type&)) | ^~~~~~~~ /usr/include/c++/14/istream:126:7: note: conversion of argument 1 would be ill-formed: a.cc:90:15: error: invalid conversion from 'll' {aka '__int128'} to 'std::basic_istream<char>::__ios_type& (*)(std::basic_istream<char>::__ios_type&)' {aka 'std::basic_ios<char>& (*)(std::basic_ios<char>&)'} [-fpermissive] 90 | cin >> s[i]; | ~~~^ | | | ll {aka __int128} /usr/include/c++/14/istream:133:7: no
s952283939
p04022
C++
#include <iostream> #include <vector> #include <algorithm> #include <queue> #include <stack> #include <tuple> #include <set> #include <map> #include <string> #include <iomanip> // #include <cmath> #include <cassert> using namespace std; typedef int128_t ll; const int MAX_SIZE = 4000; bool isprime[MAX_SIZE]; vector<ll> prime_num; vector<ll> squered; vector<ll> cubed; // const ll infty = 10000000010; void init() { fill(isprime, isprime+MAX_SIZE, true); isprime[0] = isprime[1] = false; for (auto i=2; i<MAX_SIZE; i++) { if (isprime[i]) { ll x = i; prime_num.push_back(x); squered.push_back(x*x); cubed.push_back(x*x*x); for (auto j=2; i*j<MAX_SIZE; j++) { isprime[i*j] = false; } } } } bool prime(long long x) { // 2 \leq x \leq MAX_SIZE^2 if (x < MAX_SIZE) { return isprime[x]; } for (auto e : prime_num) { if (x%e == 0) return false; } return true; } int N; ll s[100010]; map<ll, int> M; ll conj(ll k) { ll l = k; ll A = 1; ll B = 1; for (auto x : prime_num) { int t = 0; while (l % x == 0) { l /= x; t++; } if (t == 1) { A *= x; } else if (t == 2) { B *= x; } } ll red = k / (A * B * B); ll sq = sqrt(red); long long t = static_cast<long long>(sq); t = floor(t); // cerr << "red = " << red << " , sq = " << sq << endl; if (red == t * t) { B *= red; } else { A *= red; } return A * A * B; } int main() { init(); cin >> N; int ans = 0; for (auto i = 0; i < N; i++) { cin >> s[i]; for (auto x : cubed) { while (s[i]%x == 0) s[i] /= x; } if (M.find(s[i]) == M.end()) { M[s[i]] = 1; } else { M[s[i]]++; } } for (auto x : M) { ll k = x.first; int num = x.second; // cerr << k << " " << num << endl; if (k == 1 && num > 0) { ans += 1; continue; } ll c = conj(k); // cerr << "conj(" << k << ") = " << c << endl; if (M.find(c) == M.end()) { ans += num; } else { ans += max(num, M[c]); M[k] = 0; M[c] = 0; } } cout << ans << endl; }
a.cc:16:9: error: 'int128_t' does not name a type; did you mean 'int8_t'? 16 | typedef int128_t ll; | ^~~~~~~~ | int8_t a.cc:20:8: error: 'll' was not declared in this scope 20 | vector<ll> prime_num; | ^~ a.cc:20:10: error: template argument 1 is invalid 20 | vector<ll> prime_num; | ^ a.cc:20:10: error: template argument 2 is invalid a.cc:21:8: error: 'll' was not declared in this scope 21 | vector<ll> squered; | ^~ a.cc:21:10: error: template argument 1 is invalid 21 | vector<ll> squered; | ^ a.cc:21:10: error: template argument 2 is invalid a.cc:22:8: error: 'll' was not declared in this scope 22 | vector<ll> cubed; | ^~ a.cc:22:10: error: template argument 1 is invalid 22 | vector<ll> cubed; | ^ a.cc:22:10: error: template argument 2 is invalid a.cc: In function 'void init()': a.cc:31:7: error: 'll' was not declared in this scope 31 | ll x = i; | ^~ a.cc:32:17: error: request for member 'push_back' in 'prime_num', which is of non-class type 'int' 32 | prime_num.push_back(x); | ^~~~~~~~~ a.cc:32:27: error: 'x' was not declared in this scope 32 | prime_num.push_back(x); | ^ a.cc:33:15: error: request for member 'push_back' in 'squered', which is of non-class type 'int' 33 | squered.push_back(x*x); | ^~~~~~~~~ a.cc:34:13: error: request for member 'push_back' in 'cubed', which is of non-class type 'int' 34 | cubed.push_back(x*x*x); | ^~~~~~~~~ a.cc: In function 'bool prime(long long int)': a.cc:46:17: error: 'begin' was not declared in this scope; did you mean 'std::begin'? 46 | for (auto e : prime_num) { | ^~~~~~~~~ | std::begin In file included from /usr/include/c++/14/string:53, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here 114 | template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept; | ^~~~~ a.cc:46:17: error: 'end' was not declared in this scope; did you mean 'std::end'? 46 | for (auto e : prime_num) { | ^~~~~~~~~ | std::end /usr/include/c++/14/bits/range_access.h:116:37: note: 'std::end' declared here 116 | template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept; | ^~~ a.cc: At global scope: a.cc:53:1: error: 'll' does not name a type 53 | ll s[100010]; | ^~ a.cc:54:5: error: 'll' was not declared in this scope 54 | map<ll, int> M; | ^~ a.cc:54:12: error: template argument 1 is invalid 54 | map<ll, int> M; | ^ a.cc:54:12: error: template argument 3 is invalid a.cc:54:12: error: template argument 4 is invalid a.cc:56:1: error: 'll' does not name a type 56 | ll conj(ll k) { | ^~ a.cc: In function 'int main()': a.cc:90:12: error: 's' was not declared in this scope 90 | cin >> s[i]; | ^ a.cc:91:19: error: 'begin' was not declared in this scope; did you mean 'std::begin'? 91 | for (auto x : cubed) { | ^~~~~ | std::begin /usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here 114 | template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept; | ^~~~~ a.cc:91:19: error: 'end' was not declared in this scope; did you mean 'std::end'? 91 | for (auto x : cubed) { | ^~~~~ | std::end /usr/include/c++/14/bits/range_access.h:116:37: note: 'std::end' declared here 116 | template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept; | ^~~ a.cc:94:11: error: request for member 'find' in 'M', which is of non-class type 'int' 94 | if (M.find(s[i]) == M.end()) { | ^~~~ a.cc:94:27: error: request for member 'end' in 'M', which is of non-class type 'int' 94 | if (M.find(s[i]) == M.end()) { | ^~~ a.cc:100:17: error: 'begin' was not declared in this scope; did you mean 'std::begin'? 100 | for (auto x : M) { | ^ | std::begin /usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here 114 | template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept; | ^~~~~ a.cc:100:17: error: 'end' was not declared in this scope; did you mean 'std::end'? 100 | for (auto x : M) { | ^ | std::end /usr/include/c++/14/bits/range_access.h:116:37: note: 'std::end' declared here 116 | template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept; | ^~~ a.cc:101:5: error: 'll' was not declared in this scope 101 | ll k = x.first; | ^~ a.cc:104:9: error: 'k' was not declared in this scope 104 | if (k == 1 && num > 0) { | ^ a.cc:108:7: error: expected ';' before 'c' 108 | ll c = conj(k); | ^~ | ; a.cc:110:11: error: request for member 'find' in 'M', which is of non-class type 'int' 110 | if (M.find(c) == M.end()) { | ^~~~ a.cc:110:16: error: 'c' was not declared in this scope 110 | if (M.find(c) == M.end()) { | ^ a.cc:110:24: error: request for member 'end' in 'M', which is of non-class type 'int' 110 | if (M.find(c) == M.end()) { | ^~~ a.cc:114:9: error: 'k' was not declared in this scope 114 | M[k] = 0; | ^
s422507708
p04022
C++
#include <iostream> #include <cassert> #include <algorithm> #include <cstdlib> #include <cstdio> #include <vector> #include <set> #include <map> #include <iomanip> #include <math.h> #include <unordered_map> #include <unordered_set> #include <queue> #include <fstream> #define REP(i, n) for (int i = 0; i < n; ++i) #define FOR(i, a, b) for (int i = a; i < b; ++i) #define DB(x) cerr << #x << ": " << x << endl; #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; typedef long long LL; typedef long double LD; typedef pair<int, int> pii; const int MAXN = 100000; const int MOD = 1000 * 1000 * 1000 + 7; void solve(); int main() { auto start = clock(); cout.sync_with_stdio(0); cin.tie(0); cout.precision(10); cout << fixed; #ifdef HOME //freopen("input.txt", "r", stdin); freopen("biginput.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif int t = 1; //cin >> t; while (t--) { solve(); } cerr << "\nTime: " << (clock() - start) / 1.0 / CLOCKS_PER_SEC << "\n"; return 0; } vector<int> genPrimes(int upperBound) { vector<int> primes; vector<char> sieved(upperBound, false); for (int i = 2; i < upperBound; ++i) { if (!sieved[i]) { primes.pb(i); for (int j = 2 * i; j < upperBound; j += i) { sieved[j] = true; } } } return primes; } const int MAXP = 100000; LL myPow(LL base, int val) { if (val == 0) { return 1; } if (val == 1) { return base; } if (val == 2) { return base * base; } return -1; } LL MAXPATTERN = 100000LL * 100000LL; void gen(int size) { ofstream ofs("biginput.txt"); ofs << size << endl; REP(i, size) { ofs << MAXPATTERN - size + i + 1 << endl; } } void solve() { //gen(100000); //return; int n; cin >> n; vector<LL> s(n); REP(i, n) { cin >> s[i]; } auto primes = genPrimes(MAXP + 10); unordered_map<LL, int> counts; unordered_map<LL, LL> antiMap; int ans = 0; REP(i, n) { LL pattern = 1; LL antiPattern = 1; for (int p : primes) { int cnt = 0; while (s[i] % p == 0) { ++cnt; s[i] /= p; } cnt %= 3; pattern *= myPow(p, cnt); antiPattern *= myPow(p, (3 - cnt) % 3); assert(pattern > 0); assert(antiPattern > 0); if (antiPattern > MAXPATTERN) { break; } if (s[i] == 1) { break; } if (p > 2200) { LL x = sqrtl(s[i]) - 10; while (x * x < s[i]) { ++x; } if (x * x == s[i]) { pattern *= myPow(x, 2); antiPattern *= myPow(x, 1); s[i] /= x * x; } break; } } if (s[i] != 1 || antipattern > MAXPATTERN) { ++ans; } else { assert(pattern > 0); assert(antiPattern > 0); ++counts[pattern]; antiMap[pattern] = antiPattern; antiMap[antiPattern] = pattern; } } for (const auto& p : antiMap) { auto pattern = p.first; auto antiPattern = p.second; if (pattern > antiPattern) { continue; } if (pattern == antiPattern) { ans += min(counts[pattern], 1); } else { ans += max(counts[pattern], counts[antiPattern]); } } cout << ans << endl; }
a.cc: In function 'void solve()': a.cc:153:26: error: 'antipattern' was not declared in this scope; did you mean 'antiPattern'? 153 | if (s[i] != 1 || antipattern > MAXPATTERN) { | ^~~~~~~~~~~ | antiPattern
s342139391
p04022
C++
jinclude <bits/stdc++.h> using namespace std; typedef long long LL; typedef double DB; #define F(i,a,b) for(int i=(a);i<=(b);++i) #define R(i,n) for(int i=0;i<(n);++i) #define fill(a,b) memset(a,b,sizeof(a)) #define fi first #define se second const LL INF = 1e10 + 7; int n,tot; map<LL,int> cnt; map<LL,LL> cp; LL p[4][3000]; void init() { tot = 0; for(int i=2;;++i) { if(1LL*i*i*i >= INF) break; if(p[0][i]) continue; p[1][tot] = i; p[2][tot] = i*i; p[3][tot++] = 1LL*i*i*i; for(int j=i;;j+=i) { if(1LL*j*j*j >= INF) break; p[0][j] = 1; } } } int main() { //freopen("test.txt","r",stdin); init(); scanf("%d",&n); int ans = 0,fi = 1; R(i,n) { LL s,x,y; scanf("%lld",&s); x = y = 1; R(j,tot) { while(s%p[3][j] == 0) { s /= p[3][j]; } if(s%p[2][j] == 0) { x *= p[2][j]; y *= p[1][j]; if(y > INF) y = INF; } else if(s%p[1][j] == 0) { x *= p[1][j]; y *= p[2][j]; if(y > INF) y = INF; } } s /= x; if(s != 1) { int t = sqrt(s),r = -1; F(j,max(1,t-1),t+1) if(1LL*j*j == s) { r = j; break; } if(r != -1) { if(y < INF) y *= r; } else { if(INF/s/s < y) y = INF; else y *= 1LL*s*s; } } if(y >= INF) { ++ans; continue; } s *= x; if(s == 1) { if(fi) { fi = 0; ++ans; } continue; } cnt[s]++; cp[s] = y; } for(auto it = cnt.begin();it != cnt.end(); ++it) { LL gf = cp[it->fi]; if(it->fi < gf || cnt.find(gf) == cnt.end()) ans += max(it -> se,cnt[gf]); } printf("%d\n",ans); return 0; }
a.cc:1:1: error: 'jinclude' does not name a type 1 | jinclude <bits/stdc++.h> | ^~~~~~~~ a.cc:15:1: error: 'map' does not name a type 15 | map<LL,int> cnt; | ^~~ a.cc:16:1: error: 'map' does not name a type 16 | map<LL,LL> cp; | ^~~ a.cc: In function 'int main()': a.cc:41:9: error: 'scanf' was not declared in this scope 41 | scanf("%d",&n); | ^~~~~ a.cc:71:33: error: 'sqrt' was not declared in this scope 71 | int t = sqrt(s),r = -1; | ^~~~ a.cc:72:29: error: 'max' was not declared in this scope 72 | F(j,max(1,t-1),t+1) | ^~~ a.cc:6:29: note: in definition of macro 'F' 6 | #define F(i,a,b) for(int i=(a);i<=(b);++i) | ^ a.cc:75:41: error: 'r' was not declared in this scope 75 | r = j; | ^ a.cc:78:28: error: 'r' was not declared in this scope 78 | if(r != -1) | ^ a.cc:106:17: error: 'cnt' was not declared in this scope; did you mean 'int'? 106 | cnt[s]++; | ^~~ | int a.cc:107:17: error: 'cp' was not declared in this scope; did you mean 'p'? 107 | cp[s] = y; | ^~ | p a.cc:109:23: error: 'cnt' was not declared in this scope; did you mean 'int'? 109 | for(auto it = cnt.begin();it != cnt.end(); ++it) | ^~~ | int a.cc:111:25: error: 'cp' was not declared in this scope; did you mean 'p'? 111 | LL gf = cp[it->fi]; | ^~ | p a.cc:112:69: error: 'max' was not declared in this scope 112 | if(it->fi < gf || cnt.find(gf) == cnt.end()) ans += max(it -> se,cnt[gf]); | ^~~ a.cc:114:9: error: 'printf' was not declared in this scope 114 | printf("%d\n",ans); | ^~~~~~ a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>' +++ |+#include <cstdio> 1 | jinclude <bits/stdc++.h>
s668063393
p04022
C++
#include <bits/stdc++.h> using namespace std; jypedef long long LL; typedef double DB; #define F(i,a,b) for(int i=(a);i<=(b);++i) #define R(i,n) for(int i=0;i<(n);++i) #define fill(a,b) memset(a,b,sizeof(a)) #define fi first #define se second const LL INF = 1e10 + 7; int n,tot; map<LL,int> cnt; map<LL,LL> cp; LL p[4][3010]; void init() { tot = 0; for(int i=2;;++i) { if(1LL*i*i*i >= INF) break; if(p[0][i]) continue; p[1][tot] = i; p[2][tot] = i*i; p[3][tot++] = 1LL*i*i*i; for(int j=i;;j+=i) { if(1LL*j*j*j >= INF) break; p[0][j] = 1; } } } int main() { //freopen("test.txt","r",stdin); init(); scanf("%d",&n); int ans = 0,fi = 1; R(i,n) { LL s,x,y; scanf("%lld",&s); x = y = 1; R(j,tot) { while(s%p[3][j] == 0) { s /= p[3][j]; } if(s%p[2][j] == 0) { x *= p[2][j]; y *= p[1][j]; if(y > INF) y = INF; } else if(s%p[1][j] == 0) { x *= p[1][j]; y *= p[2][j]; if(y > INF) y = INF; } if(x == s) break; } if(y >= INF) { ++ans; continue; } s /= x; if(s != 1) { int t = sqrt(s),r = -1; F(j,max(1,t-10),t+10) if(1LL*j*j == s) { r = j; break; } if(r != -1) { if(y < INF) y *= r; } else { if(INF/s/s < y) y = INF; else y *= 1LL*s*s; } } if(y >= INF) { ++ans; continue; } s *= x; if(s == 1) { if(fi) { fi = 0; ++ans; } continue; } cnt[s]++; cp[s] = y; } for(auto it = cnt.begin();it != cnt.end(); ++it) { int gf = cp[it->fi]; if(it->fi < gf || cnt.find(gf) == cnt.end()) ans += max(it -> se,cnt[gf]); } printf("%d\n",ans); return 0; }
a.cc:3:1: error: 'jypedef' does not name a type; did you mean 'typedef'? 3 | jypedef long long LL; | ^~~~~~~ | typedef a.cc:12:7: error: 'LL' does not name a type 12 | const LL INF = 1e10 + 7; | ^~ a.cc:15:5: error: 'LL' was not declared in this scope 15 | map<LL,int> cnt; | ^~ a.cc:15:11: error: template argument 1 is invalid 15 | map<LL,int> cnt; | ^ a.cc:15:11: error: template argument 3 is invalid a.cc:15:11: error: template argument 4 is invalid a.cc:16:5: error: 'LL' was not declared in this scope 16 | map<LL,LL> cp; | ^~ a.cc:16:8: error: 'LL' was not declared in this scope 16 | map<LL,LL> cp; | ^~ a.cc:16:10: error: template argument 1 is invalid 16 | map<LL,LL> cp; | ^ a.cc:16:10: error: template argument 2 is invalid a.cc:16:10: error: template argument 3 is invalid a.cc:16:10: error: template argument 4 is invalid a.cc:17:1: error: 'LL' does not name a type 17 | LL p[4][3010]; | ^~ a.cc: In function 'void init()': a.cc:24:33: error: 'INF' was not declared in this scope 24 | if(1LL*i*i*i >= INF) break; | ^~~ a.cc:25:20: error: 'p' was not declared in this scope 25 | if(p[0][i]) continue; | ^ a.cc:26:17: error: 'p' was not declared in this scope 26 | p[1][tot] = i; | ^ a.cc:31:41: error: 'INF' was not declared in this scope 31 | if(1LL*j*j*j >= INF) break; | ^~~ a.cc: In function 'int main()': a.cc:45:17: error: 'LL' was not declared in this scope 45 | LL s,x,y; | ^~ a.cc:46:31: error: 's' was not declared in this scope 46 | scanf("%lld",&s); | ^ a.cc:48:17: error: 'x' was not declared in this scope 48 | x = y = 1; | ^ a.cc:48:21: error: 'y' was not declared in this scope 48 | x = y = 1; | ^ a.cc:51:33: error: 'p' was not declared in this scope 51 | while(s%p[3][j] == 0) | ^ a.cc:55:30: error: 'p' was not declared in this scope 55 | if(s%p[2][j] == 0) | ^ a.cc:59:40: error: 'INF' was not declared in this scope 59 | if(y > INF) y = INF; | ^~~ a.cc:65:40: error: 'INF' was not declared in this scope 65 | if(y > INF) y = INF; | ^~~ a.cc:69:25: error: 'INF' was not declared in this scope 69 | if(y >= INF) | ^~~ a.cc:81:41: error: 'r' was not declared in this scope 81 | r = j; | ^ a.cc:84:28: error: 'r' was not declared in this scope 84 | if(r != -1) | ^ a.cc:86:40: error: 'INF' was not declared in this scope 86 | if(y < INF) y *= r; | ^~~ a.cc:90:36: error: 'INF' was not declared in this scope 90 | if(INF/s/s < y) y = INF; | ^~~ a.cc:94:25: error: 'INF' was not declared in this scope 94 | if(y >= INF) | ^~~ a.cc:115:27: error: request for member 'begin' in 'cnt', which is of non-class type 'int' 115 | for(auto it = cnt.begin();it != cnt.end(); ++it) | ^~~~~ a.cc:115:45: error: request for member 'end' in 'cnt', which is of non-class type 'int' 115 | for(auto it = cnt.begin();it != cnt.end(); ++it) | ^~~ a.cc:118:39: error: request for member 'find' in 'cnt', which is of non-class type 'int' 118 | if(it->fi < gf || cnt.find(gf) == cnt.end()) ans += max(it -> se,cnt[gf]); | ^~~~ a.cc:118:55: error: request for member 'end' in 'cnt', which is of non-class type 'int' 118 | if(it->fi < gf || cnt.find(gf) == cnt.end()) ans += max(it -> se,cnt[gf]); | ^~~ a.cc:118:85: error: invalid types 'int[int]' for array subscript 118 | if(it->fi < gf || cnt.find(gf) == cnt.end()) ans += max(it -> se,cnt[gf]); | ^
s189344819
p04022
C++
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define li long long #define itn int using namespace std; inline int nxt(){ int n; scanf("%d", &n); return n; } int gcd(int x, int y){ while (y){ x %= y; swap(x, y); } return x; } const int mod = 1000000007; long long pw(long long a, long long b){ long long res = 1; while (b){ if (b & 1ll) res = res * a % mod; b >>= 1; a = a * a % mod; } return res; } const int N = 111111; int pr[N]; inline long long myrand(){ return 1ll * RAND_MAX * rand() + rand(); } const int sz = 11000; pair<bitset<2 * sz>, int> h[N]; // bitset<2 * sz> heh; // inline bool ok(const bitset<2 * sz>& b){ // return ((b & heh) == ((b >> 1) & heh)); // } int main(){ for (int i = 2; i < N; i++){ if (pr[i] == 0){ pr[i] = i; if (1.0 * i * i < N + N){ for (int j = i * i; j < N; j += i){ if (pr[j] == 0){ pr[j] = i; } } } } } vector<int> primes; for (int i = 2; i < N; i++){ if (pr[i] == i){ primes.push_back(i); } } int n = nxt(); // vector<pair<vector<int>, int>> h(n); for (int i = 0; i < n; i++){ long long x; scanf("%lld", &x); int cnt = 0; if (x > 1){ for (int j = 0; j < primes.size(); j++){ int p = primes[j]; if (x % p == 0){ int c = 0; while (x % p == 0){ c++; x /= p; } c %= 3; if (c){ h[i].first[j] = 1; if (c == 1) h[i].second |= (1 << cnt); cnt++; } } } } if (x > 1){ h[i].first[primes.size()] = 1; } } // for (int i = 0; i < n; i++){ // cerr << "{"; // for (int j = 0; j < h[i].first.size(); j++){ // if (j) // cerr << ", "; // cerr << h[i].first[j]; // } // cerr << "}, "; // for (int j = 0; j < h[i].first.size(); j++){ // cerr << ((h[i].second & (1 << j)) ? "1" : "0"); // } // cerr << "\n"; // } // sort(all(h)); vector<int> ph(n); int pp = 0; for (int j = 0; j < sz; j++){ int l = 0; for (int i = 0; i < n; i++){ if (i == 0 || ph[i] != ph[i - 1]){ ++pp; while (l < i){ ph[l++] = pp; } } else { if (h[i].first[j] == 0){ swap(h[i], h[l++]); } } } } int ans = 0; int i = 0; if (h[0].first.count() == 0){ ans++; while (i < n && h[i].first.empty()) i++; } while (i < n){ int l = i; while (i < n && h[i].first == h[l].first) i++; int r = i - 1; int q = (1 << ((int)h[l].first.count())) - 1; while (l <= r){ if (h[l].second + h[r].second < q){ l++; ans++; } else if (h[l].second + h[r].second > q){ r--; ans++; } else { int c1 = 0, c2 = 0; int w = h[l].second; while (l < i && h[l].second == w){ c1++; l++; } while (r >= 0 && h[r].second == q - w){ c2++; r--; } ans += max(c1, c2); } } } printf("%d\n", ans); return 0; }
a.cc: In function 'int main()': a.cc:140:44: error: 'class std::bitset<22000>' has no member named 'empty' 140 | while (i < n && h[i].first.empty()) | ^~~~~
s436237057
p04022
C++
#include <cstdio> #include <cstring> #include <map> #include <queue> #include <utility> #include <vector> #define MEM(x, y) memset((x), (y), sizeof(x)) #define X first #define Y second typedef long long lld; typedef std::pair<int,int> pii; typedef std::vector<pii> vip; typedef std::priority_queue<pii, vip, std::greater<pii>> pq; const int INFN = 1E9+5; const int MAXM = 2E5+5; const lld MAXN = 1E10+5; // 2100^3 std::map<lld, int> count; std::map<lld, int> coord; int cntC=0, cntE=0, N; // Coord Compr, Edge Count lld tem; const int SRC=0, SNK=MAXM-1; int dista[MAXM]{ }; lld nxt[MAXM]{ }; int prv[MAXM]{ }; int queue[MAXM]{ }; int upper[MAXM]{ }; void addEdge(int U, int V, int W) { prv[cntE]=upper[U], nxt[cntE] = V, wei[cntE] = W, upper[U]=cntE++; prv[cntE]=upper[V], nxt[cntE] = U, wei[cntE] = 0, upper[V]=cntE++; } bool bfs() { pq queue; MEM(dista, 63); dista[SRC] = 0; queue.emplace(dista[SRC], SRC); while(!queue.empty()) { pii cur = queue[qtr[1]++]; if(dista[cur.Y] < cur.X) continue; for(int E = upper[cur]; ~E; E = prv[E]) if(wei[E] > 0) { lld tem = dista[cur.Y] + wei[E]; if(dista[nxt[E]] > tem) { dista[nxt[E]] = tem; queue.emplace(tem, nxt[E]); } } } return dista[SNK] < INFN; } int edmonds_karp() { while(bfs()) { memcpy(ptr, upper, sizeof(upper)); dfs(SRC); } } int main() { scanf("%d", &N); MEM(upper, -1); for(int i = 0; i < N; ++i) { scanf("%lld", &tem); coord[tem]=0; ++count[tem]; } for(auto& itr: count) { lld jtr=1LL; while(jtr*jtr*jtr < itr.X) ++jtr; while(jtr*jtr*jtr < MAXN) { coord[jtr*jtr*jtr] = 0; ++jtr; } } for(auto& itr: coord) // O(Ncbrt(10^10)) itr.Y = ++cntC; for(auto& itr: count) { addEdge(SRC, coord[itr.X], itr.Y); lld jtr = 1LL; while(jtr*jtr*jtr < itr.X) ++jtr; while(jtr*jtr*jtr < MAXN) { lld cube = jtr*jtr*jtr; addEdge(coord[itr.X], coord[cube], count[cube]); ++jtr; } } printf("%d\n", N-edmonds_karp()); return 0; }
a.cc: In function 'void addEdge(int, int, int)': a.cc:31:44: error: 'wei' was not declared in this scope 31 | prv[cntE]=upper[U], nxt[cntE] = V, wei[cntE] = W, upper[U]=cntE++; | ^~~ a.cc: In function 'bool bfs()': a.cc:43:33: error: 'qtr' was not declared in this scope 43 | pii cur = queue[qtr[1]++]; | ^~~ a.cc:45:34: error: no match for 'operator[]' (operand types are 'int [200005]' and 'pii' {aka 'std::pair<int, int>'}) 45 | for(int E = upper[cur]; ~E; E = prv[E]) if(wei[E] > 0) | ^ a.cc:45:60: error: 'wei' was not declared in this scope 45 | for(int E = upper[cur]; ~E; E = prv[E]) if(wei[E] > 0) | ^~~ a.cc: In function 'int edmonds_karp()': a.cc:62:24: error: 'ptr' was not declared in this scope 62 | memcpy(ptr, upper, sizeof(upper)); | ^~~ a.cc:63:17: error: 'dfs' was not declared in this scope; did you mean 'ffs'? 63 | dfs(SRC); | ^~~ | ffs a.cc:65:1: warning: no return statement in function returning non-void [-Wreturn-type] 65 | } | ^
s912648153
p04022
C++
#include<bits/stdc++.h> using namespace std; class Disjointset { public: vector<int> rank,p; Disjointset(){} Disjointset(int size){ rank.resize(size,0); p.resize(size,0); for(int i=0;i<size;i++) makeSet(i); } void makeSet(int x){ p[x]=x; rank[x]=0; } bool same(int x,int y){ return findSet(x)==findSet(y); } void unite(int x,int y){ link(findSet(x),findSet(y)); } void link(int x,int y){ if(rank[x]>rank[y]) { p[y]=x; }else { p[x]=y; if(rank[x]==rank[y]) rank[y]++; } } int findSet(int x){ if(x!=p[x]) p[x]=findSet(p[x]); return p[x]; } }; typedef long long ll; int main(){ int n; cin>>n; ll s[n]; ll i,j,k; for(i=0;i<n;i++) cin >> s[i]; Disjointset d=Disjointset(n); bool used[n]; fill(used,used+n,false); for(i=0;i<n;i++){ if(used[i]) continue; for(j=i+1;j<n;j++){ if(max(s[i],s[j])%min(s[i],s[j])) continue; k= powl(max(s[i],s[j])/min(s[i],s[j]),1.0/3); //cout << k << ":" << s[i]*s[j] << endl; if((k-1)*(k-1)*(k-1)==max(s[i],s[j])/min(s[i],s[j])) d.unite(i,j); if(k*k*k==max(s[i],s[j])/min(s[i],s[j])]) d.unite(i,j); if((k+1)*(k+1)*(k+1)==max(s[i],s[j])/min(s[i],s[j])) d.unite(i,j); } } ll ans=0; for(i=0;i<n;i++) if(d.p[i]==i) ans++; cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:53:46: error: expected ')' before ']' token 53 | if(k*k*k==max(s[i],s[j])/min(s[i],s[j])]) d.unite(i,j); | ~ ^ | ) a.cc:53:46: error: expected primary-expression before ']' token
s409893318
p04022
C++
#include <iostream> #include <unordered_map> #include <algorithm> #include <vector> using namespace std; int N; vector<int> p; bool s[100005]; using pii = pair<long long int, int>; vector<pii> factor(long long int x) { vector<pii> f; for(long long int curp: p) { int dc = 0; while(x % curp == 0) { dc ++; x /= curp; } dc %= 3; if(dc != 0) { f.push_back(make_pair(curp, dc)); } } if(x != 1) { f.push_back(make_pair(x, 1)); } return f; } long long int a[100005]; vector<pii> fa[100005]; unordered_map<vector<pii>, int> m; vector<pii> dual(vector<pii> x) { vector<pii> d = x; for(int i = 0; i < d.size(); i++) { d[i].second = 3-d[i].second; } return d; } int main() { for(int i = 2; i <= 100000; i++) { if(!s[i]) { p.push_back(i); for(int j = i; j <= 100000; j += i) { s[j] = true; } } } cin >> N; for(int i = 0; i < N; i++) { cin >> a[i]; } for(int i = 0; i < N; i++) { fa[i] = factor(a[i]); /*for(auto x: fa[i]) { cerr << x.first << " " << x.second << " --- "; } cerr << "\n";*/ m[fa[i]]++; } int ans = 0; bool one = false; for(int i = 0; i < N; i++) { if(fa[i].size() == 0) { one = true; continue; } vector<pii> flip = dual(fa[i]); int c1 = m[flip]; int c2 = m[fa[i]]; //cerr << "Trying " << a[i] << " choose " << c1 << " " << c2 << "\n"; ans += max(c1, c2); m[flip] = 0; m[fa[i]] = 0; } if(one) { ans++; } cout << ans << "\n"; return 0; }
a.cc:36:33: error: use of deleted function 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = std::vector<std::pair<long long int, int> >; _Tp = int; _Hash = std::hash<std::vector<std::pair<long long int, int> > >; _Pred = std::equal_to<std::vector<std::pair<long long int, int> > >; _Alloc = std::allocator<std::pair<const std::vector<std::pair<long long int, int> >, int> >]' 36 | unordered_map<vector<pii>, int> m; | ^ In file included from /usr/include/c++/14/unordered_map:41, from a.cc:2: /usr/include/c++/14/bits/unordered_map.h:148:7: note: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = std::vector<std::pair<long long int, int> >; _Tp = int; _Hash = std::hash<std::vector<std::pair<long long int, int> > >; _Pred = std::equal_to<std::vector<std::pair<long long int, int> > >; _Alloc = std::allocator<std::pair<const std::vector<std::pair<long long int, int> >, int> >]' is implicitly deleted because the default definition would be ill-formed: 148 | unordered_map() = default; | ^~~~~~~~~~~~~ /usr/include/c++/14/bits/unordered_map.h:148:7: error: use of deleted function 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = std::vector<std::pair<long long int, int> >; _Value = std::pair<const std::vector<std::pair<long long int, int> >, int>; _Alloc = std::allocator<std::pair<const std::vector<std::pair<long long int, int> >, int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::vector<std::pair<long long int, int> > >; _Hash = std::hash<std::vector<std::pair<long long int, int> > >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>]' In file included from /usr/include/c++/14/bits/unordered_map.h:33: /usr/include/c++/14/bits/hashtable.h:539:7: note: 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = std::vector<std::pair<long long int, int> >; _Value = std::pair<const std::vector<std::pair<long long int, int> >, int>; _Alloc = std::allocator<std::pair<const std::vector<std::pair<long long int, int> >, int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::vector<std::pair<long long int, int> > >; _Hash = std::hash<std::vector<std::pair<long long int, int> > >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>]' is implicitly deleted because the default definition would be ill-formed: 539 | _Hashtable() = default; | ^~~~~~~~~~ /usr/include/c++/14/bits/hashtable.h:539:7: error: use of deleted function 'std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = std::vector<std::pair<long long int, int> >; _Value = std::pair<const std::vector<std::pair<long long int, int> >, int>; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::vector<std::pair<long long int, int> > >; _Hash = std::hash<std::vector<std::pair<long long int, int> > >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, false, true>]' In file included from /usr/include/c++/14/bits/hashtable.h:35: /usr/include/c++/14/bits/hashtable_policy.h:1731:7: note: 'std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = std::vector<std::pair<long long int, int> >; _Value = std::pair<const std::vector<std::pair<long long int, int> >, int>; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::vector<std::pair<long long int, int> > >; _Hash = std::hash<std::vector<std::pair<long long int, int> > >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, false, true>]' is implicitly deleted because the default definition would be ill-formed: 1731 | _Hashtable_base() = default; | ^~~~~~~~~~~~~~~ /usr/include/c++/14/bits/hashtable_policy.h:1731:7: error: use of deleted function 'std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_Hash_code_base() [with _Key = std::vector<std::pair<long long int, int> >; _Value = std::pair<const std::vector<std::pair<long long int, int> >, int>; _ExtractKey = std::__detail::_Select1st; _Hash = std::hash<std::vector<std::pair<long long int, int> > >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true]' /usr/include/c++/14/bits/hashtable_policy.h: In instantiation of 'std::__detail::_Hashtable_ebo_helper<_Nm, _Tp, true>::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash<std::vector<std::pair<long long int, int> > >]': /usr/include/c++/14/bits/hashtable_policy.h:1328:7: required from here 1328 | _Hash_code_base() = default; | ^~~~~~~~~~~~~~~ /usr/include/c++/14/bits/hashtable_policy.h:1245:49: error: use of deleted function 'std::hash<std::vector<std::pair<long long int, int> > >::hash()' 1245 | _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { } | ^~~~~ In file included from /usr/include/c++/14/string_view:50, from /usr/include/c++/14/bits/basic_string.h:47, from /usr/include/c++/14/string:54, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/bits/functional_hash.h:102:12: note: 'std::hash<std::vector<std::pair<long long int, int> > >::hash()' is implicitly deleted because the default definition would be ill-formed: 102 | struct hash : __hash_enum<_Tp> | ^~~~ /usr/include/c++/14/bits/functional_hash.h:102:12: error: no matching function for call to 'std::__hash_enum<std::vector<std::pair<long long int, int> >, false>::__hash_enum()' /usr/include/c++/14/bits/functional_hash.h:83:7: note: candidate: 'std::__hash_enum<_Tp, <anonymous> >::__hash_enum(std::__hash_enum<_Tp, <anonymous> >&&) [with _Tp = std::vector<std::pair<long long int, int> >; bool <anonymous> = false]' 83 | __hash_enum(__hash_enum&&); | ^~~~~~~~~~~ /usr/include/c++/14/bits/functional_hash.h:83:7: note: candidate expects 1 argument, 0 provided /usr/include/c++/14/bits/functional_hash.h:102:12: error: 'std::__hash_enum<_Tp, <anonymous> >::~__hash_enum() [with _Tp = std::vector<std::pair<long long int, int> >; bool <anonymous> = false]' is private within this context 102 | struct hash : __hash_enum<_Tp> | ^~~~ /usr/include/c++/14/bits/functional_hash.h:84:7: note: declared private here 84 | ~__hash_enum(); | ^ /usr/include/c++/14/bits/hashtable_policy.h:1245:49: note: use '-fdiagnostics-all-candidates' to display considered candidates 1245 | _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { } | ^~~~~ /usr/include/c++/14/bits/hashtable_policy.h:1328:7: note: 'std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_Hash_code_base() [with _Key = std::vector<std::pair<long long int, int> >; _Value = std::pair<const std::vector<std::pair<long long int, int> >, int>; _ExtractKey = std::__detail::_Select1st; _Hash = std::hash<std::vector<std::pair<long long int, int> > >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true]' is implicitly deleted because the default definition would be ill-formed: 1328 | _Hash_code_base() = default; | ^~~~~~~~~~~~~~~ /usr/include/c++/14/bits/hashtable_policy.h:1328:7: error: use of deleted function 'std::__detail::_Hashtable_ebo_helper<1, std::hash<std::vector<std::pair<long long int, int> > >, true>::~_Hashtable_ebo_helper()' /usr/include/c++/14/bits/hashtable_policy.h:1242:12: note: 'std::__detail::_Hashtable_ebo_helper<1, std::hash<std::vector<std::pair<long long int, int> > >, true>::~_Hashtable_ebo_helper()' is implicitly deleted because the default definition would be ill-formed: 1242 | struct _Hashtable_ebo_helper<_Nm, _Tp, true> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/hashtable_policy.h:1242:12: error: use of deleted function 'std::hash<std::vector<std::pair<long long int, int> > >::~hash()' /usr/include/c++/14/bits/functional_hash.h:102:12: note: 'std::hash<std::vector<std::pair<long long int, int> > >::~hash()' is implicitly deleted because the default definition would be ill-formed: 102 | struct hash : __hash_enum<_Tp> | ^~~~ /usr/include/c++/14/bits/functional_hash.h:102:12: error: 'std::__hash_enum<_Tp, <anonymous> >::~__hash_enum() [with _Tp = std::vector<std::pair<long long int, int> >; bool <anonymous> = false]' is private within this context /usr/include/c++/14/bits/functional_hash.h:84:7: note: declared private here 84 | ~__hash_enum(); | ^ /usr/include/c++/14/bits/hashtable_policy.h:1731:7: note: use '-fdiagnostics-all-candidates' to display considered candidates 1731 | _Hashtable_base() = default; | ^~~~~~~~~~~~~~~ /usr/include/c++/14/bits/hashtable_policy.h:1731:7: error: use of deleted function 'std::__detail::_Hash_code_base<std::vector<std::pair<long long int, int> >, std::pair<const std::vector<std::pair<long long int, int> >, int>, std::__det
s902085564
p04023
C++
#include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int, int> #define ull unsigned ll #define f first #define s second #define ALL(x) x.begin(),x.end() #define SZ(x) (int)x.size() #define SQ(x) (x)*(x) #define MN(a,b) a = min(a,(__typeof__(a))(b)) #define MX(a,b) a = max(a,(__typeof__(a))(b)) #define pb push_back #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #ifdef BALBIT #define IOS() #define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__); template<typename T> void _do(T &&x){cerr<<x<<endl;} template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);} #else #define IOS() ios_base::sync_with_stdio(0);cin.tie(0); #define endl '\n' #define bug(...) #endif const int iinf = 1e9+10; const ll inf = 1ll<<60; const ll mod = 1e9+7 ; void GG(){cout<<"0\n"; exit(0);} ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod ll re=1; while (n>0){ if (n&1) re = re*a %mo; a = a*a %mo; n>>=1; } return re; } ll inv (ll b, ll mo = mod){ if (b==1) return b; return (mo-mo/b) * inv(mo%b,mo) % mo; } const int maxn = 1e6+5; signed main(){ IOS(); int n,q; cin>>n>>q; vector<ll> lens = {n}; for (ll i = 0; i<q; ++i) { ll x; cin>>x; while (SZ(lens) && lens.back() >= x) lens.pop_back(); lens.pb(x); } q = SZ(lens); // for (ll x : lens) bug(x); vector<ll> numat(q); // map<ll, ll> mp; numat.back() = 1; vector<ll> ret(n+1); for (int i = q-1; i>=0; --i) { if (numat[i] == 0) continue; ll me = lens[i]; while (me > lens[0]) { int tt = lower_bound(ALL(lens), me) - lens.begin()-1; bug(tt,lens[tt]); numat[tt] += numat[i] * ll(me / lens[tt]); me = me % lens[tt]; } if (me) ret[me-1] += numat[i]; } for (int i = n; i>=0; --i) { if (i!=n) ret[i] += ret[i+1]; } for (int i = 0; i<n; ++i) { cout<<ret[i]<<endl; } }
a.cc: In function 'int main()': a.cc:3:12: error: expected primary-expression before 'long' 3 | #define ll long long | ^~~~ a.cc:72:37: note: in expansion of macro 'll' 72 | numat[tt] += numat[i] * ll(me / lens[tt]); | ^~
s048247966
p04023
C++
// in the name of GOD #include <bits/stdc++.h> #define S second #define F first #define pb push_back #define sz(cp) 1LL*cp.size() #define tm are_you_now_tm_is_define_? #define ta(c) c-'a'+1 //#define int long long using namespace std; typedef long long ll ; typedef long double ld ; typedef pair < ll , ll > pii ; const int maxn = 1e5 + 10 ; int n , q , _n; ll Ans[maxn] , path[maxn] ; vector<pii>v[maxn] ; vector<int>add[maxn] ; vector<ll>mv ; void get_yal(int i , ll w1){ if(w1 <= n){ add[w1].pb(i) ; return ; } int j = min(1LL*i-1,upper_bound(mv.begin(),mv.end(),w1)-mv.begin()-1) ; v[j].pb(pii(i,w1/mv[j])) ; get_yal(i,w1%mv[j]); } int main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin >> n >> q ; _n = n ; mv.resize(q) ; for(int y = 0 ; y < q ; y++) cin >> mv[y] ; for(int y = q-2 ; y+1 ; y--) mv[y] = min(mv[y] , mv[y+1]) ; if(mv[0] <= n) n = mv[0] ; else reverse(mv.begin(),mv.end()),mv.pb(n),reverse(mv.begin(),mv.end()),q++; mv.pb(1LL*1e18+10) ; path[q-1] = 1; for(int y = 0 ; y < q ; y++) get_yal(y,mv[y]) ; for(int y = q-1 ; y+1 ; y--) for(auto A : v[y]) path[y] += A.S*path[A.F] ; for(int y = n ; y ; y--){ Ans[y] += Ans[y+1] ; for(auto A : add[y]) Ans[y] += path[A] ; } for(int y = 1 ; y <= _n ; y++) cout << Ans[y] << endl ; return 0 ; }
a.cc: In function 'void get_yal(int, ll)': a.cc:26:20: error: no matching function for call to 'min(long long int, __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type)' 26 | int j = min(1LL*i-1,upper_bound(mv.begin(),mv.end(),w1)-mv.begin()-1) ; | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:2: /usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)' 233 | min(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed: a.cc:26:20: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type' {aka 'long int'}) 26 | int j = min(1LL*i-1,upper_bound(mv.begin(),mv.end(),w1)-mv.begin()-1) ; | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)' 281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61: /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)' 5686 | min(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)' 5696 | min(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed: a.cc:26:20: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int' 26 | int j = min(1LL*i-1,upper_bound(mv.begin(),mv.end(),w1)-mv.begin()-1) ; | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
s673828290
p04023
C++
#include<bits/stdc++.h> using namespace std; #define LL long long #define ULL unsigned long long #define mp make_pair #define pb push_back #define pii pair<int,int> #define pll pair<LL,LL> #define x first #define y second #define pi acos(-1) #define sqr(x) ((x)*(x)) #define pdd pair<double,double> #define MEMS(x) memset(x,-1,sizeof(x)) #define MEM(x) memset(x,0,sizeof(x)) #define less Less #define EPS 1e-4 #define arg ARG #define cpdd const pdd #define rank Rank #define KK 500 #define N 100005 #define MXN 200005 int main(){ int n,q; scanf("%d %d",&n,&q); /*if(q==0){ for(int i = 0;i<n;i++){ printf("%d\n",1); } return 0; }*/ vector<LL> v; v.pb(n); for(int i = 0;i<q;i++){ LL x; scanf("%lld",&x); while(!v.empty()&&x<v.back())v.pop_back(); v.pb(x); } //printf("%d\n",v.size()); if(v.size()==1){ for(int i = 0;i<n;i++){ if(i<v[0])printf("1\n"); else printf("0\n"); } return 0; } // reverse(v.begin(),v.end()); LL now=1; map<LL,LL> m; for(int i = v.size()-2;i>=0;i--){ if(v[i+1]%v[i]!=0) m[v[i+1]%v[i]]+=now; now*=v[i+1]/v[i]; while(!m.empty()&&m.rbegin()->x>v[i]){ now+=m.rbegin()->x/v[i]*m.rbegin()->y; if(m.rbegin->x%v[i]!=0) m[m.rbegin()->x%v[i]]+=m.rbegin()->y; m.erase(m.rbegin()->x); } } // printf("%lld\n",now); LL ans[100005]; MEM(ans); for(auto it:m){ ans[it.x]=it.y; } ans[v[0]]=now; for(int i = n-1;i>=1;i--) ans[i]+=ans[i+1]; for(int i = 1;i<=n;i++) printf("%lld\n",ans[i]); }
a.cc: In function 'int main()': a.cc:58:18: error: invalid use of member function 'std::map<long long int, long long int>::rbegin' (did you forget the '()' ?) 58 | if(m.rbegin->x%v[i]!=0) | ~~^~~~~~
s601063833
p04023
C++
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cassert> #include <iostream> #include <sstream> #include <vector> #include <queue> #include <set> #include <map> #include <utility> #include <numeric> #include <algorithm> #include <bitset> #include <complex> #include <array> #include <list> #include <stack> #include <valarray> using namespace std; typedef unsigned uint; typedef long long Int; typedef unsigned long long UInt; const int INF = 1001001001; const Int INFLL = 1001001001001001001LL; template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; } template<typename T> void chmin(T& a, T b) { if (a > b) a = b; } template<typename T> void chmax(T& a, T b) { if (a < b) a = b; } int in() { int x; scanf("%d", &x); return x; } double fin() { double x; scanf("%lf", &x); return x; } Int lin() { Int x; scanf("%lld", &x); return x; } int main() { Int N = in(); int Q = in(); vector<Int> A; A.push_back(N); for (int i = 0; i < Q; ++i) { Int x = lin(); while (!A.empty() && A.back() >= x) { A.pop_back(); } A.push_back(x); } Q = A.size(); reverse(A.begin(), A.end()); vector<Int> W(max(A.back(), N), 0), WX(Q, 0); WX[0] = 1; for (int i = 0; i + 1 < Q; ++i) { Int pos = A[i]; for (int j = i + 1; pos > 0 && j < Q; ) { int jj = upper_bound(A.begin() + j, A.end(), pos, [] (const Int& a, const Int& b) { return a > b; }) - A.begin(); if (jj < Q) { WX[jj] += WX[i] * (pos / A[jj]); pos %= A[jj]; } j = jj + 1; }#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cassert> #include <iostream> #include <sstream> #include <vector> #include <queue> #include <set> #include <map> #include <utility> #include <numeric> #include <algorithm> #include <bitset> #include <complex> #include <array> #include <list> #include <stack> #include <valarray> using namespace std; typedef unsigned uint; typedef long long Int; typedef unsigned long long UInt; const int INF = 1001001001; const Int INFLL = 1001001001001001001LL; template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; } template<typename T> void chmin(T& a, T b) { if (a > b) a = b; } template<typename T> void chmax(T& a, T b) { if (a < b) a = b; } int in() { int x; scanf("%d", &x); return x; } double fin() { double x; scanf("%lf", &x); return x; } Int lin() { Int x; scanf("%lld", &x); return x; } int main() { Int N = in(); int Q = in(); vector<Int> A; A.push_back(N); for (int i = 0; i < Q; ++i) { Int x = lin(); while (!A.empty() && A.back() >= x) { A.pop_back(); } A.push_back(x); } Q = A.size(); reverse(A.begin(), A.end()); vector<Int> W(max(A.back(), N), 0), WX(Q, 0); WX[0] = 1; for (int i = 0; i + 1 < Q; ++i) { Int pos = A[i]; for (int j = i + 1; pos > 0 && j < Q; ) { int jj = upper_bound(A.begin() + j, A.end(), pos, [] (const Int& a, const Int& b) { return a > b; }) - A.begin(); if (jj < Q) { WX[jj] += WX[i] * (pos / A[jj]); pos %= A[jj]; } j = jj + 1; } if (pos > 0) { W[pos - 1] += WX[i]; } } W[A[Q - 1] - 1] += WX[Q - 1]; for (int v = A.back() - 2; v >= 0; --v) { W[v] += W[v + 1]; } for (int v = 0; v < N; ++v) { printf("%lld\n", W[v]); } return 0; } if (pos > 0) { W[pos - 1] += WX[i]; } } W[A[Q - 1] - 1] += WX[Q - 1]; for (int v = A.back() - 2; v >= 0; --v) { W[v] += W[v + 1]; } for (int v = 0; v < N; ++v) { printf("%lld\n", W[v]); } return 0; }
a.cc:67:6: error: stray '#' in program 67 | }#include <cstdio> | ^ a.cc: In function 'int main()': a.cc:67:7: error: 'include' was not declared in this scope 67 | }#include <cstdio> | ^~~~~~~ a.cc:67:16: error: 'cstdio' was not declared in this scope; did you mean 'stdin'? 67 | }#include <cstdio> | ^~~~~~ | stdin a.cc:88:1: error: expected primary-expression before 'using' 88 | using namespace std; | ^~~~~ a.cc:97:1: error: a template declaration cannot appear at block scope 97 | template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; } | ^~~~~~~~ a.cc:99:1: error: a template declaration cannot appear at block scope 99 | template<typename T> void chmax(T& a, T b) { if (a < b) a = b; } | ^~~~~~~~ a.cc:101:11: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse] 101 | double fin() { double x; scanf("%lf", &x); return x; } | ^~ a.cc:101:11: note: remove parentheses to default-initialize a variable 101 | double fin() { double x; scanf("%lf", &x); return x; } | ^~ | -- a.cc:101:11: note: or replace parentheses with braces to value-initialize a variable a.cc:101:14: error: a function-definition is not allowed here before '{' token 101 | double fin() { double x; scanf("%lf", &x); return x; } | ^ a.cc:102:8: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse] 102 | Int lin() { Int x; scanf("%lld", &x); return x; } | ^~ a.cc:102:8: note: remove parentheses to default-initialize a variable 102 | Int lin() { Int x; scanf("%lld", &x); return x; } | ^~ | -- a.cc:102:8: note: or replace parentheses with braces to value-initialize a variable a.cc:102:11: error: a function-definition is not allowed here before '{' token 102 | Int lin() { Int x; scanf("%lld", &x); return x; } | ^ a.cc:104:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse] 104 | int main() { | ^~ a.cc:104:9: note: remove parentheses to default-initialize a variable 104 | int main() { | ^~ | -- a.cc:104:9: note: or replace parentheses with braces to value-initialize a variable a.cc:104:12: error: a function-definition is not allowed here before '{' token 104 | int main() { | ^
s148541665
p04023
C++
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cassert> #define ll long long using namespace std; namespace IO { const int __S=(1<<20)+5;char __buf[__S],*__H,*__T; inline char getc() { if(__H==__T) __T=(__H=__buf)+fread(__buf,1,__S,stdin); if(__H==__T) return -1;return *__H++; } template <class __I>inline void read(__I &__x) { __x=0;int __fg=1;char __c=getc(); while(!isdigit(__c)&&__c!='-') __c=getc(); if(__c=='-') __fg=-1,__c=getc(); while(isdigit(__c)) __x=__x*10+__c-'0',__c=getc(); __x*=__fg; } inline void readd(double &__x) { __x=0;double __fg=1.0;char __c=getc(); while(!isdigit(__c)&&__c!='-') __c=getc(); if(__c=='-') __fg=-1.0,__c=getc(); while(isdigit(__c)) __x=__x*10.0+__c-'0',__c=getc(); if(__c!='.'){__x=__x*__fg;return;}else while(!isdigit(__c)) __c=getc(); double __t=1e-1;while(isdigit(__c)) __x=__x+1.0*(__c-'0')*__t,__t=__t*0.1,__c=getc(); __x=__x*__fg; } inline void reads(char *__s,int __x) { char __c=getc();int __tot=__x-1; while(__c<'a'||__c>'z') __c=getc(); while(__c>='a'&&__c<='z') __s[++__tot]=__c,__c=getc(); __s[++__tot]='\0'; } char __obuf[__S],*__oS=__obuf,*__oT=__oS+__S-1,__c,__qu[55];int __qr; inline void flush(){fwrite(__obuf,1,__oS-__obuf,stdout);__oS=__obuf;} inline void putc(char __x){*__oS++ =__x;if(__oS==__oT) flush();} template <class __I>inline void print(__I __x) { if(!__x) putc('0'); if(__x<0) putc('-'),__x=-__x; while(__x) __qu[++__qr]=__x%10+'0',__x/=10; while(__qr) putc(__qu[__qr--]); } inline void prints(const char *__s,const int __x) { int __len=strlen(__s+__x); for(int __i=__x;__i<__len+__x;__i++) putc(__s[__i]); } inline void printd(long double __x,int __d) { long long __t=(long long)floor(__x);print(__t);putc('.');__x-=(double)__t; while(__d--) { long double __y=__x*10.0;__x*=10.0; int __c=(int)floor(__y+1e-9);if(__c==10) __c--; putc(__c+'0');__x-=floor(__y); } } inline void el(){putc('\n');}inline void sp(){putc(' ');} }using namespace IO; int n,T,m,N; ll s[100010],f[100010],ans[100010],tmp; int main(){ read(n);read(T);int i;ll remain,now,k; while(T--){ read(tmp); while(m&&s[m]>=tmp) s[m--]=0; s[++m]=tmp; } if(m&&s[1]<n){ N=n;n=s[1]; for(i=1;i<m;i++) s[i]=s[i+1];m--; } s[0]=n;f[m]=1; for(i=m;i>=0;i--){ remain=s[i];now=i-1; while(remain>n){ k=remain/s[now]; f[now]+=f[i]*k;remain-=s[now]*k; now=upper_bound(s,s+now,remain)-s-1; } ans[1]+=f[i];ans[remain+1]-=f[i]; } for(i=1;i<=n;i++) ans[i]+=ans[i-1],print(ans[i]),el(); while(n<N) n++,print(0),el(); flush(); }
a.cc: In function 'void IO::printd(long double, int)': a.cc:58:34: error: 'floor' was not declared in this scope 58 | long long __t=(long long)floor(__x);print(__t);putc('.');__x-=(double)__t; | ^~~~~
s170650536
p04023
C++
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #define LL long long #define M 200020 using namespace std; LL read(){ LL nm=0,fh=1; LL cw=getchar(); for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh; for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0'); return nm*fh; } LL n,T,m,p[M],N,G[M],F[M],K[M],fs[M*30],nt[M*30],to[M*30],len[M*30],tmp; void link(LL x,LL y,LL dst){nt[tmp]=fs[x],fs[x]=tmp,to[tmp]=y,len[tmp++]=dst;} LL main(){ //freopen(".in","r",stdin); //freopen(".out","w",stdout); n=read(),T=read(),memset(fs,-1,sizeof(fs)); while(T--){LL x=read(); while(m&&p[m]>=x) m--; p[++m]=x;} if(m&&p[1]<n){N=n,n=p[1];for(LL i=1;i<m;i++) p[i]=p[i+1];m--;} // for(LL i=1;i<=m;i++) printf("%lld\n",p[i]); // printf("n = %lld\n",n); G[0]=p[0]=n,F[m]=1; for(LL i=1;i<=m;i++){ LL res=p[i],now=i-1; while(res>n){ if(res>=p[now]){LL k=res/p[now]; link(i,now,k),res-=k*p[now];} now=lower_bound(p,p+now+1,res)-p; } G[i]=res; } for(LL i=n;i>=0;i--){ for(LL j=fs[i];j!=-1;j=nt[j]) F[to[j]]+=F[i]*len[j]; K[1]+=F[i],K[G[i]+1]-=F[i]; } for(LL i=1;i<=n;i++) K[i]+=K[i-1],printf("%lld\n",K[i]); while(n<N) n++,putchar('0'),putchar('\n'); return 0; }
cc1plus: error: '::main' must return 'int'
s655589311
p04023
C++
#include <bits/stdc++.h> using namespace std; namespace IO { const int __S=(1<<20)+5;char __bua[__S],*__H,*__T; inline char getc() { if(__H==__T) __T=(__H=__buf)+fread(__buf,1,__S,stdin); if(__H==__T) return -1;return *__H++; } template <class __I>inline void read(__I &__x) { __x=0;int __fg=1;char __c=getc(); while(!isdigit(__c)&&__c!='-') __c=getc(); if(__c=='-') __fg=-1,__c=getc(); while(isdigit(__c)) __x=__x*10+__c-'0',__c=getc(); __x*=__fg; } inline void readd(double &__x) { __x=0;double __fg=1.0;char __c=getc(); while(!isdigit(__c)&&__c!='-') __c=getc(); if(__c=='-') __fg=-1.0,__c=getc(); while(isdigit(__c)) __x=__x*10.0+__c-'0',__c=getc(); if(__c!='.'){__x=__x*__fg;return;}else while(!isdigit(__c)) __c=getc(); double __t=1e-1;while(isdigit(__c)) __x=__x+1.0*(__c-'0')*__t,__t=__t*0.1,__c=getc(); __x=__x*__fg; } inline void reads(char *__s,int __x) { char __c=getc();int __tot=__x-1; while(__c<'!'||__c>'~') __c=getc(); while(__c>='!'&&__c<='~') __s[++__tot]=__c,__c=getc(); __s[++__tot]='\0'; } char __obua[__S],*__oS=__obuf,*__oT=__oS+__S-1,__c,__qu[55];int __qr; inline void flush(){fwrite(__obuf,1,__oS-__obuf,stdout);__oS=__obuf;} inline void putc(char __x){*__oS++ =__x;if(__oS==__oT) flush();} template <class __I>inline void print(__I __x) { if(!__x) putc('0'); if(__x<0) putc('-'),__x=-__x; while(__x) __qu[++__qr]=__x%10+'0',__x/=10; while(__qr) putc(__qu[__qr--]); } inline void prints(const char *__s,const int __x) { int __len=strlen(__s+__x); for(int __i=__x;__i<__len+__x;__i++) putc(__s[__i]); } inline void printd(double __x,int __d) { long long __t=(long long)floor(__x);print(__t);putc('.');__x-=(double)__t; while(__d--) { double __y=__x*10.0;__x*=10.0; int __c=(int)floor(__y); putc(__c+'0');__x-=floor(__y); } } inline void el(){putc('\n');}inline void sp(){putc(' ');} }using namespace IO; #define ll long long ll n,m,tot,x,t[200005],a[200005],a[200005],ans[200005];stack<ll>sta; void gao(int x,ll y) { if(!x) return;int t=upper_bound(a+1,a+tot+1,x)-a-1; if(!t) ans[1]+=y,ans[x+1]-=y;else a[t]+=x/a[t]*y,gao(x%a[t],y); } int main() { read(n);read(m);a[++tot]=n; for(int i=1;i<=m;i++){read(x);while(tot&&a[tot]>=x) tot--;a[++tot]=x;} a[tot]=1;for(int i=tot;i>=2;i--) a[i-1]+=a[i]*(a[i]/a[i-1]),gao(a[i]%a[i-1],a[i]); ans[1]+=a[1];ans[a[1]+1]-=a[1];for(int i=1;i<=n;i++) ans[i]+=ans[i-1]; for(int i=1;i<=n;i++) print(ans[i]),el();flush(); }
a.cc: In function 'char IO::getc()': a.cc:8:39: error: '__buf' was not declared in this scope; did you mean '__bua'? 8 | if(__H==__T) __T=(__H=__buf)+fread(__buf,1,__S,stdin); | ^~~~~ | __bua a.cc: At global scope: a.cc:36:32: error: '__obuf' was not declared in this scope; did you mean '__obua'? 36 | char __obua[__S],*__oS=__obuf,*__oT=__oS+__S-1,__c,__qu[55];int __qr; | ^~~~~~ | __obua a.cc: In function 'void IO::flush()': a.cc:37:36: error: '__obuf' was not declared in this scope; did you mean '__obua'? 37 | inline void flush(){fwrite(__obuf,1,__oS-__obuf,stdout);__oS=__obuf;} | ^~~~~~ | __obua a.cc: In function 'void IO::putc(char)': a.cc:38:58: error: '__oT' was not declared in this scope; did you mean '__oS'? 38 | inline void putc(char __x){*__oS++ =__x;if(__oS==__oT) flush();} | ^~~~ | __oS a.cc: In function 'void IO::print(__I)': a.cc:43:28: error: '__qu' was not declared in this scope; did you mean '__qr'? 43 | while(__x) __qu[++__qr]=__x%10+'0',__x/=10; | ^~~~ | __qr a.cc:44:34: error: '__qu' was not declared in this scope; did you mean '__qr'? 44 | while(__qr) putc(__qu[__qr--]); | ^~~~ | __qr a.cc: At global scope: a.cc:64:34: error: redefinition of 'long long int a [200005]' 64 | ll n,m,tot,x,t[200005],a[200005],a[200005],ans[200005];stack<ll>sta; | ^ a.cc:64:24: note: 'long long int a [200005]' previously declared here 64 | ll n,m,tot,x,t[200005],a[200005],a[200005],ans[200005];stack<ll>sta; | ^
s470409598
p04023
C++
include<cstring> #include<cstdlib> #include<cstdio> #include<cmath> #include<iostream> #define N 110000 #define LL long long using namespace std; LL sta[N],a[N],t[N],s[N],ans; int tp,n,m; int td(LL k,int r) { int l=1,res=0; while(l<=r) { int mid=(l+r)/2; if(a[mid]<=k) res=mid,l=mid+1; else r=mid-1; } return res; } int main() { scanf("%d%d",&n,&m); sta[tp=1]=n; for(int i=1;i<=m;i++) { LL x;scanf("%lld",&x); while(x<=sta[tp]) tp--; sta[++tp]=x; } m=tp; for(int i=1;i<=m;i++) a[i]=sta[i]; t[m]=1; for(int i=m;i>=1;i--) { LL k=a[i];int p=td(k,i-1); while(p) { t[p]+=(k/a[p])*t[i]; k%=a[p]; p=td(k,p-1); } s[1]+=t[i];s[k+1]-=t[i]; } for(int i=1;i<=n;i++) {ans+=s[i];printf("%lld\n",ans);} return 0; }
a.cc:1:1: error: 'include' does not name a type 1 | include<cstring> | ^~~~~~~ In file included from /usr/include/c++/14/cmath:45, from a.cc:4: /usr/include/c++/14/ext/type_traits.h:164:35: error: 'constexpr const bool __gnu_cxx::__is_null_pointer' redeclared as different kind of entity 164 | __is_null_pointer(std::nullptr_t) | ^ /usr/include/c++/14/ext/type_traits.h:159:5: note: previous declaration 'template<class _Type> constexpr bool __gnu_cxx::__is_null_pointer(_Type)' 159 | __is_null_pointer(_Type) | ^~~~~~~~~~~~~~~~~ /usr/include/c++/14/ext/type_traits.h:164:26: error: 'nullptr_t' is not a member of 'std' 164 | __is_null_pointer(std::nullptr_t) | ^~~~~~~~~ In file included from /usr/include/c++/14/bits/stl_pair.h:60, from /usr/include/c++/14/bits/stl_algobase.h:64, from /usr/include/c++/14/bits/specfun.h:43, from /usr/include/c++/14/cmath:3906: /usr/include/c++/14/type_traits:666:33: error: 'nullptr_t' is not a member of 'std' 666 | struct is_null_pointer<std::nullptr_t> | ^~~~~~~~~ /usr/include/c++/14/type_traits:666:42: error: template argument 1 is invalid 666 | struct is_null_pointer<std::nullptr_t> | ^ /usr/include/c++/14/type_traits:670:48: error: template argument 1 is invalid 670 | struct is_null_pointer<const std::nullptr_t> | ^ /usr/include/c++/14/type_traits:674:51: error: template argument 1 is invalid 674 | struct is_null_pointer<volatile std::nullptr_t> | ^ /usr/include/c++/14/type_traits:678:57: error: template argument 1 is invalid 678 | struct is_null_pointer<const volatile std::nullptr_t> | ^ /usr/include/c++/14/type_traits:1429:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 1429 | : public integral_constant<std::size_t, alignof(_Tp)> | ^~~~~~ In file included from /usr/include/stdlib.h:32, from /usr/include/c++/14/cstdlib:79, from a.cc:2: /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/type_traits:1429:57: error: template argument 1 is invalid 1429 | : public integral_constant<std::size_t, alignof(_Tp)> | ^ /usr/include/c++/14/type_traits:1429:57: note: invalid template non-type parameter /usr/include/c++/14/type_traits:1438:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 1438 | : public integral_constant<std::size_t, 0> { }; | ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/type_traits:1438:46: error: template argument 1 is invalid 1438 | : public integral_constant<std::size_t, 0> { }; | ^ /usr/include/c++/14/type_traits:1438:46: note: invalid template non-type parameter /usr/include/c++/14/type_traits:1440:26: error: 'std::size_t' has not been declared 1440 | template<typename _Tp, std::size_t _Size> | ^~~ /usr/include/c++/14/type_traits:1441:21: error: '_Size' was not declared in this scope 1441 | struct rank<_Tp[_Size]> | ^~~~~ /usr/include/c++/14/type_traits:1441:27: error: template argument 1 is invalid 1441 | struct rank<_Tp[_Size]> | ^ /usr/include/c++/14/type_traits:1442:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 1442 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; | ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/type_traits:1442:65: error: template argument 1 is invalid 1442 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; | ^ /usr/include/c++/14/type_traits:1442:65: note: invalid template non-type parameter /usr/include/c++/14/type_traits:1446:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 1446 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; | ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/type_traits:1446:65: error: template argument 1 is invalid 1446 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; | ^ /usr/include/c++/14/type_traits:1446:65: note: invalid template non-type parameter /usr/include/c++/14/type_traits:2086:26: error: 'std::size_t' has not been declared 2086 | template<typename _Tp, std::size_t _Size> | ^~~ /usr/include/c++/14/type_traits:2087:30: error: '_Size' was not declared in this scope 2087 | struct remove_extent<_Tp[_Size]> | ^~~~~ /usr/include/c++/14/type_traits:2087:36: error: template argument 1 is invalid 2087 | struct remove_extent<_Tp[_Size]> | ^ /usr/include/c++/14/type_traits:2099:26: error: 'std::size_t' has not been declared 2099 | template<typename _Tp, std::size_t _Size> | ^~~ /usr/include/c++/14/type_traits:2100:35: error: '_Size' was not declared in this scope 2100 | struct remove_all_extents<_Tp[_Size]> | ^~~~~ /usr/include/c++/14/type_traits:2100:41: error: template argument 1 is invalid 2100 | struct remove_all_extents<_Tp[_Size]> | ^ /usr/include/c++/14/type_traits:2171:12: error: 'std::size_t' has not been declared 2171 | template<std::size_t _Len> | ^~~ /usr/include/c++/14/type_traits:2176:30: error: '_Len' was not declared in this scope 2176 | unsigned char __data[_Len]; | ^~~~ /usr/include/c++/14/type_traits:2194:12: error: 'std::size_t' has not been declared 2194 | template<std::size_t _Len, std::size_t _Align = | ^~~ /usr/include/c++/14/type_traits:2194:30: error: 'std::size_t' has not been declared 2194 | template<std::size_t _Len, std::size_t _Align = | ^~~ /usr/include/c++/14/type_traits:2195:55: error: '_Len' was not declared in this scope 2195 | __alignof__(typename __aligned_storage_msa<_Len>::__type)> | ^~~~ /usr/include/c++/14/type_traits:2195:59: error: template argument 1 is invalid 2195 | __alignof__(typename __aligned_storage_msa<_Len>::__type)> | ^ /usr/include/c++/14/type_traits:2202:30: error: '_Len' was not declared in this scope 2202 | unsigned char __data[_Len]; | ^~~~ /usr/include/c++/14/type_traits:2203:44: error: '_Align' was not declared in this scope 2203 | struct __attribute__((__aligned__((_Align)))) { } __align; | ^~~~~~ In file included from /usr/include/c++/14/bits/stl_algobase.h:65: /usr/include/c++/14/bits/stl_iterator_base_types.h:125:67: error: 'ptrdiff_t' does not name a type 125 | template<typename _Category, typename _Tp, typename _Distance = ptrdiff_t, | ^~~~~~~~~ /usr/include/c++/14/bits/stl_iterator_base_types.h:1:1: note: 'ptrdiff_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>' +++ |+#include <cstddef> 1 | // Types used in iterator implementation -*- C++ -*- /usr/include/c++/14/bits/stl_iterator_base_types.h:214:15: error: 'ptrdiff_t' does not name a type 214 | typedef ptrdiff_t difference_type; | ^~~~~~~~~ /usr/include/c++/14/bits/stl_iterator_base_types.h:214:15: note: 'ptrdiff_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>' /usr/include/c++/14/bits/stl_iterator_base_types.h:225:15: error: 'ptrdiff_t' does not name a type 225 | typedef ptrdiff_t difference_type; | ^~~~~~~~~ /usr/include/c++/14/bits/stl_iterator_base_types.h:225:15: note: 'ptrdiff_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>' In file included from /usr/include/c++/14/bits/stl_algobase.h:66: /usr/include/c++/14/bits/stl_iterator_base_funcs.h:112:5: error: 'ptrdiff_t' does not name a type 112 | ptrdiff_t | ^~~~~~~~~ /usr/include/c++/14/bits/stl_iterator_base_funcs.h:66:1: note: 'ptrdiff_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>' 65 | #include <debug/assertions.h> +++ |+#include <cstddef> 66 | #include <bits/stl_iterator_base_types.h> /usr/include/c++/14/bits/stl_iterator_base_funcs.h:118:5: error: 'ptrdiff_t' does not name a type 118 | ptrdiff_t | ^~~~~~~~~ /usr/include/c++/14/bits/stl_iterator_base_funcs.h:118:5: note: 'ptrdiff_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>' In file included from /usr/include/c++/14/bits/stl_iterator.h:67, from /usr/include/c++/14/bits/stl_algobase.h:67: /usr/include/c++/14/bits/ptr_traits.h:156:47: error: '
s732863016
p04023
C++
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int MAXN = 100005; typedef long long ll; int n,q,top; ll a[MAXN],op[MAXN],t[MAXN],d[MAXN]; inline int getnext(ll k,int r) { int l=1,mid,ret=-1; while(l<=r){ mid=(l+r)>>1; if(op[mid]<=k)l=mid+1,ret=mid; else r=mid-1; } return ret; } int main() { scanf("%d%d",&n,&q); stk[++top]=n; for(int i=1;i<=q;++i){ scanf("%lld",a+i); while(top && op[top]>=a[i])--top; op[++top]=a[i]; } ll k; t[top]=1; for(int i=top;i;--i){ k=op[i]; while(k){ int p=getnext(k,i-1); if(p==-1)break; t[p]+=k/op[p]*t[i]; k%=op[p]; } d[1]+=t[i],d[k+1]-=t[i]; } for(int i=1;i<=n;++i) printf("%lld\n",d[i]+=d[i-1]); return 0; }
a.cc: In function 'int main()': a.cc:22:9: error: 'stk' was not declared in this scope; did you mean 'std'? 22 | stk[++top]=n; | ^~~ | std
s132980629
p04023
C++
#include<bits/stdc++.h> #define N (100009) #define ll long long using namespace std; ll n,q,x,a[N],c,A[N],f[N]; ll main() { cin>>n>>q; a[++c]=n; for (ll i=1; i<=q; ++i) { cin>>x; while (c && x<=a[c]) --c; a[++c]=x; } f[c]=1; for (ll i=c; i; --i) { ll k=a[i]; while (k>a[1]) { ll t=lower_bound(a+1,a+c+1,k)-a-1; f[t]+=f[i]*(k/a[t]); k%=a[t]; } A[k]+=f[i]; } for (ll i=n; i; --i) A[i]+=A[i+1]; for (ll i=1; i<=n; ++i) cout<<A[i]<<endl; }
cc1plus: error: '::main' must return 'int'
s385658239
p04023
C++
#include<bits/stdc++.h> typedef long long LL; using namespace std; const int MX=100005; int n,Q; LL a[MX],dt[MX],t[MX],x,cur,c; int main(){ cin>>n>>Q,a[++c]=n; for(int i=1;i<=Q;i++){cin>>x;while(c&&x<=a[c])--c;a[++c]=x;} t[c]=1; for(int i=c;i;i--){ LL tmp=a[i],it=lower_bound(a+1,a+i,tmp)-a; for(;it;it=lower_bound(a+1,a+it,tmp)-a)t[it]+=(tmp/a[it])*t[i],tmp%=a[it]; dt[1]+=t[i],dt[tmp+1]-=t[i]; } for(int i=1;i<=n;i++)cout<<(cur+=dt[i]))<<endl; return 0; }
a.cc: In function 'int main()': a.cc:19:48: error: expected ';' before ')' token 19 | for(int i=1;i<=n;i++)cout<<(cur+=dt[i]))<<endl; | ^ | ;
s683751806
p04023
C++
#include<cstdio> #include<algorithm> #define fo(i,a,b) for(i=a;i<=b;i++) #define fd(i,a,b) for(i=a;i>=b;i--) using namespace std; typedef long long ll; const int maxn=100000+10,maxtot=maxn*25; ll ans[maxn],cnt[maxn],a[maxn],b[maxn],tree[maxtot],p[maxn][70][2]; int root[maxn],left[maxtot],right[maxtot],rank[maxn]; int len[maxn]; int i,j,k,l,t,n,m,tot,top,num; int newnode(int x){ tree[++tot]=tree[x]; left[tot]=left[x]; right[tot]=right[x]; return tot; } void insert(int &x,int l,int r,int a,int b){ x=newnode(x); tree[x]=b; if (l==r) return; int mid=(l+r)/2; if (a<=mid) insert(left[x],l,mid,a,b);else insert(right[x],mid+1,r,a,b); } int query(int x,int l,int r,int a,int b){ if (!x||a>b) return 0; if (l==a&&r==b) return tree[x]; int mid=(l+r)/2; if (b<=mid) return query(left[x],l,mid,a,b); else if (a>mid) return query(right[x],mid+1,r,a,b); else return max(query(left[x],l,mid,a,mid),query(right[x],mid+1,r,mid+1,b)); } void solve(int x,ll l){ int t=upper_bound(b+1,b+num+1,l)-b-1; int y=query(root[x-1],1,num,1,t); if (!y){ if (l>=n){ p[i][++top][0]=0; p[i][top][1]=l%n; l%=n; } p[i][++top][0]=l; return; } p[i][++top][0]=y; p[i][top][1]=l/a[y]; solve(y,l%a[y]); } int main(){ scanf("%d%d",&n,&m); a[0]=n; fo(i,1,m) scanf("%lld",&a[i]),b[i]=a[i]; //b[++m]=n; sort(b+1,b+m+1); num=unique(b+1,b+m+1)-b-1; b[++num]=2000000000000000000; fo(i,1,m) rank[i]=lower_bound(b+1,b+num+1,a[i])-b; fo(i,1,m){ root[i]=root[i-1]; insert(root[i],1,num,rank[i],i); } fo(i,1,m){ top=0; solve(i,a[i]); len[i]=top; } cnt[m]=1; fd(i,m,1){ fo(j,1,len[i]-1) cnt[p[i][j][0]]+=cnt[i]*p[i][j][1]; ans[p[i][len[i]][0]]+=cnt[i]; } ans[n]+=cnt[0]; fd(i,n,1) ans[i]+=ans[i+1]; fo(i,1,n) printf("%lld\n",ans[i]); }
a.cc: In function 'int main()': a.cc:57:19: error: reference to 'rank' is ambiguous 57 | fo(i,1,m) rank[i]=lower_bound(b+1,b+num+1,a[i])-b; | ^~~~ In file included from /usr/include/c++/14/bits/stl_pair.h:60, from /usr/include/c++/14/bits/stl_algobase.h:64, from /usr/include/c++/14/algorithm:60, from a.cc:2: /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:9:43: note: 'int rank [100010]' 9 | int root[maxn],left[maxtot],right[maxtot],rank[maxn]; | ^~~~ a.cc:60:38: error: reference to 'rank' is ambiguous 60 | insert(root[i],1,num,rank[i],i); | ^~~~ /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:9:43: note: 'int rank [100010]' 9 | int root[maxn],left[maxtot],right[maxtot],rank[maxn]; | ^~~~
s719603826
p04023
C++
#include<bits/stdc++.h> #define MX 30001000 using namespace std; struct treaps { int son[MX][2],num[MX],cop[MX],inn[MX],tt; long long size[MX],ans[MX]; int newnode(int s=0) { if (tt>MX) assert(0); int t=++tt; son[t][0]=son[s][0]; son[t][1]=son[s][1]; size[t]=size[s]; num[t]=num[s]; return t; } void update(int s) {size[s]=size[son[s][0]]+size[son[s][1]]+1;} int merge(int s,int t) { if (!s) return t;if (!t) return s; if (rand()*(1ll<<31)+rand())%(size[s]+size[t])<size[s]) { int d=newnode(s); son[d][1]=merge(son[d][1],t); update(d); return d; } else { int d=newnode(t); son[d][0]=merge(s,son[d][0]); update(d); return d; } } pair<int,int> split(int s,long long k) { if (!s) return pair<int,int>(0,0); if (size[son[s][0]]>=k) { pair<int,int> ls=split(son[s][0],k); int d=newnode(s); son[d][0]=ls.second;update(d); return pair<int,int>(ls.first,d); } pair<int,int> ls=split(son[s][1],k-size[son[s][0]]-1); int d=newnode(s); son[d][1]=ls.first;update(d); return pair<int,int>(d,ls.second); } void clear(int& s){s=0;} void push_back(int& s,int w) { int t=newnode(); size[t]=1;num[t]=w; s=merge(s,t); } void pop_back(int& s) { s=split(s,size[s]-1).first; } /*int findkth(int s,int k) { if (size[son[s][0]]>=k) return findkth(son[s][0],k); if (size[son[s][0]]+1==k) return num[s]; return findkth(son[s][1],k-(size[son[s][0]]+1)); }*/ void work(int n,int root) { for (int i=1;i<=tt;i++) {inn[son[i][0]]++;inn[son[i][1]]++;size[i]=(i==root);} int head=0,tail=0; for (int i=1;i<=tt;i++) if (inn[i]==0) cop[++head]=i; while (head!=tail) { int s=cop[++tail];ans[num[s]]+=size[s]; inn[son[s][0]]--;inn[son[s][1]]--;size[son[s][0]]+=size[s];size[son[s][1]]+=size[s]; if (inn[son[s][0]]==0) cop[++head]=son[s][0]; if (inn[son[s][1]]==0) cop[++head]=son[s][1]; } for (int i=1;i<=n;i++) printf("%lld\n",ans[i]); } }treap; int main() { //freopen("01.txt","r",stdin); //freopen("my.out","w",stdout); int n,q,root=0;scanf("%d%d",&n,&q); for (int i=1;i<=n;i++) treap.push_back(root,i); while (q--) {//if (q%100==0) cerr<<q<<endl; long long w;scanf("%lld",&w); while (treap.size[root]<w) root=treap.merge(root,root); root=treap.split(root,w).first; } treap.work(n,root); //cerr<<treap.tt<<endl; }
a.cc: In member function 'int treaps::merge(int, int)': a.cc:22:45: error: expected primary-expression before '%' token 22 | if (rand()*(1ll<<31)+rand())%(size[s]+size[t])<size[s]) | ^ a.cc:36:9: warning: control reaches end of non-void function [-Wreturn-type] 36 | } | ^
s621901457
p04023
C++
#include<cstdio> #include<algorithm> #include<cstring> #define LL long long using namespace std; const int maxn=500001; int n,q,sz=1; LL a,st[maxn],cnt[maxn],sum[maxn],lazy[maxn]; inline int find(int l,int r,LL key) { while(l<=r) { int mid=(l+r)/2; if(st[mid]>=key) r=mid-1; else l=mid+1; } return r; } inline void split(LL now,int pos,LL num) { if(now==0) return ; if(now<=st[1]) { cnt[now]+=num; return ; } /*if(pos==1) printf("NO");*/ LL k1=now/st[pos-1],k2=now%st[pos-1]; int pos2=find(1,pos,k2); lazy[pos-1]+=k1*num; //split(st[pos-1],pos-1,k1*num); split(k2,pos2+1,num); } int main() { int size = 64 << 20; // 256MB char *p = (char*)malloc(size) + size; __asm__("movl %0, %%esp\n" :: "r"(p)); scanf("%d %d",&n,&q); st[1]=n; for(int i=1;i<=q;i++) { scanf("%lld",&a); if(st[sz]<a) st[++sz]=a; else { while(st[sz]>=a) sz--; st[++sz]=a; } } lazy[sz]=1; for(int i=sz;i>=1;i--) split(st[i],i,lazy[i]); for(int i=st[1];i>=1;i--) { sum[i]=sum[i+1]+cnt[i]; } for(int i=1;i<=n;i++) printf("%lld\n",sum[i]); return 0; }
a.cc: Assembler messages: a.cc:40: Error: operand type mismatch for `mov'
s373353510
p04023
C++
//C++14 (Clang 3.8.0) #include <vector> #include <list> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <string> typedef long long ll; using namespace std; const int MAX_N=1e5+1; const int MAX_Q=1e5+1; ll MAX_q=1e18+1; ll a[MAX_N]; ll t[MAX_N]; int binsearch(vector<ll> x,ll y,int z){ int l=-1,r=z,mid; while(r-l>1){ mid=(l+r) / 2; if(y >= x[mid]) l=mid; else r = mid; } return r; } int main(){ int N; int Q; cin>>N>>Q; vector<ll> q; q.push_back(N); for(int i =0;i<Q;i++) { ll x; cin>>x; while(!q.empty() && q.back() >= x) q.pop_back(); q.push_back(x); } int L = q.size() - 1; t[L] = 1; for(int i = L;i >0;i--){ ll k=q[i]; bef=i-1; while(k>q[0]){ int ind=binsearch(q,k,bef); t[ind]+=t[i]*(k/q[ind]); k=k%q[ind]; bef=ind; } a[k-1]+=t[i]; } a[q[0]-1] += t[0]; for(int i=N-1;i>=0;i--) a[i]+=a[i+1]; for(int i=0;i<N;i++) cout<<a[i]<<endl; return 0; };
a.cc: In function 'int main()': a.cc:60:9: error: 'bef' was not declared in this scope 60 | bef=i-1; | ^~~
s648527394
p04023
C++
#include <cstdlib> #include <cstdio> #include <algorithm> #include <vector> #include <queue> #include <cmath> #include <stack> #include <map> #include <set> #include <deque> #include <cstring> #include <functional> #include <climits> #include <list> #include <ctime> #include <complex> #include <ext/rope> #define F1(x,y,z) for(int x=y;x<z;x++) #define F2(x,y,z) for(int x=y;x<=z;x++) #define F3(x,y,z) for(int x=y;x>z;x--) #define F4(x,y,z) for(int x=y;x>=z;x--) #define mp make_pair #define pb push_back #define LL long long #define co complex<double> #define fi first #define se second #define MAX 100005 #define AMAX 1500 #define MOD 1000000007 #define f(c,d) ((1<<(c))*(d)) using namespace std; using namespace __gnu_cxx; int n,q; LL ta; vector<LL> x; vector<pair<LL,int> > y; int main(){ scanf("%d%d",&n,&q); while(q--){ scanf("%lld",&ta); while(!x.empty()&&x.back()>=ta)x.pop_back(); x.pb(ta); } y.pb(mp(x[0],0)); F1(a,1,x.size())y.pb(x[a]%x[a-1]),y.pb(x[a]); F1(a,0,n)printf("%d\n",1); #ifdef LOCAL_PROJECT system("pause"); #endif return 0; }
a.cc: In function 'int main()': a.cc:52:29: error: no matching function for call to 'std::vector<std::pair<long long int, int> >::push_back(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)' 52 | F1(a,1,x.size())y.pb(x[a]%x[a-1]),y.pb(x[a]); | ~~~~^~~~~~~~~~~~~ In file included from /usr/include/c++/14/vector:66, from a.cc:4: /usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, int>; _Alloc = std::allocator<std::pair<long long int, int> >; value_type = std::pair<long long int, int>]' 1283 | push_back(const value_type& __x) | ^~~~~~~~~ /usr/include/c++/14/bits/stl_vector.h:1283:35: note: no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'const std::vector<std::pair<long long int, int> >::value_type&' {aka 'const std::pair<long long int, int>&'} 1283 | push_back(const value_type& __x) | ~~~~~~~~~~~~~~~~~~^~~ /usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::pair<long long int, int>; _Alloc = std::allocator<std::pair<long long int, int> >; value_type = std::pair<long long int, int>]' 1300 | push_back(value_type&& __x) | ^~~~~~~~~ /usr/include/c++/14/bits/stl_vector.h:1300:30: note: no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'std::vector<std::pair<long long int, int> >::value_type&&' {aka 'std::pair<long long int, int>&&'} 1300 | push_back(value_type&& __x) | ~~~~~~~~~~~~~^~~ a.cc:52:47: error: no matching function for call to 'std::vector<std::pair<long long int, int> >::push_back(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&)' 52 | F1(a,1,x.size())y.pb(x[a]%x[a-1]),y.pb(x[a]); | ~~~~^~~~~~ /usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, int>; _Alloc = std::allocator<std::pair<long long int, int> >; value_type = std::pair<long long int, int>]' 1283 | push_back(const value_type& __x) | ^~~~~~~~~ /usr/include/c++/14/bits/stl_vector.h:1283:35: note: no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'const std::vector<std::pair<long long int, int> >::value_type&' {aka 'const std::pair<long long int, int>&'} 1283 | push_back(const value_type& __x) | ~~~~~~~~~~~~~~~~~~^~~ /usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::pair<long long int, int>; _Alloc = std::allocator<std::pair<long long int, int> >; value_type = std::pair<long long int, int>]' 1300 | push_back(value_type&& __x) | ^~~~~~~~~ /usr/include/c++/14/bits/stl_vector.h:1300:30: note: no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'std::vector<std::pair<long long int, int> >::value_type&&' {aka 'std::pair<long long int, int>&&'} 1300 | push_back(value_type&& __x) | ~~~~~~~~~~~~~^~~
s109670019
p04023
C
#include "stdio.h" #include "climits" int i = 0; int j = 0; int far; int retu[100000]; int trynum; int getnum[100000]; int num[100000]; int start; int min(); int box; int little; int prev; int startbox; int cal; int main() { scanf("%d", &far); scanf("%d", &trynum); for (i = 0; i < trynum; i++) { scanf("%d", &getnum[i]); } start = 0; startbox = 0; prev = 0; for (i = 0; i < min(); i++) { if (i >= 100000) { num[i % 100000]++; } num[i]++; } little = min(); printf("%d\n\n", little); if (little >= 100000)little = 100000; prev = min();; start = startbox + 1 ; while (start != trynum) { for (i = 0; i < little; i++) { num[i] *= (min() / prev); } cal = min() % prev; for (i = 0; i < cal; i++) { num[i%little]++; } prev = min(); start = startbox+1; } for (i = 0; i < far; i++) { printf("%d\n",num[i]); } return 0; } int min() { box = INT_MAX; for (j = start; j < trynum; j++) { if (getnum[j] < box) { box = getnum[j]; startbox = j; } } return box; }
main.c:2:10: fatal error: climits: No such file or directory 2 | #include "climits" | ^~~~~~~~~ compilation terminated.
s744691017
p04023
C++
#include <iostream> #include <unordered_map> #include <algorithm> #include <vector> using namespace std; int N; vector<int> p; bool s[100005]; using pii = pair<long long int, int>; vector<pii> factor(long long int x) { vector<pii> f; for(long long int curp: p) { int dc = 0; while(x % curp == 0) { dc ++; x /= curp; } dc %= 3; if(dc != 0) { f.push_back(make_pair(curp, dc)); } } if(x != 1) { f.push_back(make_pair(x, 1)); } return f; } long long int a[100005]; vector<pii> fa[100005]; unordered_map<vector<pii>, int> m; vector<pii> dual(vector<pii> x) { vector<pii> d = x; for(int i = 0; i < d.size(); i++) { d[i].second = 3-d[i].second; } return d; } int main() { for(int i = 2; i <= 100000; i++) { if(!s[i]) { p.push_back(i); for(int j = i; j <= 100000; j += i) { s[j] = true; } } } cin >> N; for(int i = 0; i < N; i++) { cin >> a[i]; } for(int i = 0; i < N; i++) { fa[i] = factor(a[i]); /*for(auto x: fa[i]) { cerr << x.first << " " << x.second << " --- "; } cerr << "\n";*/ m[fa[i]]++; } int ans = 0; bool one = false; for(int i = 0; i < N; i++) { if(fa[i].size() == 0) { one = true; continue; } vector<pii> flip = dual(fa[i]); int c1 = m[flip]; int c2 = m[fa[i]]; //cerr << "Trying " << a[i] << " choose " << c1 << " " << c2 << "\n"; ans += max(c1, c2); m[flip] = 0; m[fa[i]] = 0; } if(one) { ans++; } cout << ans << "\n"; return 0; }
a.cc:36:33: error: use of deleted function 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = std::vector<std::pair<long long int, int> >; _Tp = int; _Hash = std::hash<std::vector<std::pair<long long int, int> > >; _Pred = std::equal_to<std::vector<std::pair<long long int, int> > >; _Alloc = std::allocator<std::pair<const std::vector<std::pair<long long int, int> >, int> >]' 36 | unordered_map<vector<pii>, int> m; | ^ In file included from /usr/include/c++/14/unordered_map:41, from a.cc:2: /usr/include/c++/14/bits/unordered_map.h:148:7: note: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = std::vector<std::pair<long long int, int> >; _Tp = int; _Hash = std::hash<std::vector<std::pair<long long int, int> > >; _Pred = std::equal_to<std::vector<std::pair<long long int, int> > >; _Alloc = std::allocator<std::pair<const std::vector<std::pair<long long int, int> >, int> >]' is implicitly deleted because the default definition would be ill-formed: 148 | unordered_map() = default; | ^~~~~~~~~~~~~ /usr/include/c++/14/bits/unordered_map.h:148:7: error: use of deleted function 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = std::vector<std::pair<long long int, int> >; _Value = std::pair<const std::vector<std::pair<long long int, int> >, int>; _Alloc = std::allocator<std::pair<const std::vector<std::pair<long long int, int> >, int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::vector<std::pair<long long int, int> > >; _Hash = std::hash<std::vector<std::pair<long long int, int> > >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>]' In file included from /usr/include/c++/14/bits/unordered_map.h:33: /usr/include/c++/14/bits/hashtable.h:539:7: note: 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = std::vector<std::pair<long long int, int> >; _Value = std::pair<const std::vector<std::pair<long long int, int> >, int>; _Alloc = std::allocator<std::pair<const std::vector<std::pair<long long int, int> >, int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::vector<std::pair<long long int, int> > >; _Hash = std::hash<std::vector<std::pair<long long int, int> > >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>]' is implicitly deleted because the default definition would be ill-formed: 539 | _Hashtable() = default; | ^~~~~~~~~~ /usr/include/c++/14/bits/hashtable.h:539:7: error: use of deleted function 'std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = std::vector<std::pair<long long int, int> >; _Value = std::pair<const std::vector<std::pair<long long int, int> >, int>; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::vector<std::pair<long long int, int> > >; _Hash = std::hash<std::vector<std::pair<long long int, int> > >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, false, true>]' In file included from /usr/include/c++/14/bits/hashtable.h:35: /usr/include/c++/14/bits/hashtable_policy.h:1731:7: note: 'std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = std::vector<std::pair<long long int, int> >; _Value = std::pair<const std::vector<std::pair<long long int, int> >, int>; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<std::vector<std::pair<long long int, int> > >; _Hash = std::hash<std::vector<std::pair<long long int, int> > >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, false, true>]' is implicitly deleted because the default definition would be ill-formed: 1731 | _Hashtable_base() = default; | ^~~~~~~~~~~~~~~ /usr/include/c++/14/bits/hashtable_policy.h:1731:7: error: use of deleted function 'std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_Hash_code_base() [with _Key = std::vector<std::pair<long long int, int> >; _Value = std::pair<const std::vector<std::pair<long long int, int> >, int>; _ExtractKey = std::__detail::_Select1st; _Hash = std::hash<std::vector<std::pair<long long int, int> > >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true]' /usr/include/c++/14/bits/hashtable_policy.h: In instantiation of 'std::__detail::_Hashtable_ebo_helper<_Nm, _Tp, true>::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash<std::vector<std::pair<long long int, int> > >]': /usr/include/c++/14/bits/hashtable_policy.h:1328:7: required from here 1328 | _Hash_code_base() = default; | ^~~~~~~~~~~~~~~ /usr/include/c++/14/bits/hashtable_policy.h:1245:49: error: use of deleted function 'std::hash<std::vector<std::pair<long long int, int> > >::hash()' 1245 | _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { } | ^~~~~ In file included from /usr/include/c++/14/string_view:50, from /usr/include/c++/14/bits/basic_string.h:47, from /usr/include/c++/14/string:54, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/bits/functional_hash.h:102:12: note: 'std::hash<std::vector<std::pair<long long int, int> > >::hash()' is implicitly deleted because the default definition would be ill-formed: 102 | struct hash : __hash_enum<_Tp> | ^~~~ /usr/include/c++/14/bits/functional_hash.h:102:12: error: no matching function for call to 'std::__hash_enum<std::vector<std::pair<long long int, int> >, false>::__hash_enum()' /usr/include/c++/14/bits/functional_hash.h:83:7: note: candidate: 'std::__hash_enum<_Tp, <anonymous> >::__hash_enum(std::__hash_enum<_Tp, <anonymous> >&&) [with _Tp = std::vector<std::pair<long long int, int> >; bool <anonymous> = false]' 83 | __hash_enum(__hash_enum&&); | ^~~~~~~~~~~ /usr/include/c++/14/bits/functional_hash.h:83:7: note: candidate expects 1 argument, 0 provided /usr/include/c++/14/bits/functional_hash.h:102:12: error: 'std::__hash_enum<_Tp, <anonymous> >::~__hash_enum() [with _Tp = std::vector<std::pair<long long int, int> >; bool <anonymous> = false]' is private within this context 102 | struct hash : __hash_enum<_Tp> | ^~~~ /usr/include/c++/14/bits/functional_hash.h:84:7: note: declared private here 84 | ~__hash_enum(); | ^ /usr/include/c++/14/bits/hashtable_policy.h:1245:49: note: use '-fdiagnostics-all-candidates' to display considered candidates 1245 | _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { } | ^~~~~ /usr/include/c++/14/bits/hashtable_policy.h:1328:7: note: 'std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_Hash_code_base() [with _Key = std::vector<std::pair<long long int, int> >; _Value = std::pair<const std::vector<std::pair<long long int, int> >, int>; _ExtractKey = std::__detail::_Select1st; _Hash = std::hash<std::vector<std::pair<long long int, int> > >; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true]' is implicitly deleted because the default definition would be ill-formed: 1328 | _Hash_code_base() = default; | ^~~~~~~~~~~~~~~ /usr/include/c++/14/bits/hashtable_policy.h:1328:7: error: use of deleted function 'std::__detail::_Hashtable_ebo_helper<1, std::hash<std::vector<std::pair<long long int, int> > >, true>::~_Hashtable_ebo_helper()' /usr/include/c++/14/bits/hashtable_policy.h:1242:12: note: 'std::__detail::_Hashtable_ebo_helper<1, std::hash<std::vector<std::pair<long long int, int> > >, true>::~_Hashtable_ebo_helper()' is implicitly deleted because the default definition would be ill-formed: 1242 | struct _Hashtable_ebo_helper<_Nm, _Tp, true> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/hashtable_policy.h:1242:12: error: use of deleted function 'std::hash<std::vector<std::pair<long long int, int> > >::~hash()' /usr/include/c++/14/bits/functional_hash.h:102:12: note: 'std::hash<std::vector<std::pair<long long int, int> > >::~hash()' is implicitly deleted because the default definition would be ill-formed: 102 | struct hash : __hash_enum<_Tp> | ^~~~ /usr/include/c++/14/bits/functional_hash.h:102:12: error: 'std::__hash_enum<_Tp, <anonymous> >::~__hash_enum() [with _Tp = std::vector<std::pair<long long int, int> >; bool <anonymous> = false]' is private within this context /usr/include/c++/14/bits/functional_hash.h:84:7: note: declared private here 84 | ~__hash_enum(); | ^ /usr/include/c++/14/bits/hashtable_policy.h:1731:7: note: use '-fdiagnostics-all-candidates' to display considered candidates 1731 | _Hashtable_base() = default; | ^~~~~~~~~~~~~~~ /usr/include/c++/14/bits/hashtable_policy.h:1731:7: error: use of deleted function 'std::__detail::_Hash_code_base<std::vector<std::pair<long long int, int> >, std::pair<const std::vector<std::pair<long long int, int> >, int>, std::__det
s955818770
p04024
C++
#include <cstdio> using namespace std; const int Mod = 1e9 + 7; int Ad(int x, int y) { return ((x + y) > Mod) ? (x + y - Mod) : (x + y); } int Dc(int x, int y) { return ((x - y) < 0) ? (x - y + Mod) : (x - y); } int Ml(int x, int y) { return (long long)x * y % Mod; } int ksm(int x, long long y) { int ret = 1; for (; y; y >>= 1, x = Ml(x, x)) if (y & 1ll) ret = Ml(ret, x); return ret; } struct Matrix { int r, c, A[2][2]; Matrix() : r(0), c(0) {} Matrix(int _r, int _c, int a00, int a01, int a10, int a11) : r(_r), c(_c) { A[0][0] = a00; A[0][1] = a01; A[1][0] = a10; A[1][1] = a11; } void Print() { printf("r : %d c : %d\n", r, c); for (int i = 0; i < r; ++i) { for (int j = 0; j < c; ++j) printf("%d ", A[i][j]); printf("\n"); } } }; Matrix operator*(const Matrix &a, const Matrix &b) { Matrix ret; ret.r = a.r; ret.c = b.c; for (int i = 0; i < ret.r; ++i) for (int j = 0; j < ret.c; ++j) { ret.A[i][j] = 0; for (int k = 0; k < a.c; ++k) ret.A[i][j] = Ad(ret.A[i][j], Ml(a.A[i][k], b.A[k][j])); } return ret; } void ksm(Matrix &ans, Matrix x, ll y) { for (; y; y >>= 1, x = x * x) if (y & 1) ans = ans * x; } int eup, edown, H, W, ud, lr; const int NH = 1e3 + 5; char base[NH][NH]; long long K; int main() { scanf("%d%d%lld", &H, &W, &K); for (int i = 1; i <= H; ++i) scanf("%s", base[i] + 1); for (int i = 1; i <= W; ++i) if (base[1][i] == '#') ud += (base[1][i] == base[H][i]); for (int i = 1; i <= H; ++i) if (base[i][1] == '#') lr += (base[i][1] == base[i][W]); if (ud && lr) printf("1\n"); else if (ud || lr) { Matrix ans(1, 2, 1, 1, 0, 0); int cnt = 0; for (int i = 1; i <= H; ++i) for (int j = 1; j <= W; ++j) cnt += (base[i][j] == '#'); int con = 0; if (ud) { for (int i = 2; i <= H; ++i) for (int j = 1; j <= W; ++j) if (base[i][j] == '#') con += (base[i][j] == base[i-1][j]); } else { for (int i = 1; i <= H; ++i) for (int j = 2; j <= W; ++j) if (base[i][j] == '#') con += (base[i][j] == base[i][j-1]); } Matrix b(2, 2, cnt, 0, Dc(0, con), ud | lr); ksm(ans, b, K-1); printf("%d\n", ans.A[0][0]); } else { int cnt = 0; for (int i = 1; i <= H; ++i) for (int j = 1; j <= W; ++j) cnt += (base[i][j] == '#'); printf("%d\n", ksm(cnt, K - 1)); } return 0; }
a.cc:44:33: error: 'll' has not been declared 44 | void ksm(Matrix &ans, Matrix x, ll y) { | ^~
s454562414
p04024
C++
#include<bits/stdc++.h> using namespace std; const int P=1e9+7; const int N=1e3+5; struct Mar{ int v[2][2]; }x,ans; Mar operator * (Mar x,Mar y){ Mar ans; for(int i=0;i<2;i++) for(int j=0;j<2;j++){ ans.v[i][j]=0; for(int k=0;k<2;k++) ans.v[i][j]=(ans.v[i][j]+1LL*x.v[i][k]*y.v[k][j])%P; } return ans; } long long fsp(long long x,long long y){ long long ans=1; while(y){ if(y&1) ans=ans*x%P; x=x*x%P,y>>=1; } return ans; } long long n; char s[N][N]; int h,w,s1,s2,rl,ud,cnt; int main(){ scanf("%d%d%lld",&h,&w,&n); for(int i=1;i<=h;i++) scanf("%s",s[i]+1); for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) if(s[i][j]=='#'){ s1+=s[i][j-1]=='#'; s2+=s[i-1][j]=='#'; ++cnt; } for(int i=1;i<=h;i++) if(s[i][1]=='#'&&s[i][w]=='#') ++rl; for(int i=1;i<=w;i++) if(s[1][i]=='#'&&s[h][i]=='#') ++ud; if((rl&&ud)||n<2){ puts("1"); return 0; } if(!rl&&!ud){ printf("%lld\n",fsp(cnt,n-1)); return 0; } if(ud) swap(s1,s2),swap(rl,ud); x.v[0][0]=cnt,x.v[0][1]=s1; x.v[1][1]=rl,ans.v[0][0]=ans.v[1][1]=1,--n; while(n){ if(n&1) ans=x*ans; x=x*x,n>>=1; } printf("%d\n",(ans.v[0][0]-ans.v[0][1]+P)%P); return 0; } #include<bits/stdc++.h> using namespace std; const int P=1e9+7; const int N=1e3+5; struct Mar{ int v[2][2]; }x,ans; Mar operator * (Mar x,Mar y){ Mar ans; for(int i=0;i<2;i++) for(int j=0;j<2;j++){ ans.v[i][j]=0; for(int k=0;k<2;k++) ans.v[i][j]=(ans.v[i][j]+1LL*x.v[i][k]*y.v[k][j])%P; } return ans; } long long fsp(long long x,long long y){ long long ans=1; while(y){ if(y&1) ans=ans*x%P; x=x*x%P,y>>=1; } return ans; } long long n; char s[N][N]; int h,w,s1,s2,rl,ud,cnt; int main(){ scanf("%d%d%lld",&h,&w,&n); for(int i=1;i<=h;i++) scanf("%s",s[i]+1); for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) if(s[i][j]=='#'){ s1+=s[i][j-1]=='#'; s2+=s[i-1][j]=='#'; ++cnt; } for(int i=1;i<=h;i++) if(s[i][1]=='#'&&s[i][w]=='#') ++rl; for(int i=1;i<=w;i++) if(s[1][i]=='#'&&s[h][i]=='#') ++ud; if((rl&&ud)||n<2){ puts("1"); return 0; } if(!rl&&!ud){ printf("%lld\n",fsp(cnt,n-1)); return 0; } if(ud) swap(s1,s2),swap(rl,ud); x.v[0][0]=cnt,x.v[0][1]=s1; x.v[1][1]=rl,ans.v[0][0]=ans.v[1][1]=1,--n; while(n){ if(n&1) ans=x*ans; x=x*x,n>>=1; } printf("%d\n",(ans.v[0][0]-ans.v[0][1]+P)%P); return 0; }
a.cc:65:11: error: redefinition of 'const int P' 65 | const int P=1e9+7; | ^ a.cc:3:11: note: 'const int P' previously defined here 3 | const int P=1e9+7; | ^ a.cc:66:11: error: redefinition of 'const int N' 66 | const int N=1e3+5; | ^ a.cc:4:11: note: 'const int N' previously defined here 4 | const int N=1e3+5; | ^ a.cc:67:8: error: redefinition of 'struct Mar' 67 | struct Mar{ | ^~~ a.cc:5:8: note: previous definition of 'struct Mar' 5 | struct Mar{ | ^~~ a.cc:69:2: error: conflicting declaration 'int x' 69 | }x,ans; | ^ a.cc:7:2: note: previous declaration as 'Mar x' 7 | }x,ans; | ^ a.cc:69:4: error: conflicting declaration 'int ans' 69 | }x,ans; | ^~~ a.cc:7:4: note: previous declaration as 'Mar ans' 7 | }x,ans; | ^~~ a.cc:70:5: error: redefinition of 'Mar operator*(Mar, Mar)' 70 | Mar operator * (Mar x,Mar y){ | ^~~~~~~~ a.cc:8:5: note: 'Mar operator*(Mar, Mar)' previously defined here 8 | Mar operator * (Mar x,Mar y){ | ^~~~~~~~ a.cc:80:11: error: redefinition of 'long long int fsp(long long int, long long int)' 80 | long long fsp(long long x,long long y){ | ^~~ a.cc:18:11: note: 'long long int fsp(long long int, long long int)' previously defined here 18 | long long fsp(long long x,long long y){ | ^~~ a.cc:88:11: error: redefinition of 'long long int n' 88 | long long n; | ^ a.cc:26:11: note: 'long long int n' previously declared here 26 | long long n; | ^ a.cc:89:6: error: redefinition of 'char s [1005][1005]' 89 | char s[N][N]; | ^ a.cc:27:6: note: 'char s [1005][1005]' previously declared here 27 | char s[N][N]; | ^ a.cc:90:5: error: redefinition of 'int h' 90 | int h,w,s1,s2,rl,ud,cnt; | ^ a.cc:28:5: note: 'int h' previously declared here 28 | int h,w,s1,s2,rl,ud,cnt; | ^ a.cc:90:7: error: redefinition of 'int w' 90 | int h,w,s1,s2,rl,ud,cnt; | ^ a.cc:28:7: note: 'int w' previously declared here 28 | int h,w,s1,s2,rl,ud,cnt; | ^ a.cc:90:9: error: redefinition of 'int s1' 90 | int h,w,s1,s2,rl,ud,cnt; | ^~ a.cc:28:9: note: 'int s1' previously declared here 28 | int h,w,s1,s2,rl,ud,cnt; | ^~ a.cc:90:12: error: redefinition of 'int s2' 90 | int h,w,s1,s2,rl,ud,cnt; | ^~ a.cc:28:12: note: 'int s2' previously declared here 28 | int h,w,s1,s2,rl,ud,cnt; | ^~ a.cc:90:15: error: redefinition of 'int rl' 90 | int h,w,s1,s2,rl,ud,cnt; | ^~ a.cc:28:15: note: 'int rl' previously declared here 28 | int h,w,s1,s2,rl,ud,cnt; | ^~ a.cc:90:18: error: redefinition of 'int ud' 90 | int h,w,s1,s2,rl,ud,cnt; | ^~ a.cc:28:18: note: 'int ud' previously declared here 28 | int h,w,s1,s2,rl,ud,cnt; | ^~ a.cc:90:21: error: redefinition of 'int cnt' 90 | int h,w,s1,s2,rl,ud,cnt; | ^~~ a.cc:28:21: note: 'int cnt' previously declared here 28 | int h,w,s1,s2,rl,ud,cnt; | ^~~ a.cc:91:5: error: redefinition of 'int main()' 91 | int main(){ | ^~~~ a.cc:29:5: note: 'int main()' previously defined here 29 | int main(){ | ^~~~
s706825135
p04024
C++
#include <bits/stdc++.h> using namespace std; typedef long long lint; #define int long long const int P = 1e9 + 7; int h, w, cnt, s1, s2, f1, f2; lint k; char s[1050][1050]; struct Maxtir { int a[10][10], n; void init(int _n, int x) {n = _n; memset(a, 0, sizeof a); for(int i = 1; i <= n; ++i) a[i][i] = x;} Maxtir operator *(const Maxtir &b) const { Maxtir c; c.init(n, 0); for(int i = 1; i <= n; ++i) for(int j = 1; j <= n; ++j) for(int k = 1; k <= n; ++k) c.a[i][j] = (c.a[i][j] + 1ll * a[i][k] * b.a[k][j] % P) % P; return c; } }; int pint(int a, lint b) { int res = 0; for(; b; a = 1ll*a*a%P, b>>=1) if(b&1) res=1ll*res*a%P; return res; } Maxtir pmax(Maxtir a, lint b) { Maxtir res; res.init(a.n, 1); for(; b; a = a * a, b >>= 1) if(b&1) res = res * a; return res; } signed main() { scanf("%lld%lld%lld", &h, &w, &k) for(int i = 1; i <= h; ++i) { scanf("%s", s[i]+1); for(int j = 1; j <= w; ++j) { //while(s[i][j] = getchar(), s[i][j] != '#' && s[i][j] != '.'); cnt += (s[i][j] == '#'); s1 += (s[i][j] == '#' && s[i][j-1] == '#'); s2 += (s[i][j] == '#' && s[i-1][j] == '#'); } f1 += (s[i][1] == '#' && s[i][w] == '#'); } for(int i = 1; i <= w; ++i) f2 += (s[1][i] == '#' && s[h][i] == '#'); if(f1 && f2) {puts("1"); return 0;} if(!f1 && !f2) {printf("%lld\n", pint(cnt, k-1)); return 0;} if(!f1) swap(f1, f2), swap(s1, s2); Maxtir ori; ori.init(2, 0); ori.a[1][1] = cnt; ori.a[2][1] = s1; ori.a[2][2] = f1; ori = pmax(ori, k-1); printf("%lld\n", (ori.a[1][1] - ori.a[2][1] + P) % P); }
a.cc: In function 'int main()': a.cc:31:42: error: expected ';' before 'for' 31 | scanf("%lld%lld%lld", &h, &w, &k) | ^ | ; 32 | for(int i = 1; i <= h; ++i) { | ~~~ a.cc:32:24: error: 'i' was not declared in this scope 32 | for(int i = 1; i <= h; ++i) { | ^
s869655561
p04024
C++
#include <iostream> #include <vector> #include <queue> #include <math.h> #include <set> #include <random> #include <map> #include <unordered_map> #define FOR(i, n, m) for(ll i = n; i < (int)m; i++) #define REP(i, n) FOR(i, 0, n) #define ALL(v) v.begin(), v.end() #define pb push_back using namespace std; using ll = std::int_fast64_t; using P = pair<ll, ll>; constexpr ll inf = 1000000000; constexpr ll mod = 1000000007; constexpr long double eps = 1e-15; template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1, T2> p) { os << to_string(p.first) << " " << to_string(p.second); return os; } template<typename T> ostream& operator<<(ostream& os, vector<T>& v) { REP(i, v.size()) { if(i) os << " "; os << to_string(v[i]); } return os; } struct modint { ll n; public: modint(const ll n = 0) : n((n % mod + mod) % mod) {} static modint pow(modint a, int m) { modint r = 1; while(m > 0) { if(m & 1) { r *= a; } a = (a * a); m /= 2; } return r; } modint &operator++() { *this += 1; return *this; } modint &operator--() { *this -= 1; return *this; } modint operator++(int) { modint ret = *this; *this += 1; return ret; } modint operator--(int) { modint ret = *this; *this -= 1; return ret; } modint operator~() const { return (this -> pow(n, mod - 2)); } // inverse friend bool operator==(const modint& lhs, const modint& rhs) { return lhs.n == rhs.n; } friend bool operator<(const modint& lhs, const modint& rhs) { return lhs.n < rhs.n; } friend bool operator>(const modint& lhs, const modint& rhs) { return lhs.n > rhs.n; } friend modint &operator+=(modint& lhs, const modint& rhs) { lhs.n += rhs.n; if (lhs.n >= mod) lhs.n -= mod; return lhs; } friend modint &operator-=(modint& lhs, const modint& rhs) { lhs.n -= rhs.n; if (lhs.n < 0) lhs.n += mod; return lhs; } friend modint &operator*=(modint& lhs, const modint& rhs) { lhs.n = (lhs.n * rhs.n) % mod; return lhs; } friend modint &operator/=(modint& lhs, const modint& rhs) { lhs.n = (lhs.n * (~rhs).n) % mod; return lhs; } friend modint operator+(const modint& lhs, const modint& rhs) { return modint(lhs.n + rhs.n); } friend modint operator-(const modint& lhs, const modint& rhs) { return modint(lhs.n - rhs.n); } friend modint operator*(const modint& lhs, const modint& rhs) { return modint(lhs.n * rhs.n); } friend modint operator/(const modint& lhs, const modint& rhs) { return modint(lhs.n * (~rhs).n); } }; istream& operator>>(istream& is, modint m) { is >> m.n; return is; } ostream& operator<<(ostream& os, modint m) { os << m.n; return os; } #define MAX_N 3030303 long long extgcd(long long a, long long b, long long& x, long long& y) { long long d = a; if (b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } long long mod_inverse(long long a, long long m) { long long x, y; if(extgcd(a, m, x, y) == 1) return (m + x % m) % m; else return -1; } vector<long long> fact(MAX_N+1, inf); long long mod_fact(long long n, long long& e) { if(fact[0] == inf) { fact[0]=1; if(MAX_N != 0) fact[1]=1; for(ll i = 2; i <= MAX_N; ++i) { fact[i] = (fact[i-1] * i) % mod; } } e = 0; if(n == 0) return 1; long long res = mod_fact(n / mod, e); e += n / mod; if((n / mod) % 2 != 0) return (res * (mod - fact[n % mod])) % mod; return (res * fact[n % mod]) % mod; } // return nCk long long mod_comb(long long n, long long k) { if(n < 0 || k < 0 || n < k) return 0; long long e1, e2, e3; long long a1 = mod_fact(n, e1), a2 = mod_fact(k, e2), a3 = mod_fact(n - k, e3); if(e1 > e2 + e3) return 0; return (a1 * mod_inverse((a2 * a3) % mod, mod)) % mod; } using mi = modint; mi mod_pow(ll a, ll n) { mi ret = 1; mi tmp = a; while(n > 0) { if(n % 2) ret *= tmp; tmp = tmp * tmp; n /= 2; } return ret; } ll h, w, k; vector<string> s; int r(vector<string>& s) { int ret = 0; REP(i, h) if(s[i][0] == '#' && s[i][w - 1] == '#') ret++; return ret; } int c(vector<string>& s) { int ret = 0;; REP(i, w) if(s[0][i] == '#' && s[h - 1][i] == '#') ret++; return ret; } vector<vector<mi>> matprod(vector<vector<mi>>& a, vector<vector<mi>>& b) { vector<vector<mi>> ret = {{0, 0}, {0, 0}}; REP(i, 2) REP(j, 2) REP(k, 2) { ret[i][j] += a[i][k] * b[k][j]; } return ret; } vector<vector<mi>> matpow(vector<vector<mi>>& mat, ll a) { vector<vector<mi>> ret = {{1, 0}, {0, 1}}; vector<vector<mi>> tmp = mat; while(a > 0) { if(a % 2) ret = matprod(ret, tmp); tmp = matprod(tmp, tmp); a /= 2; } return ret; } void solve(vector<string> s) { int cnt1 = r(s), cnt2 = 0; REP(i, h) REP(j, w) if(s[i][j] == '#') cnt2++; int coe = 0; REP(i, h) REP(j, w - 1) { if(s[i][j] == '#' && s[i][j + 1] == '#') coe++; } vector<vector<mi>> mat = {{cnt2, -coe}, {0, cnt1}}; vector<vector<mi>> ans = matpow(mat, k - 1); cout << ans[0][0] * 1 + ans[0][1] * 1 << endl; return; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> h >> w >> k; s.resize(h); REP(i, h) cin >> s[i]; if(k == 0) { cout << 1 << endl; return 0; } int cnt = 0; REP(i, h) REP(j, w) if(s[i][j] == '#') cnt++; if(r(s) && c(s)) { cout << 1 << endl; return 0; } if(!r(s) && !c(s)) { cout << mod_pow(cnt, k - 1) << endl; return 0; } if(r()) { solve(s); } else { vector<string> ss; REP(i, w) { string str = ""; REP(j, h) str += s[j][i]; ss.pb(str); } swap(h, w); solve(ss); } return 0; }
a.cc: In function 'int main()': a.cc:215:9: error: too few arguments to function 'int r(std::vector<std::__cxx11::basic_string<char> >&)' 215 | if(r()) { | ~^~ a.cc:151:5: note: declared here 151 | int r(vector<string>& s) { | ^
s420041357
p04024
C++
#include <bits/stdc++.h> #define IL __inline__ __attribute__((always_inline)) #define For(i, a, b) for (int i = a, i##end = b; i <= i##end; ++ i) #define FOR(i, a, b) for (int i = a, i##end = b; i < i##end; ++ i) #define Rep(i, a, b) for (int i = a, i##end = b; i >= i##end; -- i) #define REP(i, a, b) for (int i = (a) - 1, i##end = b; i >= i##end; -- i) typedef long long LL; template <class T> IL bool chkmax(T &a, const T &b) { return a < b ? ((a = b), 1) : 0; } template <class T> IL bool chkmin(T &a, const T &b) { return a > b ? ((a = b), 1) : 0; } template <class T> IL T mymax(const T &a, const T &b) { return a > b ? a : b; } template <class T> IL T mymin(const T &a, const T &b) { return a < b ? a : b; } template <class T> IL T myabs(const T &a) { return a > 0 ? a : -a; } const int INF = 0X3F3F3F3F; const double EPS = 1E-10, PI = acos(-1.0); #define DEBUG(...) fprintf(stderr, __VA_ARGS__) #define OK DEBUG("Passing [%s] in LINE %d...\n", __FUNCTION__, __LINE__) /*------------------------------header------------------------------*/ const int MAXN = 1000 + 5, MOD = 1000000007; IL int add(int a, int b) { a += b; return a >= MOD ? a - MOD : a; } IL int mul(int a, int b) { return (LL)a * b % MOD; } IL int quickPow(int a, LL p) { int result = 1; for (int base = a; p; p >>= 1, base = mul(base, base)) { if (p & 1) { result = mul(result, base); } } return result; } template<int N> struct Matrix { int det[N][N]; Matrix() { memset(det, 0, sizeof det); } int *operator[](int x) { return det[x]; } const int *operator[](int x) const { return det[x]; } friend Matrix &operator*=(Matrix &a, const Matrix &b) { static Matrix<N> x; FOR(i, 0, N) { FOR(j, 0, N) { x[i][j] = 0; FOR(k, 0, N) { x[i][j] = add(x[i][j], mul(a[i][k], b[k][j])); } } } return a = x; } }; IL int solve(int x, int y, int z, LL p) { Matrix<2> result, base; result[0][0] = result[1][1] = 1; base[0][0] = x, base[0][1] = y, base[1][1] = z; for (; p; p >>= 1, base *= base) { if (p & 1) { result *= base; } } return add(result[0][0], result[0][1]); } char str[MAXN][MAXN]; int main() { int n, m; LL k; scanf("%d%d%lld", &n, &m, &k); if (k <= 1) { puts("1"); exit(0); } int num = 0; For(i, 1, n) { scanf("%s", str[i] + 1); For(j, 1, m) { num += str[i][j] == '#'; } } int adj_r = 0, adj_c = 0, n_r = 0, n_c = 0; For(i, 1, n) { FOR(j, 1, m) { if (str[i][j] == '#' && str[i][j + 1] == '#') { ++ adj_r; } } if (str[i][1] == '#' && str[i][m] == '#') { ++ n_r; } row |= ok; } For(i, 1, m) { FOR(j, 1, n) { if (str[j][i] == '#' && str[j + 1][i] == '#') { ++ adj_c; } } if (str[1][i] == '#' && str[n][i] == '#') { ++ n_c; } } if (n_r && n_c) { puts("1"); } else if (!n_r && !n_c) { printf("%d\n", quickPow(num, k - 1)); } else if (n_r) { printf("%d\n", solve(num, MOD - adj_r, n_r, k - 1)); } else { printf("%d\n", solve(num, MOD - adj_c, n_c, k - 1)); } return 0; }
a.cc: In function 'int main()': a.cc:134:5: error: 'row' was not declared in this scope; did you mean 'pow'? 134 | row |= ok; | ^~~ | pow a.cc:134:12: error: 'ok' was not declared in this scope; did you mean 'k'? 134 | row |= ok; | ^~ | k
s158321140
p04024
C++
11 15 1000000000000000000 .....#......... ....###........ ....####....... ...######...... ...#######..... ..##.###.##.... ..##########... .###.....####.. .####...######. ############### #.##..##..##..#
a.cc:2:6: error: stray '#' in program 2 | .....#......... | ^ a.cc:3:5: error: stray '##' in program 3 | ....###........ | ^~ a.cc:3:7: error: stray '#' in program 3 | ....###........ | ^ a.cc:4:5: error: stray '##' in program 4 | ....####....... | ^~ a.cc:4:7: error: stray '##' in program 4 | ....####....... | ^~ a.cc:5:4: error: stray '##' in program 5 | ...######...... | ^~ a.cc:5:6: error: stray '##' in program 5 | ...######...... | ^~ a.cc:5:8: error: stray '##' in program 5 | ...######...... | ^~ a.cc:6:4: error: stray '##' in program 6 | ...#######..... | ^~ a.cc:6:6: error: stray '##' in program 6 | ...#######..... | ^~ a.cc:6:8: error: stray '##' in program 6 | ...#######..... | ^~ a.cc:6:10: error: stray '#' in program 6 | ...#######..... | ^ a.cc:7:3: error: stray '##' in program 7 | ..##.###.##.... | ^~ a.cc:7:6: error: stray '##' in program 7 | ..##.###.##.... | ^~ a.cc:7:8: error: stray '#' in program 7 | ..##.###.##.... | ^ a.cc:7:10: error: stray '##' in program 7 | ..##.###.##.... | ^~ a.cc:8:3: error: stray '##' in program 8 | ..##########... | ^~ a.cc:8:5: error: stray '##' in program 8 | ..##########... | ^~ a.cc:8:7: error: stray '##' in program 8 | ..##########... | ^~ a.cc:8:9: error: stray '##' in program 8 | ..##########... | ^~ a.cc:8:11: error: stray '##' in program 8 | ..##########... | ^~ a.cc:9:2: error: stray '##' in program 9 | .###.....####.. | ^~ a.cc:9:4: error: stray '#' in program 9 | .###.....####.. | ^ a.cc:9:10: error: stray '##' in program 9 | .###.....####.. | ^~ a.cc:9:12: error: stray '##' in program 9 | .###.....####.. | ^~ a.cc:10:2: error: stray '##' in program 10 | .####...######. | ^~ a.cc:10:4: error: stray '##' in program 10 | .####...######. | ^~ a.cc:10:9: error: stray '##' in program 10 | .####...######. | ^~ a.cc:10:11: error: stray '##' in program 10 | .####...######. | ^~ a.cc:10:13: error: stray '##' in program 10 | .####...######. | ^~ a.cc:11:1: error: stray '##' in program 11 | ############### | ^~ a.cc:11:3: error: stray '##' in program 11 | ############### | ^~ a.cc:11:5: error: stray '##' in program 11 | ############### | ^~ a.cc:11:7: error: stray '##' in program 11 | ############### | ^~ a.cc:11:9: error: stray '##' in program 11 | ############### | ^~ a.cc:11:11: error: stray '##' in program 11 | ############### | ^~ a.cc:11:13: error: stray '##' in program 11 | ############### | ^~ a.cc:11:15: error: stray '#' in program 11 | ############### | ^ a.cc:12:2: error: invalid preprocessing directive #. 12 | #.##..##..##..# | ^ a.cc:1:1: error: expected unqualified-id before numeric constant 1 | 11 15 1000000000000000000 | ^~
s362120097
p04024
C++
11 15 1000000000000000000 .....#......... ....###........ ....####....... ...######...... ...#######..... ..##.###.##.... ..##########... .###.....####.. .####...######. ############### #.##..##..##..#
a.cc:2:6: error: stray '#' in program 2 | .....#......... | ^ a.cc:3:5: error: stray '##' in program 3 | ....###........ | ^~ a.cc:3:7: error: stray '#' in program 3 | ....###........ | ^ a.cc:4:5: error: stray '##' in program 4 | ....####....... | ^~ a.cc:4:7: error: stray '##' in program 4 | ....####....... | ^~ a.cc:5:4: error: stray '##' in program 5 | ...######...... | ^~ a.cc:5:6: error: stray '##' in program 5 | ...######...... | ^~ a.cc:5:8: error: stray '##' in program 5 | ...######...... | ^~ a.cc:6:4: error: stray '##' in program 6 | ...#######..... | ^~ a.cc:6:6: error: stray '##' in program 6 | ...#######..... | ^~ a.cc:6:8: error: stray '##' in program 6 | ...#######..... | ^~ a.cc:6:10: error: stray '#' in program 6 | ...#######..... | ^ a.cc:7:3: error: stray '##' in program 7 | ..##.###.##.... | ^~ a.cc:7:6: error: stray '##' in program 7 | ..##.###.##.... | ^~ a.cc:7:8: error: stray '#' in program 7 | ..##.###.##.... | ^ a.cc:7:10: error: stray '##' in program 7 | ..##.###.##.... | ^~ a.cc:8:3: error: stray '##' in program 8 | ..##########... | ^~ a.cc:8:5: error: stray '##' in program 8 | ..##########... | ^~ a.cc:8:7: error: stray '##' in program 8 | ..##########... | ^~ a.cc:8:9: error: stray '##' in program 8 | ..##########... | ^~ a.cc:8:11: error: stray '##' in program 8 | ..##########... | ^~ a.cc:9:2: error: stray '##' in program 9 | .###.....####.. | ^~ a.cc:9:4: error: stray '#' in program 9 | .###.....####.. | ^ a.cc:9:10: error: stray '##' in program 9 | .###.....####.. | ^~ a.cc:9:12: error: stray '##' in program 9 | .###.....####.. | ^~ a.cc:10:2: error: stray '##' in program 10 | .####...######. | ^~ a.cc:10:4: error: stray '##' in program 10 | .####...######. | ^~ a.cc:10:9: error: stray '##' in program 10 | .####...######. | ^~ a.cc:10:11: error: stray '##' in program 10 | .####...######. | ^~ a.cc:10:13: error: stray '##' in program 10 | .####...######. | ^~ a.cc:11:1: error: stray '##' in program 11 | ############### | ^~ a.cc:11:3: error: stray '##' in program 11 | ############### | ^~ a.cc:11:5: error: stray '##' in program 11 | ############### | ^~ a.cc:11:7: error: stray '##' in program 11 | ############### | ^~ a.cc:11:9: error: stray '##' in program 11 | ############### | ^~ a.cc:11:11: error: stray '##' in program 11 | ############### | ^~ a.cc:11:13: error: stray '##' in program 11 | ############### | ^~ a.cc:11:15: error: stray '#' in program 11 | ############### | ^ a.cc:12:2: error: invalid preprocessing directive #. 12 | #.##..##..##..# | ^ a.cc:1:1: error: expected unqualified-id before numeric constant 1 | 11 15 1000000000000000000 | ^~
s043291714
p04024
C++
#include<algorithm> using namespace std; const int N = 1005, P = 1e9 + 7; int h, w, num, o1, o2, s; using ll = long long; ll k; char m[N][N]; int qp (int a, ll b) { int c = 1; for (; b; b >>= 1, a = 1ll * a * a % P) if (b & 1) c = 1ll * c * a % P; return c; } struct Matrix { int T[2][2]; Matrix () { T[0][0] = T[0][1] = T[1][0] = T[1][1] = 0; } }S, T; void Mul (Matrix &CC, const Matrix &A, const Matrix &B) { static Matrix C; C.T[0][0] = (1ll * A.T[0][0] * B.T[0][0] + 1ll * A.T[0][1] * B.T[1][0]) % P; C.T[0][1] = (1ll * A.T[0][0] * B.T[0][1] + 1ll * A.T[0][1] * B.T[1][1]) % P; C.T[1][0] = (1ll * A.T[1][0] * B.T[0][0] + 1ll * A.T[1][1] * B.T[1][0]) % P; C.T[1][1] = (1ll * A.T[1][0] * B.T[0][1] + 1ll * A.T[1][1] * B.T[1][1]) % P; CC = C; } void mqp (const Matrix &AA, Matrix &CC, ll b) { static Matrix A, C; C = A = AA; --b; for (; b; b >>= 1, Mul(A, A, A)) if (b & 1) Mul(C, C, A); CC = C; } int main () { scanf("%d%d%lld", &h, &w, &k); if (k <= 1) return puts("1"), 0; --k; for (int i = 1; i <= h; ++i) { scanf("%s", m[i] + 1); for (int j = 1; j <= w; ++j) if (m[i][j] == '#') { ++num; if (j > 1 && m[i][j - 1] == '#') ++s; } } for (int i = 1; i <= h; ++i) if (m[i][1] == '#' && m[i][w] == '#') ++o1; for (int i = 1; i <= w; ++i) if (m[1][i] == '#' && m[h][i] == '#') ++o2; if (o1 > o2) o1 ^= o2 ^= o1 ^= o2; if (o1) return puts("1"), 0; if (!o2) return printf("%d\n", qp(num, k)), 0; T.T[0][0] = o2; T.T[1][0] = s; T.T[1][1] = num; S.T[0][0] = 0; S.T[0][1] = 1; mqp(T, T, k); // for (int i = 1; i <= k; ++i) // Mul(S, S, T); Mul(S, S, T); printf("%d\n", (S.T[0][1] - S.T[0][0] + P) % P); return 0; } /* 5 5 10000000000000000 #.#.# ##### .###. ##### #.#.# */
a.cc: In function 'int main()': a.cc:35:9: error: 'scanf' was not declared in this scope 35 | scanf("%d%d%lld", &h, &w, &k); | ^~~~~ a.cc:36:28: error: 'puts' was not declared in this scope 36 | if (k <= 1) return puts("1"), 0; --k; | ^~~~ a.cc:48:24: error: 'puts' was not declared in this scope 48 | if (o1) return puts("1"), 0; | ^~~~ a.cc:49:25: error: 'printf' was not declared in this scope 49 | if (!o2) return printf("%d\n", qp(num, k)), 0; | ^~~~~~ a.cc:2:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>' 1 | #include<algorithm> +++ |+#include <cstdio> 2 | using namespace std; a.cc:56:9: error: 'printf' was not declared in this scope 56 | printf("%d\n", (S.T[0][1] - S.T[0][0] + P) % P); | ^~~~~~ a.cc:56:9: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
s544412858
p04024
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; typedef pair<int,P> P1; typedef pair<P,P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define mod 1000000007 #define fi first #define sc second #define rep(i,x) for(int i=0;i<x;i++) #define repn(i,x) for(int i=1;i<=x;i++) #define SORT(x) sort(x.begin(),x.end()) #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end()) #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) ll modpow(ll x,ll n) { ll res=1; while(n>0) { if(n&1) res=res*x%mod; x=x*x%mod; n>>=1; } return res; } int n,m; ll k; char f[2005][1005]; int main(){ scanf("%d%d",&n,&m); cin>>M; if(M<=1){ puts("1"); return 0;} for(int i=0;i<n;i++) scanf("%s",&f[i]); bool tate=0,yoko=0; for(int i=0;i<n;i++){ if(f[i][0]=='#' && f[i][m-1]=='#'){ yoko = 1; } } for(int i=0;i<m;i++){ if(f[0][i]=='#' && f[n-1][i]=='#'){ tate = 1; } } if(yoko&&tate){ puts("1"); return 0; } if(!yoko&&!tate){ ll ans = 0; for(int i=0;i<n;i++) for(int j=0;j<m;j++) ans+=f[i][j]=='#'; cout<<modpow(ans,M-1)<<endl; return 0; } if(yoko){ ll val = 0,c = 0; for(int i=0;i<n;i++){ for(int j=0;j<m-1;j++){ if(f[i][j]=='#' && f[i][j+1]=='#'){ val++; } } for(int j=0;j<m;j++) c+=f[i][j]=='#'; } ll ans = modpow(c,k-1); ll x = val * modpow(c,k-2)%mod; ll y = val * modpow(c,mod-2) % mod; //x+...x*y^(k-2) ll z; if(y==1) z = k-1; else z = (modpow(y,k-1)-1)*modpow(y-1,mod-2)%mod; cout<<(ans-x*z%mod+mod)%mod<<endl; } else{ ll val = 0,c = 0; for(int i=0;i<n-1;i++){ for(int j=0;j<m;j++){ if(f[i][j]=='#' && f[i+1][j]=='#'){ val++; } } for(int j=0;j<m;j++) c+=f[i][j]=='#'; } ll ans = modpow(c,k-1); ll x = val * modpow(c,k-2)%mod; ll y = val * modpow(c,mod-2) % mod; //x+...x*y^(k-2) ll z; if(y==1) z = k-1; else z = (modpow(y,k-1)-1)*modpow(y-1,mod-2)%mod; cout<<(ans-x*z%mod+mod)%mod<<endl; } }
a.cc: In function 'int main()': a.cc:34:35: error: 'M' was not declared in this scope 34 | scanf("%d%d",&n,&m); cin>>M; | ^
s788777928
p04024
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; typedef pair<int,P> P1; typedef pair<P,P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define mod 1000000007 #define fi first #define sc second #define rep(i,x) for(int i=0;i<x;i++) #define repn(i,x) for(int i=1;i<=x;i++) #define SORT(x) sort(x.begin(),x.end()) #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end()) #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) ll modpow(ll x,ll n) { ll res=1; while(n>0) { if(n&1) res=res*x%mod; x=x*x%mod; n>>=1; } return res; } int n,m; ll M; char f[2005][1005]; int main(){ scanf("%d%d",&n,&m); cin>>M; if(M<=1){ puts("1"); return 0;} for(int i=0;i<n;i++) scanf("%s",&f[i]); bool tate=0,yoko=0; for(int i=0;i<n;i++){ if(f[i][0]=='#' && f[i][m-1]=='#'){ yoko = 1; } } for(int i=0;i<m;i++){ if(f[0][i]=='#' && f[n-1][i]=='#'){ tate = 1; } } if(yoko&&tate){ puts("1"); return 0; } if(!yoko&&!tate){ ll ans = 0; for(int i=0;i<n;i++) for(int j=0;j<m;j++) ans+=f[i][j]=='#'; cout<<modpow(ans,M-1)<<endl; return 0; } if(yoko){ ll val = 0,c = 0; for(int i=0;i<n;i++){ for(int j=0;j<m-1;j++){ if(f[i][j]=='#' && f[i][j+1]=='#'){ val++; } } for(int j=0;j<m;j++) c+=f[i][j]=='#'; } ll ans = modpow(c,k-1); ll x = val * modpow(c,k-2)%mod; ll y = val * modpow(c,mod-2) % mod; //x+...x*y^(k-2) ll z; if(y==1) z = k-1; else z = (modpow(y,k-1)-1)*modpow(y-1,mod-2)%mod; cout<<(ans-x*z%mod+mod)%mod<<endl; } else{ ll val = 0,c = 0; for(int i=0;i<n-1;i++){ for(int j=0;j<m;j++){ if(f[i][j]=='#' && f[i+1][j]=='#'){ val++; } } for(int j=0;j<m;j++) c+=f[i][j]=='#'; } ll ans = modpow(c,k-1); ll x = val * modpow(c,k-2)%mod; ll y = val * modpow(c,mod-2) % mod; //x+...x*y^(k-2) ll z; if(y==1) z = k-1; else z = (modpow(y,k-1)-1)*modpow(y-1,mod-2)%mod; cout<<(ans-x*z%mod+mod)%mod<<endl; } }
a.cc: In function 'int main()': a.cc:66:35: error: 'k' was not declared in this scope 66 | ll ans = modpow(c,k-1); | ^ a.cc:85:35: error: 'k' was not declared in this scope 85 | ll ans = modpow(c,k-1); | ^
s010999416
p04024
C
//ProblemD.cpp #include <iostream> static std::istream & ip = std::cin; static std::ostream & op = std::cout; #if OJ_MYPC #include <ojio.h> #endif #ifndef OPENOJIO #define OPENOJIO #endif #if 1 || DEFINE /***************************************************************/ typedef unsigned long long u64; typedef long long s64; typedef unsigned uint; #define ABS(x) ((x) > 0 ? (x) : -(x)) #define MIN(x, y) ((x) < (y) ? (x) : (y)) #define MAX(x, y) ((x) > (y) ? (x) : (y)) #define MIN3(x, y, z) MIN(x, MIN(y, z)) #define MAX3(x, y, z) MAX(x, MAX(y, z)) #define FillZero(arr) memset(arr, 0, sizeof(arr)); /***************************************************************/ #endif //1 || DEFINE #include <string> #include <vector> #include <map> #include <set> #include <bitset> #include <queue> #include <stack> #include <utility> #include <algorithm> #include <iomanip> #include <cstring> #include <cmath> #include <cstdio> //001 //op << setfill('0') << setw(3) << setiosflags(ios::right) << 1; //op << fixed << setprecision(20); using namespace std; //ProblemD.cpp /* a[1] = a, b[1] = b, c[1] = c a[n+1] = a[n]*a = a^n b[n+1] = a[n]*b + b[n]*c c[n+1] = c[n]*c = c^n -> b[n+1] = b(a^(n-1) + b(a^(n-2))+...+b^(n-1)) = b * (a^n - c^n)) / (a - c) = b * (a^n - c^n) * k ((a-c) * k = 1(mod p)) x[n+1] = a[n+1] - b[n+1] */ #define MOD 1000000007 static s64 getpow(s64 a, s64 x, s64 m = MOD) { if (x == 0) return 1; a = a % m; if (a < 0) a += m; s64 mul = a; s64 rst = 1; while (x) { if (x & 1) rst = rst * mul % m; x >>= 1; mul = mul * mul % m; } return rst; } #define MAXSIZE 1010 int main(int argc, char* argv[]) { OPENOJIO; int h, w; s64 k; ip >> h >> w >> k; s64 a, bx, cx, by, cy; a = bx = cx = by = cy = 0; static int s[MAXSIZE][MAXSIZE]; for(int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) { char tc; ip >> tc; s[i][j] = tc == '#'; a += s[i][j]; } for (int i = 0; i < h; ++i) { if (s[i][0] && s[i][w - 1]) ++cx; for (int j = 0; j < w - 1; ++j) { if (s[i][j] && s[i][j + 1]) ++bx; } } for (int j = 0; j < w; ++j) { if (s[0][j] && s[h - 1][j]) ++cy; for (int i = 0; i < h - 1; ++i) { if (s[i][j] && s[i + 1][j]) ++by; } } s64 rst = 1; if (k <= 1) rst = 1; else if (cx > 0 && cy > 0) rst = 1; else if (cx == 0 && cy == 0) { rst = getpow(a, k - 1); } else { s64 b, c; if (cx > 0) { b = bx; c = cx; } else { b = by; c = cy; } s64 ak = getpow(a, k - 1); s64 ck = getpow(c, k - 1); s64 a_c = a - c; s64 inv = getpow(a_c, MOD - 2); s64 bk = (ak - ck) % MOD * b % MOD * inv % MOD; rst = (ak - bk) % MOD; if (rst < 0) rst += MOD; } cout << rst << endl; return 0; } /***************************************************************/
main.c:3:10: fatal error: iostream: No such file or directory 3 | #include <iostream> | ^~~~~~~~~~ compilation terminated.
s134743587
p04024
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define forn(i, a, n) for (int i = a; i < n; ++i) #define ford(i, a, n) for (int i = n - 1; i >= a; --i) #define fore(i, a, n) for (int i = a; i <= n; ++i) #define all(a) (a).begin(), (a).end() #define fs first #define sn second #define trace(a)\ for (auto i : a) cerr << i << ' ';\ cerr << '\n' #define eb emplace_back #ifndef M_PI const ld M_PI = acos(-1.0); #endif const ld eps = 1e-9; const int INF = 2000000000; const ll LINF = 1ll * INF * INF; const ll MOD = 1000000007; struct Matrix { ll a[2][2]; Matrix () {}; Matrix (int cells, int inBound, int outBound) { a[0][0] = cells; a[0][1] = -inBound; if (a[0][1] < 0) a[0][1] += MOD; a[1][0] = 0; a[1][1] = outBound; } Matrix operator* (Matrix other) { Matrix m(0, 0, 0); forn(i, 0, 2) forn(j, 0, 2) forn(k, 0, 2) { m.a[i][k] += a[i][j] * other.a[j][k]; m.a[i][k] %= MOD; } return m; } Matrix Pow (ll k) { Matrix x = *this, y = Matrix(1, 0, 1); while (k) { if (k % 2) y = x * y; x = x * x; k /= 2; } return y; } }; ll Pow (ll n, ll k) { ll x = n, y = 1; while (k) { if (k % 2) y = y * x % MOD; x = x * x % MOD; k /= 2; } return y; } const int N = 1002; char a[N][N]; int main() { ios::sync_with_stdio(false); cin.tie(0); int h, w; ll k; cin >> h >> w >> k; if (k <= 1) { cout << "1\n"; return 0; } forn(i, 0, h) gets(a[i]); bool ver = false, hor = false; forn(i, 0, h) if (a[i][0] == '#' && a[i][w - 1] == '#') hor = true; forn(i, 0, w) if (a[0][i] == '#' && a[h - 1][i] == '#') ver = true; if (hor && ver) { cout << "1\n"; return 0; } int sz = 0; forn(i, 0, h) forn(j, 0, w) if (a[i][j] == '#') ++sz; if (!hor && !ver) { cout << Pow(sz, k - 1) << '\n'; return 0; } if (ver) { forn(i, 0, N) forn(j, 0, i) swap(a[i][j], a[j][i]); swap(h, w); } int in = 0; forn(i, 0, h) forn(j, 0, w - 1) if (a[i][j] == '#' && a[i][j + 1] == '#') ++in; int out = 0; forn(i, 0, h) if (a[i][0] == '#' && a[i][w - 1] == '#') ++out; Matrix M = Matrix(sz, in, out); Matrix P = M.Pow(k - 1); cout << (P.a[0][0] + P.a[0][1]) % MOD << '\n'; return 0; }
a.cc: In function 'int main()': a.cc:84:23: error: 'gets' was not declared in this scope; did you mean 'getw'? 84 | forn(i, 0, h) gets(a[i]); | ^~~~ | getw
s898091929
p04025
C++
#include <bits/stdc++.h> using namespace std; #define llong long long #define len(x) ((int)x.size()) #define rep(i,n) for (int i = -1; ++ i < n; ) #define rep1(i,n) for (int i = 0; i ++ < n; ) #define rand __rand mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); // or mt19937_64 template<class T = int> T rand(T range = numeric_limits<T>::max()) { return (T)(rng() % range); } #define CONCAT_(x, y) x##y/*{{{*/ #define CONCAT(x, y) CONCAT_(x, y) #ifdef LOCAL_DEBUG int __db_level = 0; bool __db_same_line = false; #define clog cerr << string(!__db_same_line ? __db_level * 2 : 0, ' ') struct debug_block { function<void()> fn; void print_name() { __db_same_line = true; fn(); clog << endl; __db_same_line = false; } debug_block(function<void()> fn_): fn(fn_) { clog << "{ "; print_name(); ++__db_level; } ~debug_block() { --__db_level; clog << "} "; print_name(); } }; #define DB(args...) debug_block CONCAT(dbbl, __LINE__)([=]{ clog << args; }) #define deb(...) if (1) { (clog << "[" #__VA_ARGS__ "] = [" << __VA_ARGS__) << "]"; if (!__db_same_line) clog << endl; } #else #define clog if (0) cerr #define DB(...) #define deb(...) #endif template<class T> ostream& operator,(ostream& out, const T& thing) { return out << ", " << thing; } template<class U, class V> ostream& operator<<(ostream& out, const pair<U, V>& p) { return (out << "(" << p.first, p.second) << ")"; } template<class A, class B> ostream& operator<<(ostream& out, const tuple<A, B>& t) { return (out << "(" << get<0>(t), get<1>(t)) << ")"; } template<class A, class B, class C> ostream& operator<<(ostream& out, const tuple<A, B, C>& t) { return (out << "(" << get<0>(t), get<1>(t), get<2>(t)) << ")"; } template<class T> ostream& operator<<(ostream& out, const vector<T>& container) { out << "{"; if (len(container)) out << container[0]; rep1(i, len(container) - 1) out, container[i]; return out << "}"; } template<class x> vector<typename x::value_type> $v(const x& a) { return vector<typename x::value_type>(a.begin(), a.end()); } #define ptrtype(x) typename iterator_traits<x>::value_type template<class u> vector<ptrtype(u)> $v(u a, u b) { return vector<ptrtype(u)>(a, b); }/*}}}*/ // ACTUAL SOLUTION BELOW //////////////////////////////////////////////////////////// const int maxn = 111; int n; llong a[maxn]; int main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; rep(i, n) cin >> a[i]; llong ans = LLONG_MAX; for (llong m = -100; m <= 100; ++m) { llong cur_ans = 0; rep(i, n) cur_ans += (a[i] - m) * (a[i] - m); ans = min(ans, cur_ans); } cout << ans return 0; } // Remember: // - Multitest? REFRESHING the data!!! // - Constrains for each set of data may differs. Should NOT USE the same max constant (maxn) // for all of them. // vim: foldmethod=marker
a.cc: In function 'int main()': a.cc:65:16: error: expected ';' before 'return' 65 | cout << ans | ^ | ; ...... 68 | return 0; | ~~~~~~
s251541359
p04025
C++
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0;i < (n);i++) using namespace std; using ll = long long; using pii = pair<int,int>; const int INF = 2e9; int main(){ int n; cin >> n; vector<int> a[n]; rep(i,n) cin >> a[i]; ll ans = INF; for(int i = -100;i <= 100;i++){ ll sum = 0; rep(j,n){ sum += (a[i] - j) * (a[i] - j); } ans = min(ans,sum); } cout << sum << endl; }
a.cc: In function 'int main()': a.cc:13:18: error: no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'std::vector<int>') 13 | rep(i,n) cin >> a[i]; | ~~~ ^~ ~~~~ | | | | | std::vector<int> | std::istream {aka std::basic_istream<char>} In file included from /usr/include/c++/14/sstream:40, from /usr/include/c++/14/complex:45, from /usr/include/c++/14/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127, from a.cc:1: /usr/include/c++/14/istream:170:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' 170 | operator>>(bool& __n) | ^~~~~~~~ /usr/include/c++/14/istream:170:24: note: no known conversion for argument 1 from 'std::vector<int>' to 'bool&' 170 | operator>>(bool& __n) | ~~~~~~^~~ /usr/include/c++/14/istream:174:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char; _Traits = std::char_traits<char>]' 174 | operator>>(short& __n); | ^~~~~~~~ /usr/include/c++/14/istream:174:25: note: no known conversion for argument 1 from 'std::vector<int>' to 'short int&' 174 | operator>>(short& __n); | ~~~~~~~^~~ /usr/include/c++/14/istream:177:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' 177 | operator>>(unsigned short& __n) | ^~~~~~~~ /usr/include/c++/14/istream:177:34: note: no known conversion for argument 1 from 'std::vector<int>' to 'short unsigned int&' 177 | operator>>(unsigned short& __n) | ~~~~~~~~~~~~~~~~^~~ /usr/include/c++/14/istream:181:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char; _Traits = std::char_traits<char>]' 181 | operator>>(int& __n); | ^~~~~~~~ /usr/include/c++/14/istream:181:23: note: no known conversion for argument 1 from 'std::vector<int>' to 'int&' 181 | operator>>(int& __n); | ~~~~~^~~ /usr/include/c++/14/istream:184:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' 184 | operator>>(unsigned int& __n) | ^~~~~~~~ /usr/include/c++/14/istream:184:32: note: no known conversion for argument 1 from 'std::vector<int>' to 'unsigned int&' 184 | operator>>(unsigned int& __n) | ~~~~~~~~~~~~~~^~~ /usr/include/c++/14/istream:188:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' 188 | operator>>(long& __n) | ^~~~~~~~ /usr/include/c++/14/istream:188:24: note: no known conversion for argument 1 from 'std::vector<int>' to 'long int&' 188 | operator>>(long& __n) | ~~~~~~^~~ /usr/include/c++/14/istream:192:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' 192 | operator>>(unsigned long& __n) | ^~~~~~~~ /usr/include/c++/14/istream:192:33: note: no known conversion for argument 1 from 'std::vector<int>' to 'long unsigned int&' 192 | operator>>(unsigned long& __n) | ~~~~~~~~~~~~~~~^~~ /usr/include/c++/14/istream:199:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' 199 | operator>>(long long& __n) | ^~~~~~~~ /usr/include/c++/14/istream:199:29: note: no known conversion for argument 1 from 'std::vector<int>' to 'long long int&' 199 | operator>>(long long& __n) | ~~~~~~~~~~~^~~ /usr/include/c++/14/istream:203:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' 203 | operator>>(unsigned long long& __n) | ^~~~~~~~ /usr/include/c++/14/istream:203:38: note: no known conversion for argument 1 from 'std::vector<int>' to 'long long unsigned int&' 203 | operator>>(unsigned long long& __n) | ~~~~~~~~~~~~~~~~~~~~^~~ /usr/include/c++/14/istream:219:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' 219 | operator>>(float& __f) | ^~~~~~~~ /usr/include/c++/14/istream:219:25: note: no known conversion for argument 1 from 'std::vector<int>' to 'float&' 219 | operator>>(float& __f) | ~~~~~~~^~~ /usr/include/c++/14/istream:223:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' 223 | operator>>(double& __f) | ^~~~~~~~ /usr/include/c++/14/istream:223:26: note: no known conversion for argument 1 from 'std::vector<int>' to 'double&' 223 | operator>>(double& __f) | ~~~~~~~~^~~ /usr/include/c++/14/istream:227:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' 227 | operator>>(long double& __f) | ^~~~~~~~ /usr/include/c++/14/istream:227:31: note: no known conversion for argument 1 from 'std::vector<int>' to 'long double&' 227 | operator>>(long double& __f) | ~~~~~~~~~~~~~^~~ /usr/include/c++/14/istream:328:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' 328 | operator>>(void*& __p) | ^~~~~~~~ /usr/include/c++/14/istream:328:25: note: no known conversion for argument 1 from 'std::vector<int>' to 'void*&' 328 | operator>>(void*& __p) | ~~~~~~~^~~ /usr/include/c++/14/istream:122:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(__istream_type& (*)(__istream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' 122 | operator>>(__istream_type& (*__pf)(__istream_type&)) | ^~~~~~~~ /usr/include/c++/14/istream:122:36: note: no known conversion for argument 1 from 'std::vector<int>' to 'std::basic_istream<char>::__istream_type& (*)(std::basic_istream<char>::__istream_type&)' {aka 'std::basic_istream<char>& (*)(std::basic_istream<char>&)'} 122 | operator>>(__istream_type& (*__pf)(__istream_type&)) | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/istream:126:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>; __ios_type = std::basic_ios<char>]' 126 | operator>>(__ios_type& (*__pf)(__ios_type&)) | ^~~~~~~~ /usr/include/c++/14/istream:126:32: note: no known conversion for argument 1 from 'std::vector<int>' to 'std::basic_istream<char>::__ios_type& (*)(std::basic_istream<char>::__ios_type&)' {aka 'std::basic_ios<char>& (*)(std::basic_ios<char>&)'} 126 | operator>>(__ios_type& (*__pf)(__ios_type&)) | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~ /usr/include/c++/14/istream:133:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' 133 | operator>>(ios_base& (*__pf)(ios_base&)) | ^~~~~~~~ /usr/include/c++/14/istream:133:30: note: no known conversion for argument 1 from 'std::vector<int>' to 'std::ios_base& (*)(std::ios_base&)' 133 | operator>>(ios_base& (*__pf)(ios_base&)) | ~~~~~~~~~~~~^~~~~~~~~~~~~~~~ /usr/include/c++/14/istream:352:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(__streambuf_type*) [with _CharT = char; _Traits = std::char_traits<char>; __streambuf_type = std::basic_streambuf<char>]' 352 | operator>>(__streambuf_type* __sb); | ^~~~~~~~ /usr/include/c++/14/istream:352:36: note: no known conversion for argument 1 from 'std::vector<int>' to 'std::basic_istream<char>::__streambuf_type*' {aka 'std::basic_streambuf<char>*'} 352 | operator>>(__streambuf_type* __sb); | ~~~~~~~~~~~~~~~~~~^~~~ In file included from /usr/include/x86_64
s905652725
p04025
C++
r
a.cc:1:1: error: 'r' does not name a type 1 | r | ^
s324912407
p04025
C++
r
a.cc:1:1: error: 'r' does not name a type 1 | r | ^
s379070057
p04025
C++
#include <algorithm> #include <bitset> #include <tuple> #include <cstdint> #include <cstdio> #include <cctype> #include <assert.h> #include <stdlib.h> #include <stdio.h> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <limits> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define ArraySizeOf(array) (sizeof(array) / sizeof(array[0])) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i,n) for(int i=1;i<n;i++) #define int long long #define rev(i,n) for(int i=n-1;i>=0;i--) #define _GLIBCXX_DEBUG unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1) { unsigned day; if(dow < dow1) dow += 7; day = dow - dow1; day += 7 * n - 6; return day; } unsigned DayToWeekNumber(unsigned day) { return (day - 1) / 7 + 1; } unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0) { return (dow0 + 35 + day - day0) % 7; } using namespace std; signed main(){ int main(){ int N; cin>>N; int A,B; vector<int>a(N); rep(i,N)cin>>a[i]; sort(a.begin(),a.end()); rep(i,a[N-1]-a[0]){ rep(j,N){ A+=abs(a[j]-i-a[i]); } if(i!=0)B=min(A,B); else B=A; A=0; } cout<<B<<endl; }
a.cc: In function 'int main()': a.cc:59:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse] 59 | int main(){ | ^~ a.cc:59:9: note: remove parentheses to default-initialize a variable 59 | int main(){ | ^~ | -- a.cc:59:9: note: or replace parentheses with braces to value-initialize a variable a.cc:59:11: error: a function-definition is not allowed here before '{' token 59 | int main(){ | ^ a.cc:75:2: error: expected '}' at end of input 75 | } | ^ a.cc:58:14: note: to match this '{' 58 | signed main(){ | ^
s607090068
p04025
C++
//BISMILLAHIR RAHMANIR RAHIM //By the name of ALLAH #include<iostream> #include<algorithm> #include<vector> #include<set> #include<iterator> #include<numeric> #define pi acos(-1.0) using namespace std; bool f(long long int x,long long int y) { return x>y; } void solve() { int t; cin>>t; int a[10000]; for(int i=0;i<t;i++){ cin>>a[i]; } int p=ceil((a[0]+a[t-1])/2); long long cost=0; for(int i=0;i<t;i++){ cost+=(p-a[i])*(p-a[i]); } cout<<cost<<endl; } int main() { solve(); return 0; }
a.cc: In function 'void solve()': a.cc:23:11: error: 'ceil' was not declared in this scope 23 | int p=ceil((a[0]+a[t-1])/2); | ^~~~
s200252602
p04025
C
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a.at(i); } int totalc = 50000;// for (int i = -100; i <= 100; i++) { int totalc_ati = 0; for (int j = 0; j < n; j++) { int sa = a.at(j) - i;//(x-y) totalc_ati += sa * sa; } totalc = min(totalc_ati, totalc); } cout << totalc; }
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory 1 | #include <bits/stdc++.h> | ^~~~~~~~~~~~~~~ compilation terminated.
s778099826
p04025
C++
n = int(input()); a = list(map(int, input().split())); a.sort() ans = 1 << 60 for x in range(a[0], a[n-1]) : res = 0 for j in range(n) : res += abs(x - a[j])**2 ans = min(ans, res) print(ans)
a.cc:1:1: error: 'n' does not name a type 1 | n = int(input()); | ^ a.cc:2:1: error: 'a' does not name a type 2 | a = list(map(int, input().split())); | ^ a.cc:4:1: error: 'a' does not name a type 4 | a.sort() | ^
s551656659
p04025
C++
#include <iostream> #include <vector> using namespace std; int main(){ int N; cin >> N; vector<long long> a(N); long long sun = 0; for(int i = 0; i < N; i++) { cin >> a[i]; sum += a[i]; } long long ave = sum / N; long long ave2 = ave + 1; long long res = 0, res2 = 0; for(int i = 0; i < N; i++){ res += (a[i] - ave) * (a[i] - ave); res2 += (a[i] - ave2) *(a[i] - ave2); } cout << min(res, res2) << endl; }
a.cc: In function 'int main()': a.cc:11:5: error: 'sum' was not declared in this scope; did you mean 'sun'? 11 | sum += a[i]; | ^~~ | sun a.cc:13:19: error: 'sum' was not declared in this scope; did you mean 'sun'? 13 | long long ave = sum / N; | ^~~ | sun
s269054772
p04025
C++
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,no-stack-protector,fast-math") #include <bits/stdc++.h> #define ll long long #define ld long double #define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); using namespace std; const int N = 1e5 + 5, M = 2 * N + 5; ll ans(LLONG_MAX) int n, a[N]; int getCst(int a, int b){ return (a - b) * (a - b); } int check(int x){ ll ret = 0; for(int i = 0 ; i < n ; ++i) ret += getCst(x, a[i]); return ret; } int main(){ scanf("%d", &n); for(int i = 0 ; i < n ; ++i) scanf("%d", a + i); int mn = *min_element(a, a + n); int mx = *max_element(a, a + n); for(int x = mn ; x <= mx ; ++x) check(x); printf("%lld\n", ans); }
a.cc:10:1: error: expected ',' or ';' before 'int' 10 | int n, a[N]; | ^~~ a.cc: In function 'int check(int)': a.cc:18:25: error: 'n' was not declared in this scope 18 | for(int i = 0 ; i < n ; ++i) | ^ a.cc:19:26: error: 'a' was not declared in this scope 19 | ret += getCst(x, a[i]); | ^ a.cc: In function 'int main()': a.cc:24:18: error: 'n' was not declared in this scope 24 | scanf("%d", &n); | ^ a.cc:26:21: error: 'a' was not declared in this scope 26 | scanf("%d", a + i); | ^ a.cc:28:27: error: 'a' was not declared in this scope 28 | int mn = *min_element(a, a + n); | ^
s166257708
p04025
C++
#include<iostream> using namespace std; int main(){ int n; cin>>n; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; sum+=a[i]; } int p=sum/n; int ans1=0,ans2=0; for(int i=0;i<n;i++){ ans1+=((a[i]-p)*(a[i]-p)); ans2+((a[i]-(p+1))*(a[i]-(p+1))); } cout<<min(ans1,ans2)<<endl; return 0; }
a.cc: In function 'int main()': a.cc:9:5: error: 'sum' was not declared in this scope 9 | sum+=a[i]; | ^~~ a.cc:11:9: error: 'sum' was not declared in this scope 11 | int p=sum/n; | ^~~
s831031818
p04025
C++
#ifndef UNTITLED15_TEMPLATE_H #define UNTITLED15_TEMPLATE_H #ifdef _DEBUG #include "bits_stdc++.h" #else #include <bits/stdc++.h> #endif #ifndef fast_sort #define fast_sort sort #endif #define use_pq #define use_for #define use_for_each #define use_sort #define use_fill #define use_rand #define use_mgr #define use_rui #define use_compress // // // // // // #define use_pbds #ifdef use_pbds #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> template<class T, class U, class W, class X> auto count(__gnu_pbds::gp_hash_table<T, U, W> &a, X k) { return a.find(k) != a.end(); } #endif using namespace std; using namespace std::chrono; /*@formatter:off*/ #define ll long long using sig_dou = double; //マクロ省略形 関数等 #define arsz(a) (sizeof(a)/sizeof(a[0])) #define sz(a) ((ll)(a).size()) #define mp make_pair #define mt make_tuple #define pb pop_back #define pf push_front #define eb emplace_back #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() template<class T,class U> auto max(T a, U b){return a>b ? a: b;} template<class T,class U> auto min(T a, U b){return a<b ? a: b;} //optional<T>について下でオーバーロード(nullopt_tを左辺右辺について単位元として扱う) template<class T, class U> bool chma(T &a, const U &b) { if (a < b) { a = b; return true; } return false;} template<class T, class U> bool chmi(T &a, const U &b) { if (b < a) { a = b; return true; } return false;} //メタ系 namespace{//helper template<class T>T s_decl2(const T& A){return A;}template<class T>auto s_decl2(const vector<T>& A){return s_decl2(A[0]);} } //vector<T>でTを返す #define decl_t(A) decltype(A)::value_type //vector<vector<.....T>>でTを返す #define decl2(A) decltype(s_decl2(A)) #define decl_max(a, b) decltype(max(MAX<decltype(a)>(), MAX<decltype(b)>())) #define is_same2(T, U) is_same<T, U>::value template<class T>struct is_vector : std::false_type{}; template<class T>struct is_vector<std::vector<T>> : std::true_type{}; #define int long long //todo 消したら動かない intの代わりにsignedを使う auto start_time = system_clock::now(); auto past_time = system_clock::now(); #define debugName(VariableName) # VariableName //最大引数がN #define over2(o1, o2, name, ...) name #define over3(o1, o2, o3, name, ...) name #define over4(o1, o2, o3, o4, name, ...) name #define over5(o1, o2, o3, o4, o5, name, ...) name #define over6(o1, o2, o3, o4, o5, o6, name, ...) name #define over7(o1, o2, o3, o4, o5, o6, o7, name, ...) name #define over8(o1, o2, o3, o4, o5, o6, o7, o8, name, ...) name #define over9(o1, o2, o3, o4, o5, o6, o7, o8, o9, name, ...) name #define over10(o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, name, ...) name void assert2(bool b,const string& s = ""){ if(!b){ cerr<<s<<endl; exit(1);/*assert(0);*/ }} //my_nulloptをあらゆる操作の単位元的な物として扱う //vectorの参照外時に返したり、右辺値として渡されたときに何もしないなど struct my_nullopt_t {} my_nullopt; #define nullopt_t my_nullopt_t #define nullopt my_nullopt /*@formatter:off*/ //値が無いときは、setを使わない限り代入できない //=を使っても無視される template<class T> struct my_optional { private: bool is_null; T v; public: my_optional() : is_null(true) {} my_optional(const nullopt_t&) : is_null(true) {} my_optional(const T& v) : v(v), is_null(false) {} bool has_value() const { return !is_null; } T &value() {assert2(!is_null, "optional has no value");return v;} const T &value() const {assert2(!is_null, "optional has no value");return v;} void set(const T &nv) {is_null = false;v = nv;} template<class U> void operator=(const U &v) {if (has_value())value() = v;else return;} template<class U> void operator=(const my_optional<U> &v) {if (has_value() && v.has_value())(*this) = v;else return;} void reset() { is_null = true; } void operator=(const nullopt_t &) { reset(); } //nullの時はエラー operator T&(){return value();} operator const T&()const {return value();} my_optional<T> operator++() { if (this->has_value()) { this->value()++; return *this; } else { return *this; } } my_optional<T> operator++(signed) { if (this->has_value()) { auto tem = *this; this->value()++; return tem; } else { return *this; } } my_optional<T> operator--() { if (this->has_value()) { this->value()--; return *this; } else { return *this; } } my_optional<T> operator--(signed) { if (this->has_value()) { auto tem = *this; this->value()--; return tem; } else { return *this; } } }; #define optional my_optional //template<class T, class A = std::allocator<T>> struct debtor : std::vector<T, A> { template<class Key, class T, class Compare = less<Key>, class Allocator = allocator<pair<const Key, T> >> struct o_map : std::map<Key, optional<T>, Compare, Allocator> { optional<T> emp; o_map() : std::map<Key, optional<T>, Compare, Allocator>() {} auto operator()(const nullopt_t&) {return nullopt;} optional<T> &operator()(const optional<Key> &k) {if (k.has_value()) {return std::map<Key, optional<T>, Compare, Allocator>::operator[](k.value());} else {emp.reset();return emp;}} optional<T> &operator()(const Key &k) { auto &v = std::map<Key, optional<T>, Compare, Allocator>::operator[](k); if (v.has_value())return v; else { v.set(0); return v; } } template<class U> void operator[](U){assert2("s_map");} }; //以下、空のoptionalをnulloptと書く //ov[-1(参照外)] でnulloptを返す //ov[nullopt] で nulloptをかえす template<class T> struct ov{ optional<T> emp; vector<optional<T>> v; ov(int i, T val = 0):v(i, val){} ov(const vector<T>& rhs){v.resize(rhs);for (int i = 0; i < sz(rhs); i ++)v[i] = rhs[i];} optional<T> &operator()(int i) {if (i < 0 || sz(v) <= i) {emp.reset();return emp;} else { return v[i]; }} optional<T> &operator()(const nullopt_t &) { return operator()(-1); } optional<T> &operator()(const optional<T> &i) { if (i.has_value())return operator()(i.value()); else { return operator()(-1); } } /*@formatter:off*/ }; template<class T>string deb_tos(const ov<T>& v){ return deb_tos(v.v); } template<class T> struct ovv{ optional<T> emp; vector<vector<optional<T>> > v ; ovv(int i, int j, T val = 0) : v(i, vector<optional<T>>(j, val) ){} optional<T> &operator()(int i, int j) { if (i < 0 || j < 0 || sz(v) <= i || sz(v[i]) <= j) { emp.reset(); return emp; } else { return v[i][j]; } } //再帰ver 遅いと思う // optional<T>& gets(optional<T>& v){return v;} // template<class V, class H, class... U> optional<T>& gets(V& v, H i, U... tail){ if constexpr(is_same2(H, nullopt_t))return operator()(-1,-1); else if constexpr(is_same2(H, optional<int>)){ if(i.has_value())return gets(v[(int)i], tail...); else return operator()(-1,-1); }else if constexpr(is_integral<H>::value){ return gets(v[(int)i], tail...); }else{ assert(0); return emp; } } #if __cplusplus >= 201703L //if constexprバージョン 上が遅かったらこれで template<class U, class V> optional<T> &operator()(const U &i, const V &j) { /*駄目な場合を除外*/ if constexpr(is_same2(U, nullopt_t) || is_same2(U, nullopt_t)) { return operator()(-1, -1); /* o, o*/ } else if constexpr(is_same2(U, optional<int>) && is_same2(V, optional<int>)) { return operator()(i.has_value() ? (int) i : -1, j.has_value() ? (int) j : -1); /* o, x*/ } else if constexpr(is_same2(U, optional<int>)) { return operator()(i.has_value() ? (int) i : -1, (int) j); /* x, o*/ } else if constexpr(is_same2(V, optional<int>)) { return operator()((int) i, j.has_value() ? (int) j : -1); /* x, x*/ } else { return operator()((int) i, (int) j); } } #endif }; template<class T>string deb_tos(const ovv<T>& v){ return deb_tos(v.v); } template<class T> struct ov3{ optional<T> emp; vector<vector<vector<optional<T>>> > v ; ov3(int i, int j, int k, T val = 0) : v(i, vector<vector<optional<T>>>(j, vector<optional<T>>(k, val) ) ){} optional<T> &operator()(int i, int j, int k) { if (i < 0 || j < 0 || sz(v) <= i || sz(v[i]) <= j) { if(k < 0 || sz(v[i][j]) <= k){ emp.reset(); return emp; } } return v[i][j][k]; } private: #if __cplusplus >= 201703L //再帰ver 遅いと思う template<class V, class H> optional<T> &gets(V &nowv, H i) { if constexpr(is_same2(H, nullopt_t)) { return emp; } else if constexpr(is_same2(H, optional<int>)) { if (i.has_value()) { return nowv[(int) i]; } else { return emp; } } else if constexpr(is_integral<H>::value) { return nowv[(int) i]; } else { assert2(0, "ov3 error not index"); return emp; } } //todo const &消した template<class V, class H, class... U> optional<T> &gets(V &nowv, H i, U... tail) { if constexpr(is_same2(H, nullopt_t)) { return emp; } else if constexpr(is_same2(H, optional<int>)) { if (i.has_value()) { return gets(nowv[(int) i], tail...); } else { return emp; } } else if constexpr(is_integral<H>::value) { return gets(nowv[(int) i], tail...); } else { assert2(0, "ov3 error not index"); return emp; } } #endif public: template<class U, class V, class W> optional<T> &operator()(U i, V j, W k) { return gets(v, i, j, k); } /*@formatter:off*/ }; template<class T>string deb_tos(const ov3<T>& v){ return deb_tos(v.v); } //nullopt_t //優先順位 //null, [opt, tem] // + と += は違う意味を持つ //val+=null : val //val+null : null // //+は途中計算 //+=は最終的に格納したい値にだけ持たせる //+=がvoidを返すのは、途中計算で使うのを抑制するため //nulloptを考慮する際、計算途中では+を使ってnulloptを作り //格納する際は+=で無効にする必要がある //演算子== //optional<int>(10) == 10 //null同士を比較する状況はおかしいのではないか bool operator==(const nullopt_t &, const nullopt_t&){assert2(0, "nul == null cant hikaku");return false;} template<class T> bool operator==(const nullopt_t &, const T&){return false;} template<class T> bool operator!=(const nullopt_t &, const T&){return true;} template<class T> bool operator==(const T&, const nullopt_t &){return false;} template<class T> bool operator!=(const T&, const nullopt_t &){return true;} template<class O, class T> bool operator==(const optional<O>& opt, const T& tem){if(opt.has_value()){return opt.value()==tem;}else return nullopt == tem;} template<class O, class T> bool operator!=(const optional<O>& opt, const T& tem){if(opt.has_value()){return opt.value()!=tem;}else return nullopt != tem;} template<class O, class T> bool operator==(const T& tem, const optional<O>& opt){if(opt.has_value()){return opt.value()==tem;}else return nullopt == tem;} template<class O, class T> bool operator!=(const T& tem, const optional<O>& opt){if(opt.has_value()){return opt.value()!=tem;}else return nullopt != tem;} template<class Ol, class Or> bool operator==(const optional<Ol>& opl, const optional<Or>& opr){ if(opl.has_value() != opr.has_value()){ return false; }else if(opl.has_value()){ return opl.value() == opr.value(); }else { return nullopt == nullopt; }} template<class Ol, class Or> bool operator!=(const optional<Ol>& opl, const optional<Or>& opr){return !(opl == opr);} //nullを nullopt_t& operator +(const nullopt_t &, const nullopt_t&) {return nullopt;} nullopt_t& operator -(const nullopt_t &, const nullopt_t&) {return nullopt;} nullopt_t& operator *(const nullopt_t &, const nullopt_t&) {return nullopt;} nullopt_t& operator /(const nullopt_t &, const nullopt_t&) {return nullopt;} nullopt_t& operator +=(const nullopt_t &, const nullopt_t&) {return nullopt;} nullopt_t& operator -=(const nullopt_t &, const nullopt_t&) {return nullopt;} nullopt_t& operator *=(const nullopt_t &, const nullopt_t&) {return nullopt;} nullopt_t& operator /=(const nullopt_t &, const nullopt_t&) {return nullopt;} template<class ANY> nullopt_t operator+(const nullopt_t&, const ANY &) {return nullopt;} template<class ANY> nullopt_t operator-(const nullopt_t&, const ANY &) {return nullopt;} template<class ANY> nullopt_t operator*(const nullopt_t&, const ANY &) {return nullopt;} template<class ANY> nullopt_t operator/(const nullopt_t&, const ANY &) {return nullopt;} template<class ANY> nullopt_t operator+(const ANY &, const nullopt_t &) {return nullopt;} template<class ANY> nullopt_t operator-(const ANY &, const nullopt_t &) {return nullopt;} template<class ANY> nullopt_t operator*(const ANY &, const nullopt_t &) {return nullopt;} template<class ANY> nullopt_t operator/(const ANY &, const nullopt_t &) {return nullopt;} template<class ANY> void operator+=(nullopt_t &, const ANY &) {} template<class ANY> void operator-=(nullopt_t &, const ANY &) {} template<class ANY> void operator*=(nullopt_t &, const ANY &) {} template<class ANY> void operator/=(nullopt_t &, const ANY &) {} template<class ANY> void operator+=(ANY &, const nullopt_t &) {} template<class ANY> void operator-=(ANY &, const nullopt_t &) {} template<class ANY> void operator*=(ANY &, const nullopt_t &) {} template<class ANY> void operator/=(ANY &, const nullopt_t &) {} //tem, [tem, opt] //optional<T> //+-/* template<class T, class O> optional<O> operator+(const T &tem, const optional<O> &opt) { if (opt.has_value()) { return optional<O>(tem + opt.value()); } return optional<O>();} template<class T, class O> optional<O> operator-(const T &tem, const optional<O> &opt) { if (opt.has_value()) { return optional<O>(tem - opt.value()); } return optional<O>();} template<class T, class O> optional<O> operator*(const T &tem, const optional<O> &opt) { if (opt.has_value()) { return optional<O>(tem * opt.value()); } return optional<O>();} template<class T, class O> optional<O> operator/(const T &tem, const optional<O> &opt) { if (opt.has_value()) { return optional<O>(tem / opt.value()); } return optional<O>();} template<class T, class O> optional<O> operator+(const optional<O> &opt, const T &tem) { return tem + opt; } template<class T, class O> optional<O> operator-(const optional<O> &opt, const T &tem) { return tem - opt; } template<class T, class O> optional<O> operator*(const optional<O> &opt, const T &tem) { return tem * opt; } template<class T, class O> optional<O> operator/(const optional<O> &opt, const T &tem) { return tem / opt; } //(a+=null) != (a=a+null) // a null template<class T, class O> void operator+=(T &tem, const optional<O> &opt) { if (opt.has_value()) { tem += opt.value(); }} template<class T, class O> void operator-=(T &tem, const optional<O> &opt) { if (opt.has_value()) { tem -= opt.value(); }} template<class T, class O> void operator*=(T &tem, const optional<O> &opt) { if (opt.has_value()) { tem *= opt.value(); }} template<class T, class O> void operator/=(T &tem, const optional<O> &opt) { if (opt.has_value()) { tem /= opt.value(); }} template<class T, class O> void operator+=(optional<O> &opt, const T &tem) { if (opt.has_value()) { opt.value() += tem; }} template<class T, class O> void operator-=(optional<O> &opt, const T &tem) { if (opt.has_value()) { opt.value() -= tem; }} template<class T, class O> void operator*=(optional<O> &opt, const T &tem) { if (opt.has_value()) { opt.value() *= tem; }} template<class T, class O> void operator/=(optional<O> &opt, const T &tem) { if (opt.has_value()) { opt.value() /= tem; }} template<class O> void operator+(optional<O> &opl, const optional<O> &opr) { if (opr.has_value()) { return opl + opr.value(); }} template<class O> void operator-(optional<O> &opl, const optional<O> &opr) { if (opr.has_value()) { return opl - opr.value(); }} template<class O> void operator*(optional<O> &opl, const optional<O> &opr) { if (opr.has_value()) { return opl * opr.value(); }} template<class O> void operator/(optional<O> &opl, const optional<O> &opr) { if (opr.has_value()) { return opl / opr.value(); }} template<class Ol, class Or> void operator+=(optional<Ol> &opl, const optional<Or> &opr) { if (opr.has_value()) { return opl += opr.value(); }} template<class Ol, class Or> void operator-=(optional<Ol> &opl, const optional<Or> &opr) { if (opr.has_value()) { return opl -= opr.value(); }} template<class Ol, class Or> void operator*=(optional<Ol> &opl, const optional<Or> &opr) { if (opr.has_value()) { return opl *= opr.value(); }} template<class Ol, class Or> void operator/=(optional<Ol> &opl, const optional<Or> &opr) { if (opr.has_value()) { return opl /= opr.value(); }} /*@formatter:off*/ template<class U> auto max(const nullopt_t &, const U &val) { return val; } template<class U> auto max(const U &val, const nullopt_t &) { return val; } template<class U> auto min(const nullopt_t &, const U &val) { return val; } template<class U> auto min(const U &val, const nullopt_t &) { return val; } template<class T, class U> auto max(const optional<T> &opt, const U &val) { if (opt.has_value())return max(opt.value(), val); else return val; } template<class T, class U> auto max(const U &val, const optional<T> &opt) { if (opt.has_value())return max(opt.value(), val); else return val; } template<class T, class U> auto min(const optional<T> &opt, const U &val) { if (opt.has_value())return min(opt.value(), val); else return val; } template<class T, class U> auto min(const U &val, const optional<T> &opt) { if (opt.has_value())return min(opt.value(), val); else return val; } //null , optional, T bool chma(nullopt_t &, const nullopt_t &) { return false; } template<class T> bool chma(T &opt, const nullopt_t &) { return false; } template<class T> bool chma(nullopt_t &, const T &opt) { return false; } template<class T> bool chma(optional<T> &olv, const optional<T> &orv) { if (orv.has_value()) { return chma(olv, orv.value()); } else return false; } template<class T, class U> bool chma(optional<T> &opt, const U &rhs) { if (opt.has_value()) { return chma(opt.value(), rhs); } else return false; } template<class T, class U> bool chma(T &lhs, const optional<U> &opt) { if (opt.has_value()) { return chma(lhs, opt.value()); } else return false; } bool chmi(nullopt_t &, const nullopt_t &) { return false; } template<class T> bool chmi(T &opt, const nullopt_t &) { return false; } template<class T> bool chmi(nullopt_t &, const T &opt) { return false; } template<class T> bool chmi(optional<T> &olv, const optional<T> &orv) { if (orv.has_value()) { return chmi(olv, orv.value()); } else return false; } template<class T, class U> bool chmi(optional<T> &opt, const U &rhs) { if (opt.has_value()) { return chmi(opt.value(), rhs); } else return false; } template<class T, class U> bool chmi(T &lhs, const optional<U> &opt) { if (opt.has_value()) { return chmi(lhs, opt.value()); } else return false; } template<class T> ostream &operator<<(ostream &os, optional<T> p) { if (p.has_value())os << p.value(); else os << "e"; return os;} #ifdef _DEBUG string message; string res_mes; //#define use_debtor #ifdef use_debtor //https://marycore.jp/prog/cpp/class-extension-methods/ 違うかも template<class T, class A = std::allocator<T>> struct debtor : std::vector<T, A> { using std::vector<T, A>::vector; template<class U> int deb_v(U a, int v) { return v; } template<class U> int deb_v(debtor<U> &a, int v = 0) { cerr << a.size() << " "; return deb_v(a.at(0), v + 1); } template<class U> void deb_o(U a) { cerr << a << " "; } template<class U> void deb_o(debtor<U> &a) { for (int i = 0; i < min((int) a.size(), 15ll); i++) { deb_o(a[i]); } if ((int) a.size() > 15) { cerr << "..."; } cerr << endl; } typename std::vector<T>::reference my_at(typename std::vector<T>::size_type n, vector<int> &ind) { if (n < 0 || n >= (int) this->size()) { int siz = (int) this->size(); cerr << "vector size = "; int dim = deb_v((*this)); cerr << endl; ind.push_back(n); cerr << "out index at "; for (auto &&i: ind) { cerr << i << " "; } cerr << endl; cerr << endl; if (dim <= 2) { deb_o((*this)); } exit(0); } return this->at(n); } typename std::vector<T>::reference operator[](typename std::vector<T>::size_type n) { if (n < 0 || n >= (int) this->size()) { int siz = (int) this->size(); cerr << "vector size = "; int dim = deb_v((*this)); cerr << endl; cerr << "out index at " << n << endl; cerr << endl; if (dim <= 2) { deb_o((*this)); } exit(0); } return this->at(n); } }; #define vector debtor #endif #ifdef use_pbds template<class T> struct my_pbds_tree { set<T> s; auto begin() { return s.begin(); } auto end() { return s.end(); } auto rbegin() { return s.rbegin(); } auto rend() { return s.rend(); } auto empty() { return s.empty(); } auto size() { return s.size(); } void clear() { s.clear(); } template<class U> void insert(U v) { s.insert(v); } template<class U> void operator+=(U v) { insert(v); } template<class F> auto erase(F v) { return s.erase(v); } template<class U> auto find(U v) { return s.find(v); } template<class U> auto lower_bound(U v) { return s.lower_bound(v); } template<class U> auto upper_bound(U v) { return s.upper_bound(v); } auto find_by_order(ll k) { auto it = s.begin(); for (ll i = 0; i < k; i++)it++; return it; } auto order_of_key(ll v) { auto it = s.begin(); ll i = 0; for (; it != s.end() && *it < v; i++)it++; return i; } }; #define pbds(T) my_pbds_tree<T> #endif //区間削除は出来ない //gp_hash_tableでcountを使えないようにするため template<class T, class U> struct my_unordered_map { unordered_map<T, U> m; my_unordered_map() {}; auto begin() { return m.begin(); } auto end() { return m.end(); } auto cbegin() { return m.cbegin(); } auto cend() { return m.cend(); } template<class V> auto erase(V v) { return m.erase(v); } void clear() { m.clear(); } /*countは gp_hash_tableに存在しない*/ /*!= m.end()*/ template<class V> auto find(V v) { return m.find(v); } template<class V> auto &operator[](V n) { return m[n]; }}; #define unordered_map my_unordered_map #define umapi unordered_map<ll,ll> #define umapp unordered_map<P,ll> #define umapu unordered_map<uint64_t,ll> #define umapip unordered_map<ll,P> template<class T, class U, class X> auto count(unordered_map<T, U> &a, X k) { return a.find(k) != a.end(); } #else #define endl '\n' //umapはunorderd_mapになる //umapiはgp_hash_table //find_by_order(k) k番目のイテレーター //order_of_key(k) k以上が前から何番目か #define pbds(U) __gnu_pbds::tree<U, __gnu_pbds::null_type, less<U>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> #define umapi __gnu_pbds::gp_hash_table<ll,ll,xorshift> #define umapp __gnu_pbds::gp_hash_table<P,ll,xorshift> #define umapu __gnu_pbds::gp_hash_table<uint64_t,ll,xorshift> #define umapip __gnu_pbds::gp_hash_table<ll,P,xorshift> #endif /*@formatter:off*/ struct xorshift { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } size_t operator()(std::pair<ll, ll> x) const { ll v = ((x.first) << 32) | x.second; static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(v + FIXED_RANDOM); } }; #ifdef use_pbds template<class U, class L> void operator+=(__gnu_pbds::tree<U, __gnu_pbds::null_type, less<U>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> &s, L v) { s.insert(v); } #endif //衝突対策 #define ws ws_ //todo 要らないと思う template<class A, class B, class C> struct T2 { A f;B s;C t;T2() { f = 0, s = 0, t = 0; }T2(A f, B s, C t) : f(f), s(s), t(t) {}bool operator<(const T2 &r) const { return f != r.f ? f < r.f : s != r.s ? s < r.s : t < r.t; /*return f != r.f ? f > r.f : s != r.s ?n s > r.s : t > r.t; 大きい順 */ } bool operator>(const T2 &r) const { return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; /*return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 小さい順 */ } bool operator==(const T2 &r) const { return f == r.f && s == r.s && t == r.t; } bool operator!=(const T2 &r) const { return f != r.f || s != r.s || t != r.t; }}; template<class A, class B, class C, class D> struct F2 { A a;B b;C c;D d; F2() { a = 0, b = 0, c = 0, d = 0; } F2(A a, B b, C c, D d) : a(a), b(b), c(c), d(d) {} bool operator<(const F2 &r) const { return a != r.a ? a < r.a : b != r.b ? b < r.b : c != r.c ? c < r.c : d < r.d; /* return a != r.a ? a > r.a : b != r.b ? b > r.b : c != r.c ? c > r.c : d > r.d;*/ } bool operator>(const F2 &r) const { return a != r.a ? a > r.a : b != r.b ? b > r.b : c != r.c ? c > r.c : d > r.d;/* return a != r.a ? a < r.a : b != r.b ? b < r.b : c != r.c ? c < r.c : d < r.d;*/ } bool operator==(const F2 &r) const { return a == r.a && b == r.b && c == r.c && d == r.d; } bool operator!=(const F2 &r) const { return a != r.a || b != r.b || c != r.c || d != r.d; } ll operator[](ll i) {assert(i < 4);return i == 0 ? a : i == 1 ? b : i == 2 ? c : d;} }; typedef T2<ll, ll, ll> T; typedef F2<ll, ll, ll, ll> F; //T mt(ll a, ll b, ll c) { return T(a, b, c); } //F mf(ll a, ll b, ll c, ll d) { return F(a, b, c, d); } //関数内をまとめる //初期値l=-1, r=-1 void set_lr12(int &l, int &r, int n) { /*r==-1*/ if (r == -1) { if (l == -1) { l = 0; r = n; } else { r = l; l = 0; } }} //@マクロ省略系 型,構造 //using で元のdoubleを同時に使えるはず #define double_big #ifdef double_big #define double long double //#define pow powl #endif using dou = double; /*@formatter:off*/ template<class T> T MAX() { return numeric_limits<T>::max(); } template<class T> T MIN() { return numeric_limits<T>::min(); } constexpr ll inf = (ll) 1e9 + 100; constexpr ll linf = (ll) 1e18 + 100; constexpr dou dinf = (dou) linf * linf; constexpr char infc = '{'; const string infs = "{"; template<class T> T INF() { return MAX<T>() / 2; } template<> signed INF() { return inf; } template<> ll INF() { return linf; } template<> double INF() { return dinf; } template<> char INF() { return infc; } template<> string INF() { return infs; } const double eps = 1e-9; //#define use_epsdou #ifdef use_epsdou //基本コメントアウト struct epsdou { double v; epsdou(double v = 0) : v(v) {} template<class T> epsdou &operator+=(T b) { v += (double) b; return (*this); } template<class T> epsdou &operator-=(T b) { v -= (double) b; return (*this); } template<class T> epsdou &operator*=(T b) { v *= (double) b; return (*this); } template<class T> epsdou &operator/=(T b) { v /= (double) b; return (*this); } epsdou operator+(epsdou b) { return v + (double) b; } epsdou operator-(epsdou b) { return v - (double) b; } epsdou operator*(epsdou b) { return v * (double) b; } epsdou operator/(epsdou b) { return v / (double) b; } epsdou operator-() const { return epsdou(-v); } template<class T> bool operator<(T b) { return v < (double) b; } template<class T> bool operator>(T b) {auto r = (double)b; return v > (double) b; } template<class T> bool operator==(T b) { return fabs(v - (double) b) <= eps; } template<class T> bool operator<=(T b) { return v < (double) b || fabs(v - b) <= eps; } template<class T> bool operator>=(T b) { return v > (double) b || fabs(v - b) <= eps; } operator double() { return v; }}; template<>epsdou MAX(){return MAX<double>();} template<>epsdou MIN(){return MIN<double>();} //priqrity_queue等で使うのに必要 bool operator<(const epsdou &a, const epsdou &b) {return a.v < b.v;} bool operator>(const epsdou &a, const epsdou &b) {return a.v > b.v;} istream &operator>>(istream &iss, epsdou &a) {iss >> a.v;return iss;} ostream &operator<<(ostream &os, epsdou &a) {os << a.v;return os;} #define eps_conr_t(o) template<class T> epsdou operator o(T a, epsdou b) {return (dou) a o b.v;} #define eps_conl_t(o) template<class T> epsdou operator o(epsdou a, T b) {return a.v o (dou) b;} eps_conl_t(+)eps_conl_t(-)eps_conl_t(*)eps_conl_t(/)eps_conr_t(+)eps_conr_t(-)eps_conr_t(*)eps_conr_t(/) //template<class U> epsdou max(epsdou a, U b){return a.v>b ? a.v: b;} //template<class U> epsdou max(U a, epsdou b){return a>b.v ? a: b.v;} //template<class U> epsdou min(epsdou a, U b){return a.v<b ? a.v: b;} //template<class U> epsdou min(U a, epsdou b){return a<b.v ? a: b.v;} #undef double #define double epsdou #undef dou #define dou epsdou #endif #if __cplusplus >= 201703L template<class T = int, class A, class B = int> auto my_pow(A a, B b = 2) { if constexpr(is_floating_point<T>::value) { return pow((T) a, (T) b); } else if constexpr(is_floating_point<A>::value) { assert2(0, "pow <not dou>(dou, )");/*return 0;しない方がコンパイル前に(voidを受け取るので)エラーが出ていいかも*/} else if constexpr(is_floating_point<B>::value) { assert2(0, "pow <not dou>(, dou)");/*return 0;しない方がコンパイル前に(voidを受け取るので)エラーが出ていいかも*/} else { T ret = 1; T bek = a; while (b) { if (b & 1)ret *= bek; bek *= bek; b >>= 1; } return ret; } } #define pow my_pow #endif #define ull unsigned long long using itn = int; using str = string; using bo= bool; #define au auto using P = pair<ll, ll>; #define fi first #define se second #define beg begin #define rbeg rbegin #define con continue #define bre break #define brk break #define is == #define el else #define elf else if #define upd update #define sstream stringstream #define maxq 1 #define minq -1 #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) #define MALLOC(type, len) (type*)malloc((len) * sizeof(type)) #define lam1(ret) [&](auto& v){return ret;} #define lam2(v, ret) [&](auto& v){return ret;} #define lam(...) over2(__VA_ARGS__,lam2,lam1)(__VA_ARGS__) #define lamr(right) [&](auto& p){return p right;} #define unique(v) v.erase( unique(v.begin(), v.end()), v.end() ); //マクロ省略系 コンテナ using vi = vector<ll>; using vb = vector<bool>; using vs = vector<string>; using vd = vector<double>; using vc = vector<char>; using vp = vector<P>; using vt = vector<T>; //#define V vector #define vvt0(t) vector<vector<t>> #define vvt1(t, a) vector<vector<t>>a #define vvt2(t, a, b) vector<vector<t>>a(b) #define vvt3(t, a, b, c) vector<vector<t>> a(b,vector<t>(c)) #define vvt4(t, a, b, c, d) vector<vector<t>> a(b,vector<t>(c,d)) #define vvi(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(ll,__VA_ARGS__) #define vvb(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(bool,__VA_ARGS__) #define vvs(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(string,__VA_ARGS__) #define vvd(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(double,__VA_ARGS__) #define vvc(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(char,__VA_ARGS__) #define vvp(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(P,__VA_ARGS__) #define vvt(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(T,__VA_ARGS__) #define vv(type, ...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(type,__VA_ARGS__) template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template<typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } #define vni(name, ...) auto name = make_v<ll>(__VA_ARGS__) #define vnb(name, ...) auto name = make_v<bool>(__VA_ARGS__) #define vns(name, ...) auto name = make_v<string>(__VA_ARGS__) #define vnd(name, ...) auto name = make_v<double>(__VA_ARGS__) #define vnc(name, ...) auto name = make_v<char>(__VA_ARGS__) #define vnp(name, ...) auto name = make_v<P>(__VA_ARGS__) #define vn(type, name, ...) auto name = make_v<type>(__VA_ARGS__) #define PQ priority_queue<ll, vector<ll>, greater<ll> > #define tos to_string using mapi = map<ll, ll>; using mapp = map<P, ll>; using mapd = map<dou, ll>; using mapc = map<char, ll>; using maps = map<str, ll>; using seti = set<ll>; using setp = set<P>; using setd = set<dou>; using setc = set<char>; using sets = set<str>; using qui = queue<ll>; #define uset unordered_set #define useti unordered_set<ll,xorshift> #define mset multiset #define mseti multiset<ll> #define umap unordered_map #define mmap multimap //任意のマクロサポート用 使う度に初期化する int index_, v1_, v2_, v3_; #ifdef use_pq /*@formatter:off*/ string to_string(char c) { string ret = ""; ret += c; return ret;} template<class T> class pq_min_max { vector<T> d; void make_heap() { for (int i = d.size(); i--;) { if (i & 1 && d[i - 1] < d[i]) swap(d[i - 1], d[i]); int k = down(i); up(k, i); } } inline int parent(int k) const { return ((k >> 1) - 1) & ~1; } int down(int k) { int n = d.size(); if (k & 1) { /* min heap*/ while (2 * k + 1 < n) { int c = 2 * k + 3; if (n <= c || d[c - 2] < d[c]) c -= 2; if (c < n && d[c] < d[k]) { swap(d[k], d[c]); k = c; } else break; } } else { /* max heap*/ while (2 * k + 2 < n) { int c = 2 * k + 4; if (n <= c || d[c] < d[c - 2]) c -= 2; if (c < n && d[k] < d[c]) { swap(d[k], d[c]); k = c; } else break; } } return k; } int up(int k, int root = 1) { if ((k | 1) < (int) d.size() && d[k & ~1] < d[k | 1]) { swap(d[k & ~1], d[k | 1]); k ^= 1; } int p; while (root < k && d[p = parent(k)] < d[k]) { /*max heap*/ swap(d[p], d[k]); k = p; } while (root < k && d[k] < d[p = parent(k) | 1]) { /* min heap*/ swap(d[p], d[k]); k = p; } return k; }public: pq_min_max() {} pq_min_max(const vector<T> &d_) : d(d_) { make_heap(); } template<class Iter> pq_min_max(Iter first, Iter last) : d(first, last) { make_heap(); } void operator+=(const T &x) { int k = d.size(); d.push_back(x); up(k); } void pop_min() { if (d.size() < 3u) { d.pop_back(); } else { swap(d[1], d.back()); d.pop_back(); int k = down(1); up(k); } } void pop_max() { if (d.size() < 2u) { d.pop_back(); } else { swap(d[0], d.back()); d.pop_back(); int k = down(0); up(k); } } const T &get_min() const { return d.size() < 2u ? d[0] : d[1]; } const T &get_max() const { return d[0]; } int size() const { return d.size(); } bool empty() const { return d.empty(); }}; //小さいほうからM個取得するpq template<class T> struct helper_pq_size { pq_min_max<T> q; T su = 0; int max_size = 0; helper_pq_size() {} helper_pq_size(int max_size) : max_size(max_size) {} void clear() { q = pq_min_max<T>(); su = 0; } void operator+=(T v) { su += v; q += (v); if (sz(q) > max_size) { su -= q.get_max(); q.pop_max(); } } T sum() { return su; } T top() { return q.get_min(); } void pop() { su -= q.get_min(); q.pop_min(); } T poll() { T ret = q.get_min(); su -= ret; q.pop_min(); return ret; } ll size() { return q.size(); }}; //大きいほうからM個取得するpq template<class T> struct helper_pqg_size { pq_min_max<T> q; T su = 0; int max_size = 0; helper_pqg_size() {} helper_pqg_size(int max_size) : max_size(max_size) {} void clear() { q = pq_min_max<T>(); su = 0; } void operator+=(T v) { su += v; q += (v); if (sz(q) > max_size) { su -= q.get_min(); q.pop_min(); } } T sum() { return su; } T top() { return q.get_max(); } void pop() { su -= q.get_max(); q.pop_max(); } T poll() { T ret = q.get_max(); su -= ret; q.pop_min(); return ret; } ll size() { return q.size(); }};; template<class T> struct helper_pq { priority_queue<T, vector<T>, greater<T> > q;/*小さい順*/ T su = 0; helper_pq() {} void clear() { q = priority_queue<T, vector<T>, greater<T> >(); su = 0; } void operator+=(T v) { su += v; q.push(v); } T sum() { return su; } T top() { return q.top(); } void pop() { su -= q.top(); q.pop(); } T poll() { T ret = q.top(); su -= ret; q.pop(); return ret; } ll size() { return q.size(); }}; template<class T> struct helper_pqg { priority_queue<T> q;/*大きい順*/ T su = 0; helper_pqg() {} void clear() { q = priority_queue<T>(); su = 0; } void operator+=(T v) { su += v; q.push(v); } T sum() { return su; } T top() { return q.top(); } void pop() { su -= q.top(); q.pop(); } T poll() { T ret = q.top(); su -= ret; q.pop(); return ret; } ll size() { return q.size(); }}; //小さいほうからsize個残る template<class T> struct pq { helper_pq<T> a_q;/*大きい順*/ helper_pq_size<T> b_q;/*大きい順*/ bool aquery; T su = 0; pq(int size = inf) { aquery = size == inf; if (!aquery) { b_q = helper_pq_size<T>(size); } } void clear() { if (aquery) a_q.clear(); else b_q.clear(); } void operator+=(T v) { if (aquery) a_q += v; else b_q += v; } T sum() { if (aquery)return a_q.sum(); else return b_q.sum(); } T top() { if (aquery) return a_q.top(); else return b_q.top(); } void pop() { if (aquery) a_q.pop(); else b_q.pop(); } T poll() { if (aquery) return a_q.poll(); else return b_q.poll(); } ll size() { if (aquery) return a_q.size(); else return b_q.size(); }}; //大きいほうからsize個残る template<class T> struct pqg { helper_pqg<T> a_q;/*大きい順*/ helper_pqg_size<T> b_q;/*大きい順*/ bool aquery; T su = 0; pqg(int size = inf) { aquery = size == inf; if (!aquery) { b_q = helper_pqg_size<T>(size); } } void clear() { if (aquery) a_q.clear(); else b_q.clear(); } void operator+=(T v) { if (aquery) a_q += v; else b_q += v; } T sum() { if (aquery)return a_q.sum(); else return b_q.sum(); } T top() { if (aquery) return a_q.top(); else return b_q.top(); } void pop() { if (aquery) a_q.pop(); else b_q.pop(); } T poll() { if (aquery) return a_q.poll(); else return b_q.poll(); } ll size() { if (aquery) return a_q.size(); else return b_q.size(); }}; #define pqi pq<ll> #define pqgi pqg<ll> #endif /*@formatter:off*/ //マクロ 繰り返し //↓@オーバーロード隔離 //todo 使わないもの非表示 #define rep1(n) for(ll rep1i = 0,rep1lim=n; rep1i < rep1lim ; ++rep1i) #define rep2(i, n) for(ll i = 0,rep2lim=n; i < rep2lim ; ++i) #define rep3(i, m, n) for(ll i = m,rep3lim=n; i < rep3lim ; ++i) #define rep4(i, m, n, ad) for(ll i = m,rep4lim=n; i < rep4lim ; i+= ad) //逆順 閉区間 #define rer2(i, n) for(ll i = n; i >= 0 ; i--) #define rer3(i, m, n) for(ll i = m,rer3lim=n; i >= rer3lim ; i--) #define rer4(i, m, n, dec) for(ll i = m,rer4lim=n; i >= rer4lim ; i-=dec) #ifdef use_for //ループを一つにまとめないとフォーマットで汚くなるため #define nex_ind1(i) i++ #define nex_ind2(i, j, J) i = (j + 1 == J) ? i + 1 : i, j = (j + 1 == J ? 0 : j + 1) #define nex_ind3(i, j, k, J, K)i = (j + 1 == J && k + 1 == K) ? i + 1 : i, j = (k + 1 == K) ? (j + 1 == J ? 0 : j + 1) : j, k = (k + 1 == K ? 0 : k + 1) #define nex_ind4(i, j, k, l, J, K, L) i = (j + 1 == J && k + 1 == K && l + 1 == L) ? i + 1 : i, j = (k + 1 == K && l + 1 == L) ? (j + 1 == J ? 0 : j + 1) : j, k = (l + 1 == L ?(k + 1 == K ? 0 : k + 1) : k), l = l + 1 == L ? 0 : l + 1 #define nex_ind5(i, j, k, l, m, J, K, L, M) i = (j + 1 == J && k + 1 == K && l + 1 == L && m + 1 == M) ? i + 1 : i, j = (k + 1 == K && l + 1 == L && m + 1 == M) ? (j + 1 == J ? 0 : j + 1) : j, k = (l + 1 == L && m + 1 == M ?(k + 1 == K ? 0 : k + 1) : k), l = m + 1 == M ? l+1 == L ? 0 : l+1 : l, m = m + 1 == M ? 0 : m + 1 #define repss2(i, I) for (int i = 0; i < I; i++) #define repss4(i, j, I, J) for (int i = (J ? 0 : I), j = 0; i < I; nex_ind2(i, j, J)) #define repss6(i, j, k, I, J, K) for (int i = (J && K ? 0 : I), j = 0, k = 0; i < I; nex_ind3(i, j, k, J, K)) #define repss8(i, j, k, l, I, J, K, L) for (int i = (J && K && L ? 0 : I), j = 0, k = 0, l = 0; i < I; nex_ind4(i, j, k, l, J, K, L)) #define repss10(i, j, k, l, m, I, J, K, L, M)for (int i = (J && K && L && M ? 0 : I), j = 0, k = 0, l = 0, m = 0; i < I; nex_ind5(i, j, k, l, m, J, K, L, M)) //i,j,k...をnまで見る #define reps2(i, n) repss2(i, n) #define reps3(i, j, n) repss4(i, j, n, n) #define reps4(i, j, k, n) repss6(i, j, k, n, n, n) #define reps5(i, j, k, l, n) repss8(i, j, k, l, n, n, n, n) template<class T> void nex_repv2(int &i, int &j, int &I, int &J, vector<vector<T>> &s) { while (1) { j++; if (j >= J) { j = 0; i++; if (i < I) { J = (int) s[i].size(); } } if (i >= I || J) return; }} template<class T> void nex_repv3(int &i, int &j, int &k, int &I, int &J, int &K, vector<vector<vector<T>>> &s) { while (1) { k++; if (k >= K) { k = 0; j++; if (j >= J) { j = 0; i++; if (i >= I)return; } } J = (int) s[i].size(); K = (int) s[i][j].size(); if (J && K) return; }} #define repv_2(i, a) repss2(i, sz(a)) //正方形である必要はない //直前を持つのとどっちが早いか #define repv_3(i, j, a) for (int repvI = (int)a.size(), repvJ = (int)a[0].size(), i = 0, j = 0; i < repvI; nex_repv2(i,j,repvI,repvJ,a)) //箱状になっている事が要求される つまり[i] 次元目の要素数は一定 #define repv_4(i, j, k, a) for (int repvI = (int)a.size(), repvJ = (int)a[0].size(), repvK =(int)a[0][0].size(), i = 0, j = 0, k=0; i < repvI; nex_repv3(i,j,k,repvI,repvJ,repvK,a)) #define repv_5(i, j, k, l, a) repss8(i, j, k, l, sz(a), sz(a[0]), sz(a[0][0]), sz(a[0][0][0])) #define repv_6(i, j, k, l, m, a) repss10(i, j, k, l, m, sz(a), sz(a[0]), sz(a[0][0]), sz(a[0][0][0]), sz(a[0][0][0][0])) #endif template<typename T> struct has_rbegin_rend { private:template<typename U> static auto check(U &&obj) -> decltype(std::rbegin(obj), std::rend(obj), std::true_type{});static std::false_type check(...);public:static constexpr bool value = decltype(check(std::declval<T>()))::value; }; template<typename T> constexpr bool has_rbegin_rend_v = has_rbegin_rend<T>::value; template<typename Iterator> class Range { public:Range(Iterator &&begin, Iterator &&end) noexcept: m_begin(std::forward<Iterator>(begin)), m_end(std::forward<Iterator>(end)) {}Iterator begin() const noexcept { return m_begin; }Iterator end() const noexcept { return m_end; }private:const Iterator m_begin;const Iterator m_end; }; template<typename Iterator> static inline Range<Iterator> makeRange(Iterator &&begin, Iterator &&end) noexcept { return Range<Iterator>{std::forward<Iterator>(begin), std::forward<Iterator>(end)}; } template<typename T> static inline decltype(auto) makeReversedRange(const std::initializer_list<T> &iniList) noexcept { return makeRange(std::rbegin(iniList), std::rend(iniList)); } template<typename T, typename std::enable_if_t<has_rbegin_rend_v<T>, std::nullptr_t> = nullptr> static inline decltype(auto) makeReversedRange(T &&c) noexcept { return makeRange(std::rbegin(c), std::rend(c)); }/* rbegin(), rend()を持たないものはこっちに分岐させて,エラーメッセージを少なくする*/template<typename T, typename std::enable_if<!has_rbegin_rend<T>::value, std::nullptr_t>::type = nullptr> static inline void makeReversedRange(T &&) noexcept { static_assert(has_rbegin_rend<T>::value, "Specified argument doesn't have reverse iterator."); } //#define use_for #define form1(st) for (auto &&form_it = st.begin(); form_it != st.end(); ++form_it) #define form3(k, v, st) for (auto &&form_it = st.begin(); form_it != st.end(); ++form_it) #define form4(k, v, st, r) for (auto &&form_it = st.begin(); form_it != st.end() && (*form_it).fi < r; ++form_it) #define form5(k, v, st, l, r) for (auto &&form_it = st.lower_bound(l); form_it != st.end() && (*form_it).fi < r; ++form_it) #define forrm1(st) for (auto &&forrm_it = st.rbegin(); forrm_it != st.rend(); ++forrm_it) #define forrm3(k, v, st) for (auto &&forrm_it = st.rbegin(); forrm_it != st.rend(); ++forrm_it) //向こう側で // ++itか it = st.erase(it)とする #define fors1(st) for (auto &&it = st.begin(); it != st.end(); ) #define fors2(v, st) for (auto &&it = st.begin(); it != st.end(); ) #define fors3(v, st, r) for (auto &&it = st.begin(); it != st.end() && (*it) < r; ) #define fors4(v, st, l, r) for (auto &&it = st.lower_bound(l); it != st.end() && (*it) < r; ) #ifdef use_for #define forslr3(st, a, b) for (auto &&forslr_it = st.begin(); forslr_it != st.end(); ++forslr_it) #define forslr4(v, st, a, b) for (auto &&forslr_it = st.begin(); forslr_it != st.end(); ++forslr_it) #define forslr5(v, st, r, a, b) for (auto &&forslr_it = st.begin(); forslr_it != st.end() && (*forslr_it) < r; ++forslr_it) #define forslr6(v, st, l, r, a, b) for (auto &&forslr_it = st.lower_bound(l); forslr_it != st.end() && (*forslr_it) < r; ++forslr_it) #define fora_f_init_2(a, A) ; #define fora_f_init_3(fora_f_i, a, A) auto &&a = A[fora_f_i]; #define fora_f_init_4(a, b, A, B) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i]; #define fora_f_init_5(fora_f_i, a, b, A, B) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i]; #define fora_f_init_6(a, b, c, A, B, C) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i]; auto &&c = C[fora_f_i]; #define fora_f_init_7(fora_f_i, a, b, c, A, B, C) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i]; auto &&c = C[fora_f_i]; #define fora_f_init_8(a, b, c, d, A, B, C, D) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i]; auto &&c = C[fora_f_i]; auto && d = D[fora_f_i]; #define fora_f_init_9(fora_f_i, a, b, c, d, A, B, C, D) auto &&a = A[fora_f_i]; auto &&b = B[fora_f_i]; auto &&c = C[fora_f_i]; auto && d = D[fora_f_i]; #define fora_f_init(...) over9(__VA_ARGS__,fora_f_init_9, fora_f_init_8, fora_f_init_7, fora_f_init_6, fora_f_init_5, fora_f_init_4, fora_f_init_3, fora_f_init_2)(__VA_ARGS__) #define forr_init_2(a, A) auto &&a = A[forr_i]; #define forr_init_3(forr_i, a, A) auto &&a = A[forr_i]; #define forr_init_4(a, b, A, B) auto &&a = A[forr_i]; auto &&b = B[forr_i]; #define forr_init_5(forr_i, a, b, A, B) auto &&a = A[forr_i]; auto &&b = B[forr_i]; #define forr_init_6(a, b, c, A, B, C) auto &&a = A[forr_i]; auto &&b = B[forr_i]; auto &&c = C[forr_i]; #define forr_init_7(forr_i, a, b, c, A, B, C) auto &&a = A[forr_i]; auto &&b = B[forr_i]; auto &&c = C[forr_i]; #define forr_init_8(a, b, c, d, A, B, C, D) auto &&a = A[forr_i]; auto &&b = B[forr_i]; auto &&c = C[forr_i]; auto && d = D[forr_i]; #define forr_init_9(forr_i, a, b, c, d, A, B, C, D) auto &&a = A[forr_i]; auto &&b = B[forr_i]; auto &&c = C[forr_i]; auto && d = D[forr_i]; #define forr_init(...) over9(__VA_ARGS__, forr_init_9, forr_init_8, forr_init_7, forr_init_6, forr_init_5, forr_init_4, forr_init_3, forr_init_2)(__VA_ARGS__) #define forp_init3(k, v, S) auto &&k = S[forp_i].first;auto &&v = S[forp_i].second; #define forp_init4(forp_i, k, v, S) auto &&k = S[forp_i].first;auto &&v = S[forp_i].second; #define forp_init(...) over4(__VA_ARGS__,forp_init4,forp_init3,forp_init2,forp_init1)(__VA_ARGS__) #define form_init(k, v, ...) auto &&k = (*form_it).fi;auto &&v = (*form_it).se; #define forrm_init(k, v, ...) auto &&k = (*forrm_it).fi;auto &&v = (*forrm_it).se; #define fors_init(v, ...) auto &&v = (*it); #define forlr_init(a, A, ngl, ngr) auto a = A[forlr_i]; auto prev = forlr_i ? A[forlr_i-1] : ngl;auto next = forlr_i+1< rep2lim? A[forlr_i+1] : ngr; #define forslr_init4(a, A, ngl, ngr) auto a = (*forslr_it); auto prev = (forslr_it!=A.begin())? (*std::prev(forslr_it)) : ngl;auto next = (forslr_it!=std::prev(A.end()))? (*std::next(forslr_it)) : ngr; #define forslr_init5(a, A, r, ngl, ngr) auto a = (*forslr_it); auto prev = (forslr_it!=A.begin())? (*std::prev(forslr_it)) : ngl;auto next = (forslr_it!=std::prev(A.end()))? (*std::next(forslr_it)) : ngr; #define forslr_init6(a, A, l, r, ngl, ngr) auto a = (*forslr_it); auto prev = (forslr_it!=A.begin())? (*std::prev(forslr_it)) : ngl;auto next = (forslr_it!=std::prev(A.end()))? (*std::next(forslr_it)) : ngr; #define forslr_init(...) over6(__VA_ARGS__,forslr_init6,forslr_init5,forslr_init4)(__VA_ARGS__); //こうしないとmapがおかしくなる #define fora_f_2(a, A) for(auto&& a : A) #define fora_f_3(fora_f_i, a, A) rep(fora_f_i, sz(A)) #define fora_f_4(a, b, A, B) rep(fora_f_i, sz(A)) #define fora_f_5(fora_f_i, a, b, A, B) rep(fora_f_i, sz(A)) #define fora_f_6(a, b, c, A, B, C) rep(fora_f_i, sz(A)) #define fora_f_7(fora_f_i, a, b, c, A, B, C) rep(fora_f_i, sz(A)) #define fora_f_8(a, b, c, d, A, B, C, D) rep(fora_f_i, sz(A)) #define fora_f_9(fora_f_i, a, b, c, d, A, B, C, D) rep(fora_f_i, sz(A)) #define forr_2(a, A) rer(forr_i, sz(A)-1) #define forr_3(forr_i, a, A) rer(forr_i, sz(A)-1) #define forr_4(a, b, A, B) rer(forr_i, sz(A)-1) #define forr_5(forr_i, a, b, A, B) rer(forr_i, sz(A)-1) #define forr_6(a, b, c, A, B, C) rer(forr_i, sz(A)-1) #define forr_7(forr_i, a, b, c, A, B, C) rer(forr_i, sz(A)-1) #define forr_8(a, b, c, d, A, B, C, D) rer(forr_i, sz(A)-1) #define forr_9(forr_i, a, b, c, d, A, B, C, D) rer(forr_i, sz(A)-1) #endif //↑@オーバーロード隔離 //rep系はインデックス、for系は中身 #define rep(...) over4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__) #define rer(...) over4(__VA_ARGS__,rer4,rer3,rer2,)(__VA_ARGS__) //自分込みで残りがREM以上の間ループを回す #define rem(i, N, REM) for (int i = 0; i < N - REM + 1; i++) //char用のrep #define repc(i, m, n) for(char i = m,repc3lim=n; i < repc3lim ; ++i) //i,j,k...をnまで見る #define reps(...) over5(__VA_ARGS__,reps5,reps4,reps3,reps2,)(__VA_ARGS__) #define repss(...) over10(__VA_ARGS__, repss10, a, repss8, a, repss6, a, repss4, a, repss2) (__VA_ARGS__) //vectorのindexを走査する //repv(i,j,vvi) #define repv(...) over6(__VA_ARGS__,repv_6,repv_5,repv_4,repv_3,repv_2,)(__VA_ARGS__) #define rerv(i, A) for (int i = sz(A)-1; i >= 0 ; i--) //repvn(dp) nは次元 #define repv1(a) repv(i, a) #define repv2(a) repv(i, j, a) #define repv3(a) repv(i, j, k, a) #define repv4(a) repv(i, j, k, l, a) #ifdef use_for #define fora_f(...) over9(__VA_ARGS__, fora_f_9, fora_f_8, fora_f_7, fora_f_6, fora_f_5, fora_f_4, fora_f_3, fora_f_2)(__VA_ARGS__) #endif #define forr(...) over9(__VA_ARGS__, forr_9, forr_8, forr_7, forr_6, forr_5, forr_4, forr_3, forr_2)(__VA_ARGS__) //0~N-2まで見る #define forar_init(v, rv, A) auto &&v = A[forar_i]; auto && rv = A[forar_i+1]; #define forar(v, rv, A) rep(forar_i, sz(A) - 1) #if __cplusplus >= 201703L template<size_t M_SZ, bool indexed, class Iterator, class T, class U=T, class V=T, class W=T> class ite_vec_merge : public Iterator { std::size_t i = 0; vector<T> &A; vector<U> &B; vector<V> &C; vector<W> &D;public : ite_vec_merge(Iterator ita, vector<T> &A) : Iterator(ita), A(A), B(A), C(A), D(A) {} ite_vec_merge(Iterator ita, vector<T> &A, vector<U> &B) : Iterator(ita), A(A), B(B), C(A), D(A) {} ite_vec_merge(Iterator ita, vector<T> &A, vector<U> &B, vector<V> &C) : Iterator(ita), A(A), B(B), C(C), D(A) {} ite_vec_merge(Iterator ita, vector<T> &A, vector<U> &B, vector<V> &C, vector<W> &D) : Iterator(ita), A(A), B(B), C(C), D(D) {} auto &operator++() { ++i; this->Iterator::operator++(); return *this; } auto operator*() const noexcept { if constexpr(!indexed && M_SZ == 1) { return tuple<T &>(A[i]); } else if constexpr(!indexed && M_SZ == 2) { return tuple<T &, U &>(A[i], B[i]); } else if constexpr(!indexed && M_SZ == 3) { return tuple<T &, U &, V &>(A[i], B[i], C[i]); } else if constexpr(!indexed && M_SZ == 4) { return tuple<T &, U &, V &, W &>(A[i], B[i], C[i], D[i]); } else if constexpr(indexed && M_SZ == 1) { return tuple<int, T &>(i, A[i]); } else if constexpr(indexed && M_SZ == 2) { return tuple<int, T &, U &>(i, A[i], B[i]); } else if constexpr(indexed && M_SZ == 3) { return tuple<int, T &, U &, V &>(i, A[i], B[i], C[i]); } else if constexpr(indexed && M_SZ == 4) { return tuple<int, T &, U &, V &, W &>(i, A[i], B[i], C[i], D[i]); } else { assert(0); return tuple<int>(i); } }}; template<size_t M_SZ, bool indexed, class T, class U=T, class V=T, class W=T> class vec_merge { vector<T> &a; vector<U> &b; vector<V> &c; vector<W> &d;public : vec_merge(vector<T> &a) : a(a), b(a), c(a), d(a) {} vec_merge(vector<T> &a, vector<U> &b) : a(a), b(b), c(a), d(a) {} vec_merge(vector<T> &a, vector<U> &b, vector<V> &c) : a(a), b(b), c(c), d(a) {} vec_merge(vector<T> &a, vector<U> &b, vector<V> &c, vector<W> &d) : a(a), b(b), c(c), d(d) {} auto begin() const { if constexpr(M_SZ == 1) { return ite_vec_merge<M_SZ, indexed, decltype(std::begin(a)), T, U, V, W>{std::begin(a), a}; } else if constexpr(M_SZ == 2) { return ite_vec_merge<M_SZ, indexed, decltype(std::begin(a)), T, U, V, W>{std::begin(a), a, b}; } else if constexpr(M_SZ == 3) { return ite_vec_merge<M_SZ, indexed, decltype(std::begin(a)), T, U, V, W>{std::begin(a), a, b, c}; } else if constexpr(M_SZ == 4) { return ite_vec_merge<M_SZ, indexed, decltype(std::begin(a)), T, U, V, W>{std::begin(a), a, b, c, d}; } else { assert(0); return ite_vec_merge<M_SZ, indexed, decltype(std::begin(a)), T, U, V, W>{std::begin(a), a}; } } auto end() const { if constexpr(M_SZ == 1) { return ite_vec_merge<M_SZ, indexed, decltype(std::end(a)), T, U, V, W>{std::end(a), a}; } else if constexpr(M_SZ == 2) { return ite_vec_merge<M_SZ, indexed, decltype(std::end(a)), T, U, V, W>{std::end(a), a, b}; } else if constexpr(M_SZ == 3) { return ite_vec_merge<M_SZ, indexed, decltype(std::end(a)), T, U, V, W>{std::end(a), a, b, c}; } else if constexpr(M_SZ == 4) { return ite_vec_merge<M_SZ, indexed, decltype(std::end(a)), T, U, V, W>{std::end(a), a, b, c, d}; } else { assert(0); return ite_vec_merge<M_SZ, indexed, decltype(std::end(a)), T, U, V, W>{std::end(a), a}; } }}; #endif #define fora_2(a, A) for(auto&& a : A) #if __cplusplus >= 201703L #define fora_3(i, a, A) for(auto[i, a] : vec_merge<1, true, decl_t(A)>(A)) #define fora_4(a, b, A, B) for(auto[a, b] : vec_merge<2, false, decl_t(A), decl_t(B)>(A, B)) #define fora_5(i, a, b, A, B) for(auto[i, a, b] : vec_merge<2, true, decl_t(A), decl_t(B)>(A, B)) #define fora_6(a, b, c, A, B, C) for(auto[a, b, c] : vec_merge<3, false, decl_t(A), decl_t(B), decl_t(C)>(A, B, C)) #define fora_7(i, a, b, c, A, B, C) for(auto[i, a, b, c] : vec_merge<3, true, decl_t(A), decl_t(B), decl_t(C)>(A, B, C)) #define fora_8(a, b, c, d, A, B, C, D) for(auto[a, b, c, d] : vec_merge<4, false, decl_t(A), decl_t(B), decl_t(C), decl_t(D)>(A, B, C, D)) #define fora_9(i, a, b, c, d, A, B, C, D) for(auto[i, a, b, c, d] : vec_merge<4, true, decl_t(A), decl_t(B), decl_t(C), decl_t(D)>(A, B, C, D)) #endif //構造化束縛ver //1e5要素で40ms程度 //遅いときはfora_fを使う #define fora(...) over9(__VA_ARGS__, fora_9, fora_8, fora_7, fora_6, fora_5, fora_4, fora_3, fora_2)(__VA_ARGS__) //#define forr(v, a) for(auto&& v : makeReversedRange(a)) //参照を取らない /*@formatter:off*/ #ifdef use_for template<class U> vector<U> to1d(vector<U> &a) { return a; } template<class U> auto to1d(vector<vector<U>> &a) { vector<U> res; for (auto &&a1 : a)for (auto &&a2 : a1)res.push_back(a2); return res;} template<class U> vector<U> to1d(vector<vector<vector<U>>> &a) { vector<U> res; for (auto &&a1 : a)for (auto &&a2 : a1)for (auto &&a3 : a2) res.push_back(a3); return res;} template<class U> vector<U> to1d(vector<vector<vector<vector<U>>>> &a) {vector<U> res; for (auto &&a1 : a)for (auto &&a2 : a1)for (auto &&a3 : a2) for (auto &&a4 : a3)res.push_back(a4); return res;} template<class U> vector<U> to1d(vector<vector<vector<vector<vector<U>>>>> &a) {vector<U> res; for (auto &&a1 : a)for (auto &&a2 : a1)for (auto &&a3 : a2) for (auto &&a4 : a3)for (auto &&a5 : a4)res.push_back(a5); return res;} template<class U> vector<U> to1d(vector<vector<vector<vector<vector<vector<U>>>>>> &a) {vector<U> res; for (auto &&a1 : a)for (auto &&a2 : a1)for (auto &&a3 : a2) for (auto &&a4 : a3)for (auto &&a5 : a4)for (auto &&a6 : a5)res.push_back(a6); return res;} #define forv(a, b) for(auto a : to1d(b)) //インデックスを前後含めて走査 #define ring(i, s, len) for (int i = s, prev = (s == 0) ? len - 1 : s - 1, next = (s == len - 1) ? 0 : s + 1, cou = 0; cou < len; cou++, prev = i, i = next, next = (next == len - 1) ? 0 : next + 1) //値と前後を見る #define ringv(v, d) index_=0;for (auto prev = d[sz(d)-1],next= (int)d.size()>1?d[1]:d[0],v = d[0]; index_ < sz(d); index_++, prev = v, v = next, next = (index_>=sz(d)-1?d[0]:d[index_+1])) // 左右をnext prevで見る 0の左と nの右 #define forlr(v, d, banpei_l, banpei_r) rep(forlr_i,sz(d)) #endif #define form(...) over5(__VA_ARGS__,form5,form4,form3,form2,form1)(__VA_ARGS__) #define forrm(...) over5(__VA_ARGS__,forrm5,forrm4,forrm3,forrm2,forrm1)(__VA_ARGS__) #define fors(...) over4(__VA_ARGS__,fors4,fors3,fors2,fors1)(__VA_ARGS__) #define forslr(...) over6(__VA_ARGS__,forslr6,forslr5,forslr4,forslr3)(__VA_ARGS__) #define forp3(k, v, st) rep(forp_i,sz(st)) #define forp4(forp_i, k, v, st) rep(forp_i,sz(st)) #define forp(...) over4(__VA_ARGS__,forp4,forp3)(__VA_ARGS__) //マクロ 定数 #define k3 1010 #define k4 10101 #define k5 101010 #define k6 1010101 #define k7 10101010 const double PI = 3.1415926535897932384626433832795029L; constexpr bool ev(ll a) { return !(a & 1); } constexpr bool od(ll a) { return (a & 1); } //@拡張系 こう出来るべきというもの //埋め込み 存在を意識せずに機能を増やされているもの namespace std { template<> class hash<std::pair<signed, signed>> { public:size_t operator()(const std::pair<signed, signed> &x) const { return hash<ll>()(((ll) x.first << 32) | x.second); }}; template<> class hash<std::pair<ll, ll>> { public:/*大きいllが渡されると、<<32でオーバーフローするがとりあえず問題ないと判断*/size_t operator()(const std::pair<ll, ll> &x) const { return hash<ll>()(((ll) x.first << 32) | x.second); }}; } //stream まとめ /*@formatter:off*/ istream &operator>>(istream &iss, P &a) {iss >> a.first >> a.second;return iss;} template<typename T> istream &operator>>(istream &iss, vector<T> &vec_) {for (T &x: vec_) iss >> x;return iss;} template<class T, class U> ostream &operator<<(ostream &os, pair<T, U> p) {os << p.fi << " " << p.se;return os;} ostream &operator<<(ostream &os, T p) {os << p.f << " " << p.s << " " << p.t;return os;} ostream &operator<<(ostream &os, F p) {os << p.a << " " << p.b << " " << p.c << " " << p.d;return os;} template<typename T> ostream &operator<<(ostream &os, vector<T> &vec_) {for (ll i = 0; i < vec_.size(); ++i)os << vec_[i] << (i + 1 == vec_.size() ? "" : " ");return os;} template<typename T> ostream &operator<<(ostream &os, vector<vector<T>> &vec_) {for (ll i = 0; i < vec_.size(); ++i) {for (ll j = 0; j < vec_[i].size(); ++j) { os << vec_[i][j] << " "; }os << endl;}return os;} template<typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &m) {os << endl;for (auto &&v:m) os << v << endl;return os;} template<class T> ostream &operator<<(ostream &os, set<T> s) { fora(v, s) { os << v << " "; } return os;} template<class T> ostream &operator<<(ostream &os, mset<T> s) { fora(v, s) { os << v << " "; } return os;} template<class T> ostream &operator<<(ostream &os, deque<T> a) { fora(v, a) { os << v << " "; } return os;} ostream &operator<<(ostream &os, vector<vector<char>> &vec_) { rep(h, sz(vec_)) { rep(w, sz(vec_[0])) { os << vec_[h][w]; } os << endl; } return os;} /*@formatter:off*/ //template<class T,class U>ostream &operator<<(ostream &os, vector<pair<T,U>>& a) {fora_f(v,a)os<<v<<endl;return os;} template<typename W, typename H> void resize(W &vec_, const H head) { vec_.resize(head); } template<typename W, typename H, typename ... T> void resize(W &vec_, const H &head, const T ... tail) {vec_.resize(head);for (auto &v: vec_)resize(v, tail...);} //#define use_for_each //_each _all_of _any_of _none_of _find_if _rfind_if _contains _count_if _erase_if _entry_if #ifdef use_for_each template<typename T, typename F> bool all_of2(const T &v, F f) { return f(v); } template<typename T, typename F> bool all_of2(const vector<T> &v, F f) { rep(i, sz(v)) { if (!all_of2(v[i], f))return false; } return true;} template<typename T, typename F> bool any_of2(const T &v, F f) { return f(v); } template<typename T, typename F> bool any_of2(const vector<T> &v, F f) { rep(i, sz(v)) { if (any_of2(v[i], f))return true; } return false;} template<typename T, typename F> bool none_of2(const T &v, F f) { return f(v); } template<typename T, typename F> bool none_of2(const vector<T> &v, F f) { rep(i, sz(v)) { if (none_of2(v[i], f))return false; } return true;} template<typename T, typename F> bool find_if2(const T &v, F f) { return f(v); } template<typename T, typename F> ll find_if2(const vector<T> &v, F f) { rep(i, sz(v)) { if (find_if2(v[i], f))return i; } return sz(v);} template<typename T, typename F> bool rfind_if2(const T &v, F f) { return f(v); } template<typename T, typename F> ll rfind_if2(const vector<T> &v, F f) { rer(i, sz(v) - 1) { if (rfind_if2(v[i], f))return i; } return -1;} template<class T> bool contains(const string &s, const T &v) { return s.find(v) != string::npos; } template<typename T> bool contains(const vector<T> &v, const T &val) { return std::find(v.begin(), v.end(), val) != v.end(); } template<typename T, typename F> bool contains_if2(const vector<T> &v, F f) { return find_if(v.begin(), v.end(), f) != v.end(); } template<typename T, typename F> ll count_if2(const T &v, F f) { return f(v); } template<typename T, typename F> ll count_if2(const vector<T> &vec_, F f) { ll ret = 0; fora(v, vec_) { ret += count_if2(v, f); } return ret;} //template<typename T, typename F> void for_each2(T &v, F f) { f(v); } //template<typename T, typename F> void for_each2(vector<T> &vec_, F f) { fora_f(v, vec_)for_each2(v, f); } template<typename T, typename F> void for_each2(vector<T> &a, F f) { rep(i, sz(a))f(a[i]); } template<typename T, typename F> void for_each2(vector<vector<T> > &a, F f) { rep(i, sz(a))rep(j, sz(a[i]))f(a[i][j]); } template<typename T, typename F> void for_each2(vector<vector<vector<T> > > &a, F f) { rep(i, sz(a))rep(j, sz(a[i]))rep(k, sz(a[i][j]))f(a[i][j][k]); } template<typename W> ll count_od(const vector<W> &a) { return count_if2(a, [](ll v) { return v & 1; }); } template<typename W> ll count_ev(const vector<W> &a) { return count_if2(a, [](ll v) { return !(v & 1); }); } //削除した後のvectorを返す template<typename T, typename F> vector<T> erase_if2(const vector<T> &v, F f) { vector<T> nv; rep(i, sz(v)) { if (!f(v[i])) { nv.push_back(v[i]); }} return nv;} template<typename T, typename F> vector<vector<T>> erase_if2(const vector<vector<T>> &v, F f) { vector<vector<T>> res; rep(i, sz(v)) { res[i] = erase_if2(v[i], f); } return res;} template<typename T, typename F> vector<T> l_erase_if2(const vector<T> &v, F f) { vector<T> nv; rep(i, sz(v)) { if (!f(v[i])) { nv.push_back(v[i]); }} return nv;} template<typename T, typename F> vector<T> entry_if2(const vector<T> &v, F f) { vector<T> nv; rep(i, sz(v)) { if (f(v[i])) { nv.push_back(v[i]); }} return nv;} template<typename T, typename F> vector<vector<T>> entry_if2(const vector<vector<T>> &v, F f) { vector<vector<T>> res; rep(i, sz(v)) { res[i] = entry_if2(v[i], f); } return res;} template<typename T, typename F> vector<T> l_entry_if2(const vector<T> &v, F f) { vector<T> nv; rep(i, sz(v)) { if (f(v[i])) { nv.push_back(v[i]); }} return nv;} template<typename T, typename F> ll l_rfind_if(const vector<T> &v, F f) { rer(i, sz(v) - 1) { if (f(v[i]))return i; } return -1;} template<typename T, typename F> bool l_contains_if(const vector<T> &v, F f) { rer(i, sz(v) - 1) { if (f(v[i]))return true; } return false;} template<class A, class B, class C> auto t_all_of(A a, B b, C c) { return std::all_of(a, b, c); } template<class A, class B, class C> auto t_any_of(A a, B b, C c) { return std::any_of(a, b, c); } template<class A, class B, class C> auto t_none_of(A a, B b, C c) { return std::none_of(a, b, c); } template<class A, class B, class C> auto t_find_if(A a, B b, C c) { return std::find_if(a, b, c); } template<class A, class B, class C> auto t_count_if(A a, B b, C c) { return std::count_if(a, b, c); } #define all_of_s__2(a, right) (t_all_of(all(a),lamr(right))) #define all_of_s__3(a, v, siki) (t_all_of(all(a),[&](auto v){return siki;})) #define all_of_s(...) over3(__VA_ARGS__,all_of_s__3,all_of_s__2)(__VA_ARGS__) //all_of(A, %2); //all_of(A, a, a%2); #define all_of__2(a, right) all_of2(a,lamr(right)) #define all_of__3(a, v, siki) all_of2(a,[&](auto v){return siki;}) #define all_of(...) over3(__VA_ARGS__,all_of__3,all_of__2)(__VA_ARGS__) #define all_of_f(a, f) all_of2(a,f) #define any_of_s__2(a, right) (t_any_of(all(a),lamr(right))) #define any_of_s__3(a, v, siki) (t_any_of(all(a),[&](auto v){return siki;})) #define any_of_s(...) over3(__VA_ARGS__,any_of_s__3,any_of_s__2)(__VA_ARGS__) #define any_of__2(a, right) any_of2(a,lamr(right)) #define any_of__3(a, v, siki) any_of2(a,[&](auto v){return siki;}) #define any_of(...) over3(__VA_ARGS__,any_of__3,any_of__2)(__VA_ARGS__) #define any_of_f(a, f) any_of2(a,f) #define none_of_s__2(a, right) (t_none_of(all(a),lamr(right))) #define none_of_s__3(a, v, siki) (t_none_of(all(a),[&](auto v){return siki;})) #define none_of_s(...) over3(__VA_ARGS__,none_of_s__3,none_of_s__2)(__VA_ARGS__) #define none_of__2(a, right) none_of2(a,lamr(right)) #define none_of__3(a, v, siki) none_of2(a,[&](auto v){return siki;}) #define none_of(...) over3(__VA_ARGS__,none_of__3,none_of__2)(__VA_ARGS__) #define none_of_f(a, f) none_of2(a,f) #define find_if_s__2(a, right) (t_find_if(all(a),lamr(right))-a.begin()) #define find_if_s__3(a, v, siki) (t_find_if(all(a),[&](auto v){return siki;})-a.begin()) #define find_if_s(...) over3(__VA_ARGS__,find_if_s__3,find_if_s__2)(__VA_ARGS__) #define find_if__2(a, right) find_if2(a,lamr(right)) #define find_if__3(a, v, siki) find_if2(a,[&](auto v){return siki;}) #define find_if(...) over3(__VA_ARGS__,find_if__3,find_if__2)(__VA_ARGS__) #define find_if_f(a, f) find_if2(a,f) #define rfind_if_s__2(a, right) l_rfind_if(a, lamr(right)) #define rfind_if_s__3(a, v, siki) l_rfind_if(a, [&](auto v){return siki;}) #define rfind_if_s(...) over3(__VA_ARGS__,rfind_if_s__3,rfind_if_s__2)(__VA_ARGS__) #define rfind_if__2(a, right) rfind_if2(a,lamr(right)) #define rfind_if__3(a, v, siki) rfind_if2(a,[&](auto v){return siki;}) #define rfind_if(...) over3(__VA_ARGS__,rfind_if__3,rfind_if__2)(__VA_ARGS__) #define rfind_if_f(a, f) rfind_if2(a,f) #define contains_if_s__2(a, right) l_contains_if(a, lamr(right)) #define contains_if_s__3(a, v, siki) l_contains_if(a, [&](auto v){return siki;}) #define contains_if_s(...) over3(__VA_ARGS__,contains_if_s__3,contains_if_s__2)(__VA_ARGS__) #define contains_if__2(a, right) contains_if2(a,lamr(right)) #define contains_if__3(a, v, siki) contains_if2(a,[&](auto v){return siki;}) #define contains_if(...) over3(__VA_ARGS__,contains_if__3,contains_if__2)(__VA_ARGS__) #define contains_if_f(a, f) contains_if2(a,f) #define count_if_s__2(a, right) (t_count_if(all(a),lamr(right))) #define count_if_s__3(a, v, siki) (t_count_if(all(a),[&](auto v){return siki;})) #define count_if_s(...) over3(__VA_ARGS__,count_if_s__3,count_if_s__2)(__VA_ARGS__) #define count_if__2(a, right) count_if2(a,lamr(right)) #define count_if__3(a, v, siki) count_if2(a,[&](auto v){return siki;}) #define count_if(...) over3(__VA_ARGS__,count_if__3,count_if__2)(__VA_ARGS__) #define count_if_f(a, f) count_if2(a,f) //vector<vi>で、viに対して操作 #define for_each_s__2(a, right) do{fora(v,a){v right;}}while(0) #define for_each_s__3(a, v, shori) do{fora(v,a){shori;}}while(0) #define for_each_s(...) over3(__VA_ARGS__,for_each_s__3,for_each_s__2)(__VA_ARGS__) //vector<vi>で、intに対して操作 #define for_each__2(a, right) for_each2(a,lamr(right)) #define for_each__3(a, v, shori) for_each2(a,[&](auto& v){shori;}) #define for_each(...) over3(__VA_ARGS__,for_each__3,for_each__2)(__VA_ARGS__) #define for_each_f(a, f) for_each2(a, f); template<class T, class F> vector<T> help_for_eached(const vector<T> &A, F f) {vector<T> ret = A;for_each(ret, v, f(v));return ret;} #define for_eached__2(a, right) help_for_eached(a, lamr(right)) #define for_eached__3(a, v, shori) help_for_eached(a, lam(v, shori)) #define for_eached(...) over3(__VA_ARGS__,for_eached__3,for_eached__2)(__VA_ARGS__) #define for_eached_f(a, f) for_eached2(a, f); #define each for_each #define eached for_eached #define erase_if_s__2(a, right) l_erase_if2(a,lamr(right)) #define erase_if_s__3(a, v, siki) l_erase_if2(a,[&](auto v){return siki;}) #define erase_if_s(...) over3(__VA_ARGS__,erase_if_s__3,erase_if_s__2)(__VA_ARGS__) #define erase_if__2(a, right) erase_if2(a,lamr(right)) #define erase_if__3(a, v, siki) erase_if2(a,[&](auto v){return siki;}) #define erase_if(...) over3(__VA_ARGS__,erase_if__3,erase_if__2)(__VA_ARGS__) #define erase_if_f(a, f) erase_if2(a,f) #define entry_if_s__2(a, right) l_entry_if2(a,lamr(right)) #define entry_if_s__3(a, v, siki) l_entry_if2(a,[&](auto v){return siki;}) #define entry_if_s(...) over3(__VA_ARGS__,entry_if_s__3,entry_if_s__2)(__VA_ARGS__) #define entry_if__2(a, right) entry_if2(a,lamr(right)) #define entry_if__3(a, v, siki) entry_if2(a,[&](auto v){return siki;}) #define entry_if(...) over3(__VA_ARGS__,entry_if__3,entry_if__2)(__VA_ARGS__) #define entry_if_f(a, f) entry_if2(a,f) #endif /*@formatter:off*/ template<class T, class U, class W> void replace(vector<W> &a, T key, U v) { rep(i, sz(a))if (a[i] == key)a[i] = v; } template<class T, class U, class W> void replace(vector<vector<W>> &A, T key, U v) { rep(i, sz(A))replace(A[i], key, v); } void replace(str &a, char key, str v) { if (v == "")a.erase(remove(all(a), key), a.end()); } void replace(str &a, char key, char v) { replace(all(a), key, v); } //keyと同じかどうか01で置き換える template<class T, class U> void replace(vector<T> &a, U k) { rep(i, sz(a)) a[i] = a[i] == k; } template<class T, class U> void replace(vector<vector<T >> &a, U k) { rep(i, sz(a))rep(j, sz(a[0])) a[i][j] = a[i][j] == k; } void replace(str &a) { int dec = 0; if ('a' <= a[0] && a[0] <= 'z')dec = 'a'; if ('A' <= a[0] && a[0] <= 'Z')dec = 'A'; fora(v, a) { v -= dec; }} void replace(str &a, str key, str v) { stringstream t; ll kn = sz(key); std::string::size_type Pos(a.find(key)); ll l = 0; while (Pos != std::string::npos) { t << a.substr(l, Pos - l); t << v; l = Pos + kn; Pos = a.find(key, Pos + kn); } t << a.substr(l, sz(a) - l); a = t.str();} template<class T> bool is_permutation(vector<T> &a, vector<T> &b) { return is_permutation(all(a), all(b)); } template<class T> bool next_permutation(vector<T> &a) { return next_permutation(all(a)); } vi iota(ll s, ll len) {vi ve(len);iota(all(ve), s);return ve;} template<class A, class B> auto vtop(vector<A> &a, vector<B> &b) { assert(sz(a) == sz(b)); /*stringを0で初期化できない */ vector<pair<A, B>> res; rep(i, sz(a))res.eb(a[i], b[i]); return res;} template<class A, class B> void ptov(vector<pair<A, B>> &p, vector<A> &a, vector<B> &b) { a.resize(sz(p)), b.resize(sz(p)); rep(i, sz(p))a[i] = p[i].fi, b[i] = p[i].se;} template<class A, class B, class C> auto vtot(vector<A> &a, vector<B> &b, vector<C> &c) { assert(sz(a) == sz(b) && sz(b) == sz(c)); vector<T2<A, B, C>> res; rep(i, sz(a))res.eb(a[i], b[i], c[i]); return res;} template<class A, class B, class C, class D> auto vtof(vector<A> &a, vector<B> &b, vector<C> &c, vector<D> &d) { assert(sz(a) == sz(b) && sz(b) == sz(c) && sz(c) == sz(d)); vector<F2<A, B, C, D>> res; rep(i, sz(a))res.eb(a[i], b[i], c[i], d[i]); return res;} /*@formatter:off*/ template<class T> void sort(vector<T> &a, int l = -1, int r = -1) { set_lr12(l, r, sz(a)); fast_sort(a.begin() + l, a.begin() + r);} template<class T> void rsort(vector<T> &a, int l = -1, int r = -1) { set_lr12(l, r, sz(a)); fast_sort(a.begin() + l, a.begin() + r, greater<T>());}; template<class A, class B> void sortp(vector<A> &a, vector<B> &b) { auto c = vtop(a, b); sort(c); rep(i, sz(a)) a[i] = c[i].fi, b[i] = c[i].se;} template<class A, class B> void rsortp(vector<A> &a, vector<B> &b) { auto c = vtop(a, b); rsort(c); rep(i, sz(a))a[i] = c[i].first, b[i] = c[i].second;} template<class A, class B, class C> void sortt(vector<A> &a, vector<B> &b, vector<C> &c) { auto d = vtot(a, b, c); sort(d); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;} template<class A, class B, class C> void rsortt(vector<A> &a, vector<B> &b, vector<C> &c) { auto d = vtot(a, b, c); rsort(d); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;} template<class... T, class U> auto sorted(U head, T... a) { sort(head, a...); return head;} template<class... T, class U> auto rsorted(U head, T... a) {rsort(head, a...);return head;} //sortindex 元のvectorはソートしない template<class T> vi sorti(vector<T> &a) { auto b = a; vi ind = iota(0, sz(a)); sortp(b, ind); return ind;} //#define use_sort #ifdef use_sort enum pcomparator { fisi, fisd, fdsi, fdsd, sifi, sifd, sdfi, sdfd }; enum tcomparator { fisiti, fisitd, fisdti, fisdtd, fdsiti, fdsitd, fdsdti, fdsdtd, fitisi, fitisd, fitdsi, fitdsd, fdtisi, fdtisd, fdtdsi, fdtdsd, sifiti, sifitd, sifdti, sifdtd, sdfiti, sdfitd, sdfdti, sdfdtd, sitifi, sitifd, sitdfi, sitdfd, sdtifi, sdtifd, sdtdfi, sdfdfd, tifisi, tifisd, tifdsi, tifdsd, tdfisi, tdfisd, tdfdsi, tdfdsd, tisifi, tisifd, tisdfi, tisdfd, tdsifi, tdsifd, tdsdfi, tdsdfd}; template<class A, class B> void sort(vector<pair<A, B>> &a, pcomparator type) {typedef pair<A, B> U;if (type == fisi) sort(all(a), [&](U l, U r) { return l.fi != r.fi ? l.fi < r.fi : l.se < r.se; }); else if (type == fisd) sort(all(a), [&](U l, U r) { return l.fi != r.fi ? l.fi < r.fi : l.se > r.se; }); else if (type == fdsi) sort(all(a), [&](U l, U r) { return l.fi != r.fi ? l.fi > r.fi : l.se < r.se; }); else if (type == fdsd) sort(all(a), [&](U l, U r) { return l.fi != r.fi ? l.fi > r.fi : l.se > r.se; }); else if (type == sifi) sort(all(a), [&](U l, U r) { return l.se != r.se ? l.se < r.se : l.fi < r.fi; }); else if (type == sifd) sort(all(a), [&](U l, U r) { return l.se != r.se ? l.se < r.se : l.fi > r.fi; }); else if (type == sdfi) sort(all(a), [&](U l, U r) { return l.se != r.se ? l.se > r.se : l.fi < r.fi; }); else if (type == sdfd) sort(all(a), [&](U l, U r) { return l.se != r.se ? l.se > r.se : l.fi > r.fi; });}; template<class U> void sort(vector<U> &a, pcomparator type) { if (type == fisi) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s < r.s; }); else if (type == fisd) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s > r.s; }); else if (type == fdsi) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s < r.s; }); else if (type == fdsd) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s > r.s; }); else if (type == sifi) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f < r.f; }); else if (type == sifd) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f > r.f; }); else if (type == sdfi) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f < r.f; }); else if (type == sdfd) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f > r.f; }); }; template<class A, class B, class C, class D> void sort(vector<F2<A, B, C, D> > &a, pcomparator type) {typedef F2<A, B, C, D> U;if (type == fisi) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b < r.b; }); else if (type == fisd) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b > r.b; }); else if (type == fdsi) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b < r.b; }); else if (type == fdsd) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b > r.b; }); else if (type == sifi) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a < r.a; }); else if (type == sifd) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a > r.a; }); else if (type == sdfi) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a < r.a; }); else if (type == sdfd) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a > r.a; });}; template<class U> void sort(vector<U> &a, tcomparator type) {if (type == 0) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s < r.s : l.t < r.t; }); else if (type == 1) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s < r.s : l.t > r.t; }); else if (type == 2) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s > r.s : l.t < r.t; }); else if (type == 3) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s > r.s : l.t > r.t; }); else if (type == 4) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s < r.s : l.t < r.t; }); else if (type == 5) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s < r.s : l.t > r.t; }); else if (type == 6) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s > r.s : l.t < r.t; }); else if (type == 7) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s > r.s : l.t > r.t; }); else if (type == 8) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t < r.t : l.s < r.s; }); else if (type == 9) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t < r.t : l.s > r.s; }); else if (type == 10) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t > r.t : l.s < r.s; }); else if (type == 11) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t > r.t : l.s > r.s; }); else if (type == 12) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t < r.t : l.s < r.s; }); else if (type == 13) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t < r.t : l.s > r.s; }); else if (type == 14) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t > r.t : l.s < r.s; }); else if (type == 15) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t > r.t : l.s > r.s; }); else if (type == 16) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f < r.f : l.t < r.t; }); else if (type == 17) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f < r.f : l.t > r.t; }); else if (type == 18) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f > r.f : l.t < r.t; }); else if (type == 19) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f > r.f : l.t > r.t; }); else if (type == 20) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f < r.f : l.t < r.t; }); else if (type == 21) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f < r.f : l.t > r.t; }); else if (type == 22) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f > r.f : l.t < r.t; }); else if (type == 23) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f > r.f : l.t > r.t; }); else if (type == 24) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t < r.t : l.f < r.f; }); else if (type == 25) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t < r.t : l.f > r.f; }); else if (type == 26) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t > r.t : l.f < r.f; }); else if (type == 27) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t > r.t : l.f > r.f; }); else if (type == 28) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t < r.t : l.f < r.f; }); else if (type == 29) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t < r.t : l.f > r.f; }); else if (type == 30) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t > r.t : l.f < r.f; }); else if (type == 31) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t > r.t : l.f > r.f; }); else if (type == 32) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f < r.f : l.s < r.s; }); else if (type == 33) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f < r.f : l.s > r.s; }); else if (type == 34) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f > r.f : l.s < r.s; }); else if (type == 35) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f > r.f : l.s > r.s; }); else if (type == 36) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f < r.f : l.s < r.s; }); else if (type == 37) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f < r.f : l.s > r.s; }); else if (type == 38) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f > r.f : l.s < r.s; }); else if (type == 39) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f > r.f : l.s > r.s; }); else if (type == 40) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s < r.s : l.f < r.f; }); else if (type == 41) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s < r.s : l.f > r.f; }); else if (type == 42) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s > r.s : l.f < r.f; }); else if (type == 43) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s > r.s : l.f > r.f; }); else if (type == 44) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s < r.s : l.f < r.f; }); else if (type == 45) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s < r.s : l.f > r.f; }); else if (type == 46) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s > r.s : l.f < r.f; }); else if (type == 47) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s > r.s : l.f > r.f; });} template<class A, class B, class C, class D> void sort(vector<F2<A, B, C, D>> &a, tcomparator type) { typedef F2<A, B, C, D> U; if (type == 0) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b < r.b : l.c < r.c; }); else if (type == 1) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b < r.b : l.c > r.c; }); else if (type == 2) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b > r.b : l.c < r.c; }); else if (type == 3) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b > r.b : l.c > r.c; }); else if (type == 4) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b < r.b : l.c < r.c; }); else if (type == 5) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b < r.b : l.c > r.c; }); else if (type == 6) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b > r.b : l.c < r.c; }); else if (type == 7) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b > r.b : l.c > r.c; }); else if (type == 8) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c < r.c : l.b < r.b; }); else if (type == 9) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c < r.c : l.b > r.b; }); else if (type == 10) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c > r.c : l.b < r.b; }); else if (type == 11) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c > r.c : l.b > r.b; }); else if (type == 12) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c < r.c : l.b < r.b; }); else if (type == 13) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c < r.c : l.b > r.b; }); else if (type == 14) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c > r.c : l.b < r.b; }); else if (type == 15) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c > r.c : l.b > r.b; }); else if (type == 16) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a < r.a : l.c < r.c; }); else if (type == 17) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a < r.a : l.c > r.c; }); else if (type == 18) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a > r.a : l.c < r.c; }); else if (type == 19) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a > r.a : l.c > r.c; }); else if (type == 20) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a < r.a : l.c < r.c; }); else if (type == 21) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a < r.a : l.c > r.c; }); else if (type == 22) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a > r.a : l.c < r.c; }); else if (type == 23) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a > r.a : l.c > r.c; }); else if (type == 24) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c < r.c : l.a < r.a; }); else if (type == 25) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c < r.c : l.a > r.a; }); else if (type == 26) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c > r.c : l.a < r.a; }); else if (type == 27) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c > r.c : l.a > r.a; }); else if (type == 28) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c < r.c : l.a < r.a; }); else if (type == 29) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c < r.c : l.a > r.a; }); else if (type == 30) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c > r.c : l.a < r.a; }); else if (type == 31) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c > r.c : l.a > r.a; }); else if (type == 32) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a < r.a : l.b < r.b; }); else if (type == 33) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a < r.a : l.b > r.b; }); else if (type == 34) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a > r.a : l.b < r.b; }); else if (type == 35) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a > r.a : l.b > r.b; }); else if (type == 36) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a < r.a : l.b < r.b; }); else if (type == 37) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a < r.a : l.b > r.b; }); else if (type == 38) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a > r.a : l.b < r.b; }); else if (type == 39) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a > r.a : l.b > r.b; }); else if (type == 40) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b < r.b : l.a < r.a; }); else if (type == 41) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b < r.b : l.a > r.a; }); else if (type == 42) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b > r.b : l.a < r.a; }); else if (type == 43) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b > r.b : l.a > r.a; }); else if (type == 44) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b < r.b : l.a < r.a; }); else if (type == 45) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b < r.b : l.a > r.a; }); else if (type == 46) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b > r.b : l.a < r.a; }); else if (type == 47) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b > r.b : l.a > r.a; });} /*@formatter:off*/ void sort(string &a) { sort(all(a)); } void sort(int &a, int &b) { if (a > b)swap(a, b); } void sort(int &a, int &b, int &c) { sort(a, b); sort(a, c); sort(b, c);} void rsort(int &a, int &b) { if (a < b)swap(a, b); } void rsort(int &a, int &b, int &c) { rsort(a, b); rsort(a, c); rsort(b, c);} //P l, P rで f(P) の形で渡す template<class U, class F> void sort(vector<U> &a, F f) { sort(all(a), [&](U l, U r) { return f(l) < f(r); }); }; template<class U, class F> void rsort(vector<U> &a, F f) { sort(all(a), [&](U l, U r) { return f(l) > f(r); }); }; //F = T<T> //例えばreturn p.fi + p.se; template<class A, class B, class F> void sortp(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); sort(c, f); rep(i, sz(a)) a[i] = c[i].fi, b[i] = c[i].se;} template<class A, class B, class F> void rsortp(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); rsort(c, f); rep(i, sz(a))a[i] = c[i].first, b[i] = c[i].second;} template<class A, class B, class C, class F> void sortt(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); sort(d, f); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;} template<class A, class B, class C, class F> void rsortt(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); rsort(d, f); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;} template<class A, class B, class C, class D> void sortf(vector<A> &a, vector<B> &b, vector<C> &c, vector<D> &d) { auto e = vtof(a, b, c, d); sort(e); rep(i, sz(a)) a[i] = e[i].a, b[i] = e[i].b, c[i] = e[i].c, d[i] = e[i].d;} template<class A, class B, class C, class D> void rsortf(vector<A> &a, vector<B> &b, vector<C> &c, vector<D> &d) { auto e = vtof(a, b, c, d); rsort(e); rep(i, sz(a)) a[i] = e[i].a, b[i] = e[i].b, c[i] = e[i].c, d[i] = e[i].d;} /*indexの分で型が変わるためpcomparatorが必要*/ template<class T> vi sorti(vector<T> &a, pcomparator f) { auto b = a; vi ind = iota(0, sz(a)); sortp(b, ind, f); return ind;} template<class T, class F> vi sorti(vector<T> &a, F f) { vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { return f(a[x]) < f(a[y]); }); return ind;} template<class T> vi rsorti(vector<T> &a) { auto b = a; vi ind = iota(0, sz(a)); rsortp(b, ind); return ind;} template<class T, class F> vi rsorti(vector<T> &a, F f) { vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { return f(a[x]) > f(a[y]); }); return ind;} template<class A, class B, class F> vi sortpi(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { return f(c[x]) < f(c[y]); }); return ind;} template<class A, class B> vi sortpi(vector<A> &a, vector<B> &b, pcomparator f) { vi ind = iota(0, sz(a)); auto c = a; auto d = b; sortt(c, d, ind, f); return ind;} template<class A, class B> vi sortpi(vector<A> &a, vector<B> &b) { return sortpi(a, b, fisi); }; template<class A, class B, class F> vi rsortpi(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { return f(c[x]) > f(c[y]); }); return ind;} template<class A, class B> vi rsortpi(vector<A> &a, vector<B> &b) { return sortpi(a, b, fdsd); }; template<class A, class B, class C, class F> vi sortti(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { return f(d[x]) < f(d[y]); }); return ind;} template<class A, class B, class C> vi sortti(vector<A> &a, vector<B> &b, vector<C> &c, pcomparator f) { vi ind = iota(0, sz(a)); auto d = vtof(a, b, c, ind); sort(d, f); rep(i, sz(a))ind[i] = d[i].d; return ind;} template<class A, class B, class C> vi sortti(vector<A> &a, vector<B> &b, vector<C> &c) { vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { if (a[x] == a[y]) { if (b[x] == b[y])return c[x] < c[y]; else return b[x] < b[y]; } else { return a[x] < a[y]; }}); return ind;} template<class A, class B, class C, class F> vi rsortti(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { return f(d[x]) > f(d[y]); }); return ind;} template<class A, class B, class C> vi rsortti(vector<A> &a, vector<B> &b, vector<C> &c) { vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { if (a[x] == a[y]) { if (b[x] == b[y])return c[x] > c[y]; else return b[x] > b[y]; } else { return a[x] > a[y]; }}); return ind;} template<class T> void sort2(vector<vector<T >> &a) { for (ll i = 0, n = a.size(); i < n; ++i)sort(a[i]); } template<class T> void rsort2(vector<vector<T >> &a) { for (ll i = 0, n = a.size(); i < n; ++i)rsort(a[i]); } #endif template<class T> bool includes(vector<T> &a, vector<T> &b) { vi c = a; vi d = b; sort(c); sort(d); return includes(all(c), all(d));} template<class T> bool distinct(const vector<T> &A) { if ((int) (A).size() == 1)return true; if ((int) (A).size() == 2)return A[0] != A[1]; if ((int) (A).size() == 3)return (A[0] != A[1] && A[1] != A[2] && A[0] != A[2]); auto B = A; sort(B); int N = (B.size()); unique(B); return N == (int) (B.size());} template<class H, class... T> bool distinct(const H &a, const T &...b) { return distinct(vector<H>{a, b...}); } /*@formatter:off*/ template<typename W, typename T> void fill(W &xx, const T vall) { xx = vall; } template<typename W, typename T> void fill(vector<W> &vecc, const T vall) { for (auto &&vx : vecc)fill(vx, vall); } template<typename W, typename T> void fill(vector<W> &xx, const T v, ll len) { rep(i, len)xx[i] = v; } template<typename W, typename T> void fill(vector<W> &xx, const T v, int s, ll t) { rep(i, s, t)xx[i] = v; } template<typename W, typename T> void fill(vector<vector<W>> &xx, T v, int sh, int th, int sw, int tw) { rep(h, sh, th)rep(w, sw, tw)xx[h][w] = v; } //#define use_fill //_sum _array _max _min #ifdef use_fill template<typename A, size_t N, typename T> void fill(A (&a)[N], const T &v) { rep(i, N)a[i] = v; } template<typename A, size_t N, size_t O, typename T> void fill(A (&a)[N][O], const T &v) { rep(i, N)rep(j, O)a[i][j] = v; } template<typename A, size_t N, size_t O, size_t P, typename T> void fill(A (&a)[N][O][P], const T &v) { rep(i, N)rep(j, O)rep(k, P)a[i][j][k] = v; } template<typename A, size_t N, size_t O, size_t P, size_t Q, typename T> void fill(A (&a)[N][O][P][Q], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)a[i][j][k][l] = v; } template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, typename T> void fill(A (&a)[N][O][P][Q][R], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)a[i][j][k][l][m] = v; } template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S, typename T> void fill(A (&a)[N][O][P][Q][R][S], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)rep(n, S)a[i][j][k][l][m][n] = v; } template<class T, class U> void fill(vector<T> &a, const vi &ind, U val) { fora(v, ind) { a[v] = val; }} template<typename A, size_t N> A sum(A (&a)[N]) {A res = 0; rep(i, N)res += a[i]; return res;} template<typename A, size_t N, size_t O> A sum(A (&a)[N][O]) {A res = 0; rep(i, N)rep(j, O)res += a[i][j]; return res;} template<typename A, size_t N, size_t O, size_t P> A sum(A (&a)[N][O][P]) {A res = 0; rep(i, N)rep(j, O)rep(k, P)res += a[i][j][k]; return res;} template<typename A, size_t N, size_t O, size_t P, size_t Q> A sum(A (&a)[N][O][P][Q]) { A res = 0; rep(i, N)rep(j, O)rep(k, P)rep(l, Q)res += a[i][j][k][l]; return res;} template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R> A sum(A (&a)[N][O][P][Q][R]) { A res = 0; rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)res += a[i][j][k][l][m]; return res;} template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S> A sum(A (&a)[N][O][P][Q][R][S]) { A res = 0; rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)rep(n, S)res += a[i][j][k][l][m][n]; return res;} template<typename A, size_t N> A max(A (&a)[N]) {A res = a[0]; rep(i, N)res = max(res, a[i]); return res;} template<typename A, size_t N, size_t O> A max(A (&a)[N][O]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;} template<typename A, size_t N, size_t O, size_t P> A max(A (&a)[N][O][P]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;} template<typename A, size_t N, size_t O, size_t P, size_t Q> A max(A (&a)[N][O][P][Q], const T &v) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;} template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R> A max(A (&a)[N][O][P][Q][R]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;} template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S> A max(A (&a)[N][O][P][Q][R][S]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;} template<typename A, size_t N> A min(A (&a)[N]) { A res = a[0]; rep(i, N)res = min(res, a[i]); return res;} template<typename A, size_t N, size_t O> A min(A (&a)[N][O]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;} template<typename A, size_t N, size_t O, size_t P> A min(A (&a)[N][O][P]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;} template<typename A, size_t N, size_t O, size_t P, size_t Q> A min(A (&a)[N][O][P][Q], const T &v) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;} template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R> A min(A (&a)[N][O][P][Q][R]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;} template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S> A min(A (&a)[N][O][P][Q][R][S]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;} #endif /*@formatter:off*/ template<class T, class U> void inc(pair<T, U> &a, U v = 1) { a.first += v, a.second += v; } template<class T, class U> void inc(T &a, U v = 1) { a += v; } template<class T, class U = int> void inc(vector<T> &a, U v = 1) { for (auto &u:a)inc(u, v); } template<class T, class U> void dec(T &a, U v = 1) { a -= v; } template<class T, class U = int> void dec(vector<T> &a, U v = 1) { for (auto &u :a)dec(u, v); } template<class U> void dec(string &a, U v = 1) { for (auto &u :a)dec(u, v); } template<class T, class U, class W> void dec(vector<T> &a, vector<U> &b, W v = 1) {for (auto &u :a)dec(u, v);for (auto &u :b)dec(u, v);} template<class T, class U, class W> void dec(vector<T> &a, vector<U> &b, vector<W> &c) { for (auto &u :a)dec(u, 1); for (auto &u :b)dec(u, 1); for (auto &u :c)dec(u, 1);} bool ins(ll h, ll w, ll H, ll W) { return h >= 0 && w >= 0 && h < H && w < W; } bool san(ll l, ll v, ll r) { return l <= v && v < r; } template<class T> bool ins(vector<T> &a, ll i, ll j = 0) { return san(0, i, sz(a)) && san(0, j, sz(a)); } #define inside ins ll u0(ll a) { return a < 0 ? 0 : a; } template<class T> vector<T> u0(vector<T> &a) { vector<T> ret = a; fora(v, ret) { v = u(v); } return ret;} //todo 名前 bool d_(int a, int b) {if (b == 0)return false;return (a % b) == 0;} //エラー void ole() { #ifdef _DEBUG cerr << "ole" << endl;exit(0); #endif string a = "a"; rep(i, 30)a += a; rep(i, 1 << 17)cout << a << endl; cout << "OLE 出力長制限超過" << endl;exit(0); } void re(string s = "") {cerr << s << endl;assert(0 == 1);exit(0);} void tle() { while (inf)cout << inf << endl; } //@汎用便利関数 入力 ll in() {ll ret;cin >> ret;return ret;} template<class T> T in() { T ret; cin >> ret; return ret;} string sin() { string ret; cin >> ret; return ret;} template<class T> void in(T &head) { cin >> head; } template<class T, class... U> void in(T &head, U &... tail) { cin >> head; in(tail...);} template<class T, class U = typename T::value_type> true_type has_value_type(); template<class T> false_type has_value_type(); template<class T>struct is_iterable{using value = decltype(has_value_type<T>());}; /*@formatter:on*/ //value_typeを持つ場合呼べる //len回要素を追加する template<class Iterable, class T = typename Iterable::value_type> Iterable tin(int len) { Iterable ret; T tem; while (len--) { cin >> tem; ret += tem; } return ret;} template<class T> T tin() { T ret; cin >> ret; return ret;} template<class T> T tind(int len = 0) { auto ret = tin<T>(len); dec(ret, 1); return ret;} #define din_t2(type, a) type a;cin>>a #define din_t3(type, a, b) type a,b;cin>>a>> b #define din_t4(type, a, b, c) type a,b,c;cin>>a>>b>>c #define din_t5(type, a, b, c, d) type a,b,c,d;cin>>a>>b>>c>>d #define din_t6(type, a, b, c, d, e) type a,b,c,d,e;cin>>a>>b>>c>>d>>e #define din_t7(type, a, b, c, d, e, f) type a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f #define din_t(...) over7(__VA_ARGS__,din_t7,din_t6,din_t5,din_t4,din_t3 ,din_t2)(__VA_ARGS__) #define din(...) din_t(int,__VA_ARGS__) #define d_in #define dsig(...) din_t(signed,__VA_ARGS__) #define dst(...) din_t(string,__VA_ARGS__) #define dstr dst #define d_str dst #define dcha(...) din_t(char,__VA_ARGS__) #define dchar dcha #define ddou(...) din_t(double,__VA_ARGS__) #define din1d(a) din_t2(int, a);a-- #define din2d(a, b) din_t3(int, a,b);a--,b-- #define din3d(a, b, c) din_t4(int, a,b,c);a--,b--,c-- #define din4d(a, b, c, d) din_t5(int, a,b,c,d);a--,b--,c--,d-- #define dind(...) over4(__VA_ARGS__,din4d,din3d,din2d ,din1d)(__VA_ARGS__) #ifdef _DEBUG template<class T> void err2(T &&head) { cerr << head; } template<class T, class... U> void err2(T &&head, U &&... tail) { cerr << head << " "; err2(tail...);} template<class T, class... U> void err(T &&head, U &&... tail) { cerr << head << " "; err2(tail...); cerr << "" << endl;} template<class T> void err(T &&head) { cerr << head << endl; } void err() { cerr << "" << endl; } //debで出力する最大長 constexpr int DEB_LEN = 20; constexpr int DEB_LEN_H = 12; string deb_tos(const int &v) { if (abs(v) == inf || abs(v) == linf)return "e"; else return to_string(v);} template<class T> string deb_tos(const T &a) { stringstream ss; ss << a; return ss.str();} template<class T> string deb_tos(const optional<T> &a) { if (a.has_value()) { return deb_tos(a.value()); } else return "e"; } template<class T> string deb_tos(const vector<T> &a, ll W = inf) { stringstream ss; if (W == inf)W = min(sz(a), DEB_LEN); if (sz(a) == 0)return ss.str(); rep(i, W) { ss << deb_tos(a[i]); if (typeid(a[i]) == typeid(P)) { ss << endl; } else { ss << " "; } } return ss.str();} template<class T> string deb_tos(const vector<vector<T> > &a, vi H, vi W, int key = -1) { stringstream ss; ss << endl; vi lens(sz(W)); fora(h, H) { rep(wi, sz(W)) { lens[wi] = max(lens[wi], sz(deb_tos(a[h][W[wi]])) + 1); lens[wi] = max(lens[wi], sz(deb_tos(W[wi])) + 1); } } if (key == -1)ss << " *|"; else ss << " " << key << "|"; int wi = 0; fora(w, W) { ss << std::right << std::setw(lens[wi]) << w; wi++; } ss << "" << endl; rep(i, sz(W))rep(lens[i])ss << "_"; rep(i, 3)ss << "_"; ss << "" << endl; fora(h, H) { ss << std::right << std::setw(2) << h << "|"; int wi = 0; fora(w, W) { ss << std::right << std::setw(lens[wi]) << deb_tos(a[h][w]); wi++; } ss << "" << endl; } return ss.str();} template<class T> string deb_tos(const vector<vector<T> > &a, ll H = inf, ll W = inf, int key = -1) { H = (H != inf) ? H : min({H, sz(a), DEB_LEN_H}); W = min({W, sz(a[0]), DEB_LEN_H}); vi hs, ws; rep(h, H) { hs.push_back(h); } rep(w, W) { ws.push_back(w); } return deb_tos(a, hs, ws, key);} template<class T> string deb_tos(const vector<vector<vector<T> > > &a, ll H = inf) { stringstream ss; if (H == inf)H = DEB_LEN_H; H = min(H, sz(a)); rep(i, H) { ss << endl; ss << deb_tos(a[i], inf, inf, i); } return ss.str();} template<class T> string deb_tos(vector<set<T> > &a, ll H = inf, ll W = inf, int key = -1) {vector<vector<T> > b(sz(a));rep(i, sz(a)) { fora(v, a[i]) { b[i].push_back(v); }}return deb_tos(b, H, W, key);} template<size_t A>string deb_tos(T (&a)[A]){return deb_tos(vector<T>(begin(a), end(a)));} template<size_t A, size_t B>string deb_tos(T (&a)[A][B]){return deb_tos(vector<vector<T > >(begin(a), end(a)));} template<size_t A, size_t B, size_t C>string deb_tos(T (&a)[A][B][C]){return deb_tos(vector<vector<vector<T> > >(begin(a), end(a)));} template<class T> void out2(T head) { cout << head; res_mes += deb_tos(head);} template<class T, class... U> void out2(T head, U ... tail) { cout << head << " "; res_mes += deb_tos(head) + " "; out2(tail...);} template<class T, class... U> void out(T head, U ... tail) { cout << head << " "; res_mes += deb_tos(head) + " "; out2(tail...); cout << "" << endl; res_mes += "\n";} template<class T> void out(T head) { cout << head << endl; res_mes += deb_tos(head) + "\n";} void out() { cout << "" << endl; } #else #define err(...); template<class T> void out2(T &&head) { cout << head; } template<class T, class... U> void out2(T &&head, U &&... tail) { cout << head << " "; out2(tail...);} template<class T, class... U> void out(T &&head, U &&... tail) { cout << head << " "; out2(tail...); cout << "" << endl;} template<class T> void out(T &&head) { cout << head << endl;} void out() { cout << "" << endl;} #endif template<class T> void outl(const vector<T> &a, int n = inf) { rep(i, min(n, sz(a)))cout << a[i] << endl; } //テーブルをスペースなしで出力 template<class T> void outt(vector<vector<T>> &a) {rep(i, sz(a)) {rep(j, sz(a[i])) { cout << a[i][j]; }cout << endl;}} //int型をbit表記で出力 void outb(int a) { cout << bitset<20>(a) << endl; } template<class T> void na(vector<T> &a, ll n) {a.resize(n);rep(i, n)cin >> a[i];} template<class T> void na(set<T> &a, ll n) { rep(i, n)a.insert(in()); } #define dna(a, n) vi a; na(a, n);/*nを複数使うと n==in()の時バグる事に注意*/ #define dnad(a, n) vi a; nad(a, n); template<class T> void nao(vector<T> &a, ll n) {a.resize(n + 1);a[0] = 0;rep(i, n)cin >> a[i + 1];} template<class T> void naod(vector<T> &a, ll n) {a.resize(n + 1);a[0] = 0;rep(i, n)cin >> a[i + 1], a[i + 1]--;} template<class T> void nad(vector<T> &a, ll n) {a.resize(n);rep(i, n)cin >> a[i], a[i]--;} template<class T> void nad(set<T> &a, ll n) { rep(i, n)a.insert(in() - 1); } template<class T, class U> void na2(vector<T> &a, vector<U> &b, ll n) {a.resize(n);b.resize(n);rep(i, n)cin >> a[i] >> b[i];} template<class T, class U> void na2(set<T> &a, set<U> &b, ll n) {rep(i, n) {a.insert(in());b.insert(in());}} #define dna2(a, b, n) vi a,b; na2(a,b,n); template<class T, class U> void nao2(vector<T> &a, vector<U> &b, ll n) {a.resize(n + 1);b.resize(n + 1);a[0] = b[0] = 0;rep(i, n)cin >> a[i + 1] >> b[i + 1];} template<class T, class U> void na2d(vector<T> &a, vector<U> &b, ll n) {a.resize(n);b.resize(n);rep(i, n)cin >> a[i] >> b[i], a[i]--, b[i]--;} #define dna2d(a, b, n) vi a,b; na2d(a,b,n); template<class T, class U, class W> void na3(vector<T> &a, vector<U> &b, vector<W> &c, ll n) {a.resize(n);b.resize(n);c.resize(n);rep(i, n)cin >> a[i] >> b[i] >> c[i];} #define dna3(a, b, c, n) vi a,b,c; na3(a,b,c,n); template<class T, class U, class W> void na3d(vector<T> &a, vector<U> &b, vector<W> &c, ll n) {a.resize(n);b.resize(n);c.resize(n);rep(i, n)cin >> a[i] >> b[i] >> c[i], a[i]--, b[i]--, c[i]--;} #define dna3d(a, b, c, n) vi a,b,c; na3d(a,b,c,n); template<class T, class U, class W, class X> void na4(vector<T> &a, vector<U> &b, vector<W> &c, vector<X> &d, ll n) {a.resize(n);b.resize(n);c.resize(n);d.resize(n);rep(i, n)cin >> a[i] >> b[i] >> c[i] >> d[i];} #define dna4(a, b, c, d, n) vi a,b,c,d; na4(a,b,c,d,n); #define dna4d(a, b, c, d, n) vi a,b,c,d; na4d(a,b,c,d,n); #define nt(a, h, w) resize(a,h,w);rep(nthi,h)rep(ntwi,w) cin >> a[nthi][ntwi]; #define ntd(a, h, w) resize(a,h,w);rep(ntdhi,h)rep(ntdwi,w) cin >> a[ntdhi][ntdwi], a[ntdhi][ntdwi]--; #define ntp(a, h, w) resize(a,h+2,w+2);fill(a,'#');rep(ntphi,1,h+1)rep(ntpwi,1,w+1) cin >> a[ntphi][ntpwi]; #define dnt(S, h, w) vvi(S,h,w);nt(S,h,w); #define dntc(S, h, w) vvc(S,h,w);nt(S,h,w); #define dnts(S, h, w) vvs(S,h,w);nt(S,h,w); //デバッグ #define sp << " " << #define deb1(x) debugName(x)<<" = "<<deb_tos(x) #define deb_2(x, ...) deb1(x) <<", "<< deb1(__VA_ARGS__) #define deb_3(x, ...) deb1(x) <<", "<< deb_2(__VA_ARGS__) #define deb_4(x, ...) deb1(x) <<", "<< deb_3(__VA_ARGS__) #define deb5(x, ...) deb1(x) <<", "<< deb_4(__VA_ARGS__) #define deb6(x, ...) deb1(x) <<", "<< deb5(__VA_ARGS__) //#define deb7(x, ...) deb1(x) <<", "<< deb6(__VA_ARGS__) //#define deb8(x, ...) deb1(x) <<", "<< deb7(__VA_ARGS__) //#define deb9(x, ...) deb1(x) <<", "<< deb8(__VA_ARGS__) //#define deb10(x, ...) deb1(x) <<", "<< deb9(__VA_ARGS__) #ifdef _DEBUG bool was_deb = false; #define deb(...) do{was_deb=true;cerr<< over10(__VA_ARGS__,deb10,deb9,deb8,deb7,deb6,deb5,deb_4,deb_3,deb_2,deb1)(__VA_ARGS__) <<endl;}while(0) #define base_keta 8 void print_n_base(int x, int base) { cerr << bitset<base_keta>(x) << endl; } template<class T> void print_n_base(vector<T> X, int base) {cerr << endl;for (auto &&x:X) { print_n_base(x, base); }cerr << endl;} //n進数 #define deb2(x) was_deb=true;cerr<<debugName(x)<<" = ";print_n_base(x, 2); #define deb3(x) was_deb=true;cerr<<debugName(x)<<" = ";print_n_base(x, 3); #define deb4(x) was_deb=true;cerr<<debugName(x)<<" = ";print_n_base(x, 4); #define deb_ex_deb(x, len) debugName(x)<<" = "<<deb_tos(x, len) #define call_deb_ex_deb(x, len) deb_ex_deb(x, len) //要素が存在する行だけ出力(vvt) #define deb_ex(v) do {int N = sz(v);int s = N;int t = 0;rep(i, N) {if (sz(v[i])) {chmi(s, i);chma(t, i);}}auto ex_v = sub(v, s, N);str S = deb_tos(ex_v, sz(ex_v));debugName(v);cerr<<" = "<<endl;cerr << S << endl;} while (0); #define debi(A) {int len=min(sz(A),20); was_deb=true;cerr<<debugName(A)<<" = "<<endl;rep(i, len)cerr<<std::right << std::setw((int)(sz(tos(A[i]))+(i ? 1 : 0)))<<(i%10);cerr<<endl;rep(i, len)cerr<<std::right << std::setw((int)(sz(tos(A[i]))+(i ? 1 : 0)))<<A[i];cerr<<endl;} template<class T, class F> string deb_tos_f(vector<vector<T> > &a, F f, int key = -1) { vi hs, ws_; int H = sz(a), W = sz(a[0]); vi exh(H), exw(W); rep(h, H) { rep(w, W) { if (f(a[h][w])) { exh[h] = true; exw[w] = true; } } } rep(h, H) if (exh[h])hs.push_back(h); rep(w, W) if (exw[w])ws_.push_back(w); return deb_tos(a, hs, ws_, key);} template<class T, class F> string deb_tos_f(vector<vector<vector<T>>> &a, F f) { stringstream ss; int H = sz(a); if (sz(a) == 0)return ss.str(); rep(i, H) { ss << deb_tos_f(a[i], f, i); } ss << "" << endl; return ss.str();} #define debf_normal(tab, f) do{cerr<<debugName(tab)<<" = "<<endl;cerr<< deb_tos_f(tab, f)<<endl;}while(0); #define debf2(tab, siki_r) debf_normal(tab, lamr(siki_r)) #define debf3(tab, v, siki) debf_normal(tab, lam(siki)) //S, sikir //S, v, siki #define debf(...) over3(__VA_ARGS__,debf3,debf2,debf1)(__VA_ARGS__) #else #define deb(...) ; #define deb2(...) ; #define deb3(...) ; #define deb4(...) ; #define deb_ex(...) ; #define debf(...) ; #define debi(...) ; #endif #define debugline(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n' using u32 = unsigned; using u64 = unsigned long long; using u128 = __uint128_t; using bint =__int128; std::ostream &operator<<(std::ostream &dest, __int128_t value) { std::ostream::sentry s(dest); if (s) { __uint128_t tmp = value < 0 ? -value : value; char buffer[128]; char *d = std::end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } ll len = std::end(buffer) - d; if (dest.rdbuf()->sputn(d, len) != len) { dest.setstate(std::ios_base::badbit); } } return dest;} __int128 to_bint(string &s) { __int128 ret = 0; for (ll i = 0; i < (ll)s.length(); ++i) if ('0' <= s[i] && s[i] <= '9') ret = 10 * ret + s[i] - '0'; return ret;} void operator>>(istream &iss, bint &v) { string S; iss >> S; v = 0; rep(i, sz(S)) { v *= 10; v += S[i] - '0'; }} //便利関数 //テスト用 #define rand xor128_ unsigned long xor128_(void) { static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123; unsigned long t; t = (x ^ (x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));} char ranc() { return (char) ('a' + rand() % 26); } ll rand(ll min, ll max) { assert(min <= max); if (min >= 0 && max >= 0) { return rand() % (max + 1 - min) + min; } else if (max < 0) { return -rand(-max, -min); } else { if (rand() % 2) { return rand(0, max); } else { return -rand(0, -min); }}} ll rand(ll max) { return rand(0, max); } template<class T> T rand(vector<T> &A) { return A[rand(sz(A) - 1)]; } //重複することがある template<class T> vector<T> ranv(vector<T>& A, int N){vector<T>ret(N);rep(i,N){ret[i]=rand(A);}return ret;} template<class T> vector<T> ranv_unique(vector<T>& A, int N){ vector<T> ret(N); umapi was; rep(j,N){ int i; while(1){ i = rand(sz(A)-1); if(was.find(i) == was.end())break; } ret[j] = A[i];was[i]=1; } return ret;} vi ranv(ll n, ll min, ll max) { vi v(n); rep(i, n)v[i] = rand(min, max); return v;} #ifdef _DEBUG bool timeup(int time){ static bool never = true; if(never)message += "may timeup, because slow"; never = false; auto end_time = system_clock::now(); auto part = duration_cast<milliseconds>(end_time - start_time); auto lim = milliseconds(time); return part >= lim; } #else bool timeup(int time) { auto end_time = system_clock::now(); auto part = duration_cast<milliseconds>(end_time - start_time); auto lim = milliseconds(time); return part >= lim; } #endif void set_time() { past_time = system_clock::now(); } //MS型(millisecqnds)で返る //set_timeをしてからの時間 auto calc_time_milli() { auto now = system_clock::now(); auto part = duration_cast<milliseconds>(now - past_time); return part;} auto calc_time_micro() { auto now = system_clock::now(); auto part = duration_cast<microseconds>(now - past_time); return part;} auto calc_time_nano() { auto now = system_clock::now(); auto part = duration_cast<nanoseconds>(now - past_time); return part;} bool calc_time(int zikan) { return calc_time_micro() >= microseconds(zikan); } using MS=std::chrono::microseconds; int div(microseconds a, microseconds b) { return a / b; } int div(nanoseconds a, nanoseconds b) { if (b < nanoseconds(1)) { return a / nanoseconds(1); } int v = a / b; return v;} //set_time(); //rep(i,lim)shori //lim*=time_nanbai(); //rep(i,lim)shoriと使う //全体でmilliかかっていいときにlimを何倍してもう一回できるかを返す int time_nanbai(int milli) { auto dec = duration_cast<nanoseconds>(past_time - start_time); auto part = calc_time_nano(); auto can_time = nanoseconds(milli * 1000 * 1000); can_time -= part; can_time -= dec; return div(can_time, part); } //#define use_rand #ifdef use_rand str ransu(ll n) { str s; rep(i, n)s += (char) rand('A', 'Z'); return s;} str ransl(ll n) { str s; rep(i, n)s += (char) rand('a', 'z'); return s;} //単調増加 vi ranvinc(ll n, ll min, ll max) { vi v(n); bool bad = 1; while (bad) { bad = 0; v.resize(n); rep(i, n) { if (i && min > max - v[i - 1]) { bad = 1; break; } if (i)v[i] = v[i - 1] + rand(min, max - v[i - 1]); else v[i] = rand(min, max); } } return v;} //便利 汎用 #endif void ranvlr(ll n, ll min, ll max, vi &l, vi &r) { l.resize(n); r.resize(n); rep(i, n) { l[i] = rand(min, max); r[i] = l[i] + rand(0, max - l[i]); }} template<class Iterable, class T = typename Iterable::value_type> vector<pair<T, int>> run_length(const Iterable &a) { vector<pair<T, int>> ret; ret.eb(a[0], 1); rep(i, 1, sz(a)) { if (ret.back().fi == a[i]) { ret.back().se++; } else { ret.eb(a[i], 1); }} return ret;} /*@formatter:off*/ //#define use_mgr //_goldd _goldt #ifdef use_mgr template<class T, class F> T mgr(T ok, T ng, F f, int deb_ = 0) { bool han = true; if (deb_) { if (ok < ng) while (ng - ok > 1) { T mid = (ok + ng) >> 1; if (f(mid))ok = mid, han = true; else ng = mid, han = false; deb(mid, han); } else while (ok - ng > 1) { T mid = (ok + ng) >> 1; if (f(mid))ok = mid, han = true; else ng = mid, han = false; deb(mid, han); } } else { if (ok < ng) while (ng - ok > 1) { T mid = (ok + ng) >> 1; if (f(mid))ok = mid, han = true; else ng = mid, han = false; } else while (ok - ng > 1) { T mid = (ok + ng) >> 1; if (f(mid))ok = mid, han = true; else ng = mid, han = false; } } return ok;} template<class T, class F> T mgr(signed ok, T ng, F f) { return mgr((T) ok, ng, f); } template<class T, class F> T mgr(T ok, signed ng, F f) { return mgr(ok, (T) ng, f); } template<class F> int mgr(signed ok, signed ng, F f) { return mgr((ll) ok, (ll) ng, f); } //[l, r)の中で,f(i)がtrueとなる範囲を返す okはそこに含まれる template<class F> P mgr(int l, int r, F f, int ok) { if (f(ok) == 0) { out("f(ok) must true"); re(); } return mp(mgr(ok, l - 1, f), mgr(ok, r, f) + 1);} template<class F> dou mgrd(dou ok, dou ng, F f, int kai = 100) { bool han = true; if (ok < ng) rep(i, kai) { dou mid = (ok + ng) / 2; if (f(mid))ok = mid, han = true; else ng = mid, han = false; deb(mid, han); } else rep(i, kai) { dou mid = (ok + ng) / 2; if (f(mid))ok = mid, han = true; else ng = mid, han = false; deb(mid, han); } return ok;} template<class F> dou mgrd_time(dou ok, dou ng, F f,int time = 1980) { bool han = true; if (ok < ng) while(1) { dou mid = (ok + ng) /2; if (f(mid))ok = mid, han = true; else ng = mid, han = false; deb(mid,han); if(timeup(time)){ break; } } else while(1) { dou mid = (ok + ng) /2; if (f(mid))ok = mid, han = true; else ng = mid, han = false; deb(mid,han); if(timeup(time)){ break; } } return ok;} //添え字を返す template<class F> ll goldd_l(ll left, ll right, F calc) { double GRATIO = 1.6180339887498948482045868343656; ll lm = left + (ll) ((right - left) / (GRATIO + 1.0)); ll rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); ll fl = calc(lm); ll fr = calc(rm); while (right - left > 10) { if (fl < fr) { right = rm; rm = lm; fr = fl; lm = left + (ll) ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } ll minScore = MAX<ll>(); ll resIndex = left; for (ll i = left; i < right + 1; ++i) { ll score = calc(i); if (minScore > score) { minScore = score; resIndex = i; } } return resIndex;} template<class F> ll goldt_l(ll left, ll right, F calc) { double GRATIO = 1.6180339887498948482045868343656; ll lm = left + (ll) ((right - left) / (GRATIO + 1.0)); ll rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); ll fl = calc(lm); ll fr = calc(rm); while (right - left > 10) { if (fl > fr) { right = rm; rm = lm; fr = fl; lm = left + (ll) ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } if (left > right) { ll l = left; left = right; right = l; } ll maxScore = MIN<ll>(); ll resIndex = left; for (ll i = left; i < right + 1; ++i) { ll score = calc(i); if (maxScore < score) { maxScore = score; resIndex = i; } } return resIndex;} /*loopは200にすればおそらく大丈夫 余裕なら300に*/ template<class F> dou goldd_d(dou left, dou right, F calc, ll loop = 200) { dou GRATIO = 1.6180339887498948482045868343656; dou lm = left + ((right - left) / (GRATIO + 1.0)); dou rm = lm + ((right - lm) / (GRATIO + 1.0)); dou fl = calc(lm); dou fr = calc(rm); /*200にすればおそらく大丈夫*/ /*余裕なら300に*/ ll k = 141; loop++; while (--loop) { if (fl < fr) { right = rm; rm = lm; fr = fl; lm = left + ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } return left;} template<class F> dou goldt_d(dou left, dou right, F calc, ll loop = 200) { double GRATIO = 1.6180339887498948482045868343656; dou lm = left + ((right - left) / (GRATIO + 1.0)); dou rm = lm + ((right - lm) / (GRATIO + 1.0)); dou fl = calc(lm); dou fr = calc(rm); loop++; while (--loop) { if (fl > fr) { right = rm; rm = lm; fr = fl; lm = left + ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } return left;} //l ~ rを複数の区間に分割し、極致を与えるiを返す time-20 msまで探索 template<class F> ll goldd_ls(ll l, ll r, F calc, ll time = 2000) { auto lim = milliseconds(time - 20); ll mini = 0, minv = MAX<ll>(); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); ll haba = (r - l + k) / k;/*((r-l+1) + k-1) /k*/ ll nl = l; ll nr = l + haba; rep(i, k) { ll ni = goldd_l(nl, nr, calc); if (chmi(minv, calc(ni))) mini = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return mini;} template<class F> ll goldt_ls(ll l, ll r, F calc, ll time = 2000) { auto lim = milliseconds(time - 20); ll maxi = 0, maxv = MIN<ll>(); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); ll haba = (r - l + k) / k;/*((r-l+1) + k-1) /k*/ ll nl = l; ll nr = l + haba; rep(i, k) { ll ni = goldt_l(nl, nr, calc); if (chma(maxv, calc(ni))) maxi = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return maxi;} template<class F> dou goldd_d_s(dou l, dou r, F calc, ll time = 2000) { /*20ms余裕を持つ*/ auto lim = milliseconds(time - 20); dou mini = 0, minv = MAX<dou>(); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); dou haba = (r - l) / k; dou nl = l; dou nr = l + haba; rep(i, k) { dou ni = goldd_d(nl, nr, calc); if (chmi(minv, calc(ni))) mini = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return mini;} template<class F> dou goldt_d_s(dou l, dou r, F calc, ll time = 2000) { /*20ms余裕を残している*/ auto lim = milliseconds(time - 20); dou maxi = 0, maxv = MIN<dou>(); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); dou haba = (r - l) / k; dou nl = l; dou nr = l + haba; rep(i, k) { dou ni = goldt_d(nl, nr, calc); if (chma(maxv, calc(ni))) maxi = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return maxi;} #endif //strを整数として比較 string smax(str &a, str b) { if (sz(a) < sz(b)) { return b; } else if (sz(a) > sz(b)) { return a; } else if (a < b)return b; else return a; } //strを整数として比較 string smin(str &a, str b) { if (sz(a) > sz(b)) { return b; } else if (sz(a) < sz(b)) { return a; } else if (a > b)return b; else return a; } //エラー-1 template<typename W, typename T> ll find(vector<W> &a, int l, const T key) {rep(i, l, sz(a))if (a[i] == key)return i;return -1;} template<typename W, typename T> ll find(vector<W> &a, const T key) {rep(i, sz(a))if (a[i] == key)return i;return -1;} template<typename W, typename T> P find(vector<vector<W >> &a, const T key) {rep(i, sz(a))rep(j, sz(a[0]))if (a[i][j] == key)return mp(i, j);return mp(-1, -1);} //getid(find())を返す 1次元にする template<typename W, typename T> int findi(vector<vector<W >> &a, const T key) {rep(i, sz(a))rep(j, sz(a[0]))if (a[i][j] == key)return i * sz(a[0]) + j;return -1;} template<typename W, typename U> T find(vector<vector<vector<W >>> &a, const U key) {rep(i, sz(a))rep(j, sz(a[0]))rep(k, sz(a[0][0]))if (a[i][j][k] == key)return T(i, j, k);return T(-1, -1, -1);} //無ければ-1 int find(string &s, const string key) { int klen = sz(key); rep(i, sz(s) - klen + 1) { if (s[i] != key[0])continue; if (s.substr(i, klen) == key) { return i; } }return -1;} int find(string &s, int l, const string key) { int klen = sz(key); rep(i, l, sz(s) - klen + 1) { if (s[i] != key[0])continue; if (s.substr(i, klen) == key) { return i; } } return -1;} int find(string &s, const char key) { rep(i, sz(s)) { if (s[i] == key)return i; } return -1;} int find(string &s, int l, const char key) { rep(i, l, sz(s)) { if (s[i] == key)return i; } return -1;} //N箇所について右のkeyの場所を返す template<typename W, typename T> vi finds(const W &a, const T& key) { int n = sz(a); vi rpos(n, -1); rer(i, n-1){ if(i<n-1){ rpos[i] = rpos[i+1]; } if(a[i]==key)rpos[i] = i; } return rpos;} template<typename W, typename T> vi rfinds(const W &a, const T& key) { int n = sz(a); vi lpos(n, -1); rep(i, n){ if(i> 0){ lpos[i] = lpos[i-1]; } if(a[i]==key)lpos[i] = i; } return lpos;} template<typename W, typename T> ll count2(W &a, const T k) { return a == k; } template<typename W, typename T> ll count2(vector<W> &a, const T k) { ll ret = 0; fora(v, a){ret += count2(v, k); } return ret;} template<typename W, typename T> ll count(vector<W> &a, const T k) { ll ret = 0; fora(v, a){ret += count2(v, k);} return ret;} vi count(vi &a) { int ma = 0; fora(v, a) { if (ma < v)ma = v; } vi res(ma + 1); fora(v, a) { res[v]++; } return res;} ll count(str &a, str k) { ll ret = 0, len = k.length(); auto pos = a.find(k); while (pos != string::npos)pos = a.find(k, pos + len), ++ret; return ret;} ll count(const str &a, char k){ int cou=0; for(auto && c :a ){ cou += c==k; } return cou;} //'a' = 'A' = 0 として集計 既に-'a'されていても動く vi count(str &a, int l, int r) { vi cou(26); char c = 'a'; if ('A' <= a[l] && a[l] <= 'Z')c = 'A'; if ('a' <= a[l] && a[l] <= 'z') c = 'a'; else c = 0; rep(i, l, r)++cou[a[i] - c]; return cou;} #define couif count_if //algorythm ll rev(ll a) { ll res = 0; while (a) { res *= 10; res += a % 10; a /= 10; } return res;} template<class T> auto rev(const vector<T> &a) { auto b = a; reverse(all(b)); return b;} /* \反転 */ template<class U> auto rev(vector<vector<U>> &a) { vector<vector<U> > b(sz(a[0]), vector<U>(sz(a))); rep(h, sz(a)) rep(w, sz(a[0]))b[w][h] = a[h][w]; return b;} /* |反転 */ template<class U> auto revw(vector<vector<U>> &a) { vector<vector<U> > b(sz(a), vector<U>(sz(a[0]))); int W = sz(a[0]); rep(h, sz(a)) rep(w, sz(a[0])) { b[h][W - 1 - w] = a[h][w]; } return b;} /* ー反転 */ template<class U> auto revh(vector<vector<U>> &a) { vector<vector<U> > b(sz(a), vector<U>(sz(a[0]))); int H = sz(a); rep(h, sz(a)) rep(w, sz(a[0])) { b[H - 1 - h][w] = a[h][w]; } return b;} /* /反転 */ template<class U> auto revr(vector<vector<U>> &a) { vector<vector<U> > b(sz(a[0]), vector<U>(sz(a))); int H = sz(a); int W = sz(a[0]); rep(h, sz(a)) rep(w, sz(a[0]))b[w][h] = a[H - 1 - h][W - 1 - w]; return b;} auto rev(const string &a) { string b = a; reverse(all(b)); return b;} constexpr ll p10[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000ll, 100000000000ll, 1000000000000ll, 10000000000000ll, 100000000000000ll, 1000000000000000ll, 10000000000000000ll, 100000000000000000ll, 1000000000000000000ll}; //0は0桁 ll keta(ll v, int if_zero_res) { if(!v)return if_zero_res;if (v < p10[9]) { if (v < p10[4]) { if (v < p10[2]) { if (v < p10[1]) { if (v < p10[0])return 0; else return 1; } else return 2; } else { if (v < p10[3]) return 3; else return 4; }} else { if (v < p10[7]) { if (v < p10[5]) return 5; else if (v < p10[6])return 6; else return 7; } else { if (v < p10[8])return 8; else return 9; }}} else { if (v < p10[13]) { if (v < p10[11]) { if (v < p10[10]) return 10; else return 11; } else { if (v < p10[12]) return 12; else return 13; }} else { if (v < p10[15]) { if (v < p10[14]) return 14; else return 15; } else { if (v < p10[17]) { if (v < p10[16]) return 16; else return 17; } else { if (v < p10[18])return 18; else return 19; }}}}} #if __cplusplus >= 201703L ll getr(ll a, ll keta) { return (a / pow<ll>(10, keta)) % 10; } #else ll getr(ll a, ll keta) { return (a / (int)pow(10, keta)) % 10; } #endif //上から何桁目か ll getl(ll a, ll ket) {int sketa = keta(a, 1);return getr(a, sketa - 1 - ket);} ll dsum(ll v, ll sin = 10) {ll ret = 0;for (; v; v /= sin)ret += v % sin;return ret;} ll mask10(ll v) { return p10[v] - 1; } //変換系 template<class T, class U> auto to_v1(vector<reference_wrapper<U>>& ret, vector<T> &A) { rep(i, sz(A))ret.push_back(A[i]); return ret;} template<class T, class U> auto to_v1(vector<reference_wrapper<U>>& ret, vector<vector<T> > &A) {rep(i, sz(A))to_v1(ret, A[i]);return ret;} //参照付きで1次元に起こす template<class T> auto to_v1(vector<vector<T> > &A) {vector<reference_wrapper<decl2(A)>> ret;rep(i, sz(A))to_v1(ret, A[i]);return ret;} //[v] := iとなるようなvectorを返す //存在しない物は-1 //空でも動く(なぜか) template<class T> auto keys(const T& a) { vector<decltype((a.begin())->fi)> res; for (auto &&k :a)res.push_back(k.fi); return res;} template<class T> auto values(const T& a) { vector<decltype((a.begin())->se)> res; for (auto &&k :a)res.push_back(k.se); return res;} //todo 可変長で template<class T> constexpr T min(T a, T b, T c) { return a >= b ? b >= c ? c : b : a >= c ? c : a; } template<class T> constexpr T max(T a, T b, T c) { return a <= b ? b <= c ? c : b : a <= c ? c : a; } template<class T> T min(vector<T> &a, ll s = -1, ll n = -1) { set_lr12(s, n, sz(a)); return *min_element(a.begin() + s, a.begin() + min(n, sz(a))); } template<class T> T max(vector<T> &a, ll s = -1, ll n = -1) { set_lr12(s, n,sz(a)); return *max_element(a.begin() + s, a.begin() + min(n, sz(a))); } template<class T> T mini(const vector<T> &a) { return min_element(all(a)) - a.begin(); } template<class T> T maxi(const vector<T> &a) { return max_element(all(a)) - a.begin(); } template<class T> T sum(const vector<T> &A, int l = -1, int r = -1) { T s = 0; set_lr12(l, r, sz(A)); rep(i, l, r)s += A[i]; return s;} template<class T> auto sum(const vector<vector<T>> &A) { decl2(A) s = 0; rep(i, sz(A))s += sum(A[i]); return s;} template<class T> T min(const vector<T>& A, int l = -1, int r = -1 ){T s=MAX<T>();set_lr12(l, r, sz(A));rep(i, l, r)s=min(s, A[i]);return s;} template<class T> auto min(const vector<vector<T>>& A ){using S =decl2(A);S s=MAX<S>();rep(i, sz(A))s=min(s, A[i]);return s;} template<class T> T max(const vector<T>& A, int l = -1, int r = -1 ){T s=MIN<T>();set_lr12(l, r, sz(A));rep(i, l, r); rep(i, l, r)s=max(s, A[i]);return s;} template<class T> auto max(const vector<vector<T>>& A ){using S =decl2(A);S s=MIN<S>();rep(i, sz(A))s=max(s, A[i]);return s;} template<class T> T mul(vector<T> &v, ll t = inf) { T ret = v[0]; rep(i, 1, min(t, sz(v)))ret *= v[i]; return ret;} //template<class T, class U, class... W> auto sumn(vector<T> &v, U head, W... tail) { auto ret = sum(v[0], tail...); rep(i, 1, min(sz(v), head))ret += sum(v[i], tail...); return ret;} //indexを持つvectorを返す vi inds_(vi &a) { int n = max(a) + 1; vi ret(n, -1); rep(i, sz(a)) { assert(ret[a[i]] ==-1);ret[a[i]] = i; } return ret;} void clear(PQ &q) { q = PQ(); } void clear(priority_queue<int> &q) { q = priority_queue<int>(); } template<class T> void clear(queue<T> &q) { while (q.size())q.pop(); } //template<class T> T *negarr(ll size) { T *body = (T *) malloc((size * 2 + 1) * sizeof(T)); return body + size;} //template<class T> T *negarr2(ll h, ll w) { double **dummy1 = new double *[2 * h + 1]; double *dummy2 = new double[(2 * h + 1) * (2 * w + 1)]; dummy1[0] = dummy2 + w; for (ll i = 1; i <= 2 * h + 1; ++i) { dummy1[i] = dummy1[i - 1] + 2 * w + 1; } double **a = dummy1 + h; return a;} template<class T> struct ruiC { vector<T> rui; ruiC(vector<T> &ru) : rui(ru) {} /*先頭0*/ ruiC() : rui(1, 0) {} T operator()(ll l, ll r) { if (l > r) { cerr << "ruic "; deb(l, r); assert(0); } return rui[r] - rui[l]; } T operator()(int r = inf) { return operator()(0, min(r, sz(rui) - 1)); } /*ruiv[]をruic[]に変えた際意味が変わるのがまずいため()と統一*/ /*単体iを返す 累積でないことに注意(seg木との統一でこうしている)*/ // T operator[](ll i) { return rui[i + 1] - rui[i]; } T operator[](ll i) { return rui[i]; } /*0から順に追加される必要がある*/ void operator+=(T v) { rui.push_back(rui.back() + v); } void add(int i, T v) {if (sz(rui) - 1 != i)ole();operator+=(v);} T back() { return rui.back(); } ll size() { return rui.size(); } auto begin() { return rui.begin(); } auto end() { return rui.end(); } }; template<class T> string deb_tos(ruiC<T> &a) {return deb_tos(a.rui);} template<class T> ostream &operator<<(ostream &os, ruiC<T> a) { fora(v, a.rui){os << v << " "; } return os;} template<class T> vector<T> ruiv(vector<T> &a) { vector<T> ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] + a[i]; return ret;} template<class T> ruiC<T> ruic(vector<T> &a) { vector<T> ret = ruiv(a); return ruiC<T>(ret);} template<class T> ruiC<T> ruic() { return ruiC<T>(); } //imoは0-indexed //ruiは1-indexed template<class T> vector<T> imo(vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)ret[i + 1] += ret[i]; return ret;} //#define use_rui //_imo _ruic _ruiv #ifdef use_rui //kと同じものの数 template<class T, class U> vi imo(const vector<T> &a, U k) { vi equ(sz(a)); rep(i, sz(a)){ equ[i] = a[i]==k; } return imo(equ);} template<class T> vector<T> imox(vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)ret[i + 1] ^= ret[i]; return ret;} //漸化的に最小を持つ template<class T> vector<T> imi(vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)chmi(ret[i + 1], ret[i]); return ret;} template<class T> vector<T> ima(vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)chma(ret[i + 1], ret[i]); return ret;} template<class T> vector<T> rimi(vector<T> &v) { vector<T> ret = v; rer(i, sz(ret) - 1, 1)chmi(ret[i - 1], ret[i]); return ret;} template<class T> vector<T> rima(vector<T> &v) { vector<T> ret = v; rer(i, sz(ret) - 1, 1)chma(ret[i - 1], ret[i]); return ret;} template<class T> struct ruimax { template<typename Monoid> struct SegmentTree { /*pairで処理*/ int sz; vector<Monoid> seg; const Monoid M1 = mp(MIN<T>(), -1); Monoid f(Monoid a, Monoid b) { return max(a, b); } void build(vector<T> &a) { int n = sz(a); sz = 1; while (sz < n) sz <<= 1; seg.assign(2 * sz, M1); rep(i, n) { seg[i + sz] = mp(a[i], i); } for (int k = sz - 1; k > 0; k--) { seg[k] = f(seg[k << 1], seg[(k << 1) | 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, seg[a++]); if (b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } }; private: vector<T> ve; SegmentTree<pair<T, int>> seg; vector<T> rv; vector<int> ri; bool build = false; public: int n; ruimax(vector<T> &a) : ve(a), n(sz(a)) { int index = -1; T ma = MIN<T>(); rv.resize(n + 1); ri.resize(n + 1); rv[0] = -INF<T>; ri[0] = -1; rep(i, n) { if (chma(ma, a[i])) { index = i; } rv[i + 1] = ma; ri[i + 1] = index; } } T operator()(int l, int r) { if (!(l <= r && 0 <= l && r <= n)) { deb(l, r, n); assert(0); } if (l == 0) { return rv[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).first; } } T operator()(int r = inf) { return operator()(0, min(r, n)); } T operator[](int r) { return operator()(0, r); } T getv(int l, int r) { return operator()(l, r); } T getv(int r = inf) { return getv(0, min(r, n)); }; int geti(int l, int r) { assert(l <= r && 0 <= l && r <= n); if (l == 0) { return ri[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).second; } } int geti(int r = inf) { return geti(0, min(r, n)); }; auto begin() { return rv.begin(); } auto end() { return rv.end(); } }; template<class T> struct ruimin { template<typename Monoid> struct SegmentTree { /*pairで処理*/ int sz;vector<Monoid> seg; const Monoid M1 = mp(MAX<T>(), -1); Monoid f(Monoid a, Monoid b) { return min(a, b); } void build(vector<T> &a) { int n = sz(a); sz = 1; while (sz < n) sz <<= 1; seg.assign(2 * sz, M1); rep(i, n) { seg[i + sz] = mp(a[i], i); } for (int k = sz - 1; k > 0; k--) { seg[k] = f(seg[k << 1], seg[(k << 1) | 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, seg[a++]); if (b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } }; private: vector<T> ve; SegmentTree<pair<T, int>> seg; vector<T> rv; vector<int> ri; bool build = false; int n; public: ruimin(vector<T> &a) : ve(a), n(sz(a)) { int index = -1; T mi = MAX<T>(); rv.resize(n + 1); ri.resize(n + 1); rv[0] = INF<T>; ri[0] = -1; rep(i, n) { if (chmi(mi, a[i])) { index = i; } rv[i + 1] = mi; ri[i + 1] = index; } } T operator()(int l, int r) { assert(l <= r && 0 <= l && r <= n); if (l == 0) { return rv[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).first; } } T operator()(int r = inf) { return operator()(0, min(r, n)); } T operator[](int r) { return operator()(0, r); } T getv(int l, int r) { return operator()(l, r); } T getv(int r = inf) { return getv(0, min(r, n)); }; int geti(int l, int r) { { assert(l <= r && 0 <= l && r <= n); if (l == 0) { return ri[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).second; } } assert(l <= r && 0 <= l && r <= n); if (l == 0) { return ri[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).second; } } int geti(int r = inf) { return geti(0, min(r, n)); }; auto begin() { return rv.begin(); } auto end() { return rv.end(); } };/*@formatter:off*/ vvi() ruib(vi &a) { vvi(res, 61, sz(a) + 1); rep(k, 61) { rep(i, sz(a)) { res[k][i + 1] = res[k][i] + ((a[i] >> k) & 1); }} return res;} vector<ruiC<int>> ruibc(vi &a) {vector<ruiC<int>> ret(61); vvi(res, 61, sz(a)); rep(k, 61) { rep(i, sz(a)) { res[k][i] = (a[i] >> k) & 1; } ret[k] = ruic(res[k]); } return ret;} vector<ll> ruiv(string &a) { if (sz(a) == 0)return vi(1); ll dec = ('0' <= a[0] && a[0] <= '9') ? '0' : 0; vector<ll> ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] + a[i] - dec; return ret;} ruiC<ll> ruic(string &a) { vector<ll> ret = ruiv(a); return ruiC<ll>(ret);} //kと同じものの数 template<class T, class U> vi ruiv(T &a, U k) { vi ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] + (a[i] == k); return ret;} template<class T, class U> ruiC<ll> ruic(T &a, U k) { vi ret = ruiv(a, k); return ruiC<ll>(ret);} template<class T> struct ruiC2 { int H; vector<ruiC<T>> rui; ruiC2(vector<vector<T>> &ru) : rui(sz(ru)), H(sz(ru)) { for (int h = 0; h < H; h++) { rui[h] = ruic(ru[h]); }} //WについてHを返す vector<T> operator()(ll l, ll r) { if (l > r) { cerr << "ruic "; deb(l, r); assert(0); } vector<T> res(H); for (int h = 0; h < H; h++)res[h] = rui[h](l, r); return res; } //HについてWを返す ruiC<T> &operator[](ll h) { assert(h < H); return rui[h]; } // vector<T> operator()(int r) { return operator()(0, r); } /*ruiv[]をruic[]に変えた際意味が変わるのがまずいため()と統一*/ /*単体iを返す 累積でないことに注意(seg木との統一でこうしている)*/ // T operator[](ll i) { return rui[i + 1] - rui[i]; } /*0から順に追加される必要がある*/ // T back() { return rui.back(); } // ll size() { return rui.size(); } // auto begin(){return rui.begin();} // auto end(){return rui.end();} }; //a~zを0~25として // rui(l,r)でvector(26文字について, l~rのcの個数) // rui[h] ruic()を返す ruiC2<ll> ruicou(str &a) { str s = a; replace(s); vector<ruiC<ll>> res(26); vvi(cou, 26, sz(s)); rep(i, sz(s)) { cou[s[i]][i] = 1; } return ruiC2<ll>(cou);} ruiC2<ll> ruicou(vi &a) { int H = max(a) + 1; vector<ruiC<ll>> res(H); vvi(cou, H, sz(a)); rep(i, sz(a)) { cou[a[i]][i] = 1; } return ruiC2<ll>(cou);} template<class T, class U> ruiC<ll> ruicou(vector<T> &a, U b) { vi cou(sz(a)); rep(i, sz(a)) { cou[i] = a[i] == b; } return ruic(cou);} //h query template<class T> vector<T> imoh(vector<vector<T>> &v, int w) { vector<T> ret(sz(v)); rep(h, sz(ret)) { ret[h] = v[h][w]; } rep(i, sz(ret) - 1) { ret[i + 1] += ret[i]; } return ret;} template<class T> vector<T> ruih(vector<vector<T>> &v, int w) { vector<T> ret(sz(v) + 1); rep(h, sz(v)) { ret[h + 1] = v[h][w]; } rep(i, sz(v)) { ret[i + 1] += ret[i]; } return ret;} template<class T> ruiC<T> ruihc(vector<vector<T>> &a, int w) { vector<T> ret = ruih(a, w); return ruiC<T>(ret);} //xor template<class T> struct ruixC { vector<T> rui; ruixC(vector<T> &ru) : rui(ru) {} T operator()(ll l, ll r) { if (l > r) { cerr << "ruiXc "; deb(l, r); assert(0); } return rui[r] ^ rui[l]; } T operator[](ll i) { return rui[i]; } T back() { return rui.back(); } ll size() { return rui.size(); } }; template<class T> vector<T> ruix(vector<T> &a) { vector<T> ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] ^ a[i]; return ret;} template<class T> ruixC<ll> ruixc(vector<T> &a) { vi ret = ruix(a); return ruixC<ll>(ret);} //差分を返す(累積を取ると元に戻る) //101なら //1111を返す //元の配列で[l, r)へのxorは //[l]と[r]へのxorになる https://atcoder.jp/contests/abc155/tasks/abc155_f vi ruix_diff(vi &A) { int N = sz(A); assert(N); vi res(N + 1); res[0] = A[0]; rep(i, 1, N) { res[i] = A[i - 1] ^ A[i]; } res[N] = A[N - 1]; return res;} template<class T> vector<T> ruim(vector<T> &a) { vector<T> res(a.size() + 1, 1); rep(i, a.size())res[i + 1] = res[i] * a[i]; return res;} //漸化的に最小を1indexで持つ template<class T> vector<T> ruimi(vector<T> &a) {ll n = sz(a); vector<T> ret(n + 1); rep(i, 1, n) { ret[i] = a[i - 1]; chmi(ret[i + 1], ret[i]); } return ret;} //template<class T> T *rrui(vector<T> &a) { //右から左にかけての半開区間 (-1 n-1] template<class T> struct rruiC { vector<T> rui; int n; rruiC(vector<T> &a) : n(sz(a)) { rui.resize(n + 1); rer(i, n - 1) { rui[i] = rui[i + 1] + a[i]; } } /*[r l)*/ T operator()(int r, int l) { r++; l++; assert(l <= r && l >= 0 && r <= n); return rui[l] - rui[r]; } T operator()(int l) { return operator()(n - 1, l); } T operator[](int i) { return operator()(i); } }; template<class T> ostream &operator<<(ostream &os, rruiC<T> a) { fora(v, a.rui){os << v << " "; } return os;} template<class T> string deb_tos(rruiC<T> &a) {return deb_tos(a.rui);} #define rrui rruic template<class T> rruiC<T> rruic(vector<T> &a) { return rruiC<T>(a); } //掛け算 template<class T> struct ruimulC { vector<T> rv; int n; ruimulC(vector<T> &a) : rv(a), n(sz(a)) { rv.resize(n + 1); rv[0] = 1; rep(i, n) { rv[i + 1] = a[i] * rv[i]; } } ruimulC() : n(0) { rv.resize(n + 1); rv[0] = 1; } void operator+=(T v) { rv.push_back(rv.back() * v); n++; } T operator()(int l, int r) { assert(l <= r && 0 <= l && r <= n); return rv[r] / rv[l]; } T operator()(int r = inf) { return operator()(0, min(r, n)); } T operator[](int r) { return operator()(0, r); } auto begin() { return rv.begin(); } auto end() { return rv.end(); } }; template<class T> ruimulC<T> ruimul(vector<T> &a) { return ruimulC<T>(a); } template<class T> ruimulC<T> ruimul() { vector<T> a; return ruimulC<T>(a);} template<class T> T *rruim(vector<T> &a) { ll len = a.size(); T *body = (T *) malloc((len + 1) * sizeof(T)); T *res = body + 1; res[len - 1] = 1; rer(i, len - 1)res[i - 1] = res[i] * a[i]; return res;} template<class T, class U, class W> T lowerBound(ruiC <T> &a, U v, W banpei) { return lowerBound(a.rui, v, banpei); } template<class T, class U, class W> T upperBound(ruiC <T> &a, U v, W banpei) { return upperBound(a.rui, v, banpei); } template<class T, class U, class W> T rlowerBound(ruiC <T> &a, U v, W banpei) { return rlowerBound(a.rui, v, banpei); } template<class T, class U, class W> T rupperBound(ruiC <T> &a, U v, W banpei) { return rupperBound(a.rui, v, banpei); } #endif constexpr bool bget(ll m, ll keta) { #ifdef _DEBUG assert(keta <= 62);//オーバーフロー 1^62までしか扱えない #endif return (m >> keta) & 1; } //bget(n)次元 // NならN-1まで vector<vi> bget2(vi &a, int keta_size) { vvi(res, keta_size, sz(a)); rep(k, keta_size) { rep(i, sz(a)) { res[k][i] = bget(a[i], k); }} return res;} vi bget1(vi &a, int keta) { vi res(sz(a)); rep(i, sz(a)) { res[i] = bget(a[i], keta); } return res;} #if __cplusplus >= 201703L ll bget(ll m, ll keta, ll sinsuu) { m /= pow<ll>(sinsuu, keta); return m % sinsuu;} #else ll bget(ll m, ll keta, ll sinsuu) { m /= (ll)pow(sinsuu, keta); return m % sinsuu;} #endif constexpr ll bit(ll n) { #ifdef _DEBUG assert(n <= 62);//オーバーフロー 1^62までしか扱えない #endif return (1LL << (n)); } #if __cplusplus >= 201703L ll bit(ll n, ll sinsuu) { return pow<ll>(sinsuu, n); } #else ll bit(ll n, ll sinsuu) { return (ll)pow(sinsuu, n); } #endif ll mask(ll n) { return (1ll << n) - 1; } //aをbitに置きなおす //{0, 2} -> 101 ll bit(const vi &a) { int m = 0; for (auto &&v:a) m |= bit(v); return m;} //{1, 1, 0} -> 011 //bitsetに置き換える感覚 i が立っていたら i bit目を立てる ll bit_bool(vi &a) { int m = 0; rep(i, sz(a)) if (a[i])m |= bit(i); return m;} #define bcou __builtin_popcountll //最下位ビット ll lbit(ll n) { assert(n);return n & -n; } ll lbiti(ll n) { assert(n);return log2(n & -n); } //最上位ビット ll hbit(ll n) { assert(n);n |= (n >> 1); n |= (n >> 2); n |= (n >> 4); n |= (n >> 8); n |= (n >> 16); n |= (n >> 32); return n - (n >> 1);} ll hbiti(ll n) { assert(n);return log2(hbit(n)); } //ll hbitk(ll n) { ll k = 0; rer(i, 5) { ll a = k + (1ll << i); ll b = 1ll << a; if (b <= n)k += 1ll << i; } return k;} //初期化は0を渡す ll nextComb(ll &mask, ll n, ll r) { if (!mask)return mask = (1LL << r) - 1; ll x = mask & -mask; /*最下位の1*/ ll y = mask + x; /*連続した下の1を繰り上がらせる*/ ll res = ((mask & ~y) / x >> 1) | y; if (bget(res, n))return mask = 0; else return mask = res;} //n桁以下でビットがr個立っているもののvectorを返す vi bitCombList(ll n, ll r) { vi res; ll m = 0; while (nextComb(m, n, r)) { res.push_back(m); } return res;} /*over*/#define forbit1_2(i, mas) for (int forbitj = !mas ? 0 : lbit(mas), forbitm = mas, i = !mas ? 0 :log2(forbitj); forbitm; forbitm = forbitm ^ forbitj, forbitj = !forbitm ? 1 : lbit(forbitm), i = log2(forbitj)) /*over*/#define forbit1_3(i, N, mas) for (int forbitj = !mas ? 0 : lbit(mas), forbitm = mas, i = !mas ? 0 :log2(forbitj); forbitm && i < N; forbitm = forbitm ^ forbitj, forbitj = !forbitm ? 1 : lbit(forbitm), i = log2(forbitj)) //masの立ってるindexを見る // i, [N], mas #define forbit1(...) over3(__VA_ARGS__, forbit1_3, forbit1_2)(__VA_ARGS__) //masが立っていないindexを見る // i, N, mas #define forbit0(i, N, mas) forbit1(i, mask(N) & (~(mas))) //forsubをスニペットして使う //Mの部分集合(0,M含む)を見る 3^sz(S)個ある #define forsub_all(m, M) for (int m = M; m != -1; m = m == 0 ? -1 : (m - 1) & M) //BASE進数 template<size_t BASE> class base_num { int v; public: base_num(int v = 0) : v(v) {}; int operator[](int i) { return bget(v, i, BASE); } void operator++() { v++; } void operator++(signed) { v++; } operator int() { return v; } }; #define base3(mas, lim, BASE) for (base_num<BASE> mas; mas < lim; mas++) #define base2(mas, lim) base3(mas, lim, 2) #define base(...) over3(__VA_ARGS__,base3,base2,base1)(__VA_ARGS__) //aにある物をtrueとする vb bool_(vi a, int n) { vb ret(max(max(a) + 1, n)); rep(i, sz(a))ret[a[i]] = true; return ret;} char itoal(ll i) { return 'a' + i; } char itoaL(ll i) { return 'A' + i; } ll altoi(char c) { if ('A' <= c && c <= 'Z')return c - 'A'; return c - 'a';} ll ctoi(char c) { return c - '0'; } char itoc(ll i) { return i + '0'; } ll vtoi(vi &v) { ll res = 0; if (sz(v) > 18) { debugline("vtoi"); deb(sz(v)); ole(); } rep(i, sz(v)) { res *= 10; res += v[i]; } return res;} vi itov(ll i) { vi res; while (i) { res.push_back(i % 10); i /= 10; } res = rev(res); return res;} vi stov(string &a) { ll n = sz(a); vi ret(n); rep(i, n) { ret[i] = a[i] - '0'; } return ret;} //基準を満たさないものは0になる vi stov(string &a, char one) { ll n = sz(a); vi ret(n); rep(i, n)ret[i] = a[i] == one; return ret;} vector<vector<ll>> ctoi(vector<vector<char>> s, char c) { ll n = sz(s), m = sz(s[0]); vector<vector<ll>> res(n, vector<ll>(m)); rep(i, n)rep(j, m)res[i][j] = s[i][j] == c; return res;} //#define use_compress //[i] := vを返す //aは0~n-1で置き換えられる vi compress(vi &a) { vi b; ll len = a.size(); for (ll i = 0; i < len; ++i) { b.push_back(a[i]); } sort(b); unique(b); for (ll i = 0; i < len; ++i) { a[i] = lower_bound(all(b), a[i]) - b.begin(); } ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;} #ifdef use_compress //ind[i] := i番目に小さい数 //map[v] := vは何番目に小さいか vi compress(vi &a, umapi &map) { vi b; ll len = a.size(); for (ll i = 0; i < len; ++i) { b.push_back(a[i]); } sort(b); unique(b); for (ll i = 0; i < len; ++i) { ll v = a[i]; a[i] = lower_bound(all(b), a[i]) - b.begin(); map[v] = a[i]; } ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;} vi compress(vi &a, vi &r) { vi b; ll len = a.size(); fora(v, a){b.push_back(v);} fora(v, r){b.push_back(v);} sort(b); unique(b); for (ll i = 0; i < len; ++i) a[i] = lower_bound(all(b), a[i]) - b.begin(); for (ll i = 0; i < sz(r); ++i) r[i] = lower_bound(all(b), r[i]) - b.begin(); ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;} vi compress(vi &a, vi &r, vi &s) { vi b; ll len = a.size(); fora(v, a){b.push_back(v);} fora(v, r){b.push_back(v);} fora(v, s){b.push_back(v); } sort(b); unique(b); for (ll i = 0; i < len; ++i) a[i] = lower_bound(all(b), a[i]) - b.begin(); for (ll i = 0; i < sz(r); ++i) r[i] = lower_bound(all(b), r[i]) - b.begin(); for (ll i = 0; i < sz(s); ++i) r[i] = lower_bound(all(b), s[i]) - b.begin(); ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;} vi compress(vector<vi> &a) { vi b; fora(vv, a){fora(v, vv){b.push_back(v);}} sort(b); unique(b); fora(vv, a){fora(v, vv){v = lower_bound(all(b), v) - b.begin(); }} ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;} vi compress(vector<vector<vi >> &a) { vi b; fora(vvv, a){fora(vv, vvv){fora(v, vv){b.push_back(v);}}} sort(b); unique(b); fora(vvv, a){fora(vv, vvv){fora(v, vv){v = lower_bound(all(b), v) - b.begin();}}} ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;} void compress(ll a[], ll len) { vi b; for (ll i = 0; i < len; ++i) { b.push_back(a[i]); } sort(b); unique(b); for (ll i = 0; i < len; ++i) { a[i] = lower_bound(all(b), a[i]) - b.begin(); }} #endif //要素が見つからなかったときに困る #define binarySearch(a, v) (binary_search(all(a),v)) #define lowerIndex(a, v) (lower_bound(all(a),v)-a.begin()) #define upperIndex(a, v) (upper_bound(all(a),v)-a.begin()) #define rlowerIndex(a, v) (upper_bound(all(a),v)-a.begin()-1) #define rupperIndex(a, v) (lower_bound(all(a),v)-a.begin()-1) template<class T, class U, class W> T lowerBound(vector<T> &a, U v, W banpei) { auto it = lower_bound(a.begin(), a.end(), v); if (it == a.end())return banpei; else return *it;} template<class T, class U, class W> T upperBound(vector<T> &a, U v, W banpei) { auto it = upper_bound(a.begin(), a.end(), v); if (it == a.end())return banpei; else return *it;} template<class T, class U, class W> T rlowerBound(vector<T> &a, U v, W banpei) { auto it = upper_bound(a.begin(), a.end(), v); if (it == a.begin())return banpei; else { return *(--it); }} template<class T, class U, class W> T rupperBound(vector<T> &a, U v, W banpei) { auto it = lower_bound(a.begin(), a.end(), v); if (it == a.begin())return banpei; else { return *(--it); }} //todo 消せないか template<class T, class U, class W> T lowerBound(set<T> &a, U v, W banpei) { auto it = a.lower_bound(v); if (it == a.end())return banpei; else return *it;} template<class T, class U, class W> T upperBound(set<T> &a, U v, W banpei) { auto it = a.upper_bound(v); if (it == a.end())return banpei; else return *it;} template<class T, class U, class W> T rlowerBound(set<T> &a, U v, W banpei) { auto it = a.upper_bound(v); if (it == a.begin())return banpei; else { return *(--it); }} template<class T, class U, class W> T rupperBound(set<T> &a, U v, W banpei) {auto it = a.lower_bound(v);if (it == a.begin())return banpei; else { return *(--it); }} template<class T, class U, class W> T lowerBound(mset<T> &a, U v, W banpei) { auto it = a.lower_bound(v); if (it == a.end())return banpei; else return *it;} template<class T, class U, class W> T upperBound(mset<T> &a, U v, W banpei) { auto it = a.upper_bound(v); if (it == a.end())return banpei; else return *it;} template<class T, class U, class W> T rlowerBound(mset<T> &a, U v, W banpei) { auto it = a.upper_bound(v); if (it == a.begin())return banpei; else { return *(--it); }} template<class T, class U, class W> T rupperBound(mset<T> &a, U v, W banpei) {auto it = a.lower_bound(v);if (it == a.begin())return banpei; else { return *(--it); }} #define next2(a) next(next(a)) #define prev2(a) prev(prev(a)) //狭義の単調増加列 長さを返す template<class T> int lis(vector<T> &a) { int n = sz(a); vi tail(n + 1, MAX<T>()); rep(i, n) { int id = lowerIndex(tail, a[i]);/**/ tail[id] = a[i]; } return lowerIndex(tail, MAX<T>());} template<class T> int lis_eq(vector<T> &a) { int n = sz(a); vi tail(n + 1, MAX<T>()); rep(i, n) { int id = upperIndex(tail, a[i]);/**/ tail[id] = a[i]; } return lowerIndex(tail, MAX<T>());} //iteratorを返す //valueが1以上の物を返す 0は見つけ次第削除 //vを減らす場合 (*it).se--でいい template<class T, class U, class V> auto lower_map(map<T, U> &m, V k) { auto ret = m.lower_bound(k); while (ret != m.end() && (*ret).second == 0) { ret = m.erase(ret); } return ret;} template<class T, class U, class V> auto upper_map(map<T, U> &m, V k) { auto ret = m.upper_bound(k); while (ret != m.end() && (*ret).second == 0) { ret = m.erase(ret); } return ret;} //存在しなければエラー template<class T, class U, class V> auto rlower_map(map<T, U> &m, V k) { auto ret = upper_map(m, k); assert(ret != m.begin()); ret--; while (1) { if ((*ret).second != 0)break; assert(ret != m.begin()); auto next = ret; --next; m.erase(ret); ret = next; } return ret;} template<class T, class U, class V> auto rupper_map(map<T, U> &m, V k) { auto ret = lower_map(m, k); assert(ret != m.begin()); ret--; while (1) { if ((*ret).second != 0)break; assert(ret != m.begin()); auto next = ret; --next; m.erase(ret); ret = next; } return ret;} template<class... T> void fin(T... s) {out(s...); exit(0); } //便利 数学 math //sub ⊂ top bool subset(int sub, int top) {return (sub & top) == sub;} //-180 ~ 180 degree double atand(double h, double w) {return atan2(h, w) / PI * 180;} //% -mの場合、最小の正の数を返す ll mod(ll a, ll m) {if (m < 0) m *= -1;return (a % m + m) % m;} //ll pow(ll a) { return a * a; }; template<class T> T fact(int v) { static vector<T> fact(2, 1); if (sz(fact) <= v) { rep(i, sz(fact), v + 1) { fact.emplace_back(fact.back() * i); }} return fact[v];} ll comi(ll n, ll r) { assert(n < 100); static vvi(pas, 100, 100); if (pas[0][0])return pas[n][r]; pas[0][0] = 1; rep(i, 1, 100) { pas[i][0] = 1; rep(j, 1, i + 1)pas[i][j] = pas[i - 1][j - 1] + pas[i - 1][j]; } return pas[n][r];} //二項係数の偶奇を返す int com_mod2(int n,int r){return n == ( r | (n - r) );} double comd2(ll n, ll r) { static vvd(comb, 2020, 2020); if (comb[0][0] == 0) { comb[0][0] = 1; rep(i, 2000) { comb[i + 1][0] = 1; rep(j, 1, i + 2) { comb[i + 1][j] = comb[i][j] + comb[i][j - 1]; } } } return comb[n][r];} double comd(int n, int r) { if (r < 0 || r > n) return 0; if (n < 2020)return comd2(n, r); static vd fact(2, 1); if (sz(fact) <= n) { rep(i, sz(fact), n + 1) { fact.push_back(fact.back() * i); }} return fact[n] / fact[n - r] / fact[r];} #define gcd my_gcd ll gcd(ll a, ll b) {while (b) a %= b, swap(a, b);return abs(a);} ll gcd(vi b) {ll res = b[0];rep(i, 1, sz(b))res = gcd(b[i], res);return res;} #define lcm my_lcm ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll lcm(vi a) {ll res = a[0];rep(i, 1, sz(a))res = lcm(a[i], res);return res;} ll ceil(ll a, ll b) {if (b == 0) {debugline("ceil");deb(a, b);ole();return -1;} else if (a < 0) { return 0; } else { return (a + b - 1) / b; }} #define hypot my_hypot double hypot(double dx, double dy){return std::sqrt(dx*dx+ dy*dy);} ll sig0(int t) { return t <= 0 ? 0 : ((1 + t) * t) >> 1; } bint sig0(bint t) {return t <= 0 ? 0 : ((1 + t) * t) >> 1; } //ll sig(ll s, ll t) { return ((s + t) * (t - s + 1)) >> 1; } ll sig(ll s, ll t) {if (s > t)swap(s, t);return sig0(t - s) + s * (t - s + 1);} #define tousa_i tosa_i #define lower_tousa_i lower_tosa_i #define upper_tousa upper_tosa #define upper_tousa_i upper_tosa_i ll tosa_i(ll st, ll ad, ll v) { assert(((v - st) % ad) == 0); return (v - st) / ad;} ll tosa_s(ll st, ll ad, ll len) { return st * len + sig0(len - 1) * ad;} // ax + r (x は非負整数) で表せる整数のうち、v 以上となる最小の整数 ll lower_tosa(ll st, ll ad, ll v) { if (st >= v) return st; return (v - st + ad - 1) / ad * ad + st;} //第何項か ll lower_tosa_i(ll st, ll ad, ll v) { if (st >= v) return 0; return (v - st + ad - 1) / ad;} ll upper_tosa(ll st, ll ad, ll v) { return lower_tosa(st, ad, v + 1); } ll upper_tosa_i(ll st, ll ad, ll v) { return lower_tosa_i(st, ad, v + 1); } //b * res <= aを満たす [l, r)を返す div P drange_ika(int a, int b) { P null_p = mp(linf, linf); if (b == 0) { if (a >= 0) { return mp(-linf, linf + 1)/*全て*/; } else { return null_p/*無い*/; } } else { if (a >= 0) { if (b > 0) { return mp(-linf, a / b + 1); } else { return mp(-(a / -b), linf + 1); } } else { if (b > 0) { return mp(-linf, -ceil(-a, b) + 1); } else { return mp(ceil(-a, -b), linf + 1); } } }} //v * v >= aとなる最小のvを返す ll sqrt(ll a) { if (a < 0) { debugline("sqrt"); deb(a); ole(); } ll res = (ll) std::sqrt(a); while (res * res < a)++res; return res;} double log(double e, double x) { return log(x) / log(e); } /*@formatter:off*/ //機能拡張 #define dtie(a, b) int a, b; tie(a, b) template<class T, class U> string to_string(T a, U b) { string res = ""; res += a; res += b; return res;} template<class T, class U, class V> string to_string(T a, U b, V c) { string res = ""; res += a; res += b; res += c; return res;} template<class T, class U, class V, class W> string to_string(T a, U b, V c, W d) { string res = ""; res += a; res += b; res += c; res += d; return res;} template<class T, class U, class V, class W, class X> string to_string(T a, U b, V c, W d, X e) { string res = ""; res += a; res += b; res += c; res += d; res += e; return res;} template<class T> vector<T> sub(const vector<T> &A, int l, int r) { assert(0 <= l && l <= r && r <= sz(A)); vector<T> ret(r - l); std::copy(A.begin() + l, A.begin() + r, ret.begin()); return ret;} template<class T> vector<T> sub(const vector<T> &A, int r) { return sub(A, 0, r); } template<class T> vector<T> subn(const vector<T> &A, int l, int len) { return sub(A, l, l + len); } string sub(string &A, int l, int r) { assert(0 <= l && l <= r && r <= sz(A)); return A.substr(l, r - l);} template<class T, class F> //sub2で呼ぶ vector<T> sub(const vector<vector<T> >& A, int h, int w, int ah,int aw, F f){ vector<T> res; while(0<= h && h < sz(A) && 0 <= w && w < sz(A[h]) && f(A[h][w])){ res.emplace_back(A[h][w]); h += ah; w += aw; } return res;} template<class T> vector<T>sub(const vector<vector<T> >& A, int h, int w, int ah,int aw){return sub(A, h, w, ah, aw, [&](T v){return true;});} #define sub25(A, h, w, ah, aw) sub(A, h, w, ah, aw) #define sub26(A, h, w, ah, aw, siki_r) sub(A, h, w, ah, aw, [&](auto v){return v siki_r;}) #define sub27(A, h, w, ah, aw, v, siki) sub(A, h, w, ah, aw, [&](auto v){return siki;}) #define sub2(...) over7(__VA_ARGS__,sub27,sub26,sub25)(__VA_ARGS__) constexpr int bsetlen = k5 * 2; //constexpr int bsetlen = 5050; #define bset bitset<bsetlen> bool operator<(bitset<bsetlen> &a, bitset<bsetlen> &b) {rer(i, bsetlen - 1) {if (a[i] < b[i])return true;if (a[i] > b[i])return false;}return false;} bool operator>(bitset<bsetlen> &a, bitset<bsetlen> &b) {rer(i, bsetlen - 1) {if (a[i] > b[i])return true;if (a[i] < b[i])return false;}return false;} bool operator<=(bitset<bsetlen> &a, bitset<bsetlen> &b) {rer(i, bsetlen - 1) {if (a[i] < b[i])return true;if (a[i] > b[i])return false;}return true;} bool operator>=(bitset<bsetlen> &a, bitset<bsetlen> &b) {rer(i, bsetlen - 1) {if (a[i] > b[i])return true;if (a[i] < b[i])return false;}return true;} string operator~(string &a) {string res = a;for (auto &&c:res) {if (c == '0')c = '1';else if (c == '1')c = '0';else {cerr << "cant ~" << a << "must bit" << endl;exit(0);}}return res;} ostream &operator<<(ostream &os, bset& a) { bitset<10> b; vi list; rep(i,bsetlen){ if(a[i])list.push_back(i),b[i]=1; } os<<b<<", "<<list; return os;} int hbiti(bset&a){rer(i,bsetlen){if(a[i])return i;}return -1;} #define hk(a, b, c) (a <= b && b < c) //O(N/64) bset nap(bset &a, int v) {bset r = a | a << v;return r;} bset nap(bset &a, bset &v) {bset r = a;rep(i, bsetlen) {if (v[i])r |= a << i;}return r;} template<class T> int count(set<T> &S, T l, T r) { assert(l < r); auto it = S.lower_bound(l); return it != S.end() && (*it) < r;} //template<class T> void seth(vector<vector<T>> &S, int w, vector<T> &v) {assert(sz(S) == sz(v));assert(w < sz(S[0]));rep(h, sz(S)) { S[h][w] = v[h]; }} template<class T> vector<T> geth(vector<vector<T>> &S, int w) { assert(w < sz(S[0])); vector<T> ret(sz(S)); rep(h, sz(S)) { ret[h] = S[h][w]; } return ret;} //vector<bool>[i]は参照を返さないため、こうしないとvb[i] |= trueがコンパイルエラー vb::reference operator|=(vb::reference a, bool b){return a = a | b;} template<class T, class U> void operator+=(pair<T,U> &a, pair<T,U> & b) {a.fi+=b.fi;a.se+=b.se;} template<class T, class U> pair<T,U> operator+(pair<T,U> &a, pair<T,U> & b) {return pair<T,U>(a.fi+b.fi,a.se+b.se);} template<typename CharT, typename Traits, typename Alloc> basic_string<CharT, Traits, Alloc> operator+(const basic_string<CharT, Traits, Alloc> &lhs, const int rv) { #ifdef _DEBUG static bool was = false;if (!was)message += "str += 65 is 'A' not \"65\" ";was = true; #endif return lhs + (char) rv; } template<typename CharT, typename Traits, typename Alloc> void operator+=(basic_string<CharT, Traits, Alloc> &lhs, const int rv) { lhs = lhs + rv;} template<typename CharT, typename Traits, typename Alloc> basic_string<CharT, Traits, Alloc> operator+(const basic_string<CharT, Traits, Alloc> &lhs, const signed rv) { const int rv2 = rv; return lhs + rv2;} template<typename CharT, typename Traits, typename Alloc> void operator+=(basic_string<CharT, Traits, Alloc> &lhs, const signed rv) {const int v = rv; lhs += v; } template<typename CharT, typename Traits, typename Alloc> void operator*=(basic_string<CharT, Traits, Alloc> &s, int num) { auto bek = s; s = ""; for (; num; num >>= 1) { if (num & 1) { s += bek; } bek += bek; }} template<class T, class U> void operator+=(queue<T> &a, U v) { a.push(v); }template<class T, class U> void operator+=(deque<T> &a, U v) { a.push_back(v); }template<class T> priority_queue<T, vector<T>, greater<T> > &operator+=(priority_queue<T, vector<T>, greater<T> > &a, vector<T> &v) { fora(d, v){a.push(d);} return a;}template<class T, class U> priority_queue<T, vector<T>, greater<T> > &operator+=(priority_queue<T, vector<T>, greater<T> > &a, U v) { a.push(v); return a;}template<class T, class U> priority_queue<T> &operator+=(priority_queue<T> &a, U v) { a.push(v); return a;}template<class T> set<T> &operator+=(set<T> &a, vector<T> v) { fora(d, v){a.insert(d);} return a;}template<class T, class U> auto operator+=(set<T> &a, U v) { return a.insert(v); }template<class T, class U> auto operator-=(set<T> &a, U v) { return a.erase(v); }template<class T, class U> auto operator+=(mset<T> &a, U v) { return a.insert(v); }template<class T, class U> set<T, greater<T>> &operator+=(set<T, greater<T>> &a, U v) { a.insert(v); return a;}template<class T, class U> vector<T> &operator+=(vector<T> &a, U v) { a.push_back(v); return a;}template<class T, class U> vector<T> operator+(U v,const vector<T> &a) { vector<T> ret = a; ret.insert(ret.begin(), v); return ret;}template<class T> vector<T> operator+(const vector<T>& a, const vector<T>& b) { vector<T> ret; ret = a; fora(v, b){ret += v; } return ret;}template<class T> vector<T> &operator+=(vector<T> &a,const vector<T> &b) { rep(i, sz(b)) {/*こうしないとa+=aで両辺が増え続けてバグる*/ a.push_back(b[i]); } return a;}template<class T, class U> map<T, U> &operator+=(map<T, U> &a, map<T, U> &b) { for(auto&& bv : b) { a[bv.first] += bv.second; } return a;}template<class T, class U> vector<T> operator+(const vector<T> &a, const U& v) { vector<T> ret = a; ret += v; return ret;}template<class T, class U> auto operator+=(uset<T> &a, U v) { return a.insert(v); } template<class T> vector<T> operator%(vector<T>& a, int v){ vi ret(sz(a)); rep(i,sz(a)){ ret[i] = a[i] % v; } return ret;} template<class T> vector<T> operator%=(vector<T>& a, int v){ rep(i,sz(a)){ a[i] %= v; } return a;} vi operator&(vi& a, vi& b){ assert(sz(a)==sz(b)); vi ret(sz(a)); rep(i,sz(a)){ ret[i] = min(a[i],b[i]); } return ret;} template<class T> void operator+=(mset<T> &a, vector<T>& v) { for(auto&& u : v)a.insert(u); } template<class T> void operator+=(set<T> &a, vector<T>& v) { for(auto&& u : v)a.insert(u); } template<class T> void operator+=(vector<T> &a, set<T>& v) { for(auto&& u : v)a.emplace_back(u); } template<class T> void operator+=(vector<T> &a, mset<T>& v) { for(auto&& u : v)a.emplace_back(u); } template<class T> vector<T> &operator-=(vector<T> &a, vector <T> &b) { if (sz(a) != sz(b)) { debugline("vector<T> operator-="); deb(a); deb(b); exit(0); } rep(i, sz(a))a[i] -= b[i]; return a;} template<class T> vector<T> operator-(vector<T> &a, vector<T> &b) { if (sz(a) != sz(b)) { debugline("vector<T> operator-"); deb(a); deb(b); ole(); } vector<T> res(sz(a)); rep(i, sz(a))res[i] = a[i] - b[i]; return res;} //template<class T, class U> void operator*=(vector<T> &a, U b) { vector<T> ta = a; rep(b-1){ a+=ta; }} template<typename T> void erase(vector<T> &v, unsigned ll i) { v.erase(v.begin() + i); } template<typename T> void erase(vector<T> &v, unsigned ll s, unsigned ll e) { v.erase(v.begin() + s, v.begin() + e); } template<typename T> void pop_front(vector<T> &v) { erase(v, 0); } template<typename T> void entry(vector<T> &v, unsigned ll s, unsigned ll e) { erase(v, e, sz(v));erase(v,0,s);} template<class T, class U> void erase(map<T, U> &m, ll okl, ll ngr) { m.erase(m.lower_bound(okl), m.lower_bound(ngr)); } template<class T> void erase(set<T> &m, ll okl, ll ngr) { m.erase(m.lower_bound(okl), m.lower_bound(ngr)); } template<typename T> void erasen(vector<T> &v, unsigned ll s, unsigned ll n) { v.erase(v.begin() + s, v.begin() + s + n); } template<typename T, typename U> void insert(vector<T> &v, unsigned ll i, U t) { v.insert(v.begin() + i, t); } template<typename T, typename U> void push_front(vector<T> &v, U t) { v.insert(v.begin(), t); } template<typename T, typename U> void insert(vector<T> &v, unsigned ll i, vector<T> list) { for (auto &&va:list)v.insert(v.begin() + i++, va); } vector<string> split(const string a, const char deli) { string b = a + deli; ll l = 0, r = 0, n = b.size(); vector<string> res; rep(i, n) { if (b[i] == deli) { r = i; if (l < r)res.push_back(b.substr(l, r - l)); l = i + 1; } } return res;} vector<string> split(const string a, const string deli) { vector<string> res; ll kn = sz(deli); std::string::size_type Pos(a.find(deli)); ll l = 0; while (Pos != std::string::npos) { if (Pos - l)res.push_back(a.substr(l, Pos - l)); l = Pos + kn; Pos = a.find(deli, Pos + kn); } if (sz(a) - l)res.push_back(a.substr(l, sz(a) - l)); return res;} ll stoi(string& s){return stol(s);} #define assert_yn(yn_v, v); assert(yn_v == 0 || yn_v == v);yn_v = v; //不完全な対策、現状はautohotkeyで対応 int yn_v = 0; void yn(bool a) { assert_yn(yn_v, 1);if (a)cout << "yes" << endl; else cout << "no" << endl; } void fyn(bool a) { assert_yn(yn_v, 1);yn(a); exit(0);} void Yn(bool a) { assert_yn(yn_v, 2);if (a)cout << "Yes" << endl; else cout << "No" << endl; } void fYn(bool a) { assert_yn(yn_v, 2);Yn(a); exit(0);} void YN(bool a) { assert_yn(yn_v, 3);if (a)cout << "YES" << endl; else cout << "NO" << endl; } void fYN(bool a) { assert_yn(yn_v, 3);YN(a); exit(0);} int ab_v = 0; void fAb(bool a) { assert_yn(ab_v, 1);if(a)cout<<"Alice"<<endl;else cout<<"Bob";} void fAB(bool a) { assert_yn(yn_v, 2);if(a)cout<<"ALICE"<<endl;else cout<<"BOB";} int pos_v = 0; void Possible(bool a) { assert_yn(pos_v, 1);if (a)cout << "Possible" << endl; else cout << "Impossible" << endl; exit(0);} void POSSIBLE(bool a) { assert_yn(pos_v, 2);if (a)cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; exit(0);} void fPossible(bool a) { assert_yn(pos_v, 1)Possible(a);exit(0);} void fPOSSIBLE(bool a) { assert_yn(pos_v, 2)POSSIBLE(a);exit(0);} template<typename T> class fixed_point : T {public: explicit constexpr fixed_point(T &&t) noexcept: T(std::forward<T>(t)) {} template<typename... Args> constexpr decltype(auto) operator()(Args &&... args) const { return T::operator()(*this, std::forward<Args>(args)...); }};template<typename T> static inline constexpr decltype(auto) fix(T &&t) noexcept { return fixed_point<T>{std::forward<T>(t)}; } //未分類 //0,2,1 1番目と2番目の次元を入れ替える template<class T> auto irekae(vector<vector<vector<T> > > &A, int x, int y, int z) { #define irekae_resize_loop(a, b, c) resize(res,a,b,c);rep(i,a)rep(j,b)rep(k,c) vector<vector<vector<T> > > res; if (x == 0 && y == 1 && z == 2) { res = A; } else if (x == 0 && y == 2 && z == 1) { irekae_resize_loop(sz(A), sz(A[0][0]), sz(A[0])) { res[i][j][k] = A[i][k][j]; } } else if (x == 1 && y == 0 && z == 2) { irekae_resize_loop(sz(A[0]), sz(A), sz(A[0][0])) { res[i][j][k] = A[j][i][k]; } } else if (x == 1 && y == 2 && z == 0) { irekae_resize_loop(sz(A[0]), sz(A[0][0]), sz(A)) { res[i][j][k] = A[k][i][j]; } } else if (x == 2 && y == 0 && z == 1) { irekae_resize_loop(sz(A[0][0]), sz(A), sz(A[0])) { res[i][j][k] = A[j][k][i]; } } else if (x == 2 && y == 1 && z == 0) { irekae_resize_loop(sz(A[0][0]), sz(A[0]), sz(A)) { res[i][j][k] = A[k][j][i]; } } return res; #undef irekae_resize_loop } template<class T> auto irekae(vector<vector<T>>&A,int i=1,int j=0){ vvt(res,sz(A[0]),sz(A)); rep(i,sz(A)){ rep(j,sz(A[0])){ res[j][i]=A[i][j]; } } return res;} //tou分割する template<typename Iterable> vector<Iterable> cut(const Iterable &a, int tou = 2) {int N = sz(a); vector<Iterable> res(tou); int hab = N / tou; vi lens(tou, hab); rep(i, N % tou) { lens[tou - 1 - i]++; } int l = 0; rep(i, tou) { int len = lens[i]; int r = l + len; res[i].resize(len); std::copy(a.begin() + l, a.begin() + r, res[i].begin()); l = r; } return res;} //長さn毎に分割する template<typename Iterable> vector<Iterable> cutn(const Iterable &a, int len) { int N = sz(a); vector<Iterable> res(ceil(N, len)); vi lens(N / len, len); if (N % len)lens.push_back(N % len); int l = 0; rep(i, sz(lens)) { int len = lens[i]; int r = l + len; res[i].resize(len); std::copy(a.begin() + l, a.begin() + r, res[i].begin()); l = r; } return res;} //縦を返す vi& geth(vvi()& a, int w){ static vi ret; ret.resize(sz(a)); rep(i,sz(a)){ ret[i] = a[i][w]; } return ret;} //@起動時 struct initon { initon() { cin.tie(0); ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(16); srand((unsigned) clock() + (unsigned) time(NULL)); }; } initonv; //#define pre prev //#define nex next //gra mll pr //上下左右 const string udlr = "udlr"; string UDLR = "UDLR";//x4と連動 UDLR.find('U') := x4[0] vc atoz = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x','y', 'z'}; vc AtoZ = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X','Y', 'Z'}; //右、上が正 constexpr ll h4[] = {1, -1, 0, 0}; constexpr ll w4[] = {0, 0, -1, 1}; constexpr ll h8[] = {0, 1, 0, -1, -1, 1, 1, -1}; constexpr ll w8[] = {1, 0, -1, 0, 1, -1, 1, -1}; int mei_inc(int h, int w, int H, int W, int i) {while (++i < 4) { if (inside(h + h4[i], w + w4[i], H, W))return i; }return i;} #define mei(nh, nw, h, w) for (int i = mei_inc(h, w, H, W, -1), nh = i<4? h + h4[i] : 0, nw = i<4? w + w4[i] : 0; i < 4; i=mei_inc(h,w,H,W,i), nh = h+h4[i], nw = w+w4[i]) int mei_inc8(int h, int w, int H, int W, int i) { while (++i < 8) { if (inside(h + h8[i], w + w8[i], H, W))return i; } return i;} #define mei8(nh, nw, h, w) for (int i = mei_inc8(h, w, H, W, -1), nh = i<8? h + h8[i] : 0, nw = i<8? w + w8[i] : 0; i < 8; i=mei_inc8(h,w,H,W,i), nh = h+h8[i], nw = w+w8[i]) int mei_incv(int h, int w, int H, int W, int i, vp &p) { while (++i < sz(p)) { if (inside(h + p[i].fi, w + p[i].se, H, W))return i; } return i;} #define meiv(nh, nw, h, w, p) for (int i = mei_incv(h, w, H, W, -1, p), nh = i<sz(p)? h + p[i].fi : 0, nw = i<sz(p)? w + p[i].se : 0; i < sz(p); i=mei_incv(h,w,H,W,i,p), nh = h+p[i].fi, nw = w+p[i].se) //H*Wのグリッドを斜めに分割する //右上 vector<vp> naname_list_ne(int H, int W) { vector<vp> res(H + W - 1); rep(sh, H) { int sw = 0; res[sh] += mp(sh, sw); int nh = sh; int nw = sw; while (1) { nh--; nw++; if (0 <= nh && nw < W) { res[sh] += mp(nh, nw); }else{ break; } } } rep(sw, 1, W) { int sh = H - 1; res[H + sw - 1] += mp(sh, sw); int nh = sh; int nw = sw; while (1) { nh--; nw++; if (0 <= nh && nw < W) { res[H + sw-1] += mp(nh, nw); }else{ break; } } } return res;} //右下 vector<vp> naname_list_se(int H, int W) { vector<vp> res(H + W - 1); rep(sh, H) { int sw = 0; res[sh] += mp(sh, sw); int nh = sh; int nw = sw; while (1) { nh++; nw++; if (0 <= nh && nh< H && nw < W) { res[sh] += mp(nh, nw); } else { break; } } } rep(sw, 1, W) { int sh = 0; res[H + sw - 1] += mp(sh, sw); int nh = sh; int nw = sw; while (1) { nh++; nw++; if (0 <= nh && nh < H && nw < W) { res[H + sw - 1] += mp(nh, nw); } else { break; } } } return res;} //グラフ内で #undef getid //#define getidとしているため、ここを書き直したらgraphも書き直す #define getid_2(h, w) ((h) * (W) + (w)) #define getid_1(p) ((p).first * W + (p).second) #define getid(...) over2(__VA_ARGS__, getid_2, getid_1) (__VA_ARGS__) #define getp(id) mp(id / W, id % W) //#define set_shuffle() std::random_device seed_gen;std::mt19937 engine(seed_gen()) //#define shuffle(a) std::shuffle((a).begin(), (a).end(), engine); //1980 開始からtime ms経っていたらtrue vb bit_bool(int v, int len) { assert(bit(len) > v); vb ret(len); rep(i, len) { ret[i] = bget(v, i); } return ret;} vi range(int l, int r) {vi ret;ret.resize(r - l);rep(v, l, r) {ret[v - l] = v;}return ret;} vi range(int r) {return range(0, r);} vi tov(vb& a){ vi ret; rep(i,sz(a)){ if(a[i])ret.push_back(i); } return ret;} bool kaibun(const str& S){return S==rev(S);} template<class T> vector<T> repeat(const vector<T> &A, int kaisu) { vector<T> ret; while (kaisu--) { ret += A; } return ret;} #define rge range #define upd update //S[{s, t, d}] #define strs slice_str struct slice_str { string S; slice_str() {} slice_str(const string &S) : S(S) {} slice_str(int len, char c) : S(len, c) {} auto size(){return S.size();} char& operator[](int p) { return S[p]; } string operator[](initializer_list<int> p) { if (sz(p) == 1) { return S.substr(0, *(p.begin())); } else if (sz(p) == 2) { int l = *(p.begin()); int r = *(next(p.begin())); return S.substr(l, r - l); } else { auto it = p.begin(); int s = *(it++); int t = *(it++); int d = *(it); if (d == -1) { int s_ = sz(S) - s - 1; int t_ = sz(S) - t - 1; return rev(S).substr(s_, t_ - s_); } else if (d < 0) { t = max(-1ll, t); string ret; while (s > t) { ret += S[s]; s += d; } return ret; } else { t = min(sz(S), t); string ret; while (s < t) { ret += S[s]; s += d; } return ret; } } } operator string &() { return S; } template<class T> void operator+=(const T &a) { S += a; } }; ostream &operator<<(ostream &os, const slice_str &a) { os << a.S; return os;} istream &operator>>(istream &iss, const slice_str &a) { iss >> a.S; return iss;} template<class T> bool can(const T &v, int i) { return 0 <= i && i < sz(v); } #if __cplusplus >= 201703L //template<class T> auto sum(int a, T v...) {return (v + ... + 0);} #endif #define VEC vector #endif /*UNTITLED15_TEMPLATE_H*/
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start': (.text+0x17): undefined reference to `main' collect2: error: ld returned 1 exit status
s290008271
p04025
C++
int main() { int N; cin >> N; int sum = 0; vector<int> A(N); rep(i, N) { cin >> A[i]; sum += A[i]; } int mean = sum / N; int can1, can2, can3, can4; can1 = mean + 1; can2 = mean + 2; can3 = mean - 1; can4 = mean - 2; int res, res1, res2, res3, res4; res = 0, res1 = 0, res2 = 0, res3 = 0, res4 = 0; rep(i, N) { res += pow((A[i] - mean), 2); } rep(i, N) { res1 += pow((A[i] - can1), 2); } rep(i, N) { res2 += pow((A[i] - can2), 2); } rep(i, N) { res3 += pow((A[i] - can3), 2); } rep(i, N) { res4 += pow((A[i] - can4), 2); } res = min(res, min(res1, min(res2, min(res3, res4)))); cout << res << endl; }
a.cc: In function 'int main()': a.cc:3:5: error: 'cin' was not declared in this scope 3 | cin >> N; | ^~~ a.cc:5:5: error: 'vector' was not declared in this scope 5 | vector<int> A(N); | ^~~~~~ a.cc:5:12: error: expected primary-expression before 'int' 5 | vector<int> A(N); | ^~~ a.cc:6:9: error: 'i' was not declared in this scope 6 | rep(i, N) { | ^ a.cc:6:5: error: 'rep' was not declared in this scope 6 | rep(i, N) { | ^~~ a.cc:29:40: error: 'min' was not declared in this scope; did you mean 'main'? 29 | res = min(res, min(res1, min(res2, min(res3, res4)))); | ^~~ | main a.cc:29:30: error: 'min' was not declared in this scope; did you mean 'main'? 29 | res = min(res, min(res1, min(res2, min(res3, res4)))); | ^~~ | main a.cc:29:20: error: 'min' was not declared in this scope; did you mean 'main'? 29 | res = min(res, min(res1, min(res2, min(res3, res4)))); | ^~~ | main a.cc:29:11: error: 'min' was not declared in this scope; did you mean 'main'? 29 | res = min(res, min(res1, min(res2, min(res3, res4)))); | ^~~ | main a.cc:30:5: error: 'cout' was not declared in this scope 30 | cout << res << endl; | ^~~~ a.cc:30:20: error: 'endl' was not declared in this scope 30 | cout << res << endl; | ^~~~
s400916372
p04025
C++
#include <bits/stdc++.h> #include <math.h> #define rep(i, n) for(int i = 0; i < n; ++i) using namespace std; int main() { int n, m = 1000000000; cin >> n; vector<int> v(n); rep(i, n) cin >> v[i]; sort(v.begin(), v.end()); rep(i, n){ int tmp = 0 rep(j, n) tmp += (v[i]-v[j])*(v[i]-v[j]); m = min(m, tmp); } cout << m << endl; return 0; }
a.cc: In function 'int main()': a.cc:3:19: error: expected ',' or ';' before 'for' 3 | #define rep(i, n) for(int i = 0; i < n; ++i) | ^~~ a.cc:14:5: note: in expansion of macro 'rep' 14 | rep(j, n) tmp += (v[i]-v[j])*(v[i]-v[j]); | ^~~ a.cc:14:9: error: 'j' was not declared in this scope 14 | rep(j, n) tmp += (v[i]-v[j])*(v[i]-v[j]); | ^ a.cc:3:34: note: in definition of macro 'rep' 3 | #define rep(i, n) for(int i = 0; i < n; ++i) | ^
s310091226
p04025
C++
#include<bits/stdc++.h> using namespace std; int A[MAXN]; int N; int sub; int ans; int main(){ cin>>N; for (int i=1;i<=N;++i)cin>>A[i]; ans = 1000000000; for (int x=-100;x<=100;++x){ sub=0; for (int i=1;i<=N;++i)sub += (A[i] - x)*(A[i]-x); ans = min(ans,sub); } cout<<ans; }
a.cc:3:7: error: 'MAXN' was not declared in this scope 3 | int A[MAXN]; | ^~~~ a.cc: In function 'int main()': a.cc:10:36: error: 'A' was not declared in this scope 10 | for (int i=1;i<=N;++i)cin>>A[i]; | ^ a.cc:14:39: error: 'A' was not declared in this scope 14 | for (int i=1;i<=N;++i)sub += (A[i] - x)*(A[i]-x); | ^
s063527820
p04025
Java
import java.io.*; import java.util.*; public class BeTogether { public static void main(String[] args) { FastReader sc=new FastReader(); int N=sc.nextInt(); int[] a=new int[N]; double sum=0; for(int i=0;i<N;i++){ a[i]=sc.nextInt(); sum+=a[i]; } int avg=(int)Math.round(sum/N); int mini=0; for(int i=0;i<N;i++){ mini+=Math.pow(a[i]-avg,2); } System.out.print(mini); } } class FastReader{ BufferedReader br ; StringTokenizer st; public FastReader(){ InputStreamReader inr =new InputStreamReader(System.in); br=new BufferedReader(inr); } String next(){ while(st==null || !st.hasMoreElements()){ try{ st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); }} return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } double nextDouble(){ return Double.parseDouble(next()); } long nextLong(){ return Long.parseLong(next()); } String nextLine(){ String str=""; try{ str=br.readLine(); } catch(IOException e) { e.printStackTrace(); } return str; } }
Main.java:5: error: class BeTogether is public, should be declared in a file named BeTogether.java public class BeTogether { ^ 1 error
s500271363
p04025
Java
import java.io.*; import java.util.*; public class BeTogether { public static void main(String[] args) { FastReader sc=new FastReader(); int N=sc.nextInt(); int[] a=new int[N]; double sum=0; for(int i=0;i<N;i++){ a[i]=sc.nextInt(); sum+=a[i]; } int avg=(int)Math.round(sum/N); int mini=0; for(int i=0;i<N;i++){ mini+=Math.pow(a[i]-avg,2); } System.out.print(mini); } } class FastReader{ BufferedReader br ; StringTokenizer st; public FastReader(){ InputStreamReader inr =new InputStreamReader(System.in); br=new BufferedReader(inr); } String next(){ while(st==null || !st.hasMoreElements()){ try{ st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); }} return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } double nextDouble(){ return Double.parseDouble(next()); } long nextLong(){ return Long.parseLong(next()); } String nextLine(){ String str=""; try{ str=br.readLine(); } catch(IOException e) { e.printStackTrace(); } return str; } }
Main.java:5: error: class BeTogether is public, should be declared in a file named BeTogether.java public class BeTogether { ^ 1 error
s485364114
p04025
C++
#include<bits/stdc++.h> using namespace std ; const int N = 5005 , mod = 1e9 + 7 ; int n, f [N] [N], m; char s [N]; int main () { scanf ( "% d% s" , & n, s + 1 ); m = strlen (s + 1 ); f [ 0 ] [ 0 ] = 1 ; for ( int i = 0 ; i <n; i ++) for ( int j = 0 ; j <= i; j ++) { if (j) f [i + 1 ] [j- 1 ] = (f [i + 1 ] [j- 1 ] + f [i] [j])% mod; else f [i + 1 ] [j] = (f [i + 1 ] [j] + f [i] [j])% mod; f [i + 1 ] [j + 1 ] = (f [i + 1 ] [j + 1 ] + 1l l * f [i] [j] * 2 )% mod; } for ( int i = 1 ; i <= m; i ++) f [n] [m] = 1l l * f [n] [m] * 500000004 % mod; printf ( "% d \ n" , f [n] [m]); return 0 ; }
a.cc: In function 'int main()': a.cc:12:58: error: expected ')' before 'l' 12 | f [i + 1 ] [j + 1 ] = (f [i + 1 ] [j + 1 ] + 1l l * f [i] [j] * 2 )% mod; | ~ ^~ | ) a.cc:14:49: error: expected ';' before 'l' 14 | for ( int i = 1 ; i <= m; i ++) f [n] [m] = 1l l * f [n] [m] * 500000004 % mod; | ^~ | ; a.cc:15:13: warning: unknown escape sequence: '\040' 15 | printf ( "% d \ n" , f [n] [m]); | ^~~~~~~~~
s034259506
p04025
C++
#include <bits / stdc ++. h> using namespace std ; const int N = 5005 , mod = 1e9 + 7 ; int n, f [N] [N], m; char s [N]; int main () { scanf ( "% d% s" , & n, s + 1 ); m = strlen (s + 1 ); f [ 0 ] [ 0 ] = 1 ; for ( int i = 0 ; i <n; i ++) for ( int j = 0 ; j <= i; j ++) { if (j) f [i + 1 ] [j- 1 ] = (f [i + 1 ] [j- 1 ] + f [i] [j])% mod; else f [i + 1 ] [j] = (f [i + 1 ] [j] + f [i] [j])% mod; f [i + 1 ] [j + 1 ] = (f [i + 1 ] [j + 1 ] + 1l l * f [i] [j] * 2 )% mod; } for ( int i = 1 ; i <= m; i ++) f [n] [m] = 1l l * f [n] [m] * 500000004 % mod; printf ( "% d \ n" , f [n] [m]); return 0 ; }
a.cc:1:10: fatal error: bits / stdc ++. h: No such file or directory 1 | #include <bits / stdc ++. h> | ^~~~~~~~~~~~~~~~~~~ compilation terminated.
s592595611
p04025
Java
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { new Main(); } FS in = new FS(); PrintWriter out = new PrintWriter(System.out); int n, c; long mod = (long)1e9 + 7; int[] a, b; long[][] pre, dp; Main() { n = in.nextInt(); c = in.nextInt(); a = new int[n]; b = new int[n]; for (int i = 0; i < n; a[i++] = in.nextInt()); for (int i = 0; i < n; b[i++] = in.nextInt()); pre = new long[n][c + 1]; for (int i = 0; i < n; i++) for (int j = 0; j <= c; j++) for (int k = a[i]; k <= b[i]; k++) { pre[i][j] += pow(k, j); pre[i][j] %= mod; } dp = new long[n][c + 1]; out.println(dp(0, c)); out.close(); } long dp(int idx, int left) { if (left == 0) return 1; if (idx == n) return 0; if (dp[idx][left] != -1) return dp[idx][left]; long ans = 0; for (int i = 0; i <= left; i++) { ans += mult(pre[idx][i], dp(idx + 1, left - i)); ans %= mod; } return dp[idx][left] = ans; } long mult(long a, long b) { return (a % mod)*(b % mod) % mod; } long pow(long a, long b) { long res = 1L; while (b > 0) { res *= res; if ((b & 1) > 0) res *= a; res %= mod; b >> 1; } return res; } class FS { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) {} } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } }
Main.java:62: error: not a statement b >> 1; ^ 1 error
s320943370
p04025
Java
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { new Main(); } FS in = new FS(); PrintWriter out = new PrintWriter(System.out); int n, min, arr[]; Main() { arr = new int[n = in.nextInt()]; for (int i = 0; i < n; arr[i++] = in.nextInt()); min = 400_000*n; for (int j = -100; j <= 100; j++) { int cost = 0; for (int i = 0; i < n; i++) cost += (arr[i] - j)*(arr[i] - j); min = min(min, cost); } out.println(min); out.close(); } int min(int a, int b) { if (a < b) return a; return b; } class FS { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenier(""); String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) {} } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } }
Main.java:35: error: cannot find symbol StringTokenizer st = new StringTokenier(""); ^ symbol: class StringTokenier location: class Main.FS 1 error
s335025590
p04025
C++
#include <bits/stdc++.h> #include <algorithm> using namespace std; int main() { int a,b[110],c,d; cin >> a; for(int i=0;i<a;i++) cin >> b[i]; c=10000000; for(int i=0;i<a;i++){ d =0; for(int i=-100;i<110;i++){ d +=(b[i]-j); } c =min(c,d); } cout << c << endl; }
a.cc: In function 'int main()': a.cc:15:15: error: 'j' was not declared in this scope 15 | d +=(b[i]-j); | ^
s216344506
p04025
C++
#include<iostream> #include<algorithm> #include<cmath> using namespace std; int main() { int n,a[100],ans=10000000,cnt=0; cin >> n; for(int i=0; i<n; i++) { cin >> a[i]; } for(int i=-100; i<=100; i++) { for(int j=0; j<n; j++) { cnt+=(a[j]-i)(a[j]-i); } if(cnt<ans) { ans=cnt; } } cout << ans << endl; }
a.cc: In function 'int main()': a.cc:13:20: error: expression cannot be used as a function 13 | cnt+=(a[j]-i)(a[j]-i); | ~~~~~~~~^~~~~~~~
s069889159
p04025
C++
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=410; const ll mod = 1e9+7 ; ll a[N],b[N]; ll sum[N][N], l[N][N]; ll dp[N][N]; int main(){ ll n,m; scanf("%lld%lld",&n, &m); for(int i=1;i<=n;i++){ scanf("%lld",&a[i]); } for(int i=1;i<=n;i++){ scanf("%lld",&b[i]); } for(int i=0; i<N; i++){ l[i][0]=1; for(int j=1; j<N; j++){ l[i][j]=(l[i][j-1]*i)%mod; } } for(int i=1; i<N; i++){ for(int j=0; j<N; j++){ sum[i][j]=(sum[i][j]+sum[i-1][j]+l[i][j])%mod; } } dp[0][0]=1; for(int i=1;i<=n;i++){ for(int j=0;j<=m;j++){ for(int k=0;k<=j;k++){ dp[i][j]=(dp[i][j]%mod+(1ll*dp[i-1][j-k]*(sum[b[i]][k]-sum[a[i]-1][k]+))%mod)%mod; } } } printf("%lld\n",dp[n][m]); //system("pause"); return 0; }
a.cc: In function 'int main()': a.cc:33:87: error: expected primary-expression before ')' token 33 | dp[i][j]=(dp[i][j]%mod+(1ll*dp[i-1][j-k]*(sum[b[i]][k]-sum[a[i]-1][k]+))%mod)%mod; | ^
s712112130
p04025
C++
#include<iostream> #include<vector> using namespace std; int main(void){ int N; cin >> N; vector<int> a(N); int s = 0; for(int i = 0; i < N; i++){ cin >> a[i]; s += a[i]; } int m = (int)round((double)s / N); int ans = 0; for(int i = 0; i < N; i++) ans += (a[i] - m) * (a[i] - m); cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:15:16: error: 'round' was not declared in this scope 15 | int m = (int)round((double)s / N); | ^~~~~
s687261208
p04025
C++
#include<iostream> #include<cmath> #include<vector> using namespace std; int main() { vector<int> num(n); long long n; cin>>n; for(int i=0;i<n;i++) { cin>>num[i]; } int cost=1000000; for(int i=-200;i<=200;i++) { int be=0; for(int j=0;j<n;j++) { be+=(i-num[j])*(i-num[j]); } cost=min(cost,be); } cout<<cost; return 0; }
a.cc: In function 'int main()': a.cc:7:25: error: 'n' was not declared in this scope; did you mean 'yn'? 7 | vector<int> num(n); | ^ | yn
s719037782
p04025
C++
#include<iostream> #include<vector> #include<climits> #include<algorithm> using namespace std; int ans=INT_MAX; int main(void){ int n; cin>>n; vector<int> a(n); for(int i =0;i<n;i++)cin>>a(i); for(int i =-100;i<=100;i++){ int tmp=0; for(int j =0;j<n;j++)tmp+=(a[j]-i)*(a[j]-i); ans=min(ans,tmp); } cout <<ans<<endl; return 0; }
a.cc: In function 'int main()': a.cc:11:30: error: no match for call to '(std::vector<int>) (int&)' 11 | for(int i =0;i<n;i++)cin>>a(i); | ~^~~
s501922205
p04025
C++
#include<iostream> #include<vector> #include<climits> #include<algorithm> using namespace std; int ans=INT_MAX; int main(void){ int n; cin>>n; vector<int> a(n); for(int i =0;i<n;i++)cin>>a(i); for(int i =-100;i<=100;i++){ int tmp=0; for(int j =0;j<n;j++)tmp+=(a[j]-i)*(a[j]-i); ans=max(ans,tmp); } cout <<ans<<endl; return 0; }
a.cc: In function 'int main()': a.cc:11:30: error: no match for call to '(std::vector<int>) (int&)' 11 | for(int i =0;i<n;i++)cin>>a(i); | ~^~~
s928747182
p04025
C++
#include<iostream> #include<vector> #include<climts> #include<algorithm> using namespace std; int ans=INT_MAX; int main(void){ int n; cin>>n; vector<int> a(n); for(int i =0;i<n;i++)cin>>a(i); for(int i =-100;i<=100;i++){ int tmp=0; for(int j =0;j<n;j++)tmp+=(a[j]-i)*(a[j]-i); ans=max(ans,tmp); } cout <<ans<<endl; return 0; }
a.cc:3:9: fatal error: climts: No such file or directory 3 | #include<climts> | ^~~~~~~~ compilation terminated.
s341653742
p04025
C++
#include<stdio.h> #include<iostream> #include<algorithm> #include<cmath> #include<map> #include<vector> #include<string.h> #include<set> #define inf 0x3f3f3f3f using namespace std; int pre[110]; int main() { int n; cin>>n; int sum=0; for(int i=0;i<n;i++) { scanf("%d",&pre[i]); sum+=pre[i]; } sum=sum/n; for(int i=0;i<n;i++) { ans+=(pre[i]-sum)*(pre[i]-sum); } printf("%d\n",ans); }
a.cc: In function 'int main()': a.cc:25:9: error: 'ans' was not declared in this scope; did you mean 'abs'? 25 | ans+=(pre[i]-sum)*(pre[i]-sum); | ^~~ | abs a.cc:27:19: error: 'ans' was not declared in this scope; did you mean 'abs'? 27 | printf("%d\n",ans); | ^~~ | abs
s106938276
p04025
C++
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define ll long long #define Di 3.1415926 #include<math.h> #include<string> #include<stack> #define INF 0x3f3f3f3f using namespace std; ll gcd(ll a,ll b) { return a%b? gcd(b,a%b):b; } struct Node { int t; char a[102]; }s[102]; bool cmp(Node a,Node b) { return strcmp(a.a,b.a)<0; } int a[200]; int main() { int m,sum=0; cin>>m; for(i=0;i<m;i++) { cin>>a[i]; sum+=a[i]; } int num=sum/m; if(sum%m!=0) num+=1; sum=0; for(i=0;i<m;i++) { sum+= pow((a[i]-num),2); } cout<<sum<<endl; return 0; }
a.cc: In function 'int main()': a.cc:29:11: error: 'i' was not declared in this scope 29 | for(i=0;i<m;i++) | ^ a.cc:38:13: error: 'i' was not declared in this scope 38 | for(i=0;i<m;i++) | ^
s894615675
p04025
C++
#include<iostream> #include<cstdio> #include<cmath> using namespace std; long long sum=1e9+7; int main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int n; scanf("%d",&n); vector<int> v(n); for(int i=0;i<n;i++) cin>>v[i]; for (int i=-100;i<=100;++i){ long long tmp=0; for(int j=0;j<n;j++){ tmp+=pow((i-v[j]),2); } sum=min(tmp,sum); } cout << sum << endl; }
a.cc: In function 'int main()': a.cc:10:5: error: 'vector' was not declared in this scope 10 | vector<int> v(n); | ^~~~~~ a.cc:4:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>' 3 | #include<cmath> +++ |+#include <vector> 4 | using namespace std; a.cc:10:12: error: expected primary-expression before 'int' 10 | vector<int> v(n); | ^~~ a.cc:12:22: error: 'v' was not declared in this scope 12 | cin>>v[i]; | ^ a.cc:16:25: error: 'v' was not declared in this scope 16 | tmp+=pow((i-v[j]),2); | ^