problem_id stringlengths 6 6 | language stringclasses 2 values | original_status stringclasses 3 values | original_src stringlengths 19 243k | changed_src stringlengths 19 243k | change stringclasses 3 values | i1 int64 0 8.44k | i2 int64 0 8.44k | j1 int64 0 8.44k | j2 int64 0 8.44k | error stringclasses 270 values | stderr stringlengths 0 226k |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02956 | C++ | Runtime Error | #include <bits/stdc++.h>
#define mod 998244353
#define M 200007
using namespace std;
struct mo {
int x, y;
} a[M];
int n, X[M], Y[M], c[M];
long long ans, pre[507] = {1};
bool Mo(mo x, mo y) { return x.y < y.y; }
void add(int x) {
while (x < M)
c[x]++, x += x & -x;
}
int query(int x) {
int res = 0;
while (x)
res += c[x], x -= x & -x;
return res;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
pre[i] = pre[i - 1] * 2 % mod;
for (int i = 1; i <= n; i++)
scanf("%d%d", &a[i].x, &a[i].y), X[i] = a[i].x, Y[i] = a[i].y;
sort(X + 1, X + n + 1), sort(Y + 1, Y + n + 1);
for (int i = 1; i <= n; i++) {
a[i].x = lower_bound(X + 1, X + n + 1, a[i].x) - X;
a[i].y = lower_bound(Y + 1, Y + n + 1, a[i].y) - Y;
}
ans = n * (pre[n] - 1) % mod;
for (int i = 1; i <= n; i++) {
ans = (ans - pre[i] + 2 + mod) % mod;
ans = (ans - pre[n - i + 1] + 2 + mod) % mod;
}
sort(a + 1, a + n + 1, Mo);
for (int i = 1; i <= n; i++) {
int p = query(a[i].x);
ans = (ans + pre[p] - 1) % mod;
ans = (ans + pre[i - p - 1] - 1) % mod;
add(a[i].x);
}
memset(c, 0, sizeof c);
for (int i = n; i >= 1; i--) {
int p = query(a[i].x);
ans = (ans + pre[p] - 1) % mod;
ans = (ans + pre[n - i - p] - 1) % mod;
add(a[i].x);
}
printf("%lld\n", ans);
return 0;
} | #include <bits/stdc++.h>
#define mod 998244353
#define M 200007
using namespace std;
struct mo {
int x, y;
} a[M];
int n, X[M], Y[M], c[M];
long long ans, pre[M] = {1};
bool Mo(mo x, mo y) { return x.y < y.y; }
void add(int x) {
while (x < M)
c[x]++, x += x & -x;
}
int query(int x) {
int res = 0;
while (x)
res += c[x], x -= x & -x;
return res;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
pre[i] = pre[i - 1] * 2 % mod;
for (int i = 1; i <= n; i++)
scanf("%d%d", &a[i].x, &a[i].y), X[i] = a[i].x, Y[i] = a[i].y;
sort(X + 1, X + n + 1), sort(Y + 1, Y + n + 1);
for (int i = 1; i <= n; i++) {
a[i].x = lower_bound(X + 1, X + n + 1, a[i].x) - X;
a[i].y = lower_bound(Y + 1, Y + n + 1, a[i].y) - Y;
}
ans = n * (pre[n] - 1) % mod;
for (int i = 1; i <= n; i++) {
ans = (ans - pre[i] + 2 + mod) % mod;
ans = (ans - pre[n - i + 1] + 2 + mod) % mod;
}
sort(a + 1, a + n + 1, Mo);
for (int i = 1; i <= n; i++) {
int p = query(a[i].x);
ans = (ans + pre[p] - 1) % mod;
ans = (ans + pre[i - p - 1] - 1) % mod;
add(a[i].x);
}
memset(c, 0, sizeof c);
for (int i = n; i >= 1; i--) {
int p = query(a[i].x);
ans = (ans + pre[p] - 1) % mod;
ans = (ans + pre[n - i - p] - 1) % mod;
add(a[i].x);
}
printf("%lld\n", ans);
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02956 | C++ | Runtime Error | #include <bits/stdc++.h>
/* FastIO by rsk0315 (last update: 2018/02/21 00:36) */
namespace FastIn {
static constexpr size_t BUF_SIZE = 1 << 17, INT_LEN = 24, FLT_LEN = 400;
static char buf[BUF_SIZE | 1] = {}, *pos = buf, *endbuf = nullptr;
FILE *fin;
inline bool rebuffer() {
// returns true <=> there is at least one unread character
size_t rest = endbuf - pos;
if (buf + rest > pos) {
// buf[:pos] and buf[-pos:] are overlapping, which std::memcpy()
// causes undefined behavior.
return true;
}
std::memcpy(buf, pos, rest);
pos = buf;
size_t len = std::fread(pos + rest, 1, BUF_SIZE - rest, fin);
*(endbuf = buf + (rest + len)) = 0;
return *pos;
}
inline bool scan(char &in) {
if ((in = *pos)) {
++pos;
return true;
}
return rebuffer() && (in = *pos++);
}
inline bool scan(char *in) {
if ((*in = *pos) == 0) {
if (rebuffer() && (*in = *pos) == 0) {
return false;
}
}
++in;
while (true) {
if ((*in = *pos++) == 0) {
if (rebuffer() && (*in = *pos++) == 0) {
return true;
}
}
++in;
}
}
inline bool scan(double &in) {
if (pos + FLT_LEN >= endbuf && !rebuffer()) {
in = 0.0;
return false;
}
char *tmp;
in = std::strtod(pos, &tmp);
pos = tmp;
return true;
}
template <class Int> inline bool scan(Int &in) {
in = 0;
// assume that no redundant whitespace appears
if (pos + INT_LEN >= endbuf && !rebuffer()) {
return false;
}
if (std::is_signed<Int>::value) {
if (*pos == '-') {
in = ~*++pos + '1';
while (*++pos >= '0') {
in = in * 10 + ~*pos + '1';
}
++pos;
return true;
}
}
// assume that numbers are separated by the character whose value is
// less than '0' (e.g. whitespaces, newlines)
do {
in = in * 10 + *pos - '0';
} while (*++pos >= '0');
++pos;
return true;
}
inline bool eat() {
if (*pos > ' ') {
return true;
}
do {
if (*pos == 0 && !rebuffer()) {
return false;
}
} while (*++pos <= ' ');
return true;
}
inline bool eat(char ch) {
if (*pos == ch) {
return true;
}
do {
if (*pos == 0 && !rebuffer()) {
return false;
}
} while (*++pos != ch);
return true;
}
class Scanner {
bool rebuffer() { return FastIn::rebuffer(); }
public:
Scanner(FILE *fin = stdin) {
FastIn::fin = fin;
endbuf = pos + std::fread(buf, 1, BUF_SIZE, fin);
}
template <class T> inline bool scan(T &in) { return FastIn::scan(in); }
template <class First, class... Rest>
inline bool scan(First &in, Rest &...ins) {
return scan(in) && scan(ins...);
}
};
} // namespace FastIn
template <class RandomIt>
auto rsort(RandomIt first, RandomIt last) -> typename std::enable_if<
std::is_integral<typename RandomIt::value_type::first_type>::value>::type {
using PairType = typename RandomIt::value_type;
using KeyType = typename PairType::first_type;
intmax_t cur_shift = 0, max_exp = sizeof(KeyType);
std::vector<PairType> work(last - first);
for (int i = 0; i < max_exp; ++i) {
size_t num[256] = {};
for (RandomIt it = first; it < last; ++it)
++num[((it->first) >> cur_shift) & 255];
{
size_t tmp = 0;
for (int j = 0; j < 256; ++j)
std::swap(tmp, num[j] += tmp);
}
for (RandomIt it = first; it < last; ++it)
work[num[((it->first) >> cur_shift) & 255]++] = *it;
{
size_t j = 0;
for (RandomIt it = first; it < last; ++it)
*it = work[j++];
}
cur_shift += 8;
}
if (!std::is_signed<KeyType>::value)
return;
RandomIt mid = last;
for (RandomIt it = last; --it >= first;)
if ((it->first) >= 0) {
mid = ++it;
break;
}
if (mid == last)
return;
std::copy(first, mid, work.begin() + (last - mid));
std::copy(mid, last, work.begin());
std::copy(work.begin(), work.end(), first);
}
/* kokomade */
int main() {
using namespace std;
FastIn::Scanner in;
unsigned long N;
in.scan(N);
vector<unsigned long> perm(N);
{
vector<pair<long, long>> p(N);
for (auto &i : p)
in.scan(i.first, i.second);
rsort(p.begin(), p.end());
for (unsigned long i = 0; i < N; ++i)
p[i] = {p[i].second, i + 1};
rsort(p.begin(), p.end());
transform(p.cbegin(), p.cend(), perm.begin(),
[](auto i) { return i.second; });
}
constexpr unsigned long MOD = 998244353;
vector<unsigned long> binary(N + 1);
unsigned long n = binary[0] = 1;
generate(binary.begin() + 1, binary.end(), [&n]() {
if (n >= MOD)
n -= MOD;
return n <<= 1;
});
unsigned long N_{*lower_bound(binary.begin(), binary.begin() + 29, N)};
vector<unsigned long> fenwick_tree(N_ + 1);
auto que = [&fenwick_tree, &N_](unsigned long i) {
unsigned long s{0}, j{i};
while (i) {
s += fenwick_tree[i];
i -= i & -i;
}
while (j <= N_) {
++fenwick_tree[j];
j += j & -j;
}
return s;
};
vector<unsigned long> coef(N + 1);
coef[N] = N + MOD - 4;
for (unsigned long i = 0; i != N; ++i) {
auto q = que(perm[i]);
++coef[q];
++coef[i - q];
++coef[perm[i] - q - 1];
++coef[N - i - perm[i] + q];
}
cout << inner_product(binary.begin(), binary.end(), coef.begin(),
4 + MOD - N) %
MOD
<< endl;
return 0;
} | #include <bits/stdc++.h>
/* FastIO by rsk0315 (last update: 2018/02/21 00:36) */
namespace FastIn {
static constexpr size_t BUF_SIZE = 1 << 17, INT_LEN = 24, FLT_LEN = 400;
static char buf[BUF_SIZE | 1] = {}, *pos = buf, *endbuf = nullptr;
FILE *fin;
inline bool rebuffer() {
// returns true <=> there is at least one unread character
size_t rest = endbuf - pos;
if (buf + rest > pos) {
// buf[:pos] and buf[-pos:] are overlapping, which std::memcpy()
// causes undefined behavior.
return true;
}
std::memcpy(buf, pos, rest);
pos = buf;
size_t len = std::fread(pos + rest, 1, BUF_SIZE - rest, fin);
*(endbuf = buf + (rest + len)) = 0;
return *pos;
}
inline bool scan(char &in) {
if ((in = *pos)) {
++pos;
return true;
}
return rebuffer() && (in = *pos++);
}
inline bool scan(char *in) {
if ((*in = *pos) == 0) {
if (rebuffer() && (*in = *pos) == 0) {
return false;
}
}
++in;
while (true) {
if ((*in = *pos++) == 0) {
if (rebuffer() && (*in = *pos++) == 0) {
return true;
}
}
++in;
}
}
inline bool scan(double &in) {
if (pos + FLT_LEN >= endbuf && !rebuffer()) {
in = 0.0;
return false;
}
char *tmp;
in = std::strtod(pos, &tmp);
pos = tmp;
return true;
}
template <class Int> inline bool scan(Int &in) {
in = 0;
// assume that no redundant whitespace appears
if (pos + INT_LEN >= endbuf && !rebuffer()) {
return false;
}
if (std::is_signed<Int>::value) {
if (*pos == '-') {
in = ~*++pos + '1';
while (*++pos >= '0') {
in = in * 10 + ~*pos + '1';
}
++pos;
return true;
}
}
// assume that numbers are separated by the character whose value is
// less than '0' (e.g. whitespaces, newlines)
do {
in = in * 10 + *pos - '0';
} while (*++pos >= '0');
++pos;
return true;
}
inline bool eat() {
if (*pos > ' ') {
return true;
}
do {
if (*pos == 0 && !rebuffer()) {
return false;
}
} while (*++pos <= ' ');
return true;
}
inline bool eat(char ch) {
if (*pos == ch) {
return true;
}
do {
if (*pos == 0 && !rebuffer()) {
return false;
}
} while (*++pos != ch);
return true;
}
class Scanner {
bool rebuffer() { return FastIn::rebuffer(); }
public:
Scanner(FILE *fin = stdin) {
FastIn::fin = fin;
endbuf = pos + std::fread(buf, 1, BUF_SIZE, fin);
}
template <class T> inline bool scan(T &in) { return FastIn::scan(in); }
template <class First, class... Rest>
inline bool scan(First &in, Rest &...ins) {
return scan(in) && scan(ins...);
}
};
} // namespace FastIn
template <class RandomIt>
auto rsort(RandomIt first, RandomIt last) -> typename std::enable_if<
std::is_integral<typename RandomIt::value_type::first_type>::value>::type {
using PairType = typename RandomIt::value_type;
using KeyType = typename PairType::first_type;
intmax_t cur_shift = 0, max_exp = sizeof(KeyType);
std::vector<PairType> work(last - first);
for (int i = 0; i < max_exp; ++i) {
size_t num[256] = {};
for (RandomIt it = first; it < last; ++it)
++num[((it->first) >> cur_shift) & 255];
{
size_t tmp = 0;
for (int j = 0; j < 256; ++j)
std::swap(tmp, num[j] += tmp);
}
for (RandomIt it = first; it < last; ++it)
work[num[((it->first) >> cur_shift) & 255]++] = *it;
{
size_t j = 0;
for (RandomIt it = first; it < last; ++it)
*it = work[j++];
}
cur_shift += 8;
}
if (!std::is_signed<KeyType>::value)
return;
RandomIt mid = last;
for (RandomIt it = last; --it >= first;)
if ((it->first) >= 0) {
mid = ++it;
break;
}
if (mid == last)
return;
std::copy(first, mid, work.begin() + (last - mid));
std::copy(mid, last, work.begin());
std::copy(work.begin(), work.end(), first);
}
/* kokomade */
int main() {
using namespace std;
FastIn::Scanner in;
unsigned long N;
in.scan(N);
vector<unsigned long> perm(N);
{
vector<pair<long, long>> p(N);
for (auto &i : p)
in.scan(i.first, i.second);
rsort(p.begin(), p.end());
for (unsigned long i = 0; i < N; ++i)
p[i] = {p[i].second, i + 1};
rsort(p.begin(), p.end());
transform(p.cbegin(), p.cend(), perm.begin(),
[](auto i) { return i.second; });
}
constexpr unsigned long MOD = 998244353;
vector<unsigned long> binary(N + 1);
unsigned long n = binary[0] = 1;
generate(binary.begin() + 1, binary.end(), [&n]() {
if (n >= MOD)
n -= MOD;
return n <<= 1;
});
unsigned long N_{2};
{
while (N_ <= N)
N_ <<= 1;
}
vector<unsigned long> fenwick_tree(N_ + 1);
auto que = [&fenwick_tree, &N_](unsigned long i) {
unsigned long s{0}, j{i};
while (i) {
s += fenwick_tree[i];
i -= i & -i;
}
while (j <= N_) {
++fenwick_tree[j];
j += j & -j;
}
return s;
};
vector<unsigned long> coef(N + 1);
coef[N] = N + MOD - 4;
for (unsigned long i = 0; i != N; ++i) {
auto q = que(perm[i]);
++coef[q];
++coef[i - q];
++coef[perm[i] - q - 1];
++coef[N - i - perm[i] + q];
}
cout << inner_product(binary.begin(), binary.end(), coef.begin(),
4 + MOD - N) %
MOD
<< endl;
return 0;
} | replace | 217 | 219 | 217 | 222 | 0 | |
p02956 | C++ | Runtime Error | #include <bits/stdc++.h>
/* FastIO by rsk0315 (last update: 2018/02/21 00:36) */
namespace FastIn {
static constexpr size_t BUF_SIZE = 1 << 17, INT_LEN = 24, FLT_LEN = 400;
static char buf[BUF_SIZE | 1] = {}, *pos = buf, *endbuf = nullptr;
FILE *fin;
inline bool rebuffer() {
// returns true <=> there is at least one unread character
size_t rest = endbuf - pos;
if (buf + rest > pos) {
// buf[:pos] and buf[-pos:] are overlapping, which std::memcpy()
// causes undefined behavior.
return true;
}
std::memcpy(buf, pos, rest);
pos = buf;
size_t len = std::fread(pos + rest, 1, BUF_SIZE - rest, fin);
*(endbuf = buf + (rest + len)) = 0;
return *pos;
}
inline bool scan(char &in) {
if ((in = *pos)) {
++pos;
return true;
}
return rebuffer() && (in = *pos++);
}
inline bool scan(char *in) {
if ((*in = *pos) == 0) {
if (rebuffer() && (*in = *pos) == 0) {
return false;
}
}
++in;
while (true) {
if ((*in = *pos++) == 0) {
if (rebuffer() && (*in = *pos++) == 0) {
return true;
}
}
++in;
}
}
inline bool scan(double &in) {
if (pos + FLT_LEN >= endbuf && !rebuffer()) {
in = 0.0;
return false;
}
char *tmp;
in = std::strtod(pos, &tmp);
pos = tmp;
return true;
}
template <class Int> inline bool scan(Int &in) {
in = 0;
// assume that no redundant whitespace appears
if (pos + INT_LEN >= endbuf && !rebuffer()) {
return false;
}
if (std::is_signed<Int>::value) {
if (*pos == '-') {
in = ~*++pos + '1';
while (*++pos >= '0') {
in = in * 10 + ~*pos + '1';
}
++pos;
return true;
}
}
// assume that numbers are separated by the character whose value is
// less than '0' (e.g. whitespaces, newlines)
do {
in = in * 10 + *pos - '0';
} while (*++pos >= '0');
++pos;
return true;
}
inline bool eat() {
if (*pos > ' ') {
return true;
}
do {
if (*pos == 0 && !rebuffer()) {
return false;
}
} while (*++pos <= ' ');
return true;
}
inline bool eat(char ch) {
if (*pos == ch) {
return true;
}
do {
if (*pos == 0 && !rebuffer()) {
return false;
}
} while (*++pos != ch);
return true;
}
class Scanner {
bool rebuffer() { return FastIn::rebuffer(); }
public:
Scanner(FILE *fin = stdin) {
FastIn::fin = fin;
endbuf = pos + std::fread(buf, 1, BUF_SIZE, fin);
}
template <class T> inline bool scan(T &in) { return FastIn::scan(in); }
template <class First, class... Rest>
inline bool scan(First &in, Rest &...ins) {
return scan(in) && scan(ins...);
}
};
} // namespace FastIn
template <class RandomIt>
auto rsort(RandomIt first, RandomIt last) -> typename std::enable_if<
std::is_integral<typename RandomIt::value_type::first_type>::value>::type {
using PairType = typename RandomIt::value_type;
using KeyType = typename PairType::first_type;
intmax_t cur_shift = 0, max_exp = sizeof(KeyType);
std::vector<PairType> work(last - first);
for (int i = 0; i < max_exp; ++i) {
size_t num[256] = {};
for (RandomIt it = first; it < last; ++it)
++num[((it->first) >> cur_shift) & 255];
{
size_t tmp = 0;
for (int j = 0; j < 256; ++j)
std::swap(tmp, num[j] += tmp);
}
for (RandomIt it = first; it < last; ++it)
work[num[((it->first) >> cur_shift) & 255]++] = *it;
{
size_t j = 0;
for (RandomIt it = first; it < last; ++it)
*it = work[j++];
}
cur_shift += 8;
}
if (!std::is_signed<KeyType>::value)
return;
RandomIt mid = last;
for (RandomIt it = last; --it >= first;)
if ((it->first) >= 0) {
mid = ++it;
break;
}
if (mid == last)
return;
std::copy(first, mid, work.begin() + (last - mid));
std::copy(mid, last, work.begin());
std::copy(work.begin(), work.end(), first);
}
/* kokomade */
int main() {
using namespace std;
FastIn::Scanner in;
unsigned long N;
in.scan(N);
vector<unsigned long> perm(N);
{
vector<pair<long, long>> p(N), q(N);
for (auto &i : p)
in.scan(i.first, i.second);
rsort(p.begin(), p.end());
for (unsigned long i = 0; i < N; ++i)
q[i] = {p[i].second, i};
rsort(q.begin(), q.end());
transform(q.cbegin(), q.cend(), perm.begin(),
[](auto i) { return i.first; });
}
constexpr unsigned long MOD = 998244353;
vector<unsigned long> binary(N + 1);
binary[0] = 1;
for (unsigned long i = 0; i != N; ++i)
binary[i + 1] = binary[i] * 2 - (binary[i] > 499122176) * MOD;
vector<unsigned long> fenwick_tree(N + 1);
auto que = [&fenwick_tree, &N](unsigned long i) {
unsigned long r = i;
unsigned long ret{fenwick_tree[i]};
while (i &= i + 1)
ret += fenwick_tree[--i];
i = r;
while (i < N) {
++fenwick_tree[i];
i |= i + 1;
}
return ret;
};
vector<unsigned long> coef(N + 1);
coef[N] = N + MOD - 4;
for (unsigned long i = 0; i != N; ++i) {
auto q = que(perm[i]);
++coef[q];
++coef[i - q];
++coef[perm[i] - q];
++coef[N - i - perm[i] + q - 1];
}
cout << inner_product(binary.begin(), binary.end(), coef.begin(),
4 + MOD - N) %
MOD
<< endl;
return 0;
} | #include <bits/stdc++.h>
/* FastIO by rsk0315 (last update: 2018/02/21 00:36) */
namespace FastIn {
static constexpr size_t BUF_SIZE = 1 << 17, INT_LEN = 24, FLT_LEN = 400;
static char buf[BUF_SIZE | 1] = {}, *pos = buf, *endbuf = nullptr;
FILE *fin;
inline bool rebuffer() {
// returns true <=> there is at least one unread character
size_t rest = endbuf - pos;
if (buf + rest > pos) {
// buf[:pos] and buf[-pos:] are overlapping, which std::memcpy()
// causes undefined behavior.
return true;
}
std::memcpy(buf, pos, rest);
pos = buf;
size_t len = std::fread(pos + rest, 1, BUF_SIZE - rest, fin);
*(endbuf = buf + (rest + len)) = 0;
return *pos;
}
inline bool scan(char &in) {
if ((in = *pos)) {
++pos;
return true;
}
return rebuffer() && (in = *pos++);
}
inline bool scan(char *in) {
if ((*in = *pos) == 0) {
if (rebuffer() && (*in = *pos) == 0) {
return false;
}
}
++in;
while (true) {
if ((*in = *pos++) == 0) {
if (rebuffer() && (*in = *pos++) == 0) {
return true;
}
}
++in;
}
}
inline bool scan(double &in) {
if (pos + FLT_LEN >= endbuf && !rebuffer()) {
in = 0.0;
return false;
}
char *tmp;
in = std::strtod(pos, &tmp);
pos = tmp;
return true;
}
template <class Int> inline bool scan(Int &in) {
in = 0;
// assume that no redundant whitespace appears
if (pos + INT_LEN >= endbuf && !rebuffer()) {
return false;
}
if (std::is_signed<Int>::value) {
if (*pos == '-') {
in = ~*++pos + '1';
while (*++pos >= '0') {
in = in * 10 + ~*pos + '1';
}
++pos;
return true;
}
}
// assume that numbers are separated by the character whose value is
// less than '0' (e.g. whitespaces, newlines)
do {
in = in * 10 + *pos - '0';
} while (*++pos >= '0');
++pos;
return true;
}
inline bool eat() {
if (*pos > ' ') {
return true;
}
do {
if (*pos == 0 && !rebuffer()) {
return false;
}
} while (*++pos <= ' ');
return true;
}
inline bool eat(char ch) {
if (*pos == ch) {
return true;
}
do {
if (*pos == 0 && !rebuffer()) {
return false;
}
} while (*++pos != ch);
return true;
}
class Scanner {
bool rebuffer() { return FastIn::rebuffer(); }
public:
Scanner(FILE *fin = stdin) {
FastIn::fin = fin;
endbuf = pos + std::fread(buf, 1, BUF_SIZE, fin);
}
template <class T> inline bool scan(T &in) { return FastIn::scan(in); }
template <class First, class... Rest>
inline bool scan(First &in, Rest &...ins) {
return scan(in) && scan(ins...);
}
};
} // namespace FastIn
template <class RandomIt>
auto rsort(RandomIt first, RandomIt last) -> typename std::enable_if<
std::is_integral<typename RandomIt::value_type::first_type>::value>::type {
using PairType = typename RandomIt::value_type;
using KeyType = typename PairType::first_type;
intmax_t cur_shift = 0, max_exp = sizeof(KeyType);
std::vector<PairType> work(last - first);
for (int i = 0; i < max_exp; ++i) {
size_t num[256] = {};
for (RandomIt it = first; it < last; ++it)
++num[((it->first) >> cur_shift) & 255];
{
size_t tmp = 0;
for (int j = 0; j < 256; ++j)
std::swap(tmp, num[j] += tmp);
}
for (RandomIt it = first; it < last; ++it)
work[num[((it->first) >> cur_shift) & 255]++] = *it;
{
size_t j = 0;
for (RandomIt it = first; it < last; ++it)
*it = work[j++];
}
cur_shift += 8;
}
if (!std::is_signed<KeyType>::value)
return;
RandomIt mid = last;
for (RandomIt it = last; --it >= first;)
if ((it->first) >= 0) {
mid = ++it;
break;
}
if (mid == last)
return;
std::copy(first, mid, work.begin() + (last - mid));
std::copy(mid, last, work.begin());
std::copy(work.begin(), work.end(), first);
}
/* kokomade */
int main() {
using namespace std;
FastIn::Scanner in;
unsigned long N;
in.scan(N);
vector<unsigned long> perm(N);
{
vector<pair<long, long>> p(N), q(N);
for (auto &i : p)
in.scan(i.first, i.second);
rsort(p.begin(), p.end());
for (unsigned long i = 0; i < N; ++i)
q[i] = {p[i].second, i};
rsort(q.begin(), q.end());
transform(q.cbegin(), q.cend(), perm.begin(),
[](auto i) { return i.second; });
}
constexpr unsigned long MOD = 998244353;
vector<unsigned long> binary(N + 1);
binary[0] = 1;
for (unsigned long i = 0; i != N; ++i)
binary[i + 1] = binary[i] * 2 - (binary[i] > 499122176) * MOD;
vector<unsigned long> fenwick_tree(N + 1);
auto que = [&fenwick_tree, &N](unsigned long i) {
unsigned long r = i;
unsigned long ret{fenwick_tree[i]};
while (i &= i + 1)
ret += fenwick_tree[--i];
i = r;
while (i < N) {
++fenwick_tree[i];
i |= i + 1;
}
return ret;
};
vector<unsigned long> coef(N + 1);
coef[N] = N + MOD - 4;
for (unsigned long i = 0; i != N; ++i) {
auto q = que(perm[i]);
++coef[q];
++coef[i - q];
++coef[perm[i] - q];
++coef[N - i - perm[i] + q - 1];
}
cout << inner_product(binary.begin(), binary.end(), coef.begin(),
4 + MOD - N) %
MOD
<< endl;
return 0;
} | replace | 205 | 206 | 205 | 206 | -11 | |
p02956 | C++ | Runtime Error | #include <bits/stdc++.h>
/* FastIO by rsk0315 (last update: 2018/02/21 00:36) */
namespace FastIn {
static constexpr size_t BUF_SIZE = 1 << 17, INT_LEN = 24, FLT_LEN = 400;
static char buf[BUF_SIZE | 1] = {}, *pos = buf, *endbuf = nullptr;
FILE *fin;
inline bool rebuffer() {
// returns true <=> there is at least one unread character
size_t rest = endbuf - pos;
if (buf + rest > pos) {
// buf[:pos] and buf[-pos:] are overlapping, which std::memcpy()
// causes undefined behavior.
return true;
}
std::memcpy(buf, pos, rest);
pos = buf;
size_t len = std::fread(pos + rest, 1, BUF_SIZE - rest, fin);
*(endbuf = buf + (rest + len)) = 0;
return *pos;
}
inline bool scan(char &in) {
if ((in = *pos)) {
++pos;
return true;
}
return rebuffer() && (in = *pos++);
}
inline bool scan(char *in) {
if ((*in = *pos) == 0) {
if (rebuffer() && (*in = *pos) == 0) {
return false;
}
}
++in;
while (true) {
if ((*in = *pos++) == 0) {
if (rebuffer() && (*in = *pos++) == 0) {
return true;
}
}
++in;
}
}
inline bool scan(double &in) {
if (pos + FLT_LEN >= endbuf && !rebuffer()) {
in = 0.0;
return false;
}
char *tmp;
in = std::strtod(pos, &tmp);
pos = tmp;
return true;
}
template <class Int> inline bool scan(Int &in) {
in = 0;
// assume that no redundant whitespace appears
if (pos + INT_LEN >= endbuf && !rebuffer()) {
return false;
}
if (std::is_signed<Int>::value) {
if (*pos == '-') {
in = ~*++pos + '1';
while (*++pos >= '0') {
in = in * 10 + ~*pos + '1';
}
++pos;
return true;
}
}
// assume that numbers are separated by the character whose value is
// less than '0' (e.g. whitespaces, newlines)
do {
in = in * 10 + *pos - '0';
} while (*++pos >= '0');
++pos;
return true;
}
inline bool eat() {
if (*pos > ' ') {
return true;
}
do {
if (*pos == 0 && !rebuffer()) {
return false;
}
} while (*++pos <= ' ');
return true;
}
inline bool eat(char ch) {
if (*pos == ch) {
return true;
}
do {
if (*pos == 0 && !rebuffer()) {
return false;
}
} while (*++pos != ch);
return true;
}
class Scanner {
bool rebuffer() { return FastIn::rebuffer(); }
public:
Scanner(FILE *fin = stdin) {
FastIn::fin = fin;
endbuf = pos + std::fread(buf, 1, BUF_SIZE, fin);
}
template <class T> inline bool scan(T &in) { return FastIn::scan(in); }
template <class First, class... Rest>
inline bool scan(First &in, Rest &...ins) {
return scan(in) && scan(ins...);
}
};
} // namespace FastIn
/* kokomade */
int main() {
using namespace std;
FastIn::Scanner in;
unsigned long N;
cin >> N;
vector<unsigned long> perm(N);
{
vector<pair<long, long>> p(N);
for (auto &i : p)
in.scan(i.first, i.second);
sort(p.begin(), p.end());
iota(perm.begin(), perm.end(), 0UL);
sort(perm.begin(), perm.end(),
[&p](auto i, auto j) { return p[i].second < p[j].second; });
}
constexpr unsigned long MOD = 998244353;
vector<unsigned long> binary(N + 1);
binary[0] = 1;
for (unsigned long i = 0; i < N; ++i)
binary[i + 1] = binary[i] * 2 - (binary[i] > 499122176) * MOD;
vector<unsigned long> fenwick_tree(N);
auto que = [&fenwick_tree, &N](unsigned long i) {
unsigned long r = i;
unsigned long ret{fenwick_tree[i]};
while (i &= i + 1)
ret += fenwick_tree[--i];
i = r;
while (i < N) {
++fenwick_tree[i];
i |= i + 1;
}
return ret;
};
vector<unsigned long> coef(N + 1);
for (unsigned long i = 0; i < N; ++i) {
auto q = que(perm[i]);
++coef[q];
++coef[i - q];
++coef[perm[i] - q];
++coef[N - i - perm[i] + q - 1];
}
cout << inner_product(binary.begin(), binary.end(), coef.begin(),
(N + MOD - 4) * (binary[N] - 1)) %
MOD
<< endl;
return 0;
} | #include <bits/stdc++.h>
/* FastIO by rsk0315 (last update: 2018/02/21 00:36) */
namespace FastIn {
static constexpr size_t BUF_SIZE = 1 << 17, INT_LEN = 24, FLT_LEN = 400;
static char buf[BUF_SIZE | 1] = {}, *pos = buf, *endbuf = nullptr;
FILE *fin;
inline bool rebuffer() {
// returns true <=> there is at least one unread character
size_t rest = endbuf - pos;
if (buf + rest > pos) {
// buf[:pos] and buf[-pos:] are overlapping, which std::memcpy()
// causes undefined behavior.
return true;
}
std::memcpy(buf, pos, rest);
pos = buf;
size_t len = std::fread(pos + rest, 1, BUF_SIZE - rest, fin);
*(endbuf = buf + (rest + len)) = 0;
return *pos;
}
inline bool scan(char &in) {
if ((in = *pos)) {
++pos;
return true;
}
return rebuffer() && (in = *pos++);
}
inline bool scan(char *in) {
if ((*in = *pos) == 0) {
if (rebuffer() && (*in = *pos) == 0) {
return false;
}
}
++in;
while (true) {
if ((*in = *pos++) == 0) {
if (rebuffer() && (*in = *pos++) == 0) {
return true;
}
}
++in;
}
}
inline bool scan(double &in) {
if (pos + FLT_LEN >= endbuf && !rebuffer()) {
in = 0.0;
return false;
}
char *tmp;
in = std::strtod(pos, &tmp);
pos = tmp;
return true;
}
template <class Int> inline bool scan(Int &in) {
in = 0;
// assume that no redundant whitespace appears
if (pos + INT_LEN >= endbuf && !rebuffer()) {
return false;
}
if (std::is_signed<Int>::value) {
if (*pos == '-') {
in = ~*++pos + '1';
while (*++pos >= '0') {
in = in * 10 + ~*pos + '1';
}
++pos;
return true;
}
}
// assume that numbers are separated by the character whose value is
// less than '0' (e.g. whitespaces, newlines)
do {
in = in * 10 + *pos - '0';
} while (*++pos >= '0');
++pos;
return true;
}
inline bool eat() {
if (*pos > ' ') {
return true;
}
do {
if (*pos == 0 && !rebuffer()) {
return false;
}
} while (*++pos <= ' ');
return true;
}
inline bool eat(char ch) {
if (*pos == ch) {
return true;
}
do {
if (*pos == 0 && !rebuffer()) {
return false;
}
} while (*++pos != ch);
return true;
}
class Scanner {
bool rebuffer() { return FastIn::rebuffer(); }
public:
Scanner(FILE *fin = stdin) {
FastIn::fin = fin;
endbuf = pos + std::fread(buf, 1, BUF_SIZE, fin);
}
template <class T> inline bool scan(T &in) { return FastIn::scan(in); }
template <class First, class... Rest>
inline bool scan(First &in, Rest &...ins) {
return scan(in) && scan(ins...);
}
};
} // namespace FastIn
/* kokomade */
int main() {
using namespace std;
FastIn::Scanner in;
unsigned long N;
in.scan(N);
vector<unsigned long> perm(N);
{
vector<pair<long, long>> p(N);
for (auto &i : p)
in.scan(i.first, i.second);
sort(p.begin(), p.end());
iota(perm.begin(), perm.end(), 0UL);
sort(perm.begin(), perm.end(),
[&p](auto i, auto j) { return p[i].second < p[j].second; });
}
constexpr unsigned long MOD = 998244353;
vector<unsigned long> binary(N + 1);
binary[0] = 1;
for (unsigned long i = 0; i < N; ++i)
binary[i + 1] = binary[i] * 2 - (binary[i] > 499122176) * MOD;
vector<unsigned long> fenwick_tree(N);
auto que = [&fenwick_tree, &N](unsigned long i) {
unsigned long r = i;
unsigned long ret{fenwick_tree[i]};
while (i &= i + 1)
ret += fenwick_tree[--i];
i = r;
while (i < N) {
++fenwick_tree[i];
i |= i + 1;
}
return ret;
};
vector<unsigned long> coef(N + 1);
for (unsigned long i = 0; i < N; ++i) {
auto q = que(perm[i]);
++coef[q];
++coef[i - q];
++coef[perm[i] - q];
++coef[N - i - perm[i] + q - 1];
}
cout << inner_product(binary.begin(), binary.end(), coef.begin(),
(N + MOD - 4) * (binary[N] - 1)) %
MOD
<< endl;
return 0;
} | replace | 144 | 145 | 144 | 145 | 0 | |
p02956 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
vector<ll> compress(vector<ll> &vec) {
vector<ll> v = vec;
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
vector<ll> ret;
rep(i, vec.size()) {
ret.push_back(find(v.begin(), v.end(), vec[i]) - v.begin());
}
return ret;
}
#define MAX_N (1 << 18) // 260000
template <typename T> struct segtree {
int n;
T dat[2 * MAX_N - 1];
T cnt[2 * MAX_N - 1];
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = 0;
}
void update(int k, T a) {
k += n - 1;
dat[k] += a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = dat[k * 2 + 1] + dat[k * 2 + 2];
}
}
//(a,b,0,0,seg.n)で呼ぶ
T query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return 0;
if (a <= l && r <= b)
return dat[k];
else {
T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return vl + vr;
}
}
};
int n;
vector<ll> X, Y;
vector<ll> x, y;
vector<pl> p;
segtree<ll> seg;
ll block[200000][4];
ll po2[200001];
int main() {
cin >> n;
po2[0] = 1;
for (int i = 1; i <= n; i++)
po2[i] = po2[i - 1] * 2 % MOD;
rep(i, n) {
ll tx, ty;
cin >> tx >> ty;
X.push_back(tx);
Y.push_back(ty);
}
x = compress(X);
y = compress(Y);
rep(i, n) p.push_back(pl(y[i], x[i]));
sort(p.begin(), p.end());
seg.init(p.size());
rep(i, p.size()) {
block[i][0] = seg.query(0, p[i].second, 0, 0, seg.n);
block[i][1] = i - block[i][0];
seg.update(p[i].second, 1);
}
reverse(p.begin(), p.end());
seg.init(p.size());
rep(i, p.size()) {
block[p.size() - 1 - i][3] = seg.query(0, p[i].second, 0, 0, seg.n);
block[p.size() - 1 - i][2] = i - block[p.size() - 1 - i][3];
seg.update(p[i].second, 1);
}
ll ans = 0;
rep(i, n) {
ll add = po2[n] - 1;
rep(j, 4) add =
(add - po2[block[i][j] + block[i][(j + 1) % 4]] + 1 + 2 * MOD) % MOD;
rep(j, 4) add = (add + (po2[block[i][j]] - 1)) % MOD;
(ans += add) %= MOD;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
vector<ll> compress(vector<ll> &vec) {
vector<ll> v = vec;
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
vector<ll> ret;
rep(i, vec.size()) {
ret.push_back(lower_bound(v.begin(), v.end(), vec[i]) - v.begin());
}
return ret;
}
#define MAX_N (1 << 18) // 260000
template <typename T> struct segtree {
int n;
T dat[2 * MAX_N - 1];
T cnt[2 * MAX_N - 1];
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = 0;
}
void update(int k, T a) {
k += n - 1;
dat[k] += a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = dat[k * 2 + 1] + dat[k * 2 + 2];
}
}
//(a,b,0,0,seg.n)で呼ぶ
T query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return 0;
if (a <= l && r <= b)
return dat[k];
else {
T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return vl + vr;
}
}
};
int n;
vector<ll> X, Y;
vector<ll> x, y;
vector<pl> p;
segtree<ll> seg;
ll block[200000][4];
ll po2[200001];
int main() {
cin >> n;
po2[0] = 1;
for (int i = 1; i <= n; i++)
po2[i] = po2[i - 1] * 2 % MOD;
rep(i, n) {
ll tx, ty;
cin >> tx >> ty;
X.push_back(tx);
Y.push_back(ty);
}
x = compress(X);
y = compress(Y);
rep(i, n) p.push_back(pl(y[i], x[i]));
sort(p.begin(), p.end());
seg.init(p.size());
rep(i, p.size()) {
block[i][0] = seg.query(0, p[i].second, 0, 0, seg.n);
block[i][1] = i - block[i][0];
seg.update(p[i].second, 1);
}
reverse(p.begin(), p.end());
seg.init(p.size());
rep(i, p.size()) {
block[p.size() - 1 - i][3] = seg.query(0, p[i].second, 0, 0, seg.n);
block[p.size() - 1 - i][2] = i - block[p.size() - 1 - i][3];
seg.update(p[i].second, 1);
}
ll ans = 0;
rep(i, n) {
ll add = po2[n] - 1;
rep(j, 4) add =
(add - po2[block[i][j] + block[i][(j + 1) % 4]] + 1 + 2 * MOD) % MOD;
rep(j, 4) add = (add + (po2[block[i][j]] - 1)) % MOD;
(ans += add) %= MOD;
}
cout << ans << endl;
} | replace | 19 | 20 | 19 | 20 | TLE | |
p02956 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define repn(i, a, n) for (int(i) = (a); (i) < (int)(n); (i)++)
#define EQ(a, b) (abs((a) - (b)) < eps)
template <class T> void chmin(T &a, const T &b) {
if (a > b)
a = b;
}
template <class T> void chmax(T &a, const T &b) {
if (a < b)
a = b;
}
#define MOD 998244353ll // prime
// How to devide :
// ModInt a(6ll);
// ModInt b(2ll);
// a *= b.exp(MOD-2ll); -> a/=b; result: a = 3
struct ModInt {
ll val;
ModInt() : val(0ll) {}
ModInt(ll v) : val(((v % MOD) + MOD) % MOD) {}
ModInt exp(ll y) const {
if (!y)
return ModInt(1ll);
ModInt a = exp(y / 2ll);
a *= a;
if (y & 1)
a *= (*this);
return a;
}
bool operator==(const ModInt &x) const { return val == x.val; }
inline bool operator!=(const ModInt &x) const { return !(*this == x); }
bool operator<(const ModInt &x) const { return val < x.val; }
bool operator>(const ModInt &x) const { return val > x.val; }
inline bool operator>=(const ModInt &x) const { return !(*this < x); }
inline bool operator<=(const ModInt &x) const { return !(*this > x); }
ModInt &operator+=(const ModInt &x) {
if ((val += x.val) >= MOD)
val -= MOD;
return *this;
}
ModInt &operator-=(const ModInt &x) {
if ((val += MOD - x.val) >= MOD)
val -= MOD;
return *this;
}
ModInt &operator*=(const ModInt &x) {
(val *= x.val) %= MOD;
return *this;
}
ModInt operator+(const ModInt &x) const { return ModInt(*this) += x; }
ModInt operator-(const ModInt &x) const { return ModInt(*this) -= x; }
ModInt operator*(const ModInt &x) const { return ModInt(*this) *= x; }
};
istream &operator>>(istream &i, ModInt &x) {
i >> x.val;
return i;
}
ostream &operator<<(ostream &o, const ModInt &x) {
o << x.val;
return o;
}
ModInt pow(ModInt a, ll x) {
ModInt res = ModInt(1ll);
while (x) {
if (x & 1)
res *= a;
x >>= 1;
a = a * a;
}
return res;
}
const int SIZE = 1 << 4;
ModInt inv[SIZE + 10], fac[SIZE + 10], facinv[SIZE + 10];
// notice: 0C0 = 1
ModInt nCr(int n, int r) {
assert(!(n < r));
assert(!(n < 0 || r < 0));
return fac[n] * facinv[r] * facinv[n - r];
}
void init() {
fac[0] = ModInt(1ll);
for (int i = 1; i <= SIZE; i++)
fac[i] = fac[i - 1] * ModInt(i);
inv[1] = ModInt(1ll);
for (int i = 2; i <= SIZE; i++)
inv[i] = ModInt(0ll) - ModInt(MOD / i) * inv[MOD % i];
facinv[0] = ModInt(1ll);
for (int i = 1; i <= SIZE; i++)
facinv[i] = facinv[i - 1] * inv[i];
return;
}
void dump(vector<int> &vec) {
for (int i = 0; i < vec.size(); i++) {
cout << vec[i] << ' ';
}
cout << endl;
}
struct segtree {
vector<int> seg[SIZE * 2];
void init() {
for (int i = SIZE - 1; i >= 0; i--) {
merge(all(seg[i * 2 + 1]), all(seg[i * 2 + 2]), back_inserter(seg[i]));
// cout << i << " : ";
// dump(seg[i]);
}
}
int query(int a, int b, int k, int l, int r, int y) {
if (a <= l && r <= b) {
return (lower_bound(all(seg[k]), y) - seg[k].begin());
} else if (r <= a || b <= l) {
return 0;
} else {
int lch = query(a, b, k * 2 + 1, l, (l + r) / 2, y);
int rch = query(a, b, k * 2 + 2, (l + r) / 2, r, y);
return lch + rch;
}
}
int query2(int a, int b, int k, int l, int r, int y) {
if (a <= l && r <= b) {
return seg[k].size() - (lower_bound(all(seg[k]), y) - seg[k].begin());
} else if (r <= a || b <= l) {
return 0;
} else {
int lch = query2(a, b, k * 2 + 1, l, (l + r) / 2, y);
int rch = query2(a, b, k * 2 + 2, (l + r) / 2, r, y);
return lch + rch;
}
}
} seg;
int N;
P p[200100];
vector<int> xz, yz;
int main() {
// init();
cin >> N;
for (int i = 0; i < N; i++) {
cin >> p[i].fi >> p[i].sec;
xz.pb(p[i].fi);
yz.pb(p[i].sec);
}
sort(all(xz));
sort(all(yz));
xz.erase(unique(all(xz)), xz.end());
yz.erase(unique(all(yz)), yz.end());
for (int i = 0; i < N; i++) {
p[i].fi = lower_bound(all(xz), p[i].fi) - xz.begin();
p[i].sec = lower_bound(all(yz), p[i].sec) - yz.begin();
// cout << p[i].fi << ' ' << p[i].sec << endl;
}
for (int i = 0; i < N; i++) {
seg.seg[p[i].fi + SIZE - 1].pb(p[i].sec);
}
seg.init();
ModInt ans;
ModInt one = ModInt(1ll);
for (int i = 0; i < N; i++) {
vector<int> v;
v.pb(seg.query(0, p[i].fi, 0, 0, SIZE, p[i].sec));
v.pb(seg.query(p[i].fi + 1, N, 0, 0, SIZE, p[i].sec));
v.pb(seg.query2(0, p[i].fi, 0, 0, SIZE, p[i].sec));
v.pb(seg.query2(p[i].fi + 1, N, 0, 0, SIZE, p[i].sec));
// for(int i=0;i<4;i++){
// cout << v[i] << ' ';
// }
// cout << endl;
ModInt base = pow(ModInt(2ll), N - 1);
ans += base;
// cout << base << endl;
for (int j = 0; j < (1 << 4); j++) {
ModInt ret = one;
for (int k = 0; k < 4; k++) {
if ((j >> k) & 1) {
ret *= pow(ModInt(2ll), v[k]) - one;
}
}
if ((j & 9) == 9 || (j & 6) == 6) {
ans += ret;
// cout << ret << endl;
}
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define repn(i, a, n) for (int(i) = (a); (i) < (int)(n); (i)++)
#define EQ(a, b) (abs((a) - (b)) < eps)
template <class T> void chmin(T &a, const T &b) {
if (a > b)
a = b;
}
template <class T> void chmax(T &a, const T &b) {
if (a < b)
a = b;
}
#define MOD 998244353ll // prime
// How to devide :
// ModInt a(6ll);
// ModInt b(2ll);
// a *= b.exp(MOD-2ll); -> a/=b; result: a = 3
struct ModInt {
ll val;
ModInt() : val(0ll) {}
ModInt(ll v) : val(((v % MOD) + MOD) % MOD) {}
ModInt exp(ll y) const {
if (!y)
return ModInt(1ll);
ModInt a = exp(y / 2ll);
a *= a;
if (y & 1)
a *= (*this);
return a;
}
bool operator==(const ModInt &x) const { return val == x.val; }
inline bool operator!=(const ModInt &x) const { return !(*this == x); }
bool operator<(const ModInt &x) const { return val < x.val; }
bool operator>(const ModInt &x) const { return val > x.val; }
inline bool operator>=(const ModInt &x) const { return !(*this < x); }
inline bool operator<=(const ModInt &x) const { return !(*this > x); }
ModInt &operator+=(const ModInt &x) {
if ((val += x.val) >= MOD)
val -= MOD;
return *this;
}
ModInt &operator-=(const ModInt &x) {
if ((val += MOD - x.val) >= MOD)
val -= MOD;
return *this;
}
ModInt &operator*=(const ModInt &x) {
(val *= x.val) %= MOD;
return *this;
}
ModInt operator+(const ModInt &x) const { return ModInt(*this) += x; }
ModInt operator-(const ModInt &x) const { return ModInt(*this) -= x; }
ModInt operator*(const ModInt &x) const { return ModInt(*this) *= x; }
};
istream &operator>>(istream &i, ModInt &x) {
i >> x.val;
return i;
}
ostream &operator<<(ostream &o, const ModInt &x) {
o << x.val;
return o;
}
ModInt pow(ModInt a, ll x) {
ModInt res = ModInt(1ll);
while (x) {
if (x & 1)
res *= a;
x >>= 1;
a = a * a;
}
return res;
}
const int SIZE = 1 << 18;
ModInt inv[SIZE + 10], fac[SIZE + 10], facinv[SIZE + 10];
// notice: 0C0 = 1
ModInt nCr(int n, int r) {
assert(!(n < r));
assert(!(n < 0 || r < 0));
return fac[n] * facinv[r] * facinv[n - r];
}
void init() {
fac[0] = ModInt(1ll);
for (int i = 1; i <= SIZE; i++)
fac[i] = fac[i - 1] * ModInt(i);
inv[1] = ModInt(1ll);
for (int i = 2; i <= SIZE; i++)
inv[i] = ModInt(0ll) - ModInt(MOD / i) * inv[MOD % i];
facinv[0] = ModInt(1ll);
for (int i = 1; i <= SIZE; i++)
facinv[i] = facinv[i - 1] * inv[i];
return;
}
void dump(vector<int> &vec) {
for (int i = 0; i < vec.size(); i++) {
cout << vec[i] << ' ';
}
cout << endl;
}
struct segtree {
vector<int> seg[SIZE * 2];
void init() {
for (int i = SIZE - 1; i >= 0; i--) {
merge(all(seg[i * 2 + 1]), all(seg[i * 2 + 2]), back_inserter(seg[i]));
// cout << i << " : ";
// dump(seg[i]);
}
}
int query(int a, int b, int k, int l, int r, int y) {
if (a <= l && r <= b) {
return (lower_bound(all(seg[k]), y) - seg[k].begin());
} else if (r <= a || b <= l) {
return 0;
} else {
int lch = query(a, b, k * 2 + 1, l, (l + r) / 2, y);
int rch = query(a, b, k * 2 + 2, (l + r) / 2, r, y);
return lch + rch;
}
}
int query2(int a, int b, int k, int l, int r, int y) {
if (a <= l && r <= b) {
return seg[k].size() - (lower_bound(all(seg[k]), y) - seg[k].begin());
} else if (r <= a || b <= l) {
return 0;
} else {
int lch = query2(a, b, k * 2 + 1, l, (l + r) / 2, y);
int rch = query2(a, b, k * 2 + 2, (l + r) / 2, r, y);
return lch + rch;
}
}
} seg;
int N;
P p[200100];
vector<int> xz, yz;
int main() {
// init();
cin >> N;
for (int i = 0; i < N; i++) {
cin >> p[i].fi >> p[i].sec;
xz.pb(p[i].fi);
yz.pb(p[i].sec);
}
sort(all(xz));
sort(all(yz));
xz.erase(unique(all(xz)), xz.end());
yz.erase(unique(all(yz)), yz.end());
for (int i = 0; i < N; i++) {
p[i].fi = lower_bound(all(xz), p[i].fi) - xz.begin();
p[i].sec = lower_bound(all(yz), p[i].sec) - yz.begin();
// cout << p[i].fi << ' ' << p[i].sec << endl;
}
for (int i = 0; i < N; i++) {
seg.seg[p[i].fi + SIZE - 1].pb(p[i].sec);
}
seg.init();
ModInt ans;
ModInt one = ModInt(1ll);
for (int i = 0; i < N; i++) {
vector<int> v;
v.pb(seg.query(0, p[i].fi, 0, 0, SIZE, p[i].sec));
v.pb(seg.query(p[i].fi + 1, N, 0, 0, SIZE, p[i].sec));
v.pb(seg.query2(0, p[i].fi, 0, 0, SIZE, p[i].sec));
v.pb(seg.query2(p[i].fi + 1, N, 0, 0, SIZE, p[i].sec));
// for(int i=0;i<4;i++){
// cout << v[i] << ' ';
// }
// cout << endl;
ModInt base = pow(ModInt(2ll), N - 1);
ans += base;
// cout << base << endl;
for (int j = 0; j < (1 << 4); j++) {
ModInt ret = one;
for (int k = 0; k < 4; k++) {
if ((j >> k) & 1) {
ret *= pow(ModInt(2ll), v[k]) - one;
}
}
if ((j & 9) == 9 || (j & 6) == 6) {
ans += ret;
// cout << ret << endl;
}
}
}
cout << ans << endl;
return 0;
}
| replace | 86 | 87 | 86 | 87 | 0 | |
p02956 | C++ | Runtime Error | #include <bits/stdc++.h>
// using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i, j, n) for (ll i = (ll)(j); i < (ll)(n); i++)
#define REP(i, j, n) for (ll i = (ll)(j); i <= (ll)(n); i++)
#define per(i, j, n) for (ll i = (ll)(j); (ll)(n) <= i; i--)
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (ll)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (ll)(key)))
#define pb emplace_back
#define mp std::make_pair
// #define endl "\n"
using std::cin;
using std::cout;
using std::endl;
using std::lower_bound;
using std::string;
using std::upper_bound;
using std::vector;
using vi = vector<ll>;
using vii = vector<vi>;
using pii = std::pair<ll, ll>;
// constexpr ll MOD=1e9+7;
constexpr ll MOD = 998244353;
// constexpr ll MOD=10000000;
constexpr ll MAX = 1e7;
constexpr ll INF = (1ll << 60);
template <class T>
class prique : public std::priority_queue<T, std::vector<T>, std::greater<T>> {
};
struct Binary_indexed_tree {
int N;
vi bit;
Binary_indexed_tree(int n) : N(n) { bit.resize(N + 1, 0); }
void add(int x, int a) {
for (x; x <= N; x += (x & -x))
bit[x] += a;
}
ll sum(int x) {
ll ret = 0;
for (x; x > 0; x -= (x & -x))
ret += bit[x];
return ret;
}
ll lower_bound(ll X) {
if (sum(N) < X)
return -1;
ll ret = 0, memo = 1, sum = 0;
while (memo * 2 <= N)
memo *= 2;
while (memo > 0) {
if (memo + ret <= N && sum + bit[memo + ret] < X) {
sum += bit[memo + ret];
ret += memo;
}
memo /= 2;
}
return ret + 1;
}
};
struct Union_Find {
ll N;
vi par;
vi siz;
Union_Find(int n) : N(n) {
par.resize(N);
siz.resize(N, 1);
rep(i, 0, N) par[i] = i;
}
ll root(ll X) {
if (par[X] == X)
return X;
return par[X] = root(par[X]);
}
bool same(ll X, ll Y) { return root(X) == root(Y); }
void unite(ll X, ll Y) {
X = root(X);
Y = root(Y);
if (X == Y)
return;
par[X] = Y;
siz[Y] += siz[X];
siz[X] = 0;
}
ll size(ll X) { return siz[root(X)]; }
};
ll modpow(ll X, ll Y, ll mod) {
ll sum = X, cnt = 1;
vi A;
while (cnt <= Y) {
A.pb(sum);
sum *= sum;
sum %= mod;
cnt *= 2;
}
int M = A.size();
ll ret = 1;
REP(i, 1, M) {
if (Y >= (1ll << M - i)) {
Y -= (1ll << M - i);
ret *= A[M - i];
ret %= mod;
}
}
return ret;
}
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll COM(ll n, ll r) {
if (n < r || n < 0 || r < 0)
return 0;
return fac[n] * finv[r] % MOD * finv[n - r] % MOD;
}
template <typename T> struct BIT2D {
int H, W;
vector<vector<T>> bit; // データの格納先
BIT2D(int H_, int W_) { init(H_, W_); }
void init(int H_, int W_) {
H = H_ + 1;
W = W_ + 1;
bit.assign(H, vector<T>(W, 0));
}
void add(int h, int w, T x) {
for (int i = h; i < H; i += (i & -i)) {
for (int j = w; j < W; j += (j & -j)) {
bit[i][j] += x;
}
}
}
// 1≦i≦h かつ 1≦j≦w
T sum(int h, int w) {
T s(0);
for (int i = h; i > 0; i -= (i & -i)) {
for (int j = w; j > 0; j -= (j & -j)) {
s += bit[i][j];
}
}
return s;
}
// h1≦i<h2 かつ w1≦j<w2
T query(int h1, int w1, int h2, int w2) {
return sum(h2, w2) - sum(h2, w1 - 1) - sum(h1 - 1, w2) +
sum(h1 - 1, w1 - 1);
}
};
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int N;
cin >> N;
std::map<int, int> x, y;
std::set<int> p, q;
vi A(N), B(N);
rep(i, 0, N) {
cin >> A[i] >> B[i];
p.insert(A[i]);
q.insert(B[i]);
}
ll X = p.size() + 1, Y = q.size() + 1;
int cnt = 0;
for (auto a : p)
x[a] = ++cnt;
cnt = 0;
for (auto a : q)
y[a] = ++cnt;
Binary_indexed_tree BIT(Y);
vii m(X);
rep(i, 0, N) { m[x[A[i]]].pb(y[B[i]]); }
ll ans = 0;
vii memo(N, vi(9));
cnt = 0;
REP(i, 0, X) {
ll q = cnt;
rep(j, 0, m[i].size()) {
ll p = m[i][j];
memo[q][0] = BIT.sum(p - 1);
memo[q][3] = BIT.sum(p) - memo[q][0];
memo[q][6] = BIT.sum(Y) - memo[q][0] - memo[q][3];
q++;
}
rep(j, 0, m[i].size()) {
ll p = m[i][j];
BIT.add(p, 1);
}
rep(j, 0, m[i].size()) {
ll p = m[i][j];
memo[cnt][1] = BIT.sum(p - 1) - memo[cnt][0];
memo[cnt][4] = BIT.sum(p) - memo[cnt][0] - memo[cnt][1] - memo[cnt][3];
memo[cnt][7] = BIT.sum(Y) - memo[cnt][0] - memo[cnt][3] - memo[cnt][1] -
memo[cnt][4] - memo[cnt][6];
cnt++;
}
}
cnt = 0;
REP(i, 0, X) {
rep(j, 0, m[i].size()) {
ll p = m[i][j];
memo[cnt][2] = BIT.sum(p - 1) - memo[cnt][0] - memo[cnt][1];
memo[cnt][5] = BIT.sum(p) - memo[cnt][0] - memo[cnt][1] - memo[cnt][3] -
memo[cnt][2] - memo[cnt][4];
memo[cnt][8] = BIT.sum(Y) - memo[cnt][0] - memo[cnt][3] - memo[cnt][1] -
memo[cnt][4] - memo[cnt][6] - memo[cnt][2] - memo[cnt][5] -
memo[cnt][7];
cnt++;
}
}
rep(i, 0, N) {
ans += modpow(2, N, MOD) - 1;
vi P = memo[i];
ans -= modpow(2, P[0] + P[3] + P[6], MOD) - 1;
ans -= modpow(2, P[2] + P[5] + P[8], MOD) - 1;
ans -= modpow(2, P[0] + P[1] + P[2], MOD) - 1;
ans += modpow(2, P[0], MOD) - 1;
ans += modpow(2, P[2], MOD) - 1;
ans -= modpow(2, P[6] + P[7] + P[8], MOD) - 1;
ans += modpow(2, P[6], MOD) - 1;
ans += modpow(2, P[8], MOD) - 1;
ans %= MOD;
if (ans < 0)
ans += MOD;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
// using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i, j, n) for (ll i = (ll)(j); i < (ll)(n); i++)
#define REP(i, j, n) for (ll i = (ll)(j); i <= (ll)(n); i++)
#define per(i, j, n) for (ll i = (ll)(j); (ll)(n) <= i; i--)
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (ll)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (ll)(key)))
#define pb emplace_back
#define mp std::make_pair
// #define endl "\n"
using std::cin;
using std::cout;
using std::endl;
using std::lower_bound;
using std::string;
using std::upper_bound;
using std::vector;
using vi = vector<ll>;
using vii = vector<vi>;
using pii = std::pair<ll, ll>;
// constexpr ll MOD=1e9+7;
constexpr ll MOD = 998244353;
// constexpr ll MOD=10000000;
constexpr ll MAX = 1e7;
constexpr ll INF = (1ll << 60);
template <class T>
class prique : public std::priority_queue<T, std::vector<T>, std::greater<T>> {
};
struct Binary_indexed_tree {
int N;
vi bit;
Binary_indexed_tree(int n) : N(n) { bit.resize(N + 1, 0); }
void add(int x, int a) {
for (x; x <= N; x += (x & -x))
bit[x] += a;
}
ll sum(int x) {
ll ret = 0;
for (x; x > 0; x -= (x & -x))
ret += bit[x];
return ret;
}
ll lower_bound(ll X) {
if (sum(N) < X)
return -1;
ll ret = 0, memo = 1, sum = 0;
while (memo * 2 <= N)
memo *= 2;
while (memo > 0) {
if (memo + ret <= N && sum + bit[memo + ret] < X) {
sum += bit[memo + ret];
ret += memo;
}
memo /= 2;
}
return ret + 1;
}
};
struct Union_Find {
ll N;
vi par;
vi siz;
Union_Find(int n) : N(n) {
par.resize(N);
siz.resize(N, 1);
rep(i, 0, N) par[i] = i;
}
ll root(ll X) {
if (par[X] == X)
return X;
return par[X] = root(par[X]);
}
bool same(ll X, ll Y) { return root(X) == root(Y); }
void unite(ll X, ll Y) {
X = root(X);
Y = root(Y);
if (X == Y)
return;
par[X] = Y;
siz[Y] += siz[X];
siz[X] = 0;
}
ll size(ll X) { return siz[root(X)]; }
};
ll modpow(ll X, ll Y, ll mod) {
ll sum = X, cnt = 1;
vi A;
while (cnt <= Y) {
A.pb(sum);
sum *= sum;
sum %= mod;
cnt *= 2;
}
int M = A.size();
ll ret = 1;
REP(i, 1, M) {
if (Y >= (1ll << M - i)) {
Y -= (1ll << M - i);
ret *= A[M - i];
ret %= mod;
}
}
return ret;
}
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll COM(ll n, ll r) {
if (n < r || n < 0 || r < 0)
return 0;
return fac[n] * finv[r] % MOD * finv[n - r] % MOD;
}
template <typename T> struct BIT2D {
int H, W;
vector<vector<T>> bit; // データの格納先
BIT2D(int H_, int W_) { init(H_, W_); }
void init(int H_, int W_) {
H = H_ + 1;
W = W_ + 1;
bit.assign(H, vector<T>(W, 0));
}
void add(int h, int w, T x) {
for (int i = h; i < H; i += (i & -i)) {
for (int j = w; j < W; j += (j & -j)) {
bit[i][j] += x;
}
}
}
// 1≦i≦h かつ 1≦j≦w
T sum(int h, int w) {
T s(0);
for (int i = h; i > 0; i -= (i & -i)) {
for (int j = w; j > 0; j -= (j & -j)) {
s += bit[i][j];
}
}
return s;
}
// h1≦i<h2 かつ w1≦j<w2
T query(int h1, int w1, int h2, int w2) {
return sum(h2, w2) - sum(h2, w1 - 1) - sum(h1 - 1, w2) +
sum(h1 - 1, w1 - 1);
}
};
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int N;
cin >> N;
std::map<int, int> x, y;
std::set<int> p, q;
vi A(N), B(N);
rep(i, 0, N) {
cin >> A[i] >> B[i];
p.insert(A[i]);
q.insert(B[i]);
}
ll X = p.size() + 1, Y = q.size() + 1;
int cnt = 0;
for (auto a : p)
x[a] = ++cnt;
cnt = 0;
for (auto a : q)
y[a] = ++cnt;
Binary_indexed_tree BIT(Y);
vii m(X + 1);
rep(i, 0, N) { m[x[A[i]]].pb(y[B[i]]); }
ll ans = 0;
vii memo(N, vi(9));
cnt = 0;
REP(i, 0, X) {
ll q = cnt;
rep(j, 0, m[i].size()) {
ll p = m[i][j];
memo[q][0] = BIT.sum(p - 1);
memo[q][3] = BIT.sum(p) - memo[q][0];
memo[q][6] = BIT.sum(Y) - memo[q][0] - memo[q][3];
q++;
}
rep(j, 0, m[i].size()) {
ll p = m[i][j];
BIT.add(p, 1);
}
rep(j, 0, m[i].size()) {
ll p = m[i][j];
memo[cnt][1] = BIT.sum(p - 1) - memo[cnt][0];
memo[cnt][4] = BIT.sum(p) - memo[cnt][0] - memo[cnt][1] - memo[cnt][3];
memo[cnt][7] = BIT.sum(Y) - memo[cnt][0] - memo[cnt][3] - memo[cnt][1] -
memo[cnt][4] - memo[cnt][6];
cnt++;
}
}
cnt = 0;
REP(i, 0, X) {
rep(j, 0, m[i].size()) {
ll p = m[i][j];
memo[cnt][2] = BIT.sum(p - 1) - memo[cnt][0] - memo[cnt][1];
memo[cnt][5] = BIT.sum(p) - memo[cnt][0] - memo[cnt][1] - memo[cnt][3] -
memo[cnt][2] - memo[cnt][4];
memo[cnt][8] = BIT.sum(Y) - memo[cnt][0] - memo[cnt][3] - memo[cnt][1] -
memo[cnt][4] - memo[cnt][6] - memo[cnt][2] - memo[cnt][5] -
memo[cnt][7];
cnt++;
}
}
rep(i, 0, N) {
ans += modpow(2, N, MOD) - 1;
vi P = memo[i];
ans -= modpow(2, P[0] + P[3] + P[6], MOD) - 1;
ans -= modpow(2, P[2] + P[5] + P[8], MOD) - 1;
ans -= modpow(2, P[0] + P[1] + P[2], MOD) - 1;
ans += modpow(2, P[0], MOD) - 1;
ans += modpow(2, P[2], MOD) - 1;
ans -= modpow(2, P[6] + P[7] + P[8], MOD) - 1;
ans += modpow(2, P[6], MOD) - 1;
ans += modpow(2, P[8], MOD) - 1;
ans %= MOD;
if (ans < 0)
ans += MOD;
}
cout << ans << endl;
}
| replace | 181 | 182 | 181 | 182 | -11 | |
p02956 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using ll = long long int;
using P = std::pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rag(con) std::begin(con), std::end(con)
constexpr ll mod = 998244353;
ll pow(ll x, ll m) {
ll re = 1, y = 1;
for (int i = 0; i < 60; ++i) {
if (m & y)
re = re * x % mod;
x = x * x % mod;
y *= 2;
}
return re;
}
ll inv(ll x) { return pow(x, mod - 2); }
class mint {
ll num = 0;
public:
mint(ll x = 0) : num(x) {}
mint operator+(const mint &rhs) const { return (num + rhs.num) % mod; }
mint operator*(const mint &rhs) const { return num * rhs.num % mod; }
mint operator-(const mint &rhs) const { return (num - rhs.num + mod) % mod; }
mint operator/(const mint &rhs) const { return num * inv(rhs.num) % mod; }
mint operator+=(const mint &rhs) { return *this = *this + rhs; }
mint operator*=(const mint &rhs) { return *this = *this * rhs; }
mint operator-=(const mint &rhs) { return *this = *this - rhs; }
mint operator/=(const mint &rhs) { return *this = *this / rhs; }
friend std::ostream &operator<<(std::ostream &os, const mint &rhs);
};
std::ostream &operator<<(std::ostream &os, const mint &rhs) {
os << rhs.num;
return os;
}
int m;
std::vector<ll> node;
void debug() {
int x = 0;
rep(i, 2 * m - 1) {
std::cerr << node[i] << ' ';
if (x == i) {
std::cerr << std::endl;
x = x * 2 + 2;
}
}
}
void init(int n) {
m = 1;
while (m < n)
m *= 2;
node.resize(m * 2 - 1);
}
void add(int y) {
y += m - 1;
node[y]++;
while (y > 0) {
y = (y - 1) / 2;
node[y]++;
}
}
int get(int a, int b, int k = 0, int l = 0, int r = m) {
if (r <= a || b <= l)
return 0;
if (a <= l && r <= b)
return node[k];
int lv = get(a, b, 2 * k + 1, l, (l + r) / 2);
int rv = get(a, b, 2 * k + 2, (l + r) / 2, r);
return lv + rv;
}
int main() {
int n;
std::cin >> n;
init(n);
std::vector<P> vec;
std::vector<int> xs, ys;
rep(i, n) {
int x, y;
std::cin >> x >> y;
xs.push_back(x);
ys.push_back(y);
vec.emplace_back(x, y);
}
std::sort(rag(xs));
std::sort(rag(ys));
rep(i, n) {
vec[i].first = std::lower_bound(rag(xs), vec[i].first) - std::begin(xs);
vec[i].second = std::lower_bound(rag(ys), vec[i].second) - std::begin(ys);
}
std::sort(rag(vec));
std::vector<int> a(n), b(n), c(n), d(n);
// std::cerr << "A&C" << std::endl;
rep(i, n) {
int ny = vec[i].second;
a[i] = get(ny + 1, n);
c[i] = get(0, ny);
add(ny);
// std::cerr << i << std::endl;
// debug();
}
rep(i, 2 * m - 1) node[i] = 0;
// std::cerr << "B&D" << std::endl;
for (int i = n - 1; i >= 0; --i) {
int ny = vec[i].second;
b[i] = get(ny + 1, n);
d[i] = get(0, ny);
add(ny);
// debug();
}
// std::cerr << "DEBUG" << std::endl;
rep(i, n) {
std::cerr << a[i] << ' ' << b[i] << ' ' << c[i] << ' ' << d[i] << std::endl;
}
mint ans = 0;
std::vector<mint> p2(n + 1);
p2[0] = 1;
rep(i, n) { p2[i + 1] = p2[i] * 2; }
rep(i, n) {
ans += p2[n] - 1 + p2[a[i]] + p2[b[i]] + p2[c[i]] + p2[d[i]];
ans -=
p2[a[i] + b[i]] + p2[d[i] + b[i]] + p2[d[i] + c[i]] + p2[a[i] + c[i]];
}
std::cout << ans << std::endl;
return 0;
} | #include <bits/stdc++.h>
using ll = long long int;
using P = std::pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rag(con) std::begin(con), std::end(con)
constexpr ll mod = 998244353;
ll pow(ll x, ll m) {
ll re = 1, y = 1;
for (int i = 0; i < 60; ++i) {
if (m & y)
re = re * x % mod;
x = x * x % mod;
y *= 2;
}
return re;
}
ll inv(ll x) { return pow(x, mod - 2); }
class mint {
ll num = 0;
public:
mint(ll x = 0) : num(x) {}
mint operator+(const mint &rhs) const { return (num + rhs.num) % mod; }
mint operator*(const mint &rhs) const { return num * rhs.num % mod; }
mint operator-(const mint &rhs) const { return (num - rhs.num + mod) % mod; }
mint operator/(const mint &rhs) const { return num * inv(rhs.num) % mod; }
mint operator+=(const mint &rhs) { return *this = *this + rhs; }
mint operator*=(const mint &rhs) { return *this = *this * rhs; }
mint operator-=(const mint &rhs) { return *this = *this - rhs; }
mint operator/=(const mint &rhs) { return *this = *this / rhs; }
friend std::ostream &operator<<(std::ostream &os, const mint &rhs);
};
std::ostream &operator<<(std::ostream &os, const mint &rhs) {
os << rhs.num;
return os;
}
int m;
std::vector<ll> node;
void debug() {
int x = 0;
rep(i, 2 * m - 1) {
std::cerr << node[i] << ' ';
if (x == i) {
std::cerr << std::endl;
x = x * 2 + 2;
}
}
}
void init(int n) {
m = 1;
while (m < n)
m *= 2;
node.resize(m * 2 - 1);
}
void add(int y) {
y += m - 1;
node[y]++;
while (y > 0) {
y = (y - 1) / 2;
node[y]++;
}
}
int get(int a, int b, int k = 0, int l = 0, int r = m) {
if (r <= a || b <= l)
return 0;
if (a <= l && r <= b)
return node[k];
int lv = get(a, b, 2 * k + 1, l, (l + r) / 2);
int rv = get(a, b, 2 * k + 2, (l + r) / 2, r);
return lv + rv;
}
int main() {
int n;
std::cin >> n;
init(n);
std::vector<P> vec;
std::vector<int> xs, ys;
rep(i, n) {
int x, y;
std::cin >> x >> y;
xs.push_back(x);
ys.push_back(y);
vec.emplace_back(x, y);
}
std::sort(rag(xs));
std::sort(rag(ys));
rep(i, n) {
vec[i].first = std::lower_bound(rag(xs), vec[i].first) - std::begin(xs);
vec[i].second = std::lower_bound(rag(ys), vec[i].second) - std::begin(ys);
}
std::sort(rag(vec));
std::vector<int> a(n), b(n), c(n), d(n);
// std::cerr << "A&C" << std::endl;
rep(i, n) {
int ny = vec[i].second;
a[i] = get(ny + 1, n);
c[i] = get(0, ny);
add(ny);
// std::cerr << i << std::endl;
// debug();
}
rep(i, 2 * m - 1) node[i] = 0;
// std::cerr << "B&D" << std::endl;
for (int i = n - 1; i >= 0; --i) {
int ny = vec[i].second;
b[i] = get(ny + 1, n);
d[i] = get(0, ny);
add(ny);
// debug();
}
// std::cerr << "DEBUG" << std::endl;
/*rep(i, n)
{
std::cerr << a[i] << ' ' << b[i] << ' ' << c[i] << ' ' << d[i] <<
std::endl;
}*/
mint ans = 0;
std::vector<mint> p2(n + 1);
p2[0] = 1;
rep(i, n) { p2[i + 1] = p2[i] * 2; }
rep(i, n) {
ans += p2[n] - 1 + p2[a[i]] + p2[b[i]] + p2[c[i]] + p2[d[i]];
ans -=
p2[a[i] + b[i]] + p2[d[i] + b[i]] + p2[d[i] + c[i]] + p2[a[i] + c[i]];
}
std::cout << ans << std::endl;
return 0;
} | replace | 156 | 159 | 156 | 161 | TLE | |
p02956 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using Tree =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int MOD = 998244353;
int mul(int a, int b) { return a * 1ll * b % MOD; }
int add(int a, int b) {
a += b;
while (a >= MOD)
a -= MOD;
while (a < 0)
a += MOD;
return a;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
#endif
int n;
cin >> n;
vector<int> r(n), c(n), power(n + 1);
vector<array<int, 2>> p(n);
vector<array<int, 4>> ans(n);
power[0] = 1;
for (int i = 0; i < n; i++) {
cin >> r[i] >> c[i];
p[i] = {r[i], c[i]};
power[i + 1] = mul(power[i], 2);
}
vector<int> ind(n);
iota(ind.begin(), ind.end(), 0);
sort(ind.begin(), ind.end(), [&](int i, int j) { return p[i][0] < p[j][0]; });
sort(r.begin(), r.end());
r.resize(unique(r.begin(), r.end()) - r.begin());
Tree<int> os;
int j = 0;
for (int i = 0; i < r.size(); i++) {
int st = j;
while (j < ind.size() && p[ind[j]][0] == r[i]) {
os.insert(p[ind[j]][1]);
j++;
}
j = st;
while (j < ind.size() && p[ind[j]][0] == r[i]) {
int lf = os.order_of_key(p[ind[j]][1] + 1);
int rt = os.size() - os.order_of_key(p[ind[j]][1]);
ans[ind[j]][2] = lf - 1;
ans[ind[j]][0] = rt - 1;
j++;
}
}
sort(ind.begin(), ind.end(), [&](int i, int j) { return p[i][0] > p[j][0]; });
reverse(r.begin(), r.end());
os.clear();
j = 0;
for (int i = 0; i < r.size(); i++) {
int st = j;
while (j < ind.size() && p[ind[j]][0] == r[i]) {
os.insert(p[ind[j]][1]);
j++;
}
j = st;
while (j < ind.size() && p[ind[j]][0] == r[i]) {
int lf = os.order_of_key(p[ind[j]][1] + 1);
int rt = os.size() - os.order_of_key(p[ind[j]][1]);
ans[ind[j]][3] = lf - 1;
ans[ind[j]][1] = rt - 1;
j++;
}
}
int res = mul(n, power[n - 1]);
for (int i = 0; i < n; i++) {
int a = ans[i][0], b = ans[i][1];
int c = ans[i][2], d = ans[i][3];
res = add(res, mul(mul(power[a] - 1, power[d] - 1), power[c]));
res = add(res, mul(mul(power[a] - 1, power[d] - 1), power[b] - 1));
res = add(res, mul(mul(power[b] - 1, power[c] - 1), power[a]));
res = add(res, mul(mul(power[b] - 1, power[c] - 1), power[d] - 1));
res = add(res, mul(power[a] - 1,
mul(power[b] - 1, mul(power[c] - 1, power[d] - 1))));
}
cout << res;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using Tree =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int MOD = 998244353;
int mul(int a, int b) { return a * 1ll * b % MOD; }
int add(int a, int b) {
a += b;
while (a >= MOD)
a -= MOD;
while (a < 0)
a += MOD;
return a;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n;
cin >> n;
vector<int> r(n), c(n), power(n + 1);
vector<array<int, 2>> p(n);
vector<array<int, 4>> ans(n);
power[0] = 1;
for (int i = 0; i < n; i++) {
cin >> r[i] >> c[i];
p[i] = {r[i], c[i]};
power[i + 1] = mul(power[i], 2);
}
vector<int> ind(n);
iota(ind.begin(), ind.end(), 0);
sort(ind.begin(), ind.end(), [&](int i, int j) { return p[i][0] < p[j][0]; });
sort(r.begin(), r.end());
r.resize(unique(r.begin(), r.end()) - r.begin());
Tree<int> os;
int j = 0;
for (int i = 0; i < r.size(); i++) {
int st = j;
while (j < ind.size() && p[ind[j]][0] == r[i]) {
os.insert(p[ind[j]][1]);
j++;
}
j = st;
while (j < ind.size() && p[ind[j]][0] == r[i]) {
int lf = os.order_of_key(p[ind[j]][1] + 1);
int rt = os.size() - os.order_of_key(p[ind[j]][1]);
ans[ind[j]][2] = lf - 1;
ans[ind[j]][0] = rt - 1;
j++;
}
}
sort(ind.begin(), ind.end(), [&](int i, int j) { return p[i][0] > p[j][0]; });
reverse(r.begin(), r.end());
os.clear();
j = 0;
for (int i = 0; i < r.size(); i++) {
int st = j;
while (j < ind.size() && p[ind[j]][0] == r[i]) {
os.insert(p[ind[j]][1]);
j++;
}
j = st;
while (j < ind.size() && p[ind[j]][0] == r[i]) {
int lf = os.order_of_key(p[ind[j]][1] + 1);
int rt = os.size() - os.order_of_key(p[ind[j]][1]);
ans[ind[j]][3] = lf - 1;
ans[ind[j]][1] = rt - 1;
j++;
}
}
int res = mul(n, power[n - 1]);
for (int i = 0; i < n; i++) {
int a = ans[i][0], b = ans[i][1];
int c = ans[i][2], d = ans[i][3];
res = add(res, mul(mul(power[a] - 1, power[d] - 1), power[c]));
res = add(res, mul(mul(power[a] - 1, power[d] - 1), power[b] - 1));
res = add(res, mul(mul(power[b] - 1, power[c] - 1), power[a]));
res = add(res, mul(mul(power[b] - 1, power[c] - 1), power[d] - 1));
res = add(res, mul(power[a] - 1,
mul(power[b] - 1, mul(power[c] - 1, power[d] - 1))));
}
cout << res;
} | replace | 26 | 29 | 26 | 27 | 0 | |
p02956 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <utility>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
struct mint {
ll x;
mint(ll x = 0) : x(x % MOD) {}
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
const int NMAX = 200010;
template <class X> class BIT {
X bit[NMAX];
int n;
public:
BIT(int N);
X sum(int i);
void add(int i, X x);
};
template <class X> BIT<X>::BIT(int N) {
n = N;
for (int i = 0; i < N; i++) {
bit[i] = 0;
}
}
template <class X> X BIT<X>::sum(int i) { // iまでの和=bit[0]+...+bit[i]
X s = 0;
while (i > 0) {
s += bit[i];
i -= i & (-i); // 最後の1bitを引く(ex.0110なら0010を引く)
}
return s;
}
template <class X> void BIT<X>::add(int i, X x) { // bit[i]+=x
while (i <= n) {
bit[i] += x;
i += i & (-i); // 最後の1bitを足す
}
}
int nn;
pair<int, int> p[200010];
int a[200010], b[200010], c[200010], d[200010];
int main() {
cin >> nn;
rep(i, nn) cin >> p[i].first >> p[i].second;
{
map<int, int> mp;
rep(i, nn) mp[p[i].first] = 0;
int j = 1;
for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
itr->second = j++;
}
rep(i, nn) p[i].first = mp[p[i].first];
}
{
map<int, int> mp;
rep(i, nn) mp[p[i].second] = 0;
int j = 1;
for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
itr->second = j++;
}
rep(i, nn) p[i].second = mp[p[i].second];
}
sort(p, p + nn);
{
BIT<int> bit(nn + 1);
rep(i, nn) {
int pf = p[i].first, ps = p[i].second;
int bb = bit.sum(ps);
int aa = i - bb;
a[pf - 1] = aa;
b[pf - 1] = bb;
bit.add(ps, 1);
}
}
{
BIT<int> bit(nn);
rep(i, nn) {
int pf = p[nn - 1 - i].first, ps = p[nn - 1 - i].second;
int dd = bit.sum(ps);
int cc = i - dd;
c[pf - 1] = cc;
d[pf - 1] = dd;
bit.add(ps, 1);
}
}
mint res;
rep(i, nn) {
ll aa = a[i], bb = b[i], cc = c[i], dd = d[i];
mint two = 2;
res += (two.pow(aa) - 1) * (two.pow(dd) - 1) * (two.pow(bb + cc));
res += (two.pow(bb) - 1) * (two.pow(cc) - 1) * (two.pow(aa + dd));
res -= (two.pow(aa) - 1) * (two.pow(bb) - 1) * (two.pow(cc) - 1) *
(two.pow(dd) - 1);
res += two.pow((ll)nn - 1);
}
cout << res.x << "\n";
return 0;
}
| #include <algorithm>
#include <iostream>
#include <map>
#include <utility>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
struct mint {
ll x;
mint(ll x = 0) : x(x % MOD) {}
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
const int NMAX = 200010;
template <class X> class BIT {
X bit[NMAX];
int n;
public:
BIT(int N);
X sum(int i);
void add(int i, X x);
};
template <class X> BIT<X>::BIT(int N) {
n = N;
for (int i = 0; i < N; i++) {
bit[i] = 0;
}
}
template <class X> X BIT<X>::sum(int i) { // iまでの和=bit[0]+...+bit[i]
X s = 0;
while (i > 0) {
s += bit[i];
i -= i & (-i); // 最後の1bitを引く(ex.0110なら0010を引く)
}
return s;
}
template <class X> void BIT<X>::add(int i, X x) { // bit[i]+=x
while (i <= n) {
bit[i] += x;
i += i & (-i); // 最後の1bitを足す
}
}
int nn;
pair<int, int> p[200010];
int a[200010], b[200010], c[200010], d[200010];
int main() {
cin >> nn;
rep(i, nn) cin >> p[i].first >> p[i].second;
{
map<int, int> mp;
rep(i, nn) mp[p[i].first] = 0;
int j = 1;
for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
itr->second = j++;
}
rep(i, nn) p[i].first = mp[p[i].first];
}
{
map<int, int> mp;
rep(i, nn) mp[p[i].second] = 0;
int j = 1;
for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
itr->second = j++;
}
rep(i, nn) p[i].second = mp[p[i].second];
}
sort(p, p + nn);
{
BIT<int> bit(nn + 1);
rep(i, nn) {
int pf = p[i].first, ps = p[i].second;
int bb = bit.sum(ps);
int aa = i - bb;
a[pf - 1] = aa;
b[pf - 1] = bb;
bit.add(ps, 1);
}
}
{
BIT<int> bit(nn + 1);
rep(i, nn) {
int pf = p[nn - 1 - i].first, ps = p[nn - 1 - i].second;
int dd = bit.sum(ps);
int cc = i - dd;
c[pf - 1] = cc;
d[pf - 1] = dd;
bit.add(ps, 1);
}
}
mint res;
rep(i, nn) {
ll aa = a[i], bb = b[i], cc = c[i], dd = d[i];
mint two = 2;
res += (two.pow(aa) - 1) * (two.pow(dd) - 1) * (two.pow(bb + cc));
res += (two.pow(bb) - 1) * (two.pow(cc) - 1) * (two.pow(aa + dd));
res -= (two.pow(aa) - 1) * (two.pow(bb) - 1) * (two.pow(cc) - 1) *
(two.pow(dd) - 1);
res += two.pow((ll)nn - 1);
}
cout << res.x << "\n";
return 0;
}
| replace | 124 | 125 | 124 | 125 | -11 | |
p02956 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <tuple>
#include <vector>
const long long mod = 998244353;
auto max_bit(int32_t n) {
n = n & 0xFFFF0000 ? n & 0xFFFF0000 : n;
n = n & 0xFF00FF00 ? n & 0xFF00FF00 : n;
n = n & 0xF0F0F0F0 ? n & 0xF0F0F0F0 : n;
n = n & 0xCCCCCCCC ? n & 0xCCCCCCCC : n;
n = n & 0xAAAAAAAA ? n & 0xAAAAAAAA : n;
return n;
}
template <typename T> class Segtree {
int nbin;
const T param_def;
std::vector<T> seg_vec;
std::function<T(T, T)> seg_func;
T query_partial(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return param_def;
if (a <= l && r <= b)
return seg_vec[k];
const T v_l = query_partial(a, b, k * 2 + 1, l, (l + r) / 2);
const T v_r = query_partial(a, b, k * 2 + 2, (l + r) / 2, r);
return seg_func(v_l, v_r);
}
public:
Segtree(const std::vector<T> &data, const std::function<T(T, T)> &_seg_func,
const T _param_def)
: seg_func(_seg_func), param_def(_param_def) {
nbin = max_bit(data.size() - 1) * 2;
seg_vec.resize(nbin * 2 - 1, param_def);
auto insert_top = seg_vec.begin();
insert_top += nbin - 1;
std::copy(data.cbegin(), data.cend(), insert_top);
for (int i = nbin - 2; i >= 0; i--) {
seg_vec[i] = seg_func(seg_vec[i * 2 + 1], seg_vec[i * 2 + 2]);
}
}
T get(int i) { return seg_vec[nbin - 1 + i]; }
void update(int i, int x) {
i += nbin - 1;
seg_vec[i] = x;
while (i > 0) {
i = (i - 1) / 2;
seg_vec[i] = seg_func(seg_vec[i * 2 + 1], seg_vec[i * 2 + 2]);
}
}
T query(int a, int b) { return query_partial(a, b, 0, 0, nbin); }
};
long long mod_pow2(long long n) {
long long ans = 1, np = 2;
while (n > 0) {
if (n & 1)
ans = (ans * np) % mod;
np = (np * np) % mod;
n >>= 1;
}
return ans;
}
int main() {
int N;
std::cin >> N;
std::vector<std::tuple<int, int>> xy_arr;
std::map<int, int> y_map;
for (int i = 0; i < N; i++) {
int x, y;
std::cin >> x >> y;
y_map[y] = 0;
xy_arr.emplace_back(x, y);
}
int ni = 0;
for (auto &&it : y_map) {
it.second = ni;
ni++;
}
std::vector<std::tuple<int, int, int, int>> p_arr(N);
auto f_sum = [](int l, int r) { return l + r; };
Segtree<int> seg1(std::vector<int>(N), f_sum, 0),
seg2(std::vector<int>(N), f_sum, 0);
std::sort(xy_arr.begin(), xy_arr.end());
for (int i = 0; i < N; i++) {
int y2 = y_map[std::get<1>(xy_arr[i])];
std::get<0>(p_arr[i]) = seg1.query(0, y2);
std::get<1>(p_arr[i]) = seg1.query(y2, ni);
seg1.update(y2, 1);
}
std::sort(xy_arr.rbegin(), xy_arr.rend());
for (int i = 0; i < N; i++) {
int y2 = y_map[std::get<1>(xy_arr[i])];
std::get<2>(p_arr[N - 1 - i]) = seg2.query(0, y2);
std::get<3>(p_arr[N - 1 - i]) = seg2.query(y2, ni);
seg2.update(y2, 1);
}
long long ans = 0;
for (int i = 0; i < N; i++) {
long long a, b, c, d;
std::tie(a, b, c, d) = p_arr[i];
long long a2 = mod_pow2(a);
long long b2 = mod_pow2(b);
long long c2 = mod_pow2(c);
long long d2 = mod_pow2(d);
ans += (((((a2 * b2) % mod) * c2) % mod) * d2) % mod;
ans += ((((((a2 - 1) * (d2 - 1)) % mod) * b2) % mod) * c2) % mod;
ans += ((((a2 + d2 - 1) * (b2 - 1)) % mod) * (c2 - 1)) % mod;
ans %= mod;
}
ans = ((ans % mod) + mod) % mod;
std::cout << ans << std::endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <tuple>
#include <vector>
const long long mod = 998244353;
auto max_bit(int32_t n) {
n = n & 0xFFFF0000 ? n & 0xFFFF0000 : n;
n = n & 0xFF00FF00 ? n & 0xFF00FF00 : n;
n = n & 0xF0F0F0F0 ? n & 0xF0F0F0F0 : n;
n = n & 0xCCCCCCCC ? n & 0xCCCCCCCC : n;
n = n & 0xAAAAAAAA ? n & 0xAAAAAAAA : n;
return n;
}
template <typename T> class Segtree {
int nbin;
const T param_def;
std::vector<T> seg_vec;
std::function<T(T, T)> seg_func;
T query_partial(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return param_def;
if (a <= l && r <= b)
return seg_vec[k];
const T v_l = query_partial(a, b, k * 2 + 1, l, (l + r) / 2);
const T v_r = query_partial(a, b, k * 2 + 2, (l + r) / 2, r);
return seg_func(v_l, v_r);
}
public:
Segtree(const std::vector<T> &data, const std::function<T(T, T)> &_seg_func,
const T _param_def)
: seg_func(_seg_func), param_def(_param_def) {
nbin = max_bit(data.size() - 1) * 2;
seg_vec.resize(nbin * 2 - 1, param_def);
auto insert_top = seg_vec.begin();
insert_top += nbin - 1;
std::copy(data.cbegin(), data.cend(), insert_top);
for (int i = nbin - 2; i >= 0; i--) {
seg_vec[i] = seg_func(seg_vec[i * 2 + 1], seg_vec[i * 2 + 2]);
}
}
T get(int i) { return seg_vec[nbin - 1 + i]; }
void update(int i, int x) {
i += nbin - 1;
seg_vec[i] = x;
while (i > 0) {
i = (i - 1) / 2;
seg_vec[i] = seg_func(seg_vec[i * 2 + 1], seg_vec[i * 2 + 2]);
}
}
T query(int a, int b) { return query_partial(a, b, 0, 0, nbin); }
};
long long mod_pow2(long long n) {
long long ans = 1, np = 2;
while (n > 0) {
if (n & 1)
ans = (ans * np) % mod;
np = (np * np) % mod;
n >>= 1;
}
return ans;
}
int main() {
int N;
std::cin >> N;
std::vector<std::tuple<int, int>> xy_arr;
std::map<int, int> y_map;
for (int i = 0; i < N; i++) {
int x, y;
std::cin >> x >> y;
y_map[y] = 0;
xy_arr.emplace_back(x, y);
}
int ni = 0;
for (auto &&it : y_map) {
it.second = ni;
ni++;
}
if (N == 1) {
std::cout << 1 << std::endl;
return 0;
}
std::vector<std::tuple<int, int, int, int>> p_arr(N);
auto f_sum = [](int l, int r) { return l + r; };
Segtree<int> seg1(std::vector<int>(N), f_sum, 0),
seg2(std::vector<int>(N), f_sum, 0);
std::sort(xy_arr.begin(), xy_arr.end());
for (int i = 0; i < N; i++) {
int y2 = y_map[std::get<1>(xy_arr[i])];
std::get<0>(p_arr[i]) = seg1.query(0, y2);
std::get<1>(p_arr[i]) = seg1.query(y2, ni);
seg1.update(y2, 1);
}
std::sort(xy_arr.rbegin(), xy_arr.rend());
for (int i = 0; i < N; i++) {
int y2 = y_map[std::get<1>(xy_arr[i])];
std::get<2>(p_arr[N - 1 - i]) = seg2.query(0, y2);
std::get<3>(p_arr[N - 1 - i]) = seg2.query(y2, ni);
seg2.update(y2, 1);
}
long long ans = 0;
for (int i = 0; i < N; i++) {
long long a, b, c, d;
std::tie(a, b, c, d) = p_arr[i];
long long a2 = mod_pow2(a);
long long b2 = mod_pow2(b);
long long c2 = mod_pow2(c);
long long d2 = mod_pow2(d);
ans += (((((a2 * b2) % mod) * c2) % mod) * d2) % mod;
ans += ((((((a2 - 1) * (d2 - 1)) % mod) * b2) % mod) * c2) % mod;
ans += ((((a2 + d2 - 1) * (b2 - 1)) % mod) * (c2 - 1)) % mod;
ans %= mod;
}
ans = ((ans % mod) + mod) % mod;
std::cout << ans << std::endl;
return 0;
}
| insert | 91 | 91 | 91 | 96 | 0 | |
p02957 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll A, B;
cin >> A >> B;
ll m;
m = max(A, B);
for (ll k = -m; k <= m; k++) {
ll a = abs(A - k);
ll b = abs(B - k);
if (a == b) {
cout << k << endl;
return 0;
}
}
cout << "IMPOSSIBLE" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll A, B;
cin >> A >> B;
ll m;
m = max(A, B);
for (ll k = 0; k <= m; k++) {
ll a = abs(A - k);
ll b = abs(B - k);
if (a == b) {
cout << k << endl;
return 0;
}
}
cout << "IMPOSSIBLE" << endl;
return 0;
} | replace | 9 | 10 | 9 | 10 | TLE | |
p02957 | C++ | Time Limit Exceeded | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
int main() {
ll a, b;
cin >> a >> b;
for (ll i = 0; i <= (a + b); i++) {
if (abs(a - i) == abs(b - i)) {
cout << i;
return 0;
}
}
cout << "IMPOSSIBLE";
return 0;
} | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
int main() {
ll a, b;
cin >> a >> b;
for (ll i = 0; i <= 1000000000; i++) {
if (abs(a - i) == abs(b - i)) {
cout << i;
return 0;
}
}
cout << "IMPOSSIBLE";
return 0;
} | replace | 26 | 27 | 26 | 27 | TLE | |
p02957 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
for (int i = -0; i < 100000000; i++) {
if (abs(a - i) == abs(b - i)) {
cout << i << endl;
} else {
cout << "IMPOSSIBLE" << endl;
}
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int ans;
if ((a + b) % 2 == 0) {
ans = (a + b) / 2;
cout << ans << endl;
} else {
cout << "IMPOSSIBLE" << endl;
}
return 0;
}
| replace | 4 | 10 | 4 | 12 | TLE | |
p02957 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define nl cout << '\n';
int main() {
int a, b, c, d;
cin >> a >> b;
if ((a + b) % ((a + b) / 2) == 2)
cout << (a + b) / 2;
else
cout << "IMPOSSIBLE";
nl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define nl cout << '\n';
int main() {
int a, b, c, d;
cin >> a >> b;
c = (a + b) / 2;
if (abs(a - c) == abs(b - c))
cout << c;
else
cout << "IMPOSSIBLE";
nl;
return 0;
}
| replace | 6 | 8 | 6 | 9 | 0 | |
p02957 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e9 + 1;
int main() {
int a, b, c;
cin >> a >> b;
for (int i = -maxn; i <= maxn; i++) {
if (abs(a - i) == abs(b - i)) {
cout << i << endl;
return 0;
}
}
cout << "IMPOSSIBLE" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e9 + 1;
int main() {
int a, b, c;
cin >> a >> b;
for (int i = 0; i <= maxn; i++) {
if (abs(a - i) == abs(b - i)) {
cout << i << endl;
return 0;
}
}
cout << "IMPOSSIBLE" << endl;
return 0;
} | replace | 6 | 7 | 6 | 7 | TLE | |
p02957 | C++ | Time Limit Exceeded |
#include <bits/stdc++.h>
using namespace std;
int main() {
long double a, b;
cin >> a >> b;
for (int i = 0; i <= max(a, b); i++) {
if (abs(a - i) == abs(b - i)) {
cout << i << endl;
return 0;
}
/* code */
}
cout << "IMPOSSIBLE" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
for (int i = 0; i <= max(a, b); i++) {
if (abs(a - i) == abs(b - i)) {
cout << i << endl;
return 0;
}
/* code */
}
cout << "IMPOSSIBLE" << endl;
return 0;
}
| replace | 5 | 6 | 5 | 6 | TLE | |
p02957 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
// for loop
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define repe(i, a, n) for (int i = (a); i <= (n); ++i)
#define rrep(i, n, a) for (int i = (n); n > (a); --i)
#define rrepe(i, n, a) for (int i = (n); n >= (a); --i)
// abbreviati
#define PB(v) push_back(v)
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define ENDL << "\n"
using ll = long long;
using P = pair<int, int>;
using itn = int;
// constant
const int INF = 1 << 30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI = (acos(-1));
/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/
// adjacency list
vector<int> to[100005];
// Graph
using Graph = vector<vector<int>>;
// Grid
int H, W;
vector<vector<int>> field;
// 4方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int a, b;
cin >> a >> b;
int i = 0;
while ((a + b) >= i) {
if (abs(a - i) == abs(b - i)) {
cout << i ENDL;
return 0;
}
++i;
}
cout << "IMPOSSIBLE" ENDL;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
// for loop
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define repe(i, a, n) for (int i = (a); i <= (n); ++i)
#define rrep(i, n, a) for (int i = (n); n > (a); --i)
#define rrepe(i, n, a) for (int i = (n); n >= (a); --i)
// abbreviati
#define PB(v) push_back(v)
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define ENDL << "\n"
using ll = long long;
using P = pair<int, int>;
using itn = int;
// constant
const int INF = 1 << 30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI = (acos(-1));
/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/
// adjacency list
vector<int> to[100005];
// Graph
using Graph = vector<vector<int>>;
// Grid
int H, W;
vector<vector<int>> field;
// 4方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int a, b;
cin >> a >> b;
int i = 0;
while ((a) >= i || b >= i) {
if (abs(a - i) == abs(b - i)) {
cout << i ENDL;
return 0;
}
++i;
}
cout << "IMPOSSIBLE" ENDL;
return 0;
} | replace | 51 | 52 | 51 | 52 | TLE | |
p02957 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1e18;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(), (x).end()
template <typename T> void print_vec(vector<T> a) {
int n = a.size();
REP(i, n) {
cout >> a[i];
if (i != n - 1)
cout << " ";
else
cout << endl;
}
}
ll power(ll base, ll exponent) {
if (exponent % 2) {
return power(base, exponent - 1) * base % mod;
} else if (exponent) {
ll root_ans = power(base, exponent / 2);
return root_ans * root_ans % mod;
} else {
return 1;
}
}
ll inverse(ll x) { return power(x, mod - 2); }
ll gcd(ll a, ll b) {
if (a < b)
gcd(b, a);
ll r;
while (r = a % b) {
a = b;
b = r;
}
return b;
}
template <typename T> ll sum(T begin, T end) {
return accumulate(begin, end, 0ll);
}
struct combination {
vector<ll> fact, inv;
combination(int sz) : fact(sz + 1), inv(sz + 1) {
fact[0] = 1;
for (int i = 1; i <= sz; i++) {
fact[i] = fact[i - 1] * i % mod;
}
inv[sz] = power(fact[sz], mod - 2);
for (int i = sz - 1; i >= 0; i--) {
inv[i] = inv[i + 1] * (i + 1) % mod;
}
}
ll C(int p, int q) const {
if (q < 0 || p < q)
return 0;
return (fact[p] * inv[q] % mod * inv[p - q] % mod);
}
};
int bsearch(const vector<ll> &a, ll x) {
int lft = 0;
int rgt = a.size();
while (rgt - lft > 1) {
int mid = (lft + rgt) / 2;
if (a[mid] < x) {
lft = mid;
} else {
rgt = mid;
}
}
return lft;
}
signed main() {
ios::sync_with_stdio(false);
ll a, b;
cin >> a >> b;
ll c = 1e9 + 1;
REP_FROM(k, -c, c) {
if (abs(a - k) == abs(b - k)) {
cout << k << endl;
return 0;
}
}
cout << "IMPOSSIBLE" << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1e18;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(), (x).end()
template <typename T> void print_vec(vector<T> a) {
int n = a.size();
REP(i, n) {
cout >> a[i];
if (i != n - 1)
cout << " ";
else
cout << endl;
}
}
ll power(ll base, ll exponent) {
if (exponent % 2) {
return power(base, exponent - 1) * base % mod;
} else if (exponent) {
ll root_ans = power(base, exponent / 2);
return root_ans * root_ans % mod;
} else {
return 1;
}
}
ll inverse(ll x) { return power(x, mod - 2); }
ll gcd(ll a, ll b) {
if (a < b)
gcd(b, a);
ll r;
while (r = a % b) {
a = b;
b = r;
}
return b;
}
template <typename T> ll sum(T begin, T end) {
return accumulate(begin, end, 0ll);
}
struct combination {
vector<ll> fact, inv;
combination(int sz) : fact(sz + 1), inv(sz + 1) {
fact[0] = 1;
for (int i = 1; i <= sz; i++) {
fact[i] = fact[i - 1] * i % mod;
}
inv[sz] = power(fact[sz], mod - 2);
for (int i = sz - 1; i >= 0; i--) {
inv[i] = inv[i + 1] * (i + 1) % mod;
}
}
ll C(int p, int q) const {
if (q < 0 || p < q)
return 0;
return (fact[p] * inv[q] % mod * inv[p - q] % mod);
}
};
int bsearch(const vector<ll> &a, ll x) {
int lft = 0;
int rgt = a.size();
while (rgt - lft > 1) {
int mid = (lft + rgt) / 2;
if (a[mid] < x) {
lft = mid;
} else {
rgt = mid;
}
}
return lft;
}
signed main() {
ios::sync_with_stdio(false);
ll a, b;
cin >> a >> b;
ll c = 1e9 + 1;
REP(k, c) {
if (abs(a - k) == abs(b - k)) {
cout << k << endl;
return 0;
}
}
cout << "IMPOSSIBLE" << endl;
return 0;
}
| replace | 92 | 93 | 92 | 93 | TLE | |
p02957 | C++ | Runtime Error | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define forn(i, n) for (i = 0; i < n; ++i)
#define for1(i, n) for (i = 1; i <= n; ++i)
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define fill(x, b) memset((x), b, sizeof((x)))
#define fill2D(x, r, c, b) memset((x), b, sizeof(x[0][0]) * r * c)
#define whatIs(a) cout << #a << " is : " << a << endl
typedef long long ll;
typedef vector<ll> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<vs> vvs;
const ll mod = 1e9 + 7;
clock_t t1, t2;
ll binPow(ll a, ll b) {
ll x = 1, y = a;
while (b) {
if (b & 1)
x = (x * y) % mod;
y = (y * y) % mod;
b >>= 1;
}
return x % mod;
}
ll inverserEuler(ll n) { return binPow(n, mod - 2); }
ll C(ll k, ll n) {
vll f(n + 1, 1);
for (ll i = 2; i <= n; i++)
f[i] = (f[i - 1] * i) % mod;
return (f[n] * ((inverserEuler(f[k]) * inverserEuler(f[n - k])) % mod) %
mod) %
mod;
}
/* Extend Euclid: ax + by = c;
ll x, y;
void extendEuclid(ll a, ll b){if(b == 0){x = 1;y =
0;return;}extendEuclid(b,a%b);ll x1 = y, y1 = x - (a/b) * y;x = x1;y = y1;}
// nghiem : x + (b/d)*k, y - (a/d) * k;
*/
/*--------------------------------------------------------------------------------------------------*/
void trunghieu() {
int a, b;
cin >> a >> b;
if ((a + b) % 2 == 0)
cout << (a + b) / 2;
else
cout << "IMPOSSIBLE";
}
int main() {
ios::sync_with_stdio(false);
cin.tie();
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
// freopen("output.txt","w",stdout);
#endif
trunghieu();
return 0;
} | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define forn(i, n) for (i = 0; i < n; ++i)
#define for1(i, n) for (i = 1; i <= n; ++i)
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define fill(x, b) memset((x), b, sizeof((x)))
#define fill2D(x, r, c, b) memset((x), b, sizeof(x[0][0]) * r * c)
#define whatIs(a) cout << #a << " is : " << a << endl
typedef long long ll;
typedef vector<ll> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<vs> vvs;
const ll mod = 1e9 + 7;
clock_t t1, t2;
ll binPow(ll a, ll b) {
ll x = 1, y = a;
while (b) {
if (b & 1)
x = (x * y) % mod;
y = (y * y) % mod;
b >>= 1;
}
return x % mod;
}
ll inverserEuler(ll n) { return binPow(n, mod - 2); }
ll C(ll k, ll n) {
vll f(n + 1, 1);
for (ll i = 2; i <= n; i++)
f[i] = (f[i - 1] * i) % mod;
return (f[n] * ((inverserEuler(f[k]) * inverserEuler(f[n - k])) % mod) %
mod) %
mod;
}
/* Extend Euclid: ax + by = c;
ll x, y;
void extendEuclid(ll a, ll b){if(b == 0){x = 1;y =
0;return;}extendEuclid(b,a%b);ll x1 = y, y1 = x - (a/b) * y;x = x1;y = y1;}
// nghiem : x + (b/d)*k, y - (a/d) * k;
*/
/*--------------------------------------------------------------------------------------------------*/
void trunghieu() {
int a, b;
cin >> a >> b;
if ((a + b) % 2 == 0)
cout << (a + b) / 2;
else
cout << "IMPOSSIBLE";
}
int main() {
ios::sync_with_stdio(false);
cin.tie();
trunghieu();
return 0;
} | delete | 70 | 74 | 70 | 70 | 0 | |
p02957 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back
#define speed \
ios_base::sync_with_stdio(0); \
cin.tie(0);
using namespace std;
signed main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
speed int a, b;
cin >> a >> b;
int mini = min(a, b);
int maxi = max(a, b);
if ((maxi - mini) % 2) {
cout << "IMPOSSIBLE";
} else {
cout << (mini + ((maxi - mini) / 2));
}
} | #include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back
#define speed \
ios_base::sync_with_stdio(0); \
cin.tie(0);
using namespace std;
signed main() {
speed int a, b;
cin >> a >> b;
int mini = min(a, b);
int maxi = max(a, b);
if ((maxi - mini) % 2) {
cout << "IMPOSSIBLE";
} else {
cout << (mini + ((maxi - mini) / 2));
}
} | delete | 11 | 15 | 11 | 11 | 0 | |
p02957 | Python | Runtime Error | A, B = map(int, input())
print((A + B) // 2 if abs(A - B) % 2 == 0 else "IMPOSSIBLE")
| A, B = map(int, input().split())
print((A + B) // 2 if abs(A - B) % 2 == 0 else "IMPOSSIBLE")
| replace | 0 | 1 | 0 | 1 | ValueError: invalid literal for int() with base 10: ' ' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02957/Python/s947963908.py", line 1, in <module>
A, B = map(int, input())
ValueError: invalid literal for int() with base 10: ' '
|
p02957 | Python | Time Limit Exceeded | A, B = map(int, input().split())
for K in range(10**9):
if abs(A - K) == abs(B - K):
print(K)
else:
print("IMPOSSIBLE")
| A, B = map(int, input().split())
if (A + B) % 2 != 0:
print("IMPOSSIBLE")
else:
print((A + B) // 2)
| replace | 1 | 6 | 1 | 5 | TLE | |
p02957 | Python | Runtime Error | # -*- coding: utf-8 -*-
a, b = map(int, input().split())
if isinstance((a + b) / 2):
print((a + b) / 2)
else:
print("IMPOSSIBLE")
| # -*- coding: utf-8 -*-
a, b = map(int, input().split())
if (a + b) % 2 == 0:
print((a + b) // 2)
else:
print("IMPOSSIBLE")
| replace | 2 | 4 | 2 | 4 | TypeError: isinstance expected 2 arguments, got 1 | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02957/Python/s456363956.py", line 3, in <module>
if isinstance((a + b) / 2):
TypeError: isinstance expected 2 arguments, got 1
|
p02957 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b;
cin >> a >> b;
for (long long i = 0; i <= a + b; i++) {
if (abs(a - i) == abs(b - i)) {
cout << i << endl;
return 0;
}
}
cout << "IMPOSSIBLE";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b;
cin >> a >> b;
if ((a + b) % 2 == 0)
cout << (a + b) / 2;
else
cout << "IMPOSSIBLE";
return 0;
} | replace | 6 | 13 | 6 | 10 | TLE | |
p02957 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define DEBUG 1
#define fi first
#define se second
#define pb push_back
#define fore(i, a, b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= (_b); --i)
using namespace std;
typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
const int INF = 1e9 + 3;
const int MOD = 1e9 + 7;
int main() {
if (DEBUG) {
freopen("CP.inp", "r", stdin);
// freopen("CP.out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(0);
int a, b;
cin >> a >> b;
if ((a + b) & 1)
cout << "IMPOSSIBLE\n";
else
cout << (a + b) / 2 << '\n';
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define DEBUG 0
#define fi first
#define se second
#define pb push_back
#define fore(i, a, b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= (_b); --i)
using namespace std;
typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
const int INF = 1e9 + 3;
const int MOD = 1e9 + 7;
int main() {
if (DEBUG) {
freopen("CP.inp", "r", stdin);
// freopen("CP.out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(0);
int a, b;
cin >> a >> b;
if ((a + b) & 1)
cout << "IMPOSSIBLE\n";
else
cout << (a + b) / 2 << '\n';
return 0;
}
| replace | 14 | 15 | 14 | 15 | 0 | |
p02957 | C++ | Runtime Error | #include <algorithm>
#include <cstdlib>
#include <ctype.h>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define N_MAX (100000)
#define LL_MAX_NUM (1LL << 60)
#define INF 1e7
typedef long long ll;
typedef long long int lli;
int main() {
int A, B;
cin >> A >> B;
cout << ((A + B) % 2 == 0 ? (char *)((A + B) / 2) : "IMPOSSIBLE") << endl;
return 0;
} | #include <algorithm>
#include <cstdlib>
#include <ctype.h>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define N_MAX (100000)
#define LL_MAX_NUM (1LL << 60)
#define INF 1e7
typedef long long ll;
typedef long long int lli;
int main() {
int A, B;
cin >> A >> B;
cout << ((A + B) % 2 == 0 ? to_string((A + B) / 2) : "IMPOSSIBLE") << endl;
return 0;
} | replace | 26 | 27 | 26 | 27 | -11 | |
p02957 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define fori(i, a, b) for (int i = a; i <= b; i++)
#define ford(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define mk make_pair
#define fs first
#define sc second
int main() {
ll m, n;
cin >> m >> n;
int l = max(n, m);
for (ll i = 0; i < l * l; i++) {
if (abs(n - i) == abs(m - i)) {
cout << i;
exit(0);
}
}
cout << "IMPOSSIBLE";
return 0;
} | #include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define fori(i, a, b) for (int i = a; i <= b; i++)
#define ford(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define mk make_pair
#define fs first
#define sc second
int main() {
ll m, n;
cin >> m >> n;
int l = max(n, m);
for (ll i = 0; i < l; i++) {
if (abs(n - i) == abs(m - i)) {
cout << i;
exit(0);
}
}
cout << "IMPOSSIBLE";
return 0;
} | replace | 19 | 20 | 19 | 20 | TLE | |
p02957 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B;
cin >> A >> B;
for (int i = 1; i < 2147483647; i++) {
if (abs(A - i) == abs(B - i)) {
cout << i << endl;
break;
}
if (i == 2147483646) {
cout << "IMPOSSIBLE" << endl;
}
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B;
cin >> A >> B;
int K = (A + B);
if (K % 2 == 0) {
cout << K / 2 << endl;
} else {
cout << "IMPOSSIBLE" << endl;
}
} | replace | 8 | 16 | 8 | 14 | TLE | |
p02957 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int A, B;
cin >> A >> B;
for (int i = 0;; i++) {
if ((A == 0) || (B == 0)) {
cout << "IMPOSSIBLE" << endl;
break;
}
if (abs(A - i) == abs(B - i)) {
cout << i << endl;
break;
}
}
} | #include <iostream>
using namespace std;
int main() {
int A, B;
cin >> A >> B;
for (int i = 0;; i++) {
if (abs(A - B) % 2 != 0) {
cout << "IMPOSSIBLE" << endl;
break;
}
if (abs(A - i) == abs(B - i)) {
cout << i << endl;
break;
}
}
} | replace | 9 | 10 | 9 | 10 | TLE | |
p02957 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <time.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
void solve() {
ll a, b, k;
cin >> a >> b;
k = (a + b) / 2;
if (abs(a - k) == abs(b - k))
cout << k;
else
cout << "IMPOSSIBLE";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
clock_t tStart = clock();
ll t, k;
// cin>>t;
// while(t--)
solve();
// printf("\nTime taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
return 0;
} | #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <time.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
void solve() {
ll a, b, k;
cin >> a >> b;
k = (a + b) / 2;
if (abs(a - k) == abs(b - k))
cout << k;
else
cout << "IMPOSSIBLE";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
clock_t tStart = clock();
ll t, k;
// cin>>t;
// while(t--)
solve();
// printf("\nTime taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
return 0;
} | replace | 22 | 26 | 22 | 26 | 0 | |
p02957 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> A(n + 1), B(n);
for (int i = 0; i < n + 1; ++i)
cin >> A[i];
for (int i = 0; i < n; ++i)
cin >> B[i];
int count = 0, tmp = 0;
for (int i = 0; i < n; ++i) {
count += min(A[i], B[i]);
B[i] -= min(A[i], B[i]);
count += min(A[i + 1], B[i]);
A[i + i] -= min(A[i + 1], B[i]);
}
cout << count << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
if ((a + b) % 2 == 0)
cout << (a + b) / 2 << endl;
else
cout << "IMPOSSIBLE" << endl;
return 0;
} | replace | 4 | 19 | 4 | 10 | 0 | |
p02958 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main(int argc, const char *argv[]) {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> p;
int cnt = 0;
rep(i, N) {
cin >> p[i];
if (p[i] != i + 1) {
++cnt;
}
}
if (cnt <= 2) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main(int argc, const char *argv[]) {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> p(N);
int cnt = 0;
rep(i, N) {
cin >> p[i];
if (p[i] != i + 1) {
++cnt;
}
}
if (cnt <= 2) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
| replace | 17 | 18 | 17 | 18 | -11 | |
p02958 | C++ | Runtime Error | /*~~~~~~~~~~~~~~~~~~~~~~
Code by gkothyari
~~~~~~~~~~~~~~~~~~~~~~~*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define foreach(it, c) \
for (typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define endl "\n"
#define pb push_back
#define eb emplace_back
#define ll long long
#define ld long double
#define F first
#define S second
#define mp make_pair
#define clr(x) x.clear()
#define MAX 1e9
#define MIN -1e9
#define vi vector<int>
#define vvi vector<vi>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define max(x, y) (x > y) ? x : y
#define min(x, y) (x < y) ? x : y
#define mid(s, e) (s + (e - s) / 2)
#define mini INT_MIN
#define sqr(x) ((x) * (x))
#define ones(x) __builtin_popcount(x)
#define onesll(x) __builtin_popcountll(x)
#define PI acos(-1.0)
typedef vector<pii> vpii;
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
ll power(ll a, ll n) {
ll p = 1;
while (n > 0) {
if (n % 2) {
p = p * a;
}
n >>= 1;
a *= a;
}
return p;
}
ll power(ll a, ll n, ll mod) {
ll p = 1;
while (n > 0) {
if (n % 2) {
p = p * a;
p %= mod;
}
n >>= 1;
a *= a;
a %= mod;
}
return p % mod;
}
int main() {
cout << fixed << setprecision(15);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
ll n, i, count = 0;
vector<int> v;
cin >> n;
int a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
v.push_back(a[i]);
}
sort(v.begin(), v.end());
for (i = 0; i < n; i++) {
if (a[i] != v[i])
count++;
}
if (count <= 2)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
| /*~~~~~~~~~~~~~~~~~~~~~~
Code by gkothyari
~~~~~~~~~~~~~~~~~~~~~~~*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define foreach(it, c) \
for (typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define endl "\n"
#define pb push_back
#define eb emplace_back
#define ll long long
#define ld long double
#define F first
#define S second
#define mp make_pair
#define clr(x) x.clear()
#define MAX 1e9
#define MIN -1e9
#define vi vector<int>
#define vvi vector<vi>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define max(x, y) (x > y) ? x : y
#define min(x, y) (x < y) ? x : y
#define mid(s, e) (s + (e - s) / 2)
#define mini INT_MIN
#define sqr(x) ((x) * (x))
#define ones(x) __builtin_popcount(x)
#define onesll(x) __builtin_popcountll(x)
#define PI acos(-1.0)
typedef vector<pii> vpii;
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
ll power(ll a, ll n) {
ll p = 1;
while (n > 0) {
if (n % 2) {
p = p * a;
}
n >>= 1;
a *= a;
}
return p;
}
ll power(ll a, ll n, ll mod) {
ll p = 1;
while (n > 0) {
if (n % 2) {
p = p * a;
p %= mod;
}
n >>= 1;
a *= a;
a %= mod;
}
return p % mod;
}
int main() {
cout << fixed << setprecision(15);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
ios_base::sync_with_stdio(false);
cin.tie(0);
ll n, i, count = 0;
vector<int> v;
cin >> n;
int a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
v.push_back(a[i]);
}
sort(v.begin(), v.end());
for (i = 0; i < n; i++) {
if (a[i] != v[i])
count++;
}
if (count <= 2)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
| replace | 66 | 70 | 66 | 70 | -11 | |
p02958 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
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;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
int main() {
int n;
cin >> n;
vector<int> p(n);
for (int i = 0; i < n; i++)
cin >> p[i];
int a = -1;
int b = -1;
bool flag = false;
for (int i = 0; i < n - 1; i++)
if (p[i] > p[i + 1]) {
if (!flag) {
a = i;
flag = true;
} else {
b = i + 1;
break;
}
}
if (a == -1) {
cout << "YES" << endl;
return 0;
}
int tmp = p[b];
p[b] = p[a];
p[a] = tmp;
for (int i = 0; i < n - 1; i++)
if (p[i] > p[i + 1]) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
return 0;
} | #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
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;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
int main() {
int n;
cin >> n;
vector<int> p(n);
for (int i = 0; i < n; i++)
cin >> p[i];
int a = -1;
int b = -1;
bool flag = false;
for (int i = 0; i < n - 1; i++)
if (p[i] > p[i + 1]) {
if (!flag) {
a = i;
flag = true;
} else {
b = i + 1;
break;
}
}
if (a == -1) {
cout << "YES" << endl;
return 0;
} else if (b == -1) {
cout << "NO" << endl;
return 0;
}
int tmp = p[b];
p[b] = p[a];
p[a] = tmp;
for (int i = 0; i < n - 1; i++)
if (p[i] > p[i + 1]) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
return 0;
} | insert | 76 | 76 | 76 | 79 | 0 | |
p02958 | Python | Runtime Error | n = int(input())
p = list(map(int, input().split()))
sorted_p = sorted(p)
cnt = 0
for a, b in p, sorted_p:
if a != b:
cnt += 1
if cnt > 2:
print("NO")
else:
print("YES")
| n = int(input())
p = list(map(int, input().split()))
sorted_p = sorted(p)
cnt = 0
for a, b in zip(p, sorted_p):
if a != b:
cnt += 1
if cnt > 2:
print("NO")
else:
print("YES")
| replace | 4 | 5 | 4 | 5 | ValueError: too many values to unpack (expected 2) | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02958/Python/s135206060.py", line 5, in <module>
for a, b in p, sorted_p:
ValueError: too many values to unpack (expected 2)
|
p02958 | C++ | Runtime Error | #define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rrep(i, n) for (ll i##_len = (n), i = i##_len - 1; i >= 0; --i)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
#define printd(val) std::cout << #val " = " << val << "\n";
#include <bits/stdc++.h>
using ll = long long;
using pii = std::pair<int, int>;
using namespace std;
template <class T> T chmin(T a, T b) {
if (a > b) {
a ^= b;
b ^= a;
a ^= b;
return 1;
}
return 0;
}
template <class T> T chmax(T b, T a) {
if (a < b) {
a ^= b;
b ^= a;
a ^= b;
return 1;
}
return 0;
}
ll n;
vector<ll> p;
void input() {
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> p[i];
}
}
void src() {
ll count = 0;
for (int i = 0; i < n; ++i) {
if (p[i] != i + 1)
count++;
}
cout << (count == 2 or count == 0 ? "YES" : "NO");
}
int main(int argc, char *argv[]) {
ios::sync_with_stdio(false);
// ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
input();
src();
return 0;
} | #define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rrep(i, n) for (ll i##_len = (n), i = i##_len - 1; i >= 0; --i)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
#define printd(val) std::cout << #val " = " << val << "\n";
#include <bits/stdc++.h>
using ll = long long;
using pii = std::pair<int, int>;
using namespace std;
template <class T> T chmin(T a, T b) {
if (a > b) {
a ^= b;
b ^= a;
a ^= b;
return 1;
}
return 0;
}
template <class T> T chmax(T b, T a) {
if (a < b) {
a ^= b;
b ^= a;
a ^= b;
return 1;
}
return 0;
}
ll n;
vector<ll> p;
void input() {
cin >> n;
p.resize(n);
for (int i = 0; i < n; ++i) {
cin >> p[i];
}
}
void src() {
ll count = 0;
for (int i = 0; i < n; ++i) {
if (p[i] != i + 1)
count++;
}
cout << (count == 2 or count == 0 ? "YES" : "NO");
}
int main(int argc, char *argv[]) {
ios::sync_with_stdio(false);
// ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
input();
src();
return 0;
} | insert | 31 | 31 | 31 | 32 | -11 | |
p02958 | Python | Runtime Error | N = int(input())
p = list(map(int, input().split()))
q = sorted(p)
k = 0
for i in range(1, N + 1):
if p[i] - q[i] != 0:
k += 1
if k > 2:
print("NO")
else:
print("YES")
| N = int(input())
p = list(map(int, input().split()))
q = sorted(p)
k = 0
for i in range(N):
if p[i] - q[i] != 0:
k += 1
if k > 2:
print("NO")
else:
print("YES")
| replace | 4 | 5 | 4 | 5 | IndexError: list index out of range | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02958/Python/s083953128.py", line 6, in <module>
if p[i] - q[i] != 0:
IndexError: list index out of range
|
p02958 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> p(n);
for (int i = 0; i < n; i++) {
cin >> p.at(i);
}
vector<int> a(n);
for (int i = 1; i <= n; i++) {
a.at(i) = i;
}
int cnt = 0;
for (int i = 0; i < n; i++) {
if (a.at(i) != p.at(i))
cnt++;
}
if (cnt <= 2)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> p(n);
for (int i = 0; i < n; i++) {
cin >> p.at(i);
}
vector<int> a(n);
for (int i = 0; i < n; i++) {
a.at(i) = i + 1;
}
int cnt = 0;
for (int i = 0; i < n; i++) {
if (a.at(i) != p.at(i))
cnt++;
}
if (cnt <= 2)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
| replace | 13 | 15 | 13 | 15 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 5) >= this->size() (which is 5)
|
p02958 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int i, j;
int k, m;
int N;
cin >> N;
vector<int> p(N);
for (i = 0; i < N; i++)
cin >> p[i];
int count = 0;
bool flag = false;
for (i = 0; i < N; i++) {
if (!(i == 0)) {
if (p[i] < p[i - 1]) {
count++;
flag = true;
if (count == 1) {
k = i - 1;
}
if (count == 2) {
m = i;
}
}
if (count == 3) {
cout << "NO" << endl;
return 0;
}
}
}
if (flag) {
int tmp = p[k];
p[k] = p[m];
p[m] = tmp;
}
for (i = 0; i < N; i++) {
if (!(i == 0)) {
if (p[i] < p[i - 1]) {
cout << "NO" << endl;
return 0;
}
}
}
cout << "YES" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int i, j;
int k = 0;
int m = 0;
int N;
cin >> N;
vector<int> p(N);
for (i = 0; i < N; i++)
cin >> p[i];
int count = 0;
bool flag = false;
for (i = 0; i < N; i++) {
if (!(i == 0)) {
if (p[i] < p[i - 1]) {
count++;
flag = true;
if (count == 1) {
k = i - 1;
}
if (count == 2) {
m = i;
}
}
if (count == 3) {
cout << "NO" << endl;
return 0;
}
}
}
if (flag) {
int tmp = p[k];
p[k] = p[m];
p[m] = tmp;
}
for (i = 0; i < N; i++) {
if (!(i == 0)) {
if (p[i] < p[i - 1]) {
cout << "NO" << endl;
return 0;
}
}
}
cout << "YES" << endl;
return 0;
} | replace | 6 | 7 | 6 | 8 | 0 | |
p02958 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
int ans = 0, count = 0;
int p[N], q[N], l[2], m[2];
for (int i = 0; i < N; ++i) {
cin >> p[i];
q[i] = i + 1;
}
int j = 0;
for (int i = 0; i < N; ++i) {
if (p[i] != q[i]) {
count++;
l[j] = i + 1;
m[j] = p[i];
j++;
}
}
if (count == 0)
cout << "YES" << endl;
else if (count == 2) {
if (l[0] == m[1] && l[1] == m[0])
cout << "YES" << endl;
else
cout << "NO" << endl;
} else
cout << "NO" << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
int ans = 0, count = 0;
int p[N], q[N], l[N], m[N];
for (int i = 0; i < N; ++i) {
cin >> p[i];
q[i] = i + 1;
}
int j = 0;
for (int i = 0; i < N; ++i) {
if (p[i] != q[i]) {
count++;
l[j] = i + 1;
m[j] = p[i];
j++;
}
}
if (count == 0)
cout << "YES" << endl;
else if (count == 2) {
if (l[0] == m[1] && l[1] == m[0])
cout << "YES" << endl;
else
cout << "NO" << endl;
} else
cout << "NO" << endl;
return 0;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p02958 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, cnt = 0;
cin >> n;
vector<int> p(n);
for (int i = 0; i < n; i++)
cin >> p[i];
if (is_sorted(p.begin(), p.end())) {
cout << "YES\n";
return 0;
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; i < n; j++) {
if (p[i] > p[j]) {
int tmp = p[i];
p[i] = p[j];
p[j] = tmp;
if (is_sorted(p.begin(), p.end())) {
cout << "YES\n";
return 0;
}
tmp = p[i];
p[i] = p[j];
p[j] = tmp;
}
}
}
cout << "NO\n";
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, cnt = 0;
cin >> n;
vector<int> p(n);
for (int i = 0; i < n; i++)
cin >> p[i];
if (is_sorted(p.begin(), p.end())) {
cout << "YES\n";
return 0;
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (p[i] > p[j]) {
int tmp = p[i];
p[i] = p[j];
p[j] = tmp;
if (is_sorted(p.begin(), p.end())) {
cout << "YES\n";
return 0;
}
tmp = p[i];
p[i] = p[j];
p[j] = tmp;
}
}
}
cout << "NO\n";
return 0;
}
| replace | 16 | 17 | 16 | 17 | 0 | |
p02958 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> p(N);
for (int i = 0; i < N; i++) {
cin >> p.at(i);
}
int cnt = 0;
vector<int> a(2);
for (int i = 0; i < N - 1; i++) {
if (p.at(i + 1) < p.at(i)) {
a.at(cnt) = i;
cnt++;
}
if (cnt > 2) {
break;
}
}
if (cnt == 0) {
cout << "YES" << endl;
} else if (cnt == 2) {
bool flag = true;
int ind1 = a.at(0);
int ind2 = a.at(1) + 1;
if (ind1 - 1 >= 0) {
if (p.at(ind1 - 1) > p.at(ind2)) {
flag = false;
}
}
if (p.at(ind1 + 1) < p.at(ind2)) {
flag = false;
}
if (p.at(ind2 - 1) > p.at(ind1)) {
flag = false;
}
if (ind2 + 1 < N) {
if (p.at(ind2 + 1) < p.at(ind1)) {
flag = false;
}
}
if (flag) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} else {
cout << "NO" << endl;
}
return 0;
}
| #include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> p(N);
for (int i = 0; i < N; i++) {
cin >> p.at(i);
}
int cnt = 0;
vector<int> a(3);
for (int i = 0; i < N - 1; i++) {
if (p.at(i + 1) < p.at(i)) {
a.at(cnt) = i;
cnt++;
}
if (cnt > 2) {
break;
}
}
if (cnt == 0) {
cout << "YES" << endl;
} else if (cnt == 2) {
bool flag = true;
int ind1 = a.at(0);
int ind2 = a.at(1) + 1;
if (ind1 - 1 >= 0) {
if (p.at(ind1 - 1) > p.at(ind2)) {
flag = false;
}
}
if (p.at(ind1 + 1) < p.at(ind2)) {
flag = false;
}
if (p.at(ind2 - 1) > p.at(ind1)) {
flag = false;
}
if (ind2 + 1 < N) {
if (p.at(ind2 + 1) < p.at(ind1)) {
flag = false;
}
}
if (flag) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} else {
cout << "NO" << endl;
}
return 0;
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p02958 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000;
typedef long long ll;
#define writeln(n) cout << n << "\n";
typedef pair<int, int> P;
typedef pair<string, int> Psi;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> d(n);
for (int i = 1; i <= n; i++) {
cin >> d[i];
}
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (d[i] != i)
cnt++;
}
if (cnt == 0 || cnt == 2) {
writeln("YES");
} else {
writeln("NO");
}
}
| #include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000;
typedef long long ll;
#define writeln(n) cout << n << "\n";
typedef pair<int, int> P;
typedef pair<string, int> Psi;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> d(n + 1);
for (int i = 1; i <= n; i++) {
cin >> d[i];
}
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (d[i] != i)
cnt++;
}
if (cnt == 0 || cnt == 2) {
writeln("YES");
} else {
writeln("NO");
}
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p02958 | C++ | Runtime Error | #include <bits/stdc++.h>
#define LL long long
using namespace std;
int n;
LL a[500 + 5], b[500 + 5];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i];
}
sort(b, b + n);
int now[2], nowl = 0;
for (int i = 0; i < n; i++)
if (a[i] != b[i]) {
if (nowl == 2) {
cout << "NO\n";
return 0;
}
now[nowl++] = i;
}
if (a[now[0]] == b[now[1]] && a[now[1]] == b[now[0]])
printf("YES\n");
else
printf("NO\n");
}
| #include <bits/stdc++.h>
#define LL long long
using namespace std;
int n;
LL a[500 + 5], b[500 + 5];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i];
}
sort(b, b + n);
int now[2], nowl = 0;
for (int i = 0; i < n; i++)
if (a[i] != b[i]) {
if (nowl == 2) {
cout << "NO\n";
return 0;
}
now[nowl++] = i;
}
if (nowl == 0 ||
(nowl == 2 && a[now[0]] == b[now[1]] && a[now[1]] == b[now[0]]))
printf("YES\n");
else
printf("NO\n");
}
| replace | 21 | 22 | 21 | 24 | 0 | |
p02958 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> p(n), q(n);
for (int i = 0; i < n; i++) {
cin >> p[i];
q[i] = i + 1;
}
for (int i = 0; i < n; i++) {
for (int j = 0; i < n; j++) {
swap(p[i], p[j]);
if (p == q) {
cout << "YES" << endl;
return 0;
} else
swap(p[i], p[j]);
}
}
cout << "NO" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> p(n), q(n);
for (int i = 0; i < n; i++) {
cin >> p[i];
q[i] = i + 1;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
swap(p[i], p[j]);
if (p == q) {
cout << "YES" << endl;
return 0;
} else
swap(p[i], p[j]);
}
}
cout << "NO" << endl;
return 0;
} | replace | 14 | 15 | 14 | 15 | 0 | |
p02958 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> number(N);
for (int i = 0; i < N; i++) {
cin >> number.at(i);
}
int count = 0;
for (int i = 0; i < N; i++) {
if (number.at(i) + 1 != number.at(i + 1)) {
count++;
}
}
if (count == 2 || count == 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> number(N);
for (int i = 0; i < N; i++) {
cin >> number.at(i);
}
int count = 0;
for (int i = 0; i < N; i++) {
if (number.at(i) != i + 1) {
count++;
}
}
if (count == 2 || count == 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
| replace | 13 | 14 | 13 | 14 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 5) >= this->size() (which is 5)
|
p02958 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define INF INT_MAX
#define MOD 1000000007
#define PI acos(-1)
using ll = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)
int main(int argc, char *argv[]) {
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
vector<ll> p(N);
rep(i, N) { cin >> p[i]; }
rep(k, N - 1) {
if (p[k] > p[k + 1]) {
break;
}
if (k == N - 2) {
YES;
return 0;
}
}
rep(i, N) {
for (ll j = i + 1; j <= N; j++) {
vector<ll> vec(N);
copy(p.begin(), p.end(), vec.begin());
ll tmp = vec[i];
vec[i] = vec[j];
vec[j] = tmp;
rep(k, N - 1) {
if (vec[k] > vec[k + 1]) {
break;
}
if (k == N - 2) {
YES;
return 0;
}
}
}
}
NO;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define INF INT_MAX
#define MOD 1000000007
#define PI acos(-1)
using ll = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)
int main(int argc, char *argv[]) {
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
vector<ll> p(N);
rep(i, N) { cin >> p[i]; }
rep(k, N - 1) {
if (p[k] > p[k + 1]) {
break;
}
if (k == N - 2) {
YES;
return 0;
}
}
rep(i, N) {
for (ll j = i + 1; j < N; j++) {
vector<ll> vec(N);
copy(p.begin(), p.end(), vec.begin());
ll tmp = vec[i];
vec[i] = vec[j];
vec[j] = tmp;
rep(k, N - 1) {
if (vec[k] > vec[k + 1]) {
break;
}
if (k == N - 2) {
YES;
return 0;
}
}
}
}
NO;
return 0;
}
| replace | 42 | 43 | 42 | 43 | 0 | |
p02958 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define test() \
ull t; \
cin >> t; \
while (t--)
#define pb push_back
#define mkp make_pair
#define nl cout << endl
#define MOD 1000000007
#define loop(i, start, end) for (int i = start; i < end; i++)
#define N 100001
#define oa(a, n) \
for (int i = 0; i < n; i++) \
cout << a[i] << " "; \
nl;
#define ov(a) \
for (int i = 0; i < a.size(); i++) \
cout << a[i] << endl;
#define pi M_PI
int main() {
fastio();
#ifndef ONLINE_JUDGE
auto freopenvar = freopen("in.txt", "r", stdin);
auto freeopenvar2 = freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
int a[n];
loop(i, 0, n) { cin >> a[i]; }
int flag2 = 0;
loop(i, 0, n) {
if (a[i] != i + 1)
flag2 = 1;
}
int flag1 = 0, flag = 0;
loop(i, 0, n) {
if (flag1 == 1)
break;
loop(j, 0, n) {
if (i != j) {
swap(a[i], a[j]);
flag = 0;
loop(k, 0, n - 1) {
if (a[k + 1] <= a[k]) {
flag = 1;
break;
}
}
swap(a[i], a[j]);
if (flag == 0) {
flag1 = 1;
// cout<<i<<" "<<j;
break;
}
}
}
}
if (flag1 == 1 || flag2 == 0)
cout << "YES" << endl;
else
cout << "NO";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define test() \
ull t; \
cin >> t; \
while (t--)
#define pb push_back
#define mkp make_pair
#define nl cout << endl
#define MOD 1000000007
#define loop(i, start, end) for (int i = start; i < end; i++)
#define N 100001
#define oa(a, n) \
for (int i = 0; i < n; i++) \
cout << a[i] << " "; \
nl;
#define ov(a) \
for (int i = 0; i < a.size(); i++) \
cout << a[i] << endl;
#define pi M_PI
int main() {
fastio();
int n;
cin >> n;
int a[n];
loop(i, 0, n) { cin >> a[i]; }
int flag2 = 0;
loop(i, 0, n) {
if (a[i] != i + 1)
flag2 = 1;
}
int flag1 = 0, flag = 0;
loop(i, 0, n) {
if (flag1 == 1)
break;
loop(j, 0, n) {
if (i != j) {
swap(a[i], a[j]);
flag = 0;
loop(k, 0, n - 1) {
if (a[k + 1] <= a[k]) {
flag = 1;
break;
}
}
swap(a[i], a[j]);
if (flag == 0) {
flag1 = 1;
// cout<<i<<" "<<j;
break;
}
}
}
}
if (flag1 == 1 || flag2 == 0)
cout << "YES" << endl;
else
cout << "NO";
return 0;
} | delete | 28 | 32 | 28 | 28 | TLE | |
p02958 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> p(N);
int cnt = 0;
for (int i = 1; i < N + 1; i++) {
cin >> p[i];
if (p[i] == i) {
cnt += 1;
}
}
if ((cnt == N) || (cnt == N - 2)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> p(N + 1);
int cnt = 0;
for (int i = 1; i < N + 1; i++) {
cin >> p[i];
if (p[i] == i) {
cnt += 1;
}
}
if ((cnt == N) || (cnt == N - 2)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02958 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int p, n, k;
int main() {
scanf("%d", n);
for (int i = 1; i <= n; i++) {
scanf("%d", &p);
if (p != i) {
k++;
}
}
if (k > 2) {
printf("NO");
} else
printf("YES");
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int p, n, k;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &p);
if (p != i) {
k++;
}
}
if (k > 2) {
printf("NO");
} else
printf("YES");
return 0;
}
| replace | 4 | 5 | 4 | 5 | -11 | |
p02958 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, a, n) for (int i = (n); i < (a); i++)
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<int> hoge(n), list;
rep(i, n) {
cin >> hoge[i];
list.push_back(i + 1);
}
// p$B$r>:=g$K$9$k$3$H$,$G$-$k$J$i(B
// YES $B$r!"$G$-$J$$$J$i$P(B NO $B$r=PNO$7$F$/$@$5$$!#(B
if (hoge == list) {
cout << "YES" << endl;
return 0;
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
if (i == j)
continue;
vector<int> huga(hoge);
swap(huga[i], huga[j]);
if (huga == list) {
cout << "YES" << endl;
return 0;
}
}
}
cout << "NO" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, a, n) for (int i = (n); i < (a); i++)
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<int> hoge(n), huga, list;
rep(i, n) cin >> hoge[i];
int k = 0;
rep(i, n) if (hoge[i] != i + 1) k++;
cout << (k <= 2 ? "YES" : "NO") << endl;
}
| replace | 12 | 36 | 12 | 17 | 0 | |
p02958 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
long int N, cnt = 0, a, b, tmp;
cin >> N;
int A[N];
for (int i = 0; i < N; i++) {
cin >> A[i];
}
for (int i = 0; i < N - 1; i++) {
if (A[i] > A[i + 1]) {
++cnt;
if (cnt == 1) {
a = i;
} else if (cnt == 2) {
b = i + 1;
}
}
}
if (cnt > 2) {
cout << "NO" << endl;
} else if (cnt == 0)
cout << "YES" << endl;
else {
tmp = A[a];
A[a] = A[b];
A[b] = A[tmp];
for (int i = 0; i < N - 1; i++) {
if (A[i] > A[i + 1]) {
cout << "NO" << endl;
break;
}
if (i == N - 2)
cout << "YES" << endl;
}
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long int N, cnt = 0, a, b, tmp;
cin >> N;
int A[N];
for (int i = 0; i < N; i++) {
cin >> A[i];
}
for (int i = 0; i < N - 1; i++) {
if (A[i] > A[i + 1]) {
++cnt;
if (cnt == 1) {
a = i;
} else if (cnt == 2) {
b = i + 1;
}
}
}
if (cnt > 2) {
cout << "NO" << endl;
} else if (cnt == 0)
cout << "YES" << endl;
else if (cnt == 1) {
tmp = A[a];
A[a] = A[a + 1];
A[a + 1] = A[tmp];
for (int i = 0; i < N - 1; i++) {
if (A[i] > A[i + 1]) {
cout << "NO" << endl;
break;
}
if (i == N - 2)
cout << "YES" << endl;
}
}
else {
tmp = A[a];
A[a] = A[b];
A[b] = A[tmp];
for (int i = 0; i < N - 1; i++) {
if (A[i] > A[i + 1]) {
cout << "NO" << endl;
break;
}
if (i == N - 2)
cout << "YES" << endl;
}
}
} | insert | 25 | 25 | 25 | 39 | 0 | |
p02958 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, check = 0;
cin >> N;
vector<int> a(N);
for (int i = 0; i < N; i++) {
cin >> a.at(i);
}
for (int i = 0; i < N; i++) {
if (a.at(i) != i + 1) {
swap(a.at(i), a.at(a.at(i)));
break;
}
}
for (int i = 0; i < N; i++) {
if (a.at(i) != i + 1) {
check = 1;
break;
}
}
if (check == 1) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, check = 0;
cin >> N;
vector<int> a(N);
for (int i = 0; i < N; i++) {
cin >> a.at(i);
}
for (int i = 0; i < N; i++) {
if (a.at(i) != i + 1) {
swap(a.at(i), a.at(a.at(i) - 1));
break;
}
}
for (int i = 0; i < N; i++) {
if (a.at(i) != i + 1) {
check = 1;
break;
}
}
if (check == 1) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
} | replace | 12 | 13 | 12 | 13 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 5) >= this->size() (which is 5)
|
p02958 | C++ | Runtime Error | // Created by code_sm
//
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,
// tree_order_statistics_node_update> pseudo_set;
#define ll long long
#define vi vector<int>
#define si set<int>
#define mii map<int, int>
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define extract_word(s) \
stringstream str(s); \
while (str >> word)
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define SET(s) cout << fixed << setprecision(s)
#define chotu 1000000007
#define set0(a) memset(a, 0, sizeof(a))
#define endl "\n"
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define lower_string(s) transform(all(s), s.begin(), ::tolower())
#define upper_string(s) transform(all(s), s.begin(), ::toupper())
#define size(s) s.size()
template <class T> bool umin(T &a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T> bool umax(T &a, T b) {
return a < b ? (a = b, true) : false;
}
template <typename T, typename U> bool compare(T x, U y) {
return (abs(x - y) <= 1e-9);
}
void solve() {
fastio int n;
cin >> n;
int p[n];
for (auto &x : p)
cin >> x;
int des[n];
for (int i = 0; i < n; i++)
des[i] = i + 1;
int c = 0;
for (int i = 0; i < n; i++) {
if (p[i] != des[i]) {
c++;
}
}
if (c > 2)
cout << "NO";
else
cout << "YES";
}
int main() {
// code
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fastio int t;
t = 1;
while (t--) {
solve();
cout << endl;
}
}
| // Created by code_sm
//
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,
// tree_order_statistics_node_update> pseudo_set;
#define ll long long
#define vi vector<int>
#define si set<int>
#define mii map<int, int>
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define extract_word(s) \
stringstream str(s); \
while (str >> word)
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define SET(s) cout << fixed << setprecision(s)
#define chotu 1000000007
#define set0(a) memset(a, 0, sizeof(a))
#define endl "\n"
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define lower_string(s) transform(all(s), s.begin(), ::tolower())
#define upper_string(s) transform(all(s), s.begin(), ::toupper())
#define size(s) s.size()
template <class T> bool umin(T &a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T> bool umax(T &a, T b) {
return a < b ? (a = b, true) : false;
}
template <typename T, typename U> bool compare(T x, U y) {
return (abs(x - y) <= 1e-9);
}
void solve() {
fastio int n;
cin >> n;
int p[n];
for (auto &x : p)
cin >> x;
int des[n];
for (int i = 0; i < n; i++)
des[i] = i + 1;
int c = 0;
for (int i = 0; i < n; i++) {
if (p[i] != des[i]) {
c++;
}
}
if (c > 2)
cout << "NO";
else
cout << "YES";
}
int main() {
// code
fastio int t;
t = 1;
while (t--) {
solve();
cout << endl;
}
}
| replace | 62 | 66 | 62 | 63 | -11 | |
p02958 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, pi;
cin >> n;
vector<int> p;
if (n == 2) {
cout << "YES" << endl;
return 0;
}
for (int i = 0; i < n; i++) {
cin >> pi;
p.push_back(pi);
}
int first = -1, second = -1, temp;
for (int i = 1; i < n; i++) {
if (p[i] < p[i - 1]) {
first = i;
break;
}
}
if (first == -1) {
cout << "YES" << endl;
return 0;
}
for (int i = first + 1; i < n; i++) {
if (p[i] < p[i - 1]) {
second = i;
break;
}
}
first--;
temp = p[first];
p[first] = p[second];
p[second] = temp;
for (int i = 1; i < n; i++) {
if (p[i] < p[i - 1]) {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, pi;
cin >> n;
vector<int> p;
if (n == 2) {
cout << "YES" << endl;
return 0;
}
for (int i = 0; i < n; i++) {
cin >> pi;
p.push_back(pi);
}
int first = -1, second = -1, temp;
for (int i = 1; i < n; i++) {
if (p[i] < p[i - 1]) {
first = i;
break;
}
}
if (first == -1) {
cout << "YES" << endl;
return 0;
}
for (int i = first + 1; i < n; i++) {
if (p[i] < p[i - 1]) {
second = i;
break;
}
}
first--;
if (second >= 0 && second <= n) {
temp = p[first];
p[first] = p[second];
p[second] = temp;
} else {
temp = p[first];
p[first] = p[first + 1];
p[first + 1] = temp;
}
for (int i = 1; i < n; i++) {
if (p[i] < p[i - 1]) {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
}
| replace | 42 | 45 | 42 | 51 | 0 | |
p02958 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int(i) = 0; i < (n); i++)
int n;
vector<int> a(n, 0);
bool check() {
bool f = 1;
REP(i, n - 1) if (a.at(i) > a.at(i + 1)) f = 0;
return f;
}
void sw(int i, int j) {
int tmp = a.at(i);
a.at(i) = a.at(j);
a.at(j) = tmp;
}
int main() {
bool flag = 0;
cin >> n;
REP(i, n) cin >> a.at(i);
if (check())
flag = 1;
REP(i, n - 1) for (int j = i + 1; j < n; j++) {
sw(i, j);
if (check())
flag = 1;
sw(i, j);
}
cout << (flag ? "YES" : "NO");
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int(i) = 0; i < (n); i++)
int n;
vector<int> a(50, 0);
bool check() {
bool f = 1;
REP(i, n - 1) if (a.at(i) > a.at(i + 1)) f = 0;
return f;
}
void sw(int i, int j) {
int tmp = a.at(i);
a.at(i) = a.at(j);
a.at(j) = tmp;
}
int main() {
bool flag = 0;
cin >> n;
REP(i, n) cin >> a.at(i);
if (check())
flag = 1;
REP(i, n - 1) for (int j = i + 1; j < n; j++) {
sw(i, j);
if (check())
flag = 1;
sw(i, j);
}
cout << (flag ? "YES" : "NO");
} | replace | 4 | 5 | 4 | 5 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)
|
p02958 | C++ | Runtime Error | /************************************************************************
* -> Bismillahir Rahmanir Rahim <- *
* *
* *
* *
* *
* __________ .___ .__ ____ ________ *
* \______ \_____ __| _/ ______| |__ _____ /_ |\_____ \ *
* | | _/\__ \ / __ | / ___/| | \ \__ \ | | / ____/ *
* | | \ / __ \_/ /_/ | \___ \ | Y \ / __ \_ | |/ \ *
* |______ /(____ /\____ | /____ >|___| /(____ / |___|\_______ \ *
* \/ \/ \/ \/ \/ \/ \/ *
* *
* *
* *
* .=., *
* ;c =\ *
* __| _/ *
* .'-'-._/-'-._ *
* /.. ____ \ *
* /' _ [<BF>] ) \ *
* ( / \--\_>/-/'._ ) *
* \-;_/\__;__/ _/ _/ *
* '._}|==o==\{_\/ *
* / /-._.--\ \_ *
* // / /| \ \ \ *
* / | | | \; | \ \ *
* / / | :/ \: \ \_\ *
* / | /.'| /: | \ \ *
* | | |--| |--| \_\ *
* / _/ \ | | /___--._) \ *
* |_(---'-| > | | '-' *
* /_/ \_\ *
* *
***********************************************************************/
#include <bits/stdc++.h>
#define pi acos(-1)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned un;
#define vi vector<int>
#define vl vector<ll>
#define vd vector<double>
// defined taking input;
#define sf scanf
#define si(a) sf("%d", &a)
#define sc(a) sf("%c", &a)
#define sii(a, b) sf("%d %d", &a, &b)
#define siii(a, b, c) sf("%d %d %d", &a, &b, &c)
#define sl(a) sf("%lld", &a)
#define sll(a, b) sf("%lld %lld", &a, &b)
#define slll(a, b, c) sf("%lld %lld %lld", &a, &b, &c)
#define pf printf
#define pfi(a) pf("%d\n", a)
#define pfii(a, b) pf("%d %d\n", a, b)
#define pfl(a) pf("%ld\n", a)
#define pfn pf("\n")
#define pfyes pf("YES\n")
#define pfno pf("NO\n")
#define pfYes pf("Yes\n")
#define pfNo pf("No\n")
#define wh while
#define wht(t) while (t--)
#define endl "\n"
#define pb push_back
// defined using loop
#define For(i, a, n) for (int i = a; i <= n; i++)
#define input freopen("input.txt", "r", stdin);
#define output freopen("output.txt", "w", stdout);
using namespace std;
int main() {
int n;
si(n);
vi a(n);
for (int i = 1; i <= n; i++)
si(a[i]);
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (a[i] != i)
cnt++;
}
if (cnt > 2)
pfno;
else
pfyes;
return 0;
}
| /************************************************************************
* -> Bismillahir Rahmanir Rahim <- *
* *
* *
* *
* *
* __________ .___ .__ ____ ________ *
* \______ \_____ __| _/ ______| |__ _____ /_ |\_____ \ *
* | | _/\__ \ / __ | / ___/| | \ \__ \ | | / ____/ *
* | | \ / __ \_/ /_/ | \___ \ | Y \ / __ \_ | |/ \ *
* |______ /(____ /\____ | /____ >|___| /(____ / |___|\_______ \ *
* \/ \/ \/ \/ \/ \/ \/ *
* *
* *
* *
* .=., *
* ;c =\ *
* __| _/ *
* .'-'-._/-'-._ *
* /.. ____ \ *
* /' _ [<BF>] ) \ *
* ( / \--\_>/-/'._ ) *
* \-;_/\__;__/ _/ _/ *
* '._}|==o==\{_\/ *
* / /-._.--\ \_ *
* // / /| \ \ \ *
* / | | | \; | \ \ *
* / / | :/ \: \ \_\ *
* / | /.'| /: | \ \ *
* | | |--| |--| \_\ *
* / _/ \ | | /___--._) \ *
* |_(---'-| > | | '-' *
* /_/ \_\ *
* *
***********************************************************************/
#include <bits/stdc++.h>
#define pi acos(-1)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned un;
#define vi vector<int>
#define vl vector<ll>
#define vd vector<double>
// defined taking input;
#define sf scanf
#define si(a) sf("%d", &a)
#define sc(a) sf("%c", &a)
#define sii(a, b) sf("%d %d", &a, &b)
#define siii(a, b, c) sf("%d %d %d", &a, &b, &c)
#define sl(a) sf("%lld", &a)
#define sll(a, b) sf("%lld %lld", &a, &b)
#define slll(a, b, c) sf("%lld %lld %lld", &a, &b, &c)
#define pf printf
#define pfi(a) pf("%d\n", a)
#define pfii(a, b) pf("%d %d\n", a, b)
#define pfl(a) pf("%ld\n", a)
#define pfn pf("\n")
#define pfyes pf("YES\n")
#define pfno pf("NO\n")
#define pfYes pf("Yes\n")
#define pfNo pf("No\n")
#define wh while
#define wht(t) while (t--)
#define endl "\n"
#define pb push_back
// defined using loop
#define For(i, a, n) for (int i = a; i <= n; i++)
#define input freopen("input.txt", "r", stdin);
#define output freopen("output.txt", "w", stdout);
using namespace std;
int main() {
int n;
si(n);
int a[n];
for (int i = 1; i <= n; i++)
si(a[i]);
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (a[i] != i)
cnt++;
}
if (cnt > 2)
pfno;
else
pfyes;
return 0;
}
| replace | 80 | 81 | 80 | 81 | 0 | |
p02958 | C++ | Runtime Error | #include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&...args) {
std::cout << head;
sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
for (int i = 0; i < v.size(); i++) {
std::cout << v[i];
i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
}
}
template <class T> void print(std::vector<std::vector<T>> &v) {
for (int i = 0; i < v.size(); i++) {
for (int j = 0; j < v[i].size(); j++) {
std::cout << v[i][j];
j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
}
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> a(N);
for (auto &&i : a) {
cin >> i;
}
int cnt = -1;
int cnt2 = -1;
FOR(i, 1, N) {
if (0 <= cnt && a[i - 1] > a[i]) {
cnt2 = i;
break;
}
if (cnt == -1 && a[i - 1] > a[i]) {
cnt = i - 1;
}
}
swap(a[cnt], a[cnt2]);
FOR(i, 1, N) {
if (a[i] < a[i - 1]) {
print("NO");
return 0;
}
}
print("YES");
return 0;
} | #include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&...args) {
std::cout << head;
sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
for (int i = 0; i < v.size(); i++) {
std::cout << v[i];
i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
}
}
template <class T> void print(std::vector<std::vector<T>> &v) {
for (int i = 0; i < v.size(); i++) {
for (int j = 0; j < v[i].size(); j++) {
std::cout << v[i][j];
j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
}
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> a(N);
for (auto &&i : a) {
cin >> i;
}
int cnt = -1;
int cnt2 = -1;
FOR(i, 1, N) {
if (0 <= cnt && a[i - 1] > a[i]) {
cnt2 = i;
break;
}
if (cnt == -1 && a[i - 1] > a[i]) {
cnt = i - 1;
}
}
if (0 <= cnt && 0 <= cnt2)
swap(a[cnt], a[cnt2]);
FOR(i, 1, N) {
if (a[i] < a[i - 1]) {
print("NO");
return 0;
}
}
print("YES");
return 0;
} | replace | 70 | 71 | 70 | 72 | 0 | |
p02959 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
ll ans = 0;
vector<ll> a(n + 1);
vector<ll> b(n);
rep(i, n + 1) { cin >> a[i]; }
rep(i, n) { cin >> b[i]; }
rep(i, n + 1) {
ll min1 = min(a[i], b[i]);
a[i] -= min1;
b[i] -= min1;
ans += min1;
ll min2 = min(a[i + 1], b[i]);
a[i + 1] -= min2;
b[i] -= min2;
ans += min2;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
ll ans = 0;
vector<ll> a(n + 1);
vector<ll> b(n);
rep(i, n + 1) { cin >> a[i]; }
rep(i, n) { cin >> b[i]; }
rep(i, n) {
ll min1 = min(a[i], b[i]);
a[i] -= min1;
b[i] -= min1;
ans += min1;
ll min2 = min(a[i + 1], b[i]);
a[i + 1] -= min2;
b[i] -= min2;
ans += min2;
}
cout << ans << endl;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p02959 | C++ | Runtime Error | //============================
// ABC135c City Savers
//
// 2019/08/13
//============================
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
int N;
cin >> N;
vector<long> A, B;
for (int i = 0; i < N + 1; i++)
cin >> A[i];
for (int i = 0; i < N; i++)
cin >> B[i];
long long cnt = 0;
for (int i = 0; i < N; i++) {
cnt += min(A[i], B[i]);
B[i] -= min(A[i], B[i]);
cnt += min(A[i + 1], B[i]);
A[i + 1] -= min(A[i + 1], B[i]);
}
cout << cnt << endl;
return 0;
} | //============================
// ABC135c City Savers
//
// 2019/08/13
//============================
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
int N;
cin >> N;
// long A[100000], B[100000];
vector<long> A(N + 1), B(N);
for (int i = 0; i < N + 1; i++)
cin >> A[i];
for (int i = 0; i < N; i++)
cin >> B[i];
long long cnt = 0;
for (int i = 0; i < N; i++) {
cnt += min(A[i], B[i]);
B[i] -= min(A[i], B[i]);
cnt += min(A[i + 1], B[i]);
A[i + 1] -= min(A[i + 1], B[i]);
}
cout << cnt << endl;
return 0;
} | replace | 20 | 21 | 20 | 22 | -11 | |
p02959 | C++ | Runtime Error | #include <iostream>
using namespace std;
#include <iomanip>
void _130() {
int w, h, x, y;
cin >> w >> h >> x >> y;
cout << fixed << setprecision(10);
cout << (double)w * h / 2 << " " << (2 * x == w && 2 * y == h) << endl;
}
void _131() {
long long a, b, c, d;
cin >> a >> b >> c >> d;
long long count = 0;
for (long long i = a; i <= b; ++i) {
if (i % c != 0 && i % d != 0) {
count++;
}
}
cout << count << endl;
}
#include <cmath>
void _131_() {
long long a, b, c, d;
cin >> a >> b >> c >> d;
long long min_baisuu;
for (long long i = min(c, d); i <= c * d; ++i) {
if (i % c == 0 && i % d == 0) {
min_baisuu = i;
cout << min_baisuu << endl;
break;
}
}
long long c_baisuu_num = 0;
long long d_baisuu_num = 0;
long long cd_baisuu_num = 0;
c_baisuu_num = abs(a / c - b / c);
d_baisuu_num = abs(a / d - b / d);
cd_baisuu_num = abs(a / min_baisuu - b / min_baisuu);
cout << abs(a - b) + 1 - (c_baisuu_num + d_baisuu_num - cd_baisuu_num)
<< endl;
}
void _131__() {
long long a, b, c, d;
cin >> a >> b >> c >> d;
long long min_baisuu = 0;
long long max_yakusuu = 0;
long long amari = 0;
long long bigger = max(c, d);
long long smaller = min(c, d);
while (true) {
amari = bigger % smaller;
if (amari == 0) {
max_yakusuu = smaller;
break;
}
bigger = smaller;
smaller = amari;
}
// cout << max_yakusuu << endl;
min_baisuu = c * d / max_yakusuu;
long long b_num = b - b / c - b / d + b / min_baisuu;
long long a_num = a - 1 - (a - 1) / c - (a - 1) / d + (a - 1) / min_baisuu;
// cout << b_num << " " << a_num << endl;
cout << b_num - a_num << endl;
}
#include <algorithm>
#include <vector>
void _132() {
int n;
cin >> n;
vector<int> d;
int tmp;
for (int i = 0; i < n; ++i) {
cin >> tmp;
d.push_back(tmp);
}
sort(d.begin(), d.end());
if (d.size() % 2 == 1) {
cout << 0 << endl;
return;
}
int half_index = d.size() / 2 - 1;
cout << d[half_index + 1] - d[half_index] << endl;
}
void _133() {
int l, r;
cin >> l >> r;
if (r - l > 2019) {
cout << 0 << endl;
return;
}
int min_mod = 2019;
long long multi;
long long mod;
for (int i = l; i <= r; ++i) {
for (int j = i + 1; j <= r; ++j) {
multi = (long long)i * j;
// multi = i * j;
cout << multi << endl;
mod = multi % 2019;
// cout << i << " " << j << " " << mod <<endl;
if (mod < min_mod) {
min_mod = mod;
// cout << min_mod << endl;
}
}
}
cout << min_mod << endl;
}
#include <algorithm>
#include <vector>
void _134() {
int n;
cin >> n;
int tmp;
vector<int> a;
for (int i = 0; i < n; ++i) {
cin >> tmp;
a.push_back(tmp);
}
vector<int> b(a);
sort(b.begin(), b.end());
for (int i = 0; i < n; ++i) {
if (a[i] == b[n - 1])
cout << b[n - 2] << endl;
else
cout << b[n - 1] << endl;
}
}
void _135() {
int n;
int a[10001];
int b[10000];
cin >> n;
for (int i = 0; i < n + 1; ++i)
cin >> a[i];
for (int i = 0; i < n; ++i)
cin >> b[i];
int residual_capa = 0;
long long count = 0;
int nokori = 0;
for (int i = 0; i < n; ++i) {
nokori = max(0, a[i] - residual_capa);
if (nokori == 0) {
count += a[i];
residual_capa = b[i];
} else {
nokori = max(0, nokori - b[i]);
// cout << nokori << endl;
if (nokori == 0) {
count += a[i];
residual_capa = b[i] - (a[i] - residual_capa);
} else {
count += residual_capa + b[i];
residual_capa = 0;
}
}
// cout << residual_capa << " " << count << endl;
}
count += min(residual_capa, a[n]);
cout << count << endl;
}
int main() {
_135();
return 0;
}
| #include <iostream>
using namespace std;
#include <iomanip>
void _130() {
int w, h, x, y;
cin >> w >> h >> x >> y;
cout << fixed << setprecision(10);
cout << (double)w * h / 2 << " " << (2 * x == w && 2 * y == h) << endl;
}
void _131() {
long long a, b, c, d;
cin >> a >> b >> c >> d;
long long count = 0;
for (long long i = a; i <= b; ++i) {
if (i % c != 0 && i % d != 0) {
count++;
}
}
cout << count << endl;
}
#include <cmath>
void _131_() {
long long a, b, c, d;
cin >> a >> b >> c >> d;
long long min_baisuu;
for (long long i = min(c, d); i <= c * d; ++i) {
if (i % c == 0 && i % d == 0) {
min_baisuu = i;
cout << min_baisuu << endl;
break;
}
}
long long c_baisuu_num = 0;
long long d_baisuu_num = 0;
long long cd_baisuu_num = 0;
c_baisuu_num = abs(a / c - b / c);
d_baisuu_num = abs(a / d - b / d);
cd_baisuu_num = abs(a / min_baisuu - b / min_baisuu);
cout << abs(a - b) + 1 - (c_baisuu_num + d_baisuu_num - cd_baisuu_num)
<< endl;
}
void _131__() {
long long a, b, c, d;
cin >> a >> b >> c >> d;
long long min_baisuu = 0;
long long max_yakusuu = 0;
long long amari = 0;
long long bigger = max(c, d);
long long smaller = min(c, d);
while (true) {
amari = bigger % smaller;
if (amari == 0) {
max_yakusuu = smaller;
break;
}
bigger = smaller;
smaller = amari;
}
// cout << max_yakusuu << endl;
min_baisuu = c * d / max_yakusuu;
long long b_num = b - b / c - b / d + b / min_baisuu;
long long a_num = a - 1 - (a - 1) / c - (a - 1) / d + (a - 1) / min_baisuu;
// cout << b_num << " " << a_num << endl;
cout << b_num - a_num << endl;
}
#include <algorithm>
#include <vector>
void _132() {
int n;
cin >> n;
vector<int> d;
int tmp;
for (int i = 0; i < n; ++i) {
cin >> tmp;
d.push_back(tmp);
}
sort(d.begin(), d.end());
if (d.size() % 2 == 1) {
cout << 0 << endl;
return;
}
int half_index = d.size() / 2 - 1;
cout << d[half_index + 1] - d[half_index] << endl;
}
void _133() {
int l, r;
cin >> l >> r;
if (r - l > 2019) {
cout << 0 << endl;
return;
}
int min_mod = 2019;
long long multi;
long long mod;
for (int i = l; i <= r; ++i) {
for (int j = i + 1; j <= r; ++j) {
multi = (long long)i * j;
// multi = i * j;
cout << multi << endl;
mod = multi % 2019;
// cout << i << " " << j << " " << mod <<endl;
if (mod < min_mod) {
min_mod = mod;
// cout << min_mod << endl;
}
}
}
cout << min_mod << endl;
}
#include <algorithm>
#include <vector>
void _134() {
int n;
cin >> n;
int tmp;
vector<int> a;
for (int i = 0; i < n; ++i) {
cin >> tmp;
a.push_back(tmp);
}
vector<int> b(a);
sort(b.begin(), b.end());
for (int i = 0; i < n; ++i) {
if (a[i] == b[n - 1])
cout << b[n - 2] << endl;
else
cout << b[n - 1] << endl;
}
}
void _135() {
int n;
int a[100001];
int b[100000];
cin >> n;
for (int i = 0; i < n + 1; ++i)
cin >> a[i];
for (int i = 0; i < n; ++i)
cin >> b[i];
int residual_capa = 0;
long long count = 0;
int nokori = 0;
for (int i = 0; i < n; ++i) {
nokori = max(0, a[i] - residual_capa);
if (nokori == 0) {
count += a[i];
residual_capa = b[i];
} else {
nokori = max(0, nokori - b[i]);
// cout << nokori << endl;
if (nokori == 0) {
count += a[i];
residual_capa = b[i] - (a[i] - residual_capa);
} else {
count += residual_capa + b[i];
residual_capa = 0;
}
}
// cout << residual_capa << " " << count << endl;
}
count += min(residual_capa, a[n]);
cout << count << endl;
}
int main() {
_135();
return 0;
}
| replace | 150 | 152 | 150 | 152 | 0 | |
p02959 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
int main() {
int n;
cin >> n;
vector<ll> a(n + 1), b(n);
rep(i, n + 1) cin >> a[i];
rep(i, n) cin >> b[i];
ll ans(0);
rep(i, n) {
if (a[i] >= b[i]) {
ans += b[i];
} else {
ans += a[i];
b[i] -= a[i];
if (a[i + 1] >= b[i]) {
ans += b[i];
a[i + 1] -= b[i];
} else {
ans += a[i + i];
a[i + 1] = 0;
}
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
int main() {
int n;
cin >> n;
vector<ll> a(n + 1), b(n);
rep(i, n + 1) cin >> a[i];
rep(i, n) cin >> b[i];
ll ans(0);
rep(i, n) {
if (a[i] >= b[i]) {
ans += b[i];
} else {
ans += a[i];
b[i] -= a[i];
if (a[i + 1] >= b[i]) {
ans += b[i];
a[i + 1] -= b[i];
} else {
ans += a[i + 1];
a[i + 1] = 0;
}
}
}
cout << ans << endl;
return 0;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p02959 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
#define rep(k, i, n) for (int i = k; i < n; ++i)
using namespace std;
typedef long long ll;
int N;
long a[10001], b[10000];
ll sum = 0;
int main(void) {
// Your code here!
cin >> N;
rep(0, i, N + 1) cin >> a[i];
rep(0, i, N) {
cin >> b[i];
if (b[i] < a[i]) {
a[i] -= b[i];
sum += b[i];
b[i] = 0;
} else {
sum += a[i];
b[i] -= a[i];
a[i] = 0;
if (a[i + 1] > b[i]) {
sum += b[i];
a[i + 1] -= b[i];
b[i] = 0;
} else {
sum += a[i + 1];
b[i] -= a[i + 1];
a[i + 1] = 0;
}
}
}
cout << sum << endl;
}
| #include <bits/stdc++.h>
#include <iostream>
#define rep(k, i, n) for (int i = k; i < n; ++i)
using namespace std;
typedef long long ll;
int N;
long a[100001], b[100000];
ll sum = 0;
int main(void) {
// Your code here!
cin >> N;
rep(0, i, N + 1) cin >> a[i];
rep(0, i, N) {
cin >> b[i];
if (b[i] < a[i]) {
a[i] -= b[i];
sum += b[i];
b[i] = 0;
} else {
sum += a[i];
b[i] -= a[i];
a[i] = 0;
if (a[i + 1] > b[i]) {
sum += b[i];
a[i + 1] -= b[i];
b[i] = 0;
} else {
sum += a[i + 1];
b[i] -= a[i + 1];
a[i + 1] = 0;
}
}
}
cout << sum << endl;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02959 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T> T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <typename T> T pow(T a, int b) {
return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1;
}
ll modpow(ll a, ll b, ll _mod) {
return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) {
for (auto &vi : vec)
os << vi << " ";
return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << p.F << " " << p.S;
return os;
}
template <typename T> inline istream &operator>>(istream &is, vector<T> &v) {
rep(j, sz(v)) is >> v[j];
return is;
}
template <class T> inline void add(T &a, int b) {
a += b;
if (a >= mod)
a -= mod;
}
void solve();
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(10);
int T;
// cin >> T;
T = 1;
while (T--) {
solve();
}
}
template <typename T> vector<T> lis(vector<T> a) {
vector<T> b;
b.eb(a[0]);
rep3(i, 1, sz(a)) {
int it = lb(b, a[i]);
if (it == sz(b)) {
b.eb(a[i]);
} else {
b[it] = a[i];
}
}
return b;
}
void solve() {
int n;
cin >> n;
vector<ll> a(n + 1);
cin >> a;
ll A = accumulate(all(a), 0LL);
vector<ll> b(n);
cin >> b;
rep(i, n + 1) {
ll c;
if (i) {
c = min(a[i], b[i - 1]);
a[i] -= c;
}
c = min(a[i], b[i]);
a[i] -= c;
b[i] -= c;
}
ll B = accumulate(all(a), 0LL);
cout << A - B << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T> T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <typename T> T pow(T a, int b) {
return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1;
}
ll modpow(ll a, ll b, ll _mod) {
return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) {
for (auto &vi : vec)
os << vi << " ";
return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << p.F << " " << p.S;
return os;
}
template <typename T> inline istream &operator>>(istream &is, vector<T> &v) {
rep(j, sz(v)) is >> v[j];
return is;
}
template <class T> inline void add(T &a, int b) {
a += b;
if (a >= mod)
a -= mod;
}
void solve();
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(10);
int T;
// cin >> T;
T = 1;
while (T--) {
solve();
}
}
template <typename T> vector<T> lis(vector<T> a) {
vector<T> b;
b.eb(a[0]);
rep3(i, 1, sz(a)) {
int it = lb(b, a[i]);
if (it == sz(b)) {
b.eb(a[i]);
} else {
b[it] = a[i];
}
}
return b;
}
void solve() {
int n;
cin >> n;
vector<ll> a(n + 1);
cin >> a;
ll A = accumulate(all(a), 0LL);
vector<ll> b(n);
cin >> b;
rep(i, n + 1) {
ll c;
if (i) {
c = min(a[i], b[i - 1]);
a[i] -= c;
}
if (i != n) {
c = min(a[i], b[i]);
a[i] -= c;
b[i] -= c;
}
}
ll B = accumulate(all(a), 0LL);
cout << A - B << endl;
}
| replace | 109 | 112 | 109 | 114 | 0 | |
p02959 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int ar[1000];
int br[1000];
int main() {
ll n, ans = 0, res = 0, i;
cin >> n;
for (i = 0; i <= n; i++)
cin >> ar[i];
for (i = 0; i < n; i++)
cin >> br[i];
for (i = 0; i < n; i++) {
if (ar[i] >= br[i])
ans = ans + br[i];
else {
ans = ans + ar[i];
res = br[i] - ar[i];
if (res <= ar[i + 1]) {
ar[i + 1] = ar[i + 1] - res;
ans = ans + res;
} else {
ans = ans + ar[i + 1];
ar[i + 1] = 0;
}
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
int ar[1000008];
int br[1000008];
int main() {
ll n, ans = 0, res = 0, i;
cin >> n;
for (i = 0; i <= n; i++)
cin >> ar[i];
for (i = 0; i < n; i++)
cin >> br[i];
for (i = 0; i < n; i++) {
if (ar[i] >= br[i])
ans = ans + br[i];
else {
ans = ans + ar[i];
res = br[i] - ar[i];
if (res <= ar[i + 1]) {
ar[i + 1] = ar[i + 1] - res;
ans = ans + res;
} else {
ans = ans + ar[i + 1];
ar[i + 1] = 0;
}
}
}
cout << ans << endl;
}
| replace | 3 | 5 | 3 | 5 | 0 | |
p02959 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> a(n), b(n);
for (int i = 0; i < n + 1; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
long long total = 0;
for (int i = 0; i < n; i++) {
total += min(a[i], b[i]);
if (0 < b[i] - a[i]) {
total += min(a[i + 1], b[i] - a[i]);
a[i + 1] = max(a[i + 1] - b[i] + a[i], (long long)0);
}
}
cout << total << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> a(n + 1), b(n);
for (int i = 0; i < n + 1; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
long long total = 0;
for (int i = 0; i < n; i++) {
total += min(a[i], b[i]);
if (0 < b[i] - a[i]) {
total += min(a[i + 1], b[i] - a[i]);
a[i + 1] = max(a[i + 1] - b[i] + a[i], (long long)0);
}
}
cout << total << endl;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02959 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
if (a < b)
a = b;
}
int main() {
ll n;
cin >> n;
vector<ll> a(n + 1), b(n);
rep(i, 0, n + 1) cin >> a[i];
rep(i, 0, n) cin >> b[i];
ll ans = 0;
rep(i, 0, n + 1) {
ll x = min(b[i], a[i]);
ans += x, a[i] -= x, b[i] -= x;
ll y = min(b[i], a[i + 1]);
ans += y, a[i + 1] -= y;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
if (a < b)
a = b;
}
int main() {
ll n;
cin >> n;
vector<ll> a(n + 1), b(n);
rep(i, 0, n + 1) cin >> a[i];
rep(i, 0, n) cin >> b[i];
ll ans = 0;
rep(i, 0, n) {
ll x = min(b[i], a[i]);
ans += x, a[i] -= x, b[i] -= x;
ll y = min(b[i], a[i + 1]);
ans += y, a[i + 1] -= y;
}
cout << ans << endl;
} | replace | 24 | 25 | 24 | 25 | 0 | |
p02959 | C++ | Runtime Error | //
// main.cpp
// AC
//
// Created by makinofuya on 2019/07/08.
// Copyright © 2019 makinofuya. All rights reserved.
//
#include <algorithm>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i, n) for (int i = 1; i <= n; i++)
#define out(s) cout << s << endl
int main() {
int n;
cin >> n;
vector<int> a(n + 1);
vector<int> b(n);
rep(i, n + 1) { cin >> a[i]; }
rep(i, n) { cin >> b[i]; }
int x = 0;
ll ans = 0;
rep(i, n) {
x = min(a[i], b[i]);
ans += x;
b[i] -= x;
x = min(a[i + 1], b[i]);
ans += x;
a[i + 1] -= x;
}
cout << ans << endl;
return 0;
}
| //
// main.cpp
// AC
//
// Created by makinofuya on 2019/07/08.
// Copyright © 2019 makinofuya. All rights reserved.
//
#include <algorithm>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i, n) for (int i = 1; i <= n; i++)
#define out(s) cout << s << endl
int main() {
int n;
cin >> n;
vector<int> a(n + 2);
vector<int> b(n + 1);
rep(i, n + 1) { cin >> a[i]; }
rep(i, n) { cin >> b[i]; }
int x = 0;
ll ans = 0;
rep(i, n) {
x = min(a[i], b[i]);
ans += x;
b[i] -= x;
x = min(a[i + 1], b[i]);
ans += x;
a[i + 1] -= x;
}
cout << ans << endl;
return 0;
}
| replace | 21 | 23 | 21 | 23 | 0 | |
p02959 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
int n = 0, a[100000], b[100000];
long long ans = 0;
int main() {
std::cin >> n;
for (int i = 0; i <= n; i++) {
std::cin >> a[i];
}
for (int i = 0; i < n; i++) {
std::cin >> b[i];
}
for (int i = 0; i < n; i++) {
if (a[i] >= b[i]) {
ans += b[i];
} else if (a[i + 1] + a[i] > b[i]) {
ans += b[i];
a[i + 1] = a[i + 1] + a[i] - b[i];
} else {
ans += a[i + 1] + a[i];
a[i + 1] = 0;
}
}
std::cout << ans << std::endl;
} | #include <algorithm>
#include <iostream>
#include <string>
int n = 0, a[100001], b[100000];
long long ans = 0;
int main() {
std::cin >> n;
for (int i = 0; i <= n; i++) {
std::cin >> a[i];
}
for (int i = 0; i < n; i++) {
std::cin >> b[i];
}
for (int i = 0; i < n; i++) {
if (a[i] >= b[i]) {
ans += b[i];
} else if (a[i + 1] + a[i] > b[i]) {
ans += b[i];
a[i + 1] = a[i + 1] + a[i] - b[i];
} else {
ans += a[i + 1] + a[i];
a[i + 1] = 0;
}
}
std::cout << ans << std::endl;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02959 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t n, ans = 0, j;
vector<long long> a(n + 1);
vector<long long> b(n);
cin >> n;
for (int i = 0; i <= n; i++)
cin >> a[i];
for (int j = 0; j < n; j++)
cin >> b[j];
for (int i = 0; i < n; i++) {
j = min(a[i], b[i]);
ans += j;
a[i] -= j;
b[i] -= j;
j = min(a[i + 1], b[i]);
ans += j;
a[i + 1] -= j;
b[i] -= j;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t n, ans = 0, j;
int a[100002], b[100001];
cin >> n;
for (int i = 0; i <= n; i++)
cin >> a[i];
for (int j = 0; j < n; j++)
cin >> b[j];
for (int i = 0; i < n; i++) {
j = min(a[i], b[i]);
ans += j;
a[i] -= j;
b[i] -= j;
j = min(a[i + 1], b[i]);
ans += j;
a[i + 1] -= j;
b[i] -= j;
}
cout << ans << endl;
}
| replace | 4 | 6 | 4 | 5 | -6 | terminate called after throwing an instance of 'std::length_error'
what(): cannot create std::vector larger than max_size()
|
p02959 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ar array
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n + 1), b(n);
for (int &x : a)
cin >> x;
for (int &x : b)
cin >> x;
ll ans = 0;
for (int i = 0; i < n; i++) {
int val = min(a[i], b[i]);
a[i] -= val;
b[i] -= val;
ans += 1ll * val;
if (b[i]) {
val = min(a[i + 1], b[i]);
a[i + 1] -= val;
b[i] -= val;
ans += 1ll * val;
}
}
cout << ans << '\n';
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ar array
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n + 1), b(n);
for (int i = 0; i <= n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
ll ans = 0;
for (int i = 0; i < n; i++) {
int val = min(a[i], b[i]);
a[i] -= val;
b[i] -= val;
ans += 1ll * val;
if (b[i]) {
val = min(a[i + 1], b[i]);
a[i + 1] -= val;
b[i] -= val;
ans += 1ll * val;
}
}
cout << ans << '\n';
} | replace | 15 | 19 | 15 | 19 | 0 | |
p02959 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
vector<ll> a(n + 1), b(n);
for (int i = 0; i < n + 1; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
ll ans = 0;
for (int i = 0; i < n + 1; i++) {
if (i != 0) {
if (b[i - 1] <= a[i]) {
ans += b[i - 1];
a[i] -= b[i - 1];
b[i - 1] = 0;
} else { // a[i] < b[i]
ans += a[i];
b[i - 1] -= a[i];
a[i] = 0;
}
}
if (b[i] <= a[i]) {
ans += b[i];
a[i] -= b[i];
b[i] = 0;
} else { // a[i] < b[i]
ans += a[i];
b[i] -= a[i];
a[i] = 0;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
vector<ll> a(n + 1), b(n);
for (int i = 0; i < n + 1; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
ll ans = 0;
for (int i = 0; i < n + 1; i++) {
if (i != 0) {
if (b[i - 1] <= a[i]) {
ans += b[i - 1];
a[i] -= b[i - 1];
b[i - 1] = 0;
} else { // a[i] < b[i]
ans += a[i];
b[i - 1] -= a[i];
a[i] = 0;
}
}
if (i != n) {
if (b[i] <= a[i]) {
ans += b[i];
a[i] -= b[i];
b[i] = 0;
} else { // a[i] < b[i]
ans += a[i];
b[i] -= a[i];
a[i] = 0;
}
}
}
cout << ans << endl;
return 0;
} | replace | 32 | 40 | 32 | 43 | 0 | |
p02959 | C++ | Runtime Error | #include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
int main() {
long long a, b[2000], c[2000], d, e, f = 0, g = 0, i, cnt = 0;
scanf("%lld", &a);
for (i = 0; i < a + 1; i++) {
scanf("%lld", &b[i]);
g += b[i];
}
for (i = 0; i < a; i++) {
scanf("%lld", &c[i]);
f += c[i];
}
for (i = 0; i < a; i++) {
if (c[i] <= b[i]) {
cnt += c[i];
c[i] = 0;
} else {
cnt += b[i];
c[i] -= b[i];
}
if (c[i] <= b[i + 1]) {
cnt += c[i];
b[i + 1] -= c[i];
} else {
cnt += b[i + 1];
b[i + 1] = 0;
}
}
printf("%lld\n", cnt);
return 0;
}
| #include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
int main() {
long long a, b[100001], c[100000], d, e, f = 0, g = 0, i, cnt = 0;
scanf("%lld", &a);
for (i = 0; i < a + 1; i++) {
scanf("%lld", &b[i]);
g += b[i];
}
for (i = 0; i < a; i++) {
scanf("%lld", &c[i]);
f += c[i];
}
for (i = 0; i < a; i++) {
if (c[i] <= b[i]) {
cnt += c[i];
c[i] = 0;
} else {
cnt += b[i];
c[i] -= b[i];
}
if (c[i] <= b[i + 1]) {
cnt += c[i];
b[i + 1] -= c[i];
} else {
cnt += b[i + 1];
b[i + 1] = 0;
}
}
printf("%lld\n", cnt);
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02959 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[1000], b[1000], an = 0;
cin >> n;
for (int i = 0; i <= n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
for (int i = 0; i < n; i++) {
if (a[i] >= b[i])
an += b[i];
else {
an += a[i];
b[i] -= a[i];
if (a[i + 1] >= b[i]) {
an += b[i];
a[i + 1] -= b[i];
} else {
an += a[i + 1];
a[i + 1] = 0;
}
}
}
cout << an << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a[100001], b[100001], an = 0;
cin >> n;
for (int i = 0; i <= n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
for (int i = 0; i < n; i++) {
if (a[i] >= b[i])
an += b[i];
else {
an += a[i];
b[i] -= a[i];
if (a[i + 1] >= b[i]) {
an += b[i];
a[i + 1] -= b[i];
} else {
an += a[i + 1];
a[i + 1] = 0;
}
}
}
cout << an << endl;
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02959 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
signed main() {
int n;
int a[10010], b[10010];
cin >> n;
for (int i = 0; i <= n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
int cnt = 0;
for (int i = 0; i < n; i++) {
if (a[i] <= b[i]) {
cnt += a[i];
cnt += min(a[i + 1], b[i] - a[i]);
a[i + 1] -= min(a[i + 1], b[i] - a[i]);
} else {
cnt += b[i];
}
}
cout << cnt << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
signed main() {
int n;
int a[100010], b[100010];
cin >> n;
for (int i = 0; i <= n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
int cnt = 0;
for (int i = 0; i < n; i++) {
if (a[i] <= b[i]) {
cnt += a[i];
cnt += min(a[i + 1], b[i] - a[i]);
a[i + 1] -= min(a[i + 1], b[i] - a[i]);
} else {
cnt += b[i];
}
}
cout << cnt << endl;
} | replace | 15 | 16 | 15 | 16 | 0 | |
p02959 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void) {
int n;
cin >> n;
vector<int> a(n + 1), b(n);
for (int i = 1; i <= n + 1; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
cin >> b[i];
ll sum = 0;
for (int i = 1; i <= n; i++) {
int left = min(a[i], b[i]);
sum += left;
a[i] -= left;
b[i] -= left;
int right = min(a[i + 1], b[i]);
sum += right;
a[i + 1] -= right;
b[i] -= right;
}
cout << sum << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void) {
int n;
cin >> n;
int a[n], b[n + 1];
// vector<int> a(n+1), b(n);
for (int i = 1; i <= n + 1; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
cin >> b[i];
ll sum = 0;
for (int i = 1; i <= n; i++) {
int left = min(a[i], b[i]);
sum += left;
a[i] -= left;
b[i] -= left;
int right = min(a[i + 1], b[i]);
sum += right;
a[i + 1] -= right;
b[i] -= right;
}
cout << sum << endl;
}
| replace | 6 | 7 | 6 | 8 | 0 | |
p02959 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long a[20000 + 5];
long long b[20000 + 5];
int main() {
int n;
cin >> n;
for (int i = 0; i <= n; i++)
cin >> b[i];
long long sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (b[i] >= a[i]) {
sum = sum + a[i];
} else if ((b[i] + b[i + 1]) > a[i]) {
sum = sum + a[i];
b[i + 1] = (b[i + 1] + b[i] - a[i]);
} else {
sum = sum + b[i] + b[i + 1];
b[i + 1] = 0;
}
}
cout << sum << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long a[100000 + 5];
long long b[100000 + 5];
int main() {
int n;
cin >> n;
for (int i = 0; i <= n; i++)
cin >> b[i];
long long sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (b[i] >= a[i]) {
sum = sum + a[i];
} else if ((b[i] + b[i + 1]) > a[i]) {
sum = sum + a[i];
b[i + 1] = (b[i + 1] + b[i] - a[i]);
} else {
sum = sum + b[i] + b[i + 1];
b[i + 1] = 0;
}
}
cout << sum << "\n";
return 0;
} | replace | 2 | 4 | 2 | 4 | 0 | |
p02959 | C++ | Runtime Error | #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <iostream> // cout, endl, cin
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
using namespace std;
int main() {
int a[51], sum, n, flag = 0, m, count = 0;
cin >> n;
for (int i = 0; i <= n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> m;
if (a[i] >= m) {
count = count + m;
continue;
} else {
if (m >= a[i] + a[i + 1]) {
count = count + a[i] + a[i + 1];
a[i + 1] = 0;
} else {
a[i + 1] = a[i + 1] - (m - a[i]);
count = count + m;
}
}
}
cout << count << endl;
return 0;
}
| #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <iostream> // cout, endl, cin
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
using namespace std;
int main() {
long a[100002], sum, n, flag = 0, m, count = 0;
cin >> n;
for (int i = 0; i <= n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> m;
if (a[i] >= m) {
count = count + m;
continue;
} else {
if (m >= a[i] + a[i + 1]) {
count = count + a[i] + a[i + 1];
a[i + 1] = 0;
} else {
a[i + 1] = a[i + 1] - (m - a[i]);
count = count + m;
}
}
}
cout << count << endl;
return 0;
}
| replace | 21 | 22 | 21 | 22 | 0 | |
p02959 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
int main() {
int N;
cin >> N;
vector<long long int> A(N), B(N);
for (int i = 1; i <= N + 1; i++)
cin >> A[i];
for (int i = 1; i <= N; i++)
cin >> B[i];
long long int count = 0;
for (int i = 1; i <= N; i++) {
bool flag = 0;
int disc1 = A[i] - B[i];
if (disc1 >= 0) {
count += B[i];
flag = 1;
} else {
count += A[i];
B[i] -= A[i];
}
int disc2 = A[i + 1] - B[i];
if (flag == 0) {
if (disc2 >= 0) {
count += B[i];
A[i + 1] -= B[i];
} else {
count += A[i + 1];
A[i + 1] = 0;
}
}
}
OP(count)
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
int main() {
int N;
cin >> N;
int A[N], B[N];
for (int i = 1; i <= N + 1; i++)
cin >> A[i];
for (int i = 1; i <= N; i++)
cin >> B[i];
long long int count = 0;
for (int i = 1; i <= N; i++) {
bool flag = 0;
int disc1 = A[i] - B[i];
if (disc1 >= 0) {
count += B[i];
flag = 1;
} else {
count += A[i];
B[i] -= A[i];
}
int disc2 = A[i + 1] - B[i];
if (flag == 0) {
if (disc2 >= 0) {
count += B[i];
A[i + 1] -= B[i];
} else {
count += A[i + 1];
A[i + 1] = 0;
}
}
}
OP(count)
return 0;
}
| replace | 12 | 13 | 12 | 13 | -6 | free(): invalid pointer
|
p02959 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
long long int n, A[10000], B[10000], c = 0;
cin >> n;
for (int i = 0; i < n + 1; ++i) {
cin >> A[i];
}
for (int i = 0; i < n; ++i) {
cin >> B[i];
}
for (int i = 0; i < n; ++i) {
long long int h = min(A[i], B[i]);
A[i] -= h;
B[i] -= h;
c += h;
h = min(A[i + 1], B[i]);
A[i + 1] -= h;
c += h;
}
cout << c;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
long long int n, A[100007], B[100007], c = 0;
cin >> n;
for (int i = 0; i < n + 1; ++i) {
cin >> A[i];
}
for (int i = 0; i < n; ++i) {
cin >> B[i];
}
for (int i = 0; i < n; ++i) {
long long int h = min(A[i], B[i]);
A[i] -= h;
B[i] -= h;
c += h;
h = min(A[i + 1], B[i]);
A[i + 1] -= h;
c += h;
}
cout << c;
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02959 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (n); i++)
#define ll long long
int main() {
int n;
cin >> n;
int a[n + 1], b[n];
rep(i, 0, n + 1) cin >> a[i];
rep(i, 0, n) cin >> b[i];
ll ans = 0;
int f[n][n + 1];
f[0][0] = min(a[0], b[0]);
f[0][1] = min(a[1], b[0] - f[0][0]);
ans += f[0][0];
ans += f[0][1];
rep(i, 1, n) {
f[i][i] = min(a[i], b[i] - f[i - 1][i]);
f[i][i + 1] = min(a[i + 1], b[i] - f[i][i]);
ans += f[i][i];
ans += f[i][i + 1];
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (n); i++)
#define ll long long
int main() {
int n;
cin >> n;
int a[n + 1], b[n];
rep(i, 0, n + 1) cin >> a[i];
rep(i, 0, n) cin >> b[i];
ll ans = 0;
rep(i, 0, n) {
int left = min(a[i], b[i]);
ans += left;
a[i] -= left;
b[i] -= left;
int right = min(a[i + 1], b[i]);
ans += right;
a[i + 1] -= right;
b[i] -= right;
}
cout << ans << endl;
return 0;
}
| replace | 13 | 23 | 13 | 23 | 0 | |
p02959 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<long long> A(N + 1);
vector<long long> B(N);
for (int i = 0; i < N + 1; i++) {
cin >> A[i];
}
for (int i = 0; i < N; i++) {
cin >> B[i];
}
int ans = 0;
for (int i = 0; i < N + 1; i++) {
if (A[i] < B[i]) {
ans += A[i];
B[i] = B[i] - A[i];
A[i] = 0;
if (B[i] < A[i + 1]) {
ans += B[i];
A[i + 1] = A[i + 1] - B[i];
B[i] = 0;
} else if (B[i] >= A[i + 1]) {
ans += A[i + 1];
B[i] = B[i] - A[i + 1];
A[i + 1] = 0;
}
}
if (A[i] >= B[i]) {
ans += B[i];
A[i] = A[i] - B[i];
B[i] = 0;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<long long> A(N + 1);
vector<long long> B(N);
for (int i = 0; i < N + 1; i++) {
cin >> A[i];
}
for (int i = 0; i < N; i++) {
cin >> B[i];
}
long long ans = 0;
for (int i = 0; i < N; i++) {
if (A[i] < B[i]) {
ans += A[i];
B[i] = B[i] - A[i];
A[i] = 0;
if (B[i] < A[i + 1]) {
ans += B[i];
A[i + 1] = A[i + 1] - B[i];
B[i] = 0;
} else if (B[i] >= A[i + 1]) {
ans += A[i + 1];
B[i] = B[i] - A[i + 1];
A[i + 1] = 0;
}
}
if (A[i] >= B[i]) {
ans += B[i];
A[i] = A[i] - B[i];
B[i] = 0;
}
}
cout << ans << endl;
}
| replace | 15 | 17 | 15 | 17 | 0 | |
p02959 | C++ | Runtime Error | // Ruthless Coding
#include <bits/stdc++.h>
#define uni(x) (x).resize(unique(all(x)) - (x).begin())
#define fprint(v) \
for (auto x : v) \
cout << x << ' '
#define ALL(x) (x).begin(), (x).end()
#define MP(x, y) make_pair(x, y)
#define PII pair<int, int>
#define SZ(x) int((x).size())
#define PB(x) push_back(x)
#define ll long long
#define S second
#define F first
#define nl '\n'
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x)
cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;
const int N = 2e5 + 5;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<ll> a(n + 1), b(n);
for (auto &x : a) {
cin >> x;
}
for (auto &x : b) {
cin >> x;
}
ll ans = min(a[0], b[0]);
b[0] -= min(a[0], b[0]);
for (int i = 1; i < n + 1; i++) {
if (a[i] > 0) {
if (b[i - 1] > 0) {
ans += min(a[i], b[i - 1]);
a[i] -= min(a[i], b[i - 1]);
}
if (b[i] > 0) {
ans += min(a[i], b[i]);
b[i] -= min(a[i], b[i]);
}
}
}
cout << ans;
return 0;
}
/*
*** Most Impo.. -> check base case always
1. Overflow Check (*, +)
2. Index check (0 - based or 1 - based)
3. Check for n = 1, 2, 3, 4....
4. Corner Cases
*/ | // Ruthless Coding
#include <bits/stdc++.h>
#define uni(x) (x).resize(unique(all(x)) - (x).begin())
#define fprint(v) \
for (auto x : v) \
cout << x << ' '
#define ALL(x) (x).begin(), (x).end()
#define MP(x, y) make_pair(x, y)
#define PII pair<int, int>
#define SZ(x) int((x).size())
#define PB(x) push_back(x)
#define ll long long
#define S second
#define F first
#define nl '\n'
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x)
cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;
const int N = 2e5 + 5;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<ll> a(n + 1), b(n);
for (auto &x : a) {
cin >> x;
}
for (auto &x : b) {
cin >> x;
}
ll ans = min(a[0], b[0]);
b[0] -= min(a[0], b[0]);
for (int i = 1; i < n + 1; i++) {
if (a[i] > 0) {
if (b[i - 1] > 0) {
ans += min(a[i], b[i - 1]);
a[i] -= min(a[i], b[i - 1]);
}
if (i < n && b[i] > 0) {
ans += min(a[i], b[i]);
b[i] -= min(a[i], b[i]);
}
}
}
cout << ans;
return 0;
}
/*
*** Most Impo.. -> check base case always
1. Overflow Check (*, +)
2. Index check (0 - based or 1 - based)
3. Check for n = 1, 2, 3, 4....
4. Corner Cases
*/ | replace | 84 | 85 | 84 | 85 | 0 | |
p02959 | C++ | Runtime Error | #include <iostream>
using namespace std;
int n, s[100000], t[100000];
long long ans;
int main(void) {
cin >> n;
for (int i = 0; i <= n; i++)
cin >> s[i];
for (int i = 0; i < n; i++)
cin >> t[i];
for (int i = 0; i < n; i++) {
ans += min(t[i], s[i]);
t[i] = max(t[i] - s[i], 0);
ans += min(t[i], s[i + 1]);
s[i + 1] = max(s[i + 1] - t[i], 0);
}
cout << ans << endl;
}
| #include <iostream>
using namespace std;
int n, s[100001], t[100000];
long long ans;
int main(void) {
cin >> n;
for (int i = 0; i <= n; i++)
cin >> s[i];
for (int i = 0; i < n; i++)
cin >> t[i];
for (int i = 0; i < n; i++) {
ans += min(t[i], s[i]);
t[i] = max(t[i] - s[i], 0);
ans += min(t[i], s[i + 1]);
s[i + 1] = max(s[i + 1] - t[i], 0);
}
cout << ans << endl;
}
| replace | 2 | 3 | 2 | 3 | 0 | |
p02959 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, i##_len = int(n); i < i##_len; ++i)
#define rep(i, a, b) for (int i = int(a); i < int(b); ++i)
#define All(x) (x).begin(), (x).end()
#define rAll(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
int main() {
int N;
cin >> N;
vector<ll> A(N), B(N);
REP(i, N + 1) cin >> A[i];
REP(i, N) cin >> B[i];
ll ans = 0;
REP(i, N) {
ans += min(A[i], B[i]);
B[i] -= A[i];
ans += min(A[i + 1], max(B[i], 0LL));
A[i + 1] -= min(A[i + 1], max(B[i], 0LL));
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, i##_len = int(n); i < i##_len; ++i)
#define rep(i, a, b) for (int i = int(a); i < int(b); ++i)
#define All(x) (x).begin(), (x).end()
#define rAll(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
int main() {
int N;
cin >> N;
vector<ll> A(N + 1), B(N);
REP(i, N + 1) cin >> A[i];
REP(i, N) cin >> B[i];
ll ans = 0;
REP(i, N) {
ans += min(A[i], B[i]);
B[i] -= A[i];
ans += min(A[i + 1], max(B[i], 0LL));
A[i + 1] -= min(A[i + 1], max(B[i], 0LL));
}
cout << ans << endl;
}
| replace | 11 | 12 | 11 | 12 | 0 | |
p02959 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
int n = 0, a[100000], b[100000], ans = 0;
int main() {
std::cin >> n;
for (int i = 0; i <= n; i++) {
std::cin >> a[i];
}
for (int i = 0; i < n; i++) {
std::cin >> b[i];
}
for (int i = 0; i < n; i++) {
if (a[i] >= b[i]) {
ans += b[i];
} else if (a[i + 1] + a[i] > b[i]) {
ans += b[i];
a[i + 1] = a[i + 1] + a[i] - b[i];
} else {
ans += a[i + 1] + a[i];
a[i + 1] = 0;
}
}
std::cout << ans << std::endl;
} | #include <algorithm>
#include <iostream>
#include <string>
int n = 0, a[100001], b[100000];
long long ans = 0;
int main() {
std::cin >> n;
for (int i = 0; i <= n; i++) {
std::cin >> a[i];
}
for (int i = 0; i < n; i++) {
std::cin >> b[i];
}
for (int i = 0; i < n; i++) {
if (a[i] >= b[i]) {
ans += b[i];
} else if (a[i + 1] + a[i] > b[i]) {
ans += b[i];
a[i + 1] = a[i + 1] + a[i] - b[i];
} else {
ans += a[i + 1] + a[i];
a[i + 1] = 0;
}
}
std::cout << ans << std::endl;
} | replace | 4 | 5 | 4 | 6 | 0 | |
p02959 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int N = 0, ans = 0, a = 0;
int A[10001] = {0};
int B[10001] = {0};
cin >> N;
for (int i = 0; i < N + 1; i++) {
cin >> A[i];
}
for (int i = 0; i < N; i++) {
cin >> B[i];
}
for (int i = 0; i < N; i++) {
a = A[i];
if (A[i] - B[i] < 0) {
ans += A[i];
A[i] = 0;
if (A[i + 1] - (B[i] - a) < 0) {
ans += A[i + 1];
A[i + 1] = 0;
} else {
A[i + 1] -= B[i] - a;
ans += B[i] - a;
}
} else if (A[i] - B[i] >= 0) {
A[i] -= B[i];
ans += B[i];
}
}
/*for (int i = 0; i < N + 1; i++) {
cout << A[i] << endl;
}*/
cout << ans;
}
| #include <iostream>
using namespace std;
int main() {
long long int N = 0, ans = 0, a = 0;
long long int A[100001] = {0};
long long int B[100000] = {0};
cin >> N;
for (int i = 0; i < N + 1; i++) {
cin >> A[i];
}
for (int i = 0; i < N; i++) {
cin >> B[i];
}
for (int i = 0; i < N; i++) {
a = A[i];
if (A[i] - B[i] < 0) {
ans += A[i];
A[i] = 0;
if (A[i + 1] - (B[i] - a) < 0) {
ans += A[i + 1];
A[i + 1] = 0;
} else {
A[i + 1] -= B[i] - a;
ans += B[i] - a;
}
} else if (A[i] - B[i] >= 0) {
A[i] -= B[i];
ans += B[i];
}
}
/*for (int i = 0; i < N + 1; i++) {
cout << A[i] << endl;
}*/
cout << ans;
} | replace | 3 | 6 | 3 | 6 | 0 | |
p02959 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) > (0) ? (a) : -(a))
#define rep(i, a, b) for (int(i) = int(a); (i) < int(b); (i)++)
#define rrep(i, a, b) for (int(i) = int(a); (i) >= int(b); (i)--)
#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "
#define INF 1e9 + 1
#define MOD 1e9 + 7
#define INF64 1e18 + 1
#define F first
#define S second
#define Pii pair<int, int>
#define Pll pair<long long, long long>
#define Piii pair<int, pair<int, int>>
#define Plll pair<long long, pair<long long, long long>>
#define Vll(a, b, c) vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a, b, c, d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))
#define MAX_N 1000000
int main(void) {
int N;
cin >> N;
vector<long long int> A(N);
vector<long long int> B(N);
rep(i, 0, N + 1) { cin >> A[i]; }
rep(i, 0, N) { cin >> B[i]; }
long long int ans = 0;
rep(i, 0, N) {
if (A[i] >= B[i]) {
ans += B[i];
} else {
B[i] -= A[i];
ans += A[i];
if (A[i + 1] >= B[i]) {
A[i + 1] -= B[i];
ans += B[i];
} else {
ans += A[i + 1];
A[i + 1] = 0;
}
}
}
put(ans);
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) > (0) ? (a) : -(a))
#define rep(i, a, b) for (int(i) = int(a); (i) < int(b); (i)++)
#define rrep(i, a, b) for (int(i) = int(a); (i) >= int(b); (i)--)
#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "
#define INF 1e9 + 1
#define MOD 1e9 + 7
#define INF64 1e18 + 1
#define F first
#define S second
#define Pii pair<int, int>
#define Pll pair<long long, long long>
#define Piii pair<int, pair<int, int>>
#define Plll pair<long long, pair<long long, long long>>
#define Vll(a, b, c) vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a, b, c, d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))
#define MAX_N 1000000
int main(void) {
int N;
cin >> N;
vector<long long int> A(N + 1);
vector<long long int> B(N);
rep(i, 0, N + 1) { cin >> A[i]; }
rep(i, 0, N) { cin >> B[i]; }
long long int ans = 0;
rep(i, 0, N) {
if (A[i] >= B[i]) {
ans += B[i];
} else {
B[i] -= A[i];
ans += A[i];
if (A[i + 1] >= B[i]) {
A[i + 1] -= B[i];
ans += B[i];
} else {
ans += A[i + 1];
A[i + 1] = 0;
}
}
}
put(ans);
return 0;
}
| replace | 38 | 39 | 38 | 39 | 0 | |
p02959 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define EPS (1e-7)
#define INF (2e9)
using namespace std;
typedef long long int ll;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQI;
typedef priority_queue<int, vector<int>, greater<int>> PQSI;
typedef priority_queue<ll> PQL;
typedef priority_queue<ll, vector<ll>, greater<ll>> PQSL;
const int MOD = 1000000007;
struct mint {
int n;
mint(int n_ = 0) : n(n_) {}
};
mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
mint operator+(mint a, mint b) {
int x = a.n + b.n;
return x - (x >= MOD) * MOD;
}
mint operator-(mint a, mint b) {
int x = a.n - b.n;
return x + (x < 0) * MOD;
}
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }
vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};
void check_fact(int n) {
for (int i = I_.size(); i <= n; i++) {
I_.push_back(I_[MOD % i] * (MOD - MOD / i));
F_.push_back(F_[i - 1] * i);
R_.push_back(R_[i - 1] * I_[i]);
}
}
mint I(int n) {
check_fact(abs(n));
return n >= 0 ? I_[n] : -I_[n];
}
mint F(int n) {
check_fact(n);
return n < 0 ? 0 : F_[n];
}
mint R(int n) {
check_fact(n);
return n < 0 ? 0 : R_[n];
}
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }
template <typename T> T gcd(T x, T y) {
if (y == 0)
return x;
else
return gcd(y, x % y);
}
template <typename T> T lcm(T x, T y) { return (x / gcd(x, y)) * y; }
int N;
ll A[100000], B[100000];
int main(void) {
cin >> N;
for (int i = 0; i < N + 1; i++)
scanf("%lld", &A[i]);
for (int i = 0; i < N; i++)
scanf("%lld", &B[i]);
ll monster = 0;
rep(i, N) {
if (A[i] < B[i]) {
if (A[i] + A[i + 1] >= B[i]) {
A[i + 1] = A[i + 1] - (B[i] - A[i]);
monster += B[i];
} else {
monster += A[i] + A[i + 1];
A[i + 1] = 0;
}
} else {
monster += B[i];
}
}
cout << monster << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define EPS (1e-7)
#define INF (2e9)
using namespace std;
typedef long long int ll;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQI;
typedef priority_queue<int, vector<int>, greater<int>> PQSI;
typedef priority_queue<ll> PQL;
typedef priority_queue<ll, vector<ll>, greater<ll>> PQSL;
const int MOD = 1000000007;
struct mint {
int n;
mint(int n_ = 0) : n(n_) {}
};
mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
mint operator+(mint a, mint b) {
int x = a.n + b.n;
return x - (x >= MOD) * MOD;
}
mint operator-(mint a, mint b) {
int x = a.n - b.n;
return x + (x < 0) * MOD;
}
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }
vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};
void check_fact(int n) {
for (int i = I_.size(); i <= n; i++) {
I_.push_back(I_[MOD % i] * (MOD - MOD / i));
F_.push_back(F_[i - 1] * i);
R_.push_back(R_[i - 1] * I_[i]);
}
}
mint I(int n) {
check_fact(abs(n));
return n >= 0 ? I_[n] : -I_[n];
}
mint F(int n) {
check_fact(n);
return n < 0 ? 0 : F_[n];
}
mint R(int n) {
check_fact(n);
return n < 0 ? 0 : R_[n];
}
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }
template <typename T> T gcd(T x, T y) {
if (y == 0)
return x;
else
return gcd(y, x % y);
}
template <typename T> T lcm(T x, T y) { return (x / gcd(x, y)) * y; }
int N;
ll A[100001], B[100000];
int main(void) {
cin >> N;
for (int i = 0; i < N + 1; i++)
scanf("%lld", &A[i]);
for (int i = 0; i < N; i++)
scanf("%lld", &B[i]);
ll monster = 0;
rep(i, N) {
if (A[i] < B[i]) {
if (A[i] + A[i + 1] >= B[i]) {
A[i + 1] = A[i + 1] - (B[i] - A[i]);
monster += B[i];
} else {
monster += A[i] + A[i + 1];
A[i + 1] = 0;
}
} else {
monster += B[i];
}
}
cout << monster << endl;
return 0;
}
| replace | 80 | 81 | 80 | 81 | 0 | |
p02959 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--)
#define ALL(obj) (obj).begin(), (obj).end()
int main(void) {
ll N;
ll ans;
cin >> N;
vector<ll> A(N + 1);
rep(i, N + 1) cin >> A[i];
vector<ll> B(N);
rep(i, N) cin >> B[i];
ans = 0;
if (A[0] - B[0] > 0) {
ans += B[0];
A[0] -= B[0];
B[0] = 0;
} else {
ans += A[0];
B[0] -= A[0];
A[0] = 0;
}
if (A[1] - B[0] > 0) {
ans += B[0];
A[1] -= B[0];
B[0] = 0;
} else {
ans += A[1];
B[0] -= A[1];
A[1] = 0;
}
rep2(i, 1, N + 1) {
if (A[i] - B[i] > 0) {
ans += B[i];
A[i] -= B[i];
B[i] = 0;
} else {
ans += A[i];
B[i] -= A[i];
A[i] = 0;
}
if (A[i + 1] - B[i] > 0) {
ans += B[i];
A[i + 1] -= B[i];
B[i] = 0;
} else {
ans += A[i + 1];
B[i] -= A[i + 1];
A[i + 1] = 0;
}
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--)
#define ALL(obj) (obj).begin(), (obj).end()
int main(void) {
ll N;
ll ans;
cin >> N;
vector<ll> A(N + 1);
rep(i, N + 1) cin >> A[i];
vector<ll> B(N);
rep(i, N) cin >> B[i];
ans = 0;
if (A[0] - B[0] > 0) {
ans += B[0];
A[0] -= B[0];
B[0] = 0;
} else {
ans += A[0];
B[0] -= A[0];
A[0] = 0;
}
if (A[1] - B[0] > 0) {
ans += B[0];
A[1] -= B[0];
B[0] = 0;
} else {
ans += A[1];
B[0] -= A[1];
A[1] = 0;
}
rep2(i, 1, N) {
if (A[i] - B[i] > 0) {
ans += B[i];
A[i] -= B[i];
B[i] = 0;
} else {
ans += A[i];
B[i] -= A[i];
A[i] = 0;
}
if (A[i + 1] - B[i] > 0) {
ans += B[i];
A[i + 1] -= B[i];
B[i] = 0;
} else {
ans += A[i + 1];
B[i] -= A[i + 1];
A[i + 1] = 0;
}
}
cout << ans << endl;
return 0;
}
| replace | 45 | 46 | 45 | 46 | 0 | |
p02959 | C++ | Runtime Error | #pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(), (V).end()
#define SORT(V) sort(ALL(V)) // 小さい方からソート
#define REV(V) reverse(ALL(V)) // リバース
#define RSORT(V) REV(SORT(V)) // 大きい方からソート
#define NPN(V) next_permutation(ALL(V)) // 順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define RAPID \
cin.tie(0); \
ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a, b) cin >> a >> b
#define IN3(a, b, c) cin >> a >> b >> c
#define VIN(V) \
for (int i = 0; i < (V).size(); i++) { \
cin >> (V).at(i); \
}
#define OUT(n) cout << n << endl
#define VOUT(V) \
REP(i, (V).size()) { cout << (V).at(i) << endl; }
#define VOUT2(V) \
REP(i, (V).size()) { cout << (V).at(i) << " "; } \
cout << endl;
// 型マクロ定義
#define int long long
#define P pair<ll, ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll, ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue < ll, V, greater<ll>
//
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } // 最小公倍数
// デフォルト変数定義
int n, m, a, b, c = 0, x, y, z;
double d, e, f;
string s, t;
//
signed main() {
RAPID;
IN(n);
Vi A(n + 1);
Vi B(n);
VIN(A)
VIN(B)
REP(i, n + 1) {
if (A.at(i) <= B.at(i)) {
c += A.at(i);
B.at(i) -= A.at(i);
A.at(i) = 0;
} else {
c += B.at(i);
A.at(i) -= B.at(i);
B.at(i) = 0;
}
if (A.at(i + 1) <= B.at(i)) {
c += A.at(i + 1);
B.at(i) -= A.at(i + 1);
A.at(i + 1) = 0;
} else {
c += B.at(i);
A.at(i + 1) -= B.at(i);
B.at(i) = 0;
}
}
OUT(c);
} | #pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(), (V).end()
#define SORT(V) sort(ALL(V)) // 小さい方からソート
#define REV(V) reverse(ALL(V)) // リバース
#define RSORT(V) REV(SORT(V)) // 大きい方からソート
#define NPN(V) next_permutation(ALL(V)) // 順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define RAPID \
cin.tie(0); \
ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a, b) cin >> a >> b
#define IN3(a, b, c) cin >> a >> b >> c
#define VIN(V) \
for (int i = 0; i < (V).size(); i++) { \
cin >> (V).at(i); \
}
#define OUT(n) cout << n << endl
#define VOUT(V) \
REP(i, (V).size()) { cout << (V).at(i) << endl; }
#define VOUT2(V) \
REP(i, (V).size()) { cout << (V).at(i) << " "; } \
cout << endl;
// 型マクロ定義
#define int long long
#define P pair<ll, ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll, ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue < ll, V, greater<ll>
//
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } // 最小公倍数
// デフォルト変数定義
int n, m, a, b, c = 0, x, y, z;
double d, e, f;
string s, t;
//
signed main() {
RAPID;
IN(n);
Vi A(n + 1);
Vi B(n);
VIN(A)
VIN(B)
REP(i, n) {
if (A.at(i) <= B.at(i)) {
c += A.at(i);
B.at(i) -= A.at(i);
A.at(i) = 0;
} else {
c += B.at(i);
A.at(i) -= B.at(i);
B.at(i) = 0;
}
if (A.at(i + 1) <= B.at(i)) {
c += A.at(i + 1);
B.at(i) -= A.at(i + 1);
A.at(i + 1) = 0;
} else {
c += B.at(i);
A.at(i + 1) -= B.at(i);
B.at(i) = 0;
}
}
OUT(c);
} | replace | 69 | 70 | 69 | 70 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 2) >= this->size() (which is 2)
|
p02959 | C++ | Runtime Error | #include <iostream>
#include <deque>
#include <stdio.h>
#include <cstdio>
#include <algorithm>
#include <bits/stdc++.h>
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define sp << " "
#define nw << "\n"
#define ca "Case " << tc++ << ": "
#define IOS \
ios_base::sync_with_stdio(0); \
cin.tie(0)
#define ull unsigned LL
#define check cout << "* ";
#define show_vector(i) \
for (int q = 0; q < i.size(); q++) { \
cout << i[q] << " "; \
}
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define N_MAX 26
#define rep(i, a, b) for (int i = a; i < b; i++)
const int inf = 1 << 30;
const long long int INF = 1e10;
const int MOD = 1e9 + 7;
const int maxn = 1e5 + 10;
int a[200005], b[1000005];
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
/*
int ck_prime(int n)
{
int coun;
coun=0;
if(n>1){
for(int i=2;i*i<=n;i++){
if( n%i==0 ){
coun++;
break;
}
}
}
if(n==1){
coun=coun;
}
if(coun==0){
return 1; // n is prime
}
return 0;
}
*/
int main() {
int n;
cin >> n;
vector<int> a(n), b(n - 1);
rep(i, 0, n + 1) cin >> a[i];
rep(i, 0, n) cin >> b[i];
long long int sum = 0;
rep(i, 0, n) {
int x = min(a[i], b[i]);
sum += x;
a[i] = a[i] - x;
b[i] = b[i] - x;
x = min(a[i + 1], b[i]);
sum += x;
a[i + 1] = a[i + 1] - x;
b[i] = b[i] - x;
}
cout << sum nw;
}
| #include <iostream>
#include <deque>
#include <stdio.h>
#include <cstdio>
#include <algorithm>
#include <bits/stdc++.h>
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define sp << " "
#define nw << "\n"
#define ca "Case " << tc++ << ": "
#define IOS \
ios_base::sync_with_stdio(0); \
cin.tie(0)
#define ull unsigned LL
#define check cout << "* ";
#define show_vector(i) \
for (int q = 0; q < i.size(); q++) { \
cout << i[q] << " "; \
}
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define N_MAX 26
#define rep(i, a, b) for (int i = a; i < b; i++)
const int inf = 1 << 30;
const long long int INF = 1e10;
const int MOD = 1e9 + 7;
const int maxn = 1e5 + 10;
int a[200005], b[1000005];
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
/*
int ck_prime(int n)
{
int coun;
coun=0;
if(n>1){
for(int i=2;i*i<=n;i++){
if( n%i==0 ){
coun++;
break;
}
}
}
if(n==1){
coun=coun;
}
if(coun==0){
return 1; // n is prime
}
return 0;
}
*/
int main() {
int n;
cin >> n;
vector<int> a(n + 1), b(n);
rep(i, 0, n + 1) cin >> a[i];
rep(i, 0, n) cin >> b[i];
long long int sum = 0;
rep(i, 0, n) {
int x = min(a[i], b[i]);
sum += x;
a[i] = a[i] - x;
b[i] = b[i] - x;
x = min(a[i + 1], b[i]);
sum += x;
a[i + 1] = a[i + 1] - x;
b[i] = b[i] - x;
}
cout << sum nw;
}
| replace | 67 | 69 | 67 | 68 | 0 | |
p02959 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
int main() {
size_t n;
size_t cnt = 0;
std::cin >> n;
std::vector<size_t> a(n + 1), b(n);
for (auto &&e : a) {
std::cin >> e;
}
for (auto &&e : b) {
std::cin >> e;
}
for (size_t i = 0; i < n; i++) {
if (a[i] >= b[i]) {
cnt += b[i];
} else {
cnt += a[i];
b[i] -= a[i];
if (a[i + 1] >= b[i]) {
a[i + 1] -= b[i];
cnt += b[i];
} else {
cnt += a[i + i];
a[i + 1] = 0;
}
}
}
std::cout << cnt << std::endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
int main() {
size_t n;
size_t cnt = 0;
std::cin >> n;
std::vector<size_t> a(n + 1), b(n);
for (auto &&e : a) {
std::cin >> e;
}
for (auto &&e : b) {
std::cin >> e;
}
for (size_t i = 0; i < n; i++) {
if (a[i] >= b[i]) {
cnt += b[i];
} else {
cnt += a[i];
b[i] -= a[i];
if (a[i + 1] >= b[i]) {
a[i + 1] -= b[i];
cnt += b[i];
} else {
cnt += a[i + 1];
a[i + 1] = 0;
}
}
}
std::cout << cnt << std::endl;
return 0;
}
| replace | 33 | 34 | 33 | 34 | 0 | |
p02959 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
ll N;
cin >> N;
vector<ll> B(N + 1);
vector<ll> A(N);
ll ans = 0;
rep(i, N + 1) cin >> A[i];
rep(i, N) cin >> B[i];
for (int i = 0; i < N; i++) {
if (A[i] >= B[i])
ans += B[i]; // B[i]だけ倒して町にはモンスターが残る
else if (A[i] < B[i]) {
ans += A[i]; // 町にいるモンスターは全滅
B[i] -= A[i]; // 倒せる残りの数を更新
if (A[i + 1] >= B[i]) { // 次の街にいるモンスターのほうがキャパより多い
ans += B[i];
A[i + 1] -= B[i];
} else if (A[i + 1] < B[i]) { // 次の街も全滅させられる
ans += A[i + 1];
A[i + 1] = 0;
}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
ll N;
cin >> N;
vector<ll> B(N + 2);
vector<ll> A(N + 1);
ll ans = 0;
rep(i, N + 1) cin >> A[i];
rep(i, N) cin >> B[i];
for (int i = 0; i < N; i++) {
if (A[i] >= B[i])
ans += B[i]; // B[i]だけ倒して町にはモンスターが残る
else if (A[i] < B[i]) {
ans += A[i]; // 町にいるモンスターは全滅
B[i] -= A[i]; // 倒せる残りの数を更新
if (A[i + 1] >= B[i]) { // 次の街にいるモンスターのほうがキャパより多い
ans += B[i];
A[i + 1] -= B[i];
} else if (A[i + 1] < B[i]) { // 次の街も全滅させられる
ans += A[i + 1];
A[i + 1] = 0;
}
}
}
cout << ans << endl;
} | replace | 9 | 11 | 9 | 11 | 0 | |
p02959 | C++ | Runtime Error | #include <algorithm>
#include <chrono>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
using lli = long long int;
using Vint = std::vector<int>;
using Vlli = std::vector<lli>;
using Wint = std::vector<Vint>;
using Wlli = std::vector<Vlli>;
using Vbool = std::vector<bool>;
using Wbool = std::vector<Vbool>;
using pii = std::pair<int, int>;
using pll = std::pair<lli, lli>;
template <class T> using Vec = std::vector<T>;
template <class T> using Wec = Vec<Vec<T>>;
constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const std::vector<std::pair<int, int>> DXDY = {
{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
constexpr char BR = '\n';
#define DEBUG(x) std::cerr << #x << " = " << x << '\n';
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define FOReq(i, a, b) for (int(i) = (a); (i) <= (b); ++(i))
#define rFOR(i, a, b) for (int(i) = (b); (i) >= (a); --(i))
#define FORstep(i, a, b, step) for (int(i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n - 1))
#define vREP(ele, vec) for (auto &(ele) : (vec))
#define vREPcopy(ele, vec) for (auto(ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())
#define RSORT(A) std::sort((A).rbegin(), (A).rend())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) =>
// COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) \
(A).erase(unique((A).begin(), (A).end()), (A).end())
template <class T> inline int argmin(std::vector<T> &vec) {
return min_element(vec.begin(), vec.end()) - vec.begin();
}
template <class T> inline int argmax(std::vector<T> &vec) {
return max_element(vec.begin(), vec.end()) - vec.begin();
}
template <class S, class T> inline void chmax(S &a, T b) {
if (a < b)
a = b;
}
template <class S, class T> inline void chmin(S &a, T b) {
if (a > b)
a = b;
}
template <class T> inline void reverseSORT(Vec<T> &Array) {
std::sort(Array.begin(), Array.end(), std::greater<T>());
}
inline int BitI(int k) { return 1 << k; }
inline lli BitL(int k) { return 1LL << k; }
inline void putsDouble(double d) { printf("%.16lf\n", d); }
template <class T> inline std::string toString(T n) {
if (n == 0)
return "0";
std::string res;
if (n < 0) {
n = -n;
while (n != 0) {
res += (char)(n % 10 + '0');
n /= 10;
}
std::reverse(res.begin(), res.end());
return '-' + res;
}
while (n != 0) {
res += (char)(n % 10 + '0');
n /= 10;
}
std::reverse(res.begin(), res.end());
return res;
}
namespace MyFunc {
using LLi = long long int;
using ULLi = unsigned long long int;
// GCD(a, b) ; a, bの最大公約数を求める関数
inline LLi gcd(LLi a, LLi b) {
while (b != 0) {
a %= b;
std::swap(a, b);
}
return a;
}
// LCM(a, b) ; a, bの最小公倍数を求める関数
inline LLi lcm(LLi a, LLi b) { return (a * b) / MyFunc::gcd(a, b); }
// 累乗を求める関数
inline LLi power(LLi a, LLi n) {
LLi res = 1LL, waiting = a;
while (n != 0LL) {
if ((n & 1LL) != 0LL)
res *= waiting;
waiting *= waiting;
n >>= 1;
}
return res;
}
// 累乗の余りを求める関数
inline LLi power_mod(LLi a, LLi n, LLi mod_number___ = 1e9 + 7) {
LLi res = 1LL, waiting = a;
while (n != 0LL) {
if ((n & 1LL) != 0LL) {
res *= waiting;
res %= mod_number___;
}
waiting *= waiting;
waiting %= mod_number___;
n >>= 1;
}
return res;
}
// Z/pZ上の逆元を求める関数 (フェルマーの小定理)
inline LLi inverse_mod(LLi a, LLi mod_number___ = 1e9 + 7) {
return MyFunc::power_mod(a, mod_number___ - 2);
}
inline LLi inverse_mod_euclid(LLi a, LLi mod_number___ = 1e9 + 7) {
LLi b = mod_number___, u = 1, v = 0;
while (b != 0) {
LLi t = a / b;
a -= t * b;
std::swap(a, b);
u -= t * v;
std::swap(u, v);
}
u %= mod_number___;
if (u < 0)
u += mod_number___;
return u;
}
// 素数であるかを判定する関数
template <typename Integer_type> inline bool isPrime(Integer_type n) {
if (n < 2)
return false;
if (n == 2)
return true;
if (n % 2 == 0)
return false;
for (Integer_type x = 3; x * x <= n; ++ ++x)
if (n % x == 0)
return false;
return true;
}
// 素数であるかの真偽表を返す : n ≥ 1
inline std::vector<bool> primeTable(int n) {
std::vector<bool> res(n + 1, true);
res[0] = false;
res[1] = false;
for (int x = 2; x * x <= n; ++x)
if (res[x]) {
for (int i = 2 * x; i <= n; i += x) {
res[i] = false;
}
}
return std::move(res);
}
// 素因数分解したベクトルを返す ; {素因数, 指数}
template <typename Integer_type>
inline std::vector<std::pair<Integer_type, int>>
prime_factorization(Integer_type n) {
std::vector<std::pair<Integer_type, int>> res(0);
if (n <= 0)
return std::move(res); // 例外処理 : nが 0 以下
if (n % 2 == 0) {
n /= 2;
int cnt = 1;
while (n % 2 == 0) {
n /= 2;
cnt++;
}
res.emplace_back(make_pair(2, cnt));
}
Integer_type x = 3;
while (x * x <= n) {
if (n % x == 0) {
n /= x;
int cnt = 1;
while (n % x == 0) {
n /= x;
cnt++;
}
res.emplace_back(make_pair(x, cnt));
}
++ ++x;
}
if (n > 1)
res.emplace_back(make_pair(n, 1));
return std::move(res);
}
// unsigned long 符号なし64bit整数で平方数かを判定する関数 O(log(N))
inline bool is_square_unsigned(ULLi n) {
// 0 は 平方数
if (n == 0)
return true;
// 平方数の可能性としては 2^32 - 1 が最大 : (2^32)^2 - 1
static ULLi MAX_LONG_SQRT__ = (1UL << 32) - 1;
if (MAX_LONG_SQRT__ * MAX_LONG_SQRT__ < n)
return false;
if (MAX_LONG_SQRT__ * MAX_LONG_SQRT__ == n)
return true;
// 二分探索
ULLi smaller = 0, bigger = MAX_LONG_SQRT__;
while (bigger - smaller > 1) {
ULLi m = (smaller + bigger) >> 1;
if (m * m == n)
return true;
if (m * m < n)
smaller = m;
else
bigger = m;
}
return false;
}
// 符号付き64bit整数で平方数か判定する関数
inline bool is_square(LLi n) {
if (n < 0)
return false;
// 平方数を4で割った余りは 0 か 1 に限る
if ((n & 0b11) > 0b01)
return false;
return is_square_unsigned(n);
}
} // namespace MyFunc
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int main(void) {
int n;
scanf("%d", &n);
Vint A(n + 1);
REP(i, n + 1) scanf("%d", &A[i]);
Vint B(n - 1);
REP(i, n) scanf("%d", &B[i]);
lli res = 0;
REP(i, n) {
if (A[i] <= B[i]) {
res += A[i];
B[i] -= A[i];
A[i] = 0;
} else {
res += B[i];
A[i] -= B[i];
B[i] = 0;
}
if (A[i + 1] <= B[i]) {
res += A[i + 1];
B[i] -= A[i + 1];
A[i + 1] = 0;
} else {
res += B[i];
A[i + 1] -= B[i];
B[i] = 0;
}
}
printf("%lld\n", res);
return 0;
} | #include <algorithm>
#include <chrono>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
using lli = long long int;
using Vint = std::vector<int>;
using Vlli = std::vector<lli>;
using Wint = std::vector<Vint>;
using Wlli = std::vector<Vlli>;
using Vbool = std::vector<bool>;
using Wbool = std::vector<Vbool>;
using pii = std::pair<int, int>;
using pll = std::pair<lli, lli>;
template <class T> using Vec = std::vector<T>;
template <class T> using Wec = Vec<Vec<T>>;
constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const std::vector<std::pair<int, int>> DXDY = {
{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
constexpr char BR = '\n';
#define DEBUG(x) std::cerr << #x << " = " << x << '\n';
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define FOReq(i, a, b) for (int(i) = (a); (i) <= (b); ++(i))
#define rFOR(i, a, b) for (int(i) = (b); (i) >= (a); --(i))
#define FORstep(i, a, b, step) for (int(i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n - 1))
#define vREP(ele, vec) for (auto &(ele) : (vec))
#define vREPcopy(ele, vec) for (auto(ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())
#define RSORT(A) std::sort((A).rbegin(), (A).rend())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) =>
// COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) \
(A).erase(unique((A).begin(), (A).end()), (A).end())
template <class T> inline int argmin(std::vector<T> &vec) {
return min_element(vec.begin(), vec.end()) - vec.begin();
}
template <class T> inline int argmax(std::vector<T> &vec) {
return max_element(vec.begin(), vec.end()) - vec.begin();
}
template <class S, class T> inline void chmax(S &a, T b) {
if (a < b)
a = b;
}
template <class S, class T> inline void chmin(S &a, T b) {
if (a > b)
a = b;
}
template <class T> inline void reverseSORT(Vec<T> &Array) {
std::sort(Array.begin(), Array.end(), std::greater<T>());
}
inline int BitI(int k) { return 1 << k; }
inline lli BitL(int k) { return 1LL << k; }
inline void putsDouble(double d) { printf("%.16lf\n", d); }
template <class T> inline std::string toString(T n) {
if (n == 0)
return "0";
std::string res;
if (n < 0) {
n = -n;
while (n != 0) {
res += (char)(n % 10 + '0');
n /= 10;
}
std::reverse(res.begin(), res.end());
return '-' + res;
}
while (n != 0) {
res += (char)(n % 10 + '0');
n /= 10;
}
std::reverse(res.begin(), res.end());
return res;
}
namespace MyFunc {
using LLi = long long int;
using ULLi = unsigned long long int;
// GCD(a, b) ; a, bの最大公約数を求める関数
inline LLi gcd(LLi a, LLi b) {
while (b != 0) {
a %= b;
std::swap(a, b);
}
return a;
}
// LCM(a, b) ; a, bの最小公倍数を求める関数
inline LLi lcm(LLi a, LLi b) { return (a * b) / MyFunc::gcd(a, b); }
// 累乗を求める関数
inline LLi power(LLi a, LLi n) {
LLi res = 1LL, waiting = a;
while (n != 0LL) {
if ((n & 1LL) != 0LL)
res *= waiting;
waiting *= waiting;
n >>= 1;
}
return res;
}
// 累乗の余りを求める関数
inline LLi power_mod(LLi a, LLi n, LLi mod_number___ = 1e9 + 7) {
LLi res = 1LL, waiting = a;
while (n != 0LL) {
if ((n & 1LL) != 0LL) {
res *= waiting;
res %= mod_number___;
}
waiting *= waiting;
waiting %= mod_number___;
n >>= 1;
}
return res;
}
// Z/pZ上の逆元を求める関数 (フェルマーの小定理)
inline LLi inverse_mod(LLi a, LLi mod_number___ = 1e9 + 7) {
return MyFunc::power_mod(a, mod_number___ - 2);
}
inline LLi inverse_mod_euclid(LLi a, LLi mod_number___ = 1e9 + 7) {
LLi b = mod_number___, u = 1, v = 0;
while (b != 0) {
LLi t = a / b;
a -= t * b;
std::swap(a, b);
u -= t * v;
std::swap(u, v);
}
u %= mod_number___;
if (u < 0)
u += mod_number___;
return u;
}
// 素数であるかを判定する関数
template <typename Integer_type> inline bool isPrime(Integer_type n) {
if (n < 2)
return false;
if (n == 2)
return true;
if (n % 2 == 0)
return false;
for (Integer_type x = 3; x * x <= n; ++ ++x)
if (n % x == 0)
return false;
return true;
}
// 素数であるかの真偽表を返す : n ≥ 1
inline std::vector<bool> primeTable(int n) {
std::vector<bool> res(n + 1, true);
res[0] = false;
res[1] = false;
for (int x = 2; x * x <= n; ++x)
if (res[x]) {
for (int i = 2 * x; i <= n; i += x) {
res[i] = false;
}
}
return std::move(res);
}
// 素因数分解したベクトルを返す ; {素因数, 指数}
template <typename Integer_type>
inline std::vector<std::pair<Integer_type, int>>
prime_factorization(Integer_type n) {
std::vector<std::pair<Integer_type, int>> res(0);
if (n <= 0)
return std::move(res); // 例外処理 : nが 0 以下
if (n % 2 == 0) {
n /= 2;
int cnt = 1;
while (n % 2 == 0) {
n /= 2;
cnt++;
}
res.emplace_back(make_pair(2, cnt));
}
Integer_type x = 3;
while (x * x <= n) {
if (n % x == 0) {
n /= x;
int cnt = 1;
while (n % x == 0) {
n /= x;
cnt++;
}
res.emplace_back(make_pair(x, cnt));
}
++ ++x;
}
if (n > 1)
res.emplace_back(make_pair(n, 1));
return std::move(res);
}
// unsigned long 符号なし64bit整数で平方数かを判定する関数 O(log(N))
inline bool is_square_unsigned(ULLi n) {
// 0 は 平方数
if (n == 0)
return true;
// 平方数の可能性としては 2^32 - 1 が最大 : (2^32)^2 - 1
static ULLi MAX_LONG_SQRT__ = (1UL << 32) - 1;
if (MAX_LONG_SQRT__ * MAX_LONG_SQRT__ < n)
return false;
if (MAX_LONG_SQRT__ * MAX_LONG_SQRT__ == n)
return true;
// 二分探索
ULLi smaller = 0, bigger = MAX_LONG_SQRT__;
while (bigger - smaller > 1) {
ULLi m = (smaller + bigger) >> 1;
if (m * m == n)
return true;
if (m * m < n)
smaller = m;
else
bigger = m;
}
return false;
}
// 符号付き64bit整数で平方数か判定する関数
inline bool is_square(LLi n) {
if (n < 0)
return false;
// 平方数を4で割った余りは 0 か 1 に限る
if ((n & 0b11) > 0b01)
return false;
return is_square_unsigned(n);
}
} // namespace MyFunc
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int main(void) {
int n;
scanf("%d", &n);
Vint A(n + 1);
REP(i, n + 1) scanf("%d", &A[i]);
Vint B(n);
REP(i, n) scanf("%d", &B[i]);
lli res = 0;
REP(i, n) {
if (A[i] <= B[i]) {
res += A[i];
B[i] -= A[i];
A[i] = 0;
} else {
res += B[i];
A[i] -= B[i];
B[i] = 0;
}
if (A[i + 1] <= B[i]) {
res += A[i + 1];
B[i] -= A[i + 1];
A[i + 1] = 0;
} else {
res += B[i];
A[i + 1] -= B[i];
B[i] = 0;
}
}
printf("%lld\n", res);
return 0;
} | replace | 247 | 248 | 247 | 248 | 0 | |
p02959 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rkc \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL);
typedef long long ll;
#define fl(i, a, b) for (ll i = a; i < b; i++)
#define rfl(i, a, b) for (ll i = a; i > b; i--)
#define pb push_back
#define mp make_pair
#define test \
ll t; \
cin >> t; \
while (t--)
#define lld long double
#define vpp vector<pair<ll, ll>>
#define ff first
#define ss second
const ll M = 1e9 + 7;
const double pi = 3.141592653589793238463;
int main() {
rkc;
ll n, ans = 0, p = 0, q = 0;
cin >> n;
ll a[n + 1], b[n];
fl(i, 0, n + 1) cin >> a[i];
fl(i, 0, n) cin >> b[i];
/*for(ll i=0,j=0;i<n+1,j<n+1;)
{
if(a[i]==b[j])
{
a[i]=0;
b[j]=0;
ans+=a[i];
i++;j++;
}
else if(a[i]>b[j])
{
a[i]=a[i]-b[j];
//b[i]=0;
ans+=b[j];if(a[i]!=0&&i!=n){i++;j++;}else if(j!=n-1) j++;else break;
//if(i>j&&j!=n-1)j++;
//else{
//i++;j++;}
}
else
{
ans+=a[i];
a[i]=0;
b[j]=b[j]-a[i];
i++;
}
}
cout<<ans;*/
/*for(ll i=0,j=0;i<n+1,j<n;)
{
if(a[i]>b[j]){if(i>n||j>n-1)break;else {ans+=b[j];i++;j++;}}
else if(a[i]<b[j])
{
if(i>n||j>n-1)break; else {
ans+=a[i];
b[j]-=a[i];
if(abs(i-j)<2)i++;
else {i++;j++;}
}
}
else
{
if(i>n||j>n-1)break;
else{
ans+=a[i];i++;j++;
}}
//cout<<ans<<endl;
}
cout<<ans;*/
for (ll i = 0, j = 0; i < n + 1, j < n;) {
if (a[i] > b[j]) {
ans += b[i];
i++;
j++;
} else if (a[i] < b[j]) {
ans += a[i];
b[j] -= a[i];
p = a[i + 1];
q = a[i + 1] - b[j];
/// a[i+1]-=b[j];
if (q >= 0) {
a[i + 1] -= b[j];
ans += b[j];
} else {
a[i + 1] = 0;
ans += p;
}
i += 2;
j++;
} else {
ans += a[i];
i++;
j++;
}
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
#define rkc \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL);
typedef long long ll;
#define fl(i, a, b) for (ll i = a; i < b; i++)
#define rfl(i, a, b) for (ll i = a; i > b; i--)
#define pb push_back
#define mp make_pair
#define test \
ll t; \
cin >> t; \
while (t--)
#define lld long double
#define vpp vector<pair<ll, ll>>
#define ff first
#define ss second
const ll M = 1e9 + 7;
const double pi = 3.141592653589793238463;
int main() {
rkc;
ll n, ans = 0, p = 0, q = 0;
cin >> n;
ll a[n + 1], b[n];
fl(i, 0, n + 1) cin >> a[i];
fl(i, 0, n) cin >> b[i];
/*for(ll i=0,j=0;i<n+1,j<n+1;)
{
if(a[i]==b[j])
{
a[i]=0;
b[j]=0;
ans+=a[i];
i++;j++;
}
else if(a[i]>b[j])
{
a[i]=a[i]-b[j];
//b[i]=0;
ans+=b[j];if(a[i]!=0&&i!=n){i++;j++;}else if(j!=n-1) j++;else break;
//if(i>j&&j!=n-1)j++;
//else{
//i++;j++;}
}
else
{
ans+=a[i];
a[i]=0;
b[j]=b[j]-a[i];
i++;
}
}
cout<<ans;*/
/*for(ll i=0,j=0;i<n+1,j<n;)
{
if(a[i]>b[j]){if(i>n||j>n-1)break;else {ans+=b[j];i++;j++;}}
else if(a[i]<b[j])
{
if(i>n||j>n-1)break; else {
ans+=a[i];
b[j]-=a[i];
if(abs(i-j)<2)i++;
else {i++;j++;}
}
}
else
{
if(i>n||j>n-1)break;
else{
ans+=a[i];i++;j++;
}}
//cout<<ans<<endl;
}
cout<<ans;*/
for (ll i = 0, j = 0; i < n + 1, j < n;) {
if (a[i] > b[j]) {
ans += b[i];
i++;
j++;
} else if (a[i] < b[j]) {
ans += a[i];
b[j] -= a[i];
p = a[i + 1];
q = a[i + 1] - b[j];
/// a[i+1]-=b[j];
if (q >= 0) {
a[i + 1] -= b[j];
ans += b[j];
} else {
a[i + 1] = 0;
ans += p;
}
i++;
j++;
} else {
ans += a[i];
i++;
j++;
}
}
cout << ans;
} | replace | 95 | 96 | 95 | 96 | 0 | |
p02959 | C++ | Runtime Error | #include <iostream>
using namespace std;
long long N, A[10010], B[10010], z = 0;
int main() {
cin >> N;
for (int i = 0; i < N + 1; i++) {
cin >> A[i];
}
for (int i = 0; i < N; i++) {
cin >> B[i];
}
for (int i = 0; i < N; i++) {
if (B[i] <= A[i]) {
z = z + B[i];
} else {
z = z + A[i];
if (A[i + 1] <= (B[i] - A[i])) {
z = z + A[i + 1];
A[i + 1] = 0;
} else {
z = z + (B[i] - A[i]);
A[i + 1] = A[i + 1] - (B[i] - A[i]);
}
}
}
cout << z;
return 0;
}
| #include <iostream>
using namespace std;
long long N, A[100100], B[100010], z = 0;
int main() {
cin >> N;
for (int i = 0; i < N + 1; i++) {
cin >> A[i];
}
for (int i = 0; i < N; i++) {
cin >> B[i];
}
for (int i = 0; i < N; i++) {
if (B[i] <= A[i]) {
z = z + B[i];
} else {
z = z + A[i];
if (A[i + 1] <= (B[i] - A[i])) {
z = z + A[i + 1];
A[i + 1] = 0;
} else {
z = z + (B[i] - A[i]);
A[i + 1] = A[i + 1] - (B[i] - A[i]);
}
}
}
cout << z;
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02959 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int N;
cin >> N;
vector<long> A(N + 1), B(N);
for (int i = 0; i < N + 1; ++i) {
cin >> A[i];
}
for (int i = 0; i < N; ++i) {
cin >> B[i];
}
B[N] = 0;
long sum = 0, nokori = 0, nokori_teki = 0, tmp = 0;
for (int i = 0; i < N + 1; ++i) {
// 前の残りで全て倒せるとき
if (nokori >= A[i]) {
sum += A[i];
nokori = B[i];
} // 前の残りと今ので倒せるとき
else if (B[i] + nokori >= A[i]) {
sum += A[i];
nokori = B[i] + nokori - A[i];
} // 倒しきれないとき
else {
sum += nokori + B[i];
nokori = 0;
}
}
cout << sum << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int N;
cin >> N;
vector<long> A(N + 1), B(N + 1);
for (int i = 0; i < N + 1; ++i) {
cin >> A[i];
}
for (int i = 0; i < N; ++i) {
cin >> B[i];
}
B[N] = 0;
long sum = 0, nokori = 0, nokori_teki = 0, tmp = 0;
for (int i = 0; i < N + 1; ++i) {
// 前の残りで全て倒せるとき
if (nokori >= A[i]) {
sum += A[i];
nokori = B[i];
} // 前の残りと今ので倒せるとき
else if (B[i] + nokori >= A[i]) {
sum += A[i];
nokori = B[i] + nokori - A[i];
} // 倒しきれないとき
else {
sum += nokori + B[i];
nokori = 0;
}
}
cout << sum << endl;
return 0;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p02959 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <math.h>
using namespace std;
int main(void) {
long long int n, a[20000], b;
long long int i, c, f, sum = 0;
cin >> n;
for (i = 0; i < n + 1; i++) {
cin >> a[i];
}
for (i = 0; i < n; i++) {
cin >> b;
c = a[i] + a[i + 1];
f = c - b;
if (f <= 0) {
sum += a[i] + a[i + 1];
a[i + 1] = 0;
} else if (a[i] >= b) {
sum += b;
} else {
sum += b;
a[i + 1] = f;
}
}
cout << sum << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <math.h>
using namespace std;
int main(void) {
long long int n, a[200000], b;
long long int i, c, f, sum = 0;
cin >> n;
for (i = 0; i < n + 1; i++) {
cin >> a[i];
}
for (i = 0; i < n; i++) {
cin >> b;
c = a[i] + a[i + 1];
f = c - b;
if (f <= 0) {
sum += a[i] + a[i + 1];
a[i + 1] = 0;
} else if (a[i] >= b) {
sum += b;
} else {
sum += b;
a[i + 1] = f;
}
}
cout << sum << endl;
return 0;
} | replace | 7 | 8 | 7 | 8 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.