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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p03033 | C++ | Time Limit Exceeded | ////////////////////////////////////////
/// tu3 pro-con template ///
////////////////////////////////////////
#include "bits/stdc++.h"
using namespace std;
// -- typedefs -- //
#define EPS 1e-9
typedef long long llong;
// -- loop macros -- //
#define REP(i, n) for (auto i = decltype(n)(0); i < (n); i++)
#define RREP(i, n) for (auto i = (n)-1; i >= 0; i--)
#define FOR(i, s, n) for (auto i = (s); i < (n); i++)
#define FORR(i, s, n) for (auto i = (n)-1; i >= (s); i--)
#define FORE(exp) for (auto &&exp)
#define allof(c) c.begin(), c.end()
#define partof(c, s, e) c.begin() + (s), c.begin() + (e)
// -- functors -- //
#define PREDICATE(t, a, ...) [&](const t &a) -> bool { return __VA_ARGS__; }
#define PRED(a, ...) PREDICATE(auto, a, __VA_ARGS__)
#define COMPARISON(t, a, b, ...) \
[&](const t &a, const t &b) -> bool { return __VA_ARGS__; }
#define COMP(a, b, ...) COMPARISON(auto, a, b, __VA_ARGS__)
#define CONV1(a, ...) \
[&](const auto &a) -> auto{ return __VA_ARGS__; }
#define CONV2(a, b, ...) \
[&](const auto &a, const auto &b) -> auto{ return __VA_ARGS__; }
#define CONV3(a, b, c, ...) \
[&](const auto &a, const auto &b, const auto &c) -> auto{ \
return __VA_ARGS__; \
}
// -- I/O Helper -- //
struct _Reader {
istream &cin;
template <class T> _Reader operator,(T &rhs) {
cin >> rhs;
return *this;
}
};
struct _Writer {
ostream &cout;
const char *delim{" "};
bool f{false};
template <class T> _Writer operator,(const T &rhs) {
cout << (f ? delim : "") << rhs;
f = true;
return *this;
}
};
#define READ(t, ...) \
t __VA_ARGS__; \
(_Reader{cin}), __VA_ARGS__
#define WRITE(...) (_Writer{cout}), __VA_ARGS__, "\n"
#define WRITELN(...) (_Writer{cout, "\n"}), __VA_ARGS__, "\n"
#ifdef _DEBUG
#define DEBUG(...) (_Writer{cerr}), "DEBUG -> ", __VA_ARGS__, "\n"
#else
#define DEBUG(...)
#endif
// -- vevector -- //
template <class T> struct vevector : vector<vector<T>> {
vevector(size_t n = 0, size_t m = 0, const T &initial = T())
: vector<vector<T>>(n, vector<T>(m, initial)) {}
};
template <class T> struct vevevector : vector<vevector<T>> {
vevevector(size_t n = 0, size_t m = 0, size_t l = 0, const T &initial = T())
: vector<vevector<T>>(n, vevector<T>(m, l, initial)) {}
};
template <class T> struct vevevevector : vector<vevevector<T>> {
vevevevector(size_t n = 0, size_t m = 0, size_t l = 0, size_t k = 0,
const T &initial = T())
: vector<vevevector<T>>(n, vevevector<T>(m, l, k, initial)) {}
};
namespace std {
template <class T1, class T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
}
template <class T1, class T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
out << p.first << " " << p.second;
return out;
}
} // namespace std
template <class T> T read() {
T t;
cin >> t;
return t;
}
template <class T> vector<T> read(int n) {
vector<T> v;
REP(i, n) { v.push_back(read<T>()); }
return v;
}
template <class T> vevector<T> read(int n, int m) {
vevector<T> v;
REP(i, n) v.push_back(read<T>(m));
return v;
}
template <class T> vector<T> readjag() { return read<T>(read<int>()); }
template <class T> vevector<T> readjag(int n) {
vevector<T> v;
REP(i, n) v.push_back(readjag<T>());
return v;
}
template <class T> struct iter_range_t {
T beg, end;
};
template <class T> iter_range_t<T> iter_range(T beg, T end) {
return iter_range_t<T>{beg, end};
}
template <class T> ostream &operator<<(ostream &out, iter_range_t<T> v) {
if (v.beg != v.end) {
out << *v.beg++;
while (v.beg != v.end) {
out << " " << *v.beg++;
}
}
return out;
}
template <class T> ostream &operator<<(ostream &out, const vector<T> &v) {
return out << iter_range(allof(v));
}
// -- etc -- //
template <class T> T infinity_value();
template <> int infinity_value<int>() { return int(1) << 28; }
template <> llong infinity_value<llong>() { return llong(1) << 60; }
template <> double infinity_value<double>() { return 1e+300 * 1e+300; }
#define INF(T) infinity_value<T>()
inline int sign_of(double x) { return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1); }
template <class TInt> bool in_range(TInt val, TInt min, TInt max) {
return val >= min && val < max;
}
template <> bool in_range<double>(double val, double min, double max) {
return val - min > -EPS && val - max < EPS;
}
template <class TInt> bool in_range2d(TInt x, TInt y, TInt w, TInt h) {
return x >= 0 && x < w && y >= 0 && y < h;
}
vector<int> iotavn(int start, int count) {
vector<int> r(count);
iota(allof(r), start);
return r;
}
//// start up ////
void solve();
int32_t main() {
//// for local debugging
// freopen("input.txt", "right_", stdin);
// freopen("output.txt", "w", stdout);
// auto classic_table = ctype<char>::classic_table();
// vector<ctype<char>::mask> ctable(classic_table, classic_table +
// ctype<char>::table_size); ctable[':'] |= ctype_base::space; // as delimitor
// ctable[','] |= ctype_base::space; // as delimitor
// cin.imbue(locale(cin.getloc(), new ctype<char>(ctable.data())));
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed;
cout << setprecision(std::numeric_limits<double>::max_digits10);
solve();
return 0;
}
/// 座圧 座標圧縮
template <class T> struct CoordinateCompression {
map<T, int> comp{};
vector<T> decomp{};
vector<T> init(const vector<T> &orig) {
decomp = orig;
decomp.push_back(numeric_limits<T>::min());
decomp.push_back(numeric_limits<T>::max());
sort(allof(decomp));
decomp.erase(unique(allof(decomp)), decomp.end());
REP(i, decomp.size()) { comp[decomp[i]] = i; }
vector<T> ret(orig.size());
REP(i, orig.size()) { ret[i] = comp[orig[i]]; }
return ret;
}
size_t size() { return decomp.size(); }
T operator[](int x) {
return decomp[x];
} ///< 圧縮後の値xはもともと何の値だったのか?
};
////////////////////
/// template end ///
////////////////////
void solve() {
READ(llong, N, Q);
vector<llong> koji;
vector<llong> zahyo;
REP(i, N) {
READ(int, S, T, X);
koji.push_back(X);
zahyo.push_back(X - T + 1);
zahyo.push_back(X - S + 1);
DEBUG(X - T + 1, X - S + 1, X);
}
auto D = read<int>(Q);
FORE(d : D) { zahyo.push_back(-d); }
CoordinateCompression<int> comp;
vector<int> zahyo2 = comp.init(std::vector<int>(allof(zahyo)));
vector<llong> mp(comp.size(), INF(llong));
REP(i, N) {
FOR(j, zahyo2[i * 2], zahyo2[i * 2 + 1]) {
mp[j] = min<llong>(mp[j], koji[i]);
}
}
REP(i, Q) {
auto a = mp[zahyo2[N * 2 + i]];
WRITE(a == INF(llong) ? -1 : a);
}
}
| ////////////////////////////////////////
/// tu3 pro-con template ///
////////////////////////////////////////
#include "bits/stdc++.h"
using namespace std;
// -- typedefs -- //
#define EPS 1e-9
typedef long long llong;
// -- loop macros -- //
#define REP(i, n) for (auto i = decltype(n)(0); i < (n); i++)
#define RREP(i, n) for (auto i = (n)-1; i >= 0; i--)
#define FOR(i, s, n) for (auto i = (s); i < (n); i++)
#define FORR(i, s, n) for (auto i = (n)-1; i >= (s); i--)
#define FORE(exp) for (auto &&exp)
#define allof(c) c.begin(), c.end()
#define partof(c, s, e) c.begin() + (s), c.begin() + (e)
// -- functors -- //
#define PREDICATE(t, a, ...) [&](const t &a) -> bool { return __VA_ARGS__; }
#define PRED(a, ...) PREDICATE(auto, a, __VA_ARGS__)
#define COMPARISON(t, a, b, ...) \
[&](const t &a, const t &b) -> bool { return __VA_ARGS__; }
#define COMP(a, b, ...) COMPARISON(auto, a, b, __VA_ARGS__)
#define CONV1(a, ...) \
[&](const auto &a) -> auto{ return __VA_ARGS__; }
#define CONV2(a, b, ...) \
[&](const auto &a, const auto &b) -> auto{ return __VA_ARGS__; }
#define CONV3(a, b, c, ...) \
[&](const auto &a, const auto &b, const auto &c) -> auto{ \
return __VA_ARGS__; \
}
// -- I/O Helper -- //
struct _Reader {
istream &cin;
template <class T> _Reader operator,(T &rhs) {
cin >> rhs;
return *this;
}
};
struct _Writer {
ostream &cout;
const char *delim{" "};
bool f{false};
template <class T> _Writer operator,(const T &rhs) {
cout << (f ? delim : "") << rhs;
f = true;
return *this;
}
};
#define READ(t, ...) \
t __VA_ARGS__; \
(_Reader{cin}), __VA_ARGS__
#define WRITE(...) (_Writer{cout}), __VA_ARGS__, "\n"
#define WRITELN(...) (_Writer{cout, "\n"}), __VA_ARGS__, "\n"
#ifdef _DEBUG
#define DEBUG(...) (_Writer{cerr}), "DEBUG -> ", __VA_ARGS__, "\n"
#else
#define DEBUG(...)
#endif
// -- vevector -- //
template <class T> struct vevector : vector<vector<T>> {
vevector(size_t n = 0, size_t m = 0, const T &initial = T())
: vector<vector<T>>(n, vector<T>(m, initial)) {}
};
template <class T> struct vevevector : vector<vevector<T>> {
vevevector(size_t n = 0, size_t m = 0, size_t l = 0, const T &initial = T())
: vector<vevector<T>>(n, vevector<T>(m, l, initial)) {}
};
template <class T> struct vevevevector : vector<vevevector<T>> {
vevevevector(size_t n = 0, size_t m = 0, size_t l = 0, size_t k = 0,
const T &initial = T())
: vector<vevevector<T>>(n, vevevector<T>(m, l, k, initial)) {}
};
namespace std {
template <class T1, class T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
}
template <class T1, class T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
out << p.first << " " << p.second;
return out;
}
} // namespace std
template <class T> T read() {
T t;
cin >> t;
return t;
}
template <class T> vector<T> read(int n) {
vector<T> v;
REP(i, n) { v.push_back(read<T>()); }
return v;
}
template <class T> vevector<T> read(int n, int m) {
vevector<T> v;
REP(i, n) v.push_back(read<T>(m));
return v;
}
template <class T> vector<T> readjag() { return read<T>(read<int>()); }
template <class T> vevector<T> readjag(int n) {
vevector<T> v;
REP(i, n) v.push_back(readjag<T>());
return v;
}
template <class T> struct iter_range_t {
T beg, end;
};
template <class T> iter_range_t<T> iter_range(T beg, T end) {
return iter_range_t<T>{beg, end};
}
template <class T> ostream &operator<<(ostream &out, iter_range_t<T> v) {
if (v.beg != v.end) {
out << *v.beg++;
while (v.beg != v.end) {
out << " " << *v.beg++;
}
}
return out;
}
template <class T> ostream &operator<<(ostream &out, const vector<T> &v) {
return out << iter_range(allof(v));
}
// -- etc -- //
template <class T> T infinity_value();
template <> int infinity_value<int>() { return int(1) << 28; }
template <> llong infinity_value<llong>() { return llong(1) << 60; }
template <> double infinity_value<double>() { return 1e+300 * 1e+300; }
#define INF(T) infinity_value<T>()
inline int sign_of(double x) { return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1); }
template <class TInt> bool in_range(TInt val, TInt min, TInt max) {
return val >= min && val < max;
}
template <> bool in_range<double>(double val, double min, double max) {
return val - min > -EPS && val - max < EPS;
}
template <class TInt> bool in_range2d(TInt x, TInt y, TInt w, TInt h) {
return x >= 0 && x < w && y >= 0 && y < h;
}
vector<int> iotavn(int start, int count) {
vector<int> r(count);
iota(allof(r), start);
return r;
}
//// start up ////
void solve();
int32_t main() {
//// for local debugging
// freopen("input.txt", "right_", stdin);
// freopen("output.txt", "w", stdout);
// auto classic_table = ctype<char>::classic_table();
// vector<ctype<char>::mask> ctable(classic_table, classic_table +
// ctype<char>::table_size); ctable[':'] |= ctype_base::space; // as delimitor
// ctable[','] |= ctype_base::space; // as delimitor
// cin.imbue(locale(cin.getloc(), new ctype<char>(ctable.data())));
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed;
cout << setprecision(std::numeric_limits<double>::max_digits10);
solve();
return 0;
}
/// 座圧 座標圧縮
template <class T> struct CoordinateCompression {
map<T, int> comp{};
vector<T> decomp{};
vector<T> init(const vector<T> &orig) {
decomp = orig;
decomp.push_back(numeric_limits<T>::min());
decomp.push_back(numeric_limits<T>::max());
sort(allof(decomp));
decomp.erase(unique(allof(decomp)), decomp.end());
REP(i, decomp.size()) { comp[decomp[i]] = i; }
vector<T> ret(orig.size());
REP(i, orig.size()) { ret[i] = comp[orig[i]]; }
return ret;
}
size_t size() { return decomp.size(); }
T operator[](int x) {
return decomp[x];
} ///< 圧縮後の値xはもともと何の値だったのか?
};
////////////////////
/// template end ///
////////////////////
void solve() {
READ(llong, N, Q);
vector<llong> koji;
vector<llong> zahyo;
REP(i, N) {
READ(int, S, T, X);
koji.push_back(X);
zahyo.push_back(X - T + 1);
zahyo.push_back(X - S + 1);
DEBUG(X - T + 1, X - S + 1, X);
}
auto D = read<int>(Q);
FORE(d : D) { zahyo.push_back(-d); }
CoordinateCompression<int> comp;
vector<int> zahyo2 = comp.init(std::vector<int>(allof(zahyo)));
vector<llong> mp(comp.size());
{
vevector<pair<int, llong>> w(mp.size());
REP(i, N) {
w[zahyo2[i * 2]].push_back({1, koji[i]});
w[zahyo2[i * 2 + 1]].push_back({0, koji[i]});
}
set<llong> w2 = {INF(llong)};
REP(i, mp.size()) {
sort(allof(w[i]));
FORE(c : w[i]) {
if (c.first == 0) {
w2.erase(c.second);
} else {
w2.insert(c.second);
}
}
mp[i] = *w2.begin();
}
}
REP(i, Q) {
auto a = mp[zahyo2[N * 2 + i]];
WRITE(a == INF(llong) ? -1 : a);
}
}
| replace | 222 | 226 | 222 | 242 | TLE | |
p03033 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
template <class type> class SegmentTree {
public:
int size;
vector<type> tree;
type def;
type (*marge)(type, type);
SegmentTree(int n, type d, type (*m)(type, type)) {
size = 1;
def = d;
marge = m;
n++;
while (size < n) {
size *= 2;
}
tree.resize(2 * size);
for (int i = 0; i < size; i++) {
tree[size - 1 + i] = def;
}
for (int i = size - 2; i >= 0; i--) {
tree[i] = marge(tree[i * 2 + 1], tree[i * 2 + 2]);
}
return;
}
SegmentTree(int n, type array[], type d, type (*m)(type, type)) {
size = 1;
def = d;
marge = m;
n++;
while (size < n) {
size *= 2;
}
tree.resize(2 * size);
for (int i = 0; i < size; i++) {
if (i < n)
tree[size - 1 + i] = array[i];
else
tree[size - 1 + i] = def;
}
for (int i = size - 2; i >= 0; i--) {
tree[i] = marge(tree[i * 2 + 1], tree[i * 2 + 2]);
}
return;
}
void update(int i, type val) {
i = size - 1 + i;
tree[i] = val;
while (i > 0) {
i = (i - 1) / 2;
tree[i] = marge(tree[i * 2 + 1], tree[i * 2 + 2]);
}
return;
}
void add(int i, type val) {
i = size - 1 + i;
tree[i] = tree[i] + val;
while (i > 0) {
i = (i - 1) / 2;
tree[i] = marge(tree[i * 2 + 1], tree[i * 2 + 2]);
}
return;
}
type get(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return def;
if (a <= l && r <= b)
return tree[k];
type vl = get(a, b, 2 * k + 1, l, (l + r) / 2);
type vr = get(a, b, 2 * k + 2, (l + r) / 2, r);
return marge(vl, vr);
}
type get(int a, int b) { return get(a, b, 0, 0, size); }
};
int marge(int a, int b) { return min(a, b); }
typedef pair<int, pair<int, int>> query;
int main() {
int n, q;
cin >> n >> q;
priority_queue<query, vector<query>, greater<query>> que;
int a, b, c;
vector<int> za;
for (int i = 0; i < n; i++) {
cin >> a >> b >> c;
que.push(make_pair((a - c) * 2, make_pair(1, c)));
que.push(make_pair((b - c) * 2, make_pair(2, c)));
za.push_back(c);
}
int d;
sort(za.begin(), za.end());
for (int i = 0; i < q; i++) {
cin >> d;
que.push(make_pair(d * 2 + 1, make_pair(3, 0)));
}
SegmentTree<int> seg(za.size(), INT_MAX, marge);
int cnt[100010] = {};
while (!que.empty()) {
if (que.top().second.first == 1) {
int idx = lower_bound(za.begin(), za.end(), que.top().second.second) -
za.begin();
if (cnt[idx] == 0) {
seg.update(lower_bound(za.begin(), za.end(), que.top().second.second) -
za.begin(),
que.top().second.second);
}
cnt[idx]++;
} else if (que.top().second.first == 2) {
int idx = lower_bound(za.begin(), za.end(), que.top().second.second) -
za.begin();
cnt[idx]--;
if (cnt[idx] == 0) {
seg.update(lower_bound(za.begin(), za.end(), que.top().second.second) -
za.begin(),
INT_MAX);
}
} else {
int ans = seg.get(0, za.size());
if (ans == INT_MAX) {
cout << -1 << endl;
} else {
cout << ans << endl;
}
}
que.pop();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
template <class type> class SegmentTree {
public:
int size;
vector<type> tree;
type def;
type (*marge)(type, type);
SegmentTree(int n, type d, type (*m)(type, type)) {
size = 1;
def = d;
marge = m;
n++;
while (size < n) {
size *= 2;
}
tree.resize(2 * size);
for (int i = 0; i < size; i++) {
tree[size - 1 + i] = def;
}
for (int i = size - 2; i >= 0; i--) {
tree[i] = marge(tree[i * 2 + 1], tree[i * 2 + 2]);
}
return;
}
SegmentTree(int n, type array[], type d, type (*m)(type, type)) {
size = 1;
def = d;
marge = m;
n++;
while (size < n) {
size *= 2;
}
tree.resize(2 * size);
for (int i = 0; i < size; i++) {
if (i < n)
tree[size - 1 + i] = array[i];
else
tree[size - 1 + i] = def;
}
for (int i = size - 2; i >= 0; i--) {
tree[i] = marge(tree[i * 2 + 1], tree[i * 2 + 2]);
}
return;
}
void update(int i, type val) {
i = size - 1 + i;
tree[i] = val;
while (i > 0) {
i = (i - 1) / 2;
tree[i] = marge(tree[i * 2 + 1], tree[i * 2 + 2]);
}
return;
}
void add(int i, type val) {
i = size - 1 + i;
tree[i] = tree[i] + val;
while (i > 0) {
i = (i - 1) / 2;
tree[i] = marge(tree[i * 2 + 1], tree[i * 2 + 2]);
}
return;
}
type get(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return def;
if (a <= l && r <= b)
return tree[k];
type vl = get(a, b, 2 * k + 1, l, (l + r) / 2);
type vr = get(a, b, 2 * k + 2, (l + r) / 2, r);
return marge(vl, vr);
}
type get(int a, int b) { return get(a, b, 0, 0, size); }
};
int marge(int a, int b) { return min(a, b); }
typedef pair<int, pair<int, int>> query;
int main() {
int n, q;
cin >> n >> q;
priority_queue<query, vector<query>, greater<query>> que;
int a, b, c;
vector<int> za;
for (int i = 0; i < n; i++) {
cin >> a >> b >> c;
que.push(make_pair((a - c) * 2, make_pair(1, c)));
que.push(make_pair((b - c) * 2, make_pair(2, c)));
za.push_back(c);
}
int d;
sort(za.begin(), za.end());
for (int i = 0; i < q; i++) {
cin >> d;
que.push(make_pair(d * 2 + 1, make_pair(3, 0)));
}
SegmentTree<int> seg(za.size(), INT_MAX, marge);
int cnt[200010] = {};
while (!que.empty()) {
if (que.top().second.first == 1) {
int idx = lower_bound(za.begin(), za.end(), que.top().second.second) -
za.begin();
if (cnt[idx] == 0) {
seg.update(lower_bound(za.begin(), za.end(), que.top().second.second) -
za.begin(),
que.top().second.second);
}
cnt[idx]++;
} else if (que.top().second.first == 2) {
int idx = lower_bound(za.begin(), za.end(), que.top().second.second) -
za.begin();
cnt[idx]--;
if (cnt[idx] == 0) {
seg.update(lower_bound(za.begin(), za.end(), que.top().second.second) -
za.begin(),
INT_MAX);
}
} else {
int ans = seg.get(0, za.size());
if (ans == INT_MAX) {
cout << -1 << endl;
} else {
cout << ans << endl;
}
}
que.pop();
}
return 0;
} | replace | 127 | 128 | 127 | 128 | 0 | |
p03033 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#define MN 201000
std::set<int> st;
struct xxx {
int t, o, w;
xxx() {}
xxx(int a, int b, int c) {
t = a;
o = b;
w = c;
}
} b[MN];
bool cmp(xxx a, xxx b) { return a.t == b.t ? a.o < b.o : a.t < b.t; }
int main() {
int n, q;
scanf("%d%d", &n, &q);
int m = 0;
for (int i = 1; i <= n; i++) {
int s, t, c;
scanf("%d%d%d", &s, &t, &c);
s -= c;
t -= c;
b[++m] = xxx(s, 1, c);
b[++m] = xxx(t, 0, c);
}
std::sort(b + 1, b + m + 1, cmp);
int j = 1;
for (int i = 1; i <= q; i++) {
int d;
scanf("%d", &d);
while (j <= m && d >= b[j].t) {
if (!b[j].o)
st.erase(b[j].w);
else
st.insert(b[j].w);
j++;
}
if (st.size() == 0)
puts("-1");
else
printf("%d\n", *st.begin());
}
return 0;
} | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#define MN 401000
std::set<int> st;
struct xxx {
int t, o, w;
xxx() {}
xxx(int a, int b, int c) {
t = a;
o = b;
w = c;
}
} b[MN];
bool cmp(xxx a, xxx b) { return a.t == b.t ? a.o < b.o : a.t < b.t; }
int main() {
int n, q;
scanf("%d%d", &n, &q);
int m = 0;
for (int i = 1; i <= n; i++) {
int s, t, c;
scanf("%d%d%d", &s, &t, &c);
s -= c;
t -= c;
b[++m] = xxx(s, 1, c);
b[++m] = xxx(t, 0, c);
}
std::sort(b + 1, b + m + 1, cmp);
int j = 1;
for (int i = 1; i <= q; i++) {
int d;
scanf("%d", &d);
while (j <= m && d >= b[j].t) {
if (!b[j].o)
st.erase(b[j].w);
else
st.insert(b[j].w);
j++;
}
if (st.size() == 0)
puts("-1");
else
printf("%d\n", *st.begin());
}
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p03033 | C++ | Runtime Error | #include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <stdio.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int n, q, s[200010], t[200010], x[200010], d[200010];
set<int> block;
priority_queue<pii, vector<pii>, greater<pii>> st, ed;
int main() {
scanf("%d %d", &n, &q);
for (int i = 0; i < n; i++) {
scanf("%d %d %d", s + i, t + i, x + i);
s[i] -= x[i];
t[i] -= x[i];
st.emplace(s[i], i);
}
for (int i = 0; i < q; i++)
scanf("%d", d + i);
for (int i = 0; i < q; i++) {
while (!ed.empty() && ed.top().first <= d[i]) {
block.erase(x[ed.top().second]);
ed.pop();
}
while (!st.empty() && st.top().first <= d[i]) {
int id = st.top().first;
if (d[i] < t[id]) {
block.emplace(x[id]);
ed.emplace(t[id], id);
}
st.pop();
}
if (block.empty())
printf("-1\n");
else
printf("%d\n", *block.begin());
}
} | #include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <stdio.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int n, q, s[200010], t[200010], x[200010], d[200010];
set<int> block;
priority_queue<pii, vector<pii>, greater<pii>> st, ed;
int main() {
scanf("%d %d", &n, &q);
for (int i = 0; i < n; i++) {
scanf("%d %d %d", s + i, t + i, x + i);
s[i] -= x[i];
t[i] -= x[i];
st.emplace(s[i], i);
}
for (int i = 0; i < q; i++)
scanf("%d", d + i);
for (int i = 0; i < q; i++) {
while (!ed.empty() && ed.top().first <= d[i]) {
block.erase(x[ed.top().second]);
ed.pop();
}
while (!st.empty() && st.top().first <= d[i]) {
int id = st.top().second;
if (d[i] < t[id]) {
block.emplace(x[id]);
ed.emplace(t[id], id);
}
st.pop();
}
if (block.empty())
printf("-1\n");
else
printf("%d\n", *block.begin());
}
} | replace | 28 | 29 | 28 | 29 | 0 | |
p03033 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
#define ALL(a) a.begin(), a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i, n) for (int i = 0; i < ((int)n); i++)
#define REP1(i, n) for (int i = 1; i < ((int)n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define PB push_back
#define EB emplace_back
#define MP(a, b) make_pair(a, b)
#define SORT_UNIQUE(c) \
(sort(c.begin(), c.end()), \
c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin())
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, q;
cin >> n >> q;
vll s(n), t(n), x(n);
REP(i, n) cin >> s[i] >> t[i] >> x[i];
vll d(q);
REP(i, q) cin >> d[i];
//-1:insert
// 0:delete
// 1:ans
vector<tuple<ll, ll, ll>> v;
REP(i, n) {
s[i] -= x[i];
t[i] -= x[i];
v.push_back(forward_as_tuple(s[i], -1, x[i]));
v.push_back(forward_as_tuple(t[i], 0, x[i]));
}
REP(i, q)
v.push_back(forward_as_tuple(d[i], 1, i));
sort(v.begin(), v.end());
vll dist(q, -1);
multiset<ll> se;
REP(i, v.size()) {
ll l, q, w;
tie(l, q, w) = v[i];
if (q == -1)
se.insert(w);
if (q == 0)
se.erase(se.lower_bound(w));
else {
if (!se.empty())
dist[w] = *se.begin();
}
}
REP(i, q)
cout << dist[i] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
#define ALL(a) a.begin(), a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i, n) for (int i = 0; i < ((int)n); i++)
#define REP1(i, n) for (int i = 1; i < ((int)n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define PB push_back
#define EB emplace_back
#define MP(a, b) make_pair(a, b)
#define SORT_UNIQUE(c) \
(sort(c.begin(), c.end()), \
c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin())
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, q;
cin >> n >> q;
vll s(n), t(n), x(n);
REP(i, n) cin >> s[i] >> t[i] >> x[i];
vll d(q);
REP(i, q) cin >> d[i];
//-1:insert
// 0:delete
// 1:ans
vector<tuple<ll, ll, ll>> v;
REP(i, n) {
s[i] -= x[i];
t[i] -= x[i];
v.push_back(forward_as_tuple(s[i], -1, x[i]));
v.push_back(forward_as_tuple(t[i], 0, x[i]));
}
REP(i, q)
v.push_back(forward_as_tuple(d[i], 1, i));
sort(v.begin(), v.end());
vll dist(q, -1);
multiset<ll> se;
REP(i, v.size()) {
ll l, q, w;
tie(l, q, w) = v[i];
if (q == -1)
se.insert(w);
if (q == 0)
se.erase(se.lower_bound(w));
if (q == 1 && !se.empty())
dist[w] = *se.begin();
}
REP(i, q)
cout << dist[i] << endl;
}
| replace | 73 | 77 | 73 | 75 | 0 | |
p03033 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double PI = 3.1415926535897932; // acos(-1)
const double EPS = 1e-15;
const int mod = 1e+9 + 7;
const int INF = 1e+9;
bool used[200005];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<tuple<int, int, int>> tup(n);
set<P> s;
for (int i = 0; i < n; ++i) {
int s, t, x;
cin >> s >> t >> x;
s -= x;
t -= x;
tup[i] = tie(x, s, t);
}
for (int i = 0; i < q; ++i) {
int d;
cin >> d;
s.insert(P(d, i));
}
sort(tup.begin(), tup.end());
vector<int> res(q, -1);
for (int i = 0; i < n; ++i) {
int x, st, term;
tie(x, st, term) = tup[i];
auto it = lower_bound(s.begin(), s.end(), P(st, -1));
while (it != s.end()) {
if (it->first >= term)
break;
res[it->second] = x;
auto tmp = it++;
s.erase(tmp);
}
}
for (int i = 0; i < q; ++i) {
cout << res[i] << "\n";
}
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double PI = 3.1415926535897932; // acos(-1)
const double EPS = 1e-15;
const int mod = 1e+9 + 7;
const int INF = 1e+9;
bool used[200005];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<tuple<int, int, int>> tup(n);
set<P> s;
for (int i = 0; i < n; ++i) {
int s, t, x;
cin >> s >> t >> x;
s -= x;
t -= x;
tup[i] = tie(x, s, t);
}
for (int i = 0; i < q; ++i) {
int d;
cin >> d;
s.insert(P(d, i));
}
sort(tup.begin(), tup.end());
vector<int> res(q, -1);
for (int i = 0; i < n; ++i) {
int x, st, term;
tie(x, st, term) = tup[i];
auto it = s.lower_bound(P(st, -1));
while (it != s.end()) {
if (it->first >= term)
break;
res[it->second] = x;
auto tmp = it++;
s.erase(tmp);
}
}
for (int i = 0; i < q; ++i) {
cout << res[i] << "\n";
}
} | replace | 56 | 57 | 56 | 57 | TLE | |
p03033 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
vector<pair<int, pair<int, int>>> closed;
for (int i = 0; i < n; i++) {
int s, t, x;
cin >> s >> t >> x;
closed.push_back({s - x, {1, x}}); // type : 1
closed.push_back({t - x, {-1, x}}); // type : -1
}
sort(closed.begin(), closed.end()); // -1 < 1
vector<int> d(q);
for (int i = 0; i < q; i++) {
cin >> d[i];
}
set<int> current; // set of closed points
int j = 0;
for (int i = 0; i < q; i++) {
while (closed[j].first <= d[i]) {
int type = closed[j].second.first;
int x = closed[j].second.second;
if (type == 1)
current.insert(x);
if (type == -1)
current.erase(x);
j += 1;
}
if (current.empty() == false)
cout << *current.begin() << endl;
if (current.empty() == true)
cout << -1 << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
vector<pair<int, pair<int, int>>> closed;
for (int i = 0; i < n; i++) {
int s, t, x;
cin >> s >> t >> x;
closed.push_back({s - x, {1, x}}); // type : 1
closed.push_back({t - x, {-1, x}}); // type : -1
}
sort(closed.begin(), closed.end()); // -1 < 1
vector<int> d(q);
for (int i = 0; i < q; i++) {
cin >> d[i];
}
set<int> current; // set of closed points
int j = 0;
for (int i = 0; i < q; i++) {
while (j < 2 * n && closed[j].first <= d[i]) {
int type = closed[j].second.first;
int x = closed[j].second.second;
if (type == 1)
current.insert(x);
if (type == -1)
current.erase(x);
j += 1;
}
if (current.empty() == false)
cout << *current.begin() << endl;
if (current.empty() == true)
cout << -1 << endl;
}
return 0;
} | replace | 24 | 25 | 24 | 25 | 0 | |
p03033 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define per(i, n) for (ll i = n - 1; i >= 0; i--)
#define perl(i, r, l) for (ll i = r - 1; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x, vector<x>, greater<x>>
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
#define vtpl(x, y, z) vector<tuple<x, y, z>>
#define rev(x) reverse(x);
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
using vpl = vector<pl>;
using vvpl = vector<vpl>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1};
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;
}
int main() {
ll n, q;
cin >> n >> q;
vector<pair<ll, pl>> w(n);
rep(i, n) {
cin >> w[i].se.fi >> w[i].se.se >> w[i].fi;
w[i].se.fi -= w[i].fi;
w[i].se.se -= w[i].fi + 1;
}
sort(all(w));
vector<ll> que(q), ans(q);
rep(i, q) cin >> que[i];
set<ll> st;
rep(i, q) st.ins(que[i]);
rep(i, n) {
auto p = st.lower_bound(w[i].se.fi);
while (*p <= w[i].se.se) {
ll id = lower_bound(all(que), *p) - que.begin();
ans[id] = w[i].fi;
p = st.erase(p);
if (p == st.end())
break;
}
}
rep(i, q) {
if (ans[i])
cout << ans[i] << endl;
else
cout << -1 << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define per(i, n) for (ll i = n - 1; i >= 0; i--)
#define perl(i, r, l) for (ll i = r - 1; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x, vector<x>, greater<x>>
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
#define vtpl(x, y, z) vector<tuple<x, y, z>>
#define rev(x) reverse(x);
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
using vpl = vector<pl>;
using vvpl = vector<vpl>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1};
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;
}
int main() {
ll n, q;
cin >> n >> q;
vector<pair<ll, pl>> w(n);
rep(i, n) {
cin >> w[i].se.fi >> w[i].se.se >> w[i].fi;
w[i].se.fi -= w[i].fi;
w[i].se.se -= w[i].fi + 1;
}
sort(all(w));
vector<ll> que(q), ans(q);
rep(i, q) cin >> que[i];
set<ll> st;
rep(i, q) st.ins(que[i]);
rep(i, n) {
auto p = st.lower_bound(w[i].se.fi);
if (p == st.end())
continue;
while (*p <= w[i].se.se) {
ll id = lower_bound(all(que), *p) - que.begin();
ans[id] = w[i].fi;
p = st.erase(p);
if (p == st.end())
break;
}
}
rep(i, q) {
if (ans[i])
cout << ans[i] << endl;
else
cout << -1 << endl;
}
} | insert | 57 | 57 | 57 | 59 | 0 | |
p03033 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9 + 7)
#define inf (int)(3e18 + 7)
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define P pair<int, int>
#define PiP pair<int, pair<int, int>>
#define all(v) v.begin(), v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define vecunique(vec) \
sort(vec.begin(), vec.end()); \
decltype(vec)::iterator result = std::unique(vec.begin(), vec.end()); \
vec.erase(result, vec.end())
using namespace std;
bool prime(int x) {
for (int i = 2; i * i <= x; i++) {
if (x % i == 0)
return false;
}
return x > 1;
}
int gcd(int x, int y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
int lcm(int x, int y) { return x / gcd(x, y) * y; }
int kai(int x) {
if (x == 0)
return 1;
return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
int res = 1;
while (y > 0) {
if (y & 1) {
res = res * x % mod_;
}
x = x * x % mod_;
y >>= 1;
}
return res;
}
int comb(int x, int y) {
if (y > x)
return 0;
return kai(x) * mod_pow(kai(x - y), mod - 2, mod) % mod *
mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/
P dat[1000000];
int size_ = 1;
void init(int x) {
while (size_ < x)
size_ *= 2;
rep(i, 2 * size_ - 1) dat[i] = {inf, inf};
}
void eval(int k, int l, int r) {
if (dat[k].second != inf) {
dat[k].first = dat[k].second;
if (r - l > 1) {
dat[k * 2 + 1].second = dat[k].second;
dat[k * 2 + 2].second = dat[k].second;
}
dat[k].second = inf;
}
}
void update(int a, int b, int k, int x, int l, int r) {
eval(k, l, r);
if (r <= a || b <= l)
return;
if (a <= l && r <= b) {
dat[k].second = x;
eval(k, l, r);
} else {
update(a, b, k * 2 + 1, x, l, (l + r) / 2);
update(a, b, k * 2 + 2, x, (l + r) / 2, r);
dat[k].first = min(dat[k * 2 + 1].first, dat[k * 2 + 2].first);
}
}
int query(int a, int b, int k, int l, int r) {
eval(k, l, r);
if (r <= a || b <= l)
return inf;
if (a <= l && r <= b) {
return dat[k].first;
}
int lv = query(a, b, k * 2 + 1, l, (l + r) / 2);
int rv = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(lv, rv);
}
int n, q;
PiP p[214514];
signed main() {
cin >> n >> q;
vector<int> vec;
rep(i, n) {
cin >> p[i].second.first >> p[i].second.second >> p[i].first;
vec.push_back(p[i].second.first - p[i].first);
vec.push_back(p[i].second.second - p[i].first);
}
vecunique(vec);
map<int, int> mp;
rep(i, vec.size()) { mp[vec[i]] = i; }
init(vec.size());
sort(p, p + n, greater<>());
rep(i, n) {
update(mp[p[i].second.first - p[i].first],
mp[p[i].second.second - p[i].first], 0, p[i].first, 0, size_);
}
rep(i, q) {
int a;
cin >> a;
int k = upper_bound(all(vec), a) - vec.begin();
if (k == 0)
cout << -1 << endl;
else {
int m = query(mp[vec[k - 1]], mp[vec[k - 1]] + 1, 0, 0, size_);
if (m == inf)
cout << -1 << endl;
else
cout << m << endl;
}
}
}
| #include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9 + 7)
#define inf (int)(3e18 + 7)
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define P pair<int, int>
#define PiP pair<int, pair<int, int>>
#define all(v) v.begin(), v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define vecunique(vec) \
sort(vec.begin(), vec.end()); \
decltype(vec)::iterator result = std::unique(vec.begin(), vec.end()); \
vec.erase(result, vec.end())
using namespace std;
bool prime(int x) {
for (int i = 2; i * i <= x; i++) {
if (x % i == 0)
return false;
}
return x > 1;
}
int gcd(int x, int y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
int lcm(int x, int y) { return x / gcd(x, y) * y; }
int kai(int x) {
if (x == 0)
return 1;
return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
int res = 1;
while (y > 0) {
if (y & 1) {
res = res * x % mod_;
}
x = x * x % mod_;
y >>= 1;
}
return res;
}
int comb(int x, int y) {
if (y > x)
return 0;
return kai(x) * mod_pow(kai(x - y), mod - 2, mod) % mod *
mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/
P dat[10000000];
int size_ = 1;
void init(int x) {
while (size_ < x)
size_ *= 2;
rep(i, 2 * size_ - 1) dat[i] = {inf, inf};
}
void eval(int k, int l, int r) {
if (dat[k].second != inf) {
dat[k].first = dat[k].second;
if (r - l > 1) {
dat[k * 2 + 1].second = dat[k].second;
dat[k * 2 + 2].second = dat[k].second;
}
dat[k].second = inf;
}
}
void update(int a, int b, int k, int x, int l, int r) {
eval(k, l, r);
if (r <= a || b <= l)
return;
if (a <= l && r <= b) {
dat[k].second = x;
eval(k, l, r);
} else {
update(a, b, k * 2 + 1, x, l, (l + r) / 2);
update(a, b, k * 2 + 2, x, (l + r) / 2, r);
dat[k].first = min(dat[k * 2 + 1].first, dat[k * 2 + 2].first);
}
}
int query(int a, int b, int k, int l, int r) {
eval(k, l, r);
if (r <= a || b <= l)
return inf;
if (a <= l && r <= b) {
return dat[k].first;
}
int lv = query(a, b, k * 2 + 1, l, (l + r) / 2);
int rv = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(lv, rv);
}
int n, q;
PiP p[214514];
signed main() {
cin >> n >> q;
vector<int> vec;
rep(i, n) {
cin >> p[i].second.first >> p[i].second.second >> p[i].first;
vec.push_back(p[i].second.first - p[i].first);
vec.push_back(p[i].second.second - p[i].first);
}
vecunique(vec);
map<int, int> mp;
rep(i, vec.size()) { mp[vec[i]] = i; }
init(vec.size());
sort(p, p + n, greater<>());
rep(i, n) {
update(mp[p[i].second.first - p[i].first],
mp[p[i].second.second - p[i].first], 0, p[i].first, 0, size_);
}
rep(i, q) {
int a;
cin >> a;
int k = upper_bound(all(vec), a) - vec.begin();
if (k == 0)
cout << -1 << endl;
else {
int m = query(mp[vec[k - 1]], mp[vec[k - 1]] + 1, 0, 0, size_);
if (m == inf)
cout << -1 << endl;
else
cout << m << endl;
}
}
}
| replace | 55 | 56 | 55 | 56 | 0 | |
p03033 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define INF_LL 1LL << 39
#define INF 100000000
#define MOD 1000000007LL
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define prique priority_queue
#define PI acos(-1)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef vector<ll> poly;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
struct edge {
int to, cost;
};
signed main() {
int n, q;
cin >> n >> q;
vector<pair<pair<int, int>, int>> l(n);
vi s(n), t(n), x(n);
set<int> d;
map<int, int> m;
rep(i, n) cin >> l[i].first.first >> l[i].first.second >> l[i].second;
sort(all(l), [](auto &x, auto &y) { return x.second < y.second; });
rep(i, n) {
s[i] = l[i].first.first;
t[i] = l[i].first.second;
x[i] = l[i].second;
}
rep(i, q) {
int a;
cin >> a;
d.insert(a);
m[a] = i;
}
vi ans(q, -1);
rep(i, n) {
auto it = d.lower_bound(s[i] - x[i]);
while (*it < t[i] - x[i]) {
ans[m[*it]] = x[i];
d.erase(it);
it = d.lower_bound(s[i] - x[i]);
}
}
rep(i, q) { cout << ans[i] << endl; }
}
| #include <bits/stdc++.h>
using namespace std;
#define INF_LL 1LL << 39
#define INF 100000000
#define MOD 1000000007LL
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define prique priority_queue
#define PI acos(-1)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef vector<ll> poly;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
struct edge {
int to, cost;
};
signed main() {
int n, q;
cin >> n >> q;
vector<pair<pair<int, int>, int>> l(n);
vi s(n), t(n), x(n);
set<int> d;
map<int, int> m;
rep(i, n) cin >> l[i].first.first >> l[i].first.second >> l[i].second;
sort(all(l), [](auto &x, auto &y) { return x.second < y.second; });
rep(i, n) {
s[i] = l[i].first.first;
t[i] = l[i].first.second;
x[i] = l[i].second;
}
rep(i, q) {
int a;
cin >> a;
d.insert(a);
m[a] = i;
}
vi ans(q, -1);
rep(i, n) {
set<int>::iterator it = d.lower_bound(s[i] - x[i]);
while (it != d.end() && *it < t[i] - x[i]) {
ans[m[*it]] = x[i];
d.erase(it);
it = d.lower_bound(s[i] - x[i]);
}
}
rep(i, q) { cout << ans[i] << endl; }
}
| replace | 61 | 63 | 61 | 63 | 0 | |
p03033 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for (ll i = (a); i > (b); --i)
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define VECCIN(x) \
for (auto &youso_ : (x)) \
cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
T x;
cin >> x;
return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&...tail) {
cin >> head;
CIN(move(tail)...);
}
#define CINT(...) \
int __VA_ARGS__; \
CIN(__VA_ARGS__)
#define LCIN(...) \
ll __VA_ARGS__; \
CIN(__VA_ARGS__)
#define SCIN(...) \
string __VA_ARGS__; \
CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v) \
{ \
FOREACH(x, v) { cout << x << " "; } \
cout << "\n"; \
}
typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, VL, greater<ll>> PQG;
const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};
ll N, Q;
vector<tuple<ll, ll, ll>> tup;
set<ll> now;
int main() {
cin >> N >> Q;
REP(i, N) {
LCIN(S, T, X);
tup.emplace_back(S - X, 1, X);
tup.emplace_back(T - X, 0, X);
}
sort(All(tup));
auto itr = tup.begin();
REP(i, Q) {
LCIN(D);
while (get<0>(*itr) <= D) {
if (get<1>(*itr)) {
now.insert(get<2>(*itr));
} else {
now.erase(get<2>(*itr));
}
itr++;
}
cout << (!now.empty() ? *now.begin() : -1) << "\n";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for (ll i = (a); i > (b); --i)
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define VECCIN(x) \
for (auto &youso_ : (x)) \
cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
T x;
cin >> x;
return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&...tail) {
cin >> head;
CIN(move(tail)...);
}
#define CINT(...) \
int __VA_ARGS__; \
CIN(__VA_ARGS__)
#define LCIN(...) \
ll __VA_ARGS__; \
CIN(__VA_ARGS__)
#define SCIN(...) \
string __VA_ARGS__; \
CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v) \
{ \
FOREACH(x, v) { cout << x << " "; } \
cout << "\n"; \
}
typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, VL, greater<ll>> PQG;
const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};
ll N, Q;
vector<tuple<ll, ll, ll>> tup;
set<ll> now;
int main() {
cin >> N >> Q;
REP(i, N) {
LCIN(S, T, X);
tup.emplace_back(S - X, 1, X);
tup.emplace_back(T - X, 0, X);
}
sort(All(tup));
auto itr = tup.begin();
REP(i, Q) {
LCIN(D);
while (get<0>(*itr) <= D && itr != tup.end()) {
if (get<1>(*itr)) {
now.insert(get<2>(*itr));
} else {
now.erase(get<2>(*itr));
}
itr++;
}
cout << (!now.empty() ? *now.begin() : -1) << "\n";
}
return 0;
} | replace | 73 | 74 | 73 | 74 | 0 | |
p03033 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define rrep(i, n) RREP(i, n - 1, 0)
#define all(v) v.begin(), v.end()
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, Q;
cin >> N >> Q;
vector<ll> S(N), T(N), X(N);
set<pair<ll, pair<int, ll>>> se;
rep(i, N) {
cin >> S[i] >> T[i] >> X[i];
se.emplace(S[i] - X[i], make_pair(1, X[i]));
se.emplace(T[i] - X[i], make_pair(-1, X[i]));
}
vector<pair<ll, int>> D(Q);
rep(i, Q) {
cin >> D[i].first;
D[i].second = i;
}
sort(all(D));
vector<ll> ans(Q, longinf);
auto itr = se.begin();
set<ll> se2;
se2.insert(longinf);
int cur = 0;
while (true) {
while (itr != se.end() && itr->first <= D[cur].first) {
if (itr->second.first == 1) {
se2.insert(itr->second.second);
} else {
se2.erase(itr->second.second);
}
itr++;
}
if (itr == se.end())
break;
ans[D[cur].second] = *se2.begin();
cur++;
}
rep(i, Q) cout << (ans[i] == longinf ? -1 : ans[i]) << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define rrep(i, n) RREP(i, n - 1, 0)
#define all(v) v.begin(), v.end()
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, Q;
cin >> N >> Q;
vector<ll> S(N), T(N), X(N);
set<pair<ll, pair<int, ll>>> se;
rep(i, N) {
cin >> S[i] >> T[i] >> X[i];
se.emplace(S[i] - X[i], make_pair(1, X[i]));
se.emplace(T[i] - X[i], make_pair(-1, X[i]));
}
vector<pair<ll, int>> D(Q);
rep(i, Q) {
cin >> D[i].first;
D[i].second = i;
}
sort(all(D));
vector<ll> ans(Q, longinf);
auto itr = se.begin();
set<ll> se2;
se2.insert(longinf);
int cur = 0;
while (true) {
if (cur == Q)
break;
while (itr != se.end() && itr->first <= D[cur].first) {
if (itr->second.first == 1) {
se2.insert(itr->second.second);
} else {
se2.erase(itr->second.second);
}
itr++;
}
if (itr == se.end())
break;
ans[D[cur].second] = *se2.begin();
cur++;
}
rep(i, Q) cout << (ans[i] == longinf ? -1 : ans[i]) << "\n";
return 0;
}
| insert | 36 | 36 | 36 | 38 | 0 | |
p03033 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 200;
const int INF = 1e9;
int main() {
set<int> event_set;
int d[MAXN];
vector<pair<int, int>> stoppers;
int N, Q;
cin >> N >> Q;
for (int i = 0; i < N; i++) {
int S, T, X;
cin >> S >> T >> X;
stoppers.push_back(make_pair(S - X, X));
stoppers.push_back(make_pair(T - X, -X));
}
for (int i = 0; i < Q; i++) {
int D;
cin >> D;
d[i] = D;
}
sort(d, d + Q);
sort(stoppers.begin(), stoppers.end());
stoppers.push_back(make_pair(INF, INF));
int ite = 0;
for (int i = 0; i < Q; i++) {
int T = d[i];
while (T >= stoppers[ite].first) {
if (stoppers[ite].second > 0)
event_set.insert(stoppers[ite].second);
else
event_set.erase(-stoppers[ite].second);
ite++;
}
if (event_set.size() == 0)
cout << -1 << endl;
else
cout << *event_set.begin() << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
const int INF = 1e9;
int main() {
set<int> event_set;
int d[MAXN];
vector<pair<int, int>> stoppers;
int N, Q;
cin >> N >> Q;
for (int i = 0; i < N; i++) {
int S, T, X;
cin >> S >> T >> X;
stoppers.push_back(make_pair(S - X, X));
stoppers.push_back(make_pair(T - X, -X));
}
for (int i = 0; i < Q; i++) {
int D;
cin >> D;
d[i] = D;
}
sort(d, d + Q);
sort(stoppers.begin(), stoppers.end());
stoppers.push_back(make_pair(INF, INF));
int ite = 0;
for (int i = 0; i < Q; i++) {
int T = d[i];
while (T >= stoppers[ite].first) {
if (stoppers[ite].second > 0)
event_set.insert(stoppers[ite].second);
else
event_set.erase(-stoppers[ite].second);
ite++;
}
if (event_set.size() == 0)
cout << -1 << endl;
else
cout << *event_set.begin() << endl;
}
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p03033 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int i = 0; i < n; i++)
struct info {
ll left, right, time;
};
bool comp(const info &a, const info &b) { return a.time <= b.time; }
int main() {
int n, q;
cin >> n >> q;
ll s, t, x;
vector<info> vec(n);
rep(i, n) {
cin >> s >> t >> x;
vec[i] = {x - t + 1, x - s, x};
}
sort(vec.begin(), vec.end(), comp);
vector<ll> ans(q, -1);
map<ll, int> mp;
set<ll> Set;
ll d;
rep(i, q) {
cin >> d;
d = -d;
mp[d] = i;
Set.insert(d);
}
rep(i, n) {
while (Set.size() > 0) {
auto itr1 = Set.lower_bound(vec[i].left);
if (itr1 != Set.end() && (*itr1) <= vec[i].right) {
ans[mp[(*itr1)]] = vec[i].time;
Set.erase((*itr1));
} else
break;
}
}
rep(i, q) printf("%lld\n", ans[i]);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int i = 0; i < n; i++)
struct info {
ll left, right, time;
};
bool comp(const info &a, const info &b) { return a.time < b.time; }
int main() {
int n, q;
cin >> n >> q;
ll s, t, x;
vector<info> vec(n);
rep(i, n) {
cin >> s >> t >> x;
vec[i] = {x - t + 1, x - s, x};
}
sort(vec.begin(), vec.end(), comp);
vector<ll> ans(q, -1);
map<ll, int> mp;
set<ll> Set;
ll d;
rep(i, q) {
cin >> d;
d = -d;
mp[d] = i;
Set.insert(d);
}
rep(i, n) {
while (Set.size() > 0) {
auto itr1 = Set.lower_bound(vec[i].left);
if (itr1 != Set.end() && (*itr1) <= vec[i].right) {
ans[mp[(*itr1)]] = vec[i].time;
Set.erase((*itr1));
} else
break;
}
}
rep(i, q) printf("%lld\n", ans[i]);
return 0;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p03033 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <set>
using namespace std;
const int InF = 0x3f3f3f3f, maxn = 2e5 + 2;
struct node {
int t, x, d;
inline bool operator<(const node &x) const { return t < x.t; }
} event[maxn];
int n, m;
int len;
multiset<int> msi;
int main() {
cin >> n >> m;
int i;
for (i = 1; i <= n; i++) {
int s, t, x;
cin >> s >> t >> x;
event[++len].t = s - x;
event[len].x = x;
event[len].d = 1;
event[++len].t = t - x;
event[len].x = x;
event[len].d = 0;
}
sort(event + 1, event + len + 1);
int k = 1, d, w;
for (i = 1; i <= m; i++) {
cin >> w;
while (k <= len) {
if (event[k].t <= w) {
if (event[k].d)
msi.insert(event[k].x);
else
msi.erase(msi.find(event[k].x));
k++;
} else
break;
}
int ans = -1;
if (msi.size() != 0)
ans = *msi.begin();
cout << ans << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <set>
using namespace std;
const int InF = 0x3f3f3f3f, maxn = 2e6 + 2;
struct node {
int t, x, d;
inline bool operator<(const node &x) const { return t < x.t; }
} event[maxn];
int n, m;
int len;
multiset<int> msi;
int main() {
cin >> n >> m;
int i;
for (i = 1; i <= n; i++) {
int s, t, x;
cin >> s >> t >> x;
event[++len].t = s - x;
event[len].x = x;
event[len].d = 1;
event[++len].t = t - x;
event[len].x = x;
event[len].d = 0;
}
sort(event + 1, event + len + 1);
int k = 1, d, w;
for (i = 1; i <= m; i++) {
cin >> w;
while (k <= len) {
if (event[k].t <= w) {
if (event[k].d)
msi.insert(event[k].x);
else
msi.erase(msi.find(event[k].x));
k++;
} else
break;
}
int ans = -1;
if (msi.size() != 0)
ans = *msi.begin();
cout << ans << endl;
}
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p03033 | C++ | Time Limit Exceeded | #include <algorithm> // minmax, sort, swap
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <cstdio> // printf, scanf
#include <iomanip> //cout<<setprecision(n)
#include <iostream> // cin, cout, cerr, clog
#include <iterator> //iterators
#include <map> // key-value pairs sorted by keys
#include <numeric> // iota, gcd, lcm
#include <queue> // queue
#include <set> // sets
#include <stack> // stack
#include <string> // string
#include <unordered_map> // hashed by keys
#include <vector> // vectors
#define rep(i, n) for (long long i = 0; i < n; i++)
typedef long long ll; // at least int64 > 9*10^18
typedef unsigned long long ull; // at least uint64
struct Roadwork {
ll s, t, x;
Roadwork(ll ss, ll tt, ll xx) : s(ss), t(tt), x(xx) {}
};
ll ans[200001];
int main() {
std::cin.tie(0);
std::ios_base::sync_with_stdio(false);
ll n, q;
std::cin >> n >> q;
std::vector<Roadwork> RW;
RW.reserve(n);
std::set<ll> P;
rep(i, n) {
ll s, t, x;
std::cin >> s >> t >> x;
RW.emplace_back(s - x, t - x, x);
}
std::unordered_map<ll, ll> um;
rep(i, q) {
ll d;
std::cin >> d;
P.insert(d);
um[d] = i;
ans[i] = -1;
}
std::sort(RW.begin(), RW.end(), [](Roadwork a, Roadwork b) {
if (a.x == b.x)
return a.s < b.s;
return a.x < b.x;
});
for (auto r : RW) {
while (P.size() > 0) {
auto p = lower_bound(P.begin(), P.end(), r.s);
if (p == P.end())
break;
if (r.t <= (*p))
break;
ans[um[(*p)]] = r.x;
P.erase(p);
}
}
rep(i, q) std::cout << ans[i] << "\n";
return 0;
} | #include <algorithm> // minmax, sort, swap
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <cstdio> // printf, scanf
#include <iomanip> //cout<<setprecision(n)
#include <iostream> // cin, cout, cerr, clog
#include <iterator> //iterators
#include <map> // key-value pairs sorted by keys
#include <numeric> // iota, gcd, lcm
#include <queue> // queue
#include <set> // sets
#include <stack> // stack
#include <string> // string
#include <unordered_map> // hashed by keys
#include <vector> // vectors
#define rep(i, n) for (long long i = 0; i < n; i++)
typedef long long ll; // at least int64 > 9*10^18
typedef unsigned long long ull; // at least uint64
struct Roadwork {
ll s, t, x;
Roadwork(ll ss, ll tt, ll xx) : s(ss), t(tt), x(xx) {}
};
ll ans[200001];
int main() {
std::cin.tie(0);
std::ios_base::sync_with_stdio(false);
ll n, q;
std::cin >> n >> q;
std::vector<Roadwork> RW;
RW.reserve(n);
std::set<ll> P;
rep(i, n) {
ll s, t, x;
std::cin >> s >> t >> x;
RW.emplace_back(s - x, t - x, x);
}
std::unordered_map<ll, ll> um;
rep(i, q) {
ll d;
std::cin >> d;
P.insert(d);
um[d] = i;
ans[i] = -1;
}
std::sort(RW.begin(), RW.end(), [](Roadwork a, Roadwork b) {
if (a.x == b.x)
return a.s < b.s;
return a.x < b.x;
});
for (auto r : RW) {
while (P.size() > 0) {
auto p = P.lower_bound(r.s);
if (p == P.end())
break;
if (r.t <= (*p))
break;
ans[um[(*p)]] = r.x;
P.erase(p);
}
}
rep(i, q) std::cout << ans[i] << "\n";
return 0;
} | replace | 54 | 55 | 54 | 55 | TLE | |
p03033 | C++ | Time Limit Exceeded | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tiii;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;
int ng[200010];
int main() {
int n, q;
cin >> n >> q;
priority_queue<tiii, vector<tiii>, greater<tiii>> que;
rep(i, n) {
int s, t, x;
cin >> s >> t >> x;
que.push(tiii(x, s - x, t - x));
}
set<int> st;
rep(i, q) {
int a;
cin >> a;
st.insert(a);
}
vector<pii> ans(0);
while (st.size() && que.size()) {
int a, b, x;
tie(x, a, b) = que.top();
if (st.lower_bound(a) == st.end()) {
que.pop();
} else if (*st.lower_bound(a) < b) {
ans.push_back(pii(*st.lower_bound(a), x));
st.erase(*st.lower_bound(a));
} else
que.pop();
}
for (auto c : st) {
ans.push_back(pii(c, -1));
}
sort(all(ans));
rep(i, ans.size()) { cout << ans[i].second << endl; }
} | // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tiii;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;
int ng[200010];
int main() {
int n, q;
cin >> n >> q;
priority_queue<tiii, vector<tiii>, greater<tiii>> que;
rep(i, n) {
int s, t, x;
cin >> s >> t >> x;
que.push(tiii(x, s - x, t - x));
}
set<int> st;
rep(i, q) {
int a;
cin >> a;
st.insert(a);
}
vector<pii> ans(0);
while (st.size() && que.size()) {
int a, b, x;
tie(x, a, b) = que.top();
if (st.lower_bound(a) == st.end()) {
que.pop();
} else if (*st.lower_bound(a) < b) {
ans.push_back(pii(*st.lower_bound(a), x));
st.erase(*st.lower_bound(a));
} else
que.pop();
}
for (auto c : st) {
ans.push_back(pii(c, -1));
}
sort(all(ans));
rep(i, ans.size()) { cout << ans[i].second << endl; }
} | replace | 0 | 1 | 0 | 1 | TLE | |
p03033 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
const int MAXN = 200005;
const int MOD = 1000000007;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define DEC(i, a, b) for (int i = (a); i >= (b); i--)
#define fst first
#define snd second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define sz(v) ((int)(v).size())
#define db(x) cerr << #x << " = " << x << "\n"
#define LOW(v, x) (lower_bound(all(v), (x)) - (v).begin())
int N, Q;
int X[MAXN], S[MAXN], T[MAXN];
struct node {
int l, r;
int v = INT_MAX;
} t[50 * MAXN];
int idx = 1;
void cchild(int id) {
if (t[id].l == 0)
t[id].l = ++idx;
if (t[id].r == 0)
t[id].r = ++idx;
}
void selfupd(int id, int v) { t[id].v = min(t[id].v, v); }
void prop(int id) {
if (t[id].l != 0)
selfupd(t[id].l, t[id].v);
if (t[id].r != 0)
selfupd(t[id].r, t[id].v);
}
void upd(int id, int s, int e, int x, int y, int v) {
if (s == x && e == y) {
t[id].v = min(t[id].v, v);
return;
}
int m = (s + e) >> 1;
cchild(id);
prop(id);
if (x <= m)
upd(t[id].l, s, m, x, min(m, y), v);
if (y > m)
upd(t[id].r, m + 1, e, max(m + 1, x), y, v);
}
int query(int id, int s, int e, int x) {
if (s == x && e == x) {
return t[id].v;
}
int m = (s + e) >> 1;
cchild(id);
prop(id);
if (x <= m)
return query(t[id].l, s, m, x);
else
return query(t[id].r, m + 1, e, x);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N >> Q;
typedef tuple<int, int, int> ti;
vector<ti> vec;
FOR(i, 1, N) {
int s, t, x;
cin >> s >> t >> x;
s -= x;
t -= x;
--t;
s = max(s, 0);
t = max(t, 0);
vec.pb(ti(x, s, t));
}
//~ sort(all(vec));
FOR(i, 1, N) tie(X[i], S[i], T[i]) = vec[i - 1];
//~ FOR(i,1,N)cout<<X[i]<<' '<<S[i]<<' '<<T[i]<<"\n";
FOR(i, 1, N) { upd(1, 0, 1e9, S[i], T[i], X[i]); }
while (Q--) {
int d;
cin >> d;
int tmp = query(1, 0, 1e9, d);
if (tmp == INT_MAX)
tmp = -1;
cout << tmp << "\n";
}
}
/*
*/
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
const int MAXN = 200005;
const int MOD = 1000000007;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define DEC(i, a, b) for (int i = (a); i >= (b); i--)
#define fst first
#define snd second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define sz(v) ((int)(v).size())
#define db(x) cerr << #x << " = " << x << "\n"
#define LOW(v, x) (lower_bound(all(v), (x)) - (v).begin())
int N, Q;
int X[MAXN], S[MAXN], T[MAXN];
struct node {
int l, r;
int v = INT_MAX;
} t[200 * MAXN];
int idx = 1;
void cchild(int id) {
if (t[id].l == 0)
t[id].l = ++idx;
if (t[id].r == 0)
t[id].r = ++idx;
}
void selfupd(int id, int v) { t[id].v = min(t[id].v, v); }
void prop(int id) {
if (t[id].l != 0)
selfupd(t[id].l, t[id].v);
if (t[id].r != 0)
selfupd(t[id].r, t[id].v);
}
void upd(int id, int s, int e, int x, int y, int v) {
if (s == x && e == y) {
t[id].v = min(t[id].v, v);
return;
}
int m = (s + e) >> 1;
cchild(id);
prop(id);
if (x <= m)
upd(t[id].l, s, m, x, min(m, y), v);
if (y > m)
upd(t[id].r, m + 1, e, max(m + 1, x), y, v);
}
int query(int id, int s, int e, int x) {
if (s == x && e == x) {
return t[id].v;
}
int m = (s + e) >> 1;
cchild(id);
prop(id);
if (x <= m)
return query(t[id].l, s, m, x);
else
return query(t[id].r, m + 1, e, x);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N >> Q;
typedef tuple<int, int, int> ti;
vector<ti> vec;
FOR(i, 1, N) {
int s, t, x;
cin >> s >> t >> x;
s -= x;
t -= x;
--t;
s = max(s, 0);
t = max(t, 0);
vec.pb(ti(x, s, t));
}
//~ sort(all(vec));
FOR(i, 1, N) tie(X[i], S[i], T[i]) = vec[i - 1];
//~ FOR(i,1,N)cout<<X[i]<<' '<<S[i]<<' '<<T[i]<<"\n";
FOR(i, 1, N) { upd(1, 0, 1e9, S[i], T[i], X[i]); }
while (Q--) {
int d;
cin >> d;
int tmp = query(1, 0, 1e9, d);
if (tmp == INT_MAX)
tmp = -1;
cout << tmp << "\n";
}
}
/*
*/
| replace | 21 | 22 | 21 | 22 | -11 | |
p03033 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
int main() {
int n, q;
cin >> n >> q;
vector<tuple<ll, ll, ll>> vt(n);
set<P> sq;
for (int i = 0; i < n; ++i) {
ll s, t, x;
cin >> s >> t >> x;
vt[i] = make_tuple(x, s - x, t - x);
}
sort(vt.begin(), vt.end());
for (int i = 0; i < q; ++i) {
int d;
cin >> d;
sq.insert(make_pair(d, i));
}
int c = 0;
vector<ll> ret(q, -1);
for (int i = 0; i < n; ++i) {
auto itrs =
lower_bound(sq.begin(), sq.end(), make_pair(get<1>(vt[i]), -mod));
auto itrt =
lower_bound(sq.begin(), sq.end(), make_pair(get<2>(vt[i]), -mod));
while (itrs != itrt) {
ret[itrs->second] = get<0>(vt[i]);
sq.erase(itrs++);
}
}
for (int i = 0; i < q; ++i) {
cout << ret[i] << endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
int main() {
int n, q;
cin >> n >> q;
vector<tuple<ll, ll, ll>> vt(n);
set<P> sq;
for (int i = 0; i < n; ++i) {
ll s, t, x;
cin >> s >> t >> x;
vt[i] = make_tuple(x, s - x, t - x);
}
sort(vt.begin(), vt.end());
for (int i = 0; i < q; ++i) {
int d;
cin >> d;
sq.insert(make_pair(d, i));
}
int c = 0;
vector<ll> ret(q, -1);
for (int i = 0; i < n; ++i) {
auto itrs = sq.lower_bound(make_pair(get<1>(vt[i]), -mod));
auto itrt = sq.lower_bound(make_pair(get<2>(vt[i]), -mod));
while (itrs != itrt) {
ret[itrs->second] = get<0>(vt[i]);
sq.erase(itrs++);
}
}
for (int i = 0; i < q; ++i) {
cout << ret[i] << endl;
}
return 0;
} | replace | 43 | 47 | 43 | 45 | TLE | |
p03034 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
const ll mod = 1e9 + 7;
const ll INF = 1e9;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
ll f(int x, vector<ll> s) {
ll ret = 0;
int n = s.size();
ll ma = 0;
for (int k = 1; k <= (n - 1) / x; k++) {
if ((n - 1) % x == 0 && n - 1 - (k - 1) * x <= (k - 1) * x)
break;
ret += s[n - 1 - (k - 1) * x] + s[(k - 1) * x];
ma = max(ret, ma);
}
return ma;
}
int main() {
int n;
cin >> n;
vector<ll> s(n);
rep(i, n) cin >> s[i];
ll ans = 0;
for (int x = 1; x < n; x++) {
ans = max(ans, f(x, s));
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
const ll mod = 1e9 + 7;
const ll INF = 1e9;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
ll f(int x, vector<ll> s) {
ll ret = 0;
int n = s.size();
ll ma = 0;
for (int k = 1; k <= (n - 1) / x; k++) {
if ((n - 1) % x == 0 && n - 1 - (k - 1) * x <= (k - 1) * x)
break;
ret += s[n - 1 - (k - 1) * x] + s[(k - 1) * x];
ma = max(ret, ma);
}
return ma;
}
int main() {
int n;
cin >> n;
vector<ll> s(n);
rep(i, n) cin >> s[i];
ll ans = 0;
for (int x = 1; x < n; x++) {
ll ret = 0;
// ll ma = 0;
for (int k = 1; k <= (n - 1) / x; k++) {
if ((n - 1) % x == 0 && n - 1 - (k - 1) * x <= (k - 1) * x)
break;
ret += s[n - 1 - (k - 1) * x] + s[(k - 1) * x];
ans = max(ret, ans);
}
// ans = max(ans,f(x,s));
}
cout << ans << endl;
return 0;
} | replace | 51 | 52 | 51 | 62 | TLE | |
p03034 | C++ | Runtime Error | #include <bits/stdc++.h>
int main() {
using namespace std;
unsigned long N;
cin >> N;
vector<long> s(N);
for (auto &i : s)
cin >> i;
long ans{0};
for (unsigned long i = 1; i < N; ++i) {
long tmp{0};
for (unsigned long j = 0, k = N - 1; k > 0 && (k % i != 0 || j < k);
j += i, k -= i)
ans = max(ans, tmp += s[j] + s[k]);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
int main() {
using namespace std;
unsigned long N;
cin >> N;
vector<long> s(N);
for (auto &i : s)
cin >> i;
long ans{0};
for (unsigned long i = 1; i < N; ++i) {
long tmp{0};
for (unsigned long j = 0, k = N - 1; k > i && (k % i != 0 || j < k);
j += i, k -= i)
ans = max(ans, tmp += s[j] + s[k]);
}
cout << ans << endl;
return 0;
}
| replace | 12 | 13 | 12 | 13 | -11 | |
p03034 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <chrono>
#include <random>
#include <thread>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define all(c) c.begin(), c.end()
#define repeat(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
os << ",";
os << *it;
}
return os << "}";
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &v) {
os << "{";
os << v.first << ", " << v.second;
return os << "}";
}
// ---------------------------------------------------------------------------
using point = complex<double>;
using ll = int64_t;
int my_main(int argc, char **argv) {
ios::sync_with_stdio(false);
cin.tie(0);
ll n;
cin >> n;
vector<ll> s(n);
for (ll &i : s)
cin >> i;
ll ret = 0;
for (ll c = 1; c < n - 1; c++) {
vector<bool> used(n, false);
ll sum = 0;
for (ll k = 1; (n - 1) - (k * c) < c; k++) {
ll a0 = (n - 1) - k * c;
ll a1 = k * c;
if (used[a0])
break;
used[a0] = true;
if (used[a1])
break;
used[a1] = true;
sum += s[a0] + s[a1];
ret = max(ret, sum);
}
}
cout << ret << endl;
return 0;
}
// ----------------------------------------------------------------------------
// Test driver
#ifdef DEBUG
#define MAY_RUN_TESTCASE
#endif
#ifdef MAY_RUN_TESTCASE
#include <fstream>
#if __has_include(<unistd.h>)
// Mac, Linux
#include <unistd.h>
#elif __has_include(<io.h>)
// Windows
#include <io.h>
#else
// Other?
#error "unistd.h or io.h not found"
#endif
bool test_file_exists(const std::string &str) {
std::ifstream fs(str);
return fs.is_open();
}
#endif
int main(int argc, char **argv) {
#ifndef MAY_RUN_TESTCASE
return my_main(argc, argv);
#else
if (argc == 1) {
return my_main(argc, argv);
} else if (argc == 2) {
char *stdin_file = argv[1];
freopen(stdin_file, "r", stdin);
return my_main(argc, argv);
} else if (argc == 5) {
std::string stdin_file = argv[1];
std::string expected_file = argv[2];
std::string stdout_file = argv[3];
std::string stderr_file = argv[4];
if (!test_file_exists(stdin_file)) {
std::cerr << stdin_file << " not found" << std::endl;
return 3;
}
if (!test_file_exists(expected_file)) {
std::cerr << expected_file << " not found" << std::endl;
return 3;
}
int original_stdin = dup(fileno(stdin));
int original_stdout = dup(fileno(stdout));
int original_stderr = dup(fileno(stderr));
freopen(stdin_file.c_str(), "r", stdin);
freopen(stdout_file.c_str(), "w", stdout);
freopen(stderr_file.c_str(), "w", stderr);
int ret = my_main(argc, argv);
fflush(stdout);
fflush(stderr);
dup2(original_stderr, fileno(stderr));
dup2(original_stdout, fileno(stdout));
dup2(original_stdin, fileno(stdin));
if (ret != 0) {
std::cerr << "main returns " << ret << std::endl;
return ret;
}
std::ifstream inp(stdin_file);
std::ifstream out(stdout_file);
std::ifstream err(stderr_file);
std::ifstream exp(expected_file);
// Clear is needed if the file is empty.
std::cout << "----- input -----" << std::endl;
std::cout << inp.rdbuf() << std::endl;
std::cout.clear();
std::cout << "-----------------" << std::endl << std::endl;
std::cout << "----- output ----" << std::endl;
std::cout << out.rdbuf() << std::endl;
std::cout.clear();
std::cout << "-----------------" << std::endl << std::endl;
std::cout << "---- expected ---" << std::endl;
std::cout << exp.rdbuf() << std::endl;
std::cout.clear();
std::cout << "-----------------" << std::endl << std::endl;
std::cout << "----- stderr ----" << std::endl;
std::cout << err.rdbuf() << std::endl;
std::cout.clear();
std::cout << "-----------------" << std::endl;
inp.seekg(0);
out.seekg(0);
exp.seekg(0);
err.seekg(0);
std::string output_str, expected_str;
{
std::stringstream output_ss;
output_ss << out.rdbuf();
output_str = output_ss.str();
std::stringstream expected_ss;
expected_ss << exp.rdbuf();
expected_str = expected_ss.str();
}
// Remove trailing spaces
output_str.erase(output_str.find_last_not_of(" \n\r\t") + 1);
expected_str.erase(expected_str.find_last_not_of(" \n\r\t") + 1);
if (output_str == expected_str)
return 0;
else
return 1;
}
return 1;
#endif
}
| #include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <chrono>
#include <random>
#include <thread>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define all(c) c.begin(), c.end()
#define repeat(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
os << ",";
os << *it;
}
return os << "}";
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &v) {
os << "{";
os << v.first << ", " << v.second;
return os << "}";
}
// ---------------------------------------------------------------------------
using point = complex<double>;
using ll = int64_t;
int my_main(int argc, char **argv) {
ios::sync_with_stdio(false);
cin.tie(0);
ll n;
cin >> n;
vector<ll> s(n);
for (ll &i : s)
cin >> i;
ll ret = 0;
for (ll c = 1; c < n - 1; c++) {
vector<bool> used(n, false);
ll sum = 0;
for (ll k = 1; c < (n - 1 - k * c); k++) {
ll a0 = (n - 1) - k * c;
ll a1 = k * c;
if (used[a0])
break;
used[a0] = true;
if (used[a1])
break;
used[a1] = true;
sum += s[a0] + s[a1];
ret = max(ret, sum);
}
}
cout << ret << endl;
return 0;
}
// ----------------------------------------------------------------------------
// Test driver
#ifdef DEBUG
#define MAY_RUN_TESTCASE
#endif
#ifdef MAY_RUN_TESTCASE
#include <fstream>
#if __has_include(<unistd.h>)
// Mac, Linux
#include <unistd.h>
#elif __has_include(<io.h>)
// Windows
#include <io.h>
#else
// Other?
#error "unistd.h or io.h not found"
#endif
bool test_file_exists(const std::string &str) {
std::ifstream fs(str);
return fs.is_open();
}
#endif
int main(int argc, char **argv) {
#ifndef MAY_RUN_TESTCASE
return my_main(argc, argv);
#else
if (argc == 1) {
return my_main(argc, argv);
} else if (argc == 2) {
char *stdin_file = argv[1];
freopen(stdin_file, "r", stdin);
return my_main(argc, argv);
} else if (argc == 5) {
std::string stdin_file = argv[1];
std::string expected_file = argv[2];
std::string stdout_file = argv[3];
std::string stderr_file = argv[4];
if (!test_file_exists(stdin_file)) {
std::cerr << stdin_file << " not found" << std::endl;
return 3;
}
if (!test_file_exists(expected_file)) {
std::cerr << expected_file << " not found" << std::endl;
return 3;
}
int original_stdin = dup(fileno(stdin));
int original_stdout = dup(fileno(stdout));
int original_stderr = dup(fileno(stderr));
freopen(stdin_file.c_str(), "r", stdin);
freopen(stdout_file.c_str(), "w", stdout);
freopen(stderr_file.c_str(), "w", stderr);
int ret = my_main(argc, argv);
fflush(stdout);
fflush(stderr);
dup2(original_stderr, fileno(stderr));
dup2(original_stdout, fileno(stdout));
dup2(original_stdin, fileno(stdin));
if (ret != 0) {
std::cerr << "main returns " << ret << std::endl;
return ret;
}
std::ifstream inp(stdin_file);
std::ifstream out(stdout_file);
std::ifstream err(stderr_file);
std::ifstream exp(expected_file);
// Clear is needed if the file is empty.
std::cout << "----- input -----" << std::endl;
std::cout << inp.rdbuf() << std::endl;
std::cout.clear();
std::cout << "-----------------" << std::endl << std::endl;
std::cout << "----- output ----" << std::endl;
std::cout << out.rdbuf() << std::endl;
std::cout.clear();
std::cout << "-----------------" << std::endl << std::endl;
std::cout << "---- expected ---" << std::endl;
std::cout << exp.rdbuf() << std::endl;
std::cout.clear();
std::cout << "-----------------" << std::endl << std::endl;
std::cout << "----- stderr ----" << std::endl;
std::cout << err.rdbuf() << std::endl;
std::cout.clear();
std::cout << "-----------------" << std::endl;
inp.seekg(0);
out.seekg(0);
exp.seekg(0);
err.seekg(0);
std::string output_str, expected_str;
{
std::stringstream output_ss;
output_ss << out.rdbuf();
output_str = output_ss.str();
std::stringstream expected_ss;
expected_ss << exp.rdbuf();
expected_str = expected_ss.str();
}
// Remove trailing spaces
output_str.erase(output_str.find_last_not_of(" \n\r\t") + 1);
expected_str.erase(expected_str.find_last_not_of(" \n\r\t") + 1);
if (output_str == expected_str)
return 0;
else
return 1;
}
return 1;
#endif
}
| replace | 80 | 81 | 80 | 82 | -6 | double free or corruption (out)
|
p03034 | C++ | Time Limit Exceeded | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define int long long
#define ll long long
#define eps DBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX / 10
#define P pair<int, int>
#define prique priority_queue
using namespace std;
int n, s[100010];
map<P, int> dp;
signed main() {
cin >> n;
rep(i, n) cin >> s[i];
rep(i, n) { // 2i+1回でゴール
REP(j, n - 1) { // a-b=j
if (n - 1 <= i * j + j)
continue;
if ((n - 1 - i * j) % j == 0 && (n - 1 - i * j) / j * 2 <= 2 * i)
continue;
// 2i回目の後いるのはi*j番
if (i)
dp[make_pair(i, j)] =
dp[make_pair(i - 1, j)] + s[n - 1 - i * j] + s[i * j];
else
dp[make_pair(i, j)] = s[n - 1 - i * j] + s[i * j];
}
}
int ans = 0;
for (pair<P, int> p : dp) {
ans = max(ans, p.second);
}
cout << ans << endl;
} | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define int long long
#define ll long long
#define eps DBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX / 10
#define P pair<int, int>
#define prique priority_queue
using namespace std;
int n, s[100010];
map<P, int> dp;
signed main() {
cin >> n;
rep(i, n) cin >> s[i];
rep(i, n) { // 2i+1回でゴール
REP(j, n - 1) { // a-b=j
if (n - 1 <= i * j + j)
break;
if ((n - 1 - i * j) % j == 0 && (n - 1 - i * j) / j * 2 <= 2 * i)
continue;
// 2i回目の後いるのはi*j番
if (i)
dp[make_pair(i, j)] =
dp[make_pair(i - 1, j)] + s[n - 1 - i * j] + s[i * j];
else
dp[make_pair(i, j)] = s[n - 1 - i * j] + s[i * j];
}
}
int ans = 0;
for (pair<P, int> p : dp) {
ans = max(ans, p.second);
}
cout << ans << endl;
} | replace | 40 | 41 | 40 | 41 | TLE | |
p03034 | C++ | Time Limit Exceeded | #include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using i64 = int64_t;
i64 n;
vector<i64> s;
int main() {
cin >> n;
s.resize(n);
for (int i = 0; i < n; ++i) {
cin >> s[i];
}
i64 ans = 0;
for (int c = 1; c < n; ++c) {
vector<bool> vis(n);
i64 scr = 0;
for (int i = 0; i < n; i += c) {
int j = n - i - 1;
i64 a = j, b = a - c;
if (b <= 0)
break;
if (vis[i])
break;
vis[i] = true;
if (vis[j])
break;
vis[j] = true;
scr += s[i] + s[j];
if (scr == 35) {
cerr << c << endl;
for (int i = 0; i < n; ++i) {
cerr << (vis[i] ? '*' : '.');
}
cerr << endl;
}
ans = max(ans, scr);
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using i64 = int64_t;
i64 n;
vector<i64> s;
int main() {
cin >> n;
s.resize(n);
for (int i = 0; i < n; ++i) {
cin >> s[i];
}
i64 ans = 0;
for (int c = 1; c < n; ++c) {
vector<bool> vis(n);
i64 scr = 0;
for (int i = 0; i < n; i += c) {
int j = n - i - 1;
i64 a = j, b = a - c;
if (b <= 0)
break;
if (vis[i])
break;
vis[i] = true;
if (vis[j])
break;
vis[j] = true;
scr += s[i] + s[j];
ans = max(ans, scr);
}
}
cout << ans << endl;
return 0;
} | replace | 39 | 46 | 39 | 40 | TLE | |
p03034 | C++ | Time Limit Exceeded | #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i, j, k) for (int(i) = (j); (i) < (int)(k); ++(i))
#define rep(i, j) FOR(i, 0, j)
#define each(x, y) for (auto &(x) : (y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << (x) << endl
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define MEM(x, y) memset((x), (y), sizeof(x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
void solve() {
int N;
cin >> N;
vll s(N);
rep(i, N) cin >> s[i];
ll ans = LLONG_MIN;
unordered_set<int> T;
for (int i = 1; i <= N - 1; ++i) { // A-B
T.clear();
ll sum = 0;
for (int j = 0; i * j < N - 1; ++j) { // j turns
int A = N - 1 - i * j;
int B = A - i;
if (B <= 0)
break;
if (T.count(i * j))
break;
T.insert(i * j);
sum += s[i * j];
if (T.count(N - 1 - i * j))
break;
T.insert(N - 1 - i * j);
sum += s[N - 1 - i * j];
smax(ans, sum);
}
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
solve();
return 0;
} | #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i, j, k) for (int(i) = (j); (i) < (int)(k); ++(i))
#define rep(i, j) FOR(i, 0, j)
#define each(x, y) for (auto &(x) : (y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << (x) << endl
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define MEM(x, y) memset((x), (y), sizeof(x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
void solve() {
int N;
cin >> N;
vll s(N);
rep(i, N) cin >> s[i];
ll ans = LLONG_MIN;
set<int> T;
for (int i = 1; i <= N - 1; ++i) { // A-B
T.clear();
ll sum = 0;
for (int j = 0; i * j < N - 1; ++j) { // j turns
int A = N - 1 - i * j;
int B = A - i;
if (B <= 0)
break;
if (T.count(i * j))
break;
T.insert(i * j);
sum += s[i * j];
if (T.count(N - 1 - i * j))
break;
T.insert(N - 1 - i * j);
sum += s[N - 1 - i * j];
smax(ans, sum);
}
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
solve();
return 0;
} | replace | 27 | 28 | 27 | 28 | TLE | |
p03034 | C++ | Time Limit Exceeded | /*
* じょえチャンネル
* 高評価・チャンネル登録よろしくおねがいします!
* https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// here!!!
// define int long long !!!!!
#define int long long
// define int long long !!!!!
#define mod 1000000007ll
// constexpr int mod = 998244353ll;
constexpr double PI = 3.141592653589793238462643383279;
// constexpr double eps = DBL_EPSILON;
typedef long long ll;
#ifdef int
#define inf (int)(3e18)
#else
#define inf (int)(5e8)
#endif
#define intt long long
#define itn long long
#define innt long long
#define P pair<long long, long long>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define rev_rep(i, n) for (int i = n - 1; i >= 0; i--)
#define REV_REP(i, n) for (int i = n; i >= 1; i--)
#define ALL(v) v.begin(), v.end()
#define smallpriority_queue(T) priority_queue<T, vector<T>, greater<T>>
using namespace std;
// Library
// モッドパウ
inline int modpow(int x, int y, int m = mod) {
int res = 1;
while (y) {
if (y & 1) {
res *= x;
res %= m;
}
x = x * x % m;
y /= 2;
}
return res;
}
int mypow(int x, int y) {
int res = 1;
while (y) {
if (y % 2) {
res *= x;
}
x = x * x;
y /= 2;
}
return res;
}
// is the number (x) a prime number?
// bool prime(int x) {
// if (!x || x == 1) {
// return false;
// }
// for (int i = 2; i * i <= x; i++) {
// if (!(x % i)) {
// return false;
// }
// }
// return true;
// }
bool prime(int x) {
if (!x || x == 1) {
return false;
}
if (x == 2) {
return true;
}
if (!(x & 1)) {
return false;
}
for (int i = 3; i * i <= x; i += 2) {
if (!(x % i)) {
return false;
}
}
return true;
}
// saidai-kouyakusuu
inline int gcd(int x, int y) {
if (!y) {
return x;
}
return gcd(y, x % y);
}
// number of keta
int keta(int x) {
int ans = 0;
while (x) {
x /= 10;
ans++;
}
return ans;
}
// number of 2shinsuu keta
int bitketa(int x) {
int ans = 0;
while (x) {
x >>= 1;
ans++;
}
return ans;
}
// sum of keta
int ketasum(int x) {
int ans = 0;
while (x) {
ans += x % 10;
x /= 10;
}
return ans;
}
inline int lcm(int x, int y) {
int ans = x / gcd(x, y) * y;
return ans;
}
int twobeki(int x) {
int ans = 0;
while (1) {
if (!(x & 1)) {
ans++;
x >>= 1;
} else {
break;
}
}
return ans;
}
template <class T, class U> inline bool chmax(T &lhs, const U &rhs) {
if (lhs < rhs) {
lhs = rhs;
return 1;
}
return 0;
}
template <class T, class U> inline bool chmin(T &lhs, const U &rhs) {
if (lhs > rhs) {
lhs = rhs;
return 1;
}
return 0;
}
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
#define fin(i) scanf("%lld", &i)
#define fout(i) printf("%lld", i)
#define fendl printf("\n")
int kai(int x, int y) {
int res = 1;
for (int i = x - y + 1; i <= x; i++) {
res *= i;
res %= mod;
}
return res;
}
int comb(int x, int y) {
if (y > x)
return 0;
// cout<<kai(x, y)<<' '<<modpow(kai(y, y), mod - 2)<<endl;
return kai(x, y) * modpow(kai(y, y), mod - 2) % mod;
}
// Library-End
// 入出力高速化時にはoff!!!!
// #define vecin(v) for(int i=0;i<v.size();i++)scanf("%lld",&v[i]);
// #define vecout(v) {if(v.size())printf("%lld",v[0]);for(int
// i=1;i<(int)v.size();i++)printf(" %lld",v[i]);printf("\n");}
template <class T> class SegTree {
int n;
vector<T> node;
T def;
function<T(T, T)> operation;
function<T(T, T)> update;
public:
SegTree(unsigned int _n, T _def, function<T(T, T)> _operation,
function<T(T, T)> _update)
: def(_def), operation(_operation), update(_update) {
n = 1;
while (n < _n) {
n *= 2;
}
node = vector<T>(n * 2, def);
}
SegTree(vector<int> &initvec, function<T(T, T)> _operation,
function<T(T, T)> _update)
: operation(_operation), update(_update) {
n = 1;
while (n < initvec.size()) {
n *= 2;
}
node = vector<T>(n * 2, def);
for (int i = n; i < n + initvec.size(); i++) {
node[i] = initvec[i - n];
}
for (int i = n - 1; i >= 1; i--) {
node[i] = operation(node[i * 2], node[i * 2 + 1]);
}
}
void change(int i, T x) {
i += n;
node[i] = update(node[i], x);
while (i >= 1) {
i >>= 1;
node[i] = operation(node[i * 2], node[i * 2 + 1]);
}
}
T query(int l, int r) {
l += n;
r += n;
T rx = def, lx = def;
while (l < r) {
if (l & 1) {
lx = operation(lx, node[l]);
l++;
}
if (r & 1) {
r--;
rx = operation(node[r], rx);
}
l >>= 1;
r >>= 1;
}
return operation(lx, rx);
}
T operator[](const int &x) { return node[x + n]; }
void fill(T x) { std::fill(ALL(node), x); }
void print() {
rep(i, n) std::cout << operator[](i) << " ";
std::cout << std::endl;
}
T queryForALL() { return node[1]; }
};
#define R_MIN ([](long long a, long long b) { return min(a, b); })
#define R_MAX ([](long long a, long long b) { return max(a, b); })
#define R_SUM ([](long long a, long long b) { return a + b; })
#define NORMAL_UPDATE ([](long long a, long long b) { return b; })
#define ADD_UPDATE ([](long long a, long long b) { return a + b; })
#define MINUS_UPDATE ([](long long a, long long b) { return a - b; }
class Union_Find {
vector<int> par;
vector<int> ookisa;
public:
Union_Find(int size) {
par = vector<int>(size);
ookisa = vector<int>(size);
for (int i = 0; i < size; i++) {
par[i] = i;
ookisa[i] = 1;
}
}
int find(int x) {
if (par[x] == x) {
return x;
}
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) {
return;
}
if (ookisa[x] < ookisa[y]) {
par[x] = y;
ookisa[y] += ookisa[x];
ookisa[x] = 0;
} else {
par[y] = x;
ookisa[x] += ookisa[y];
ookisa[y] = 0;
}
}
int size(int i) {
i = find(i);
return ookisa[i];
}
bool same(int x, int y) { return find(x) == find(y); }
};
class BIT {
vector<int> data;
int size = 0;
public:
BIT(int _size) {
data = vector<int>(_size + 1);
size = _size;
}
void add(int i, int x) {
while (i <= size) {
data[i] += x;
i += i & -i;
}
}
int sum(int i) {
assert(i <= size);
int s = 0;
while (i > 0) {
s += data[i];
i -= i & -i;
}
return s;
}
int lower_bound(int x) {
if (x <= 0) {
return 0;
} else {
int i = 0;
int r = 1;
while (r < size)
r = r << 1;
for (int len = r; len > 0; len = len >> 1) {
if (i + len < size && data[i + len] < x) {
x -= data[i + len];
i += len;
}
}
return i + 1;
}
}
};
// Union-Find-End
int perm[2000005];
void init_perm() {
perm[0] = 1;
REP(i, 2000004) { perm[i] = perm[i - 1] * i % mod; }
}
int nCk(int x, int y) {
if (y > x) {
return 0;
}
if (x < 0) {
return 0;
}
return perm[x] * modpow(perm[x - y], mod - 2) % mod *
modpow(perm[y], mod - 2) % mod;
}
struct Dot {
double x;
double y;
Dot(double _x = 0.0, double _y = 0.0) {
x = _x;
y = _y;
}
};
struct Dot_i {
int x;
int y;
Dot_i(int _x = 0, int _y = 0) {
x = _x;
y = _y;
}
};
double kyori(pair<int, int> f, pair<int, int> s) {
double ans = 0;
double t = fabs(f.first - s.first);
double y = fabs(f.second - s.second);
ans = sqrt(t * t + y * y);
return ans;
}
double kyori(Dot f, Dot s) {
double ans = 0;
double t = fabs(f.x - s.x);
double y = fabs(f.y - s.y);
ans = sqrt(t * t + y * y);
return ans;
}
inline string stringmax(string &x, string &y) {
if (x.size() > y.size()) {
return x;
}
if (x.size() < y.size()) {
return y;
}
rep(i, x.size()) {
if (x[i] > y[i]) {
return x;
}
if (x[i] < y[i]) {
return y;
}
}
return x;
}
// vector<int> RollingHash(string &s, string& t){
// vector<int> ans;
// __int128 h=0,hamod=0,ki=0,kim=0,hikaku=0,one=0;
// one=1;
// ki=1000000007ll;
// hamod=(one<<61)-1;
// kim=1;
// rep(i,t.size()){
// hikaku*=ki;
// h*=ki;
// kim*=ki;
// hikaku+=t[i];
// h+=s[i];
// hikaku%=hamod;
// h%=hamod;
// kim%=hamod;
// }
// rep(i,(int)s.size()-(int)t.size()+1){
// if (h==hikaku) {
// ans.emplace_back(i);
// }
// h*=ki;
// h%=hamod;
// h+=s[i+(int)t.size()];
// h%=hamod;
// h+=hamod;
// h-=s[i]*kim%hamod;
// h%=hamod;
// }
// return ans;
// }
struct edge {
int to;
int length;
edge(int _to, int _length) {
to = _to;
length = _length;
}
};
vector<int> djkstra(vector<vector<edge>> &road, int start) {
vector<int> kyo(road.size(), inf);
smallpriority_queue(P) q;
q.push({0, start});
kyo[start] = 0;
while (q.size()) {
int x = q.top().second;
itn now = q.top().first;
q.pop();
if (kyo[x] < now) {
continue;
}
for (auto &i : road[x]) {
if (kyo[i.to] > now + i.length) {
kyo[i.to] = now + i.length;
q.push({kyo[i.to], i.to});
}
}
}
return kyo;
}
template <class T> void change_to_unique(vector<T> &v) {
std::sort(ALL(v));
auto k = unique(ALL(v));
if (k != v.end())
v.erase(k, v.end());
}
double kodo_dosuu(double r) { return 180.0 * r / (double)PI; }
double dosuu_kodo(double r) { return r * (double)PI / 180.0; }
double kakudo(Dot a, Dot b1, Dot b2) {
double size1 = kyori(a, b1), size2 = kyori(a, b2);
double nai = (b1.x - a.x) * (b2.x - a.x) + (b1.y - a.y) * (b2.y - a.y);
nai /= size1 * size2;
return kodo_dosuu(acos(nai));
}
struct fraction {
int shi;
int bo;
fraction(int bunshi, int bunbo) : bo(bunbo), shi(bunshi) {
if (bunbo && bunshi) {
int g = gcd(bo, shi);
bo /= g;
shi /= g;
}
};
explicit inline operator double() const { return (double)shi / (double)bo; }
explicit inline operator long double() const {
return (long double)shi / (long double)bo;
}
};
bool operator<(const fraction &b1, const fraction &b2) {
return b1.shi * b2.bo < b2.shi * b1.bo;
}
bool operator>(const fraction &b1, const fraction &b2) {
return b1.shi * b2.bo > b2.shi * b1.bo;
}
template <class T> void vecout(vector<T> &v) {
if (v.size()) {
cout << v[0];
}
REP(i, (int)v.size() - 1) { cout << ' ' << v[i]; }
cout << endl;
}
#define endl "\n" // interactive の時に注意!!!
#define Endl "\n" // interactive の時に注意!!!
#define cinn cin
#define printd cout << fixed << setprecision(10)
#define rrep(i, f, s) for (int i = f; i < s; i++)
#define RREP(i, f, s) for (int i = f; i <= s; i++)
#define REV_RREP(i, f, s) for (int i = s; i >= f; i--)
#define hen_rep(i, l, step) for (int i = 0; i < l; i += step)
#define HEN_REP(i, l, step) for (int i = 1; i <= l; i += step)
int n, ans;
itn s[100004];
vector<P> now[100004];
signed main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cin >> n;
rep(i, n) { cin >> s[i]; }
REP(i, n - 1) {
int cnt = 0;
for (int j = n - i - 1; j >= i + 1; j -= i) {
cnt += s[j];
now[j].emplace_back(i, cnt);
}
}
ans = 0;
REP(i, n - 2) {
for (auto &j : now[i]) {
int ka = j.second;
int k = j.first;
if (!((i - j.first) % j.first)) {
if (n - 1 > i + (i - j.first)) {
continue;
}
}
while (k + (i - j.first) < n - 1) {
ka += s[k];
k += j.first;
}
chmax(ans, ka);
}
}
cout << ans << endl;
}
| /*
* じょえチャンネル
* 高評価・チャンネル登録よろしくおねがいします!
* https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
// here!!!
// define int long long !!!!!
#define int long long
// define int long long !!!!!
#define mod 1000000007ll
// constexpr int mod = 998244353ll;
constexpr double PI = 3.141592653589793238462643383279;
// constexpr double eps = DBL_EPSILON;
typedef long long ll;
#ifdef int
#define inf (int)(3e18)
#else
#define inf (int)(5e8)
#endif
#define intt long long
#define itn long long
#define innt long long
#define P pair<long long, long long>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define rev_rep(i, n) for (int i = n - 1; i >= 0; i--)
#define REV_REP(i, n) for (int i = n; i >= 1; i--)
#define ALL(v) v.begin(), v.end()
#define smallpriority_queue(T) priority_queue<T, vector<T>, greater<T>>
using namespace std;
// Library
// モッドパウ
inline int modpow(int x, int y, int m = mod) {
int res = 1;
while (y) {
if (y & 1) {
res *= x;
res %= m;
}
x = x * x % m;
y /= 2;
}
return res;
}
int mypow(int x, int y) {
int res = 1;
while (y) {
if (y % 2) {
res *= x;
}
x = x * x;
y /= 2;
}
return res;
}
// is the number (x) a prime number?
// bool prime(int x) {
// if (!x || x == 1) {
// return false;
// }
// for (int i = 2; i * i <= x; i++) {
// if (!(x % i)) {
// return false;
// }
// }
// return true;
// }
bool prime(int x) {
if (!x || x == 1) {
return false;
}
if (x == 2) {
return true;
}
if (!(x & 1)) {
return false;
}
for (int i = 3; i * i <= x; i += 2) {
if (!(x % i)) {
return false;
}
}
return true;
}
// saidai-kouyakusuu
inline int gcd(int x, int y) {
if (!y) {
return x;
}
return gcd(y, x % y);
}
// number of keta
int keta(int x) {
int ans = 0;
while (x) {
x /= 10;
ans++;
}
return ans;
}
// number of 2shinsuu keta
int bitketa(int x) {
int ans = 0;
while (x) {
x >>= 1;
ans++;
}
return ans;
}
// sum of keta
int ketasum(int x) {
int ans = 0;
while (x) {
ans += x % 10;
x /= 10;
}
return ans;
}
inline int lcm(int x, int y) {
int ans = x / gcd(x, y) * y;
return ans;
}
int twobeki(int x) {
int ans = 0;
while (1) {
if (!(x & 1)) {
ans++;
x >>= 1;
} else {
break;
}
}
return ans;
}
template <class T, class U> inline bool chmax(T &lhs, const U &rhs) {
if (lhs < rhs) {
lhs = rhs;
return 1;
}
return 0;
}
template <class T, class U> inline bool chmin(T &lhs, const U &rhs) {
if (lhs > rhs) {
lhs = rhs;
return 1;
}
return 0;
}
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
#define fin(i) scanf("%lld", &i)
#define fout(i) printf("%lld", i)
#define fendl printf("\n")
int kai(int x, int y) {
int res = 1;
for (int i = x - y + 1; i <= x; i++) {
res *= i;
res %= mod;
}
return res;
}
int comb(int x, int y) {
if (y > x)
return 0;
// cout<<kai(x, y)<<' '<<modpow(kai(y, y), mod - 2)<<endl;
return kai(x, y) * modpow(kai(y, y), mod - 2) % mod;
}
// Library-End
// 入出力高速化時にはoff!!!!
// #define vecin(v) for(int i=0;i<v.size();i++)scanf("%lld",&v[i]);
// #define vecout(v) {if(v.size())printf("%lld",v[0]);for(int
// i=1;i<(int)v.size();i++)printf(" %lld",v[i]);printf("\n");}
template <class T> class SegTree {
int n;
vector<T> node;
T def;
function<T(T, T)> operation;
function<T(T, T)> update;
public:
SegTree(unsigned int _n, T _def, function<T(T, T)> _operation,
function<T(T, T)> _update)
: def(_def), operation(_operation), update(_update) {
n = 1;
while (n < _n) {
n *= 2;
}
node = vector<T>(n * 2, def);
}
SegTree(vector<int> &initvec, function<T(T, T)> _operation,
function<T(T, T)> _update)
: operation(_operation), update(_update) {
n = 1;
while (n < initvec.size()) {
n *= 2;
}
node = vector<T>(n * 2, def);
for (int i = n; i < n + initvec.size(); i++) {
node[i] = initvec[i - n];
}
for (int i = n - 1; i >= 1; i--) {
node[i] = operation(node[i * 2], node[i * 2 + 1]);
}
}
void change(int i, T x) {
i += n;
node[i] = update(node[i], x);
while (i >= 1) {
i >>= 1;
node[i] = operation(node[i * 2], node[i * 2 + 1]);
}
}
T query(int l, int r) {
l += n;
r += n;
T rx = def, lx = def;
while (l < r) {
if (l & 1) {
lx = operation(lx, node[l]);
l++;
}
if (r & 1) {
r--;
rx = operation(node[r], rx);
}
l >>= 1;
r >>= 1;
}
return operation(lx, rx);
}
T operator[](const int &x) { return node[x + n]; }
void fill(T x) { std::fill(ALL(node), x); }
void print() {
rep(i, n) std::cout << operator[](i) << " ";
std::cout << std::endl;
}
T queryForALL() { return node[1]; }
};
#define R_MIN ([](long long a, long long b) { return min(a, b); })
#define R_MAX ([](long long a, long long b) { return max(a, b); })
#define R_SUM ([](long long a, long long b) { return a + b; })
#define NORMAL_UPDATE ([](long long a, long long b) { return b; })
#define ADD_UPDATE ([](long long a, long long b) { return a + b; })
#define MINUS_UPDATE ([](long long a, long long b) { return a - b; }
class Union_Find {
vector<int> par;
vector<int> ookisa;
public:
Union_Find(int size) {
par = vector<int>(size);
ookisa = vector<int>(size);
for (int i = 0; i < size; i++) {
par[i] = i;
ookisa[i] = 1;
}
}
int find(int x) {
if (par[x] == x) {
return x;
}
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) {
return;
}
if (ookisa[x] < ookisa[y]) {
par[x] = y;
ookisa[y] += ookisa[x];
ookisa[x] = 0;
} else {
par[y] = x;
ookisa[x] += ookisa[y];
ookisa[y] = 0;
}
}
int size(int i) {
i = find(i);
return ookisa[i];
}
bool same(int x, int y) { return find(x) == find(y); }
};
class BIT {
vector<int> data;
int size = 0;
public:
BIT(int _size) {
data = vector<int>(_size + 1);
size = _size;
}
void add(int i, int x) {
while (i <= size) {
data[i] += x;
i += i & -i;
}
}
int sum(int i) {
assert(i <= size);
int s = 0;
while (i > 0) {
s += data[i];
i -= i & -i;
}
return s;
}
int lower_bound(int x) {
if (x <= 0) {
return 0;
} else {
int i = 0;
int r = 1;
while (r < size)
r = r << 1;
for (int len = r; len > 0; len = len >> 1) {
if (i + len < size && data[i + len] < x) {
x -= data[i + len];
i += len;
}
}
return i + 1;
}
}
};
// Union-Find-End
int perm[2000005];
void init_perm() {
perm[0] = 1;
REP(i, 2000004) { perm[i] = perm[i - 1] * i % mod; }
}
int nCk(int x, int y) {
if (y > x) {
return 0;
}
if (x < 0) {
return 0;
}
return perm[x] * modpow(perm[x - y], mod - 2) % mod *
modpow(perm[y], mod - 2) % mod;
}
struct Dot {
double x;
double y;
Dot(double _x = 0.0, double _y = 0.0) {
x = _x;
y = _y;
}
};
struct Dot_i {
int x;
int y;
Dot_i(int _x = 0, int _y = 0) {
x = _x;
y = _y;
}
};
double kyori(pair<int, int> f, pair<int, int> s) {
double ans = 0;
double t = fabs(f.first - s.first);
double y = fabs(f.second - s.second);
ans = sqrt(t * t + y * y);
return ans;
}
double kyori(Dot f, Dot s) {
double ans = 0;
double t = fabs(f.x - s.x);
double y = fabs(f.y - s.y);
ans = sqrt(t * t + y * y);
return ans;
}
inline string stringmax(string &x, string &y) {
if (x.size() > y.size()) {
return x;
}
if (x.size() < y.size()) {
return y;
}
rep(i, x.size()) {
if (x[i] > y[i]) {
return x;
}
if (x[i] < y[i]) {
return y;
}
}
return x;
}
// vector<int> RollingHash(string &s, string& t){
// vector<int> ans;
// __int128 h=0,hamod=0,ki=0,kim=0,hikaku=0,one=0;
// one=1;
// ki=1000000007ll;
// hamod=(one<<61)-1;
// kim=1;
// rep(i,t.size()){
// hikaku*=ki;
// h*=ki;
// kim*=ki;
// hikaku+=t[i];
// h+=s[i];
// hikaku%=hamod;
// h%=hamod;
// kim%=hamod;
// }
// rep(i,(int)s.size()-(int)t.size()+1){
// if (h==hikaku) {
// ans.emplace_back(i);
// }
// h*=ki;
// h%=hamod;
// h+=s[i+(int)t.size()];
// h%=hamod;
// h+=hamod;
// h-=s[i]*kim%hamod;
// h%=hamod;
// }
// return ans;
// }
struct edge {
int to;
int length;
edge(int _to, int _length) {
to = _to;
length = _length;
}
};
vector<int> djkstra(vector<vector<edge>> &road, int start) {
vector<int> kyo(road.size(), inf);
smallpriority_queue(P) q;
q.push({0, start});
kyo[start] = 0;
while (q.size()) {
int x = q.top().second;
itn now = q.top().first;
q.pop();
if (kyo[x] < now) {
continue;
}
for (auto &i : road[x]) {
if (kyo[i.to] > now + i.length) {
kyo[i.to] = now + i.length;
q.push({kyo[i.to], i.to});
}
}
}
return kyo;
}
template <class T> void change_to_unique(vector<T> &v) {
std::sort(ALL(v));
auto k = unique(ALL(v));
if (k != v.end())
v.erase(k, v.end());
}
double kodo_dosuu(double r) { return 180.0 * r / (double)PI; }
double dosuu_kodo(double r) { return r * (double)PI / 180.0; }
double kakudo(Dot a, Dot b1, Dot b2) {
double size1 = kyori(a, b1), size2 = kyori(a, b2);
double nai = (b1.x - a.x) * (b2.x - a.x) + (b1.y - a.y) * (b2.y - a.y);
nai /= size1 * size2;
return kodo_dosuu(acos(nai));
}
struct fraction {
int shi;
int bo;
fraction(int bunshi, int bunbo) : bo(bunbo), shi(bunshi) {
if (bunbo && bunshi) {
int g = gcd(bo, shi);
bo /= g;
shi /= g;
}
};
explicit inline operator double() const { return (double)shi / (double)bo; }
explicit inline operator long double() const {
return (long double)shi / (long double)bo;
}
};
bool operator<(const fraction &b1, const fraction &b2) {
return b1.shi * b2.bo < b2.shi * b1.bo;
}
bool operator>(const fraction &b1, const fraction &b2) {
return b1.shi * b2.bo > b2.shi * b1.bo;
}
template <class T> void vecout(vector<T> &v) {
if (v.size()) {
cout << v[0];
}
REP(i, (int)v.size() - 1) { cout << ' ' << v[i]; }
cout << endl;
}
#define endl "\n" // interactive の時に注意!!!
#define Endl "\n" // interactive の時に注意!!!
#define cinn cin
#define printd cout << fixed << setprecision(10)
#define rrep(i, f, s) for (int i = f; i < s; i++)
#define RREP(i, f, s) for (int i = f; i <= s; i++)
#define REV_RREP(i, f, s) for (int i = s; i >= f; i--)
#define hen_rep(i, l, step) for (int i = 0; i < l; i += step)
#define HEN_REP(i, l, step) for (int i = 1; i <= l; i += step)
int n, ans;
itn s[100004];
vector<P> now[100004];
signed main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cin >> n;
rep(i, n) { cin >> s[i]; }
REP(i, n - 1) {
int cnt = 0;
for (int j = n - i - 1; j >= i + 1; j -= i) {
cnt += s[j];
now[j].emplace_back(i, cnt);
}
}
ans = 0;
REP(i, n - 2) {
for (auto &j : now[i]) {
int ka = j.second;
int k = j.first;
if (!((i - j.first) % j.first)) {
if (n - 1 > i + (i - j.first)) {
continue;
}
}
while (k + (i - j.first) < n - 1) {
ka += s[k];
k += j.first;
}
chmax(ans, ka);
}
}
cout << ans << endl;
}
| replace | 34 | 37 | 34 | 37 | TLE | |
p03034 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const long long NS = (long long)1e5 + 4;
long long N;
long long arr[NS];
vector<long long> sum1[NS], sum2[NS];
int main() {
scanf("%lld", &N);
for (long long i = 1; i <= N; ++i)
scanf("%lld", arr + i);
for (long long i = 1; i <= N; ++i) {
long long pos = N - N / i * i, sum = 0;
if (!pos)
pos += i;
while (pos <= N) {
sum += arr[pos];
sum1[i].push_back(sum);
pos += i;
}
pos = 1, sum = 0;
while (pos <= N) {
sum += arr[pos];
pos += i;
}
pos = 1;
while (pos <= N) {
sum2[i].push_back(sum), sum -= arr[pos], pos += i;
}
}
long long ans = -(long long)1e18;
for (long long i = 1; i <= N; ++i) {
for (long long j = 1; i - j > 0 && j * j <= N - i; ++j) {
if ((N - i - 1) % j == 0 &&
(i % j != 0 || i / j >= (N - i - 1) / j + 1)) {
long long A = i, B = i - j;
long long gap1 = sum1[j][(long long)sum1[j].size() - 1];
if ((long long)sum1[j].size() - (N - A - 1) / j - 1) {
gap1 -= sum1[j][(long long)sum1[j].size() - (N - A - 1) / j - 2];
}
long long gap2 = sum2[j][0];
if ((N - A - 1) / j + 1 < (long long)sum2[j].size()) {
gap2 -= sum2[j][(N - A - 1) / j + 1];
}
ans = max(ans, gap1 + gap2);
}
if ((N - i - 1) % j == 0) {
long long jj = j;
j = (N - i - 1) / j;
if ((N - i - 1) % j == 0 &&
(i % j != 0 || i / j >= (N - i - 1) / j + 1)) {
long long A = i, B = i - j;
long long gap1 = sum1[j][(long long)sum1[j].size() - 1];
if ((long long)sum1[j].size() - (N - A - 1) / j - 1) {
gap1 -= sum1[j][(long long)sum1[j].size() - (N - A - 1) / j - 2];
}
long long gap2 = sum2[j][0];
if ((N - A - 1) / j + 1 < (long long)sum2[j].size()) {
gap2 -= sum2[j][(N - A - 1) / j + 1];
}
ans = max(ans, gap1 + gap2);
}
j = jj;
}
}
}
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const long long NS = (long long)1e5 + 4;
long long N;
long long arr[NS];
vector<long long> sum1[NS], sum2[NS];
int main() {
scanf("%lld", &N);
for (long long i = 1; i <= N; ++i)
scanf("%lld", arr + i);
for (long long i = 1; i <= N; ++i) {
long long pos = N - N / i * i, sum = 0;
if (!pos)
pos += i;
while (pos <= N) {
sum += arr[pos];
sum1[i].push_back(sum);
pos += i;
}
pos = 1, sum = 0;
while (pos <= N) {
sum += arr[pos];
pos += i;
}
pos = 1;
while (pos <= N) {
sum2[i].push_back(sum), sum -= arr[pos], pos += i;
}
}
long long ans = -(long long)1e18;
for (long long i = 1; i <= N; ++i) {
for (long long j = 1; i - j > 0 && j * j <= N - i; ++j) {
if ((N - i - 1) % j == 0 &&
(i % j != 0 || i / j >= (N - i - 1) / j + 1)) {
long long A = i, B = i - j;
long long gap1 = sum1[j][(long long)sum1[j].size() - 1];
if ((long long)sum1[j].size() - (N - A - 1) / j - 1) {
gap1 -= sum1[j][(long long)sum1[j].size() - (N - A - 1) / j - 2];
}
long long gap2 = sum2[j][0];
if ((N - A - 1) / j + 1 < (long long)sum2[j].size()) {
gap2 -= sum2[j][(N - A - 1) / j + 1];
}
ans = max(ans, gap1 + gap2);
}
if ((N - i - 1) % j == 0 && (N - i - 1) / j != 0) {
long long jj = j;
j = (N - i - 1) / j;
if ((N - i - 1) % j == 0 &&
(i % j != 0 || i / j >= (N - i - 1) / j + 1)) {
long long A = i, B = i - j;
long long gap1 = sum1[j][(long long)sum1[j].size() - 1];
if ((long long)sum1[j].size() - (N - A - 1) / j - 1) {
gap1 -= sum1[j][(long long)sum1[j].size() - (N - A - 1) / j - 2];
}
long long gap2 = sum2[j][0];
if ((N - A - 1) / j + 1 < (long long)sum2[j].size()) {
gap2 -= sum2[j][(N - A - 1) / j + 1];
}
ans = max(ans, gap1 + gap2);
}
j = jj;
}
}
}
printf("%lld\n", ans);
return 0;
}
| replace | 48 | 49 | 48 | 49 | -8 | |
p03035 | C++ | Time Limit Exceeded | // written by NewbieChd
#include <cctype>
#include <cstdio>
using namespace std;
const int BUF = 1000000;
char buf[BUF], *p1, *p2;
inline char getChar() {
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2)
? EOF
: *p1++;
}
inline int read() {
register int f = 0;
char c;
while (!isdigit(c = getChar())) {
}
do
f = f * 10 + (c ^ 48);
while (isdigit(c = getChar()));
return f;
}
const int maxN = 100003;
int main() {
#ifndef ONLINE_JUDGE
freopen("a.in", "r", stdin);
// freopen("a.out", "w", stdout);
#endif
int a = read(), b = read();
if (a <= 5)
printf("0\n");
else {
if (a < 13)
b >>= 1;
printf("%d\n", b);
}
return 0;
}
| // written by NewbieChd
#include <cctype>
#include <cstdio>
using namespace std;
const int BUF = 1000000;
char buf[BUF], *p1, *p2;
inline char getChar() {
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2)
? EOF
: *p1++;
}
inline int read() {
register int f = 0;
char c;
while (!isdigit(c = getChar())) {
}
do
f = f * 10 + (c ^ 48);
while (isdigit(c = getChar()));
return f;
}
const int maxN = 100003;
int main() {
int a = read(), b = read();
if (a <= 5)
printf("0\n");
else {
if (a < 13)
b >>= 1;
printf("%d\n", b);
}
return 0;
}
| delete | 26 | 30 | 26 | 26 | TLE | |
p03035 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i, n) for (int i = 0; i < n; i++)
#define rev(i, n) for (int i = n; i >= 0; i--)
#define rep_a(i, a, n) for (int i = a; i < n; i++)
#define tr(ds, it) for (auto it = ds.begin(); it != ds.end(); it++)
#define rtr(ds, it) for (auto it = ds.rbegin(); it != ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue<int> pq;
typedef vector<long long> vi;
typedef pair<long long, long long> ii;
const ll mod = 1000000007;
ll po(ll x, ll n) {
ll ans = 1;
while (n > 0) {
if (n & 1)
ans = (ans * x) % mod;
x = (x * x) % mod;
n /= 2;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int T = 1;
// cin >> T;
while (T--) {
ll a, b;
cin >> a >> b;
if (a >= 13)
cout << b << el;
else if (a > 5)
cout << b / 2 << el;
else
cout << 0 << el;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i, n) for (int i = 0; i < n; i++)
#define rev(i, n) for (int i = n; i >= 0; i--)
#define rep_a(i, a, n) for (int i = a; i < n; i++)
#define tr(ds, it) for (auto it = ds.begin(); it != ds.end(); it++)
#define rtr(ds, it) for (auto it = ds.rbegin(); it != ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue<int> pq;
typedef vector<long long> vi;
typedef pair<long long, long long> ii;
const ll mod = 1000000007;
ll po(ll x, ll n) {
ll ans = 1;
while (n > 0) {
if (n & 1)
ans = (ans * x) % mod;
x = (x * x) % mod;
n /= 2;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T = 1;
// cin >> T;
while (T--) {
ll a, b;
cin >> a >> b;
if (a >= 13)
cout << b << el;
else if (a > 5)
cout << b / 2 << el;
else
cout << 0 << el;
}
return 0;
} | replace | 37 | 41 | 37 | 38 | 0 | |
p03035 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX = 100005;
const long long mod = 1.0e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ll a, b;
cin >> a >> b;
if (a >= 13)
cout << b << endl;
else if (a < 13 && a > 5)
cout << b / 2 << endl;
else
cout << "0" << endl;
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX = 100005;
const long long mod = 1.0e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll a, b;
cin >> a >> b;
if (a >= 13)
cout << b << endl;
else if (a < 13 && a > 5)
cout << b / 2 << endl;
else
cout << "0" << endl;
return 0;
} | delete | 14 | 18 | 14 | 14 | 0 | |
p03035 | Python | Runtime Error | def main():
a, b = map(int, input())
if a >= 13:
print(b)
elif 6 <= a <= 12:
print(b // 2)
else:
print(0)
if __name__ == "__main__":
main()
| def main():
a, b = map(int, input().split())
if a >= 13:
print(b)
elif 6 <= a <= 12:
print(b // 2)
else:
print(0)
if __name__ == "__main__":
main()
| replace | 1 | 2 | 1 | 2 | ValueError: invalid literal for int() with base 10: ' ' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03035/Python/s703074375.py", line 13, in <module>
main()
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03035/Python/s703074375.py", line 3, in main
a, b = map(int, input())
ValueError: invalid literal for int() with base 10: ' '
|
p03035 | Python | Runtime Error | A, B = map(int, input())
if A >= 13:
print(B)
elif A >= 6:
print(B // 2)
else:
print(0)
| A, B = map(int, input().split())
if A >= 13:
print(B)
elif A >= 6:
print(B // 2)
else:
print(0)
| 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/p03035/Python/s602871516.py", line 1, in <module>
A, B = map(int, input())
ValueError: invalid literal for int() with base 10: ' '
|
p03035 | 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 loop(i, a, b) for (ll i = a; i < b; i++)
#define loope(i, a, b) for (ll i = a; i <= b; i++)
#define test() \
ull t; \
cin >> t; \
while (t--)
#define puu pair<ull, ull>
#define f first
#define s second
#define pb push_back
#define mkp make_pair
#define ins insert
#define Vint vector<int>
#define Vull vector<ull>
#define nl cout << endl
#define sp cout << " "
#define MOD 1000000007
#define all(x) x.begin(), x.end()
vector<int> cache(100005);
int fact(int k) {
if (k < 2)
return 1;
if (cache[k] != 0)
return cache[k];
return cache[k] = k * fact(k - 1) % MOD;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fastio();
int a, b;
cin >> a >> b;
if (a >= 13)
cout << b;
else if (a < 13 && a >= 6)
cout << b / 2;
else
cout << 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 loop(i, a, b) for (ll i = a; i < b; i++)
#define loope(i, a, b) for (ll i = a; i <= b; i++)
#define test() \
ull t; \
cin >> t; \
while (t--)
#define puu pair<ull, ull>
#define f first
#define s second
#define pb push_back
#define mkp make_pair
#define ins insert
#define Vint vector<int>
#define Vull vector<ull>
#define nl cout << endl
#define sp cout << " "
#define MOD 1000000007
#define all(x) x.begin(), x.end()
vector<int> cache(100005);
int fact(int k) {
if (k < 2)
return 1;
if (cache[k] != 0)
return cache[k];
return cache[k] = k * fact(k - 1) % MOD;
}
int main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
// fastio();
int a, b;
cin >> a >> b;
if (a >= 13)
cout << b;
else if (a < 13 && a >= 6)
cout << b / 2;
else
cout << 0;
} | replace | 35 | 40 | 35 | 40 | 0 | |
p03035 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define test() \
int t; \
cin >> t; \
loop(test, 1, t + 1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout << "\n"
#define sp cout << " "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(), x.end()
template <class C> void min_self(C &a, C b) { a = min(a, b); }
template <class C> void max_self(C &a, C b) { a = max(a, b); }
void mod(ll &n, ll m = MOD) { n %= m, n += m, n %= m; }
const int MAXN = 1e5 + 5;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fastio();
int a, b, ans = 0;
cin >> a >> b;
if (a <= 5) {
ans = 0;
} else if (a <= 12) {
ans = b / 2;
} else
ans = b;
cout << ans, nl;
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define test() \
int t; \
cin >> t; \
loop(test, 1, t + 1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout << "\n"
#define sp cout << " "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(), x.end()
template <class C> void min_self(C &a, C b) { a = min(a, b); }
template <class C> void max_self(C &a, C b) { a = max(a, b); }
void mod(ll &n, ll m = MOD) { n %= m, n += m, n %= m; }
const int MAXN = 1e5 + 5;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
fastio();
int a, b, ans = 0;
cin >> a >> b;
if (a <= 5) {
ans = 0;
} else if (a <= 12) {
ans = b / 2;
} else
ans = b;
cout << ans, nl;
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
} | delete | 40 | 44 | 40 | 40 | 0 |
Time elapsed: 32ms
|
p03035 | C++ | Runtime Error | #include <cstdio>
#include <cstdlib>
int main(int argc, char **argv) {
int age = atoi(argv[1]);
int price = atoi(argv[2]);
if (age >= 13) {
printf("%d\n", price);
return 0;
}
if (age >= 6) {
printf("%d\n", price / 2);
return 0;
}
printf("%d\n", 0);
return 0;
}
| #include <cstdio>
#include <cstdlib>
int main() {
int age, price;
scanf("%d %d", &age, &price);
if (age >= 13) {
printf("%d\n", price);
return 0;
}
if (age >= 6) {
printf("%d\n", price / 2);
return 0;
}
printf("%d\n", 0);
return 0;
}
| replace | 3 | 6 | 3 | 6 | -11 | |
p03035 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B;
cin >> A;
cin >> B;
if (A >= 13) {
cout << B << endl;
;
} else if (A >= 6) {
cout << (int)(B / 2) << endl;
;
} else {
cout << 0 << endl;
;
}
return 1;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B;
cin >> A;
cin >> B;
if (A >= 13) {
cout << B << endl;
;
} else if (A >= 6) {
cout << (int)(B / 2) << endl;
;
} else {
cout << 0 << endl;
;
}
return 0;
} | replace | 17 | 18 | 17 | 18 | 1 | |
p03036 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int r, D, x;
cin >> r >> D >> x;
int i = 0; // カウンタ変数
while (i < 10) {
x = r * x - D;
cout << x << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int r, D, x;
cin >> r >> D >> x;
int i = 0; // カウンタ変数
while (i < 10) {
x = r * x - D;
cout << x << endl;
i++;
}
} | insert | 10 | 10 | 10 | 11 | TLE | |
p03036 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int r, D, x;
cin >> r >> D >> x;
vector<int> X(11);
X.at(0) = x;
for (int i = 0; i < 11; i++) {
X.at(i + 1) = r * X.at(i) - D;
}
for (int i = 1; i < 11; i++) {
cout << X.at(i) << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int r, D, x;
cin >> r >> D >> x;
vector<int> X(11);
X.at(0) = x;
for (int i = 0; i < 10; i++) {
X.at(i + 1) = r * X.at(i) - D;
}
for (int i = 1; i < 11; i++) {
cout << X.at(i) << endl;
}
} | replace | 7 | 8 | 7 | 8 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 11) >= this->size() (which is 11)
|
p03036 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int r, D, x[11];
cin >> r >> D >> x[0];
for (int i = 1; i < 11; i) {
x[i] = r * x[i - 1] - D;
cout << x[i] << endl;
}
return 0;
}
| #include <iostream>
using namespace std;
int main() {
int r, D, x[11];
cin >> r >> D >> x[0];
for (int i = 1; i < 11; i++) {
x[i] = r * x[i - 1] - D;
cout << x[i] << endl;
}
return 0;
}
| replace | 7 | 8 | 7 | 8 | TLE | |
p03036 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int r, d;
vector<int> x(10);
cin >> r >> d >> x[0];
for (int i; i < 10; i++) {
x[i + 1] = r * x[i] - d;
cout << x[i + 1] << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int r, d;
vector<int> x(11);
cin >> r >> d >> x[0];
for (int i; i < 10; i++) {
x[i + 1] = r * x[i] - d;
cout << x[i + 1] << endl;
}
} | replace | 5 | 6 | 5 | 6 | 0 | |
p03036 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int r;
int D;
int x;
int count = 0;
cin >> r >> D >> x;
while (count < 10) {
x = x * r - D;
cout << x << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int r;
int D;
int x;
int count = 0;
cin >> r >> D >> x;
while (count < 10) {
x = x * r - D;
cout << x << endl;
++count;
}
}
| insert | 15 | 15 | 15 | 16 | TLE | |
p03036 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> vec(11);
int r, D;
cin >> r >> D >> vec.at(0);
for (int i = 0; i < vec.size(); i++) {
vec.at(i + 1) = vec.at(i) * r - D;
cout << vec.at(i + 1) << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> vec(11);
int r, D;
cin >> r >> D >> vec.at(0);
for (int i = 0; i < vec.size() - 1; i++) {
vec.at(i + 1) = vec.at(i) * r - D;
cout << vec.at(i + 1) << endl;
}
}
| replace | 7 | 8 | 7 | 8 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 11) >= this->size() (which is 11)
|
p03036 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int r, D, x0;
cin >> r >> D >> x0;
vector<int> x(10, 0);
x[0] = x0;
for (int i = 0; i < 10 + 1; ++i) {
x[i + 1] = r * x[i] - D;
}
for (int i = 1; i < 10 + 1; ++i) {
cout << x[i] << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int r, D, x0;
cin >> r >> D >> x0;
vector<int> x(11, 0);
x[0] = x0;
for (int i = 0; i < 10 + 1; ++i) {
x[i + 1] = r * x[i] - D;
}
for (int i = 1; i < 10 + 1; ++i) {
cout << x[i] << endl;
}
}
| replace | 7 | 8 | 7 | 8 | -6 | malloc(): corrupted top size
|
p03036 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int r, d;
vector<int> x(10);
cin >> r >> d >> x[0];
for (int i = 1; i < 11; i++) {
x[i] = r * x[i - 1] - d;
cout << x[i] << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long r, d;
vector<long long> x(10);
cin >> r >> d >> x[0];
for (int i = 1; i < 11; i++) {
x[i] = r * x[i - 1] - d;
cout << x[i] << endl;
}
} | replace | 3 | 5 | 3 | 5 | 0 | |
p03036 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
int r, d;
vector<int> xi(10);
cin >> r >> d >> xi[0];
for (int i = 1; i < 11; i++) {
xi[i] = r * xi[i - 1] - d;
cout << xi[i] << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
int r, d;
vector<ll> xi(10);
cin >> r >> d >> xi[0];
for (int i = 1; i < 11; i++) {
xi[i] = r * xi[i - 1] - d;
cout << xi[i] << endl;
}
return 0;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p03036 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main(void) {
// Your code here!
int r, d, X;
int arr[10];
cin >> r >> d >> X;
arr[0] = X;
for (int i = 0; i < 10; i++) {
arr[i + 1] = (r * arr[i]) - d;
}
for (int i = 0; i < 10; i++) {
cout << arr[i + 1] << endl;
}
}
| #include <iostream>
using namespace std;
int main(void) {
// Your code here!
int r, d, X;
int arr[11];
cin >> r >> d >> X;
arr[0] = X;
for (int i = 0; i < 10; i++) {
arr[i + 1] = (r * arr[i]) - d;
}
for (int i = 0; i < 10; i++) {
cout << arr[i + 1] << endl;
}
}
| replace | 5 | 6 | 5 | 6 | -6 | *** stack smashing detected ***: terminated
|
p03036 | C++ | Runtime Error | #include "iostream"
using namespace std;
int main() {
int r, d, x;
cin >> r >> d >> x;
int xx[11] = {0};
xx[0] = x;
for (int i = 0; i < 11; i++) {
xx[i + 1] = r * xx[i] - d;
cout << xx[i] << endl;
}
} | #include "iostream"
using namespace std;
int main() {
int r, d, x;
cin >> r >> d >> x;
int xx[11] = {0};
xx[0] = x;
for (int i = 1; i < 11; i++) {
xx[i] = r * xx[i - 1] - d;
cout << xx[i] << endl;
}
} | replace | 9 | 11 | 9 | 11 | 0 | |
p03036 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int r, d, x[11];
cin >> r >> d >> x[0];
for (int i = 0; i < 11; i++) {
x[i + 1] = r * x[i] - d;
cout << x[i + 1] << endl;
}
return 0;
}
| #include <iostream>
using namespace std;
int main() {
int r, d, x[11];
cin >> r >> d >> x[0];
for (int i = 0; i < 10; i++) {
x[i + 1] = r * x[i] - d;
cout << x[i + 1] << endl;
}
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p03036 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long int
#define N 100010
using namespace std;
int main() {
int r, d, x;
cin >> r >> d >> x;
vector<int> n(10, 0);
n[0] = x;
for (int i = 1; i <= 10; i++) {
n[i] = r * n[i - 1] - d;
cout << n[i] << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define ll long long int
#define N 100010
using namespace std;
int main() {
int r, d, x;
cin >> r >> d >> x;
vector<ll> n(10);
n[0] = x;
for (int i = 1; i <= 10; i++) {
n[i] = r * n[i - 1] - d;
cout << n[i] << endl;
}
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p03036 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(ll r, ll D, ll x) {
vector<ll> X(11, 0);
X[0] = x;
for (int i = 0; i < X.size(); ++i) {
X[i + 1] = r * X[i] - D;
}
for (int i = 1; i < X.size(); ++i)
cout << X[i] << endl;
}
int main() {
ll r, D, x;
cin >> r >> D >> x;
solve(r, D, x);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(ll r, ll D, ll x) {
vector<ll> X(11, 0);
X[0] = x;
for (int i = 0; i < X.size() - 1; ++i) {
X[i + 1] = r * X[i] - D;
}
for (int i = 1; i < X.size(); ++i)
cout << X[i] << endl;
}
int main() {
ll r, D, x;
cin >> r >> D >> x;
solve(r, D, x);
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p03036 | C++ | Runtime Error | #include <algorithm>
#include <cctype>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
int a, b, c;
cin >> a >> b >> c;
int ans[b + 1];
ans[0] = c;
for (int i = 0; i < 10; i++) {
ans[i + 1] = a * ans[i] - b;
cout << ans[i + 1] << endl;
}
return 0;
} | #include <algorithm>
#include <cctype>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
int a, b, c;
cin >> a >> b >> c;
int ans[11];
ans[0] = c;
for (int i = 0; i < 10; i++) {
ans[i + 1] = a * ans[i] - b;
cout << ans[i + 1] << endl;
}
return 0;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p03036 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vc vector<char>
#define vt vector<string>
#define si set<int>
#define sc set<char>
#define st set<string>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
int main() {
int r, d, x;
cin >> r >> d >> x;
int a[10];
a[0] = x;
for (int i = 0; i < 10; i++)
a[i + 1] = a[i] * r - d;
for (int i = 1; i <= 10; i++)
cout << a[i] << endl;
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vc vector<char>
#define vt vector<string>
#define si set<int>
#define sc set<char>
#define st set<string>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
int main() {
int r, d, x;
cin >> r >> d >> x;
int a[11];
a[0] = x;
for (int i = 0; i < 10; i++)
a[i + 1] = a[i] * r - d;
for (int i = 1; i <= 10; i++)
cout << a[i] << endl;
return 0;
}
| replace | 17 | 18 | 17 | 18 | -6 | *** stack smashing detected ***: terminated
|
p03036 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
int main() {
long long int r, d, x[10];
std::cin >> r >> d >> x[0];
for (int i = 1; i <= 10; ++i) {
x[i] = x[i - 1] * r - d;
std::cout << x[i] << std::endl;
}
} | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
int main() {
long long r, d, x[11];
std::cin >> r >> d >> x[0];
for (int i = 1; i <= 10; ++i) {
x[i] = x[i - 1] * r - d;
std::cout << x[i] << std::endl;
}
} | replace | 8 | 9 | 8 | 9 | 0 | |
p03036 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int r, d, x;
cin >> r >> d >> x;
vector<int> xx(10, x);
for (int i = 0; i < 10; i++) {
xx[i + 1] = r * xx[i] - d;
cout << xx[i + 1] << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int r, d, x;
cin >> r >> d >> x;
vector<int> xx(11, x);
for (int i = 0; i < 10; i++) {
xx[i + 1] = r * xx[i] - d;
cout << xx[i + 1] << endl;
}
} | replace | 8 | 9 | 8 | 9 | 0 | |
p03036 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <set>
#include <sstream>
#include <vector>
using namespace std;
// ユーティリティ
#define INF 1e9
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
#define PI (acos(-1))
// maxを更新しつつ、変わったか返す
template <class T> bool chmax(T &former, const T &b) {
if (former < b) {
former = b;
return true;
}
return false;
}
template <class T> bool chmin(T &former, const T &b) {
if (former > b) {
former = b;
return true;
}
return false;
}
// データ読み込み
template <class TypeInt> TypeInt input_type_int2(TypeInt &a, TypeInt &b) {
cin >> a >> b;
cin.ignore();
}
void input_int2(int &a, int &b) {
cin >> a >> b;
cin.ignore();
}
void input_ll_int2(long long &a, long long &b) {
cin >> a >> b;
cin.ignore();
}
void input_int3(int &a, int &b, int &c) {
cin >> a >> b >> c;
cin.ignore();
}
void input_int_array(int n, vector<int> &vec) {
for (int i = 0, tmp = 0; i < n && cin >> tmp; i++)
vec[i] = tmp;
}
void input_int_matrix(int n, int m, vector<vector<int>> &matrix) {
int tmp;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> tmp;
matrix[i][j] = tmp;
}
}
}
void input_int_var_array(int n, vector<int> &vec) {
for (int tmp = 0; cin >> tmp;) {
vec.push_back(tmp);
}
}
void input_int_var_matrix(int n, int m, vector<vector<int>> &matrix) {
int tmp;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> tmp;
matrix[i][j] = tmp;
}
}
}
void input_var_str(vector<string> &array) {
string s;
getline(cin, s);
stringstream ss{s};
while (getline(ss, s, ' ')) {
array.push_back(s);
}
}
void input_var_int(vector<int> &array) {
string s;
getline(cin, s);
stringstream ss{s};
while (getline(ss, s, ' ')) {
array.push_back(stoi(s));
}
}
void input_var_int(set<int> &array) {
string s;
getline(cin, s);
stringstream ss{s};
while (getline(ss, s, ' ')) {
array.insert(stoi(s));
}
}
// テスト用出力
template <typename T> void print_var_vector(vector<T> vec) {
for (typename vector<T>::iterator i = begin(vec); i != end(vec); i++) {
cout << *i;
}
cout << endl;
}
void print_vector(int N, vector<int> vec) {
for (int i = 0; i < N; i++) {
cout << vec[i] << " ";
}
cout << endl;
}
// データ構造
template <typename Monoid> struct SegmentTree {
using F = function<Monoid(Monoid, Monoid)>;
int sz;
vector<Monoid> seg;
const F f;
const Monoid M1;
SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
sz = 1;
while (sz < n)
sz <<= 1;
seg.assign(2 * sz, M1);
}
void set(int k, const Monoid &x) { seg[k + sz] = x; }
void build() {
for (int k = sz - 1; k > 0; k--) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
void update(int k, const Monoid &x) {
k += sz;
seg[k] = x;
while (k >>= 1) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
Monoid query(int a, int b) {
Monoid L = M1, R = M1;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1)
L = f(L, seg[a++]);
if (b & 1)
R = f(seg[--b], R);
}
return f(L, R);
}
Monoid operator[](const int &k) const { return seg[k + sz]; }
};
int r, D, x;
void input() {
cin >> r >> D >> x;
cin.ignore();
}
// kから、10こ追加
int solve() {
for (int j = 0; j < 10; j++) {
x = r * x - D;
cout << x << endl;
}
}
int main() {
input();
solve();
// cout << solve() << endl;
}
| #include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <set>
#include <sstream>
#include <vector>
using namespace std;
// ユーティリティ
#define INF 1e9
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
#define PI (acos(-1))
// maxを更新しつつ、変わったか返す
template <class T> bool chmax(T &former, const T &b) {
if (former < b) {
former = b;
return true;
}
return false;
}
template <class T> bool chmin(T &former, const T &b) {
if (former > b) {
former = b;
return true;
}
return false;
}
// データ読み込み
template <class TypeInt> TypeInt input_type_int2(TypeInt &a, TypeInt &b) {
cin >> a >> b;
cin.ignore();
}
void input_int2(int &a, int &b) {
cin >> a >> b;
cin.ignore();
}
void input_ll_int2(long long &a, long long &b) {
cin >> a >> b;
cin.ignore();
}
void input_int3(int &a, int &b, int &c) {
cin >> a >> b >> c;
cin.ignore();
}
void input_int_array(int n, vector<int> &vec) {
for (int i = 0, tmp = 0; i < n && cin >> tmp; i++)
vec[i] = tmp;
}
void input_int_matrix(int n, int m, vector<vector<int>> &matrix) {
int tmp;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> tmp;
matrix[i][j] = tmp;
}
}
}
void input_int_var_array(int n, vector<int> &vec) {
for (int tmp = 0; cin >> tmp;) {
vec.push_back(tmp);
}
}
void input_int_var_matrix(int n, int m, vector<vector<int>> &matrix) {
int tmp;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> tmp;
matrix[i][j] = tmp;
}
}
}
void input_var_str(vector<string> &array) {
string s;
getline(cin, s);
stringstream ss{s};
while (getline(ss, s, ' ')) {
array.push_back(s);
}
}
void input_var_int(vector<int> &array) {
string s;
getline(cin, s);
stringstream ss{s};
while (getline(ss, s, ' ')) {
array.push_back(stoi(s));
}
}
void input_var_int(set<int> &array) {
string s;
getline(cin, s);
stringstream ss{s};
while (getline(ss, s, ' ')) {
array.insert(stoi(s));
}
}
// テスト用出力
template <typename T> void print_var_vector(vector<T> vec) {
for (typename vector<T>::iterator i = begin(vec); i != end(vec); i++) {
cout << *i;
}
cout << endl;
}
void print_vector(int N, vector<int> vec) {
for (int i = 0; i < N; i++) {
cout << vec[i] << " ";
}
cout << endl;
}
// データ構造
template <typename Monoid> struct SegmentTree {
using F = function<Monoid(Monoid, Monoid)>;
int sz;
vector<Monoid> seg;
const F f;
const Monoid M1;
SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
sz = 1;
while (sz < n)
sz <<= 1;
seg.assign(2 * sz, M1);
}
void set(int k, const Monoid &x) { seg[k + sz] = x; }
void build() {
for (int k = sz - 1; k > 0; k--) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
void update(int k, const Monoid &x) {
k += sz;
seg[k] = x;
while (k >>= 1) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
Monoid query(int a, int b) {
Monoid L = M1, R = M1;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1)
L = f(L, seg[a++]);
if (b & 1)
R = f(seg[--b], R);
}
return f(L, R);
}
Monoid operator[](const int &k) const { return seg[k + sz]; }
};
int r, D, x;
void input() {
cin >> r >> D >> x;
cin.ignore();
}
// kから、10こ追加
void solve() {
for (int j = 0; j < 10; j++) {
x = r * x - D;
cout << x << endl;
}
}
int main() {
input();
solve();
// cout << solve() << endl;
}
| replace | 191 | 192 | 191 | 192 | TLE | |
p03036 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int r, D, x2000;
cin >> r >> D >> x2000;
vector<int> vec(10);
vec[0] = x2000;
for (int i = 0; i < 10; i++) {
vec[i + 1] = vec[i] * r - D;
cout << vec[i + 1] << endl;
;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int r, D, x2000;
cin >> r >> D >> x2000;
vector<int> vec(12);
vec[0] = x2000;
for (int i = 0; i < 10; i++) {
vec[i + 1] = vec[i] * r - D;
cout << vec[i + 1] << endl;
;
}
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p03036 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30
int main() {
int r, d, x;
cin >> r >> d >> x;
V<ll> ans(11);
ans[0] = x;
for (int i = 0; i <= 10; i++) {
ans[i + 1] = ans[i] * r - d;
}
for (int i = 1; i <= 10; i++) {
cout << ans[i] << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30
int main() {
int r, d, x;
cin >> r >> d >> x;
V<ll> ans(11);
ans[0] = x;
for (int i = 0; i < 10; i++) {
ans[i + 1] = ans[i] * r - d;
}
for (int i = 1; i <= 10; i++) {
cout << ans[i] << endl;
}
return 0;
}
| replace | 18 | 19 | 18 | 19 | 0 | |
p03036 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int r, D;
cin >> r >> D;
vector<int> X;
cin >> X.at(0);
for (int i = 0; i < 10; i++) {
X.at(i + 1) = r * X.at(i) - D;
cout << X.at(i + 1) << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int r, D;
cin >> r >> D;
vector<int> X(11);
cin >> X.at(0);
for (int i = 0; i < 10; i++) {
X.at(i + 1) = r * X.at(i) - D;
cout << X.at(i + 1) << endl;
}
return 0;
}
| replace | 5 | 6 | 5 | 6 | -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)
|
p03036 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int r, D, x0;
cin >> r >> D >> x0;
vector<int> x(11);
x.at(0) = x0;
for (int i = 0; i <= 10; i++) {
x.at(i + 1) = r * x.at(i) - D;
cout << x.at(i + 1) << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int r, D, x0;
cin >> r >> D >> x0;
vector<int> x(11);
x.at(0) = x0;
for (int i = 0; i < 10; i++) {
x.at(i + 1) = r * x.at(i) - D;
cout << x.at(i + 1) << endl;
}
} | replace | 10 | 11 | 10 | 11 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 11) >= this->size() (which is 11)
|
p03036 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define Abs(x) ((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y)-1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y)-1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repiins(x, y, z, s) for ((x) = (z); (x) <= (y); (x) += (s))
#define repit(x) \
for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define repit2(x) \
for (__typeof((x).begin()) it2 = (x).begin(); it2 != (x).end(); it2++)
#define nepit(x) \
for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)
#define All(x) (x).begin(), (x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
// can be applied to string type
#define Unique(v) v.resize(unique(All(v)) - v.begin())
#define peq(p0, p1) (p0.first == p1.first && p0.second == p1.second)
#define End '\n'
#define Out(x) cout << (x) << End
template <typename T> void OutN(T x) {
size_t i, len = x.size() - 1;
for (i = 0; i < len; i++)
cout << x[i] << " ";
cout << x[len] << '\n';
}
#define OutaN(x) \
do { \
size_t i, len = sizeof(x) / sizeof(__typeof(x[0])) - 1; \
for (i = 0; i < len; i++) \
cout << x[i] << " "; \
cout << x[len] << '\n'; \
} while (0);
template <typename T> void Outit(T x) {
auto end = x.end();
end--;
for (auto it = x.begin(); it != end; it++)
cout << *it << " ";
cout << *end << '\n';
}
template <typename T> void Debug(const T &val) { cerr << val << End; }
template <typename T, typename... Args> void Debug(const T &val, Args... args) {
cerr << val << ' ';
Debug(std::forward<Args>(args)...);
}
template <typename T> inline bool Max(T &x, const T &y) {
return x < y ? x = y, 1 : 0;
}
template <typename T> inline bool Min(T &x, const T &y) {
return x > y ? x = y, 1 : 0;
}
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
// can be applied to string type
#define Sort(v) sort(All(v))
#define SortR(v) sort(All(v), std::greater<__typeof(v[0])>())
// array sorters
#define Sart(a) sort(a, a + sizeof(a) / sizeof(__typeof(a[0])));
#define SartR(a) \
sort(a, a + sizeof(a) / sizeof(__typeof(a[0])), \
std::greater<__typeof(a[0])>())
#define pb push_back
#define mp make_pair
#define a first
#define b second
#define lb std::lower_bound
#define ub std::upper_bound
#define lbi(v, x) lb(All(v), (x)) - v.begin()
#define ubi(v, x) ub(All(v), (x)) - v.begin()
static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;
#define LOCAL 1
int main() {
#if LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
freopen("debug.txt", "w", stderr);
#endif
cin.tie(0);
ios::sync_with_stdio(false);
// std::cout.precision(18);
ull r, d, x;
cin >> r >> d >> x;
int i;
rep(i, 10) {
x = r * x - d;
Out(x);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define Abs(x) ((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y)-1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y)-1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repiins(x, y, z, s) for ((x) = (z); (x) <= (y); (x) += (s))
#define repit(x) \
for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define repit2(x) \
for (__typeof((x).begin()) it2 = (x).begin(); it2 != (x).end(); it2++)
#define nepit(x) \
for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)
#define All(x) (x).begin(), (x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
// can be applied to string type
#define Unique(v) v.resize(unique(All(v)) - v.begin())
#define peq(p0, p1) (p0.first == p1.first && p0.second == p1.second)
#define End '\n'
#define Out(x) cout << (x) << End
template <typename T> void OutN(T x) {
size_t i, len = x.size() - 1;
for (i = 0; i < len; i++)
cout << x[i] << " ";
cout << x[len] << '\n';
}
#define OutaN(x) \
do { \
size_t i, len = sizeof(x) / sizeof(__typeof(x[0])) - 1; \
for (i = 0; i < len; i++) \
cout << x[i] << " "; \
cout << x[len] << '\n'; \
} while (0);
template <typename T> void Outit(T x) {
auto end = x.end();
end--;
for (auto it = x.begin(); it != end; it++)
cout << *it << " ";
cout << *end << '\n';
}
template <typename T> void Debug(const T &val) { cerr << val << End; }
template <typename T, typename... Args> void Debug(const T &val, Args... args) {
cerr << val << ' ';
Debug(std::forward<Args>(args)...);
}
template <typename T> inline bool Max(T &x, const T &y) {
return x < y ? x = y, 1 : 0;
}
template <typename T> inline bool Min(T &x, const T &y) {
return x > y ? x = y, 1 : 0;
}
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
// can be applied to string type
#define Sort(v) sort(All(v))
#define SortR(v) sort(All(v), std::greater<__typeof(v[0])>())
// array sorters
#define Sart(a) sort(a, a + sizeof(a) / sizeof(__typeof(a[0])));
#define SartR(a) \
sort(a, a + sizeof(a) / sizeof(__typeof(a[0])), \
std::greater<__typeof(a[0])>())
#define pb push_back
#define mp make_pair
#define a first
#define b second
#define lb std::lower_bound
#define ub std::upper_bound
#define lbi(v, x) lb(All(v), (x)) - v.begin()
#define ubi(v, x) ub(All(v), (x)) - v.begin()
static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;
#define LOCAL 0
int main() {
#if LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
freopen("debug.txt", "w", stderr);
#endif
cin.tie(0);
ios::sync_with_stdio(false);
// std::cout.precision(18);
ull r, d, x;
cin >> r >> d >> x;
int i;
rep(i, 10) {
x = r * x - d;
Out(x);
}
return 0;
}
| replace | 98 | 99 | 98 | 99 | 0 | |
p03036 | C++ | Runtime Error | #include <iostream>
using namespace std;
#define lli long long int
#include <algorithm>
#include <vector>
int main() {
lli r, d, x, i;
cin >> r >> d >> x;
vector<int> v(10);
v[0] = x;
// cout<<x<<"\n";
for (i = 1; i <= 10; i++) {
v[i] = (r * v[i - 1]) - d;
cout << v[i] << "\n";
}
return 0;
} | #include <iostream>
using namespace std;
#define lli long long int
#include <algorithm>
#include <vector>
int main() {
lli r, d, x, i;
cin >> r >> d >> x;
vector<int> v(11);
v[0] = x;
// cout<<x<<"\n";
for (i = 1; i <= 10; i++) {
v[i] = (r * v[i - 1]) - d;
cout << v[i] << "\n";
}
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p03036 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int r, d, x, arr[2010];
int main() {
cin >> r >> d >> x;
arr[2000] = x;
for (int i = 2001; i <= 2010; i++) {
arr[i] = r * arr[i - 1] - d;
cout << arr[i] << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int r, d, x, arr[2011];
int main() {
cin >> r >> d >> x;
arr[2000] = x;
for (int i = 2001; i <= 2010; i++) {
arr[i] = r * arr[i - 1] - d;
cout << arr[i] << endl;
}
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p03037 | C++ | Time Limit Exceeded | #pragma once
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end() // sortなどの引数を省略
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#ifdef _MSC_FULL_VER // デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
if (false) \
cout
#define debug() if (false)
#define check(x) \
if (false) \
cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
if (false) \
cout << "☆" << x << endl
#endif
using namespace std;
int main() {
int N, M;
int L, R;
int ans = 0;
cin >> N >> M;
vector<int> list(N);
rep(i, M) {
cin >> L >> R;
rep(i, L - 1) { list[i] = 1; }
for (int i = R; i < N; i++) {
list[i] = 1;
}
dout << "====listの内容====\n";
for (int i = 0; i < N; i++)
dout << list[i] << endl;
dout << "====ここまで====\n";
}
rep(i, N) {
if (list[i] == 0) {
ans++;
}
}
cout << ans;
return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> vec;
vec.at(i)
vector<vector<int>> vec(10, vector<int>(10));
sort(all(vec));
sort(all(vec), greater<int>());
//配列の内容表示
dout << "====vecの内容====\n";
for (int i = 0; i < N; i++) dout << vec[i] << endl;
dout << "====ここまで====\n";
*/ | #pragma once
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end() // sortなどの引数を省略
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#ifdef _MSC_FULL_VER // デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
if (false) \
cout
#define debug() if (false)
#define check(x) \
if (false) \
cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
if (false) \
cout << "☆" << x << endl
#endif
using namespace std;
int main() {
int N, M;
int L, R;
int ans = 0;
cin >> N >> M;
vector<int> list(N);
rep(i, M) {
cin >> L >> R;
if (list[L - 2] == 0) {
rep(i, L - 1) { list[i] = 1; }
}
if (list[R] == 0) {
for (int i = R; i < N; i++) {
list[i] = 1;
}
}
dout << "====listの内容====\n";
for (int i = 0; i < N; i++)
dout << list[i] << endl;
dout << "====ここまで====\n";
}
rep(i, N) {
if (list[i] == 0) {
ans++;
}
}
cout << ans;
return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> vec;
vec.at(i)
vector<vector<int>> vec(10, vector<int>(10));
sort(all(vec));
sort(all(vec), greater<int>());
//配列の内容表示
dout << "====vecの内容====\n";
for (int i = 0; i < N; i++) dout << vec[i] << endl;
dout << "====ここまで====\n";
*/ | replace | 36 | 39 | 36 | 43 | TLE | |
p03037 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a) (a).begin(), (a).end()
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); // 3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
int n, m;
cin >> n >> m;
vector<int> g(n + 1, 0);
rep(i, m) {
int l, r;
cin >> l >> r;
r++; // rを含みたいから開区間にするためのインクリメント
g[l]++;
g[r]--;
}
int CNT = 0;
rep(i, n) g[i + 1] += g[i];
// rep(i, g.size())
// {
// COUT(g[i]);
// }
int ans = 0;
rep(i, n + 1) if (g[i] == m) ans++;
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a) (a).begin(), (a).end()
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); // 3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
int n, m;
cin >> n >> m;
vector<int> g(n + 2, 0);
rep(i, m) {
int l, r;
cin >> l >> r;
r++; // rを含みたいから開区間にするためのインクリメント
g[l]++;
g[r]--;
}
int CNT = 0;
rep(i, n) g[i + 1] += g[i];
// rep(i, g.size())
// {
// COUT(g[i]);
// }
int ans = 0;
rep(i, n + 1) if (g[i] == m) ans++;
cout << ans << endl;
} | replace | 33 | 34 | 33 | 34 | 0 | |
p03037 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> l(m), r(m);
for (int i = 0; i < m; i++)
cin >> l.at(i) >> r.at(i);
sort(l.begin(), l.end());
sort(r.begin(), r.end());
int c;
c = l.at(m - 1) - r.at(1) + 1;
if (c < 0)
c = 0;
cout << c << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> l(m), r(m);
for (int i = 0; i < m; i++)
cin >> l.at(i) >> r.at(i);
sort(l.begin(), l.end());
sort(r.begin(), r.end());
int c;
c = r.at(0) - l.at(m - 1) + 1;
if (c < 0)
c = 0;
cout << c << endl;
return 0;
}
| replace | 14 | 15 | 14 | 15 | 0 | |
p03037 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
int L_max = 1, R_min = N;
int ANS;
vector<int> L;
vector<int> R;
for (int i = 0; i < M; i++) {
cin >> L.at(i) >> R.at(i);
if (L.at(i) > L_max) {
L_max = L.at(i);
}
if (R.at(i) < R_min) {
R_min = R.at(i);
}
}
ANS = R_min - L_max + 1;
if (ANS < 0) {
ANS = 0;
}
cout << ANS << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
int L_max = 1, R_min = N;
int ANS;
vector<int> L(M);
vector<int> R(M);
for (int i = 0; i < M; i++) {
cin >> L.at(i) >> R.at(i);
if (L.at(i) > L_max) {
L_max = L.at(i);
}
if (R.at(i) < R_min) {
R_min = R.at(i);
}
}
ANS = R_min - L_max + 1;
if (ANS < 0) {
ANS = 0;
}
cout << ANS << endl;
}
| replace | 8 | 10 | 8 | 10 | -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)
|
p03037 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> card(N + 1);
for (int i = 0; i < M; i++) {
int L, R;
cin >> L >> R;
card[L]++;
card[R + 1]--;
}
for (int i = 1; i <= N; i++) {
card[i] = card[i] + card[i - 1];
}
int answer = 0;
for (int i = 1; i <= N; i++) {
if (card[i] == M) {
answer++;
}
}
cout << answer << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> card(N + 1);
for (int i = 0; i < M; i++) {
int L, R;
cin >> L >> R;
card[L]++;
if (R != N) {
card[R + 1]--;
}
}
for (int i = 1; i <= N; i++) {
card[i] = card[i] + card[i - 1];
}
int answer = 0;
for (int i = 1; i <= N; i++) {
if (card[i] == M) {
answer++;
}
}
cout << answer << endl;
return 0;
} | replace | 13 | 14 | 13 | 16 | 0 | |
p03037 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <string.h>
#include <string>
using namespace std;
#define MAX_INT 10000
int array_max(int *arr, int M) {
int max = 0;
for (int i = 0; i < M; i++) {
// printf("%d ",arr[i]);
if (max < arr[i]) {
max = arr[i];
}
}
// printf("max: %d, \r\n", max);
return max;
}
int array_min(int *arr, int M) {
int min = MAX_INT;
for (int i = 0; i < M; i++) {
// printf("%d ",arr[i]);
if (min > arr[i]) {
min = arr[i];
}
}
// printf("min: %d \r\n", min);
return min;
}
int main() {
int N, M, L_e, R_e;
int L[MAX_INT], R[MAX_INT];
int ret;
scanf("%d %d", &N, &M);
for (int i = 0; i < M; i++) {
scanf("%d %d", &L_e, &R_e);
L[i] = L_e, R[i] = R_e;
}
ret = array_min(R, M) - array_max(L, M) + 1;
printf("%d\r\n", (ret > 0) ? ret : 0);
fflush(stdout);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <string.h>
#include <string>
using namespace std;
#define MAX_INT 100000
int array_max(int *arr, int M) {
int max = 0;
for (int i = 0; i < M; i++) {
// printf("%d ",arr[i]);
if (max < arr[i]) {
max = arr[i];
}
}
// printf("max: %d, \r\n", max);
return max;
}
int array_min(int *arr, int M) {
int min = MAX_INT;
for (int i = 0; i < M; i++) {
// printf("%d ",arr[i]);
if (min > arr[i]) {
min = arr[i];
}
}
// printf("min: %d \r\n", min);
return min;
}
int main() {
int N, M, L_e, R_e;
int L[MAX_INT], R[MAX_INT];
int ret;
scanf("%d %d", &N, &M);
for (int i = 0; i < M; i++) {
scanf("%d %d", &L_e, &R_e);
L[i] = L_e, R[i] = R_e;
}
ret = array_min(R, M) - array_max(L, M) + 1;
printf("%d\r\n", (ret > 0) ? ret : 0);
fflush(stdout);
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p03037 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int arr[100010];
int main() {
int N, M;
cin >> N >> M;
int l[M], r[M];
for (int i = 0; i < M; i++)
cin >> l[i] >> r[i];
for (int i = 0; i < M; i++) {
arr[l[i]]++;
arr[r[i] + 1]--;
}
for (int i = 1; i < 100010; i++)
arr[i] += arr[i - 1];
int ans = 0;
for (int i = 0; i < 1000010; i++)
if (arr[i] == M)
ans++;
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int arr[100010];
int main() {
int N, M;
cin >> N >> M;
int l[M], r[M];
for (int i = 0; i < M; i++)
cin >> l[i] >> r[i];
for (int i = 0; i < M; i++) {
arr[l[i]]++;
arr[r[i] + 1]--;
}
for (int i = 1; i < 100010; i++)
arr[i] += arr[i - 1];
int ans = 0;
for (int i = 0; i < 100010; i++)
if (arr[i] == M)
ans++;
cout << ans << endl;
return 0;
} | replace | 21 | 22 | 21 | 22 | -11 | |
p03037 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main() {
int n, m;
cin >> n >> m;
vector<int> ls, rs;
rep(i, m) cin >> ls[i] >> rs[i];
int l = *max_element(ls.begin(), ls.end());
int r = *min_element(rs.begin(), rs.end());
if (r < l) {
cout << 0 << endl;
} else {
cout << r - l + 1 << endl;
}
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main() {
int n, m;
cin >> n >> m;
vector<int> ls(m), rs(m);
rep(i, m) cin >> ls[i] >> rs[i];
int l = *max_element(ls.begin(), ls.end());
int r = *min_element(rs.begin(), rs.end());
if (r < l) {
cout << 0 << endl;
} else {
cout << r - l + 1 << endl;
}
}
| replace | 9 | 10 | 9 | 10 | -11 | |
p03037 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, l, r;
cin >> n >> m;
vector<int> imos(n + 1, 0);
for (int i = 0; i < m; ++i) {
cin >> l >> r;
imos[l]++;
imos[r + 1]--;
}
int ans = 0;
for (int i = 1; i < n + 1; ++i) {
imos[i] += imos[i - 1];
ans += (imos[i] == m);
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, l, r;
cin >> n >> m;
vector<int> imos(n + 2, 0);
for (int i = 0; i < m; ++i) {
cin >> l >> r;
imos[l]++;
imos[r + 1]--;
}
int ans = 0;
for (int i = 1; i < n + 1; ++i) {
imos[i] += imos[i - 1];
ans += (imos[i] == m);
}
cout << ans << endl;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p03037 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n, m;
cin >> n >> m;
vector<int> v(n + 1);
for (int i = 0; i < m; i++) {
int l, r;
cin >> l >> r;
v[l]++;
v[r + 1]--;
}
for (int i = 0; i < n; i++)
v[i + 1] += v[i];
int ans = 0;
for (int i = 0; i < v.size(); i++)
ans += (v[i] == m);
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n, m;
cin >> n >> m;
vector<int> v(n + 2);
for (int i = 0; i < m; i++) {
int l, r;
cin >> l >> r;
v[l]++;
v[r + 1]--;
}
for (int i = 0; i < n; i++)
v[i + 1] += v[i];
int ans = 0;
for (int i = 0; i < v.size(); i++)
ans += (v[i] == m);
cout << ans << endl;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p03037 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
// 上記が使用不可な環境において
/*
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath> //sin, cos, tan
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <iomanip> //setprecsion
#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;
typedef long long int ll;
typedef long long int lli;
typedef unsigned long long int ull;
typedef long double ld;
typedef string str;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
// define減らす!
// 0~nの範囲操作
#define rep(i, n) for (ll i = 0; i < (n); ++i)
// 1~nの範囲操作
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl;
#define mp(p, q) make_pair(p, q);
#define pb(n) push_back(n);
#define all(a) a.begin(), a.end();
#define rall(a) a.rbegin(), a.rend();
#define Sort(a) sort(a.begin(), a.end());
#define Rort(a) sort(a.rbegin(), a.rend());
// 配列の合計
#define SUM(n) accumulate(n.begin(), n.end(), 0);
// 配列を昇順
#define SORT(n) sort(n.begin(), n.end());
// 配列を降順
#define REVE(n) reverse(n.begin(), n.end());
// 配列nをmにコピー
#define COPY(n, m) copy(n.begin(), n.end(), back_inserter(m));
// 小数点型に
#define CAST(n) static_cast<ld>(n)
// 整数入力
#define LL(n) \
ll n; \
cin >> n;
// 少数入力
#define LD(n) \
ld n; \
cin >> n;
// 整数配列入力
#define LLV(a, n) \
vector<ll> a(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i); \
};
// 2列整数配列入力
#define LLV2(a, b, n) \
vector<ll> a(n), b(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i) >> b.at(i); \
};
// 3列整数配列入力
#define LLV3(a, b, c, n) \
vector<ll> a(n), b(n), c(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i) >> b.at(i) >> c.at(i); \
};
// 少数配列入力
#define LDV(a, n) \
vector<ld> a(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i); \
};
// 2列少数配列入力
#define LDV2(a, b, n) \
vector<ld> a(n), b(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i) >> b.at(i); \
};
// 3列少数配列入力
#define LD3(a, b, c, n) \
vector<ld> a(n), b(n), c(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i) >> b.at(i) >> c.at(i); \
};
// 文字列入力
#define STR(n) \
str n; \
cin >> n;
// 文字列配列入力
#define STRV(a, n) \
vector<str> a(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i); \
};
// yes, noと表示
void yn(bool a) {
if (a)
cout << "yes" << endl;
else
cout << "no" << endl;
}
// Yes, Noと表示
void Yn(bool a) {
if (a)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
// YES, NOと表示
void YN(bool a) {
if (a)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
// yes, noと表示後終了
void fyn(bool a) {
if (a)
cout << "yes" << endl;
else
cout << "no" << endl;
exit(0);
}
// Yes, Noと表示後終了
void fYn(bool a) {
if (a)
cout << "Yes" << endl;
else
cout << "No" << endl;
exit(0);
}
// YES, NOと表示後終了
void fYN(bool a) {
if (a)
cout << "YES" << endl;
else
cout << "NO" << endl;
exit(0);
}
// AC, WAと表示
void AC(bool a) {
if (a)
cout << "AC" << endl;
else
cout << "WA" << endl;
}
// AC, WAと表示後終了
void fAC(bool a) {
if (a)
cout << "AC" << endl;
else
cout << "WA" << endl;
exit(0);
}
// noneと表示後終了
void fnone(void) {
cout << "None" << endl;
exit(0);
}
// Odd(奇数), Even(偶数)と表示後終了
void fOdd(bool a) {
if (a)
cout << "Odd" << endl;
else
cout << "Even" << endl;
exit(0);
}
// Possible, Impossibleと表示後終了
void Possible(bool a) {
if (a)
cout << "Possible" << endl;
else
cout << "Impossible" << endl;
exit(0);
}
// POSSIBLE, IMPOSSIBLEと表示後終了
void POSSIBLE(bool a) {
if (a)
cout << "POSSIBLE" << endl;
else
cout << "IMPOSSIBLE" << endl;
exit(0);
}
// 四捨五入
ll C45(ll n) { return (n + 1) / 2; }
// nを出力(少数のみ)
#define OUT(n) cout << n << endl;
// nを出力(少数のみ)
void DOUT(ld n) { cout << fixed << setprecision(20) << n << endl; }
// 文字列からcを探す
ll stcount(str s, char c) { return count(s.cbegin(), s.cend(), c); }
// 素数
bool IsPrime(ll num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
long double sqrtNum = sqrt(num);
for (ll i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0)
return false;
}
return true;
}
// 桁数
ll GetDigit(ll num) { return log10(num) + 1; }
// 各桁の和
ll KSum(ll n) {
ll sum = 0;
if (n < 0)
return 0;
while (n > 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
// 数値反転
bool KReve(ll n) {
int reverse = 0;
int remaind;
int tmp = n;
while (tmp != 0) {
remaind = tmp % 10;
reverse = reverse * 10 + remaind;
tmp /= 10;
}
if (reverse == n)
return true;
else
return false;
}
// 約数全列挙
vector<ll> enum_div(ll n) {
vector<ll> ret;
for (ll i = 1; i * i <= n; ++i) {
if (n % i == 0) {
ret.push_back(i);
if (i != 1 && i * i != n) {
ret.push_back(n / i);
}
}
}
return ret;
}
// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// 複数個の最大公約数
ll ngcd(vector<ll> a) {
ll res;
res = a[0];
for (ll i = 1; i < a.size() && res != 1; i++) {
res = gcd(a[i], res);
}
return res;
}
// 最小公倍数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
// 複数個の最小公倍数
ll nlcm(vector<ll> numbers) {
ll res;
res = numbers[0];
for (ll i = 1; i < numbers.size(); i++) {
res = lcm(res, numbers[i]);
}
return res;
}
// 累乗
ll Pow(ll x, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * x;
x = x * x;
n >>= 1;
}
return res;
}
// 累乗(xのn乗%mod)
ll mod_pow(ll x, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
// 階乗
ll factorial(ll n) {
ll a = 1;
ll b = n;
for (int i = 0; i < n; i++) {
a *= b;
b--;
}
return a;
}
// 組み合わせ nCr
ll comb(ll a, ll b) {
ll c;
c = factorial(a) / (factorial(a - b) * factorial(b));
return c;
}
// n ~ mの和
ll sigma(ll n, ll m) { return ((n + m) * (m - n + 1) * 0.5); }
// 期待値
ld hope(ld a) { return (sigma(1, a) / a); }
/*理解してない
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
if (a < b)
{
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
if (a > b)
{
a = b;
return 1;
}
return 0;
}
struct io
{
io()
{
ios::sync_with_stdio(false);
cin.tie(0);
}
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
//幅優先探索
// 各座標に格納したい情報を構造体にする
// 今回はX座標,Y座標,深さ(距離)を記述している
struct Corr
{
int x;
int y;
int depth;
};
queue<Corr> q;
int bfs(vector<vector<int>> grid)
{
// 既に探索の場所を1,探索していなかったら0を格納する配列
vector<vector<int>> ispassed(grid.size(), vector<int>(grid[0].size(), false));
// このような記述をしておくと,この後のfor文が綺麗にかける
int dx[8] = {1, 0, -1, 0};
int dy[8] = {0, 1, 0, -1};
while (!q.empty())
{
Corr now = q.front();
q.pop();
//今いる座標は(x,y)=(now.x, now.y)で,深さ(距離)はnow.depthである
ここで,今いる座標がゴール(探索対象)なのか判定する for (int i = 0; i < 4; i++)
{
int nextx = now.x + dx[i];
int nexty = now.y + dy[i];
// 次に探索する場所のX座標がはみ出した時
if (nextx >= grid[0].size())
continue;
if (nextx < 0)
continue;
// 次に探索する場所のY座標がはみ出した時
if (nexty >= grid.size())
continue;
if (nexty < 0)
continue;
// 次に探索する場所が既に探索済みの場合
if (ispassed[nexty][nextx])
continue;
ispassed[nexty][nextx] = true;
Corr next = {nextx, nexty, now.depth + 1};
q.push(next);
}
}
}
//セグメント木
class Monoid
{
public:
// 単位元
ll unit;
Monoid()
{
// 単位元
unit = 0;
}
// 演算関数
ll calc(ll a, ll b)
{
return a + b;
}
};
class SegmentTree
{
public:
// セグメント木の葉の要素数
ll n;
// セグメント木
vector<ll> tree;
// モノイド
Monoid mono;
SegmentTree(vector<ll> &v)
{
n = 1 << (ll)ceil(log2(v.size()));
tree = vector<ll>(n << 1);
for (ll i = 0; i < v.size(); i++)
{
update(i, v[i]);
}
for (ll i = v.size(); i < n; i++)
{
update(i, mono.unit);
}
}
// k番目の値(0-indexed)をxに変更
void update(ll k, ll x)
{
k += n;
tree[k] = x;
for (k = k >> 1; k > 0; k >>= 1)
{
tree[k] = mono.calc(tree[k << 1 | 0], tree[k << 1 | 1]);
}
}
// [l, r)の最小値(0-indexed)を求める.
ll query(ll l, ll r)
{
ll res = mono.unit;
l += n;
r += n;
while (l < r)
{
if (l & 1)
{
res = mono.calc(res, tree[l++]);
}
if (r & 1)
{
res = mono.calc(res, tree[--r]);
}
l >>= 1;
r >>= 1;
}
return res;
}
ll operator[](ll k)
{
// st[i]で添字iの要素の値を返す
if (k - n >= 0 || k < 0)
{
return -INF;
}
return tree[tree.size() - n + k];
}
void show()
{
int ret = 2;
for (ll i = 1; i < 2 * n; i++)
{
cout << tree[i] << " ";
if (i == ret - 1)
{
cout << endl;
ret <<= 1;
}
}
cout << endl;
}
};
*/
// 四角
void square(ll h, ll w) {
for (ll i = 0; i < h; i++) {
for (ll j = 0; j < w; j++) {
cout << "#";
}
cout << endl;
}
}
// 四角枠
void yoke(ll h, ll w) {
for (ll i = 0; i < h; i++) {
for (ll j = 0; j < w; j++) {
if (i == 0 || i == h - 1)
cout << "#";
else if (j == 0 || j == w - 1)
cout << "#";
else
cout << ".";
}
cout << endl;
}
}
// 大文字->小文字(+32)
void Main() {
LL(N) LL(M) vll R(M), L(M);
ll RM = MAX, LM = MAX;
for (lli i = 0; i < M; i++) {
cin >> L[i] >> R[i];
RM = min(RM, R[i]);
LM = min(LM, L[i]);
}
map<lli, lli> k;
ll a = 0;
for (lli i = 0; i < M; i++) {
for (lli u = max(L[i], LM); u <= min(R[i], RM); u++) {
if (i == 0) {
if (k.count(u)) {
} else {
k[u] = 0;
}
}
if (k.count(u)) {
k[u]++;
if (k[u] == M) {
a++;
}
}
}
}
OUT(a)
return;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << std::fixed << std::setprecision(15);
Main();
return 0;
} | #include <bits/stdc++.h>
// 上記が使用不可な環境において
/*
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath> //sin, cos, tan
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <iomanip> //setprecsion
#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;
typedef long long int ll;
typedef long long int lli;
typedef unsigned long long int ull;
typedef long double ld;
typedef string str;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
// define減らす!
// 0~nの範囲操作
#define rep(i, n) for (ll i = 0; i < (n); ++i)
// 1~nの範囲操作
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl;
#define mp(p, q) make_pair(p, q);
#define pb(n) push_back(n);
#define all(a) a.begin(), a.end();
#define rall(a) a.rbegin(), a.rend();
#define Sort(a) sort(a.begin(), a.end());
#define Rort(a) sort(a.rbegin(), a.rend());
// 配列の合計
#define SUM(n) accumulate(n.begin(), n.end(), 0);
// 配列を昇順
#define SORT(n) sort(n.begin(), n.end());
// 配列を降順
#define REVE(n) reverse(n.begin(), n.end());
// 配列nをmにコピー
#define COPY(n, m) copy(n.begin(), n.end(), back_inserter(m));
// 小数点型に
#define CAST(n) static_cast<ld>(n)
// 整数入力
#define LL(n) \
ll n; \
cin >> n;
// 少数入力
#define LD(n) \
ld n; \
cin >> n;
// 整数配列入力
#define LLV(a, n) \
vector<ll> a(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i); \
};
// 2列整数配列入力
#define LLV2(a, b, n) \
vector<ll> a(n), b(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i) >> b.at(i); \
};
// 3列整数配列入力
#define LLV3(a, b, c, n) \
vector<ll> a(n), b(n), c(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i) >> b.at(i) >> c.at(i); \
};
// 少数配列入力
#define LDV(a, n) \
vector<ld> a(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i); \
};
// 2列少数配列入力
#define LDV2(a, b, n) \
vector<ld> a(n), b(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i) >> b.at(i); \
};
// 3列少数配列入力
#define LD3(a, b, c, n) \
vector<ld> a(n), b(n), c(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i) >> b.at(i) >> c.at(i); \
};
// 文字列入力
#define STR(n) \
str n; \
cin >> n;
// 文字列配列入力
#define STRV(a, n) \
vector<str> a(n); \
for (ll i = 0; i < n; i++) { \
cin >> a.at(i); \
};
// yes, noと表示
void yn(bool a) {
if (a)
cout << "yes" << endl;
else
cout << "no" << endl;
}
// Yes, Noと表示
void Yn(bool a) {
if (a)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
// YES, NOと表示
void YN(bool a) {
if (a)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
// yes, noと表示後終了
void fyn(bool a) {
if (a)
cout << "yes" << endl;
else
cout << "no" << endl;
exit(0);
}
// Yes, Noと表示後終了
void fYn(bool a) {
if (a)
cout << "Yes" << endl;
else
cout << "No" << endl;
exit(0);
}
// YES, NOと表示後終了
void fYN(bool a) {
if (a)
cout << "YES" << endl;
else
cout << "NO" << endl;
exit(0);
}
// AC, WAと表示
void AC(bool a) {
if (a)
cout << "AC" << endl;
else
cout << "WA" << endl;
}
// AC, WAと表示後終了
void fAC(bool a) {
if (a)
cout << "AC" << endl;
else
cout << "WA" << endl;
exit(0);
}
// noneと表示後終了
void fnone(void) {
cout << "None" << endl;
exit(0);
}
// Odd(奇数), Even(偶数)と表示後終了
void fOdd(bool a) {
if (a)
cout << "Odd" << endl;
else
cout << "Even" << endl;
exit(0);
}
// Possible, Impossibleと表示後終了
void Possible(bool a) {
if (a)
cout << "Possible" << endl;
else
cout << "Impossible" << endl;
exit(0);
}
// POSSIBLE, IMPOSSIBLEと表示後終了
void POSSIBLE(bool a) {
if (a)
cout << "POSSIBLE" << endl;
else
cout << "IMPOSSIBLE" << endl;
exit(0);
}
// 四捨五入
ll C45(ll n) { return (n + 1) / 2; }
// nを出力(少数のみ)
#define OUT(n) cout << n << endl;
// nを出力(少数のみ)
void DOUT(ld n) { cout << fixed << setprecision(20) << n << endl; }
// 文字列からcを探す
ll stcount(str s, char c) { return count(s.cbegin(), s.cend(), c); }
// 素数
bool IsPrime(ll num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
long double sqrtNum = sqrt(num);
for (ll i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0)
return false;
}
return true;
}
// 桁数
ll GetDigit(ll num) { return log10(num) + 1; }
// 各桁の和
ll KSum(ll n) {
ll sum = 0;
if (n < 0)
return 0;
while (n > 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
// 数値反転
bool KReve(ll n) {
int reverse = 0;
int remaind;
int tmp = n;
while (tmp != 0) {
remaind = tmp % 10;
reverse = reverse * 10 + remaind;
tmp /= 10;
}
if (reverse == n)
return true;
else
return false;
}
// 約数全列挙
vector<ll> enum_div(ll n) {
vector<ll> ret;
for (ll i = 1; i * i <= n; ++i) {
if (n % i == 0) {
ret.push_back(i);
if (i != 1 && i * i != n) {
ret.push_back(n / i);
}
}
}
return ret;
}
// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// 複数個の最大公約数
ll ngcd(vector<ll> a) {
ll res;
res = a[0];
for (ll i = 1; i < a.size() && res != 1; i++) {
res = gcd(a[i], res);
}
return res;
}
// 最小公倍数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
// 複数個の最小公倍数
ll nlcm(vector<ll> numbers) {
ll res;
res = numbers[0];
for (ll i = 1; i < numbers.size(); i++) {
res = lcm(res, numbers[i]);
}
return res;
}
// 累乗
ll Pow(ll x, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * x;
x = x * x;
n >>= 1;
}
return res;
}
// 累乗(xのn乗%mod)
ll mod_pow(ll x, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
// 階乗
ll factorial(ll n) {
ll a = 1;
ll b = n;
for (int i = 0; i < n; i++) {
a *= b;
b--;
}
return a;
}
// 組み合わせ nCr
ll comb(ll a, ll b) {
ll c;
c = factorial(a) / (factorial(a - b) * factorial(b));
return c;
}
// n ~ mの和
ll sigma(ll n, ll m) { return ((n + m) * (m - n + 1) * 0.5); }
// 期待値
ld hope(ld a) { return (sigma(1, a) / a); }
/*理解してない
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
if (a < b)
{
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
if (a > b)
{
a = b;
return 1;
}
return 0;
}
struct io
{
io()
{
ios::sync_with_stdio(false);
cin.tie(0);
}
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
//幅優先探索
// 各座標に格納したい情報を構造体にする
// 今回はX座標,Y座標,深さ(距離)を記述している
struct Corr
{
int x;
int y;
int depth;
};
queue<Corr> q;
int bfs(vector<vector<int>> grid)
{
// 既に探索の場所を1,探索していなかったら0を格納する配列
vector<vector<int>> ispassed(grid.size(), vector<int>(grid[0].size(), false));
// このような記述をしておくと,この後のfor文が綺麗にかける
int dx[8] = {1, 0, -1, 0};
int dy[8] = {0, 1, 0, -1};
while (!q.empty())
{
Corr now = q.front();
q.pop();
//今いる座標は(x,y)=(now.x, now.y)で,深さ(距離)はnow.depthである
ここで,今いる座標がゴール(探索対象)なのか判定する for (int i = 0; i < 4; i++)
{
int nextx = now.x + dx[i];
int nexty = now.y + dy[i];
// 次に探索する場所のX座標がはみ出した時
if (nextx >= grid[0].size())
continue;
if (nextx < 0)
continue;
// 次に探索する場所のY座標がはみ出した時
if (nexty >= grid.size())
continue;
if (nexty < 0)
continue;
// 次に探索する場所が既に探索済みの場合
if (ispassed[nexty][nextx])
continue;
ispassed[nexty][nextx] = true;
Corr next = {nextx, nexty, now.depth + 1};
q.push(next);
}
}
}
//セグメント木
class Monoid
{
public:
// 単位元
ll unit;
Monoid()
{
// 単位元
unit = 0;
}
// 演算関数
ll calc(ll a, ll b)
{
return a + b;
}
};
class SegmentTree
{
public:
// セグメント木の葉の要素数
ll n;
// セグメント木
vector<ll> tree;
// モノイド
Monoid mono;
SegmentTree(vector<ll> &v)
{
n = 1 << (ll)ceil(log2(v.size()));
tree = vector<ll>(n << 1);
for (ll i = 0; i < v.size(); i++)
{
update(i, v[i]);
}
for (ll i = v.size(); i < n; i++)
{
update(i, mono.unit);
}
}
// k番目の値(0-indexed)をxに変更
void update(ll k, ll x)
{
k += n;
tree[k] = x;
for (k = k >> 1; k > 0; k >>= 1)
{
tree[k] = mono.calc(tree[k << 1 | 0], tree[k << 1 | 1]);
}
}
// [l, r)の最小値(0-indexed)を求める.
ll query(ll l, ll r)
{
ll res = mono.unit;
l += n;
r += n;
while (l < r)
{
if (l & 1)
{
res = mono.calc(res, tree[l++]);
}
if (r & 1)
{
res = mono.calc(res, tree[--r]);
}
l >>= 1;
r >>= 1;
}
return res;
}
ll operator[](ll k)
{
// st[i]で添字iの要素の値を返す
if (k - n >= 0 || k < 0)
{
return -INF;
}
return tree[tree.size() - n + k];
}
void show()
{
int ret = 2;
for (ll i = 1; i < 2 * n; i++)
{
cout << tree[i] << " ";
if (i == ret - 1)
{
cout << endl;
ret <<= 1;
}
}
cout << endl;
}
};
*/
// 四角
void square(ll h, ll w) {
for (ll i = 0; i < h; i++) {
for (ll j = 0; j < w; j++) {
cout << "#";
}
cout << endl;
}
}
// 四角枠
void yoke(ll h, ll w) {
for (ll i = 0; i < h; i++) {
for (ll j = 0; j < w; j++) {
if (i == 0 || i == h - 1)
cout << "#";
else if (j == 0 || j == w - 1)
cout << "#";
else
cout << ".";
}
cout << endl;
}
}
// 大文字->小文字(+32)
void Main() {
LL(n) LL(m) LLV2(l, r, m) Sort(l) REVE(l) Sort(r) ll ans = r[0] - l[0];
ans = ans >= 0 ? ans + 1 : 0;
OUT(ans)
return;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << std::fixed << std::setprecision(15);
Main();
return 0;
} | replace | 556 | 582 | 556 | 559 | TLE | |
p03037 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
ll n, m;
cin >> n >> m;
vector<ll> l(m);
vector<ll> r(m);
vector<ll> a(n + 1);
rep(i, m) cin >> l[i] >> r[i];
rep(i, n) a[i] = 0;
rep(i, m) {
for (int j = l[i]; j <= r[i]; j++) {
a[j]++;
}
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
if (a[i] == m)
ans++;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
ll n, m;
cin >> n >> m;
vector<ll> l(m);
vector<ll> r(m);
vector<ll> a(n + 1);
rep(i, m) cin >> l[i] >> r[i];
sort(l.begin(), l.end());
sort(r.begin(), r.end());
if (r[0] < l[m - 1])
cout << "0" << endl;
else
cout << r[0] - l[m - 1] + 1 << endl;
return 0;
} | replace | 12 | 24 | 12 | 18 | TLE | |
p03037 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
using P = pair<int, int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int main() {
int n, m;
cin >> n >> m;
int maxL = 1;
int minR = n;
vector<int> R, L;
rep(i, n) cin >> L[i] >> R[i];
rep(i, n) {
maxL = max(maxL, L[i]);
minR = min(minR, R[i]);
}
int ans = minR - maxL + 1;
ans = max(ans, 0);
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
using P = pair<int, int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int main() {
int n, m;
cin >> n >> m;
int maxL = 1;
int minR = n;
vector<int> R(m), L(m);
rep(i, m) cin >> L[i] >> R[i];
rep(i, m) {
maxL = max(maxL, L[i]);
minR = min(minR, R[i]);
}
int ans = minR - maxL + 1;
ans = max(ans, 0);
cout << ans << endl;
return 0;
}
| replace | 20 | 23 | 20 | 23 | -11 | |
p03037 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <iomanip>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> L(M, 0), R(M, 0);
int maxL = 0, minR = 10000001;
for (int i = 0; i < M; i++) {
cin >> L.at(i);
cin >> R.at(i);
maxL = max(maxL, L.at(i));
minR = min(minR, R.at(i));
}
int ans = 0;
for (int i = maxL; i <= minR; i++) {
bool path = true;
for (int j = 0; j < M; j++) {
if (!(L.at(j) <= i && i <= R.at(j)))
path = false;
}
if (path)
ans++;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#include <iomanip>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> L(M, 0), R(M, 0);
int maxL = 0, minR = 10000001;
for (int i = 0; i < M; i++) {
cin >> L.at(i);
cin >> R.at(i);
maxL = max(maxL, L.at(i));
minR = min(minR, R.at(i));
}
int ans = minR - maxL + 1;
if (ans < 0)
ans = 0;
cout << ans << endl;
}
| replace | 16 | 26 | 16 | 19 | TLE | |
p03037 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
int N, M;
void dump(int max_, int min_) {
cout << "max:" << max_ << " min:" << min_ << endl;
}
int main(int argc, char **argv) {
int i;
cin >> N >> M;
int L[N], R[N];
int min_ = 0, max_ = N;
for (int i = 0; i < M; i++) {
cin >> L[i] >> R[i];
if (min_ < L[i])
min_ = L[i];
if (max_ > R[i])
max_ = R[i];
}
int ans;
if (max_ - min_ < 0)
ans = 0;
else
ans = max_ - min_ + 1;
// dump(max_, min_);
cout << ans << endl;
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
int N, M;
void dump(int max_, int min_) {
cout << "max:" << max_ << " min:" << min_ << endl;
}
int main(int argc, char **argv) {
int i;
cin >> N >> M;
int L[M], R[M];
int min_ = 0, max_ = N;
for (int i = 0; i < M; i++) {
cin >> L[i] >> R[i];
if (min_ < L[i])
min_ = L[i];
if (max_ > R[i])
max_ = R[i];
}
int ans;
if (max_ - min_ < 0)
ans = 0;
else
ans = max_ - min_ + 1;
// dump(max_, min_);
cout << ans << endl;
return 0;
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p03037 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for (lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for (lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for (lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for (lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for (lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) \
for (lint i = (m); (i) >= (lint)(n); --(i))
#define el cout << endl
#define es cout << " "
#define dump(x) cout << " " << #x << "=" << x
#define pdump(p) cout << " " << #p << "=(" << p.fst << "," << p.snd << ")"
#define vdump(v) \
for (size_t I = 0; I < v.size(); ++I) { \
cout << " " << #v << "[" << I << "]=" << v[I]; \
} \
cout << endl
using namespace std;
using lint = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main(void) {
int n, m;
cin >> n >> m;
vector<int> v(n + 1, 0);
rep(m) {
int l, r;
cin >> l >> r;
v[l] += 1;
v[r + 1] -= 1;
}
int s = 0;
int ans = 0;
repeat_from_to(i, 1, n) {
s += v[i];
if (s == m)
++ans;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for (lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for (lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for (lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for (lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for (lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) \
for (lint i = (m); (i) >= (lint)(n); --(i))
#define el cout << endl
#define es cout << " "
#define dump(x) cout << " " << #x << "=" << x
#define pdump(p) cout << " " << #p << "=(" << p.fst << "," << p.snd << ")"
#define vdump(v) \
for (size_t I = 0; I < v.size(); ++I) { \
cout << " " << #v << "[" << I << "]=" << v[I]; \
} \
cout << endl
using namespace std;
using lint = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main(void) {
int n, m;
cin >> n >> m;
vector<int> v(n + 2, 0);
rep(m) {
int l, r;
cin >> l >> r;
v[l] += 1;
v[r + 1] -= 1;
}
int s = 0;
int ans = 0;
repeat_from_to(i, 1, n) {
s += v[i];
if (s == m)
++ans;
}
cout << ans << endl;
}
| replace | 32 | 33 | 32 | 33 | 0 | |
p03037 | C++ | Runtime Error | #include "bits/stdc++.h"
// Begin Header {{{
using namespace std;
#ifndef DEBUG
#define dump(...)
#endif
#define all(x) x.begin(), x.end()
#define rep(i, n) for (intmax_t i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) \
for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) \
for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) \
Type __VA_ARGS__; \
input(__VA_ARGS__)
constexpr size_t operator""_zu(unsigned long long value) { return value; };
constexpr intmax_t operator""_jd(unsigned long long value) { return value; };
constexpr uintmax_t operator""_ju(unsigned long long value) { return value; };
constexpr int INF = 0x3f3f3f3f;
constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd;
template <class T> using MaxHeap = priority_queue<T, vector<T>, less<T>>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
inline void input() {}
template <class Head, class... Tail>
inline void input(Head &&head, Tail &&...tail) {
cin >> head;
input(forward<Tail>(tail)...);
}
template <class T> inline void input(vector<T> &vec) {
for (auto &e : vec) {
cin >> e;
}
}
template <class T> inline void input(vector<vector<T>> &mat) {
for (auto &vec : mat) {
input(vec);
}
}
inline void print() { cout << "\n"; }
template <class Head, class... Tail>
inline void print(Head &&head, Tail &&...tail) {
cout << head;
if (sizeof...(tail)) {
cout << " ";
}
print(forward<Tail>(tail)...);
}
template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
static constexpr const char *delim[] = {" ", ""};
for (const auto &e : vec) {
os << e << delim[&e == &vec.back()];
}
return os;
}
template <class T> inline vector<T> makeVector(const T &initValue, size_t sz) {
return vector<T>(sz, initValue);
}
template <class T, class... Args>
inline auto makeVector(const T &initValue, size_t sz, Args... args) {
return vector<decltype(makeVector<T>(initValue, args...))>(
sz, makeVector<T>(initValue, args...));
}
template <class Func> class FixPoint : Func {
public:
explicit constexpr FixPoint(Func &&f) noexcept : Func(forward<Func>(f)) {}
template <class... Args>
constexpr decltype(auto) operator()(Args &&...args) const {
return Func::operator()(*this, std::forward<Args>(args)...);
}
};
template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func &&f) noexcept {
return FixPoint<Func>{forward<Func>(f)};
}
template <class T> inline bool chmax(T &a, const T &b) noexcept {
return b > a && (a = b, true);
}
template <class T> inline bool chmin(T &a, const T &b) noexcept {
return b < a && (a = b, true);
}
template <class T> inline T diff(const T &a, const T &b) noexcept {
return a < b ? b - a : a - b;
}
// End Header }}}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
var(size_t, N, M);
vector<size_t> imos(N);
rep(i, M) {
var(size_t, L, R);
L--, R--;
imos[L]++, imos[R + 1]--;
}
size_t res = 0;
rep(i, N) {
if (i != 0) {
imos[i] += imos[i - 1];
}
res += (imos[i] == M);
}
print(res);
return 0;
}
| #include "bits/stdc++.h"
// Begin Header {{{
using namespace std;
#ifndef DEBUG
#define dump(...)
#endif
#define all(x) x.begin(), x.end()
#define rep(i, n) for (intmax_t i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) \
for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) \
for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) \
Type __VA_ARGS__; \
input(__VA_ARGS__)
constexpr size_t operator""_zu(unsigned long long value) { return value; };
constexpr intmax_t operator""_jd(unsigned long long value) { return value; };
constexpr uintmax_t operator""_ju(unsigned long long value) { return value; };
constexpr int INF = 0x3f3f3f3f;
constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd;
template <class T> using MaxHeap = priority_queue<T, vector<T>, less<T>>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
inline void input() {}
template <class Head, class... Tail>
inline void input(Head &&head, Tail &&...tail) {
cin >> head;
input(forward<Tail>(tail)...);
}
template <class T> inline void input(vector<T> &vec) {
for (auto &e : vec) {
cin >> e;
}
}
template <class T> inline void input(vector<vector<T>> &mat) {
for (auto &vec : mat) {
input(vec);
}
}
inline void print() { cout << "\n"; }
template <class Head, class... Tail>
inline void print(Head &&head, Tail &&...tail) {
cout << head;
if (sizeof...(tail)) {
cout << " ";
}
print(forward<Tail>(tail)...);
}
template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
static constexpr const char *delim[] = {" ", ""};
for (const auto &e : vec) {
os << e << delim[&e == &vec.back()];
}
return os;
}
template <class T> inline vector<T> makeVector(const T &initValue, size_t sz) {
return vector<T>(sz, initValue);
}
template <class T, class... Args>
inline auto makeVector(const T &initValue, size_t sz, Args... args) {
return vector<decltype(makeVector<T>(initValue, args...))>(
sz, makeVector<T>(initValue, args...));
}
template <class Func> class FixPoint : Func {
public:
explicit constexpr FixPoint(Func &&f) noexcept : Func(forward<Func>(f)) {}
template <class... Args>
constexpr decltype(auto) operator()(Args &&...args) const {
return Func::operator()(*this, std::forward<Args>(args)...);
}
};
template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func &&f) noexcept {
return FixPoint<Func>{forward<Func>(f)};
}
template <class T> inline bool chmax(T &a, const T &b) noexcept {
return b > a && (a = b, true);
}
template <class T> inline bool chmin(T &a, const T &b) noexcept {
return b < a && (a = b, true);
}
template <class T> inline T diff(const T &a, const T &b) noexcept {
return a < b ? b - a : a - b;
}
// End Header }}}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
var(size_t, N, M);
vector<size_t> imos(N + 1);
rep(i, M) {
var(size_t, L, R);
L--, R--;
imos[L]++, imos[R + 1]--;
}
size_t res = 0;
rep(i, N) {
if (i != 0) {
imos[i] += imos[i - 1];
}
res += (imos[i] == M);
}
print(res);
return 0;
}
| replace | 111 | 112 | 111 | 112 | 0 | |
p03037 | C++ | Runtime Error | #include <algorithm>
#include <functional>
#include <iostream>
using namespace std;
int main() {
int a, b, c[10000], d[10000], e;
e = 0;
cin >> a >> b;
for (int i = 0; i < b; i++) {
cin >> c[i] >> d[i];
}
sort(c, c + b, greater<int>());
sort(d, d + b);
for (int i = 0; i < 1000000; i++) {
if (c[0] <= i && i <= d[0]) {
e++;
}
}
if (a >= e) {
cout << e;
} else
cout << a;
}
| #include <algorithm>
#include <functional>
#include <iostream>
using namespace std;
int main() {
int a, b, c[100000], d[100000], e;
e = 0;
cin >> a >> b;
for (int i = 0; i < b; i++) {
cin >> c[i] >> d[i];
}
sort(c, c + b, greater<int>());
sort(d, d + b);
for (int i = 0; i < 1000000; i++) {
if (c[0] <= i && i <= d[0]) {
e++;
}
}
if (a >= e) {
cout << e;
} else
cout << a;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p03037 | C++ | Runtime Error | #include <iostream>
#include <math.h>
using namespace std;
int N;
int M;
int L[10020];
int R[10020];
int lmax, rmin;
int ans;
int main() {
cin >> N >> M;
lmax = 0;
rmin = N;
for (int i = 0; i < M; i++) {
cin >> L[i] >> R[i];
if (lmax < L[i])
lmax = L[i];
if (rmin > R[i])
rmin = R[i];
}
ans = rmin - lmax + 1;
if (ans < 0)
ans = 0;
cout << ans << endl;
return 0;
} | #include <iostream>
#include <math.h>
using namespace std;
int N;
int M;
int L[100020];
int R[100020];
int lmax, rmin;
int ans;
int main() {
cin >> N >> M;
lmax = 0;
rmin = N;
for (int i = 0; i < M; i++) {
cin >> L[i] >> R[i];
if (lmax < L[i])
lmax = L[i];
if (rmin > R[i])
rmin = R[i];
}
ans = rmin - lmax + 1;
if (ans < 0)
ans = 0;
cout << ans << endl;
return 0;
} | replace | 5 | 7 | 5 | 7 | 0 | |
p03037 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define REP(i, a, n) for (int i = a; i < n; ++i)
#define REPR(i, a, n) for (int i = a; i > n; --i)
#define RUP(a, b) ((a + b - 1) / (b))
#define SORTG(v) sort(v.begin(), v.end(), greater<>())
#define SORT(v) sort(v.begin(), v.end())
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX / 3
typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;
template <class T> void chmax(T &a, T b) {
if (a < b) {
a = b;
}
}
template <class T> void chmin(T &a, T b) {
if (a > b) {
a = b;
}
}
void YesNo(int a) { cout << ((a) ? "Yes" : "No") << endl; }
void YESNO(int a) { cout << ((a) ? "YES" : "NO") << endl; }
void AorB(int a, string b, string c) { cout << ((a) ? b : c) << endl; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
void start() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
}
signed main() {
start();
int n, m, ans = 0;
cin >> n >> m;
Vi l(m), r(m), a(n);
REP(i, 0, m) {
cin >> l[i] >> r[i];
l[i]--;
r[i]--;
a[l[i]]++;
a[r[i] + 1]--;
}
REP(i, 1, n) a[i] += a[i - 1];
REP(i, 0, n) if (a[i] == m) ans++;
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define REP(i, a, n) for (int i = a; i < n; ++i)
#define REPR(i, a, n) for (int i = a; i > n; --i)
#define RUP(a, b) ((a + b - 1) / (b))
#define SORTG(v) sort(v.begin(), v.end(), greater<>())
#define SORT(v) sort(v.begin(), v.end())
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX / 3
typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;
template <class T> void chmax(T &a, T b) {
if (a < b) {
a = b;
}
}
template <class T> void chmin(T &a, T b) {
if (a > b) {
a = b;
}
}
void YesNo(int a) { cout << ((a) ? "Yes" : "No") << endl; }
void YESNO(int a) { cout << ((a) ? "YES" : "NO") << endl; }
void AorB(int a, string b, string c) { cout << ((a) ? b : c) << endl; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
void start() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
}
signed main() {
start();
int n, m, ans = 0;
cin >> n >> m;
Vi l(m), r(m), a(n);
REP(i, 0, m) {
cin >> l[i] >> r[i];
l[i]--;
r[i]--;
a[l[i]]++;
if (r[i] + 1 < n)
a[r[i] + 1]--;
}
REP(i, 1, n) a[i] += a[i - 1];
REP(i, 0, n) if (a[i] == m) ans++;
cout << ans << endl;
}
| replace | 54 | 55 | 54 | 56 | 0 | |
p03037 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define MAX 50005
int tree[4 * MAX], arr[MAX], print[MAX];
map<int, int> cnt;
void bld(int n, int b, int e) {
if (b == e) {
// cout << arr[b] << " = " << tree[n] << endl;
cnt[arr[b]] += tree[n];
return;
}
int lft = 2 * n;
int rit = lft + 1;
int mid = (b + e) / 2;
tree[lft] += tree[n];
tree[rit] += tree[n];
bld(lft, b, mid);
bld(rit, mid + 1, e);
}
void up(int n, int b, int e, int l, int r) {
if (r < arr[b] or arr[e] < l)
return;
if (l <= arr[b] and arr[e] <= r) {
// cout << l << " to " << r << " val " << arr[b] << " " << arr[e] << endl;
tree[n]++;
return;
}
int left = n * 2;
int right = left + 1;
int mid = (b + e) / 2;
up(left, b, mid, l, r);
up(right, mid + 1, e, l, r);
}
int main() {
int n, q;
scanf("%d %d", &n, &q);
for (int i = 1; i <= n; i++)
arr[i] = i;
for (int i = 0; i < q; i++) {
int u, v;
scanf("%d %d", &u, &v);
if (q == 1) {
cout << v - u + 1 << endl;
return 0;
}
up(1, 1, n, u, v);
}
bld(1, 1, n);
int cn = 0;
for (int i = 1; i <= n; i++) {
if (cnt[i] == q)
cn++;
}
cout << cn << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define MAX 100005
int tree[4 * MAX], arr[MAX], print[MAX];
map<int, int> cnt;
void bld(int n, int b, int e) {
if (b == e) {
// cout << arr[b] << " = " << tree[n] << endl;
cnt[arr[b]] += tree[n];
return;
}
int lft = 2 * n;
int rit = lft + 1;
int mid = (b + e) / 2;
tree[lft] += tree[n];
tree[rit] += tree[n];
bld(lft, b, mid);
bld(rit, mid + 1, e);
}
void up(int n, int b, int e, int l, int r) {
if (r < arr[b] or arr[e] < l)
return;
if (l <= arr[b] and arr[e] <= r) {
// cout << l << " to " << r << " val " << arr[b] << " " << arr[e] << endl;
tree[n]++;
return;
}
int left = n * 2;
int right = left + 1;
int mid = (b + e) / 2;
up(left, b, mid, l, r);
up(right, mid + 1, e, l, r);
}
int main() {
int n, q;
scanf("%d %d", &n, &q);
for (int i = 1; i <= n; i++)
arr[i] = i;
for (int i = 0; i < q; i++) {
int u, v;
scanf("%d %d", &u, &v);
if (q == 1) {
cout << v - u + 1 << endl;
return 0;
}
up(1, 1, n, u, v);
}
bld(1, 1, n);
int cn = 0;
for (int i = 1; i <= n; i++) {
if (cnt[i] == q)
cn++;
}
cout << cn << endl;
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p03037 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c = 0, N = 0;
cin >> a >> b;
vector<int> L(b), R(b);
for (int i = 0; i < b; i++)
cin >> L[i] >> R[i];
for (int i = L[b - 1]; i < R[0] + 1; i++) {
for (int j = 0; j < b; j++) {
if (L[j] <= i && i <= R[j])
c++;
}
if (b == c)
N++;
c = 0;
}
cout << N << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c = 0, N = 0;
cin >> a >> b;
vector<int> L(b), R(b);
for (int i = 0; i < b; i++)
cin >> L[i] >> R[i];
sort(L.begin(), L.end());
sort(R.begin(), R.end());
N = R[0] - L[b - 1] + 1;
if (0 > N)
N = 0;
cout << N << endl;
}
| replace | 8 | 17 | 8 | 13 | TLE | |
p03037 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
const long long INF = 1e9 + 7;
using namespace std;
map<int, int> mp;
int main() {
int n, m;
cin >> n >> m;
vector<int> l(m), r(m);
for (int i = 0; i < m; i++)
cin >> l[i] >> r[i];
int counter = 0;
bool flag = true;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < m; j++) {
if (!(l[j] <= i && i <= r[j])) {
flag = false;
break;
}
}
if (flag)
counter++;
flag = true;
}
cout << counter << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
const long long INF = 1e9 + 7;
using namespace std;
map<int, int> mp;
int main() {
int n, m;
cin >> n >> m;
vector<int> l(m), r(m);
for (int i = 0; i < m; i++)
cin >> l[i] >> r[i];
sort(l.rbegin(), l.rend());
sort(r.begin(), r.end());
int x = r[0] - l[0] + 1;
if (x > 0) {
cout << x << endl;
} else
cout << 0 << endl;
return 0;
} | replace | 25 | 39 | 25 | 32 | TLE | |
p03037 | C++ | Runtime Error | #include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
/*struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) :x((x% mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
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 { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/
int main() {
int n, m;
cin >> n >> m;
vector<int> l(n / 2);
vector<int> r(n / 2);
int ans = 0;
int min = 1;
int max = INF;
rep(i, m) cin >> l[i] >> r[i];
for (int i = 0; i < m; i++) {
if (min <= l[i])
min = l[i];
if (max >= r[i])
max = r[i];
}
if (max < min) {
cout << 0 << endl;
return 0;
}
cout << max - min + 1 << endl;
return 0;
}
| #include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
/*struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) :x((x% mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
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 { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/
int main() {
int n, m;
cin >> n >> m;
vector<int> l(m);
vector<int> r(m);
int ans = 0;
int min = 1;
int max = INF;
rep(i, m) cin >> l[i] >> r[i];
for (int i = 0; i < m; i++) {
if (min <= l[i])
min = l[i];
if (max >= r[i])
max = r[i];
}
if (max < min) {
cout << 0 << endl;
return 0;
}
cout << max - min + 1 << endl;
return 0;
}
| replace | 42 | 44 | 42 | 44 | 0 | |
p03037 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define print(x) cout << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int main() {
int n, m;
cin >> n >> m;
vi s(n + 1, 0);
rep(i, m) {
int l, r;
cin >> l >> r;
s[l]++;
s[r + 1]--;
}
rep(i, n) { s[i + 1] += s[i]; }
int cnt = 0;
rep(i, n + 1) {
if (s[i] == m)
cnt++;
}
print(cnt);
return 0;
} | #include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define print(x) cout << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int main() {
int n, m;
cin >> n >> m;
vi s(n + 2, 0);
rep(i, m) {
int l, r;
cin >> l >> r;
s[l]++;
s[r + 1]--;
}
rep(i, n) { s[i + 1] += s[i]; }
int cnt = 0;
rep(i, n + 1) {
if (s[i] == m)
cnt++;
}
print(cnt);
return 0;
} | replace | 42 | 43 | 42 | 43 | 0 | |
p03037 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define ll long long
#define INF INT_MAX
using namespace std;
int main() {
int N, M;
cin >> N >> M;
int L[N], R[N];
for (int i = 0; i < M; i++)
cin >> L[i] >> R[i];
vector<int> count(N, 0);
for (int i = 0; i < M; i++) {
count[L[i] - 1]++;
count[R[i]]--;
}
for (int i = 1; i < N; i++) {
count[i] = count[i] + count[i - 1];
}
int ans = 0;
for (int i = 0; i < N; i++) {
if (count[i] == M)
ans++;
}
cout << ans << endl;
} | #include <algorithm>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define ll long long
#define INF INT_MAX
using namespace std;
int main() {
int N, M;
cin >> N >> M;
int L[N], R[N];
for (int i = 0; i < M; i++)
cin >> L[i] >> R[i];
int count[N];
for (int i = 0; i < N; i++)
count[i] = 0;
for (int i = 0; i < M; i++) {
count[L[i] - 1]++;
count[R[i]]--;
}
for (int i = 1; i < N; i++) {
count[i] = count[i] + count[i - 1];
}
int ans = 0;
for (int i = 0; i < N; i++) {
if (count[i] == M)
ans++;
}
cout << ans << endl;
} | replace | 19 | 20 | 19 | 22 | 0 | |
p03037 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
long n, m;
cin >> n >> m;
long l[m];
long r[m];
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i];
}
long sei = 0;
for (long i = 1; i <= n; i++) {
int aho = 1;
for (long j = 0; j < m; j++) {
if (i < l[j] || i > r[j]) {
aho = 0;
break;
}
}
if (aho == 1) {
sei += 1;
// cout<<i<<endl;
}
}
cout << sei;
return 0;
} | #include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
long n, m;
cin >> n >> m;
long l[m];
long r[m];
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i];
}
sort(l, l + m);
sort(r, r + m);
int hidari = l[m - 1];
int migi = r[0];
int k = migi - hidari + 1;
if (k <= 0)
cout << "0";
else
cout << k;
return 0;
} | replace | 16 | 31 | 16 | 25 | TLE | |
p03037 | Python | Time Limit Exceeded | #!/usr/bin/env python3
import sys
N, M = map(int, input().rstrip().split())
L = []
R = []
for _ in range(M):
l, r = map(int, input().rstrip().split())
L.append(l)
R.append(r)
Ans = set(range(L[0], R[0] + 1))
for i in range(1, len(L)):
Ans = set(range(L[i], R[i] + 1)) & Ans
if not Ans:
print(0)
sys.exit(0)
print(len(Ans))
| #!/usr/bin/env python3
import sys
N, M = map(int, input().rstrip().split())
L = []
R = []
for _ in range(M):
l, r = map(int, input().rstrip().split())
L.append(l)
R.append(r)
Ans = min(R) - max(L) + 1
if Ans < 0:
Ans = 0
print(Ans)
| replace | 12 | 20 | 12 | 16 | TLE | |
p03037 | Python | Time Limit Exceeded | n, m = map(int, input().split())
ans = set(range(1, n + 1))
for _ in range(m):
l, r = map(int, input().split())
st = set(range(l, r + 1))
ans &= st
print(len(ans))
| def solve2():
n, m = map(int, input().split())
L = 1
R = n
for _ in range(m):
l, r = map(int, input().split())
L = max(L, l)
R = min(R, r)
if L <= R:
print(R - L + 1)
else:
print(0)
solve2()
| replace | 0 | 7 | 0 | 15 | TLE | |
p03037 | Python | Time Limit Exceeded | N, M = map(int, input().split())
L = [0] * M
R = [0] * M
count = 0
for i in range(M):
L[i], R[i] = map(int, input().split())
for i in range(N):
clear = 0
for j in range(M):
if L[j] <= i + 1 <= R[j]:
clear += 1
else:
break
if clear == M:
count += 1
print(count)
| N, M = map(int, input().split())
L = [0] * M
R = [0] * M
count = 0
for i in range(M):
L[i], R[i] = map(int, input().split())
Lmax = max(L)
Rmin = min(R)
if Lmax <= Rmin:
print(Rmin - Lmax + 1)
else:
print(0)
| replace | 6 | 16 | 6 | 12 | TLE | |
p03037 | Python | Time Limit Exceeded | n, m = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(m)]
ans = []
for i in range(m):
res = []
for j in range(lr[i][0], lr[i][1] + 1):
res.append(j)
if i == 0:
ans = set(res)
else:
ans = set(ans) & set(res)
print(len(ans))
| n, m = map(int, input().split())
mi, ma = 1, n
for _ in range(m):
l, r = map(int, input().split())
mi = max(l, mi)
ma = min(r, ma)
print(max(0, ma - mi + 1))
| replace | 1 | 12 | 1 | 7 | TLE | |
p03037 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> l(n), r(n);
int maxl = 0, minr = n + 1;
rep(i, m) cin >> l.at(i) >> r.at(i);
rep(i, m) {
maxl = max(maxl, l.at(i));
minr = min(minr, r.at(i));
}
if (minr < maxl)
cout << 0 << endl;
else
cout << minr - maxl + 1 << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> l(m), r(m);
int maxl = 1, minr = n + 1;
rep(i, m) cin >> l.at(i) >> r.at(i);
rep(i, m) {
maxl = max(maxl, l.at(i));
minr = min(minr, r.at(i));
}
if (minr < maxl)
cout << 0 << endl;
else
cout << minr - maxl + 1 << endl;
} | replace | 11 | 13 | 11 | 13 | 0 | |
p03037 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define REP(i, a) for (int i = 0; i < (a); ++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(obj) (obj).begin, (obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main() {
int n, m;
cin >> n >> m;
int l, r;
int L[n], R[n];
REP(i, m) { cin >> L[i] >> R[i]; }
l = L[0];
r = R[0];
FOR(i, 1, m) {
if (l > R[i] || r < L[i]) {
cout << 0 << endl;
return 0;
}
l = max(l, L[i]);
r = min(r, R[i]);
}
cout << r - l + 1 << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define REP(i, a) for (int i = 0; i < (a); ++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(obj) (obj).begin, (obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main() {
int n, m;
cin >> n >> m;
int l, r;
int L[m], R[m];
REP(i, m) { cin >> L[i] >> R[i]; }
l = L[0];
r = R[0];
FOR(i, 1, m) {
if (l > R[i] || r < L[i]) {
cout << 0 << endl;
return 0;
}
l = max(l, L[i]);
r = min(r, R[i]);
}
cout << r - l + 1 << endl;
return 0;
} | replace | 19 | 20 | 19 | 20 | 0 | |
p03037 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int> vint;
typedef vector<ll> vll;
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (auto &v : vec)
is >> v;
return is;
}
int main() {
int N, M;
cin >> N >> M;
vint L(N);
vint R(N);
REP(i, M) { cin >> L[i] >> R[i]; }
int l = L[0];
int r = R[0];
REP(i, M - 1) {
l = max(l, L[i + 1]);
r = min(r, R[i + 1]);
}
int ans = 0;
if (l <= r) {
REP(i, N) {
if (l <= (i + 1) && (i + 1) <= r) {
ans++;
}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int> vint;
typedef vector<ll> vll;
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (auto &v : vec)
is >> v;
return is;
}
int main() {
int N, M;
cin >> N >> M;
vint L(M);
vint R(M);
REP(i, M) { cin >> L[i] >> R[i]; }
int l = L[0];
int r = R[0];
REP(i, M - 1) {
l = max(l, L[i + 1]);
r = min(r, R[i + 1]);
}
int ans = 0;
if (l <= r) {
REP(i, N) {
if (l <= (i + 1) && (i + 1) <= r) {
ans++;
}
}
}
cout << ans << endl;
} | replace | 18 | 20 | 18 | 20 | 0 | |
p03037 | C++ | Time Limit Exceeded | #define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep2(i, s, n) for (int i = s; i < (int)n; i++)
#define ll long long
#define all(v) v.begin(), v.end()
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m), b(m);
rep(i, m) cin >> a[i] >> b[i];
map<int, int> MAP;
rep(i, m) {
rep2(j, a[i] - 1, b[i]) { MAP[j]++; }
}
int ans = 0;
rep(i, n) if (MAP[i] == m) ans++;
cout << ans << endl;
}
| #define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep2(i, s, n) for (int i = s; i < (int)n; i++)
#define ll long long
#define all(v) v.begin(), v.end()
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m), b(m);
rep(i, m) cin >> a[i] >> b[i];
sort(all(a));
sort(all(b));
if (b[0] < a[m - 1])
cout << 0 << endl;
else
cout << b[0] - a[m - 1] + 1 << endl;
} | replace | 24 | 31 | 24 | 30 | TLE | |
p03037 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
signed main() {
int n, m;
cin >> n >> m;
vector<int> l(n), r(n);
rep(i, m) cin >> l[i] >> r[i];
int mnr = n, mxl = 1;
rep(i, m) {
mxl = max(mxl, l[i]);
mnr = min(mnr, r[i]);
}
if (mnr < mxl)
cout << 0 << endl;
else
cout << mnr - mxl + 1 << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
signed main() {
int n, m;
cin >> n >> m;
vector<int> l(m), r(m);
rep(i, m) cin >> l[i] >> r[i];
int mnr = n, mxl = 1;
rep(i, m) {
mxl = max(mxl, l[i]);
mnr = min(mnr, r[i]);
}
if (mnr < mxl)
cout << 0 << endl;
else
cout << mnr - mxl + 1 << endl;
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p03037 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
int main() {
int n, m;
cin >> n >> m;
vector<int> l(m);
vector<int> r(m);
rep(i, m) cin >> l[i] >> r[i];
int cnt = 0;
rep(i, n + 1) {
bool ok = true;
rep(j, m) {
if (!(i >= l[j] && i <= r[j]))
ok = false;
}
if (ok)
cnt++;
}
cout << cnt << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
int main() {
int n, m;
cin >> n >> m;
vector<int> l(m);
vector<int> r(m);
rep(i, m) cin >> l[i] >> r[i];
int L = *max_element(l.begin(), l.end());
int R = *min_element(r.begin(), r.end());
int ans = R - L + 1;
if (ans >= 0)
cout << ans;
else
cout << "0";
} | replace | 9 | 20 | 9 | 17 | TLE | |
p03037 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <math.h>
#include <numeric>
#include <stdlib.h>
#include <string>
#include <vector>
int main() {
int n, m;
std::cin >> n >> m;
std::vector<int> v(n + 1, 0);
for (size_t i = 0; i < m; i++) {
int a, b;
std::cin >> a >> b;
v[a]++;
v[b + 1]--;
}
for (size_t i = 1; i < n + 1; i++) {
v[i] += v[i - 1];
}
int ans = 0;
for (size_t i = 0; i < n + 1; i++) {
if (v[i] == m) {
ans++;
}
}
std::cout << ans << std::endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <math.h>
#include <numeric>
#include <stdlib.h>
#include <string>
#include <vector>
int main() {
int n, m;
std::cin >> n >> m;
std::vector<int> v(n + 1, 0);
for (size_t i = 0; i < m; i++) {
int a, b;
std::cin >> a >> b;
a--;
b--;
v[a]++;
v[b + 1]--;
}
for (size_t i = 1; i < n + 1; i++) {
v[i] += v[i - 1];
}
int ans = 0;
for (size_t i = 0; i < n + 1; i++) {
if (v[i] == m) {
ans++;
}
}
std::cout << ans << std::endl;
return 0;
} | insert | 20 | 20 | 20 | 23 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.