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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02757 | C++ | Runtime Error | #include <bits/stdc++.h>
#define per(i, a, n) for (int i = a; i <= n; i++)
#define ls l + mid >> 1
#define rs mid + 1 + r >> 1
using namespace std;
typedef long long ll;
int vp[10010];
char s[10010];
int main() {
int n, p;
cin >> n >> p;
ll ans = 0;
scanf("%s", s + 1);
ll kk = 1, an = 0;
vp[0] = 1;
if (p == 2 || p == 5) {
for (int i = n; i >= 1; i--) {
if ((s[i] - '0') % p == 0)
ans += i;
}
cout << ans << endl;
} else {
for (int i = n; i >= 1; i--) {
an = an + ((s[i] - '0') * kk) % p;
an %= p;
ans += vp[an];
vp[an]++;
kk = kk * 10 % p;
}
cout << ans << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define per(i, a, n) for (int i = a; i <= n; i++)
#define ls l + mid >> 1
#define rs mid + 1 + r >> 1
using namespace std;
typedef long long ll;
int vp[10010];
char s[200010];
int main() {
int n, p;
cin >> n >> p;
ll ans = 0;
scanf("%s", s + 1);
ll kk = 1, an = 0;
vp[0] = 1;
if (p == 2 || p == 5) {
for (int i = n; i >= 1; i--) {
if ((s[i] - '0') % p == 0)
ans += i;
}
cout << ans << endl;
} else {
for (int i = n; i >= 1; i--) {
an = an + ((s[i] - '0') * kk) % p;
an %= p;
ans += vp[an];
vp[an]++;
kk = kk * 10 % p;
}
cout << ans << endl;
}
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02757 | C++ | Runtime Error | #include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
distance(v.begin(), upper_bound(v.begin(), v.end(), x))
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;
ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
/* Macros reg. ends here */
const ll INF = 1LL << 50;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(15);
ll n, p;
cin >> n >> p;
string s;
cin >> s;
ll ans = 0;
if (10 % p == 0) {
rep(i, n) {
ll d = s[i] - '0';
if (d % p == 0)
ans += i + 1;
}
cout << ans << endl;
return 0;
}
vll csum(n + 1, 0);
ll ten = 1;
vll cnt(10, 0);
cnt[0] = 1;
rep(i, n) {
ll d = s[n - 1 - i] - '0';
csum[i + 1] = (csum[i] + ten * d) % p;
ten = (ten * 10) % p;
ans += cnt[csum[i + 1]];
cnt[csum[i + 1]]++;
}
cout << ans << endl;
return 0;
} | #include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
distance(v.begin(), upper_bound(v.begin(), v.end(), x))
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;
ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
/* Macros reg. ends here */
const ll INF = 1LL << 50;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(15);
ll n, p;
cin >> n >> p;
string s;
cin >> s;
ll ans = 0;
if (10 % p == 0) {
rep(i, n) {
ll d = s[i] - '0';
if (d % p == 0)
ans += i + 1;
}
cout << ans << endl;
return 0;
}
vll csum(n + 1, 0);
ll ten = 1;
vll cnt(p, 0);
cnt[0] = 1;
rep(i, n) {
ll d = s[n - 1 - i] - '0';
csum[i + 1] = (csum[i] + ten * d) % p;
ten = (ten * 10) % p;
ans += cnt[csum[i + 1]];
cnt[csum[i + 1]]++;
}
cout << ans << endl;
return 0;
}
| replace | 77 | 78 | 77 | 78 | 0 | |
p02757 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long n, p;
char s[100010];
map<long, long> mp;
int main() {
cin >> n >> p;
cin >> s;
long long ans = 0;
if (10 % p == 0) {
for (int i = 0; i < n; i++) {
if ((s[i] - '0') % p == 0)
ans += i + 1;
}
} else {
// 从低位往上搞
long long res = 0, t = 1;
for (int i = n - 1; i >= 0; i--) {
res = res + (s[i] - '0') * t;
res %= p;
t = t * 10 % p;
if (res == 0)
ans++;
ans += mp[res];
mp[res]++;
}
}
cout << ans << '\n';
}
| #include <bits/stdc++.h>
using namespace std;
long long n, p;
char s[200010];
map<long, long> mp;
int main() {
cin >> n >> p;
cin >> s;
long long ans = 0;
if (10 % p == 0) {
for (int i = 0; i < n; i++) {
if ((s[i] - '0') % p == 0)
ans += i + 1;
}
} else {
// 从低位往上搞
long long res = 0, t = 1;
for (int i = n - 1; i >= 0; i--) {
res = res + (s[i] - '0') * t;
res %= p;
t = t * 10 % p;
if (res == 0)
ans++;
ans += mp[res];
mp[res]++;
}
}
cout << ans << '\n';
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p02757 | C++ | Runtime Error | #include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using default_counter_t = int;
// macro
#define let auto const &
#define overload4(a, b, c, d, name, ...) name
#define rep1(n) \
for (default_counter_t i = 0, end_i = default_counter_t(n); i < end_i; ++i)
#define rep2(i, n) \
for (default_counter_t i = 0, end_##i = default_counter_t(n); i < end_##i; \
++i)
#define rep3(i, a, b) \
for (default_counter_t i = default_counter_t(a), \
end_##i = default_counter_t(b); \
i < end_##i; ++i)
#define rep4(i, a, b, c) \
for (default_counter_t i = default_counter_t(a), \
end_##i = default_counter_t(b); \
i < end_##i; i += default_counter_t(c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) \
for (default_counter_t i = default_counter_t(n) - 1; i >= 0; --i)
#define rrep2(i, n) \
for (default_counter_t i = default_counter_t(n) - 1; i >= 0; --i)
#define rrep3(i, a, b) \
for (default_counter_t i = default_counter_t(b) - 1, \
begin_##i = default_counter_t(a); \
i >= begin_##i; --i)
#define rrep4(i, a, b, c) \
for (int i = (default_counter_t(b) - default_counter_t(a) - 1) / \
default_counter_t(c) * default_counter_t(c) + \
default_counter_t(a), \
begin_##i = default_counter_t(a); \
i >= begin_##i; i -= default_counter_t(c))
#define rrep(...) \
overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define ALL(f, c, ...) \
(([&](decltype((c)) cccc) { \
return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); \
})(c))
// function
template <class C> constexpr C &Sort(C &a) {
std::sort(std::begin(a), std::end(a));
return a;
}
template <class C> constexpr auto &Min(C const &a) {
return *std::min_element(std::begin(a), std::end(a));
}
template <class C> constexpr auto &Max(C const &a) {
return *std::max_element(std::begin(a), std::end(a));
}
template <class C> constexpr auto Total(C const &c) {
return std::accumulate(std::begin(c), std::end(c), C(0));
}
template <typename T> auto CumSum(std::vector<T> const &v) {
std::vector<T> a(v.size() + 1, T(0));
for (std::size_t i = 0; i < a.size() - size_t(1); ++i)
a[i + 1] = a[i] + v[i];
return a;
}
template <typename T> constexpr bool ChMax(T &a, T const &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> constexpr bool ChMin(T &a, T const &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
void In(void) { return; }
template <typename First, typename... Rest>
void In(First &first, Rest &...rest) {
cin >> first;
In(rest...);
return;
}
template <class T, typename I> void VectorIn(vector<T> &v, const I n) {
v.resize(size_t(n));
rep(i, v.size()) cin >> v[i];
}
void Out(void) {
cout << "\n";
return;
}
template <typename First, typename... Rest>
void Out(First first, Rest... rest) {
cout << first << " ";
Out(rest...);
return;
}
constexpr auto yes(const bool c) { return c ? "yes" : "no"; }
constexpr auto Yes(const bool c) { return c ? "Yes" : "No"; }
constexpr auto YES(const bool c) { return c ? "YES" : "NO"; }
#ifdef USE_STACK_TRACE_LOGGER
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <glog/logging.h>
#pragma clang diagnostic pop
#endif //__clang__
#endif // USE_STACK_TRACE_LOGGER
signed main(int argc, char *argv[]) {
(void)argc;
#ifdef USE_STACK_TRACE_LOGGER
google::InitGoogleLogging(argv[0]);
google::InstallFailureSignalHandler();
#else
(void)argv;
#endif // USE_STACK_TRACE_LOGGER
int64_t n, p;
cin >> n >> p;
string s;
cin >> s;
if (p == 2 || p == 5) {
int64_t cnt = 0;
rep(i, n) {
const int64_t d = s[i] - '0';
if (d % p == 0) {
cnt += i + 1;
}
}
printf("%ld\n", cnt);
return 0;
}
vector<int64_t> t;
t.resize(n + 1);
t[0] = 0;
{
int64_t tmp = 1;
rep(i, n) {
t[i + 1] += t[i] + (s[n - i - 1] - '0') * tmp;
t[i + 1] %= p;
tmp *= 10;
tmp %= p;
}
}
vector<int64_t> cnts(2020, 0);
rep(i, n + 1) { cnts[t[i]]++; }
int64_t ans = 0;
for (auto cnt : cnts) {
ans += cnt * (cnt - 1) / 2;
}
printf("%ld\n", ans);
return EXIT_SUCCESS;
}
| #include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using default_counter_t = int;
// macro
#define let auto const &
#define overload4(a, b, c, d, name, ...) name
#define rep1(n) \
for (default_counter_t i = 0, end_i = default_counter_t(n); i < end_i; ++i)
#define rep2(i, n) \
for (default_counter_t i = 0, end_##i = default_counter_t(n); i < end_##i; \
++i)
#define rep3(i, a, b) \
for (default_counter_t i = default_counter_t(a), \
end_##i = default_counter_t(b); \
i < end_##i; ++i)
#define rep4(i, a, b, c) \
for (default_counter_t i = default_counter_t(a), \
end_##i = default_counter_t(b); \
i < end_##i; i += default_counter_t(c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) \
for (default_counter_t i = default_counter_t(n) - 1; i >= 0; --i)
#define rrep2(i, n) \
for (default_counter_t i = default_counter_t(n) - 1; i >= 0; --i)
#define rrep3(i, a, b) \
for (default_counter_t i = default_counter_t(b) - 1, \
begin_##i = default_counter_t(a); \
i >= begin_##i; --i)
#define rrep4(i, a, b, c) \
for (int i = (default_counter_t(b) - default_counter_t(a) - 1) / \
default_counter_t(c) * default_counter_t(c) + \
default_counter_t(a), \
begin_##i = default_counter_t(a); \
i >= begin_##i; i -= default_counter_t(c))
#define rrep(...) \
overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define ALL(f, c, ...) \
(([&](decltype((c)) cccc) { \
return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); \
})(c))
// function
template <class C> constexpr C &Sort(C &a) {
std::sort(std::begin(a), std::end(a));
return a;
}
template <class C> constexpr auto &Min(C const &a) {
return *std::min_element(std::begin(a), std::end(a));
}
template <class C> constexpr auto &Max(C const &a) {
return *std::max_element(std::begin(a), std::end(a));
}
template <class C> constexpr auto Total(C const &c) {
return std::accumulate(std::begin(c), std::end(c), C(0));
}
template <typename T> auto CumSum(std::vector<T> const &v) {
std::vector<T> a(v.size() + 1, T(0));
for (std::size_t i = 0; i < a.size() - size_t(1); ++i)
a[i + 1] = a[i] + v[i];
return a;
}
template <typename T> constexpr bool ChMax(T &a, T const &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> constexpr bool ChMin(T &a, T const &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
void In(void) { return; }
template <typename First, typename... Rest>
void In(First &first, Rest &...rest) {
cin >> first;
In(rest...);
return;
}
template <class T, typename I> void VectorIn(vector<T> &v, const I n) {
v.resize(size_t(n));
rep(i, v.size()) cin >> v[i];
}
void Out(void) {
cout << "\n";
return;
}
template <typename First, typename... Rest>
void Out(First first, Rest... rest) {
cout << first << " ";
Out(rest...);
return;
}
constexpr auto yes(const bool c) { return c ? "yes" : "no"; }
constexpr auto Yes(const bool c) { return c ? "Yes" : "No"; }
constexpr auto YES(const bool c) { return c ? "YES" : "NO"; }
#ifdef USE_STACK_TRACE_LOGGER
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <glog/logging.h>
#pragma clang diagnostic pop
#endif //__clang__
#endif // USE_STACK_TRACE_LOGGER
signed main(int argc, char *argv[]) {
(void)argc;
#ifdef USE_STACK_TRACE_LOGGER
google::InitGoogleLogging(argv[0]);
google::InstallFailureSignalHandler();
#else
(void)argv;
#endif // USE_STACK_TRACE_LOGGER
int64_t n, p;
cin >> n >> p;
string s;
cin >> s;
if (p == 2 || p == 5) {
int64_t cnt = 0;
rep(i, n) {
const int64_t d = s[i] - '0';
if (d % p == 0) {
cnt += i + 1;
}
}
printf("%ld\n", cnt);
return 0;
}
vector<int64_t> t;
t.resize(n + 1);
t[0] = 0;
{
int64_t tmp = 1;
rep(i, n) {
t[i + 1] += t[i] + (s[n - i - 1] - '0') * tmp;
t[i + 1] %= p;
tmp *= 10;
tmp %= p;
}
}
vector<int64_t> cnts(p, 0);
rep(i, n + 1) { cnts[t[i]]++; }
int64_t ans = 0;
for (auto cnt : cnts) {
ans += cnt * (cnt - 1) / 2;
}
printf("%ld\n", ans);
return EXIT_SUCCESS;
}
| replace | 163 | 164 | 163 | 164 | 0 | |
p02757 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
// P と 10が互いに素でない場合,
// つまりP=2 または P=5の場合、フェルマーの小定理や、
// その他逆元を高速に演算する手法が使えなさそうなので注意
// https://twitter.com/satanic0258/status/1236285593677520896
int N;
ll P;
const int MAX_N = 200;
string S;
ll C[MAX_N];
void solve_2() {
ll res = 0;
for (int i = 0; i < N; ++i) {
int c = S[i] - '0';
if (c % 2 == 0)
res += N - i;
}
cout << res << endl;
return;
}
void solve_5() {
ll res = 0;
for (int i = 0; i < N; ++i) {
int c = S[i] - '0';
if (c % 5 == 0)
res += N - i;
}
cout << res << endl;
return;
}
int main() {
cin >> N >> P;
cin >> S;
reverse(S.begin(), S.end());
if (P == 2) {
solve_2();
return 0;
}
if (P == 5) {
solve_5();
return 0;
}
ll base = 1;
map<ll, ll> Map;
Map[0]++; // 何も数を選択していないときは0になるため
for (int i = 0; i < N; ++i) {
C[i] = (ll)(S[i] - '0') * base % P;
base *= 10;
base %= P;
}
for (int i = 1; i < N; ++i) {
C[i] += C[i - 1];
C[i] %= P;
}
for (int i = 0; i < N; ++i) {
Map[C[i]]++;
}
ll res = 0;
for (auto &p : Map) {
ll num = p.second;
res += num * (num - 1) / 2;
}
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
// P と 10が互いに素でない場合,
// つまりP=2 または P=5の場合、フェルマーの小定理や、
// その他逆元を高速に演算する手法が使えなさそうなので注意
// https://twitter.com/satanic0258/status/1236285593677520896
int N;
ll P;
const int MAX_N = 200100;
string S;
ll C[MAX_N];
void solve_2() {
ll res = 0;
for (int i = 0; i < N; ++i) {
int c = S[i] - '0';
if (c % 2 == 0)
res += N - i;
}
cout << res << endl;
return;
}
void solve_5() {
ll res = 0;
for (int i = 0; i < N; ++i) {
int c = S[i] - '0';
if (c % 5 == 0)
res += N - i;
}
cout << res << endl;
return;
}
int main() {
cin >> N >> P;
cin >> S;
reverse(S.begin(), S.end());
if (P == 2) {
solve_2();
return 0;
}
if (P == 5) {
solve_5();
return 0;
}
ll base = 1;
map<ll, ll> Map;
Map[0]++; // 何も数を選択していないときは0になるため
for (int i = 0; i < N; ++i) {
C[i] = (ll)(S[i] - '0') * base % P;
base *= 10;
base %= P;
}
for (int i = 1; i < N; ++i) {
C[i] += C[i - 1];
C[i] %= P;
}
for (int i = 0; i < N; ++i) {
Map[C[i]]++;
}
ll res = 0;
for (auto &p : Map) {
ll num = p.second;
res += num * (num - 1) / 2;
}
cout << res << endl;
return 0;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p02758 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define vi vector<ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define rs(v, n) v.resize(n)
#define hell 998244353
#define peak 9123372036854775807
#define pii acos(-1)
#define clr(a, x) memset(a, x, sizeof(a))
#define ios \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define ordered_set \
tree<ll int, null_type, less<ll int>, rb_tree_tag, \
tree_order_statistics_node_update>
using namespace std;
template <class x, class y> x sum(x a, y b) { return a + b; }
template <class x, class y> x mul(x a, y b) { return a * b; }
template <class x, class y> x sub(x a, y b) { return a - b; }
template <class x, class y> x divi(x a, y b) { return a / b; }
template <class x, class y> istream &operator>>(istream &in, pair<x, y> &p) {
in >> p.F >> p.S;
return in;
}
template <class x> istream &operator>>(istream &in, vector<x> &v) {
for (auto &i : v)
in >> i;
return in;
}
template <class x, class y> ostream &operator<<(ostream &out, pair<x, y> &p) {
out << "(" << p.F << "," << p.S << ") ";
return out;
}
template <class x> ostream &operator<<(ostream &out, vector<x> &v) {
out << v.size() << endl;
for (auto i : v)
out << i << " ";
out << endl;
return out;
}
#define N 100005
ll n, l, r;
vi a(N + 5, 0), seg(4 * (N + 5));
void build(ll cur, ll st, ll end) {
if (st == end) {
seg[cur] = a[st];
return;
}
ll mid = (st + end) >> 1;
build(2 * cur, st, mid);
build(2 * cur + 1, mid + 1, end);
seg[cur] = max(seg[2 * cur], seg[2 * cur + 1]); /* 1-change here */
}
ll query(ll cur, ll st, ll end, ll l, ll r) {
if (l <= st && r >= end)
return seg[cur];
if (r < st || l > end)
return 0; /* 2-change here */
ll mid = (st + end) >> 1;
ll ans1 = query(2 * cur, st, mid, l, r);
ll ans2 = query(2 * cur + 1, mid + 1, end, l, r);
return max(ans1, ans2); /* 3-change here */
}
void update(ll cur, ll st, ll end, ll pos, ll upd) {
if (st == end) {
a[pos] = upd; /* 4-change here */
seg[cur] = upd; /* 5-change here */
return;
}
ll mid = (st + end) >> 1;
if (st <= pos && pos <= mid)
update(2 * cur, st, mid, pos, upd);
else
update(2 * cur + 1, mid + 1, end, pos, upd);
seg[cur] = max(seg[2 * cur], seg[2 * cur + 1]); /* 6-change here */
}
int main() {
ios;
ll tt = 1;
// cin>>tt;
while (tt--) {
ll i, j, k, l, m, n;
cin >> n;
build(1, 0, N);
vector<pair<ll, ll>> v;
vi vv;
for (i = 0; i < n; i++) {
cin >> l >> m;
vv.pb(l);
v.pb({l, m});
}
vi ans(n + 1, 0);
sort(all(v));
sort(all(vv));
ans[n] = 1;
for (i = n - 1; i >= 0; i--) {
ll x = v[i].F + v[i].S - 1;
ll ind = upper_bound(all(vv), x) - vv.begin() - 1;
ll y = query(1, 0, N, i, ind);
y = max(y, i);
update(1, 0, N, i, y);
}
for (i = n - 1; i >= 0; i--) {
ll y = a[i];
ans[i] = (ans[i + 1] + ans[a[i] + 1]) % hell;
}
cout << ans[0] << endl;
}
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define vi vector<ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define rs(v, n) v.resize(n)
#define hell 998244353
#define peak 9123372036854775807
#define pii acos(-1)
#define clr(a, x) memset(a, x, sizeof(a))
#define ios \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define ordered_set \
tree<ll int, null_type, less<ll int>, rb_tree_tag, \
tree_order_statistics_node_update>
using namespace std;
template <class x, class y> x sum(x a, y b) { return a + b; }
template <class x, class y> x mul(x a, y b) { return a * b; }
template <class x, class y> x sub(x a, y b) { return a - b; }
template <class x, class y> x divi(x a, y b) { return a / b; }
template <class x, class y> istream &operator>>(istream &in, pair<x, y> &p) {
in >> p.F >> p.S;
return in;
}
template <class x> istream &operator>>(istream &in, vector<x> &v) {
for (auto &i : v)
in >> i;
return in;
}
template <class x, class y> ostream &operator<<(ostream &out, pair<x, y> &p) {
out << "(" << p.F << "," << p.S << ") ";
return out;
}
template <class x> ostream &operator<<(ostream &out, vector<x> &v) {
out << v.size() << endl;
for (auto i : v)
out << i << " ";
out << endl;
return out;
}
#define N 200005
ll n, l, r;
vi a(N + 5, 0), seg(4 * (N + 5));
void build(ll cur, ll st, ll end) {
if (st == end) {
seg[cur] = a[st];
return;
}
ll mid = (st + end) >> 1;
build(2 * cur, st, mid);
build(2 * cur + 1, mid + 1, end);
seg[cur] = max(seg[2 * cur], seg[2 * cur + 1]); /* 1-change here */
}
ll query(ll cur, ll st, ll end, ll l, ll r) {
if (l <= st && r >= end)
return seg[cur];
if (r < st || l > end)
return 0; /* 2-change here */
ll mid = (st + end) >> 1;
ll ans1 = query(2 * cur, st, mid, l, r);
ll ans2 = query(2 * cur + 1, mid + 1, end, l, r);
return max(ans1, ans2); /* 3-change here */
}
void update(ll cur, ll st, ll end, ll pos, ll upd) {
if (st == end) {
a[pos] = upd; /* 4-change here */
seg[cur] = upd; /* 5-change here */
return;
}
ll mid = (st + end) >> 1;
if (st <= pos && pos <= mid)
update(2 * cur, st, mid, pos, upd);
else
update(2 * cur + 1, mid + 1, end, pos, upd);
seg[cur] = max(seg[2 * cur], seg[2 * cur + 1]); /* 6-change here */
}
int main() {
ios;
ll tt = 1;
// cin>>tt;
while (tt--) {
ll i, j, k, l, m, n;
cin >> n;
build(1, 0, N);
vector<pair<ll, ll>> v;
vi vv;
for (i = 0; i < n; i++) {
cin >> l >> m;
vv.pb(l);
v.pb({l, m});
}
vi ans(n + 1, 0);
sort(all(v));
sort(all(vv));
ans[n] = 1;
for (i = n - 1; i >= 0; i--) {
ll x = v[i].F + v[i].S - 1;
ll ind = upper_bound(all(vv), x) - vv.begin() - 1;
ll y = query(1, 0, N, i, ind);
y = max(y, i);
update(1, 0, N, i, y);
}
for (i = n - 1; i >= 0; i--) {
ll y = a[i];
ans[i] = (ans[i + 1] + ans[a[i] + 1]) % hell;
}
cout << ans[0] << endl;
}
return 0;
} | replace | 50 | 51 | 50 | 51 | 0 | |
p02758 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244353;
int n;
pair<int, int> p[1000001];
int t[100001 * 4];
int far[100001];
int dp[100001];
void update(int x, int st, int ed, int pos, int ind) {
if (st == ed) {
t[x] = ind;
return;
}
int mid = (st + ed) / 2;
if (pos <= mid)
update(x * 2, st, mid, pos, ind);
else
update(x * 2 + 1, mid + 1, ed, pos, ind);
t[x] = max(t[x * 2], t[x * 2 + 1]);
}
int query(int x, int st, int ed, int l, int r) {
if (st >= l && ed <= r)
return t[x];
if (st > r || ed < l)
return 0;
int mid = (st + ed) / 2;
return max(query(x * 2, st, mid, l, r), query(x * 2 + 1, mid + 1, ed, l, r));
}
signed main() {
scanf("%lld", &n);
for (int i = 1; i <= n; i++)
scanf("%lld%lld", &p[i].first, &p[i].second);
sort(p + 1, p + n + 1);
for (int i = n; i >= 1; i--) {
int l = i - 1, r = n + 1;
while (l + 1 < r) {
int mid = (l + r) / 2;
if (p[mid].first <= p[i].first + p[i].second - 1)
l = mid;
else
r = mid;
}
far[i] = max(i, query(1, 1, n, i + 1, l));
update(1, 1, n, i, far[i]);
}
dp[n + 1] = 1;
for (int i = n; i >= 1; i--) {
dp[i] = dp[i + 1] + dp[far[i] + 1];
dp[i] %= mod;
}
printf("%d", dp[1]);
return 0;
}
/*
4 2
2212
*/ | #include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244353;
int n;
pair<int, int> p[200001];
int t[200001 * 4];
int far[200001];
int dp[200001];
void update(int x, int st, int ed, int pos, int ind) {
if (st == ed) {
t[x] = ind;
return;
}
int mid = (st + ed) / 2;
if (pos <= mid)
update(x * 2, st, mid, pos, ind);
else
update(x * 2 + 1, mid + 1, ed, pos, ind);
t[x] = max(t[x * 2], t[x * 2 + 1]);
}
int query(int x, int st, int ed, int l, int r) {
if (st >= l && ed <= r)
return t[x];
if (st > r || ed < l)
return 0;
int mid = (st + ed) / 2;
return max(query(x * 2, st, mid, l, r), query(x * 2 + 1, mid + 1, ed, l, r));
}
signed main() {
scanf("%lld", &n);
for (int i = 1; i <= n; i++)
scanf("%lld%lld", &p[i].first, &p[i].second);
sort(p + 1, p + n + 1);
for (int i = n; i >= 1; i--) {
int l = i - 1, r = n + 1;
while (l + 1 < r) {
int mid = (l + r) / 2;
if (p[mid].first <= p[i].first + p[i].second - 1)
l = mid;
else
r = mid;
}
far[i] = max(i, query(1, 1, n, i + 1, l));
update(1, 1, n, i, far[i]);
}
dp[n + 1] = 1;
for (int i = n; i >= 1; i--) {
dp[i] = dp[i + 1] + dp[far[i] + 1];
dp[i] %= mod;
}
printf("%d", dp[1]);
return 0;
}
/*
4 2
2212
*/ | replace | 5 | 9 | 5 | 9 | 0 | |
p02758 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iostream>
#include <map>
#include <random>
#include <set>
#include <string>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int t[500000];
int Max(int v, int tl, int tr, int l, int r) {
if (l > r)
return 0;
if (l == tl && r == tr)
return t[v];
int tm = (tl + tr) / 2;
return max(Max(v * 2, tl, tm, l, min(r, tm)),
Max(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}
void Update(int v, int tl, int tr, int pos, int new_val) {
if (tl == tr)
t[v] = new_val;
else {
int tm = (tl + tr) / 2;
if (pos <= tm)
Update(v * 2, tl, tm, pos, new_val);
else
Update(v * 2 + 1, tm + 1, tr, pos, new_val);
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
}
int main() {
int n;
cin >> n;
vector<pair<ll, ll>> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i].first >> a[i].second;
sort(a.begin(), a.end());
vector<int> skip(n);
for (int i = 0; i < n; ++i) {
auto it = lower_bound(a.begin(), a.end(),
make_pair<ll, ll>(a[i].first + a[i].second, -1));
skip[i] = it - a.begin() - 1;
}
Update(1, 0, n, 2, 2);
for (int i = n - 1; i >= 0; --i) {
skip[i] = max(skip[i], Max(1, 0, n, i, skip[i]));
Update(1, 0, n, i, skip[i]);
}
vector<ll> ans(n + 1);
ans[n] = 1;
for (int i = n - 1; i >= 0; --i)
ans[i] = (ans[i + 1] + ans[skip[i] + 1]) % mod;
cout << ans[0] << endl;
return 0;
}
| #include <algorithm>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iostream>
#include <map>
#include <random>
#include <set>
#include <string>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int t[200 * 1001 * 4];
int Max(int v, int tl, int tr, int l, int r) {
if (l > r)
return 0;
if (l == tl && r == tr)
return t[v];
int tm = (tl + tr) / 2;
return max(Max(v * 2, tl, tm, l, min(r, tm)),
Max(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}
void Update(int v, int tl, int tr, int pos, int new_val) {
if (tl == tr)
t[v] = new_val;
else {
int tm = (tl + tr) / 2;
if (pos <= tm)
Update(v * 2, tl, tm, pos, new_val);
else
Update(v * 2 + 1, tm + 1, tr, pos, new_val);
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
}
int main() {
int n;
cin >> n;
vector<pair<ll, ll>> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i].first >> a[i].second;
sort(a.begin(), a.end());
vector<int> skip(n);
for (int i = 0; i < n; ++i) {
auto it = lower_bound(a.begin(), a.end(),
make_pair<ll, ll>(a[i].first + a[i].second, -1));
skip[i] = it - a.begin() - 1;
}
Update(1, 0, n, 2, 2);
for (int i = n - 1; i >= 0; --i) {
skip[i] = max(skip[i], Max(1, 0, n, i, skip[i]));
Update(1, 0, n, i, skip[i]);
}
vector<ll> ans(n + 1);
ans[n] = 1;
for (int i = n - 1; i >= 0; --i)
ans[i] = (ans[i + 1] + ans[skip[i] + 1]) % mod;
cout << ans[0] << endl;
return 0;
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p02758 | C++ | Time Limit Exceeded | // -----------------------------------
// Author : MatsuTaku
// Affiliation: Tokushima University
// Country : Japan
// Date : 07/03/2020
// -----------------------------------
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T> class max_segment_tree {
size_t mpt_;
vector<T> vec_;
public:
max_segment_tree(size_t size) {
mpt_ = 1;
while (mpt_ < size)
mpt_ <<= 1;
vec_.resize(mpt_ + size, 0);
}
void update(size_t index, long long value) {
auto i = mpt_ + index;
vec_[i] = value;
i /= 2;
while (i > 0) {
vec_[i] = max(vec_[i * 2], vec_[i * 2 + 1]);
cerr << "up " << i << "] " << vec_[i] << endl;
i /= 2;
}
}
long long operator[](size_t i) const { return vec_[mpt_ + i]; }
long long range_max(size_t l, size_t r, size_t _l = 0,
size_t _r = numeric_limits<size_t>::max(),
size_t _d = 1) const {
if (_r == numeric_limits<size_t>::max())
_r = mpt_;
if (_r <= l or r <= _l) {
return 0;
} else if (l <= _l and _r <= r) {
return vec_[_d];
} else {
return max(range_max(l, r, _l, (_l + _r) / 2, _d * 2),
range_max(l, r, (_l + _r) / 2, _r, _d * 2 + 1));
}
}
};
constexpr long long MOD = 998244353;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<pair<int, int>> R(N);
for (int i = 0; i < N; i++) {
cin >> R[i].first >> R[i].second;
}
sort(R.begin(), R.end());
vector<long long> dp(N + 1);
dp.back() = 1;
max_segment_tree<long long> sg(N);
for (int i = N - 1; i >= 0; i--) {
int l = i, r = N;
while (l + 1 < r) {
auto c = (l + r) / 2;
if (R[c].first < R[i].first + R[i].second) {
l = c;
} else {
r = c;
}
}
sg.update(i, i);
auto edge = sg.range_max(i, r);
sg.update(i, edge);
dp[i] = dp[i + 1] + dp[edge + 1];
dp[i] %= MOD;
}
cout << dp[0] << endl;
return 0;
}
| // -----------------------------------
// Author : MatsuTaku
// Affiliation: Tokushima University
// Country : Japan
// Date : 07/03/2020
// -----------------------------------
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T> class max_segment_tree {
size_t mpt_;
vector<T> vec_;
public:
max_segment_tree(size_t size) {
mpt_ = 1;
while (mpt_ < size)
mpt_ <<= 1;
vec_.resize(mpt_ + size, 0);
}
void update(size_t index, long long value) {
auto i = mpt_ + index;
vec_[i] = value;
i /= 2;
while (i > 0) {
vec_[i] = max(vec_[i * 2], vec_[i * 2 + 1]);
i /= 2;
}
}
long long operator[](size_t i) const { return vec_[mpt_ + i]; }
long long range_max(size_t l, size_t r, size_t _l = 0,
size_t _r = numeric_limits<size_t>::max(),
size_t _d = 1) const {
if (_r == numeric_limits<size_t>::max())
_r = mpt_;
if (_r <= l or r <= _l) {
return 0;
} else if (l <= _l and _r <= r) {
return vec_[_d];
} else {
return max(range_max(l, r, _l, (_l + _r) / 2, _d * 2),
range_max(l, r, (_l + _r) / 2, _r, _d * 2 + 1));
}
}
};
constexpr long long MOD = 998244353;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<pair<int, int>> R(N);
for (int i = 0; i < N; i++) {
cin >> R[i].first >> R[i].second;
}
sort(R.begin(), R.end());
vector<long long> dp(N + 1);
dp.back() = 1;
max_segment_tree<long long> sg(N);
for (int i = N - 1; i >= 0; i--) {
int l = i, r = N;
while (l + 1 < r) {
auto c = (l + r) / 2;
if (R[c].first < R[i].first + R[i].second) {
l = c;
} else {
r = c;
}
}
sg.update(i, i);
auto edge = sg.range_max(i, r);
sg.update(i, edge);
dp[i] = dp[i + 1] + dp[edge + 1];
dp[i] %= MOD;
}
cout << dp[0] << endl;
return 0;
}
| delete | 29 | 30 | 29 | 29 | TLE | |
p02758 | C++ | Runtime Error | #include <bits/stdc++.h>
#define maxn 100001
#define maxa 2000005
#define MOD 998244353 // 1000000007
#define INF 1000000000000000000
using namespace std;
#define ll long long
#define pii pair<ll, ll>
#define piii pair<pii, ll>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define mem(a, b) memset(a, b, sizeof(a))
#define sort(v) sort(v.begin(), v.end())
#define edge(v, x, y) \
v[x].pb(y); \
v[y].pb(x);
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
}
ll ceil(ll a, ll b) { return (a + b - 1) / b; }
void flaged(bool flag) {
if (flag)
cout << "Yes\n";
else
cout << "No\n";
}
// power and modulo inverse
ll power(ll a, ll b = MOD - 2) {
if (b == 0)
return 1;
ll r = power(a, b / 2);
r = (r * r) % MOD;
if (b % 2 == 1)
r = (r * a) % MOD;
return r;
}
// factorial
ll fact[maxa], finv[maxa];
void calf() {
fact[0] = finv[0] = 1;
for (ll i = 1; i < maxa; i++) {
fact[i] = (fact[i - 1] * i) % MOD;
finv[i] = (finv[i - 1] * power(i)) % MOD;
}
}
// nCr
ll ncr(ll N, ll R) {
if (R > N)
return 0;
return (fact[N] * ((finv[R] * finv[N - R]) % MOD)) % MOD;
}
void solve() {
ll n;
cin >> n;
vector<pii> v, vec;
rep(i, n) {
ll x, y;
cin >> x >> y;
v.pb({x, y});
}
sort(v);
ll dp[n + 1];
mem(dp, 0);
dp[n] = 1;
vec.pb({n, maxa});
repr(i, n) {
while (!vec.empty() && vec.back().sd < v[i].ft + v[i].sd) {
vec.pop_back();
}
ll p = vec.back().ft;
dp[i] = dp[p];
vec.pb({i, v[i].ft});
dp[i] = (dp[i] + dp[i + 1]) % MOD;
}
cout << dp[0];
}
int main() {
fast();
ll t = 1; // cin >> t;
while (t--) {
solve();
}
}
| #include <bits/stdc++.h>
#define maxn 100001
#define maxa 2000005
#define MOD 998244353 // 1000000007
#define INF 1000000000000000000
using namespace std;
#define ll long long
#define pii pair<ll, ll>
#define piii pair<pii, ll>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define mem(a, b) memset(a, b, sizeof(a))
#define sort(v) sort(v.begin(), v.end())
#define edge(v, x, y) \
v[x].pb(y); \
v[y].pb(x);
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
}
ll ceil(ll a, ll b) { return (a + b - 1) / b; }
void flaged(bool flag) {
if (flag)
cout << "Yes\n";
else
cout << "No\n";
}
// power and modulo inverse
ll power(ll a, ll b = MOD - 2) {
if (b == 0)
return 1;
ll r = power(a, b / 2);
r = (r * r) % MOD;
if (b % 2 == 1)
r = (r * a) % MOD;
return r;
}
// factorial
ll fact[maxa], finv[maxa];
void calf() {
fact[0] = finv[0] = 1;
for (ll i = 1; i < maxa; i++) {
fact[i] = (fact[i - 1] * i) % MOD;
finv[i] = (finv[i - 1] * power(i)) % MOD;
}
}
// nCr
ll ncr(ll N, ll R) {
if (R > N)
return 0;
return (fact[N] * ((finv[R] * finv[N - R]) % MOD)) % MOD;
}
void solve() {
ll n;
cin >> n;
vector<pii> v, vec;
rep(i, n) {
ll x, y;
cin >> x >> y;
v.pb({x, y});
}
sort(v);
ll dp[n + 1];
mem(dp, 0);
dp[n] = 1;
vec.pb({n, INF});
repr(i, n) {
while (!vec.empty() && vec.back().sd < v[i].ft + v[i].sd) {
vec.pop_back();
}
ll p = vec.back().ft;
dp[i] = dp[p];
vec.pb({i, v[i].ft});
dp[i] = (dp[i] + dp[i + 1]) % MOD;
}
cout << dp[0];
}
int main() {
fast();
ll t = 1; // cin >> t;
while (t--) {
solve();
}
}
| replace | 73 | 74 | 73 | 74 | 0 | |
p02758 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fo(i, a, b) for (int i = (a); i <= (b); ++i)
#define rv(i, a, b) for (int i = (a); i >= (b); --i)
#define ls (rt << 1)
#define rs (rt << 1 | 1)
using namespace std;
const int M = 220000;
typedef long long ll;
int n, m, k;
char s[M];
int c[M] = {0};
int nx[M];
struct node {
int x, d;
bool operator<(const node &b) { return x < b.x; }
} e[M];
int mx[M] = {0};
void upd(int rt, int l, int r, int p, int val) {
if (l == r) {
mx[rt] = val;
return;
}
int mid = (l + r) >> 1;
if (p <= mid)
upd(ls, l, mid, p, val);
else
upd(rs, mid + 1, r, p, val);
mx[rt] = max(mx[ls], mx[rs]);
}
int query(int rt, int l, int r, int L, int R) {
if (l == L && r == R)
return mx[rt];
int mid = (l + r) >> 1;
if (L > mid)
return query(rs, mid + 1, r, L, R);
if (R <= mid)
return query(ls, l, mid, L, R);
return max(query(ls, l, mid, L, mid), query(rs, mid + 1, r, mid + 1, R));
}
int dp[M] = {0};
const int md = 998244353;
int main() {
cin >> n;
fo(i, 1, n) { cin >> e[i].x >> e[i].d; }
sort(e + 1, e + 1 + n);
nx[n] = n;
upd(1, 1, n, n, n);
rv(i, n - 1, 1) {
int lo = i, hi = n;
int tar = e[i].x + e[i].d - 1;
for (int mid = (lo + hi) >> 1; lo < hi; mid = (lo + hi) >> 1) {
if (e[mid].x < tar)
lo = mid + 1;
else
hi = mid;
}
if (lo > n)
lo = n;
if (e[lo].x > tar)
--lo;
nx[i] = query(1, 1, n, i, lo);
nx[i] = max(nx[i], i);
upd(1, 1, n, i, nx[i]);
}
dp[0] = 1;
fo(i, 1, n) {
dp[nx[i]] = (dp[nx[i]] + dp[i - 1]) % md;
dp[i] = (dp[i] + dp[i - 1]) % md;
}
cout << dp[n] << endl;
return 0;
} | #include <bits/stdc++.h>
#define fo(i, a, b) for (int i = (a); i <= (b); ++i)
#define rv(i, a, b) for (int i = (a); i >= (b); --i)
#define ls (rt << 1)
#define rs (rt << 1 | 1)
using namespace std;
const int M = 220000;
typedef long long ll;
int n, m, k;
char s[M];
int c[M] = {0};
int nx[M];
struct node {
int x, d;
bool operator<(const node &b) { return x < b.x; }
} e[M];
int mx[M << 2] = {0};
void upd(int rt, int l, int r, int p, int val) {
if (l == r) {
mx[rt] = val;
return;
}
int mid = (l + r) >> 1;
if (p <= mid)
upd(ls, l, mid, p, val);
else
upd(rs, mid + 1, r, p, val);
mx[rt] = max(mx[ls], mx[rs]);
}
int query(int rt, int l, int r, int L, int R) {
if (l == L && r == R)
return mx[rt];
int mid = (l + r) >> 1;
if (L > mid)
return query(rs, mid + 1, r, L, R);
if (R <= mid)
return query(ls, l, mid, L, R);
return max(query(ls, l, mid, L, mid), query(rs, mid + 1, r, mid + 1, R));
}
int dp[M] = {0};
const int md = 998244353;
int main() {
cin >> n;
fo(i, 1, n) { cin >> e[i].x >> e[i].d; }
sort(e + 1, e + 1 + n);
nx[n] = n;
upd(1, 1, n, n, n);
rv(i, n - 1, 1) {
int lo = i, hi = n;
int tar = e[i].x + e[i].d - 1;
for (int mid = (lo + hi) >> 1; lo < hi; mid = (lo + hi) >> 1) {
if (e[mid].x < tar)
lo = mid + 1;
else
hi = mid;
}
if (lo > n)
lo = n;
if (e[lo].x > tar)
--lo;
nx[i] = query(1, 1, n, i, lo);
nx[i] = max(nx[i], i);
upd(1, 1, n, i, nx[i]);
}
dp[0] = 1;
fo(i, 1, n) {
dp[nx[i]] = (dp[nx[i]] + dp[i - 1]) % md;
dp[i] = (dp[i] + dp[i - 1]) % md;
}
cout << dp[n] << endl;
return 0;
} | replace | 16 | 17 | 16 | 17 | 0 | |
p02758 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using ll = long long int;
using P = std::pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rag(con) std::begin(con), std::end(con)
constexpr ll mod = 998244353;
ll pow(ll x, ll m) {
ll re = 1, y = 1;
for (int i = 0; i < 60; ++i) {
if (m & y)
re = re * x % mod;
x = x * x % mod;
y *= 2;
}
return re;
}
ll inv(ll x) { return pow(x, mod - 2); }
class mint {
ll num = 0;
public:
mint(ll x = 0) : num(x) {}
mint operator+(const mint &rhs) const { return (num + rhs.num) % mod; }
mint operator*(const mint &rhs) const { return num * rhs.num % mod; }
mint operator-(const mint &rhs) const { return (num - rhs.num + mod) % mod; }
mint operator/(const mint &rhs) const { return num * inv(rhs.num) % mod; }
mint operator+=(const mint &rhs) { return *this = *this + rhs; }
mint operator*=(const mint &rhs) { return *this = *this * rhs; }
mint operator-=(const mint &rhs) { return *this - *this / rhs; }
mint operator/=(const mint &rhs) { return *this = *this / rhs; }
friend std::ostream &operator<<(std::ostream &os, const mint &rhs);
};
std::ostream &operator<<(std::ostream &os, const mint &rhs) {
os << rhs.num;
return os;
}
constexpr int MAX = 2 * 1e5 + 5;
mint dp[MAX];
constexpr int INF = 2 * 1e9 + 1;
int next[MAX];
std::vector<int> xs;
std::vector<P> ps;
int n;
int dfs(int v) {
int m =
std::lower_bound(rag(xs), ps[v].first + ps[v].second) - std::begin(xs);
int res = v + 1;
for (int i = v + 1; i < m; ++i) {
if (res == n)
return next[v] = res;
res = std::max(res, dfs(i));
}
return next[v] = res;
}
int main() {
std::cin >> n;
ps.resize(n);
xs.resize(n + 1);
rep(i, n) {
std::cin >> ps[i].first >> ps[i].second;
xs[i] = ps[i].first;
}
xs[n] = INF;
std::sort(rag(xs));
std::sort(rag(ps));
dp[n] = 1;
for (int i = n - 1; i >= 0; --i) {
dp[i] = dp[dfs(i)] + dp[i + 1];
// std::cerr << dp[i] << std::endl;
}
std::cout << dp[0] << std::endl;
return 0;
} | #include <bits/stdc++.h>
using ll = long long int;
using P = std::pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rag(con) std::begin(con), std::end(con)
constexpr ll mod = 998244353;
ll pow(ll x, ll m) {
ll re = 1, y = 1;
for (int i = 0; i < 60; ++i) {
if (m & y)
re = re * x % mod;
x = x * x % mod;
y *= 2;
}
return re;
}
ll inv(ll x) { return pow(x, mod - 2); }
class mint {
ll num = 0;
public:
mint(ll x = 0) : num(x) {}
mint operator+(const mint &rhs) const { return (num + rhs.num) % mod; }
mint operator*(const mint &rhs) const { return num * rhs.num % mod; }
mint operator-(const mint &rhs) const { return (num - rhs.num + mod) % mod; }
mint operator/(const mint &rhs) const { return num * inv(rhs.num) % mod; }
mint operator+=(const mint &rhs) { return *this = *this + rhs; }
mint operator*=(const mint &rhs) { return *this = *this * rhs; }
mint operator-=(const mint &rhs) { return *this - *this / rhs; }
mint operator/=(const mint &rhs) { return *this = *this / rhs; }
friend std::ostream &operator<<(std::ostream &os, const mint &rhs);
};
std::ostream &operator<<(std::ostream &os, const mint &rhs) {
os << rhs.num;
return os;
}
constexpr int MAX = 2 * 1e5 + 5;
mint dp[MAX];
constexpr int INF = 2 * 1e9 + 1;
int next[MAX];
std::vector<int> xs;
std::vector<P> ps;
int n;
int dfs(int v) {
if (next[v] > 0)
return next[v];
int m =
std::lower_bound(rag(xs), ps[v].first + ps[v].second) - std::begin(xs);
int res = v + 1;
for (int i = v + 1; i < m; ++i) {
if (res == n)
return next[v] = res;
res = std::max(res, dfs(i));
}
return next[v] = res;
}
int main() {
std::cin >> n;
ps.resize(n);
xs.resize(n + 1);
rep(i, n) {
std::cin >> ps[i].first >> ps[i].second;
xs[i] = ps[i].first;
}
xs[n] = INF;
std::sort(rag(xs));
std::sort(rag(ps));
dp[n] = 1;
for (int i = n - 1; i >= 0; --i) {
dp[i] = dp[dfs(i)] + dp[i + 1];
// std::cerr << dp[i] << std::endl;
}
std::cout << dp[0] << std::endl;
return 0;
} | insert | 64 | 64 | 64 | 66 | TLE | |
p02758 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#define mod 998244353LL
#define N (20 + 5)
typedef long long ll;
struct robot {
int l, d;
friend bool operator<(robot a, robot b) {
return a.l < b.l || (a.l == b.l && a.d > b.d);
}
} a[N];
int p[N], fir[N], nxt[N];
ll f[N];
void dfs(int x) {
f[x] = 1LL;
for (int i = fir[x]; i; i = nxt[i]) {
dfs(i);
f[x] *= f[i] + 1;
f[x] %= mod;
}
}
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d%d", &a[i].l, &a[i].d);
std::sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++) {
if (i > 1 && a[i].l == a[i - 1].l)
continue;
int tp = i - 1;
while (tp && a[tp].l + a[tp].d <= a[i].l)
tp = p[tp];
p[i] = tp;
nxt[i] = fir[tp];
fir[tp] = i;
}
dfs(0);
printf("%lld\n", f[0]);
return 0;
} | #include <algorithm>
#include <cstdio>
#define mod 998244353LL
#define N (200000 + 5)
typedef long long ll;
struct robot {
int l, d;
friend bool operator<(robot a, robot b) {
return a.l < b.l || (a.l == b.l && a.d > b.d);
}
} a[N];
int p[N], fir[N], nxt[N];
ll f[N];
void dfs(int x) {
f[x] = 1LL;
for (int i = fir[x]; i; i = nxt[i]) {
dfs(i);
f[x] *= f[i] + 1;
f[x] %= mod;
}
}
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d%d", &a[i].l, &a[i].d);
std::sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++) {
if (i > 1 && a[i].l == a[i - 1].l)
continue;
int tp = i - 1;
while (tp && a[tp].l + a[tp].d <= a[i].l)
tp = p[tp];
p[i] = tp;
nxt[i] = fir[tp];
fir[tp] = i;
}
dfs(0);
printf("%lld\n", f[0]);
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02758 | C++ | Runtime Error | /*
DATE: 2020-03-11 11:08:25
NAME:
PROBLEM: ABC158F
*/
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5;
int x[MAXN + 7];
int d[MAXN + 7];
int xd[MAXN + 7];
int dp[MAXN + 7];
const int MOD = 998244353;
int add(long long x, long long y) { return ((x % MOD) + (y % MOD)) % MOD; }
int main() {
int n;
cin >> n;
{
vector<pair<int, int>> v(n);
for (int i = 0; i < n; i++) {
scanf("%d %d", &v[i].first, &v[i].second);
}
sort(v.begin(), v.end());
for (int i = 0; i < n; i++) {
x[i + 1] = v[i].first;
d[i + 1] = v[i].second;
}
}
{
vector<pair<int, int>> v;
for (int i = n; i >= 1; i--) {
xd[i] = x[i] + d[i] - 1;
while (v.size() > 0 and v.back().first <= xd[i]) {
xd[i] = max(xd[i], v.back().second);
v.pop_back();
}
v.push_back({x[i], xd[i]});
}
}
dp[n + 1] = 1;
for (int i = n; i >= 1; i--) {
dp[i] = dp[i + 1];
int j = upper_bound(x + i + 1, x + n + 1, xd[i]) - x;
dp[i] = add(dp[i], dp[j]);
}
cout << dp[1] << "\n";
return 0;
} | /*
DATE: 2020-03-11 11:08:25
NAME:
PROBLEM: ABC158F
*/
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5;
int x[MAXN + 7];
int d[MAXN + 7];
int xd[MAXN + 7];
int dp[MAXN + 7];
const int MOD = 998244353;
int add(long long x, long long y) { return ((x % MOD) + (y % MOD)) % MOD; }
int main() {
int n;
cin >> n;
{
vector<pair<int, int>> v(n);
for (int i = 0; i < n; i++) {
scanf("%d %d", &v[i].first, &v[i].second);
}
sort(v.begin(), v.end());
for (int i = 0; i < n; i++) {
x[i + 1] = v[i].first;
d[i + 1] = v[i].second;
}
}
{
vector<pair<int, int>> v;
for (int i = n; i >= 1; i--) {
xd[i] = x[i] + d[i] - 1;
while (v.size() > 0 and v.back().first <= xd[i]) {
xd[i] = max(xd[i], v.back().second);
v.pop_back();
}
v.push_back({x[i], xd[i]});
}
}
dp[n + 1] = 1;
for (int i = n; i >= 1; i--) {
dp[i] = dp[i + 1];
int j = upper_bound(x + i + 1, x + n + 1, xd[i]) - x;
dp[i] = add(dp[i], dp[j]);
}
cout << dp[1] << "\n";
return 0;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p02758 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define mkp make_pair
#define pii pair<int, int>
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int mod = 998244353;
ll tree[maxn];
void build(int o, int l, int r) {
tree[o] = 0;
if (l == r) {
return;
} else {
int mid = l + r >> 1;
build(o << 1, l, mid);
build(o << 1 | 1, mid + 1, r);
tree[o] = max(tree[o << 1], tree[o << 1 | 1]);
}
}
ll query(int o, int l, int r, int x, int y) {
if (x <= l && y >= r) {
return tree[o];
}
int mid = l + r >> 1;
ll ans = 0;
if (mid >= x)
ans = max(ans, query(o << 1, l, mid, x, y));
if (mid < y)
ans = max(ans, query(o << 1 | 1, mid + 1, r, x, y));
return ans;
}
void update(int o, int l, int r, int p, ll v) {
if (l == r) {
tree[o] = v;
} else {
int mid = l + r >> 1;
if (mid >= p)
update(o << 1, l, mid, p, v);
else if (mid < p)
update(o << 1 | 1, mid + 1, r, p, v);
tree[o] = max(tree[o << 1], tree[o << 1 | 1]);
}
}
pair<ll, ll> a[maxn];
int L[maxn];
ll b[maxn];
ll dp[maxn];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%lld%lld", &a[i].first, &a[i].second);
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++)
b[i] = a[i].first;
build(1, 1, n);
for (int i = n; i >= 1; i--) {
int tmp = upper_bound(b + 1, b + 1 + n, a[i].first + a[i].second - 1) - b;
if (tmp == i + 1)
L[i] = i;
else
L[i] = query(1, 1, n, i + 1, tmp - 1);
update(1, 1, n, i, L[i]);
}
// for(int i=1;i<=n;i++)cout<<L[i]<<" ";cout<<endl;
dp[n + 1] = 1;
for (int i = n; i >= 1; i--) {
dp[i] = dp[i + 1] + dp[L[i] + 1];
dp[i] %= mod;
}
printf("%lld\n", dp[1]);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define mkp make_pair
#define pii pair<int, int>
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int mod = 998244353;
ll tree[maxn << 2];
void build(int o, int l, int r) {
tree[o] = 0;
if (l == r) {
return;
} else {
int mid = l + r >> 1;
build(o << 1, l, mid);
build(o << 1 | 1, mid + 1, r);
tree[o] = max(tree[o << 1], tree[o << 1 | 1]);
}
}
ll query(int o, int l, int r, int x, int y) {
if (x <= l && y >= r) {
return tree[o];
}
int mid = l + r >> 1;
ll ans = 0;
if (mid >= x)
ans = max(ans, query(o << 1, l, mid, x, y));
if (mid < y)
ans = max(ans, query(o << 1 | 1, mid + 1, r, x, y));
return ans;
}
void update(int o, int l, int r, int p, ll v) {
if (l == r) {
tree[o] = v;
} else {
int mid = l + r >> 1;
if (mid >= p)
update(o << 1, l, mid, p, v);
else if (mid < p)
update(o << 1 | 1, mid + 1, r, p, v);
tree[o] = max(tree[o << 1], tree[o << 1 | 1]);
}
}
pair<ll, ll> a[maxn];
int L[maxn];
ll b[maxn];
ll dp[maxn];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%lld%lld", &a[i].first, &a[i].second);
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++)
b[i] = a[i].first;
build(1, 1, n);
for (int i = n; i >= 1; i--) {
int tmp = upper_bound(b + 1, b + 1 + n, a[i].first + a[i].second - 1) - b;
if (tmp == i + 1)
L[i] = i;
else
L[i] = query(1, 1, n, i + 1, tmp - 1);
update(1, 1, n, i, L[i]);
}
// for(int i=1;i<=n;i++)cout<<L[i]<<" ";cout<<endl;
dp[n + 1] = 1;
for (int i = n; i >= 1; i--) {
dp[i] = dp[i + 1] + dp[L[i] + 1];
dp[i] %= mod;
}
printf("%lld\n", dp[1]);
return 0;
}
| replace | 11 | 12 | 11 | 12 | 0 | |
p02758 | 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 = 998244353;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
const ll MAX_N = 200010;
ll n, dat[2 * MAX_N - 1];
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++) {
dat[i] = -LLINF;
}
}
void update(ll k, ll a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
ll query(ll a, ll b, ll k, ll l, ll r) {
if (r <= a || b <= l)
return -LLINF;
if (a <= l && r <= b)
return dat[k];
else {
ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return max(vl, vr);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll N;
cin >> N;
init(N);
vpl p(N);
REP(i, N) cin >> p[i].FI >> p[i].SE;
sort(p.begin(), p.end());
vll v(N);
REP(i, N) v[i] = p[i].FI;
// bit set
REP(i, N) {
ll index = N - 1 - i;
ll l = index;
ll value = p[index].FI + p[index].SE;
ll r = lower_bound(v.begin(), v.end(), value) - v.begin();
ll max_i = query(l, r, 0, 0, n);
if (max_i == -LLINF)
update(l, l);
else
update(l, max_i);
}
ll dp[N][2];
REP(i, N) REP(j, 2) dp[i][j] = LLINF;
for (ll i = N - 1; i >= 0; i--) {
if (i == N - 1)
dp[i][0] = dp[i][1] = 1;
else {
dp[i][0] = (dp[i + 1][0] + dp[i + 1][1]) % MOD;
ll l = i;
ll value = p[i].FI + p[i].SE;
ll r = lower_bound(v.begin(), v.end(), value) - v.begin();
ll t = query(l, r, 0, 0, n);
if (t == l)
dp[i][1] = dp[i][0];
else
dp[i][1] = dp[t][1];
}
}
ll ans = (dp[0][0] + dp[0][1]) % MOD;
cout << ans << 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 = 998244353;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
const ll MAX_N = 300010;
ll n, dat[2 * MAX_N - 1];
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++) {
dat[i] = -LLINF;
}
}
void update(ll k, ll a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
ll query(ll a, ll b, ll k, ll l, ll r) {
if (r <= a || b <= l)
return -LLINF;
if (a <= l && r <= b)
return dat[k];
else {
ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return max(vl, vr);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll N;
cin >> N;
init(N);
vpl p(N);
REP(i, N) cin >> p[i].FI >> p[i].SE;
sort(p.begin(), p.end());
vll v(N);
REP(i, N) v[i] = p[i].FI;
// bit set
REP(i, N) {
ll index = N - 1 - i;
ll l = index;
ll value = p[index].FI + p[index].SE;
ll r = lower_bound(v.begin(), v.end(), value) - v.begin();
ll max_i = query(l, r, 0, 0, n);
if (max_i == -LLINF)
update(l, l);
else
update(l, max_i);
}
ll dp[N][2];
REP(i, N) REP(j, 2) dp[i][j] = LLINF;
for (ll i = N - 1; i >= 0; i--) {
if (i == N - 1)
dp[i][0] = dp[i][1] = 1;
else {
dp[i][0] = (dp[i + 1][0] + dp[i + 1][1]) % MOD;
ll l = i;
ll value = p[i].FI + p[i].SE;
ll r = lower_bound(v.begin(), v.end(), value) - v.begin();
ll t = query(l, r, 0, 0, n);
if (t == l)
dp[i][1] = dp[i][0];
else
dp[i][1] = dp[t][1];
}
}
ll ans = (dp[0][0] + dp[0][1]) % MOD;
cout << ans << endl;
}
| replace | 37 | 38 | 37 | 38 | 0 | |
p02758 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
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;
}
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
struct SegmentTree {
private:
int n;
vector<int> node;
public:
// 元配列 v をセグメント木で表現する
SegmentTree(vector<int> v) {
// 最下段のノード数は元配列のサイズ以上になる最小の 2 冪 -> これを n とおく
// セグメント木全体で必要なノード数は 2n-1 個である
int sz = v.size();
n = 1;
while (n < sz)
n *= 2;
node.resize(2 * n - 1, -1);
// 最下段に値を入れたあとに、下の段から順番に値を入れる
// 値を入れるには、自分の子の 2 値を参照すれば良い
for (int i = 0; i < sz; i++)
node[i + n - 1] = v[i];
for (int i = n - 2; i >= 0; i--)
node[i] = max(node[2 * i + 1], node[2 * i + 2]);
}
void update(int x, int val) {
// 最下段のノードにアクセスする
x += (n - 1);
// 最下段のノードを更新したら、あとは親に上って更新していく
node[x] = val;
while (x > 0) {
x = (x - 1) / 2;
node[x] = max(node[2 * x + 1], node[2 * x + 2]);
}
}
int getmax(int a, int b, int k = 0, int l = 0, int r = -1) {
// 最初に呼び出されたときの対象区間は [0, n)
if (r < 0)
r = n;
// 要求区間と対象区間が交わらない -> 適当に返す
if (r <= a || b <= l)
return -1;
// 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う
if (a <= l && r <= b)
return node[k];
// 要求区間が対象区間の一部を被覆 -> 子について探索を行う
// 左側の子を vl ・ 右側の子を vr としている
// 新しい対象区間は、現在の対象区間を半分に割ったもの
int vl = getmax(a, b, 2 * k + 1, l, (l + r) / 2);
int vr = getmax(a, b, 2 * k + 2, (l + r) / 2, r);
return max(vl, vr);
}
};
ll dp[2][100100];
const ll MOD = 998244353;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<pair<ll, ll>> R(N);
ll x, d;
rep(i, N) {
cin >> x >> d;
R[i] = make_pair(x, d);
}
R.push_back(make_pair(3 * 1e9, 1LL));
sort(R.begin(), R.end());
vector<int> BOOT(N + 1);
rep(i, N + 1) BOOT[i] = -1;
SegmentTree st(BOOT);
for (int i = N - 1; i >= 0; i--) {
int ind = upper_bound(R.begin(), R.end(),
make_pair(R[i].first + R[i].second, 0LL)) -
R.begin();
st.update(i, i);
int max_val = st.getmax(i, ind);
st.update(i, max_val);
BOOT[i] = max_val;
}
dp[0][N] = 1;
dp[1][N] = 0;
for (int i = N - 1; i >= 0; i--) {
// ここのind取得を工夫する
// int ind = upper_bound(R.begin(), R.end(), make_pair(R[i].first +
// R[i].second, 0LL)) - R.begin();
dp[0][i] = (dp[0][i + 1] + dp[1][i + 1]) % MOD;
dp[1][i] = (dp[0][BOOT[i] + 1] + dp[1][BOOT[i] + 1]) % MOD;
}
cout << (dp[0][0] + dp[1][0]) % MOD << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
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;
}
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
struct SegmentTree {
private:
int n;
vector<int> node;
public:
// 元配列 v をセグメント木で表現する
SegmentTree(vector<int> v) {
// 最下段のノード数は元配列のサイズ以上になる最小の 2 冪 -> これを n とおく
// セグメント木全体で必要なノード数は 2n-1 個である
int sz = v.size();
n = 1;
while (n < sz)
n *= 2;
node.resize(2 * n - 1, -1);
// 最下段に値を入れたあとに、下の段から順番に値を入れる
// 値を入れるには、自分の子の 2 値を参照すれば良い
for (int i = 0; i < sz; i++)
node[i + n - 1] = v[i];
for (int i = n - 2; i >= 0; i--)
node[i] = max(node[2 * i + 1], node[2 * i + 2]);
}
void update(int x, int val) {
// 最下段のノードにアクセスする
x += (n - 1);
// 最下段のノードを更新したら、あとは親に上って更新していく
node[x] = val;
while (x > 0) {
x = (x - 1) / 2;
node[x] = max(node[2 * x + 1], node[2 * x + 2]);
}
}
int getmax(int a, int b, int k = 0, int l = 0, int r = -1) {
// 最初に呼び出されたときの対象区間は [0, n)
if (r < 0)
r = n;
// 要求区間と対象区間が交わらない -> 適当に返す
if (r <= a || b <= l)
return -1;
// 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う
if (a <= l && r <= b)
return node[k];
// 要求区間が対象区間の一部を被覆 -> 子について探索を行う
// 左側の子を vl ・ 右側の子を vr としている
// 新しい対象区間は、現在の対象区間を半分に割ったもの
int vl = getmax(a, b, 2 * k + 1, l, (l + r) / 2);
int vr = getmax(a, b, 2 * k + 2, (l + r) / 2, r);
return max(vl, vr);
}
};
ll dp[2][200100];
const ll MOD = 998244353;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<pair<ll, ll>> R(N);
ll x, d;
rep(i, N) {
cin >> x >> d;
R[i] = make_pair(x, d);
}
R.push_back(make_pair(3 * 1e9, 1LL));
sort(R.begin(), R.end());
vector<int> BOOT(N + 1);
rep(i, N + 1) BOOT[i] = -1;
SegmentTree st(BOOT);
for (int i = N - 1; i >= 0; i--) {
int ind = upper_bound(R.begin(), R.end(),
make_pair(R[i].first + R[i].second, 0LL)) -
R.begin();
st.update(i, i);
int max_val = st.getmax(i, ind);
st.update(i, max_val);
BOOT[i] = max_val;
}
dp[0][N] = 1;
dp[1][N] = 0;
for (int i = N - 1; i >= 0; i--) {
// ここのind取得を工夫する
// int ind = upper_bound(R.begin(), R.end(), make_pair(R[i].first +
// R[i].second, 0LL)) - R.begin();
dp[0][i] = (dp[0][i + 1] + dp[1][i + 1]) % MOD;
dp[1][i] = (dp[0][BOOT[i] + 1] + dp[1][BOOT[i] + 1]) % MOD;
}
cout << (dp[0][0] + dp[1][0]) % MOD << endl;
return 0;
}
| replace | 102 | 103 | 102 | 103 | 0 | |
p02758 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for (int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};
const int mod = 998244353;
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; }
mint fact(int n) {
if (n == 1 || n == 0)
return 1;
mint res = n;
return res * fact(n - 1);
}
struct UnionFind {
vector<int> d;
UnionFind(int n) : d(n, -1) {}
int root(int x) {
if (d[x] < 0)
return x;
return d[x] = root(d[x]);
}
bool unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (d[x] > d[y])
swap(x, y);
d[x] += d[y];
d[y] = x;
return true;
}
bool same(int x, int y) { return root(x) == root(y); }
int size(int x) { return -d[root(x)]; }
};
mint dp[1000000];
bool seen[1000000];
ll num[1000000];
ll n;
mint dfs(ll k) {
if (seen[k])
return dp[k];
seen[k] = true;
if (k == n) {
dp[k] = 1;
return 1;
}
dp[k] = dfs(k + num[k] + 1) + dfs(k + 1);
return dp[k];
}
int main() {
cin >> n;
vector<P> p(n);
rep(i, n) cin >> p[i].first >> p[i].second;
sort(all(p));
UnionFind uf(n);
for (int i = n - 1; i >= 0; i--) {
ll x = p[i].first, d = p[i].second;
ll l = -1, r = n;
while (l + 1 < r) {
ll now = (l + r) / 2;
if (p[now].first < x + d)
l = now;
else
r = now;
}
rep2(j, i + 1, l + 1) { uf.unite(i, j); }
num[i] = uf.size(i) - 1;
}
rep(i, n + 1) {
dp[i] = 0;
seen[i] = false;
}
cout << dfs(0) << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for (int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};
const int mod = 998244353;
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; }
mint fact(int n) {
if (n == 1 || n == 0)
return 1;
mint res = n;
return res * fact(n - 1);
}
struct UnionFind {
vector<int> d;
UnionFind(int n) : d(n, -1) {}
int root(int x) {
if (d[x] < 0)
return x;
return d[x] = root(d[x]);
}
bool unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (d[x] > d[y])
swap(x, y);
d[x] += d[y];
d[y] = x;
return true;
}
bool same(int x, int y) { return root(x) == root(y); }
int size(int x) { return -d[root(x)]; }
};
mint dp[1000000];
bool seen[1000000];
ll num[1000000];
ll n;
mint dfs(ll k) {
if (seen[k])
return dp[k];
seen[k] = true;
if (k == n) {
dp[k] = 1;
return 1;
}
dp[k] = dfs(k + num[k] + 1) + dfs(k + 1);
return dp[k];
}
int main() {
cin >> n;
vector<P> p(n);
rep(i, n) cin >> p[i].first >> p[i].second;
sort(all(p));
UnionFind uf(n);
for (int i = n - 1; i >= 0; i--) {
ll x = p[i].first, d = p[i].second;
ll l = -1, r = n;
while (l + 1 < r) {
ll now = (l + r) / 2;
if (p[now].first < x + d)
l = now;
else
r = now;
}
rep2(j, i + 1, l + 1) {
int nj = j + uf.size(j) - 1;
uf.unite(i, j);
j = nj;
}
num[i] = uf.size(i) - 1;
}
rep(i, n + 1) {
dp[i] = 0;
seen[i] = false;
}
cout << dfs(0) << endl;
} | replace | 116 | 117 | 116 | 121 | TLE | |
p02758 | C++ | Runtime Error | #include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second
using namespace std;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
class DebugStream {
} LOG;
template <typename T> DebugStream &operator<<(DebugStream &s, const T &) {
return s;
}
#ifdef DEBUG
#define LOG clog
#endif
typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 998244353, SQ = 335, lg = 20,
bs = 29;
int T[maxN << 1], n;
int query(int l, int r) {
int ret = 0;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1)
ret = max(ret, T[l++]);
if (r & 1)
ret = max(ret, T[--r]);
}
return ret;
}
void update(int w, int x) {
w += n;
T[w] = x;
while (w > 1) {
w >>= 1;
T[w] = max(T[w << 1], T[w << 1 | 1]);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
cin >> n;
vector<ii> arr(n);
for (int i = 0; i < n; i++)
cin >> arr[i].fi >> arr[i].se;
sort(arr.begin(), arr.end());
vector<int> xs(n), ds(n), reach(n), wys(n + 1);
for (int i = 0; i < n; i++)
xs[i] = arr[i].fi, ds[i] = arr[i].se;
for (int i = n - 1; i >= 0; i--) {
int lm = int(lower_bound(xs.begin(), xs.end(), xs[i] + ds[i]) - xs.begin());
lm = max(lm, query(i + 1, lm));
reach[i] = lm;
update(i, lm);
}
wys[n] = 1;
for (int i = n - 1; i >= 0; i--)
wys[i] = (wys[i + 1] + wys[reach[i]]) % MOD;
cout << wys[0] << '\n';
}
| #include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second
using namespace std;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
class DebugStream {
} LOG;
template <typename T> DebugStream &operator<<(DebugStream &s, const T &) {
return s;
}
#ifdef DEBUG
#define LOG clog
#endif
typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 2e5 + 9, maxV = 1e6 + 9, MOD = 998244353, SQ = 335, lg = 20,
bs = 29;
int T[maxN << 1], n;
int query(int l, int r) {
int ret = 0;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1)
ret = max(ret, T[l++]);
if (r & 1)
ret = max(ret, T[--r]);
}
return ret;
}
void update(int w, int x) {
w += n;
T[w] = x;
while (w > 1) {
w >>= 1;
T[w] = max(T[w << 1], T[w << 1 | 1]);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
cin >> n;
vector<ii> arr(n);
for (int i = 0; i < n; i++)
cin >> arr[i].fi >> arr[i].se;
sort(arr.begin(), arr.end());
vector<int> xs(n), ds(n), reach(n), wys(n + 1);
for (int i = 0; i < n; i++)
xs[i] = arr[i].fi, ds[i] = arr[i].se;
for (int i = n - 1; i >= 0; i--) {
int lm = int(lower_bound(xs.begin(), xs.end(), xs[i] + ds[i]) - xs.begin());
lm = max(lm, query(i + 1, lm));
reach[i] = lm;
update(i, lm);
}
wys[n] = 1;
for (int i = n - 1; i >= 0; i--)
wys[i] = (wys[i + 1] + wys[reach[i]]) % MOD;
cout << wys[0] << '\n';
}
| replace | 37 | 38 | 37 | 38 | 0 | |
p02758 | C++ | Runtime Error | #include <bits/stdc++.h>
#define f(i, n) for (int i = 0; i < n; i++)
#define P pair<int, int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
using namespace std;
int mypow(int a, int b, int c) {
if (b == 0)
return 1;
if (b % 2)
return mypow(a, b - 1, c) * a % c;
int z = mypow(a, b / 2, c);
return z * z % c;
}
P p[200000];
int n, x[200000], z = -1, vz = 0, ans = 1;
void mutu(int a) {
if (a)
x[a] += x[a - 1];
x[a] %= mmod;
for (int i = z + 1; i < n && p[a].first + p[a].second > p[i].first;
i = z + 1) {
z++;
mutu(i);
}
x[z + 1] += x[a];
}
signed main() {
cin >> n;
f(i, n) { cin >> p[i].first >> p[i].second; }
sort(p, p + n);
for (; z < n - 1;) {
if (z + 1)
x[z + 1] = x[z] * -1 + 1;
else
x[z + 1] = 1;
z++;
mutu(z);
int sum = 1;
for (; vz <= z; vz++)
sum += x[vz];
ans *= sum % mmod;
ans %= 998244353;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define f(i, n) for (int i = 0; i < n; i++)
#define P pair<int, int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
using namespace std;
int mypow(int a, int b, int c) {
if (b == 0)
return 1;
if (b % 2)
return mypow(a, b - 1, c) * a % c;
int z = mypow(a, b / 2, c);
return z * z % c;
}
P p[200110];
int n, x[200011], z = -1, vz = 0, ans = 1;
void mutu(int a) {
if (a)
x[a] += x[a - 1];
x[a] %= mmod;
for (int i = z + 1; i < n && p[a].first + p[a].second > p[i].first;
i = z + 1) {
z++;
mutu(i);
}
x[z + 1] += x[a];
}
signed main() {
cin >> n;
f(i, n) { cin >> p[i].first >> p[i].second; }
sort(p, p + n);
for (; z < n - 1;) {
if (z + 1)
x[z + 1] = x[z] * -1 + 1;
else
x[z + 1] = 1;
z++;
mutu(z);
int sum = 1;
for (; vz <= z; vz++)
sum += x[vz];
ans *= sum % mmod;
ans %= 998244353;
}
cout << ans << endl;
} | replace | 18 | 20 | 18 | 20 | 0 | |
p02758 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long LL;
const int SIZEN = 200010;
const int mod = 998244353;
struct Robot {
int x, d;
} r[SIZEN];
int R[SIZEN];
int N;
int tmp[SIZEN];
int cnt = 0;
int mx[SIZEN] = {0};
void change(int rt, int l, int r, int x, int y) {
if (l == r) {
mx[rt] = y;
return;
}
int mid = (l + r) >> 1;
if (x <= mid)
change(rt << 1, l, mid, x, y);
else
change(rt << 1 | 1, mid + 1, r, x, y);
mx[rt] = max(mx[rt << 1], mx[rt << 1 | 1]);
}
int query(int rt, int l, int r, int x, int y) {
if (x <= l && y >= r) {
return mx[rt];
}
int mid = (l + r) >> 1;
if (y <= mid)
return query(rt << 1, l, mid, x, y);
if (x > mid)
return query(rt << 1 | 1, mid + 1, r, x, y);
return max(query(rt << 1, l, mid, x, y),
query(rt << 1 | 1, mid + 1, r, x, y));
}
bool cmp(const Robot &A, const Robot &B) { return A.x < B.x; }
int f[SIZEN];
int main() {
scanf("%d", &N);
for (int i = 1; i <= N; i++)
scanf("%d%d", &r[i].x, &r[i].d), tmp[++cnt] = r[i].x;
sort(tmp + 1, tmp + 1 + cnt);
sort(r + 1, r + 1 + N, cmp);
cnt = unique(tmp + 1, tmp + 1 + cnt) - tmp - 1;
change(1, 1, N, lower_bound(tmp + 1, tmp + 1 + cnt, r[N].x) - tmp, N);
R[N] = N;
for (int i = N - 1; i >= 1; i--) {
int tr = lower_bound(tmp + 1, tmp + 1 + cnt, r[i].x + r[i].d) - tmp - 1;
int tl = lower_bound(tmp + 1, tmp + 1 + cnt, r[i].x) - tmp;
if (tl > tr) {
R[i] = tr;
} else {
R[i] = max(tr, query(1, 1, N, tl, tr));
}
change(1, 1, N, tl, R[i]);
}
// for(int i = 1;i <= N;i++)printf("%d ",R[i]);printf("\n");
f[N + 1] = 1;
for (int i = N; i >= 1; i--) {
f[i] = (f[i + 1] + f[R[i] + 1]) % mod;
}
printf("%d\n", f[1]);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long LL;
const int SIZEN = 200010;
const int mod = 998244353;
struct Robot {
int x, d;
} r[SIZEN];
int R[SIZEN];
int N;
int tmp[SIZEN];
int cnt = 0;
int mx[SIZEN << 2] = {0};
void change(int rt, int l, int r, int x, int y) {
if (l == r) {
mx[rt] = y;
return;
}
int mid = (l + r) >> 1;
if (x <= mid)
change(rt << 1, l, mid, x, y);
else
change(rt << 1 | 1, mid + 1, r, x, y);
mx[rt] = max(mx[rt << 1], mx[rt << 1 | 1]);
}
int query(int rt, int l, int r, int x, int y) {
if (x <= l && y >= r) {
return mx[rt];
}
int mid = (l + r) >> 1;
if (y <= mid)
return query(rt << 1, l, mid, x, y);
if (x > mid)
return query(rt << 1 | 1, mid + 1, r, x, y);
return max(query(rt << 1, l, mid, x, y),
query(rt << 1 | 1, mid + 1, r, x, y));
}
bool cmp(const Robot &A, const Robot &B) { return A.x < B.x; }
int f[SIZEN];
int main() {
scanf("%d", &N);
for (int i = 1; i <= N; i++)
scanf("%d%d", &r[i].x, &r[i].d), tmp[++cnt] = r[i].x;
sort(tmp + 1, tmp + 1 + cnt);
sort(r + 1, r + 1 + N, cmp);
cnt = unique(tmp + 1, tmp + 1 + cnt) - tmp - 1;
change(1, 1, N, lower_bound(tmp + 1, tmp + 1 + cnt, r[N].x) - tmp, N);
R[N] = N;
for (int i = N - 1; i >= 1; i--) {
int tr = lower_bound(tmp + 1, tmp + 1 + cnt, r[i].x + r[i].d) - tmp - 1;
int tl = lower_bound(tmp + 1, tmp + 1 + cnt, r[i].x) - tmp;
if (tl > tr) {
R[i] = tr;
} else {
R[i] = max(tr, query(1, 1, N, tl, tr));
}
change(1, 1, N, tl, R[i]);
}
// for(int i = 1;i <= N;i++)printf("%d ",R[i]);printf("\n");
f[N + 1] = 1;
for (int i = N; i >= 1; i--) {
f[i] = (f[i + 1] + f[R[i] + 1]) % mod;
}
printf("%d\n", f[1]);
return 0;
} | replace | 17 | 18 | 17 | 18 | 0 | |
p02758 | C++ | Runtime Error | #include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sys/time.h>
#include <unordered_map>
#include <vector>
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 998244353;
#define MAX_N 210000
int dat[2 * MAX_N - 1];
template <typename T> class SegTree {
public:
// セグメント木を持つグローバル変数
int n;
void init(int n_, T init_num) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++) {
dat[i] = init_num;
}
}
// k番目の値(0-indexed)をaに変更
void update(int k, T a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
// [a, b)の最小値を求める。
// kは節点の番号、l, rはその節点が[l, r)に対応づいていることを表す。
// query(a, b, 0, 0, n)で外からは呼び出す。
private:
T query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l) {
return 0;
}
if (a <= l && r <= b) {
return dat[k];
} else {
ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return max(vl, vr);
}
}
// [a, b)の最小値を求める。
public:
T query(int a, int b) { return query(a, b, 0, 0, this->n); }
};
inline ll take_mod(ll a) { return (a % mod + mod) % mod; }
inline ll add(ll a, ll b) { return take_mod(a + b); }
inline ll sub(ll a, ll b) { return take_mod(a - b); }
inline ll mul(ll a, ll b) { return take_mod(a * b); }
inline ll pow(ll x, ll n) {
ll res = 1LL;
while (n > 0) {
if (n & 1)
res = mul(res, x);
x = mul(x, x);
n >>= 1;
}
return res;
}
ll mod_inv(ll x) { return pow(x, mod - 2); }
vector<ll> dp(210000, 0);
vector<int> next1(210000, -1);
vector<int> next2(210000, -1);
int main() {
int n;
cin >> n;
vector<P> x2;
for (int i = 0; i < n; i++) {
ll xx, dd;
cin >> xx >> dd;
x2.emplace_back(P(xx, dd));
}
sort(x2.begin(), x2.end());
vector<ll> x(n, 0), d(n, 0);
for (int i = 0; i < n; i++) {
x[i] = x2[i].fs;
d[i] = x2[i].sc;
}
SegTree<int> st;
st.init(n, -1);
for (int i = 0; i < n; i++) {
st.update(i, i + 1);
}
for (int i = n - 1; i >= 0; i--) {
int next_ind = lower_bound(x.begin(), x.end(), x[i] + d[i]) - x.begin();
if (i + 1 == next_ind) {
next1[i] = i + 1;
} else {
next1[i] = st.query(i + 1, next_ind);
}
st.update(i, next1[i]);
}
dp[0] = 1;
for (int i = 0; i < n; i++) {
// 選ぶ場合
int nex = st.query(i, i + 1);
dp[nex] = add(dp[nex], dp[i]);
// 選ばない場合
dp[i + 1] = add(dp[i + 1], dp[i]);
}
cout << dp[n] << endl;
return 0;
}
| #include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sys/time.h>
#include <unordered_map>
#include <vector>
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 998244353;
#define MAX_N 410000
int dat[2 * MAX_N - 1];
template <typename T> class SegTree {
public:
// セグメント木を持つグローバル変数
int n;
void init(int n_, T init_num) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++) {
dat[i] = init_num;
}
}
// k番目の値(0-indexed)をaに変更
void update(int k, T a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
// [a, b)の最小値を求める。
// kは節点の番号、l, rはその節点が[l, r)に対応づいていることを表す。
// query(a, b, 0, 0, n)で外からは呼び出す。
private:
T query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l) {
return 0;
}
if (a <= l && r <= b) {
return dat[k];
} else {
ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return max(vl, vr);
}
}
// [a, b)の最小値を求める。
public:
T query(int a, int b) { return query(a, b, 0, 0, this->n); }
};
inline ll take_mod(ll a) { return (a % mod + mod) % mod; }
inline ll add(ll a, ll b) { return take_mod(a + b); }
inline ll sub(ll a, ll b) { return take_mod(a - b); }
inline ll mul(ll a, ll b) { return take_mod(a * b); }
inline ll pow(ll x, ll n) {
ll res = 1LL;
while (n > 0) {
if (n & 1)
res = mul(res, x);
x = mul(x, x);
n >>= 1;
}
return res;
}
ll mod_inv(ll x) { return pow(x, mod - 2); }
vector<ll> dp(210000, 0);
vector<int> next1(210000, -1);
vector<int> next2(210000, -1);
int main() {
int n;
cin >> n;
vector<P> x2;
for (int i = 0; i < n; i++) {
ll xx, dd;
cin >> xx >> dd;
x2.emplace_back(P(xx, dd));
}
sort(x2.begin(), x2.end());
vector<ll> x(n, 0), d(n, 0);
for (int i = 0; i < n; i++) {
x[i] = x2[i].fs;
d[i] = x2[i].sc;
}
SegTree<int> st;
st.init(n, -1);
for (int i = 0; i < n; i++) {
st.update(i, i + 1);
}
for (int i = n - 1; i >= 0; i--) {
int next_ind = lower_bound(x.begin(), x.end(), x[i] + d[i]) - x.begin();
if (i + 1 == next_ind) {
next1[i] = i + 1;
} else {
next1[i] = st.query(i + 1, next_ind);
}
st.update(i, next1[i]);
}
dp[0] = 1;
for (int i = 0; i < n; i++) {
// 選ぶ場合
int nex = st.query(i, i + 1);
dp[nex] = add(dp[nex], dp[i]);
// 選ばない場合
dp[i + 1] = add(dp[i + 1], dp[i]);
}
cout << dp[n] << endl;
return 0;
}
| replace | 31 | 32 | 31 | 32 | 0 | |
p02758 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define mod 998244353
pair<int, int> arr[100005];
int dp[100005];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d %d", &arr[i].first, &arr[i].second);
sort(arr, arr + n);
dp[n] = 1;
stack<pair<int, int>> s;
s.push({2e9, n});
for (int i = n - 1; i >= 0; i--) {
while (arr[i].first + arr[i].second > s.top().first)
s.pop();
dp[i] = (dp[i + 1] + dp[s.top().second]) % mod;
s.push({arr[i].first, i});
}
printf("%d", dp[0]);
} | #include <bits/stdc++.h>
using namespace std;
#define mod 998244353
pair<int, int> arr[200005];
int dp[200005];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d %d", &arr[i].first, &arr[i].second);
sort(arr, arr + n);
dp[n] = 1;
stack<pair<int, int>> s;
s.push({2e9, n});
for (int i = n - 1; i >= 0; i--) {
while (arr[i].first + arr[i].second > s.top().first)
s.pop();
dp[i] = (dp[i + 1] + dp[s.top().second]) % mod;
s.push({arr[i].first, i});
}
printf("%d", dp[0]);
} | replace | 3 | 5 | 3 | 5 | 0 | |
p02758 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define repr(i, a, b) for (ll i = a; i >= b; i--)
const long long mod = 998244353;
// Range_Minimum_Query
//(0-indexed)
const int max_n = 1 << 17;
const long long int_max = 1e9 + 7;
int nn;
long long dat[2 * max_n - 1];
void rmq_init(int initn) {
nn = 1;
while (nn < initn)
nn *= 2;
for (int i = 0; i < 2 * nn - 1; i++)
dat[i] = int_max;
}
// k番目の値(0-indexed)をaに変更
void update(int k, long long a) {
k += nn - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
//[a,b)の最小値を求める
// query(a, b, 0, 0, n)で呼ぶ
long long query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return int_max;
if (a <= l && r <= b)
return dat[k];
else {
long long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
long long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
int main() {
// your code goes here
ll n, x, d, dp[200005] = {0}, sw[200005] = {0}, swm[200005] = {0}, pb = n - 1;
vector<pair<ll, ll>> v;
vector<ll> zh;
cin >> n;
rmq_init(n);
rep(i, 0, n - 1) {
cin >> x >> d;
v.push_back({x, d});
zh.push_back(x);
}
sort(v.begin(), v.end());
sort(zh.begin(), zh.end());
rep(i, 0, n - 1) {
auto it = lower_bound(zh.begin(), zh.end(), v[i].first + v[i].second);
it--;
sw[i] = it - zh.begin();
update(i, -sw[i]);
}
swm[n - 1] = n - 1;
repr(i, n - 2, 0) {
swm[i] = -query(i, sw[i] + 1, 0, 0, nn);
update(i, -swm[i]);
}
dp[n] = 1;
dp[n - 1] = 2;
repr(i, n - 2, 0) { dp[i] = (dp[i + 1] + dp[swm[i] + 1]) % mod; }
cout << dp[0] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define repr(i, a, b) for (ll i = a; i >= b; i--)
const long long mod = 998244353;
// Range_Minimum_Query
//(0-indexed)
const int max_n = 300000;
const long long int_max = 1e9 + 7;
int nn;
long long dat[2 * max_n - 1];
void rmq_init(int initn) {
nn = 1;
while (nn < initn)
nn *= 2;
for (int i = 0; i < 2 * nn - 1; i++)
dat[i] = int_max;
}
// k番目の値(0-indexed)をaに変更
void update(int k, long long a) {
k += nn - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
//[a,b)の最小値を求める
// query(a, b, 0, 0, n)で呼ぶ
long long query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return int_max;
if (a <= l && r <= b)
return dat[k];
else {
long long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
long long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
int main() {
// your code goes here
ll n, x, d, dp[200005] = {0}, sw[200005] = {0}, swm[200005] = {0}, pb = n - 1;
vector<pair<ll, ll>> v;
vector<ll> zh;
cin >> n;
rmq_init(n);
rep(i, 0, n - 1) {
cin >> x >> d;
v.push_back({x, d});
zh.push_back(x);
}
sort(v.begin(), v.end());
sort(zh.begin(), zh.end());
rep(i, 0, n - 1) {
auto it = lower_bound(zh.begin(), zh.end(), v[i].first + v[i].second);
it--;
sw[i] = it - zh.begin();
update(i, -sw[i]);
}
swm[n - 1] = n - 1;
repr(i, n - 2, 0) {
swm[i] = -query(i, sw[i] + 1, 0, 0, nn);
update(i, -swm[i]);
}
dp[n] = 1;
dp[n - 1] = 2;
repr(i, n - 2, 0) { dp[i] = (dp[i + 1] + dp[swm[i] + 1]) % mod; }
cout << dp[0] << endl;
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02758 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i <= n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll MOD = 998244353;
int B = 320;
// バケット i は [i*B, (i+1)*B) の記録を持つ
// lazy[i] := バケットi の遅延を記録する
// 遅延が-1 ... 制約よりそんなことは発生しないことを利用して,
// これを遅延の単位元とできる i.e. lazy[i] == -1 def
// 消化時に何も伝播させないという遅延を与えるとみなす mi[i] := パケットi
// の最小値
vector<int> lazy(B, -1), mi(B, (1LL << 31) - 1), a(2e5 + 10);
// a_s, ..., a_t を x に変更する
void update(int s, int t, int x) {
// s の属するバケット, t の属するバケット
int st = s / B, gt = t / B;
// st や gt に遅延が存在するとき更新前に消化しておく
// 遅延はパケットごとに考えるから,
// 遅延が存在⇔パケット内は全て等しい値で更新されている したがって mi[st] =
// lazy[st] が成立
// 区間に被覆されるパケットについてはこのあと新しい値へ更新されるので消化しなくてOK
if (lazy[st] != -1) {
for (int i = st * B; i < (st + 1) * B; i++)
a[i] = lazy[st];
mi[st] = lazy[st];
lazy[st] = -1;
}
if (lazy[gt] != -1) {
for (int i = gt * B; i < (gt + 1) * B; i++)
a[i] = lazy[gt];
mi[gt] = lazy[gt];
lazy[gt] = -1;
}
//... || ... s ... t ... || ...
// 更新が同一パケット内で済むなら直接更新しても間に合う
if (st == gt) {
for (int i = s; i <= t; i++)
a[i] = x;
mi[st] = INT_MAX;
for (int i = st * B; i < (st + 1) * B; i++)
mi[st] = min(mi[st], a[i]);
}
//... s ... || (被覆されるパケット) || ... t ...
// a の更新に伴う mi
// の更新が区間が属する全てのパケットに対し行われていることが重要
else {
// 端が属するパケット内は直接更新
for (int i = s; i < (st + 1) * B; i++)
a[i] = x;
mi[st] = INT_MAX;
for (int i = st * B; i < (st + 1) * B; i++)
mi[st] = min(mi[st], a[i]);
for (int i = gt * B; i <= t; i++)
a[i] = x;
mi[gt] = INT_MAX;
for (int i = gt * B; i < (gt + 1) * B; i++)
mi[gt] = min(mi[gt], a[i]);
// 区間に被覆されるパケットについては更新を遅延に残す
// 区間内すべて更新されるのでパケットの最小値は x になる
for (int i = st + 1; i < gt; i++) {
lazy[i] = x;
mi[i] = x;
}
}
}
int find(int s, int t) {
int ret = INT_MAX;
int st = s / B, gt = t / B;
// st や gt に遅延が存在するとき
// update() と同様に遅延を先に処理する
if (lazy[st] != -1) {
for (int i = st * B; i < (st + 1) * B; i++)
a[i] = lazy[st];
mi[st] = lazy[st];
lazy[st] = -1;
}
if (lazy[gt] != -1) {
for (int i = gt * B; i < (gt + 1) * B; i++)
a[i] = lazy[gt];
mi[gt] = lazy[gt];
lazy[gt] = -1;
}
//... || ... s ... t ... || ...
// 直接計算
if (st == gt) {
for (int i = s; i <= t; i++)
ret = min(ret, a[i]);
}
//... s ... || (被覆されるパケット) || ... t ...
else {
// 端が属するパケット内は直接更新
for (int i = s; i < (st + 1) * B; i++)
ret = min(ret, a[i]);
for (int i = gt * B; i <= t; i++)
ret = min(ret, a[i]);
// 被覆されるパケットはパケット単位で調査する
for (int i = st + 1; i < gt; i++) {
// 遅延が存在しない場合, update() によって mi[i] に最小値が保持されている
if (lazy[i] == -1)
ret = min(ret, mi[i]);
// 遅延が存在するならばパケット内は全て等しい値 lazy[i] になっている
else
ret = min(ret, lazy[i]);
}
}
return ret;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
ll x, l;
vector<P> p(n);
vll pos(n);
REP(i, n) {
cin >> x >> l;
p[i] = {x, l};
pos[i] = x;
}
VSORT(p);
VSORT(pos);
vll mem(n + 1);
mem[n] = 1;
REP(i, n) { a[i] = -(p[i].first + p[i].second); }
vll right(n + 1);
right[n] = n;
REPR(i, n) {
ll lb = lower_bound(ALL(pos), p[i].first + p[i].second) -
pos.begin(); // 直接届かない最小の位置
ll ub = lb - 1; // 届く最大の位置
ll reach = -find(i, ub); // max(p[i].first + p[i].second) in [i, ub]
ll unboot = lower_bound(ALL(pos), reach) - pos.begin();
update(i, ub, -(p[unboot - 1].first + p[unboot - 1].second));
mem[i] = mem[i + 1] + mem[unboot];
mem[i] %= MOD;
}
cout << mem[0] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i <= n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll MOD = 998244353;
int B = 450;
// バケット i は [i*B, (i+1)*B) の記録を持つ
// lazy[i] := バケットi の遅延を記録する
// 遅延が-1 ... 制約よりそんなことは発生しないことを利用して,
// これを遅延の単位元とできる i.e. lazy[i] == -1 def
// 消化時に何も伝播させないという遅延を与えるとみなす mi[i] := パケットi
// の最小値
vector<int> lazy(B, -1), mi(B, (1LL << 31) - 1), a(2e5 + 10);
// a_s, ..., a_t を x に変更する
void update(int s, int t, int x) {
// s の属するバケット, t の属するバケット
int st = s / B, gt = t / B;
// st や gt に遅延が存在するとき更新前に消化しておく
// 遅延はパケットごとに考えるから,
// 遅延が存在⇔パケット内は全て等しい値で更新されている したがって mi[st] =
// lazy[st] が成立
// 区間に被覆されるパケットについてはこのあと新しい値へ更新されるので消化しなくてOK
if (lazy[st] != -1) {
for (int i = st * B; i < (st + 1) * B; i++)
a[i] = lazy[st];
mi[st] = lazy[st];
lazy[st] = -1;
}
if (lazy[gt] != -1) {
for (int i = gt * B; i < (gt + 1) * B; i++)
a[i] = lazy[gt];
mi[gt] = lazy[gt];
lazy[gt] = -1;
}
//... || ... s ... t ... || ...
// 更新が同一パケット内で済むなら直接更新しても間に合う
if (st == gt) {
for (int i = s; i <= t; i++)
a[i] = x;
mi[st] = INT_MAX;
for (int i = st * B; i < (st + 1) * B; i++)
mi[st] = min(mi[st], a[i]);
}
//... s ... || (被覆されるパケット) || ... t ...
// a の更新に伴う mi
// の更新が区間が属する全てのパケットに対し行われていることが重要
else {
// 端が属するパケット内は直接更新
for (int i = s; i < (st + 1) * B; i++)
a[i] = x;
mi[st] = INT_MAX;
for (int i = st * B; i < (st + 1) * B; i++)
mi[st] = min(mi[st], a[i]);
for (int i = gt * B; i <= t; i++)
a[i] = x;
mi[gt] = INT_MAX;
for (int i = gt * B; i < (gt + 1) * B; i++)
mi[gt] = min(mi[gt], a[i]);
// 区間に被覆されるパケットについては更新を遅延に残す
// 区間内すべて更新されるのでパケットの最小値は x になる
for (int i = st + 1; i < gt; i++) {
lazy[i] = x;
mi[i] = x;
}
}
}
int find(int s, int t) {
int ret = INT_MAX;
int st = s / B, gt = t / B;
// st や gt に遅延が存在するとき
// update() と同様に遅延を先に処理する
if (lazy[st] != -1) {
for (int i = st * B; i < (st + 1) * B; i++)
a[i] = lazy[st];
mi[st] = lazy[st];
lazy[st] = -1;
}
if (lazy[gt] != -1) {
for (int i = gt * B; i < (gt + 1) * B; i++)
a[i] = lazy[gt];
mi[gt] = lazy[gt];
lazy[gt] = -1;
}
//... || ... s ... t ... || ...
// 直接計算
if (st == gt) {
for (int i = s; i <= t; i++)
ret = min(ret, a[i]);
}
//... s ... || (被覆されるパケット) || ... t ...
else {
// 端が属するパケット内は直接更新
for (int i = s; i < (st + 1) * B; i++)
ret = min(ret, a[i]);
for (int i = gt * B; i <= t; i++)
ret = min(ret, a[i]);
// 被覆されるパケットはパケット単位で調査する
for (int i = st + 1; i < gt; i++) {
// 遅延が存在しない場合, update() によって mi[i] に最小値が保持されている
if (lazy[i] == -1)
ret = min(ret, mi[i]);
// 遅延が存在するならばパケット内は全て等しい値 lazy[i] になっている
else
ret = min(ret, lazy[i]);
}
}
return ret;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
ll x, l;
vector<P> p(n);
vll pos(n);
REP(i, n) {
cin >> x >> l;
p[i] = {x, l};
pos[i] = x;
}
VSORT(p);
VSORT(pos);
vll mem(n + 1);
mem[n] = 1;
REP(i, n) { a[i] = -(p[i].first + p[i].second); }
vll right(n + 1);
right[n] = n;
REPR(i, n) {
ll lb = lower_bound(ALL(pos), p[i].first + p[i].second) -
pos.begin(); // 直接届かない最小の位置
ll ub = lb - 1; // 届く最大の位置
ll reach = -find(i, ub); // max(p[i].first + p[i].second) in [i, ub]
ll unboot = lower_bound(ALL(pos), reach) - pos.begin();
update(i, ub, -(p[unboot - 1].first + p[unboot - 1].second));
mem[i] = mem[i + 1] + mem[unboot];
mem[i] %= MOD;
}
cout << mem[0] << endl;
return 0;
} | replace | 18 | 19 | 18 | 19 | 0 | |
p02758 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 998244353;
typedef pair<int, int> P;
int dp[123456]; // dp[i]:v[i+1]に干渉しv[i+2]以降に干渉しない通り
int a[123456]; // a[i]:v[i]を起動した時に干渉する右端
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
template <typename T> struct SegmentTree {
using F = function<T(T, T)>;
int n; // セグ木の幅
F f; // モノイドの作用
T ti; // 初期値
vector<T> dat; // セグ木で使う配列 一番上に使われるのがdat[1]
// 一番下の段の左端がdat[n]
SegmentTree(){};
SegmentTree(F f, T ti) : f(f), ti(ti) {} // fがモノイドとしての作用、tiが単位元
SegmentTree(F f, T ti, int n_) : f(f), ti(ti) {
n = 1;
while (n < n_)
n <<= 1;
dat.assign(n << 1, ti);
}
SegmentTree(F f, T ti, const vector<T> &v) : f(f), ti(ti) {
int n_ = v.size();
n = 1;
while (n < n_)
n <<= 1;
dat.assign(n << 1, ti);
for (int i = 0; i < n_; i++)
dat[n + i] = v[i];
for (int i = n - 1; i; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
T get(int x) { return dat[x + n]; }
void init(int n_) { // ただの初期化
n = 1;
while (n < n_)
n <<= 1; // nが実際にとる2べきの幅
dat.assign(n << 1, ti); // dat配列は幅の2倍あってその全てにtiを代入
}
void build(const vector<T> &v) { // vector vに合わせた初期化
int n_ = v.size();
init(n_);
for (int i = 0; i < n_; i++)
dat[n + i] = v[i]; // v[i]を一番子の所に代入
for (int i = n - 1; i; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); // iの子供は2*i、2*i+1
}
void set_val(int k, T x) { // (0-indexedで)kにxを代入
dat[k += n] = x;
while (k >>= 1) // kがどんどん自分の親になっていく、0になったらおしまい
dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
}
T query(int a, int b) { //[a,b)の範囲のモノイドの作用を返す
T vl = ti, vr = ti;
for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
if (l & 1)
vl = f(vl, dat[l++]); // 左端を使いたくなるのはブロックが奇数の時
if (r & 1)
vr = f(dat[--r], vr); // 右端〃偶数の時(開区間なのでr:奇数で反応)
}
return f(vl, vr);
}
template <typename C>
int find(int st, C &check, T &acc, int k, int l,
int r) { // dat[k]:[l,r)の間にいるenを返す
// 下のfind用なので先にそっち読むべき
// accはst~lとかで確定している値
if (l + 1 == r) { // 答えがちゃんと存在するならこのlが答え
acc = f(acc, dat[k]);
return check(acc) ? k - n : -1; // 入るならk-n(==l)を、入らないなら-1を返す
}
int m = (l + r) >> 1; // にぶたんのそれ
if (m <= st)
return find(st, check, acc, (k << 1) | 1, m,
r); // mがstより後ろなら明らかにl=m;
if (st <= l &&
!check(
f(acc,
dat[k]))) { // 今見てるk全部でもダメ(mだと足りないのでl=mにする)
acc = f(acc, dat[k]); // kは全部accに加えた上で-1を返す
return -1;
}
int vl = find(st, check, acc, (k << 1) | 0, l,
m); // まず[l,m)の中にenがいるか探す
if (~vl)
return vl; // いたならそれを返す(if(~vl)は-1以外にのみ反応する)
return find(st, check, acc, (k << 1) | 1, m,
r); // いなかったら[m,r)の中にenがいるのでそれを返す
// acc=f(acc,dat[k]);がここで効いてる
}
template <typename C> int find(int st, C &check) {
// check(f(dat[st]~dat[en-1]))=false,check(f(dat[st]~dat[en]))=trueとなるenを返す
T acc = ti;
return find(st, check, acc, 1, 0, n);
}
};
signed main() {
dp[0] = 1;
int n;
cin >> n;
vector<P> v(n);
for (int i = 0; i < n; i++) {
int x, d;
cin >> x >> d;
v[i] = P(x, d);
}
sort(v.begin(), v.end());
int ans = 0;
/*
for(int i=0;i<n;i++){
int now=i,right=v[i].first+v[i].second;
while(now<n&&right>v[now+1].first){
now++;
chmax(right,v[now].first+v[now].second);
}
a[i]=now;
}
*/
auto f = [](int a, int b) { return max(a, b); };
SegmentTree<int> seg(f, -1);
seg.init(n + 5);
for (int i = 0; i < n; i++)
seg.set_val(i, i);
for (int i = n - 2; i >= 0; i--) {
int l = i, r = n;
while (r - l > 1) {
int mid = (r + l) >> 1;
if (v[mid].first >= v[i].first + v[i].second)
r = mid;
else
l = mid;
}
seg.set_val(i, seg.query(i, r));
}
for (int i = 0; i < n; i++) {
dp[seg.get(i) + 1] += dp[i];
dp[seg.get(i) + 1] %= MOD;
dp[i + 1] += dp[i];
dp[i + 1] %= MOD;
}
cout << (dp[n] + dp[n + 1]) % MOD << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 998244353;
typedef pair<int, int> P;
int dp[223456]; // dp[i]:v[i+1]に干渉しv[i+2]以降に干渉しない通り
int a[223456]; // a[i]:v[i]を起動した時に干渉する右端
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
template <typename T> struct SegmentTree {
using F = function<T(T, T)>;
int n; // セグ木の幅
F f; // モノイドの作用
T ti; // 初期値
vector<T> dat; // セグ木で使う配列 一番上に使われるのがdat[1]
// 一番下の段の左端がdat[n]
SegmentTree(){};
SegmentTree(F f, T ti) : f(f), ti(ti) {} // fがモノイドとしての作用、tiが単位元
SegmentTree(F f, T ti, int n_) : f(f), ti(ti) {
n = 1;
while (n < n_)
n <<= 1;
dat.assign(n << 1, ti);
}
SegmentTree(F f, T ti, const vector<T> &v) : f(f), ti(ti) {
int n_ = v.size();
n = 1;
while (n < n_)
n <<= 1;
dat.assign(n << 1, ti);
for (int i = 0; i < n_; i++)
dat[n + i] = v[i];
for (int i = n - 1; i; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
T get(int x) { return dat[x + n]; }
void init(int n_) { // ただの初期化
n = 1;
while (n < n_)
n <<= 1; // nが実際にとる2べきの幅
dat.assign(n << 1, ti); // dat配列は幅の2倍あってその全てにtiを代入
}
void build(const vector<T> &v) { // vector vに合わせた初期化
int n_ = v.size();
init(n_);
for (int i = 0; i < n_; i++)
dat[n + i] = v[i]; // v[i]を一番子の所に代入
for (int i = n - 1; i; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); // iの子供は2*i、2*i+1
}
void set_val(int k, T x) { // (0-indexedで)kにxを代入
dat[k += n] = x;
while (k >>= 1) // kがどんどん自分の親になっていく、0になったらおしまい
dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
}
T query(int a, int b) { //[a,b)の範囲のモノイドの作用を返す
T vl = ti, vr = ti;
for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
if (l & 1)
vl = f(vl, dat[l++]); // 左端を使いたくなるのはブロックが奇数の時
if (r & 1)
vr = f(dat[--r], vr); // 右端〃偶数の時(開区間なのでr:奇数で反応)
}
return f(vl, vr);
}
template <typename C>
int find(int st, C &check, T &acc, int k, int l,
int r) { // dat[k]:[l,r)の間にいるenを返す
// 下のfind用なので先にそっち読むべき
// accはst~lとかで確定している値
if (l + 1 == r) { // 答えがちゃんと存在するならこのlが答え
acc = f(acc, dat[k]);
return check(acc) ? k - n : -1; // 入るならk-n(==l)を、入らないなら-1を返す
}
int m = (l + r) >> 1; // にぶたんのそれ
if (m <= st)
return find(st, check, acc, (k << 1) | 1, m,
r); // mがstより後ろなら明らかにl=m;
if (st <= l &&
!check(
f(acc,
dat[k]))) { // 今見てるk全部でもダメ(mだと足りないのでl=mにする)
acc = f(acc, dat[k]); // kは全部accに加えた上で-1を返す
return -1;
}
int vl = find(st, check, acc, (k << 1) | 0, l,
m); // まず[l,m)の中にenがいるか探す
if (~vl)
return vl; // いたならそれを返す(if(~vl)は-1以外にのみ反応する)
return find(st, check, acc, (k << 1) | 1, m,
r); // いなかったら[m,r)の中にenがいるのでそれを返す
// acc=f(acc,dat[k]);がここで効いてる
}
template <typename C> int find(int st, C &check) {
// check(f(dat[st]~dat[en-1]))=false,check(f(dat[st]~dat[en]))=trueとなるenを返す
T acc = ti;
return find(st, check, acc, 1, 0, n);
}
};
signed main() {
dp[0] = 1;
int n;
cin >> n;
vector<P> v(n);
for (int i = 0; i < n; i++) {
int x, d;
cin >> x >> d;
v[i] = P(x, d);
}
sort(v.begin(), v.end());
int ans = 0;
/*
for(int i=0;i<n;i++){
int now=i,right=v[i].first+v[i].second;
while(now<n&&right>v[now+1].first){
now++;
chmax(right,v[now].first+v[now].second);
}
a[i]=now;
}
*/
auto f = [](int a, int b) { return max(a, b); };
SegmentTree<int> seg(f, -1);
seg.init(n + 5);
for (int i = 0; i < n; i++)
seg.set_val(i, i);
for (int i = n - 2; i >= 0; i--) {
int l = i, r = n;
while (r - l > 1) {
int mid = (r + l) >> 1;
if (v[mid].first >= v[i].first + v[i].second)
r = mid;
else
l = mid;
}
seg.set_val(i, seg.query(i, r));
}
for (int i = 0; i < n; i++) {
dp[seg.get(i) + 1] += dp[i];
dp[seg.get(i) + 1] %= MOD;
dp[i + 1] += dp[i];
dp[i + 1] %= MOD;
}
cout << (dp[n] + dp[n + 1]) % MOD << endl;
}
| replace | 5 | 7 | 5 | 7 | 0 | |
p02758 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define f first
#define s second
#define MAXN 200010
const ll MOD = 1e9 + 7;
vpi V;
ll N, a, b;
bool cmp(pi a, pi b) { return a.f + a.s < b.f + b.s; }
struct node {
int s, e, m, v;
node *l, *r;
node(int _s, int _e) : s(_s), e(_e) {
m = (s + e) / 2;
v = 0;
if (s != e) {
l = new node(s, m);
r = new node(m + 1, e);
}
}
void up(int x, int val) {
if (s == e) {
v = max(v, val);
return;
}
if (x <= m)
l->up(x, val);
else
r->up(x, val);
v = max(l->v, r->v);
}
int query(int x, int y) {
if (s == x && e == y)
return v;
if (y <= m)
return l->query(x, y);
if (x > m)
return r->query(x, y);
return max(l->query(x, m), r->query(m + 1, y));
}
} *root;
vi des;
int lst[MAXN];
ll dp[MAXN];
vi AL[MAXN];
int main() {
cin >> N;
for (int i = 0; i < N; ++i) {
cin >> a >> b;
--b;
V.pb(a, a + b);
des.pb(a);
des.pb(a + b);
}
sort(ALL(des));
des.resize(unique(ALL(des)) - des.begin());
for (auto &i : V) {
int a = i.f;
int b = i.s;
i = mp(lb(ALL(des), a) - des.begin() + 1,
lb(ALL(des), b) - des.begin() + 1);
}
root = new node(1, SZ(des));
sort(ALL(V));
// for (auto i:V)cout<<i.f<<' '<<i.s<<'\n';
lst[SZ(V) - 1] = SZ(V) - 1;
AL[V.back().f].pb(V.back().s);
root->up(V.back().f, lst[SZ(V) - 1]);
for (int i = SZ(V) - 2; i >= 0; --i) {
int l = root->query(V[i].f, V[i].s);
l = max(l, i);
lst[i] = l;
root->up(V[i].f, l);
AL[V[i].f].pb(V[l].s);
}
dp[0] = 1;
for (int i = 1; i <= SZ(des); ++i) {
dp[i] += dp[i - 1];
dp[i] %= MOD;
// cout<<"AL: ";
for (auto x : AL[i]) {
// cout<<x<<' ';
dp[x] += dp[i - 1];
dp[x] %= MOD;
}
// cout<<'\n';
}
cout << dp[SZ(des)];
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define f first
#define s second
#define MAXN 400010
const ll MOD = 998244353;
vpi V;
ll N, a, b;
bool cmp(pi a, pi b) { return a.f + a.s < b.f + b.s; }
struct node {
int s, e, m, v;
node *l, *r;
node(int _s, int _e) : s(_s), e(_e) {
m = (s + e) / 2;
v = 0;
if (s != e) {
l = new node(s, m);
r = new node(m + 1, e);
}
}
void up(int x, int val) {
if (s == e) {
v = max(v, val);
return;
}
if (x <= m)
l->up(x, val);
else
r->up(x, val);
v = max(l->v, r->v);
}
int query(int x, int y) {
if (s == x && e == y)
return v;
if (y <= m)
return l->query(x, y);
if (x > m)
return r->query(x, y);
return max(l->query(x, m), r->query(m + 1, y));
}
} *root;
vi des;
int lst[MAXN];
ll dp[MAXN];
vi AL[MAXN];
int main() {
cin >> N;
for (int i = 0; i < N; ++i) {
cin >> a >> b;
--b;
V.pb(a, a + b);
des.pb(a);
des.pb(a + b);
}
sort(ALL(des));
des.resize(unique(ALL(des)) - des.begin());
for (auto &i : V) {
int a = i.f;
int b = i.s;
i = mp(lb(ALL(des), a) - des.begin() + 1,
lb(ALL(des), b) - des.begin() + 1);
}
root = new node(1, SZ(des));
sort(ALL(V));
// for (auto i:V)cout<<i.f<<' '<<i.s<<'\n';
lst[SZ(V) - 1] = SZ(V) - 1;
AL[V.back().f].pb(V.back().s);
root->up(V.back().f, lst[SZ(V) - 1]);
for (int i = SZ(V) - 2; i >= 0; --i) {
int l = root->query(V[i].f, V[i].s);
l = max(l, i);
lst[i] = l;
root->up(V[i].f, l);
AL[V[i].f].pb(V[l].s);
}
dp[0] = 1;
for (int i = 1; i <= SZ(des); ++i) {
dp[i] += dp[i - 1];
dp[i] %= MOD;
// cout<<"AL: ";
for (auto x : AL[i]) {
// cout<<x<<' ';
dp[x] += dp[i - 1];
dp[x] %= MOD;
}
// cout<<'\n';
}
cout << dp[SZ(des)];
} | replace | 15 | 17 | 15 | 17 | 0 | |
p02758 | C++ | Runtime Error | // Date: 2020-03-08
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO \
ios::sync_with_stdio(false); \
cin.tie(0)
#define rep(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for (int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 998244353;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {
LL a = 1;
while (y) {
if (y & 1)
a = a * x % MOD;
x = x * x % MOD;
y >>= 1;
}
return a;
}
int n;
pii a[N];
int main() {
scanf("%d", &n);
rep(i, 1, n) scanf("%d%d", &a[i].fi, &a[i].se);
sort(a + 1, a + 1 + n);
LL ans = 1;
vector<pii> v;
v.pb(mk((int)2e9 + 1, 1));
per(i, n, 1) {
while (v.back().fi < a[i].fi + a[i].se)
v.pop_back();
ans = (ans + v.back().se) % mod;
v.pb(mk(a[i].fi, ans));
}
printf("%lld\n", ans);
return 0;
} | // Date: 2020-03-08
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO \
ios::sync_with_stdio(false); \
cin.tie(0)
#define rep(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for (int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 998244353;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {
LL a = 1;
while (y) {
if (y & 1)
a = a * x % MOD;
x = x * x % MOD;
y >>= 1;
}
return a;
}
int n;
pii a[N];
int main() {
scanf("%d", &n);
rep(i, 1, n) scanf("%d%d", &a[i].fi, &a[i].se);
sort(a + 1, a + 1 + n);
LL ans = 1;
vector<pii> v;
v.pb(mk((int)2e9 + 1, 1));
per(i, n, 1) {
while (v.back().fi < a[i].fi + a[i].se)
v.pop_back();
ans = (ans + v.back().se) % mod;
v.pb(mk(a[i].fi, ans));
}
printf("%lld\n", ans);
return 0;
} | replace | 24 | 25 | 24 | 25 | 0 | |
p02758 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, x, n) for (int i = x; i <= n; i++)
#define rep3(i, x, n) for (int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
// const ll MOD = 1e9+7;
const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
using T = ll;
const int MAX_V = 2e5;
// 演算の内容
T f(T a, T b) { return max(a, b); }
// 何で初期化するか
T other = 0;
struct segment_tree {
int n;
T seg[2 * MAX_V];
// 要素数N(0〜N-1)の初期化されたセグメント木を構築
segment_tree(int N) {
n = 1;
while (n < N)
n *= 2;
fill_n(seg, 2 * n - 1, other);
}
// i番目の要素をxに変更(0番目から数える)
void update(int i, T x) {
i += n - 1;
seg[i] = x;
while (i > 0) {
i = (i - 1) / 2;
seg[i] = f(seg[2 * i + 1], seg[2 * i + 2]);
}
}
// query(a, b)で[a, b)における演算の結果を取得
T query(int a, int b, int i = 0, int l = 0, int r = -1) {
if (r < 0)
r = n;
if (a >= r || b <= l)
return other;
elif (a <= l && r <= b) return seg[i];
else {
T vl = query(a, b, 2 * i + 1, l, (l + r) / 2);
T vr = query(a, b, 2 * i + 2, (l + r) / 2, r);
return f(vl, vr);
}
}
};
int main() {
int N;
cin >> N;
pll p[N];
rep(i, N) {
ll x, d;
cin >> x >> d;
p[i] = pll(x, x + d);
}
sort(p, p + N);
ll L[N], R[N];
rep(i, N) { L[i] = p[i].first, R[i] = p[i].second; }
segment_tree seg(N);
rep(i, N) { seg.update(i, i); }
rep3(i, N - 1, 0) {
int j = lower_bound(L, L + N, R[i]) - L;
seg.update(i, seg.query(i, j));
}
// a[i]:=i個目のロボットを起動したときにどこまで消滅するか
int a[N];
rep(i, N) {
a[i] = seg.query(i, i + 1);
// cout << a[i] << endl;
}
// dp[i]:=起動させるロボットがi番目以降のものだけであるときの組み合わせの数
ll dp[N + 1];
dp[N] = 1;
rep3(i, N - 1, 0) {
dp[i] = dp[i + 1] + dp[a[i] + 1];
dp[i] %= MOD;
}
cout << dp[0] << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, x, n) for (int i = x; i <= n; i++)
#define rep3(i, x, n) for (int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
// const ll MOD = 1e9+7;
const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
using T = ll;
const int MAX_V = 5e5;
// 演算の内容
T f(T a, T b) { return max(a, b); }
// 何で初期化するか
T other = 0;
struct segment_tree {
int n;
T seg[2 * MAX_V];
// 要素数N(0〜N-1)の初期化されたセグメント木を構築
segment_tree(int N) {
n = 1;
while (n < N)
n *= 2;
fill_n(seg, 2 * n - 1, other);
}
// i番目の要素をxに変更(0番目から数える)
void update(int i, T x) {
i += n - 1;
seg[i] = x;
while (i > 0) {
i = (i - 1) / 2;
seg[i] = f(seg[2 * i + 1], seg[2 * i + 2]);
}
}
// query(a, b)で[a, b)における演算の結果を取得
T query(int a, int b, int i = 0, int l = 0, int r = -1) {
if (r < 0)
r = n;
if (a >= r || b <= l)
return other;
elif (a <= l && r <= b) return seg[i];
else {
T vl = query(a, b, 2 * i + 1, l, (l + r) / 2);
T vr = query(a, b, 2 * i + 2, (l + r) / 2, r);
return f(vl, vr);
}
}
};
int main() {
int N;
cin >> N;
pll p[N];
rep(i, N) {
ll x, d;
cin >> x >> d;
p[i] = pll(x, x + d);
}
sort(p, p + N);
ll L[N], R[N];
rep(i, N) { L[i] = p[i].first, R[i] = p[i].second; }
segment_tree seg(N);
rep(i, N) { seg.update(i, i); }
rep3(i, N - 1, 0) {
int j = lower_bound(L, L + N, R[i]) - L;
seg.update(i, seg.query(i, j));
}
// a[i]:=i個目のロボットを起動したときにどこまで消滅するか
int a[N];
rep(i, N) {
a[i] = seg.query(i, i + 1);
// cout << a[i] << endl;
}
// dp[i]:=起動させるロボットがi番目以降のものだけであるときの組み合わせの数
ll dp[N + 1];
dp[N] = 1;
rep3(i, N - 1, 0) {
dp[i] = dp[i + 1] + dp[a[i] + 1];
dp[i] %= MOD;
}
cout << dp[0] << endl;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p02758 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010, P = 998244353;
struct Ro {
int x, d;
} rb[MAXN];
int n, mx, eg, r[MAXN], hd[MAXN], ver[2 * MAXN], nx[2 * MAXN], dp[MAXN],
fa[MAXN], val[MAXN * 4];
bool cmp(Ro a, Ro b) { return a.x < b.x; }
void modify(int p, int l, int r, int pos, int v) {
if (l == r) {
val[p] = v;
return;
}
int mid = (l + r) >> 1;
if (pos <= mid) {
modify(p << 1, l, mid, pos, v);
} else {
modify((p << 1) | 1, mid + 1, r, pos, v);
}
val[p] = max(val[p << 1], val[(p << 1) | 1]);
return;
}
int query(int p, int l, int r, int xl, int xr) {
if (xr < l || r < xl) {
return 0;
}
if (xl <= l && r <= xr) {
return val[p];
}
int mid = (l + r) >> 1;
return max(query(p << 1, l, mid, xl, xr),
query((p << 1) | 1, mid + 1, r, xl, xr));
}
void add_edge(int x, int y) {
ver[++eg] = y;
nx[eg] = hd[x];
hd[x] = eg;
return;
}
void dfs(int x, int fa) {
int res = 1;
for (int i = hd[x]; i; i = nx[i]) {
if (ver[i] == fa) {
continue;
}
dfs(ver[i], x);
res = (1ll * res * dp[ver[i]]) % P;
}
dp[x] = (res + 1) % P;
return;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &rb[i].x, &rb[i].d);
}
sort(rb + 1, rb + n + 1, cmp);
for (int i = n; i >= 1; i--) {
int l = i, rr = n;
while (l < rr) {
int mid = (l + rr + 1) >> 1;
if (rb[i].x + rb[i].d > rb[mid].x) {
l = mid;
} else {
rr = mid - 1;
}
}
r[i] = query(1, 1, n, i, l);
if (!r[i]) {
r[i] = i;
}
modify(1, 1, n, i, r[i]);
}
int p = n + 1;
r[n + 1] = n;
for (int i = 1; i <= n; i++) {
while (r[i] > r[p]) {
p = fa[p];
}
fa[i] = p;
add_edge(i, p), add_edge(p, i);
p = i;
}
dfs(n + 1, 0);
printf("%d\n", (dp[n + 1] - 1 + P) % P);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010, P = 998244353;
struct Ro {
int x, d;
} rb[MAXN];
int n, mx, eg, r[MAXN], hd[MAXN], ver[2 * MAXN], nx[2 * MAXN], dp[MAXN],
fa[MAXN], val[MAXN * 4];
bool cmp(Ro a, Ro b) { return a.x < b.x; }
void modify(int p, int l, int r, int pos, int v) {
if (l == r) {
val[p] = v;
return;
}
int mid = (l + r) >> 1;
if (pos <= mid) {
modify(p << 1, l, mid, pos, v);
} else {
modify((p << 1) | 1, mid + 1, r, pos, v);
}
val[p] = max(val[p << 1], val[(p << 1) | 1]);
return;
}
int query(int p, int l, int r, int xl, int xr) {
if (xr < l || r < xl) {
return 0;
}
if (xl <= l && r <= xr) {
return val[p];
}
int mid = (l + r) >> 1;
return max(query(p << 1, l, mid, xl, xr),
query((p << 1) | 1, mid + 1, r, xl, xr));
}
void add_edge(int x, int y) {
ver[++eg] = y;
nx[eg] = hd[x];
hd[x] = eg;
return;
}
void dfs(int x, int fa) {
int res = 1;
for (int i = hd[x]; i; i = nx[i]) {
if (ver[i] == fa) {
continue;
}
dfs(ver[i], x);
res = (1ll * res * dp[ver[i]]) % P;
}
dp[x] = (res + 1) % P;
return;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &rb[i].x, &rb[i].d);
}
sort(rb + 1, rb + n + 1, cmp);
for (int i = n; i >= 1; i--) {
int l = i, rr = n;
while (l < rr) {
int mid = (l + rr + 1) >> 1;
if (rb[i].x + rb[i].d > rb[mid].x) {
l = mid;
} else {
rr = mid - 1;
}
}
r[i] = query(1, 1, n, i, l);
if (!r[i]) {
r[i] = i;
}
modify(1, 1, n, i, r[i]);
}
int p = n + 1;
r[n + 1] = n;
for (int i = 1; i <= n; i++) {
while (r[i] > r[p]) {
p = fa[p];
}
fa[i] = p;
add_edge(i, p), add_edge(p, i);
p = i;
}
dfs(n + 1, 0);
printf("%d\n", (dp[n + 1] - 1 + P) % P);
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p02758 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>
template <int64_t p> struct Fp {
Fp(int64_t n) : n(n % p) {}
Fp operator+(const Fp &rhs) { return Fp(n + rhs.n); }
Fp operator*(const Fp &rhs) { return Fp(n * rhs.n); }
int64_t n;
};
constexpr int64_t P = 998244353;
struct Robot {
int64_t x;
int64_t d;
};
void indent(size_t dep) {
for (size_t i = 0; i < dep; i++) {
std::cerr << ' ';
}
}
std::pair<size_t, Fp<P>> calc_combi(const std::vector<Robot> robots,
size_t begin, int64_t end_x) {
static size_t dep = 0;
dep++;
// indent(dep);
// std::cerr << begin << " at " << robots[begin].x << ' ' << end_x <<
// std::endl;
if (begin >= robots.size()) {
throw "out of index";
}
if (robots[begin].x >= end_x) {
throw "out of x bound";
}
size_t head = begin;
Fp<P> accum = 1;
while (head < robots.size()) {
const Robot &r = robots[head];
if (r.x >= end_x) {
break;
}
if (head + 1 >= robots.size()) {
head = head + 1;
accum = accum * 2;
break;
}
const Robot &next = robots[head + 1];
if (next.x >= r.x + r.d) {
head = head + 1;
accum = accum * 2;
} else {
auto p = calc_combi(robots, head + 1, r.x + r.d);
head = p.first;
accum = accum * (p.second + 1);
}
}
// indent(dep);
// std::cerr << begin << " at " << robots[begin].x << ' ' << end_x <<
// " -> " << head << ' ' << accum.n << std::endl;
dep--;
return {head, accum};
}
int main() {
try {
size_t n;
scanf("%ld", &n);
std::vector<Robot> robots;
for (size_t i = 0; i < n; i++) {
Robot r;
scanf("%ld %ld", &r.x, &r.d);
robots.push_back(r);
}
std::sort(robots.begin(), robots.end(),
[](const Robot &a, const Robot &b) { return a.x < b.x; });
auto result = calc_combi(robots, 0, robots.back().x + 1);
std::cout << result.second.n << std::endl;
} catch (const char *e) {
// std::cerr << e << std::endl;
}
return 0;
}
| #include <algorithm>
#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>
template <int64_t p> struct Fp {
Fp(int64_t n) : n(n % p) {}
Fp operator+(const Fp &rhs) { return Fp(n + rhs.n); }
Fp operator*(const Fp &rhs) { return Fp(n * rhs.n); }
int64_t n;
};
constexpr int64_t P = 998244353;
struct Robot {
int64_t x;
int64_t d;
};
void indent(size_t dep) {
for (size_t i = 0; i < dep; i++) {
std::cerr << ' ';
}
}
std::pair<size_t, Fp<P>> calc_combi(const std::vector<Robot> &robots,
size_t begin, int64_t end_x) {
static size_t dep = 0;
dep++;
// indent(dep);
// std::cerr << begin << " at " << robots[begin].x << ' ' << end_x <<
// std::endl;
if (begin >= robots.size()) {
throw "out of index";
}
if (robots[begin].x >= end_x) {
throw "out of x bound";
}
size_t head = begin;
Fp<P> accum = 1;
while (head < robots.size()) {
const Robot &r = robots[head];
if (r.x >= end_x) {
break;
}
if (head + 1 >= robots.size()) {
head = head + 1;
accum = accum * 2;
break;
}
const Robot &next = robots[head + 1];
if (next.x >= r.x + r.d) {
head = head + 1;
accum = accum * 2;
} else {
auto p = calc_combi(robots, head + 1, r.x + r.d);
head = p.first;
accum = accum * (p.second + 1);
}
}
// indent(dep);
// std::cerr << begin << " at " << robots[begin].x << ' ' << end_x <<
// " -> " << head << ' ' << accum.n << std::endl;
dep--;
return {head, accum};
}
int main() {
try {
size_t n;
scanf("%ld", &n);
std::vector<Robot> robots;
for (size_t i = 0; i < n; i++) {
Robot r;
scanf("%ld %ld", &r.x, &r.d);
robots.push_back(r);
}
std::sort(robots.begin(), robots.end(),
[](const Robot &a, const Robot &b) { return a.x < b.x; });
auto result = calc_combi(robots, 0, robots.back().x + 1);
std::cout << result.second.n << std::endl;
} catch (const char *e) {
// std::cerr << e << std::endl;
}
return 0;
}
| replace | 26 | 27 | 26 | 27 | 0 | |
p02758 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
struct dor {
dor *l, *r;
int sd;
void pp() {
if (l == NULL && r == NULL)
;
else if (l == NULL)
sd = r->sd;
else if (r == NULL)
sd = l->sd;
else
sd = max(l->sd, r->sd);
}
} *rt;
const int LN = -1e9, NR = 1e9, mod = 998244353;
int M(long long l, long long r) {
int m = (l + r) / 2;
if (m == r)
--m;
return m;
}
int si, vl;
void rgnk(int l, int r, dor *&t) {
if (t == NULL)
t = new dor();
if (l == r)
t->sd = vl;
else if (M(l, r) >= si)
rgnk(l, M(l, r), t->l);
else
rgnk(M(l, r) + 1, r, t->r);
t->pp();
}
void gnk(int Si, int Vl) {
si = Si, vl = Vl;
rgnk(LN, NR, rt);
}
int sl, sr;
int rsgm(int l, int r, dor *&t) {
if (l > sr || r < sl || t == NULL)
return LN;
if (l >= sl && r <= sr)
return t->sd;
return max(rsgm(l, M(l, r), t->l), rsgm(M(l, r) + 1, r, t->r));
}
int sgm(int l, int r) {
sl = l, sr = r;
return rsgm(LN, NR, rt);
}
int n, x, d;
vector<pair<int, int>> v, ve;
set<pair<int, int>> s;
long long fp;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
freopen("12.txt", "r", stdin);
v.push_back((*new pair<int, int>()));
ve.push_back((*new pair<int, int>()));
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> x >> d;
v.push_back({x, x + d - 1});
}
sort(v.begin() + 1, v.end());
reverse(v.begin() + 1, v.end());
for (int i = 1; i <= n; ++i) {
int tp = max(v[i].second, sgm(v[i].first, v[i].second));
gnk(v[i].first, tp);
ve.push_back({v[i].first, tp});
}
for (int i = 1; i <= n; ++i) {
long long tp = 1;
while (s.size() && s.begin()->first <= ve[i].second) {
tp *= s.begin()->second;
tp %= mod;
s.erase(s.begin());
}
++tp;
tp = (tp == mod ? 0 : tp);
s.insert({ve[i].first, tp});
}
fp = 1;
while (s.size()) {
fp *= s.begin()->second;
fp %= mod;
s.erase(s.begin());
}
cout << fp << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
struct dor {
dor *l, *r;
int sd;
void pp() {
if (l == NULL && r == NULL)
;
else if (l == NULL)
sd = r->sd;
else if (r == NULL)
sd = l->sd;
else
sd = max(l->sd, r->sd);
}
} *rt;
const int LN = -1e9, NR = 1e9, mod = 998244353;
int M(long long l, long long r) {
int m = (l + r) / 2;
if (m == r)
--m;
return m;
}
int si, vl;
void rgnk(int l, int r, dor *&t) {
if (t == NULL)
t = new dor();
if (l == r)
t->sd = vl;
else if (M(l, r) >= si)
rgnk(l, M(l, r), t->l);
else
rgnk(M(l, r) + 1, r, t->r);
t->pp();
}
void gnk(int Si, int Vl) {
si = Si, vl = Vl;
rgnk(LN, NR, rt);
}
int sl, sr;
int rsgm(int l, int r, dor *&t) {
if (l > sr || r < sl || t == NULL)
return LN;
if (l >= sl && r <= sr)
return t->sd;
return max(rsgm(l, M(l, r), t->l), rsgm(M(l, r) + 1, r, t->r));
}
int sgm(int l, int r) {
sl = l, sr = r;
return rsgm(LN, NR, rt);
}
int n, x, d;
vector<pair<int, int>> v, ve;
set<pair<int, int>> s;
long long fp;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
v.push_back((*new pair<int, int>()));
ve.push_back((*new pair<int, int>()));
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> x >> d;
v.push_back({x, x + d - 1});
}
sort(v.begin() + 1, v.end());
reverse(v.begin() + 1, v.end());
for (int i = 1; i <= n; ++i) {
int tp = max(v[i].second, sgm(v[i].first, v[i].second));
gnk(v[i].first, tp);
ve.push_back({v[i].first, tp});
}
for (int i = 1; i <= n; ++i) {
long long tp = 1;
while (s.size() && s.begin()->first <= ve[i].second) {
tp *= s.begin()->second;
tp %= mod;
s.erase(s.begin());
}
++tp;
tp = (tp == mod ? 0 : tp);
s.insert({ve[i].first, tp});
}
fp = 1;
while (s.size()) {
fp *= s.begin()->second;
fp %= mod;
s.erase(s.begin());
}
cout << fp << endl;
return 0;
}
| delete | 68 | 69 | 68 | 68 | 0 | |
p02758 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> pll;
// const ll mod=1e9+7;
const ll mod = 998244353;
const ll inf = 5e15;
struct query {
ll type; // 0=empty, 1=add-sum ,2=set-max
ll value;
query(ll a = 0, ll b = 0) : type(a), value(b) {}
};
ll INF = (1LL << 60);
struct segtree {
ll SIZE;
vector<query> s;
vector<ll> t; // sum-add
vector<ll> u; // max-set
segtree(ll n = 1) {
SIZE = 1;
while (SIZE < n)
SIZE *= 2;
s.clear();
t.clear();
u.clear();
s.resize(SIZE * 2, query());
t.resize(SIZE * 2, 0);
u.resize(SIZE * 2, 0);
}
void func(ll k, ll l, ll r, query q) {
if (q.type == 1) {
if (s[k].type == 0)
s[k] = q;
else
s[k].value += q.value;
t[k] += q.value * (r - l);
u[k] += q.value;
}
if (q.type == 2) {
s[k] = q;
t[k] = q.value * (r - l);
u[k] = q.value;
}
}
void compute(ll k, ll l, ll r) {
query q = s[k];
s[k] = query();
if (q.type == 0 || r - l == 1)
return;
ll m = (l + r) / 2;
func(k * 2 + 1, l, m, q);
func(k * 2 + 2, m, r, q);
}
void Update(ll a, ll b, query x, ll k, ll l, ll r) {
if (b <= l || r <= a)
return;
compute(k, l, r);
if (a <= l && r <= b) {
func(k, l, r, x);
} else {
ll m = (l + r) / 2;
Update(a, b, x, k * 2 + 1, l, m);
Update(a, b, x, k * 2 + 2, m, r);
t[k] = t[k * 2 + 1] + t[k * 2 + 2];
u[k] = max(u[k * 2 + 1], u[k * 2 + 2]);
}
}
ll Dfs(ll type, ll a, ll b, ll k, ll l, ll r) {
if (b <= l || r <= a) {
if (type == 1)
return 0; // add
if (type == 2)
return -inf; // max
}
compute(k, l, r);
if (a <= l && r <= b) {
if (type == 1)
return t[k];
if (type == 2)
return u[k];
} else {
ll m = (l + r) / 2;
ll lv = Dfs(type, a, b, k * 2 + 1, l, m);
ll rv = Dfs(type, a, b, k * 2 + 2, m, r);
if (type == 1)
return lv + rv; // add
if (type == 2)
return max(lv, rv); // max
}
}
void Add(ll a, ll b, ll x) { Update(a, b, query(1, x), 0, 0, SIZE); }
void Set(ll a, ll b, ll x) { Update(a, b, query(2, x), 0, 0, SIZE); }
ll Getsum(ll a, ll b) { return Dfs(1, a, b, 0, 0, SIZE); }
ll Getmax(ll a, ll b) { return Dfs(2, a, b, 0, 0, SIZE); }
};
int main() {
ll n;
cin >> n;
vector<pll> a(n);
vector<pll> b(n);
for (ll i = 0; i < n; i++) {
ll x, d;
cin >> x >> d;
a[i] = {x, x + d};
}
sort(a.begin(), a.end());
segtree d(n + 10);
d.Set(0, n + 1, -inf);
vec dp(n + 1);
dp[0] = 1;
for (ll i = 0; i < n; i++) {
ll x = b[n - i - 1].second;
ll it = upper_bound(a.begin(), a.end(), pll(x, -inf)) - a.begin();
d.Set(n - i - 1, n - i, it);
d.Set(n - i - 1, n - i, d.Getmax(n - i - 1, it));
ll id = n - d.Getmax(n - i - 1, n - i);
(dp[i + 1] = dp[i] + dp[id]) %= mod;
}
cout << dp[n] << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> pll;
// const ll mod=1e9+7;
const ll mod = 998244353;
const ll inf = 5e15;
struct query {
ll type; // 0=empty, 1=add-sum ,2=set-max
ll value;
query(ll a = 0, ll b = 0) : type(a), value(b) {}
};
ll INF = (1LL << 60);
struct segtree {
ll SIZE;
vector<query> s;
vector<ll> t; // sum-add
vector<ll> u; // max-set
segtree(ll n = 1) {
SIZE = 1;
while (SIZE < n)
SIZE *= 2;
s.clear();
t.clear();
u.clear();
s.resize(SIZE * 2, query());
t.resize(SIZE * 2, 0);
u.resize(SIZE * 2, 0);
}
void func(ll k, ll l, ll r, query q) {
if (q.type == 1) {
if (s[k].type == 0)
s[k] = q;
else
s[k].value += q.value;
t[k] += q.value * (r - l);
u[k] += q.value;
}
if (q.type == 2) {
s[k] = q;
t[k] = q.value * (r - l);
u[k] = q.value;
}
}
void compute(ll k, ll l, ll r) {
query q = s[k];
s[k] = query();
if (q.type == 0 || r - l == 1)
return;
ll m = (l + r) / 2;
func(k * 2 + 1, l, m, q);
func(k * 2 + 2, m, r, q);
}
void Update(ll a, ll b, query x, ll k, ll l, ll r) {
if (b <= l || r <= a)
return;
compute(k, l, r);
if (a <= l && r <= b) {
func(k, l, r, x);
} else {
ll m = (l + r) / 2;
Update(a, b, x, k * 2 + 1, l, m);
Update(a, b, x, k * 2 + 2, m, r);
t[k] = t[k * 2 + 1] + t[k * 2 + 2];
u[k] = max(u[k * 2 + 1], u[k * 2 + 2]);
}
}
ll Dfs(ll type, ll a, ll b, ll k, ll l, ll r) {
if (b <= l || r <= a) {
if (type == 1)
return 0; // add
if (type == 2)
return -inf; // max
}
compute(k, l, r);
if (a <= l && r <= b) {
if (type == 1)
return t[k];
if (type == 2)
return u[k];
} else {
ll m = (l + r) / 2;
ll lv = Dfs(type, a, b, k * 2 + 1, l, m);
ll rv = Dfs(type, a, b, k * 2 + 2, m, r);
if (type == 1)
return lv + rv; // add
if (type == 2)
return max(lv, rv); // max
}
}
void Add(ll a, ll b, ll x) { Update(a, b, query(1, x), 0, 0, SIZE); }
void Set(ll a, ll b, ll x) { Update(a, b, query(2, x), 0, 0, SIZE); }
ll Getsum(ll a, ll b) { return Dfs(1, a, b, 0, 0, SIZE); }
ll Getmax(ll a, ll b) { return Dfs(2, a, b, 0, 0, SIZE); }
};
int main() {
ll n;
cin >> n;
vector<pll> a(n);
vector<pll> b(n);
for (ll i = 0; i < n; i++) {
ll x, d;
cin >> x >> d;
a[i] = {x, x + d};
}
sort(a.begin(), a.end());
segtree d(n + 10);
d.Set(0, n + 1, -inf);
vec dp(n + 1);
dp[0] = 1;
for (ll i = 0; i < n; i++) {
ll x = a[n - i - 1].second;
ll it = upper_bound(a.begin(), a.end(), pll(x, -inf)) - a.begin();
d.Set(n - i - 1, n - i, it);
d.Set(n - i - 1, n - i, d.Getmax(n - i - 1, it));
ll id = n - d.Getmax(n - i - 1, n - i);
(dp[i + 1] = dp[i] + dp[id]) %= mod;
}
cout << dp[n] << endl;
} | replace | 124 | 125 | 124 | 125 | -11 | |
p02758 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define N 500001
#define MOD 998244353
int n, m, t[N], mx[N], fa[N], cur, f[N];
map<int, int> id;
vector<int> d[N];
struct rua {
int d, x, r;
void read() {
scanf("%d%d", &d, &x);
id[d] = id[d + x - 1] = 1;
r = d + x - 1;
}
bool operator<(const rua &t) { return d < t.d; }
} a[N];
#define ls x * 2
#define rs x * 2 + 1
void Build(int x, int l, int r) {
if (l == r) {
mx[x] = l;
return;
}
int mid = l + r >> 1;
Build(ls, l, mid);
Build(rs, mid + 1, r);
mx[x] = max(mx[ls], mx[rs]);
}
int getMax(int L, int R, int x, int l, int r) {
if (L <= l && r <= R)
return mx[x];
int mid = l + r >> 1, res = 0;
if (L <= mid)
res = max(res, getMax(L, R, ls, l, mid));
if (R > mid)
res = max(res, getMax(L, R, rs, mid + 1, r));
return res;
}
void Change(int i, int c, int x, int l, int r) {
if (l == r) {
mx[x] = c;
return;
}
int mid = l + r >> 1;
if (i <= mid)
Change(i, c, ls, l, mid);
else
Change(i, c, rs, mid + 1, r);
mx[x] = max(mx[ls], mx[rs]);
}
void dfs(int x) {
f[x] = 1;
for (auto y : d[x])
dfs(y), f[x] = 1ll * f[x] * f[y] % MOD;
if (x)
f[x] = (f[x] + 1) % MOD;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
a[i].read();
for (auto pi : id)
id[pi.first] = ++m;
sort(a + 1, a + n + 1);
Build(1, 1, m);
for (int i = n; i >= 1; i--)
Change(id[a[i].d], a[i].r = getMax(id[a[i].d], id[a[i].r], 1, 1, m), 1, 1,
m),
a[i].d = id[a[i].d];
stack<int> st;
for (int i = 1; i <= n; i++) {
while (!st.empty() && a[i].d > st.top())
st.pop(), cur = fa[cur];
d[cur].push_back(i);
st.push(a[i].r);
fa[i] = cur;
cur = i;
}
dfs(0);
printf("%d\n", f[0]);
} | #include <bits/stdc++.h>
using namespace std;
#define N 2000001
#define MOD 998244353
int n, m, t[N], mx[N], fa[N], cur, f[N];
map<int, int> id;
vector<int> d[N];
struct rua {
int d, x, r;
void read() {
scanf("%d%d", &d, &x);
id[d] = id[d + x - 1] = 1;
r = d + x - 1;
}
bool operator<(const rua &t) { return d < t.d; }
} a[N];
#define ls x * 2
#define rs x * 2 + 1
void Build(int x, int l, int r) {
if (l == r) {
mx[x] = l;
return;
}
int mid = l + r >> 1;
Build(ls, l, mid);
Build(rs, mid + 1, r);
mx[x] = max(mx[ls], mx[rs]);
}
int getMax(int L, int R, int x, int l, int r) {
if (L <= l && r <= R)
return mx[x];
int mid = l + r >> 1, res = 0;
if (L <= mid)
res = max(res, getMax(L, R, ls, l, mid));
if (R > mid)
res = max(res, getMax(L, R, rs, mid + 1, r));
return res;
}
void Change(int i, int c, int x, int l, int r) {
if (l == r) {
mx[x] = c;
return;
}
int mid = l + r >> 1;
if (i <= mid)
Change(i, c, ls, l, mid);
else
Change(i, c, rs, mid + 1, r);
mx[x] = max(mx[ls], mx[rs]);
}
void dfs(int x) {
f[x] = 1;
for (auto y : d[x])
dfs(y), f[x] = 1ll * f[x] * f[y] % MOD;
if (x)
f[x] = (f[x] + 1) % MOD;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
a[i].read();
for (auto pi : id)
id[pi.first] = ++m;
sort(a + 1, a + n + 1);
Build(1, 1, m);
for (int i = n; i >= 1; i--)
Change(id[a[i].d], a[i].r = getMax(id[a[i].d], id[a[i].r], 1, 1, m), 1, 1,
m),
a[i].d = id[a[i].d];
stack<int> st;
for (int i = 1; i <= n; i++) {
while (!st.empty() && a[i].d > st.top())
st.pop(), cur = fa[cur];
d[cur].push_back(i);
st.push(a[i].r);
fa[i] = cur;
cur = i;
}
dfs(0);
printf("%d\n", f[0]);
} | replace | 2 | 3 | 2 | 3 | 0 | |
p02758 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
int n;
vector<pair<ll, ll>> ps;
map<ll, int> mp;
ll P = 998244353;
template <typename T> class tRMQ {
vector<T> data;
T unit;
public:
static const long long INF = 100000000000;
int n;
function<T(const T &, const T &)> f;
tRMQ(int _, T u, function<T(T, T)> bi) {
unit = u;
f = bi;
n = 1;
while (n < _) {
n <<= 1;
}
data.resize(n * 4);
for (int i = 0; i < n * 4; i++)
data[i] = unit;
}
void update(int index, T val) {
int i = index + n - 1;
data[i] = val;
while (i > 0) {
i = (i - 1) / 2;
data[i] = f(data[i * 2 + 1], data[i * 2 + 2]);
}
}
// [a, b)
T query(int a, int b, int k, int l, int r) {
if (a < 0 || r <= a || b <= l)
return unit;
if (a <= l && r <= b)
return data[k];
else
return f(query(a, b, k * 2 + 1, l, (l + r) / 2),
query(a, b, k * 2 + 2, (r + l) / 2, r));
}
T query(int a, int b) { return query(a, b, 0, 0, n); }
};
tRMQ<ll> minrmq(int n) {
return tRMQ<ll>(n, 10000000000000000LL, [](ll r, ll l) { return min(l, r); });
}
tRMQ<ll> maxrmq(int n) {
return tRMQ<ll>(n, -10000000000000000LL,
[](ll r, ll l) { return max(l, r); });
}
tRMQ<ll> sumrmq(int n) {
return tRMQ<ll>(n, 0, [](ll l, ll r) { return l + r; });
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> n;
ps.resize(n);
for (int i = 0; i < n; i++) {
cin >> ps[i].first >> ps[i].second;
}
sort(ps.begin(), ps.end());
for (int i = 0; i < n; i++) {
mp[ps[i].first] = 0;
mp[ps[i].first + ps[i].second] = 0;
}
int c = 0;
vector<ll> inv;
for (auto &it : mp) {
it.second = c++;
inv.push_back(it.first);
}
inv.push_back(10000000000000LL);
tRMQ<ll> r = maxrmq(c);
for (int i = 0; i < c; i++)
r.update(i, i);
for (int i = n - 1; i >= 0; i--) {
r.update(mp[ps[i].first],
r.query(mp[ps[i].first], mp[ps[i].first + ps[i].second]));
}
ll memo[101010] = {0};
memo[n] = 1;
for (int i = n - 1; i >= 0; i--) {
auto p =
make_pair(inv[r.query(mp[ps[i].first], mp[ps[i].first] + 1)] + 1, 0LL);
auto it = lower_bound(ps.begin(), ps.end(), p);
memo[i] = (memo[i + 1] + memo[it - ps.begin()]) % P;
}
cout << memo[0] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
int n;
vector<pair<ll, ll>> ps;
map<ll, int> mp;
ll P = 998244353;
template <typename T> class tRMQ {
vector<T> data;
T unit;
public:
static const long long INF = 100000000000;
int n;
function<T(const T &, const T &)> f;
tRMQ(int _, T u, function<T(T, T)> bi) {
unit = u;
f = bi;
n = 1;
while (n < _) {
n <<= 1;
}
data.resize(n * 4);
for (int i = 0; i < n * 4; i++)
data[i] = unit;
}
void update(int index, T val) {
int i = index + n - 1;
data[i] = val;
while (i > 0) {
i = (i - 1) / 2;
data[i] = f(data[i * 2 + 1], data[i * 2 + 2]);
}
}
// [a, b)
T query(int a, int b, int k, int l, int r) {
if (a < 0 || r <= a || b <= l)
return unit;
if (a <= l && r <= b)
return data[k];
else
return f(query(a, b, k * 2 + 1, l, (l + r) / 2),
query(a, b, k * 2 + 2, (r + l) / 2, r));
}
T query(int a, int b) { return query(a, b, 0, 0, n); }
};
tRMQ<ll> minrmq(int n) {
return tRMQ<ll>(n, 10000000000000000LL, [](ll r, ll l) { return min(l, r); });
}
tRMQ<ll> maxrmq(int n) {
return tRMQ<ll>(n, -10000000000000000LL,
[](ll r, ll l) { return max(l, r); });
}
tRMQ<ll> sumrmq(int n) {
return tRMQ<ll>(n, 0, [](ll l, ll r) { return l + r; });
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> n;
ps.resize(n);
for (int i = 0; i < n; i++) {
cin >> ps[i].first >> ps[i].second;
}
sort(ps.begin(), ps.end());
for (int i = 0; i < n; i++) {
mp[ps[i].first] = 0;
mp[ps[i].first + ps[i].second] = 0;
}
int c = 0;
vector<ll> inv;
for (auto &it : mp) {
it.second = c++;
inv.push_back(it.first);
}
inv.push_back(10000000000000LL);
tRMQ<ll> r = maxrmq(c);
for (int i = 0; i < c; i++)
r.update(i, i);
for (int i = n - 1; i >= 0; i--) {
r.update(mp[ps[i].first],
r.query(mp[ps[i].first], mp[ps[i].first + ps[i].second]));
}
ll memo[201010] = {0};
memo[n] = 1;
for (int i = n - 1; i >= 0; i--) {
auto p =
make_pair(inv[r.query(mp[ps[i].first], mp[ps[i].first] + 1)] + 1, 0LL);
auto it = lower_bound(ps.begin(), ps.end(), p);
memo[i] = (memo[i + 1] + memo[it - ps.begin()]) % P;
}
cout << memo[0] << endl;
return 0;
}
| replace | 99 | 100 | 99 | 100 | 0 | |
p02758 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef pair<int, int> pii;
const int mod = 998244353;
pii a[200010];
int nxt[200010];
int dp[200010];
struct Segment_tree {
int maxj[200010];
Segment_tree() { memset(maxj, 0, sizeof(maxj)); }
void Update(int now, int l, int r, int pos, int x) {
if (l == r) {
maxj[now] = max(maxj[now], x);
return;
}
int mid = l + r >> 1;
if (pos <= mid)
Update(now << 1, l, mid, pos, x);
else
Update(now << 1 | 1, mid + 1, r, pos, x);
maxj[now] = max(maxj[now << 1], maxj[now << 1 | 1]);
}
int Query(int now, int l, int r, int L, int R) {
if (l == L && r == R)
return maxj[now];
int mid = l + r >> 1;
if (R <= mid)
return Query(now << 1, l, mid, L, R);
if (L > mid)
return Query(now << 1 | 1, mid + 1, r, L, R);
return max(Query(now << 1, l, mid, L, mid),
Query(now << 1 | 1, mid + 1, r, mid + 1, R));
}
} seg;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d%d", &a[i].fi, &a[i].se);
}
sort(a, a + n);
dp[n] = 1;
for (int i = n - 1; i >= 0; i--) {
int pos = lower_bound(a, a + n, mp(a[i].fi + a[i].se - 1, 0x3f3f3f3f)) - a;
nxt[i] = max(i, seg.Query(1, 0, n - 1, i, pos - 1));
seg.Update(1, 0, n - 1, i, nxt[i]);
dp[i] = dp[nxt[i] + 1] + dp[i + 1];
if (dp[i] >= mod)
dp[i] -= mod;
}
printf("%d\n", dp[0]);
return 0;
}
| #include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef pair<int, int> pii;
const int mod = 998244353;
pii a[200010];
int nxt[200010];
int dp[200010];
struct Segment_tree {
int maxj[800010];
Segment_tree() { memset(maxj, 0, sizeof(maxj)); }
void Update(int now, int l, int r, int pos, int x) {
if (l == r) {
maxj[now] = max(maxj[now], x);
return;
}
int mid = l + r >> 1;
if (pos <= mid)
Update(now << 1, l, mid, pos, x);
else
Update(now << 1 | 1, mid + 1, r, pos, x);
maxj[now] = max(maxj[now << 1], maxj[now << 1 | 1]);
}
int Query(int now, int l, int r, int L, int R) {
if (l == L && r == R)
return maxj[now];
int mid = l + r >> 1;
if (R <= mid)
return Query(now << 1, l, mid, L, R);
if (L > mid)
return Query(now << 1 | 1, mid + 1, r, L, R);
return max(Query(now << 1, l, mid, L, mid),
Query(now << 1 | 1, mid + 1, r, mid + 1, R));
}
} seg;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d%d", &a[i].fi, &a[i].se);
}
sort(a, a + n);
dp[n] = 1;
for (int i = n - 1; i >= 0; i--) {
int pos = lower_bound(a, a + n, mp(a[i].fi + a[i].se - 1, 0x3f3f3f3f)) - a;
nxt[i] = max(i, seg.Query(1, 0, n - 1, i, pos - 1));
seg.Update(1, 0, n - 1, i, nxt[i]);
dp[i] = dp[nxt[i] + 1] + dp[i + 1];
if (dp[i] >= mod)
dp[i] -= mod;
}
printf("%d\n", dp[0]);
return 0;
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p02758 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
vector<pair<ll, ll>> v;
vector<int> x, d;
ll dp1[200010], dp[200010], sum = 0, mod = 998244353;
ll n, seg[200010], mx = 100000000000000;
void built() {
for (int i = n - 1; i > 0; i--) {
seg[i] = max(seg[i << 1], seg[i << 1 | 1]);
}
}
void update(int p, ll a) {
for (seg[p += n] = a; p > 1; p >>= 1) {
seg[p >> 1] = max(seg[p], seg[p ^ 1]);
}
}
ll query(int l, int r) {
ll mn = 0;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1)
mn = max(mn, seg[l++]);
if (r & 1)
mn = max(mn, seg[--r]);
}
return mn;
}
int main() {
ll i;
cin >> n;
for (i = 0; i < n; i++) {
ll a, b;
cin >> a >> b;
v.push_back({a, b});
}
sort(v.begin(), v.end());
for (i = 0; i < n; i++) {
x.push_back(v[i].first);
d.push_back(v[i].second);
}
dp[n] = 1;
for (i = n - 1; i >= 0; i--) {
auto it = lower_bound(x.begin(), x.end(), x[i] + d[i]);
int j = it - x.begin();
dp1[i] = query(i, j);
dp1[i] = max(dp1[i], i);
update(i, dp1[i]);
dp[i] = (dp[i + 1] + dp[dp1[i] + 1]) % mod;
}
cout << dp[0] << endl;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
vector<pair<ll, ll>> v;
vector<int> x, d;
ll dp1[200010], dp[200010], sum = 0, mod = 998244353;
ll n, seg[400010], mx = 100000000000000;
void built() {
for (int i = n - 1; i > 0; i--) {
seg[i] = max(seg[i << 1], seg[i << 1 | 1]);
}
}
void update(int p, ll a) {
for (seg[p += n] = a; p > 1; p >>= 1) {
seg[p >> 1] = max(seg[p], seg[p ^ 1]);
}
}
ll query(int l, int r) {
ll mn = 0;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1)
mn = max(mn, seg[l++]);
if (r & 1)
mn = max(mn, seg[--r]);
}
return mn;
}
int main() {
ll i;
cin >> n;
for (i = 0; i < n; i++) {
ll a, b;
cin >> a >> b;
v.push_back({a, b});
}
sort(v.begin(), v.end());
for (i = 0; i < n; i++) {
x.push_back(v[i].first);
d.push_back(v[i].second);
}
dp[n] = 1;
for (i = n - 1; i >= 0; i--) {
auto it = lower_bound(x.begin(), x.end(), x[i] + d[i]);
int j = it - x.begin();
dp1[i] = query(i, j);
dp1[i] = max(dp1[i], i);
update(i, dp1[i]);
dp[i] = (dp[i + 1] + dp[dp1[i] + 1]) % mod;
}
cout << dp[0] << endl;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02758 | C++ | Time Limit Exceeded | #include <algorithm>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
// #define int long long
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) \
do { \
} while (0)
#define dump(x) \
do { \
} while (0)
#define BR
#endif
using namespace std;
using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
constexpr int MOD = 998244353;
// auto mod int
struct mint {
LL x;
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 {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(const LL &t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
LL operator()() const { return x; }
};
using VM = vector<mint>;
using VVM = vector<VM>;
struct S {
int x, d;
};
template <typename T = long long> class SegmentTree {
public:
std::vector<T> ary;
int n;
const T default_value = -1 * (1 << 30);
SegmentTree(int n) {
this->n = 1;
while (this->n < n)
this->n *= 2;
ary.resize(this->n * 2 - 1, default_value); // sum -> 0, min -> INF, 0?
}
T ope(T l, T r) { return std::max(l, r); }
void update(int k, T d) {
k += n - 1;
ary[k] = d;
while (k > 0) {
k = (k - 1) / 2;
ary[k] = ope(ary[2 * k + 1], ary[2 * k + 2]);
}
}
T query(int a, int b) { return query(a, b, 0, n, 0); }
T query(int a, int b, int l, int r, int i) {
if (a <= l && b >= r)
return ary[i];
// if (a >= r || b <= l) return 0; // sum
if (a >= r || b <= l)
return default_value; // min
int m = (l + r) / 2;
T vl = query(a, b, l, m, 2 * i + 1);
T vr = query(a, b, m, r, 2 * i + 2);
return ope(vl, vr);
}
};
void solve() {
int n;
cin >> n;
vector<S> ss(n);
REP(i, 0, n) cin >> ss[i].x >> ss[i].d;
sort(all(ss), [](auto &l, auto &r) { return l.x < r.x; });
SegmentTree<int> sg(n);
REP(i, 0, n) sg.update(i, ss[i].x + ss[i].d);
vector<mint> dp(n), ru(n + 1);
ru[n] = 1;
RREP(i, 0, n) {
S tmps;
tmps.x = ss[i].x + ss[i].d - 1;
int prevd = -1, d;
auto it =
upper_bound(all(ss), tmps, [](auto &l, auto &r) { return l.x < r.x; });
prevd = distance(ss.begin(), it);
// if (i == 0) dump(prevd);
for (;;) {
int mv = sg.query(i, prevd);
// if (i == 0) dump(mv);
tmps.x = mv - 1;
auto it = upper_bound(all(ss), tmps,
[](auto &l, auto &r) { return l.x < r.x; });
d = distance(ss.begin(), it);
if (d == prevd)
break;
prevd = d;
}
dp[i] = ru[d];
ru[i] = ru[i + 1] + dp[i];
}
cout << ru[0]() << endl;
return;
REP(i, 0, n) { cout << dp[i]() << " "; }
cout << endl;
REP(i, 0, n + 1) { cout << ru[i]() << " "; }
cout << endl;
}
signed main() {
solve();
return 0;
} | #include <algorithm>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
// #define int long long
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) \
do { \
} while (0)
#define dump(x) \
do { \
} while (0)
#define BR
#endif
using namespace std;
using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
constexpr int MOD = 998244353;
// auto mod int
struct mint {
LL x;
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 {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(const LL &t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
LL operator()() const { return x; }
};
using VM = vector<mint>;
using VVM = vector<VM>;
struct S {
int x, d;
};
template <typename T = long long> class SegmentTree {
public:
std::vector<T> ary;
int n;
const T default_value = -1 * (1 << 30);
SegmentTree(int n) {
this->n = 1;
while (this->n < n)
this->n *= 2;
ary.resize(this->n * 2 - 1, default_value); // sum -> 0, min -> INF, 0?
}
T ope(T l, T r) { return std::max(l, r); }
void update(int k, T d) {
k += n - 1;
ary[k] = d;
while (k > 0) {
k = (k - 1) / 2;
ary[k] = ope(ary[2 * k + 1], ary[2 * k + 2]);
}
}
T query(int a, int b) { return query(a, b, 0, n, 0); }
T query(int a, int b, int l, int r, int i) {
if (a <= l && b >= r)
return ary[i];
// if (a >= r || b <= l) return 0; // sum
if (a >= r || b <= l)
return default_value; // min
int m = (l + r) / 2;
T vl = query(a, b, l, m, 2 * i + 1);
T vr = query(a, b, m, r, 2 * i + 2);
return ope(vl, vr);
}
};
void solve() {
int n;
cin >> n;
vector<S> ss(n);
REP(i, 0, n) cin >> ss[i].x >> ss[i].d;
sort(all(ss), [](auto &l, auto &r) { return l.x < r.x; });
SegmentTree<int> sg(n);
REP(i, 0, n) sg.update(i, ss[i].x + ss[i].d);
vector<mint> dp(n), ru(n + 1);
ru[n] = 1;
RREP(i, 0, n) {
S tmps;
tmps.x = ss[i].x + ss[i].d - 1;
int prevd = -1, d;
auto it =
upper_bound(all(ss), tmps, [](auto &l, auto &r) { return l.x < r.x; });
prevd = distance(ss.begin(), it);
// if (i == 0) dump(prevd);
for (;;) {
int mv = sg.query(i, prevd);
// if (i == 0) dump(mv);
tmps.x = mv - 1;
auto it = upper_bound(all(ss), tmps,
[](auto &l, auto &r) { return l.x < r.x; });
d = distance(ss.begin(), it);
if (d == prevd)
break;
prevd = d;
}
sg.update(i, max(ss[prevd].x, ss[i].x + ss[i].d));
dp[i] = ru[d];
ru[i] = ru[i + 1] + dp[i];
}
cout << ru[0]() << endl;
return;
REP(i, 0, n) { cout << dp[i]() << " "; }
cout << endl;
REP(i, 0, n + 1) { cout << ru[i]() << " "; }
cout << endl;
}
signed main() {
solve();
return 0;
} | insert | 195 | 195 | 195 | 196 | TLE | |
p02758 | C++ | Runtime Error | // F.
#include <algorithm>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
typedef long long LL;
const LL MOD = 998244353;
struct modll {
long long x;
modll() {}
modll(int _x) : x(_x) {}
operator int() const { return (int)x; }
modll operator+(int y) { return (x + y + MOD) % MOD; }
modll operator+=(int y) {
x = (x + y + MOD) % MOD;
return *this;
}
modll operator-(int y) { return (x - y + MOD) % MOD; }
modll operator-=(int y) {
x = (x - y + MOD) % MOD;
return *this;
}
modll operator*(int y) { return (x * y) % MOD; }
modll operator*=(int y) {
x = (x * y) % MOD;
return *this;
}
modll operator/(int y) { return (x * modpow(y, MOD - 2)) % MOD; }
modll operator/=(int y) {
x = (x * modpow(y, MOD - 2)) % MOD;
return *this;
}
static modll modinv(int a) { return modpow(a, MOD - 2); }
static modll modpow(int a, int b) {
modll x = a, r = 1;
for (; b; b >>= 1, x *= x)
if (b & 1)
r *= x;
return r;
}
};
template <typename T, size_t SIZE, T DEF_VAL,
const T &Compare(const T &, const T &)>
class SegmentTree {
vector<T> val;
public:
SegmentTree() : val(SIZE * 2, DEF_VAL) {}
T get(int a, int b, int l = 0, int r = SIZE, size_t i = 1) {
if (r <= a || b <= l)
return DEF_VAL;
if (a <= l && r <= b)
return val[i];
return Compare(get(a, b, l, (l + r) / 2, i * 2),
get(a, b, (l + r) / 2, r, i * 2 + 1));
}
void update(size_t i, T value) {
i += SIZE;
val[i] = Compare(val[i], value);
while (i > 1)
i >>= 1, val[i] = Compare(val[i * 2], val[i * 2 + 1]);
}
};
typedef SegmentTree<long long, 1 << 17, 1LL << 62, min> MinLLSegTree;
typedef SegmentTree<long long, 1 << 17, 0, max> MaxLLSegTree;
int main(int argc, char *argv[]) {
cout.precision(20);
#ifdef _MSC_VER
while (true)
#endif
{
int n = -1;
cin >> n;
if (n < 0)
return 0;
vector<pair<LL, LL>> xd(n);
for (int i = 0; i < n; ++i) {
cin >> xd[i].first >> xd[i].second;
}
sort(xd.begin(), xd.end());
vector<modll> dp(n + 1, 0);
dp[n] = 1;
MaxLLSegTree st;
for (int i = n - 1; i >= 0; --i) {
int j = (int)(lower_bound(xd.begin() + i + 1, xd.end(),
make_pair(xd[i].first + xd[i].second, 0LL)) -
xd.begin());
LL m = max((LL)i, st.get(i, j));
st.update(i, m);
dp[i] = dp[i + 1] + dp[m + 1];
}
cout << dp[0] << endl;
}
return 0;
}
| // F.
#include <algorithm>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
typedef long long LL;
const LL MOD = 998244353;
struct modll {
long long x;
modll() {}
modll(int _x) : x(_x) {}
operator int() const { return (int)x; }
modll operator+(int y) { return (x + y + MOD) % MOD; }
modll operator+=(int y) {
x = (x + y + MOD) % MOD;
return *this;
}
modll operator-(int y) { return (x - y + MOD) % MOD; }
modll operator-=(int y) {
x = (x - y + MOD) % MOD;
return *this;
}
modll operator*(int y) { return (x * y) % MOD; }
modll operator*=(int y) {
x = (x * y) % MOD;
return *this;
}
modll operator/(int y) { return (x * modpow(y, MOD - 2)) % MOD; }
modll operator/=(int y) {
x = (x * modpow(y, MOD - 2)) % MOD;
return *this;
}
static modll modinv(int a) { return modpow(a, MOD - 2); }
static modll modpow(int a, int b) {
modll x = a, r = 1;
for (; b; b >>= 1, x *= x)
if (b & 1)
r *= x;
return r;
}
};
template <typename T, size_t SIZE, T DEF_VAL,
const T &Compare(const T &, const T &)>
class SegmentTree {
vector<T> val;
public:
SegmentTree() : val(SIZE * 2, DEF_VAL) {}
T get(int a, int b, int l = 0, int r = SIZE, size_t i = 1) {
if (r <= a || b <= l)
return DEF_VAL;
if (a <= l && r <= b)
return val[i];
return Compare(get(a, b, l, (l + r) / 2, i * 2),
get(a, b, (l + r) / 2, r, i * 2 + 1));
}
void update(size_t i, T value) {
i += SIZE;
val[i] = Compare(val[i], value);
while (i > 1)
i >>= 1, val[i] = Compare(val[i * 2], val[i * 2 + 1]);
}
};
typedef SegmentTree<long long, 1 << 18, 1LL << 62, min> MinLLSegTree;
typedef SegmentTree<long long, 1 << 18, 0, max> MaxLLSegTree;
int main(int argc, char *argv[]) {
cout.precision(20);
#ifdef _MSC_VER
while (true)
#endif
{
int n = -1;
cin >> n;
if (n < 0)
return 0;
vector<pair<LL, LL>> xd(n);
for (int i = 0; i < n; ++i) {
cin >> xd[i].first >> xd[i].second;
}
sort(xd.begin(), xd.end());
vector<modll> dp(n + 1, 0);
dp[n] = 1;
MaxLLSegTree st;
for (int i = n - 1; i >= 0; --i) {
int j = (int)(lower_bound(xd.begin() + i + 1, xd.end(),
make_pair(xd[i].first + xd[i].second, 0LL)) -
xd.begin());
LL m = max((LL)i, st.get(i, j));
st.update(i, m);
dp[i] = dp[i + 1] + dp[m + 1];
}
cout << dp[0] << endl;
}
return 0;
}
| replace | 69 | 71 | 69 | 71 | 0 | |
p02758 | C++ | Runtime Error | // by szh
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define SZ(x) (int((x).size()))
#define se second
#define ll long long
#define pq priority_queue
#define MP make_pair
#define pii pair<int, int>
#define mod 998244353
#define debug(x) cerr << #x << "=" << x << '\n'
const int maxn = 1e5 + 10;
int n;
pii a[maxn];
int r[maxn];
int mx[maxn][20];
int f[maxn];
int l0g[maxn];
int query(int x, int y) {
int tmp = l0g[y - x + 1];
return max(mx[x][tmp], mx[y - (1 << tmp) + 1][tmp]);
}
int main() {
l0g[1] = 0;
for (int i = 2; i < maxn; i++)
l0g[i] = l0g[i / 2] + 1;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d%d", &a[i].fi, &a[i].se);
sort(a, a + n);
f[n] = 1;
for (int i = n - 1; i >= 0; i--) {
int x = lower_bound(a, a + n, MP(a[i].fi + a[i].se, 0)) - a - 1;
if (x > i)
r[i] = query(i + 1, x);
else
r[i] = i + 1;
mx[i][0] = r[i];
for (int j = 1; i + (1 << j) <= n; j++)
mx[i][j] = max(mx[i][j - 1], mx[i + (1 << (j - 1))][j - 1]);
}
for (int i = n - 1; i >= 0; i--) {
f[i] = (f[i + 1] + f[r[i]]) % mod;
;
}
printf("%d", f[0]);
return 0;
}
| // by szh
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define SZ(x) (int((x).size()))
#define se second
#define ll long long
#define pq priority_queue
#define MP make_pair
#define pii pair<int, int>
#define mod 998244353
#define debug(x) cerr << #x << "=" << x << '\n'
const int maxn = 2e5 + 10;
int n;
pii a[maxn];
int r[maxn];
int mx[maxn][20];
int f[maxn];
int l0g[maxn];
int query(int x, int y) {
int tmp = l0g[y - x + 1];
return max(mx[x][tmp], mx[y - (1 << tmp) + 1][tmp]);
}
int main() {
l0g[1] = 0;
for (int i = 2; i < maxn; i++)
l0g[i] = l0g[i / 2] + 1;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d%d", &a[i].fi, &a[i].se);
sort(a, a + n);
f[n] = 1;
for (int i = n - 1; i >= 0; i--) {
int x = lower_bound(a, a + n, MP(a[i].fi + a[i].se, 0)) - a - 1;
if (x > i)
r[i] = query(i + 1, x);
else
r[i] = i + 1;
mx[i][0] = r[i];
for (int j = 1; i + (1 << j) <= n; j++)
mx[i][j] = max(mx[i][j - 1], mx[i + (1 << (j - 1))][j - 1]);
}
for (int i = n - 1; i >= 0; i--) {
f[i] = (f[i + 1] + f[r[i]]) % mod;
;
}
printf("%d", f[0]);
return 0;
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p02758 | C++ | Time Limit Exceeded | #include <algorithm>
#include <stdio.h>
int n;
long long p = 998244353;
long long e = 1000000005;
long long x[200000];
long long d[200000];
long long h[200000];
long long m[200000];
long long dp[200001];
long long t[500];
long long y, l, r, lr;
long long rmq(long long ll, long long rr) {
long long f = 0;
long long i;
i = ll;
while (i % 400 && i <= rr) {
if (f < m[i])
f = m[i];
i++;
}
i = rr;
while ((i + 1) % 400 && i >= ll) {
if (f < m[i])
f = m[i];
i--;
}
i = (ll + 399) / 400;
while (i * 400 + 399 <= rr) {
if (f < t[i])
f = t[i];
}
return f;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%lld%lld", x + i, d + i);
x[i] += e;
h[i] = x[i] * e + d[i];
}
std::sort(h, h + n);
for (int i = 0; i < n; i++) {
d[i] = h[i] % e;
x[i] = h[i] / e - e;
}
dp[n] = 1;
for (int i = n - 1; i >= 0; i--) {
y = x[i] + d[i];
l = i;
r = n;
while (r - l > 1) {
lr = (l + r) / 2;
if (x[lr] >= y)
r = lr;
else
l = lr;
}
r = rmq(i, l);
if (r == 0)
r = i;
m[i] = r;
if (t[i / 400] < r)
t[i / 400] = r;
dp[i] = dp[i + 1] + dp[r + 1];
dp[i] %= p;
}
printf("%lld\n", dp[0]);
} | #include <algorithm>
#include <stdio.h>
int n;
long long p = 998244353;
long long e = 1000000005;
long long x[200000];
long long d[200000];
long long h[200000];
long long m[200000];
long long dp[200001];
long long t[500];
long long y, l, r, lr;
long long rmq(long long ll, long long rr) {
long long f = 0;
long long i;
i = ll;
while (i % 400 && i <= rr) {
if (f < m[i])
f = m[i];
i++;
}
i = rr;
while ((i + 1) % 400 && i >= ll) {
if (f < m[i])
f = m[i];
i--;
}
i = (ll + 399) / 400;
while (i * 400 + 399 <= rr) {
if (f < t[i])
f = t[i];
i++;
}
return f;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%lld%lld", x + i, d + i);
x[i] += e;
h[i] = x[i] * e + d[i];
}
std::sort(h, h + n);
for (int i = 0; i < n; i++) {
d[i] = h[i] % e;
x[i] = h[i] / e - e;
}
dp[n] = 1;
for (int i = n - 1; i >= 0; i--) {
y = x[i] + d[i];
l = i;
r = n;
while (r - l > 1) {
lr = (l + r) / 2;
if (x[lr] >= y)
r = lr;
else
l = lr;
}
r = rmq(i, l);
if (r == 0)
r = i;
m[i] = r;
if (t[i / 400] < r)
t[i / 400] = r;
dp[i] = dp[i + 1] + dp[r + 1];
dp[i] %= p;
}
printf("%lld\n", dp[0]);
} | insert | 31 | 31 | 31 | 32 | TLE | |
p02758 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define int long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define mp make_pair
#define MOD 998244353
#define IDE -1
using namespace std;
const int MAX_N = 1 << 17;
int n_max, n, dat[2 * MAX_N - 1];
void init(int n) {
n_max = 1;
while (n_max < n)
n_max *= 2;
REP(i, 2 * n_max - 1) dat[i] = IDE;
}
int segfunc(int l, int m) { return max(l, m); }
// k番目の値(0-indexed)をaに変更
void update(int k, int a) {
k += n_max - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = segfunc(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
// cout << "query: " << a << " " << b << " " << k << " " << l << " " << r <<
// "\n";
if (r <= a || b <= l) {
// cout << "-1\n";
return IDE;
}
if (a <= l && r <= b) {
// cout << dat[k] << "\n";
return dat[k];
} else {
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return segfunc(vl, vr);
}
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
init(n);
vector<pair<int, int>> robots;
REP(i, n) {
int xt, dt;
cin >> xt >> dt;
robots.pb(mp(xt, dt));
}
sort(robots.begin(), robots.end());
vector<int> x(n), d(n);
REP(i, n) {
x[i] = robots[i].first;
d[i] = robots[i].second;
}
REP(i, n) {
int j = i;
update(j, j);
}
for (int i = n - 1; i >= 0; i--) {
int idx_direct = lower_bound(x.begin(), x.end(), x[i] + d[i]) - x.begin();
// cout << "idx_direct " << i << ":" << idx_direct << "\n";
int q = query(i + 1, idx_direct, 0, 0, n_max);
int upval = max(i, q);
if (upval >= 0)
update(i, upval);
for (int j = 0; j < n + n_max - 1; j++) {
// cout << dat[j] << " ";
}
// cout << "\n";
}
vector<int> dp(n + 1);
dp[n] = 1;
for (int i = n - 1; i >= 0; i--) {
dp[i] = (dp[i + 1] + dp[dat[i + n_max - 1] + 1]) % MOD;
}
cout << dp[0] << "\n";
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define int long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define mp make_pair
#define MOD 998244353
#define IDE -1
using namespace std;
const int MAX_N = 1 << 20;
int n_max, n, dat[2 * MAX_N - 1];
void init(int n) {
n_max = 1;
while (n_max < n)
n_max *= 2;
REP(i, 2 * n_max - 1) dat[i] = IDE;
}
int segfunc(int l, int m) { return max(l, m); }
// k番目の値(0-indexed)をaに変更
void update(int k, int a) {
k += n_max - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = segfunc(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
// cout << "query: " << a << " " << b << " " << k << " " << l << " " << r <<
// "\n";
if (r <= a || b <= l) {
// cout << "-1\n";
return IDE;
}
if (a <= l && r <= b) {
// cout << dat[k] << "\n";
return dat[k];
} else {
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return segfunc(vl, vr);
}
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
init(n);
vector<pair<int, int>> robots;
REP(i, n) {
int xt, dt;
cin >> xt >> dt;
robots.pb(mp(xt, dt));
}
sort(robots.begin(), robots.end());
vector<int> x(n), d(n);
REP(i, n) {
x[i] = robots[i].first;
d[i] = robots[i].second;
}
REP(i, n) {
int j = i;
update(j, j);
}
for (int i = n - 1; i >= 0; i--) {
int idx_direct = lower_bound(x.begin(), x.end(), x[i] + d[i]) - x.begin();
// cout << "idx_direct " << i << ":" << idx_direct << "\n";
int q = query(i + 1, idx_direct, 0, 0, n_max);
int upval = max(i, q);
if (upval >= 0)
update(i, upval);
for (int j = 0; j < n + n_max - 1; j++) {
// cout << dat[j] << " ";
}
// cout << "\n";
}
vector<int> dp(n + 1);
dp[n] = 1;
for (int i = n - 1; i >= 0; i--) {
dp[i] = (dp[i + 1] + dp[dat[i + n_max - 1] + 1]) % MOD;
}
cout << dp[0] << "\n";
return 0;
} | replace | 15 | 16 | 15 | 16 | 0 | |
p02759 | C++ | Runtime Error | #pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define tr(x, container) for (auto &x : container)
#define fr(i, n) for (ll i = 0; i < (n); ++i)
#define frs(i, s, n) for (ll i = s; i < (n); ++i)
#define frb(i, s, e) for (ll i = s; i <= (e); ++i)
#define rfr(i, n) for (ll i = (n - 1); i >= 0; i--)
#define frbr(i, e, s) for (ll i = e; i >= (s); i--)
#define mset(m, v) memset(m, v, sizeof(m))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define find_bug(x) cout << '>' << #x << " : " << x << endl;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x)
cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define dbg(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#define dbg_arr(a, n) \
cerr << "[" << #a << "] = [ "; \
fr(i, n) cerr << a[i] << " "; \
cerr << "]\n";
#define dbg_mat(m, r, c) \
cerr << "[" << #m << "]:\n"; \
fr(i, r) { \
cerr << "[ "; \
fr(j, c) cerr << m[i][j] << " "; \
cerr << "]\n"; \
}
#define dbg_time(t) cerr << "Time elapsed: " << t << endl;
#else
#define dbg(x...) \
{}
#define dbg_arr(a, n) \
{}
#define dbg_mat(m, r, c) \
{}
#define dbg_time(t) \
{}
#endif
const ll MOD = 1e9 + 7;
const ll SMOD = 998244353;
const ll INF = 1e18;
const ll SINF = 1e9;
const ll MAX = 100100;
/*******************************************************************************************************************/
void pre() {}
void solve() {
ll n;
cin >> n;
if (n % 2 == 0)
cout << n / 2 << '\n';
else {
cout << (n + 1) / 2 << '\n';
}
}
signed main() {
clock_t begin = clock();
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
// cout<<fixed<<setprecision(15);
// pre();
ll test = 1;
// cin>>test;
fr(ii, test) {
// cout << "Case #" << ii + 1 << ": "<<endl;
solve();
}
clock_t end = clock();
double elapsed_secs = (double)(end - begin) / CLOCKS_PER_SEC;
dbg_time(elapsed_secs);
return 0;
}
| #pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define tr(x, container) for (auto &x : container)
#define fr(i, n) for (ll i = 0; i < (n); ++i)
#define frs(i, s, n) for (ll i = s; i < (n); ++i)
#define frb(i, s, e) for (ll i = s; i <= (e); ++i)
#define rfr(i, n) for (ll i = (n - 1); i >= 0; i--)
#define frbr(i, e, s) for (ll i = e; i >= (s); i--)
#define mset(m, v) memset(m, v, sizeof(m))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define find_bug(x) cout << '>' << #x << " : " << x << endl;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x)
cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define dbg(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#define dbg_arr(a, n) \
cerr << "[" << #a << "] = [ "; \
fr(i, n) cerr << a[i] << " "; \
cerr << "]\n";
#define dbg_mat(m, r, c) \
cerr << "[" << #m << "]:\n"; \
fr(i, r) { \
cerr << "[ "; \
fr(j, c) cerr << m[i][j] << " "; \
cerr << "]\n"; \
}
#define dbg_time(t) cerr << "Time elapsed: " << t << endl;
#else
#define dbg(x...) \
{}
#define dbg_arr(a, n) \
{}
#define dbg_mat(m, r, c) \
{}
#define dbg_time(t) \
{}
#endif
const ll MOD = 1e9 + 7;
const ll SMOD = 998244353;
const ll INF = 1e18;
const ll SINF = 1e9;
const ll MAX = 100100;
/*******************************************************************************************************************/
void pre() {}
void solve() {
ll n;
cin >> n;
if (n % 2 == 0)
cout << n / 2 << '\n';
else {
cout << (n + 1) / 2 << '\n';
}
}
signed main() {
clock_t begin = clock();
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// cout<<fixed<<setprecision(15);
// pre();
ll test = 1;
// cin>>test;
fr(ii, test) {
// cout << "Case #" << ii + 1 << ": "<<endl;
solve();
}
clock_t end = clock();
double elapsed_secs = (double)(end - begin) / CLOCKS_PER_SEC;
dbg_time(elapsed_secs);
return 0;
}
| delete | 121 | 126 | 121 | 121 | 0 | Time elapsed: 0.000304
|
p02759 | Python | Runtime Error | #!/usr/bin/env python3
def main():
N = map(int, open(0).read().split())
print(-(-N // 2))
main()
| #!/usr/bin/env python3
def main():
N = int(input())
print(-(-N // 2))
main()
| replace | 4 | 5 | 4 | 5 | TypeError: bad operand type for unary -: 'map' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02759/Python/s289619736.py", line 9, in <module>
main()
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02759/Python/s289619736.py", line 6, in main
print(-(-N // 2))
TypeError: bad operand type for unary -: 'map'
|
p02759 | Python | Runtime Error | n = input()
paper = 0
if n % 2 == 0:
paper = n / 2
else:
paper = n / 2 + 1
print(paper)
| n = int(input())
print((n + 1) // 2)
| replace | 0 | 7 | 0 | 2 | TypeError: not all arguments converted during string formatting | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02759/Python/s809156396.py", line 3, in <module>
if n % 2 == 0:
TypeError: not all arguments converted during string formatting
|
p02759 | Python | Runtime Error | import sys
import os
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
a = int(sys.stdin.readline().rstrip())
print(int(a // 2 if a % 2 == 0 else a // 2 + 1))
if __name__ == "__main__":
main()
| import sys
import os
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
a = int(sys.stdin.readline().rstrip())
print(a // 2 if a % 2 == 0 else a // 2 + 1)
if __name__ == "__main__":
main()
| replace | 8 | 11 | 8 | 10 | UnboundLocalError: local variable 'a' referenced before assignment | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02759/Python/s654779229.py", line 15, in <module>
main()
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02759/Python/s654779229.py", line 11, in main
print(int(a // 2 if a % 2 == 0 else a // 2 + 1))
UnboundLocalError: local variable 'a' referenced before assignment
|
p02759 | C++ | Runtime Error | #include <bits/stdc++.h>
// definitions
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++)
#define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--)
#define high(x) __builtin_popcountll(x)
#define pb push_back
#define pf push_front
#define mod1 998244353
#define mod 1000000007
#define MAX_CHAR 256
#define pi 3.1415926535897932384
using namespace std;
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<long long, long long>> vp;
typedef vector<tuple<long long, long long, long long>> vtup;
typedef deque<long long> dql;
typedef deque<char> dqc;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
ll INF = 1e18;
// prevent collisions in unordered_map
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
template <class T> void read(T arr[], ll n) { rep(i, 0, n) cin >> arr[i]; }
typedef unordered_map<long long, long long, custom_hash> umap;
// standard functions
ll mystoi(string str) {
stringstream ss(str);
ll ans = 0;
ss >> ans;
return ans;
}
ll exp(ll x, ll ex, ll p) {
ll ans = 1ll;
while (ex > 0) {
if (ex & 1ll)
ans = (ans * x) % p;
ex >>= 1ll;
x = (x * x) % p;
}
return ans;
}
bool sort_cond(const pair<ll, ll> &a, const pair<ll, ll> &b) {
return ((a.f - a.s) > (b.f - b.s));
}
// code beigns in main
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll t = 1;
// cin >> t;
while (t--) {
ll n;
cin >> n;
cout << ((n % 2) ? (n / 2 + 1) : (n / 2)) << endl;
}
} | #include <bits/stdc++.h>
// definitions
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++)
#define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--)
#define high(x) __builtin_popcountll(x)
#define pb push_back
#define pf push_front
#define mod1 998244353
#define mod 1000000007
#define MAX_CHAR 256
#define pi 3.1415926535897932384
using namespace std;
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<long long, long long>> vp;
typedef vector<tuple<long long, long long, long long>> vtup;
typedef deque<long long> dql;
typedef deque<char> dqc;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
ll INF = 1e18;
// prevent collisions in unordered_map
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
template <class T> void read(T arr[], ll n) { rep(i, 0, n) cin >> arr[i]; }
typedef unordered_map<long long, long long, custom_hash> umap;
// standard functions
ll mystoi(string str) {
stringstream ss(str);
ll ans = 0;
ss >> ans;
return ans;
}
ll exp(ll x, ll ex, ll p) {
ll ans = 1ll;
while (ex > 0) {
if (ex & 1ll)
ans = (ans * x) % p;
ex >>= 1ll;
x = (x * x) % p;
}
return ans;
}
bool sort_cond(const pair<ll, ll> &a, const pair<ll, ll> &b) {
return ((a.f - a.s) > (b.f - b.s));
}
// code beigns in main
int main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll t = 1;
// cin >> t;
while (t--) {
ll n;
cin >> n;
cout << ((n % 2) ? (n / 2 + 1) : (n / 2)) << endl;
}
} | replace | 78 | 82 | 78 | 82 | 0 | |
p02759 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main() {
int N, M;
bool f = true;
cin >> N >> M;
vector<int> s(M), c(M), ans(N);
rep(i, M) {
cin >> s.at(i) >> c.at(i);
ans.at(s.at(i) - 1) = c.at(i);
}
rep(i, M) {
rep(j, M) {
if (s.at(i) == s.at(j) && c.at(i) != c.at(j)) {
f = false;
break;
} else if (N != 1 && ans.at(0) == 0) {
f = false;
break;
}
}
if (f == false) {
break;
}
}
if (f) {
rep(i, N) { cout << ans.at(i); }
cout << endl;
} else {
cout << "-1" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main() {
int N;
cin >> N;
cout << (N + 1) / 2 << endl;
} | replace | 7 | 35 | 7 | 10 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 18446744073709551615) >= this->size() (which is 5)
|
p02759 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fr(i, a, b) for (int i = a; i < b; i++)
#define bfr(i, a, b) for (int i = a; i >= b; i--)
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL), cout.tie(NULL);
#define tc \
int t; \
cin >> t; \
while (t--)
#define mod 1000000007
#define all(vec) vec.begin(), vec.end()
#define ld long double
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fio
lli n;
cin >> n;
cout << (lli)(ceil(n / 2.000));
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fr(i, a, b) for (int i = a; i < b; i++)
#define bfr(i, a, b) for (int i = a; i >= b; i--)
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL), cout.tie(NULL);
#define tc \
int t; \
cin >> t; \
while (t--)
#define mod 1000000007
#define all(vec) vec.begin(), vec.end()
#define ld long double
int main() {
fio
lli n;
cin >> n;
cout << (lli)(ceil(n / 2.000));
return 0;
} | delete | 18 | 23 | 18 | 18 | 0 | |
p02759 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define pb emplace_back
#define f first
#define s second
#define rep(i, st, ed) for (ll i = st; i < ed; ++i)
#define repn(i, st, ed) for (ll i = st; i <= ed; ++i)
#define repb(i, ed, st) for (ll i = ed; i >= st; --i)
#define all(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define PI acosl(-1.0)
#define mp(a, b) make_pair(a, b)
#define eps 1e-9
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
typedef long long ll;
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;
}
const int N = 1e5 + 10;
const ll INF = 1LL << 60;
ll iv[N];
ll powM(ll a, ll b) {
ll res = 1;
for (; b; a = a * a % M, b /= 2)
if (b & 1)
res = res * a % M;
return res;
}
ll nckbig(int n, int k) {
ll ans = 1;
for (int i = 1; i <= k; ++i) {
ans = ans * (n - i + 1) % M * iv[i] % M;
}
return ans;
}
void caliv() {
iv[1] = 1;
for (int i = 2; i < N; i++) {
iv[i] = M - M / i * iv[M % i] % M;
}
}
ll f1[N], f2[N];
void calf() {
f1[0] = f2[0] = 1;
for (int i = 2; i < N; ++i) {
f1[i] = f1[i - 1] * i % M;
f2[i] = f2[i - i] * iv[i] % M;
}
}
ll nck(int n, int k) { return f1[n] * f2[n - k] % M * f2[k] % M; }
ll npk(int n, int k) { return f1[n] * f2[n - k] % M; }
void Rnck(int big) {
if (big) {
caliv();
} else {
calf();
}
}
void solve() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int x;
cin >> x;
int ans = x / 2 + x % 2;
cout << ans << endl;
}
int main() {
FAST ll Tests = 1;
// cin>>Tests;
while (Tests--) {
solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define pb emplace_back
#define f first
#define s second
#define rep(i, st, ed) for (ll i = st; i < ed; ++i)
#define repn(i, st, ed) for (ll i = st; i <= ed; ++i)
#define repb(i, ed, st) for (ll i = ed; i >= st; --i)
#define all(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define PI acosl(-1.0)
#define mp(a, b) make_pair(a, b)
#define eps 1e-9
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
typedef long long ll;
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;
}
const int N = 1e5 + 10;
const ll INF = 1LL << 60;
ll iv[N];
ll powM(ll a, ll b) {
ll res = 1;
for (; b; a = a * a % M, b /= 2)
if (b & 1)
res = res * a % M;
return res;
}
ll nckbig(int n, int k) {
ll ans = 1;
for (int i = 1; i <= k; ++i) {
ans = ans * (n - i + 1) % M * iv[i] % M;
}
return ans;
}
void caliv() {
iv[1] = 1;
for (int i = 2; i < N; i++) {
iv[i] = M - M / i * iv[M % i] % M;
}
}
ll f1[N], f2[N];
void calf() {
f1[0] = f2[0] = 1;
for (int i = 2; i < N; ++i) {
f1[i] = f1[i - 1] * i % M;
f2[i] = f2[i - i] * iv[i] % M;
}
}
ll nck(int n, int k) { return f1[n] * f2[n - k] % M * f2[k] % M; }
ll npk(int n, int k) { return f1[n] * f2[n - k] % M; }
void Rnck(int big) {
if (big) {
caliv();
} else {
calf();
}
}
void solve() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int x;
cin >> x;
int ans = x / 2 + x % 2;
cout << ans << endl;
}
int main() {
FAST ll Tests = 1;
// cin>>Tests;
while (Tests--) {
solve();
}
return 0;
}
| replace | 69 | 73 | 69 | 73 | 0 | |
p02759 | C++ | Runtime Error | #include <cstdio>
int main() {
int n;
scanf("%d", n);
printf("%d\n", n + 1 >> 1);
return 0;
}
| #include <cstdio>
int main() {
int n;
scanf("%d", &n);
printf("%d\n", n + 1 >> 1);
return 0;
}
| replace | 4 | 5 | 4 | 5 | -11 | |
p02759 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n;
cin >> n;
int ans = (n + 1) / 2;
return ans;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n;
cin >> n;
int ans = (n + 1) / 2;
cout << ans << endl;
} | replace | 10 | 11 | 10 | 11 | 3 | |
p02759 | C++ | Time Limit Exceeded | /**
* “Experience is the name everyone gives to their mistakes.” – Oscar Wilde
*
* author : prodipdatta7
* created : Sunday 01-March, 2020 06:00:48 PM
**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimize("unroll-loops")
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define debug(x) cerr << #x << " = " << x << '\n';
#define rep(i, b, e) \
for (__typeof(e) i = (b); i != (e + 1) - 2 * ((b) > (e)); \
i += 1 - 2 * ((b) > (e)))
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mem(a) memset(a, 0, sizeof a)
#define memn(a) memset(a, -1, sizeof a)
#define fread freopen("input.txt", "r", stdin)
#define fwrite freopen("output.txt", "w", stdout)
#define TN typename
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_multiset;
/*
Note : There is a problem with erase() function in ordered_multiset (for
less_equal<int> tag). lower_bound() works as upper_bound() and vice-versa. Be
careful to use. i) find_by_order(k) : kth smallest element counting from 0 . ii)
order_of_key(k) : number of elements strictly smaller than k.
*/
/*###############-> Input Section <-###############*/
template <TN T> inline void Int(T &a) {
bool minus = false;
a = 0;
char ch = getchar();
while (true) {
if (ch == '-' or (ch >= '0' && ch <= '9'))
break;
ch = getchar();
}
if (ch == '-')
minus = true;
else
a = ch - '0';
while (true) {
ch = getchar();
if (ch < '0' || ch > '9')
break;
a = a * 10 + (ch - '0');
}
if (minus)
a *= -1;
}
template <TN T, TN T1> inline void Int(T &a, T1 &b) { Int(a), Int(b); }
template <TN T, TN T1, TN T2> inline void Int(T &a, T1 &b, T2 &c) {
Int(a, b), Int(c);
}
template <TN T, TN T1, TN T2, TN T3>
inline void Int(T &a, T1 &b, T2 &c, T3 &d) {
Int(a, b), Int(c, d);
}
template <TN T, TN T1, TN T2, TN T3, TN T4>
inline void Int(T &a, T1 &b, T2 &c, T3 &d, T4 &e) {
Int(a, b), Int(c, d, e);
}
/*###############-> Debugger <-###############*/
#define error(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
void err(istream_iterator<string> it) { cout << endl; }
template <TN T, TN... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << ' ';
err(++it, args...);
}
/*###############-> Constraints <-###############*/
const int N = (int)2e5 + 5;
const int maxN = (int)1e6 + 6;
const ll Mod = (ll)1e9 + 7;
const int inf = (int)2e9;
const ll Inf = (ll)1e18;
const int mod = (int)1e9 + 7;
inline int add(int a, int b, int mod) {
a += b;
return a >= mod ? a - mod : a;
}
inline int sub(int a, int b, int mod) {
a -= b;
return a < 0 ? a + mod : a;
}
inline int mul(int a, int b, int mod) { return (ll)a * b % mod; }
/*...... ! Code starts from here ! ......*/
int main() {
// ios_base::sync_with_stdio(false) ;
// cin.tie(NULL) ; cout.tie(NULL) ;
int test = 1, tc = 0;
Int(test);
while (test--) {
int n;
Int(n);
cout << (n + 1) / 2 << '\n';
}
return 0;
} | /**
* “Experience is the name everyone gives to their mistakes.” – Oscar Wilde
*
* author : prodipdatta7
* created : Sunday 01-March, 2020 06:00:48 PM
**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimize("unroll-loops")
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define debug(x) cerr << #x << " = " << x << '\n';
#define rep(i, b, e) \
for (__typeof(e) i = (b); i != (e + 1) - 2 * ((b) > (e)); \
i += 1 - 2 * ((b) > (e)))
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mem(a) memset(a, 0, sizeof a)
#define memn(a) memset(a, -1, sizeof a)
#define fread freopen("input.txt", "r", stdin)
#define fwrite freopen("output.txt", "w", stdout)
#define TN typename
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_multiset;
/*
Note : There is a problem with erase() function in ordered_multiset (for
less_equal<int> tag). lower_bound() works as upper_bound() and vice-versa. Be
careful to use. i) find_by_order(k) : kth smallest element counting from 0 . ii)
order_of_key(k) : number of elements strictly smaller than k.
*/
/*###############-> Input Section <-###############*/
template <TN T> inline void Int(T &a) {
bool minus = false;
a = 0;
char ch = getchar();
while (true) {
if (ch == '-' or (ch >= '0' && ch <= '9'))
break;
ch = getchar();
}
if (ch == '-')
minus = true;
else
a = ch - '0';
while (true) {
ch = getchar();
if (ch < '0' || ch > '9')
break;
a = a * 10 + (ch - '0');
}
if (minus)
a *= -1;
}
template <TN T, TN T1> inline void Int(T &a, T1 &b) { Int(a), Int(b); }
template <TN T, TN T1, TN T2> inline void Int(T &a, T1 &b, T2 &c) {
Int(a, b), Int(c);
}
template <TN T, TN T1, TN T2, TN T3>
inline void Int(T &a, T1 &b, T2 &c, T3 &d) {
Int(a, b), Int(c, d);
}
template <TN T, TN T1, TN T2, TN T3, TN T4>
inline void Int(T &a, T1 &b, T2 &c, T3 &d, T4 &e) {
Int(a, b), Int(c, d, e);
}
/*###############-> Debugger <-###############*/
#define error(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
void err(istream_iterator<string> it) { cout << endl; }
template <TN T, TN... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << ' ';
err(++it, args...);
}
/*###############-> Constraints <-###############*/
const int N = (int)2e5 + 5;
const int maxN = (int)1e6 + 6;
const ll Mod = (ll)1e9 + 7;
const int inf = (int)2e9;
const ll Inf = (ll)1e18;
const int mod = (int)1e9 + 7;
inline int add(int a, int b, int mod) {
a += b;
return a >= mod ? a - mod : a;
}
inline int sub(int a, int b, int mod) {
a -= b;
return a < 0 ? a + mod : a;
}
inline int mul(int a, int b, int mod) { return (ll)a * b % mod; }
/*...... ! Code starts from here ! ......*/
int main() {
// ios_base::sync_with_stdio(false) ;
// cin.tie(NULL) ; cout.tie(NULL) ;
int test = 1, tc = 0;
// Int(test) ;
while (test--) {
int n;
Int(n);
cout << (n + 1) / 2 << '\n';
}
return 0;
} | replace | 136 | 137 | 136 | 137 | TLE | |
p02759 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mp make_pair
#define rep(i, s, n) for (int i = s; i < n; i++)
#define repeq(i, s, n) for (int i = s; i <= n; i++)
#define MOD (int)10e9 + 7
template <typename T> void amax(T &a, T b) { a = a > b ? a : b; }
template <typename T> void amin(T &a, T b) { a = a < b ? a : b; }
using namespace std;
int n;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
#ifndef FLOSH
freopen("helloin.txt", "r", stdin);
freopen("helloout.txt", "w", stdout);
#endif
int n;
cin >> n;
cout << ((n + 1) / 2) << endl;
return 0;
}
| #include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mp make_pair
#define rep(i, s, n) for (int i = s; i < n; i++)
#define repeq(i, s, n) for (int i = s; i <= n; i++)
#define MOD (int)10e9 + 7
template <typename T> void amax(T &a, T b) { a = a > b ? a : b; }
template <typename T> void amin(T &a, T b) { a = a < b ? a : b; }
using namespace std;
int n;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
cout << ((n + 1) / 2) << endl;
return 0;
}
| delete | 22 | 27 | 22 | 22 | 0 | |
p02760 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int marked[3][3];
int nums[3][3];
void mark(int num) {
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j)
marked[i][j] = (marked[i][j]) | (nums[i][j] == num);
}
}
int main() {
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j)
scanf(" %d", &nums[i][j]);
}
int n;
scanf(" %d", &n);
while (n--) {
int a;
scanf(" %d", &a);
mark(a);
}
bool yes = 0;
for (int i = 0; i < 3 && !yes; ++i) {
int sum = 0;
for (int j = 0; j < 3; ++j)
sum += marked[i][j];
yes = (sum == 3);
}
for (int j = 0; j < 3 && !yes; ++j) {
int sum = 0;
for (int i = 0; i < 3; ++i)
sum += marked[i][j];
yes = (sum == 3);
}
int sum = 0;
for (int i = 0; i < 3 && !yes; ++i)
sum += marked[i][i];
yes = yes | (sum == 3);
sum = 0;
for (int i = 0, j = 2; i > -1 && !yes; ++i, --j)
sum += marked[i][j];
yes = yes | (sum == 3);
if (yes)
puts("Yes");
else
puts("No");
}
| #include <bits/stdc++.h>
using namespace std;
int marked[3][3];
int nums[3][3];
void mark(int num) {
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j)
marked[i][j] = (marked[i][j]) | (nums[i][j] == num);
}
}
int main() {
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j)
scanf(" %d", &nums[i][j]);
}
int n;
scanf(" %d", &n);
while (n--) {
int a;
scanf(" %d", &a);
mark(a);
}
bool yes = 0;
for (int i = 0; i < 3 && !yes; ++i) {
int sum = 0;
for (int j = 0; j < 3; ++j)
sum += marked[i][j];
yes = (sum == 3);
}
for (int j = 0; j < 3 && !yes; ++j) {
int sum = 0;
for (int i = 0; i < 3; ++i)
sum += marked[i][j];
yes = (sum == 3);
}
int sum = 0;
for (int i = 0; i < 3 && !yes; ++i)
sum += marked[i][i];
yes = yes | (sum == 3);
sum = 0;
for (int i = 0, j = 2; i < 3 && !yes; ++i, --j)
sum += marked[i][j];
yes = yes | (sum == 3);
if (yes)
puts("Yes");
else
puts("No");
}
| replace | 43 | 44 | 43 | 44 | TLE | |
p02760 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int main() {
vector<vector<int>> A(3, vector<int>(3));
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j)
cin >> A[i][j];
int M;
cin >> M;
for (int i = 0; i < M; ++i) {
int a;
cin >> a;
for (int j = 0; j < 3; ++j)
for (int k = 0; k < 3; ++k)
if (A[i][j] == a)
A[i][j] = -1;
}
bool res = false;
for (int i = 0; i < 3; ++i) {
if (A[i][0] == -1 && A[i][1] == -1 && A[i][2] == -1)
res = true;
if (A[0][i] == -1 && A[1][i] == -1 && A[2][i] == -1)
res = true;
}
if (A[0][0] == -1 && A[1][1] == -1 && A[2][2] == -1)
res = true;
if (A[0][2] == -1 && A[1][1] == -1 && A[2][0] == -1)
res = true;
if (res)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
| #include <iostream>
#include <vector>
using namespace std;
int main() {
vector<vector<int>> A(3, vector<int>(3));
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j)
cin >> A[i][j];
int M;
cin >> M;
for (int i = 0; i < M; ++i) {
int a;
cin >> a;
for (int j = 0; j < 3; ++j)
for (int k = 0; k < 3; ++k)
if (A[j][k] == a)
A[j][k] = -1;
}
bool res = false;
for (int i = 0; i < 3; ++i) {
if (A[i][0] == -1 && A[i][1] == -1 && A[i][2] == -1)
res = true;
if (A[0][i] == -1 && A[1][i] == -1 && A[2][i] == -1)
res = true;
}
if (A[0][0] == -1 && A[1][1] == -1 && A[2][2] == -1)
res = true;
if (A[0][2] == -1 && A[1][1] == -1 && A[2][0] == -1)
res = true;
if (res)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
| replace | 17 | 19 | 17 | 19 | -11 | |
p02760 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i, a, n) for (int i = a; i < (int)n; i++)
#define rf(i, n, a) for (int i = n; i >= a; i--)
#define F first
#define S second
#define all(c) (c).begin(), (c).end()
#define sz(v) (int)(v).size()
#define fill(a, v) memset(a, v, sizeof(a))
#define d1(a) cout << a << "\n"
#define d2(a, b) cout << a << " " << b << "\n"
#define d3(a, b, c) cout << a << " " << b << " " << c << "\n"
#define d4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << "\n"
#define fast ios::sync_with_stdio(false), cin.tie(0);
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef vector<pii> vpi;
const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;
signed main() {
fast;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int a[3][3];
f(i, 0, 3) f(j, 0, 3) cin >> a[i][j];
map<int, int> m;
int n;
cin >> n;
f(i, 0, n) {
int x;
cin >> x;
m[x] = 1;
}
f(i, 0, 3) f(j, 0, 3) a[i][j] = m[a[i][j]];
int ok = 0;
if (a[0][0] && a[0][1] && a[0][2])
ok = 1;
if (a[1][0] && a[1][1] && a[1][2])
ok = 1;
if (a[2][0] && a[2][1] && a[2][2])
ok = 1;
if (a[0][0] && a[1][0] && a[2][0])
ok = 1;
if (a[0][1] && a[1][1] && a[2][1])
ok = 1;
if (a[0][2] && a[1][2] && a[2][2])
ok = 1;
if (a[0][0] && a[1][1] && a[2][2])
ok = 1;
if (a[2][0] && a[1][1] && a[0][2])
ok = 1;
cout << (ok ? "Yes" : "No");
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i, a, n) for (int i = a; i < (int)n; i++)
#define rf(i, n, a) for (int i = n; i >= a; i--)
#define F first
#define S second
#define all(c) (c).begin(), (c).end()
#define sz(v) (int)(v).size()
#define fill(a, v) memset(a, v, sizeof(a))
#define d1(a) cout << a << "\n"
#define d2(a, b) cout << a << " " << b << "\n"
#define d3(a, b, c) cout << a << " " << b << " " << c << "\n"
#define d4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << "\n"
#define fast ios::sync_with_stdio(false), cin.tie(0);
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef vector<pii> vpi;
const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;
signed main() {
fast;
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt" , "w" , stdout);
// #endif
int a[3][3];
f(i, 0, 3) f(j, 0, 3) cin >> a[i][j];
map<int, int> m;
int n;
cin >> n;
f(i, 0, n) {
int x;
cin >> x;
m[x] = 1;
}
f(i, 0, 3) f(j, 0, 3) a[i][j] = m[a[i][j]];
int ok = 0;
if (a[0][0] && a[0][1] && a[0][2])
ok = 1;
if (a[1][0] && a[1][1] && a[1][2])
ok = 1;
if (a[2][0] && a[2][1] && a[2][2])
ok = 1;
if (a[0][0] && a[1][0] && a[2][0])
ok = 1;
if (a[0][1] && a[1][1] && a[2][1])
ok = 1;
if (a[0][2] && a[1][2] && a[2][2])
ok = 1;
if (a[0][0] && a[1][1] && a[2][2])
ok = 1;
if (a[2][0] && a[1][1] && a[0][2])
ok = 1;
cout << (ok ? "Yes" : "No");
} | replace | 33 | 37 | 33 | 37 | 0 | |
p02760 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int A[2][2];
int B[2][2] = {0};
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
cin >> A[i][j];
}
}
int N;
cin >> N;
int b[N];
int aa, bb, cc;
for (int k = 0; k < N; ++k) {
aa = k;
cin >> b[k];
for (int ii = 0; ii < 3; ++ii) {
bb = ii;
for (int jj = 0; jj < 3; ++jj) {
cc = jj;
if (A[bb][cc] == b[aa])
B[bb][cc] = 1;
}
}
}
bool flag = false;
int d;
for (int kk = 0; kk < 3; ++kk) {
d = kk;
if (B[0][d] == 1 && B[1][d] == 1 && B[2][d] == 1)
flag = true;
if (B[d][0] == 1 && B[d][1] == 1 && B[d][2] == 1)
flag = true;
}
if (B[0][0] == 1 && B[1][1] == 1 && B[2][2] == 1)
flag = true;
if (B[0][2] == 1 && B[1][1] == 1 && B[2][0] == 1)
flag = true;
if (flag)
cout << "Yes";
if (!flag)
cout << "No";
}
| #include <iostream>
using namespace std;
int main() {
int A[3][3];
int B[3][3] = {};
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
cin >> A[i][j];
}
}
int N;
cin >> N;
int b[N];
int aa, bb, cc;
for (int k = 0; k < N; ++k) {
aa = k;
cin >> b[k];
for (int ii = 0; ii < 3; ++ii) {
bb = ii;
for (int jj = 0; jj < 3; ++jj) {
cc = jj;
if (A[bb][cc] == b[aa])
B[bb][cc] = 1;
}
}
}
bool flag = false;
int d;
for (int kk = 0; kk < 3; ++kk) {
d = kk;
if (B[0][d] == 1 && B[1][d] == 1 && B[2][d] == 1)
flag = true;
if (B[d][0] == 1 && B[d][1] == 1 && B[d][2] == 1)
flag = true;
}
if (B[0][0] == 1 && B[1][1] == 1 && B[2][2] == 1)
flag = true;
if (B[0][2] == 1 && B[1][1] == 1 && B[2][0] == 1)
flag = true;
if (flag)
cout << "Yes";
if (!flag)
cout << "No";
}
| replace | 3 | 5 | 3 | 5 | -6 | *** stack smashing detected ***: terminated
|
p02760 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
vector<vector<int>> bingo;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> bingo.at(i).at(j);
}
}
int n;
cin >> n;
int b;
rep(i, n) {
cin >> b;
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (bingo.at(j).at(k) == b) {
bingo.at(j).at(k) = 0;
}
}
}
}
if ((bingo.at(0).at(0) == 0 && bingo.at(0).at(1) == 0 &&
bingo.at(0).at(2) == 0) ||
(bingo.at(1).at(0) == 0 && bingo.at(1).at(1) == 0 &&
bingo.at(1).at(2) == 0) ||
(bingo.at(2).at(0) == 0 && bingo.at(2).at(1) == 0 &&
bingo.at(2).at(2) == 0) ||
(bingo.at(0).at(0) == 0 && bingo.at(1).at(0) == 0 &&
bingo.at(2).at(0) == 0) ||
(bingo.at(0).at(1) == 0 && bingo.at(1).at(1) == 0 &&
bingo.at(2).at(1) == 0) ||
(bingo.at(0).at(2) == 0 && bingo.at(1).at(2) == 0 &&
bingo.at(2).at(2) == 0) ||
(bingo.at(0).at(0) == 0 && bingo.at(1).at(1) == 0 &&
bingo.at(2).at(2) == 0) ||
(bingo.at(2).at(0) == 0 && bingo.at(1).at(1) == 0 &&
bingo.at(0).at(2) == 0)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
vector<vector<int>> bingo(3, vector<int>(3));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> bingo.at(i).at(j);
}
}
int n;
cin >> n;
int b;
rep(i, n) {
cin >> b;
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (bingo.at(j).at(k) == b) {
bingo.at(j).at(k) = 0;
}
}
}
}
if ((bingo.at(0).at(0) == 0 && bingo.at(0).at(1) == 0 &&
bingo.at(0).at(2) == 0) ||
(bingo.at(1).at(0) == 0 && bingo.at(1).at(1) == 0 &&
bingo.at(1).at(2) == 0) ||
(bingo.at(2).at(0) == 0 && bingo.at(2).at(1) == 0 &&
bingo.at(2).at(2) == 0) ||
(bingo.at(0).at(0) == 0 && bingo.at(1).at(0) == 0 &&
bingo.at(2).at(0) == 0) ||
(bingo.at(0).at(1) == 0 && bingo.at(1).at(1) == 0 &&
bingo.at(2).at(1) == 0) ||
(bingo.at(0).at(2) == 0 && bingo.at(1).at(2) == 0 &&
bingo.at(2).at(2) == 0) ||
(bingo.at(0).at(0) == 0 && bingo.at(1).at(1) == 0 &&
bingo.at(2).at(2) == 0) ||
(bingo.at(2).at(0) == 0 && bingo.at(1).at(1) == 0 &&
bingo.at(0).at(2) == 0)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| replace | 8 | 9 | 8 | 9 | -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)
|
p02760 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> vec(8);
int N;
for (int i = 0; i < 9; i++) {
cin >> vec.at(i);
}
cin >> N;
for (int i = 0; i < N; i++) {
int x;
cin >> x;
for (int j = 0; j < 9; j++) {
if (x == vec.at(j)) {
vec.at(j) = 'a';
}
}
}
if (vec.at(0) == 'a' && vec.at(1) == 'a' && vec.at(2) == 'a') {
cout << "Yes" << endl;
}
else if (vec.at(3) == 'a' && vec.at(4) == 'a' && vec.at(5) == 'a') {
cout << "Yes" << endl;
}
else if (vec.at(6) == 'a' && vec.at(7) == 'a' && vec.at(8) == 'a') {
cout << "Yes" << endl;
}
else if (vec.at(0) == 'a' && vec.at(3) == 'a' && vec.at(6) == 'a') {
cout << "Yes" << endl;
}
else if (vec.at(1) == 'a' && vec.at(4) == 'a' && vec.at(7) == 'a') {
cout << "Yes" << endl;
}
else if (vec.at(2) == 'a' && vec.at(5) == 'a' && vec.at(8) == 'a') {
cout << "Yes" << endl;
}
else if (vec.at(0) == 'a' && vec.at(4) == 'a' && vec.at(8) == 'a') {
cout << "Yes" << endl;
}
else if (vec.at(2) == 'a' && vec.at(4) == 'a' && vec.at(6) == 'a') {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> vec(9);
int N;
for (int i = 0; i < 9; i++) {
cin >> vec.at(i);
}
cin >> N;
for (int i = 0; i < N; i++) {
int x;
cin >> x;
for (int j = 0; j < 9; j++) {
if (x == vec.at(j)) {
vec.at(j) = 'a';
}
}
}
if (vec.at(0) == 'a' && vec.at(1) == 'a' && vec.at(2) == 'a') {
cout << "Yes" << endl;
}
else if (vec.at(3) == 'a' && vec.at(4) == 'a' && vec.at(5) == 'a') {
cout << "Yes" << endl;
}
else if (vec.at(6) == 'a' && vec.at(7) == 'a' && vec.at(8) == 'a') {
cout << "Yes" << endl;
}
else if (vec.at(0) == 'a' && vec.at(3) == 'a' && vec.at(6) == 'a') {
cout << "Yes" << endl;
}
else if (vec.at(1) == 'a' && vec.at(4) == 'a' && vec.at(7) == 'a') {
cout << "Yes" << endl;
}
else if (vec.at(2) == 'a' && vec.at(5) == 'a' && vec.at(8) == 'a') {
cout << "Yes" << endl;
}
else if (vec.at(0) == 'a' && vec.at(4) == 'a' && vec.at(8) == 'a') {
cout << "Yes" << endl;
}
else if (vec.at(2) == 'a' && vec.at(4) == 'a' && vec.at(6) == 'a') {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
}
| replace | 4 | 5 | 4 | 5 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 8) >= this->size() (which is 8)
|
p02760 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
#define pb push_back
#define popb pop_back
#define popf pop_front
#define pf push_front
#define si size()
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define ask(i, m, n) for (lli i = m; i < n; i++)
#define anket ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define o0(a) cout << a << " "
#define o1(a) cout << a << "\n"
#define o2(a, b) cout << a << " " << b << "\n"
#define o3(a, b, c) cout << a << " " << b << " " << c << "\n"
#define o4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << "\n"
using namespace std;
#define prime1 1000000007
#define prime2 998244353
lli modadd(lli n, lli m, lli mod) {
lli sum = ((n + m) % mod + mod) % mod;
return sum;
}
lli modsub(lli n, lli m, lli mod) {
lli diff = ((n - m + mod) % mod + mod) % mod;
return diff;
}
lli modpro(lli n, lli m, lli mod) {
lli pro = ((n * m) % mod + mod) % mod;
return pro;
}
lli powmod(lli x, lli y, lli mod) {
x %= mod;
y %= mod;
lli res = 1;
while (y > 0) {
if (y & 1)
res = modpro(res, x, mod);
y = y >> 1;
x = modpro(x, x, mod);
}
return res;
}
lli moddiv(lli n, lli m, lli mod) {
// return n/m mod (mod) or n*(m)^-1 mod (mod)
lli a = powmod(m, mod - 2, mod);
// this is because of fermats thm i.e. a^-1 = a^p-2 mod(p) check
// multiplying p on both sides
lli res = modpro(a, n, mod);
return res;
}
int main() {
anket;
lli a[3][3], c[3][3];
ask(i, 0, 3) {
ask(j, 0, 3) {
cin >> c[i][j];
a[i][j] = 0;
}
}
lli n;
cin >> n;
ask(i, 0, n) {
lli b;
cin >> b;
ask(j, 0, 3){ask(k, 0, 3){if (c[j][k] == b){a[i][j] = 1;
}
}
}
;
}
if ((a[0][0] && a[0][1] && a[0][2]) || (a[1][0] && a[1][1] && a[1][2]) ||
(a[2][0] && a[2][1] && a[2][2]) || (a[0][0] && a[1][0] && a[2][0]) ||
(a[0][1] && a[1][1] && a[2][1]) || (a[0][2] && a[1][2] && a[2][2]) ||
(a[0][0] && a[1][1] && a[2][2]) || (a[0][2] && a[1][1] && a[2][0])) {
o1("Yes");
} else {
o1("No");
}
return 0;
}
| #include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
#define pb push_back
#define popb pop_back
#define popf pop_front
#define pf push_front
#define si size()
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define ask(i, m, n) for (lli i = m; i < n; i++)
#define anket ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define o0(a) cout << a << " "
#define o1(a) cout << a << "\n"
#define o2(a, b) cout << a << " " << b << "\n"
#define o3(a, b, c) cout << a << " " << b << " " << c << "\n"
#define o4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << "\n"
using namespace std;
#define prime1 1000000007
#define prime2 998244353
lli modadd(lli n, lli m, lli mod) {
lli sum = ((n + m) % mod + mod) % mod;
return sum;
}
lli modsub(lli n, lli m, lli mod) {
lli diff = ((n - m + mod) % mod + mod) % mod;
return diff;
}
lli modpro(lli n, lli m, lli mod) {
lli pro = ((n * m) % mod + mod) % mod;
return pro;
}
lli powmod(lli x, lli y, lli mod) {
x %= mod;
y %= mod;
lli res = 1;
while (y > 0) {
if (y & 1)
res = modpro(res, x, mod);
y = y >> 1;
x = modpro(x, x, mod);
}
return res;
}
lli moddiv(lli n, lli m, lli mod) {
// return n/m mod (mod) or n*(m)^-1 mod (mod)
lli a = powmod(m, mod - 2, mod);
// this is because of fermats thm i.e. a^-1 = a^p-2 mod(p) check
// multiplying p on both sides
lli res = modpro(a, n, mod);
return res;
}
int main() {
anket;
lli a[3][3], c[3][3];
ask(i, 0, 3) {
ask(j, 0, 3) {
cin >> c[i][j];
a[i][j] = 0;
}
}
lli n;
cin >> n;
ask(i, 0, n) {
lli b;
cin >> b;
ask(j, 0, 3){ask(k, 0, 3){if (c[j][k] == b){a[j][k] = 1;
}
}
}
;
}
if ((a[0][0] && a[0][1] && a[0][2]) || (a[1][0] && a[1][1] && a[1][2]) ||
(a[2][0] && a[2][1] && a[2][2]) || (a[0][0] && a[1][0] && a[2][0]) ||
(a[0][1] && a[1][1] && a[2][1]) || (a[0][2] && a[1][2] && a[2][2]) ||
(a[0][0] && a[1][1] && a[2][2]) || (a[0][2] && a[1][1] && a[2][0])) {
o1("Yes");
} else {
o1("No");
}
return 0;
}
| replace | 84 | 85 | 84 | 85 | 0 | |
p02760 | C++ | Runtime Error | #include <algorithm>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define PB push_back
#define ll long long
#define ull unsigned long long
#define uint unsigned
#define PIE (3.14159265358979323846)
#define MOD 1000000007;
using namespace std;
void checkStream() {
#ifndef _DEBUG
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
#endif
}
void inMat(vector<vector<int>> &mat, const int &num) {
bool found{false};
for (auto &i : mat) {
for (auto &j : i) {
if (j == num) {
found = true;
j = 0;
break;
}
}
if (found)
break;
}
}
int main() {
checkStream();
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// vector<vector<bool>> mat (3, vector<bool> (3, false));
vector<vector<int>> mat(3, vector<int>(3));
for (auto &i : mat) {
for (auto &j : i)
cin >> j;
}
int n{};
cin >> n;
while (n--) {
int num{};
cin >> num;
inMat(mat, num);
}
bool found{true};
for (int i{}; i < 3; ++i) {
if (mat.at(i).at(i)) {
found = false;
break;
}
}
if (found) {
cout << "Yes" << endl;
return 0;
}
found = true;
for (int i{}, j{2}; i < 3; ++i, --j) {
if (mat.at(i).at(j)) {
found = false;
break;
}
}
if (found) {
cout << "Yes" << endl;
return 0;
}
for (int i{}; i < 3; ++i) {
found = true;
for (int j{}; j < 3; ++j) {
if (mat.at(i).at(j)) {
found = false;
break;
}
}
if (found) {
cout << "Yes" << endl;
return 0;
}
}
for (int i{}; i < 3; ++i) {
found = true;
for (int j{}; j < 3; ++j) {
if (mat.at(j).at(i)) {
found = false;
break;
}
}
if (found) {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
return 0;
}
| #include <algorithm>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define PB push_back
#define ll long long
#define ull unsigned long long
#define uint unsigned
#define PIE (3.14159265358979323846)
#define MOD 1000000007;
using namespace std;
void checkStream() {
#ifndef _DEBUG
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
#endif
}
void inMat(vector<vector<int>> &mat, const int &num) {
bool found{false};
for (auto &i : mat) {
for (auto &j : i) {
if (j == num) {
found = true;
j = 0;
break;
}
}
if (found)
break;
}
}
int main() {
// checkStream();
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// vector<vector<bool>> mat (3, vector<bool> (3, false));
vector<vector<int>> mat(3, vector<int>(3));
for (auto &i : mat) {
for (auto &j : i)
cin >> j;
}
int n{};
cin >> n;
while (n--) {
int num{};
cin >> num;
inMat(mat, num);
}
bool found{true};
for (int i{}; i < 3; ++i) {
if (mat.at(i).at(i)) {
found = false;
break;
}
}
if (found) {
cout << "Yes" << endl;
return 0;
}
found = true;
for (int i{}, j{2}; i < 3; ++i, --j) {
if (mat.at(i).at(j)) {
found = false;
break;
}
}
if (found) {
cout << "Yes" << endl;
return 0;
}
for (int i{}; i < 3; ++i) {
found = true;
for (int j{}; j < 3; ++j) {
if (mat.at(i).at(j)) {
found = false;
break;
}
}
if (found) {
cout << "Yes" << endl;
return 0;
}
}
for (int i{}; i < 3; ++i) {
found = true;
for (int j{}; j < 3; ++j) {
if (mat.at(j).at(i)) {
found = false;
break;
}
}
if (found) {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
return 0;
}
| replace | 40 | 41 | 40 | 41 | 0 | |
p02760 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<vector<int>> a(3, vector<int>(3, 0));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> a.at(i).at(j);
}
}
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int b;
cin >> b;
for (int j = 0; j < 3; j++) {
for (int l = 0; l < 3; l++) {
if (b == a.at(i).at(j)) {
a.at(i).at(j) = 0;
}
}
}
}
string k = "No";
for (int i = 0; i < 3; i++) {
if (a.at(i).at(0) == 0 && a.at(i).at(1) == 0 && a.at(i).at(2) == 0) {
k = "Yes";
} else if (a.at(0).at(i) == 0 && a.at(1).at(i) == 0 && a.at(2).at(i) == 0) {
k = "Yes";
}
}
if (a.at(0).at(0) == 0 && a.at(1).at(1) == 0 && a.at(2).at(2) == 0) {
k = "Yes";
}
if (a.at(2).at(0) == 0 && a.at(1).at(1) == 0 && a.at(0).at(2) == 0) {
k = "Yes";
}
cout << k << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
vector<vector<int>> a(3, vector<int>(3, 0));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> a.at(i).at(j);
}
}
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int b;
cin >> b;
for (int j = 0; j < 3; j++) {
for (int l = 0; l < 3; l++) {
if (b == a.at(j).at(l)) {
a.at(j).at(l) = 0;
}
}
}
}
string k = "No";
for (int i = 0; i < 3; i++) {
if (a.at(i).at(0) == 0 && a.at(i).at(1) == 0 && a.at(i).at(2) == 0) {
k = "Yes";
} else if (a.at(0).at(i) == 0 && a.at(1).at(i) == 0 && a.at(2).at(i) == 0) {
k = "Yes";
}
}
if (a.at(0).at(0) == 0 && a.at(1).at(1) == 0 && a.at(2).at(2) == 0) {
k = "Yes";
}
if (a.at(2).at(0) == 0 && a.at(1).at(1) == 0 && a.at(0).at(2) == 0) {
k = "Yes";
}
cout << k << endl;
return 0;
}
| replace | 17 | 19 | 17 | 19 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)
|
p02760 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int a[3][3], N, b[N];
cin >> a[0][0] >> a[0][1] >> a[0][2];
cin >> a[1][0] >> a[1][1] >> a[1][2];
cin >> a[2][0] >> a[2][1] >> a[2][2];
cin >> N;
for (int i = 0; i < N; i++) {
cin >> b[i];
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (b[i] == a[j][k]) {
a[i][k] = 0;
}
}
}
}
if (a[0][0] == 0 && a[0][1] == 0 && a[0][2] == 0)
cout << "Yes"
<< "\n";
else if (a[1][0] == 0 && a[1][1] == 0 && a[1][2] == 0)
cout << "Yes"
<< "\n";
else if (a[2][0] == 0 && a[2][1] == 0 && a[2][2] == 0)
cout << "Yes"
<< "\n";
else if (a[0][0] == 0 && a[1][0] == 0 && a[2][0] == 0)
cout << "Yes"
<< "\n";
else if (a[0][1] == 0 && a[1][1] == 0 && a[2][1] == 0)
cout << "Yes"
<< "\n";
else if (a[0][2] == 0 && a[1][2] == 0 && a[2][2] == 0)
cout << "Yes"
<< "\n";
else if (a[0][0] == 0 && a[1][1] == 0 && a[2][2] == 0)
cout << "Yes"
<< "\n";
else if (a[0][2] == 0 && a[1][1] == 0 && a[2][0] == 0)
cout << "Yes"
<< "\n";
else
cout << "No"
<< "\n";
} | #include <iostream>
using namespace std;
int main() {
int a[3][3], N, b[N];
cin >> a[0][0] >> a[0][1] >> a[0][2];
cin >> a[1][0] >> a[1][1] >> a[1][2];
cin >> a[2][0] >> a[2][1] >> a[2][2];
cin >> N;
for (int i = 0; i < N; i++) {
cin >> b[i];
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (b[i] == a[j][k]) {
a[j][k] = 0;
}
}
}
}
if (a[0][0] == 0 && a[0][1] == 0 && a[0][2] == 0)
cout << "Yes"
<< "\n";
else if (a[1][0] == 0 && a[1][1] == 0 && a[1][2] == 0)
cout << "Yes"
<< "\n";
else if (a[2][0] == 0 && a[2][1] == 0 && a[2][2] == 0)
cout << "Yes"
<< "\n";
else if (a[0][0] == 0 && a[1][0] == 0 && a[2][0] == 0)
cout << "Yes"
<< "\n";
else if (a[0][1] == 0 && a[1][1] == 0 && a[2][1] == 0)
cout << "Yes"
<< "\n";
else if (a[0][2] == 0 && a[1][2] == 0 && a[2][2] == 0)
cout << "Yes"
<< "\n";
else if (a[0][0] == 0 && a[1][1] == 0 && a[2][2] == 0)
cout << "Yes"
<< "\n";
else if (a[0][2] == 0 && a[1][1] == 0 && a[2][0] == 0)
cout << "Yes"
<< "\n";
else
cout << "No"
<< "\n";
} | replace | 20 | 21 | 20 | 21 | -11 | |
p02760 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int A[3][3], B[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> A[i][j];
B[i][j] = 0;
}
}
int N;
cin >> N;
for (int t = 0; t < N; t++) {
int b;
cin >> b;
for (int i = 0; i < N; i++) {
for (int j = 0; j < 3; j++) {
if (A[i][j] == b) {
B[i][j] = 1;
}
}
}
}
if (B[0][0] == 1 && B[1][0] == 1 && B[2][0] == 1)
cout << "Yes";
else if (B[0][1] == 1 && B[1][1] == 1 && B[2][1] == 1)
cout << "Yes";
else if (B[0][2] == 1 && B[1][2] == 1 && B[2][2] == 1)
cout << "Yes";
else if (B[0][0] == 1 && B[0][1] == 1 && B[0][2] == 1)
cout << "Yes";
else if (B[1][0] == 1 && B[1][1] == 1 && B[1][2] == 1)
cout << "Yes";
else if (B[2][0] == 1 && B[2][1] == 1 && B[2][2] == 1)
cout << "Yes";
else if (B[0][0] == 1 && B[1][1] == 1 && B[2][2] == 1)
cout << "Yes";
else if (B[2][0] == 1 && B[1][1] == 1 && B[0][2] == 1)
cout << "Yes";
else
cout << "No";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int A[3][3], B[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> A[i][j];
B[i][j] = 0;
}
}
int N;
cin >> N;
for (int t = 0; t < N; t++) {
int b;
cin >> b;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (A[i][j] == b) {
B[i][j] = 1;
}
}
}
}
if (B[0][0] == 1 && B[1][0] == 1 && B[2][0] == 1)
cout << "Yes";
else if (B[0][1] == 1 && B[1][1] == 1 && B[2][1] == 1)
cout << "Yes";
else if (B[0][2] == 1 && B[1][2] == 1 && B[2][2] == 1)
cout << "Yes";
else if (B[0][0] == 1 && B[0][1] == 1 && B[0][2] == 1)
cout << "Yes";
else if (B[1][0] == 1 && B[1][1] == 1 && B[1][2] == 1)
cout << "Yes";
else if (B[2][0] == 1 && B[2][1] == 1 && B[2][2] == 1)
cout << "Yes";
else if (B[0][0] == 1 && B[1][1] == 1 && B[2][2] == 1)
cout << "Yes";
else if (B[2][0] == 1 && B[1][1] == 1 && B[0][2] == 1)
cout << "Yes";
else
cout << "No";
return 0;
} | replace | 16 | 17 | 16 | 17 | 0 | |
p02760 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<vector<int>> A(3, vector<int>(3));
vector<vector<bool>> B(3, vector<bool>(3, false));
for (vector<int> &i : A)
for (int &j : i)
cin >> j;
int N;
cin >> N;
for (int i = 0; i < N; i++) {
int j;
cin >> j;
for (int k = 0; k < 3; k++)
for (int l = 0; l < 3; l++)
if (A[k][l] == j)
B[k][l] = true;
}
for (int i = 0; i < N; i++) {
if (B[i][0] && B[i][1] && B[i][2]) {
cout << "Yes" << endl;
return 0;
}
if (B[0][i] && B[1][i] && B[2][i]) {
cout << "Yes" << endl;
return 0;
}
}
if ((B[0][0] && B[1][1] && B[2][2]) || (B[0][2] && B[1][1] && B[2][0])) {
cout << "Yes" << endl;
} else
cout << "No" << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<vector<int>> A(3, vector<int>(3));
vector<vector<bool>> B(3, vector<bool>(3, false));
for (vector<int> &i : A)
for (int &j : i)
cin >> j;
int N;
cin >> N;
for (int i = 0; i < N; i++) {
int j;
cin >> j;
for (int k = 0; k < 3; k++)
for (int l = 0; l < 3; l++)
if (A[k][l] == j)
B[k][l] = true;
}
for (int i = 0; i < 3; i++) {
if (B[i][0] && B[i][1] && B[i][2]) {
cout << "Yes" << endl;
return 0;
}
if (B[0][i] && B[1][i] && B[2][i]) {
cout << "Yes" << endl;
return 0;
}
}
if ((B[0][0] && B[1][1] && B[2][2]) || (B[0][2] && B[1][1] && B[2][0])) {
cout << "Yes" << endl;
} else
cout << "No" << endl;
} | replace | 19 | 20 | 19 | 20 | -11 | |
p02760 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<vector<int>> A(3, vector<int>(3));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> A[i][j];
}
}
int N;
cin >> N;
int b[N];
for (int k = 0; k < N; k++) {
cin >> b[k];
}
for (int k = 0; k < N; k++) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (b[k] == A[i][j]) {
A[i][j] = 0;
}
}
}
}
bool can = false;
for (int i = 0; i < 3; i++) {
if (A[i][0] == 0 && A[i][1] == 0 && A[i][2] == 0) {
can = true;
}
if (A[0][i] == 0 && A[1][i] == 0 && A[2][i] == 0) {
can = true;
}
if (A[0][0] == 0 && A[1][1] == 0 && A[2][2] == 0) {
can = true;
}
if (A[1][3] == 0 && A[2][2] == 0 && A[3][1] == 0) {
can = true;
}
}
if (can) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<vector<int>> A(3, vector<int>(3));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> A[i][j];
}
}
int N;
cin >> N;
int b[N];
for (int k = 0; k < N; k++) {
cin >> b[k];
}
for (int k = 0; k < N; k++) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (b[k] == A[i][j]) {
A[i][j] = 0;
}
}
}
}
bool can = false;
for (int i = 0; i < 3; i++) {
if (A[i][0] == 0 && A[i][1] == 0 && A[i][2] == 0) {
can = true;
}
if (A[0][i] == 0 && A[1][i] == 0 && A[2][i] == 0) {
can = true;
}
if (A[0][0] == 0 && A[1][1] == 0 && A[2][2] == 0) {
can = true;
}
if (A[0][2] == 0 && A[1][1] == 0 && A[2][0] == 0) {
can = true;
}
}
if (can) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
} | replace | 36 | 37 | 36 | 37 | -11 | |
p02760 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<vector<int>> a(3, vector<int>(3));
vector<vector<int>> A(3, vector<int>(3));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> a.at(i).at(j);
}
}
int N;
cin >> N;
vector<int> b(N);
for (int k = 0; k < N; k++) {
cin >> b.at(k);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (a.at(i).at(j) == b.at(k))
A.at(i).at(j) = 1;
}
}
}
bool tf = false;
int sum = 0;
for (int i = 0; i < 3; i++) {
sum = A.at(i).at(0) + A.at(i).at(1) + A.at(i).at(2);
if (sum == 3)
tf = true;
}
sum = 0;
for (int i = 0; i < 3; i++) {
sum = A.at(0).at(i) + A.at(1).at(i) + A.at(3).at(i);
if (sum == 3)
tf = true;
}
sum = 0;
for (int i = 0; i < 3; i++)
sum += A.at(i).at(i);
if (sum == 3)
tf = true;
sum = 0;
sum = A.at(0).at(2) + A.at(1).at(1) + A.at(2).at(0);
if (sum == 3)
tf = true;
if (tf == true)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
vector<vector<int>> a(3, vector<int>(3));
vector<vector<int>> A(3, vector<int>(3));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> a.at(i).at(j);
}
}
int N;
cin >> N;
vector<int> b(N);
for (int k = 0; k < N; k++) {
cin >> b.at(k);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (a.at(i).at(j) == b.at(k))
A.at(i).at(j) = 1;
}
}
}
bool tf = false;
int sum = 0;
for (int i = 0; i < 3; i++) {
sum = A.at(i).at(0) + A.at(i).at(1) + A.at(i).at(2);
if (sum == 3)
tf = true;
}
sum = 0;
for (int i = 0; i < 3; i++) {
sum = A.at(0).at(i) + A.at(1).at(i) + A.at(2).at(i);
if (sum == 3)
tf = true;
}
sum = 0;
for (int i = 0; i < 3; i++)
sum += A.at(i).at(i);
if (sum == 3)
tf = true;
sum = 0;
sum = A.at(0).at(2) + A.at(1).at(1) + A.at(2).at(0);
if (sum == 3)
tf = true;
if (tf == true)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
| replace | 39 | 40 | 39 | 40 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)
|
p02760 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int A[3][3];
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
cin >> A[i][j];
}
}
vector<vector<bool>> ok(3, vector<bool>(3, false));
int N;
cin >> N;
for (int k = 0; k < N; ++k) {
int b;
cin >> b;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
if (A[i][j] == b) {
ok[i][j] = true;
}
}
}
}
bool ans = false;
for (int i = 0; i < N; ++i) {
ans = ans || (ok[i][0] && ok[i][1] && ok[i][2]) ||
(ok[0][i] && ok[1][i] && ok[2][i]);
}
ans = ans || (ok[0][0] && ok[1][1] && ok[2][2]) ||
(ok[0][2] && ok[1][1] && ok[2][0]);
cout << (ans ? "Yes" : "No") << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int A[3][3];
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
cin >> A[i][j];
}
}
vector<vector<bool>> ok(3, vector<bool>(3, false));
int N;
cin >> N;
for (int k = 0; k < N; ++k) {
int b;
cin >> b;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
if (A[i][j] == b) {
ok[i][j] = true;
}
}
}
}
bool ans = false;
for (int i = 0; i < 3; ++i) {
ans = ans || (ok[i][0] && ok[i][1] && ok[i][2]) ||
(ok[0][i] && ok[1][i] && ok[2][i]);
}
ans = ans || (ok[0][0] && ok[1][1] && ok[2][2]) ||
(ok[0][2] && ok[1][1] && ok[2][0]);
cout << (ans ? "Yes" : "No") << endl;
}
| replace | 28 | 29 | 28 | 29 | -11 | |
p02760 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> s(9);
for (int i = 0; i < 9; i++) {
cin >> s.at(i);
}
int n;
cin >> n;
vector<int> m(n);
for (int i = 0; i < n; i++) {
cin >> m.at(i);
for (int j = 0; j < 9; j++) {
if (m.at(i) == s.at(j))
s.at(i) = 0;
}
}
bool e = false;
for (int i = 0; i < 3; i++) {
if (s.at(i) == 0 && s.at(i + 3) == 0 && s.at(i + 6) == 0) {
e = true;
break;
}
}
if (s.at(0) == 0 && s.at(1) == 0 && s.at(2) == 0) {
e = true;
}
if (s.at(3) == 0 && s.at(4) == 0 && s.at(5) == 0) {
e = true;
}
if (s.at(6) == 0 && s.at(7) == 0 && s.at(8) == 0) {
e = true;
}
if (s.at(0) == 0 && s.at(4) == 0 && s.at(8) == 0) {
e = true;
}
if (s.at(2) == 0 && s.at(4) == 0 && s.at(6) == 0) {
e = true;
}
if (e == true)
cout << "Yes" << endl;
else
cout << "No" << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> s(9);
for (int i = 0; i < 9; i++) {
cin >> s.at(i);
}
int n;
cin >> n;
vector<int> m(n);
for (int i = 0; i < n; i++) {
cin >> m.at(i);
for (int j = 0; j < 9; j++) {
if (m.at(i) == s.at(j))
s.at(j) = 0;
}
}
bool e = false;
for (int i = 0; i < 3; i++) {
if (s.at(i) == 0 && s.at(i + 3) == 0 && s.at(i + 6) == 0) {
e = true;
break;
}
}
if (s.at(0) == 0 && s.at(1) == 0 && s.at(2) == 0) {
e = true;
}
if (s.at(3) == 0 && s.at(4) == 0 && s.at(5) == 0) {
e = true;
}
if (s.at(6) == 0 && s.at(7) == 0 && s.at(8) == 0) {
e = true;
}
if (s.at(0) == 0 && s.at(4) == 0 && s.at(8) == 0) {
e = true;
}
if (s.at(2) == 0 && s.at(4) == 0 && s.at(6) == 0) {
e = true;
}
if (e == true)
cout << "Yes" << endl;
else
cout << "No" << endl;
} | replace | 16 | 17 | 16 | 17 | 0 | |
p02760 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> A(9);
for (int i = 0; i < 9; i++)
cin >> A.at(i);
int N;
cin >> N;
vector<int> B(N);
for (int i = 0; i < N; i++)
cin >> B.at(i);
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (A.at(i) == B.at(j))
A.at(i) = 0;
}
}
if (A.at(0) + A.at(1) + A.at(2) == 0)
return cout << "Yes"
<< "\n",
0;
if (A.at(3) + A.at(4) + A.at(5) == 0)
return cout << "Yes"
<< "\n",
0;
if (A.at(6) + A.at(7) + A.at(8) == 0)
return cout << "Yes"
<< "\n",
0;
if (A.at(0) + A.at(3) + A.at(6) == 0)
return cout << "Yes"
<< "\n",
0;
if (A.at(1) + A.at(4) + A.at(7) == 0)
return cout << "Yes"
<< "\n",
0;
if (A.at(2) + A.at(5) + A.at(8) == 0)
return cout << "Yes"
<< "\n",
0;
if (A.at(0) + A.at(4) + A.at(8) == 0)
return cout << "Yes"
<< "\n",
0;
if (A.at(2) + A.at(4) + A.at(6) == 0)
return cout << "Yes"
<< "\n",
0;
cout << "No"
<< "\n";
} | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> A(9);
for (int i = 0; i < 9; i++)
cin >> A.at(i);
int N;
cin >> N;
vector<int> B(N);
for (int i = 0; i < N; i++)
cin >> B.at(i);
for (int i = 0; i < 9; i++) {
for (int j = 0; j < N; j++) {
if (A.at(i) == B.at(j))
A.at(i) = 0;
}
}
if (A.at(0) + A.at(1) + A.at(2) == 0)
return cout << "Yes"
<< "\n",
0;
if (A.at(3) + A.at(4) + A.at(5) == 0)
return cout << "Yes"
<< "\n",
0;
if (A.at(6) + A.at(7) + A.at(8) == 0)
return cout << "Yes"
<< "\n",
0;
if (A.at(0) + A.at(3) + A.at(6) == 0)
return cout << "Yes"
<< "\n",
0;
if (A.at(1) + A.at(4) + A.at(7) == 0)
return cout << "Yes"
<< "\n",
0;
if (A.at(2) + A.at(5) + A.at(8) == 0)
return cout << "Yes"
<< "\n",
0;
if (A.at(0) + A.at(4) + A.at(8) == 0)
return cout << "Yes"
<< "\n",
0;
if (A.at(2) + A.at(4) + A.at(6) == 0)
return cout << "Yes"
<< "\n",
0;
cout << "No"
<< "\n";
} | replace | 13 | 14 | 13 | 14 | 0 | |
p02760 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<vector<int>> A(3, vector<int>(3));
bool c = false;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> A.at(i).at(j);
}
}
int N;
cin >> N;
for (int h = 0; h < N; h++) {
int b;
cin >> b;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (A.at(i).at(j) == b) {
A.at(i).at(j) = 0;
}
}
}
}
for (int i = 0; i < 3; i++) {
if (A.at(0).at(i) == 0 && A.at(1).at(i) == 0 && A.at(2).at(i) == 0) {
c = true;
}
}
for (int i = 0; i < 3; i++) {
if (A.at(i).at(0) == 0 && A.at(i).at(1) == 0 && A.at(i).at(2) == 0) {
c = true;
}
}
if (A.at(0).at(0) == 0 && A.at(1).at(1) == 0 && A.at(2).at(3) == 0) {
c = true;
} else if (A.at(0).at(2) == 0 && A.at(1).at(1) == 0 && A.at(2).at(0) == 0) {
c = true;
}
if (c) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<vector<int>> A(3, vector<int>(3));
bool c = false;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> A.at(i).at(j);
}
}
int N;
cin >> N;
for (int h = 0; h < N; h++) {
int b;
cin >> b;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (A.at(i).at(j) == b) {
A.at(i).at(j) = 0;
}
}
}
}
for (int i = 0; i < 3; i++) {
if (A.at(0).at(i) == 0 && A.at(1).at(i) == 0 && A.at(2).at(i) == 0) {
c = true;
}
}
for (int i = 0; i < 3; i++) {
if (A.at(i).at(0) == 0 && A.at(i).at(1) == 0 && A.at(i).at(2) == 0) {
c = true;
}
}
if (A.at(0).at(0) == 0 && A.at(1).at(1) == 0 && A.at(2).at(2) == 0) {
c = true;
} else if (A.at(0).at(2) == 0 && A.at(1).at(1) == 0 && A.at(2).at(0) == 0) {
c = true;
}
if (c) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | replace | 33 | 34 | 33 | 34 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)
|
p02760 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;
v2 a(3, v1(3));
int n;
int main() {
rep(i, 3) {
rep(j, 3) { cin >> a[i][j]; }
}
cin >> n;
rep(i, n) {
int x;
cin >> x;
rep(i, 3) {
rep(j, 3) {
if (a[i][j] == x) {
a[i][j] = 0;
}
}
}
}
rep(i, 3) {
if (a[i][0] == 0 && a[i][1] == 0 && a[i][2] == 0) {
cout << "Yes" << endl;
return 0;
}
}
rep(i, 3) {
if (a[0][i] == 0 && a[1][i] == 0 && a[2][i] == 0) {
cout << "Yes" << endl;
return 0;
}
}
if (a[1][1] == 0 && a[2][2] == 0 && a[0][0] == 0) {
cout << "Yes" << endl;
return 0;
}
if (a[1][3] == 0 && a[2][2] == 0 && a[3][1] == 0) {
cout << "Yes" << endl;
return 0;
}
cout << "No" << endl;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;
v2 a(3, v1(3));
int n;
int main() {
rep(i, 3) {
rep(j, 3) { cin >> a[i][j]; }
}
cin >> n;
rep(i, n) {
int x;
cin >> x;
rep(i, 3) {
rep(j, 3) {
if (a[i][j] == x) {
a[i][j] = 0;
}
}
}
}
rep(i, 3) {
if (a[i][0] == 0 && a[i][1] == 0 && a[i][2] == 0) {
cout << "Yes" << endl;
return 0;
}
}
rep(i, 3) {
if (a[0][i] == 0 && a[1][i] == 0 && a[2][i] == 0) {
cout << "Yes" << endl;
return 0;
}
}
if (a[1][1] == 0 && a[2][2] == 0 && a[0][0] == 0) {
cout << "Yes" << endl;
return 0;
}
if (a[0][2] == 0 && a[1][1] == 0 && a[2][0] == 0) {
cout << "Yes" << endl;
return 0;
}
cout << "No" << endl;
}
| replace | 45 | 46 | 45 | 46 | 0 | |
p02760 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
bool Bingo(vector<vector<int>> &A) {
for (int i = 0; i < 3; i++) {
if (A.at(0).at(i) == A.at(1).at(i) && A.at(1).at(i) == A.at(2).at(i) &&
A.at(2).at(i) == 0)
return true;
else if (A.at(i).at(0) == A.at(i).at(1) && A.at(i).at(1) == A.at(i).at(2) &&
A.at(i).at(2) == 0)
return true;
}
if (A.at(0).at(0) == A.at(1).at(1) && A.at(1).at(1) == A.at(2).at(2) &&
A.at(2).at(2) == 0)
return true;
else if (A.at(2).at(0) == A.at(1).at(1) && A.at(1).at(1) == A.at(0).at(3) &&
A.at(0).at(3) == 0)
return true;
return false;
}
int main() {
vector<vector<int>> A(3, vector<int>(3));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> A.at(i).at(j);
}
}
int N;
cin >> N;
vector<int> B(N);
for (int i = 0; i < N; i++) {
cin >> B.at(i);
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (A.at(j).at(k) == B.at(i))
A.at(j).at(k) = 0;
}
}
}
if (Bingo(A))
cout << "Yes" << endl;
else
cout << "No" << endl;
} | #include <bits/stdc++.h>
using namespace std;
bool Bingo(vector<vector<int>> &A) {
for (int i = 0; i < 3; i++) {
if (A.at(0).at(i) == A.at(1).at(i) && A.at(1).at(i) == A.at(2).at(i) &&
A.at(2).at(i) == 0)
return true;
else if (A.at(i).at(0) == A.at(i).at(1) && A.at(i).at(1) == A.at(i).at(2) &&
A.at(i).at(2) == 0)
return true;
}
if (A.at(0).at(0) == A.at(1).at(1) && A.at(1).at(1) == A.at(2).at(2) &&
A.at(2).at(2) == 0)
return true;
else if (A.at(2).at(0) == A.at(1).at(1) && A.at(1).at(1) == A.at(0).at(2) &&
A.at(0).at(2) == 0)
return true;
return false;
}
int main() {
vector<vector<int>> A(3, vector<int>(3));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> A.at(i).at(j);
}
}
int N;
cin >> N;
vector<int> B(N);
for (int i = 0; i < N; i++) {
cin >> B.at(i);
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (A.at(j).at(k) == B.at(i))
A.at(j).at(k) = 0;
}
}
}
if (Bingo(A))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
| replace | 14 | 16 | 14 | 16 | 0 | |
p02760 | C++ | Runtime Error | // https://atcoder.jp/contests/abc157/tasks/abc157_b
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, b, e) for (int i = (b); i <= (int)(e); i++)
#if DEBUG
#define DUMP(a) \
REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
#define DUMP2D(b) \
REP(_j, b.size()) DUMP(b[_j]); \
cout << endl
#else
#define DUMP(a)
#define DUMP2D(b)
#endif
const int A_IJ_MAX = 100;
const int N_MAX = 10;
const int B_I_MAX = 100;
vector<vector<int>> A;
int N;
vector<int> b;
vector<bool> f;
int main() {
A = vector<vector<int>>(3, vector<int>(3));
REP(i, 3) REP(j, 3) cin >> A[i][j];
cin >> N;
b = vector<int>(N);
REP(i, N) cin >> b[i];
f = vector<bool>(A_IJ_MAX, false);
REP(i, N) f[b[i]] = true;
bool cond = false;
bool bingo;
REP(i, 3) {
bingo = true;
REP(j, 3) bingo &= f[A[i][j]];
if (bingo)
cond = true;
}
REP(i, 3) {
bingo = true;
REP(j, 3) bingo &= f[A[j][i]];
if (bingo)
cond = true;
}
bingo = true;
REP(i, 3) bingo &= f[A[i][i]];
if (bingo)
cond = true;
bingo = true;
REP(i, 3) bingo &= f[A[i][2 - i]];
if (bingo)
cond = true;
cout << (cond ? "Yes" : "No") << endl;
}
| // https://atcoder.jp/contests/abc157/tasks/abc157_b
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, b, e) for (int i = (b); i <= (int)(e); i++)
#if DEBUG
#define DUMP(a) \
REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
#define DUMP2D(b) \
REP(_j, b.size()) DUMP(b[_j]); \
cout << endl
#else
#define DUMP(a)
#define DUMP2D(b)
#endif
const int A_IJ_MAX = 100;
const int N_MAX = 10;
const int B_I_MAX = 100;
vector<vector<int>> A;
int N;
vector<int> b;
vector<bool> f;
int main() {
A = vector<vector<int>>(3, vector<int>(3));
REP(i, 3) REP(j, 3) cin >> A[i][j];
cin >> N;
b = vector<int>(N);
REP(i, N) cin >> b[i];
f = vector<bool>(A_IJ_MAX + 1, false);
REP(i, N) f[b[i]] = true;
bool cond = false;
bool bingo;
REP(i, 3) {
bingo = true;
REP(j, 3) bingo &= f[A[i][j]];
if (bingo)
cond = true;
}
REP(i, 3) {
bingo = true;
REP(j, 3) bingo &= f[A[j][i]];
if (bingo)
cond = true;
}
bingo = true;
REP(i, 3) bingo &= f[A[i][i]];
if (bingo)
cond = true;
bingo = true;
REP(i, 3) bingo &= f[A[i][2 - i]];
if (bingo)
cond = true;
cout << (cond ? "Yes" : "No") << endl;
}
| replace | 36 | 37 | 36 | 37 | 0 | |
p02760 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> a(9);
for (int i = 0; i < 9; i++) {
cin >> a.at(i);
}
int n;
cin >> n;
vector<int> b(n);
vector<int> c(n);
for (int i = 0; i < n; i++) {
cin >> b.at(i);
for (int j = 0; j < 9; j++) {
if (a.at(j) == b.at(i)) {
c.at(j)++;
}
}
}
int count = 0;
for (int i = 0; i <= 6; i += 3) {
if (c.at(i) * c.at(i + 1) * c.at(i + 2) != 0) {
count++;
}
}
for (int i = 0; i <= 2; i++) {
if (c.at(i) * c.at(i + 3) * c.at(i + 6) != 0) {
count++;
}
}
if (c.at(0) * c.at(4) * c.at(8) != 0) {
count++;
}
if (c.at(2) * c.at(4) * c.at(6) != 0) {
count++;
}
if (count > 0) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> a(9);
for (int i = 0; i < 9; i++) {
cin >> a.at(i);
}
int n;
cin >> n;
vector<int> b(n);
vector<int> c(9);
for (int i = 0; i < n; i++) {
cin >> b.at(i);
for (int j = 0; j < 9; j++) {
if (a.at(j) == b.at(i)) {
c.at(j)++;
}
}
}
int count = 0;
for (int i = 0; i <= 6; i += 3) {
if (c.at(i) * c.at(i + 1) * c.at(i + 2) != 0) {
count++;
}
}
for (int i = 0; i <= 2; i++) {
if (c.at(i) * c.at(i + 3) * c.at(i + 6) != 0) {
count++;
}
}
if (c.at(0) * c.at(4) * c.at(8) != 0) {
count++;
}
if (c.at(2) * c.at(4) * c.at(6) != 0) {
count++;
}
if (count > 0) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| replace | 13 | 14 | 13 | 14 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 8) >= this->size() (which is 7)
|
p02760 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int a[10][10];
int m[10][10];
int ok;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> a[i][j];
}
}
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int b;
cin >> b;
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; j++) {
if (a[j][k] == b)
m[j][k] = 1;
}
}
}
for (int i = 0; i < 3; i++) {
ok = 1;
for (int j = 0; j < 3; j++) {
if (m[i][j] != 1)
ok = 0;
}
if (ok) {
cout << "Yes\n";
return 0;
}
}
for (int i = 0; i < 3; i++) {
ok = 1;
for (int j = 0; j < 3; j++) {
if (m[j][i] != 1)
ok = 0;
}
if (ok) {
cout << "Yes\n";
return 0;
}
}
ok = 1;
for (int i = 0; i < 3; i++) {
if (m[i][i] != 1)
ok = 0;
}
if (ok) {
cout << "Yes\n";
return 0;
}
ok = 1;
for (int i = 0; i < 3; i++) {
if (m[i][2 - i] != 1)
ok = 0;
}
if (ok) {
cout << "Yes\n";
return 0;
}
cout << "No\n";
}
| #include <bits/stdc++.h>
using namespace std;
int a[10][10];
int m[10][10];
int ok;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> a[i][j];
}
}
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int b;
cin >> b;
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (a[j][k] == b)
m[j][k] = 1;
}
}
}
for (int i = 0; i < 3; i++) {
ok = 1;
for (int j = 0; j < 3; j++) {
if (m[i][j] != 1)
ok = 0;
}
if (ok) {
cout << "Yes\n";
return 0;
}
}
for (int i = 0; i < 3; i++) {
ok = 1;
for (int j = 0; j < 3; j++) {
if (m[j][i] != 1)
ok = 0;
}
if (ok) {
cout << "Yes\n";
return 0;
}
}
ok = 1;
for (int i = 0; i < 3; i++) {
if (m[i][i] != 1)
ok = 0;
}
if (ok) {
cout << "Yes\n";
return 0;
}
ok = 1;
for (int i = 0; i < 3; i++) {
if (m[i][2 - i] != 1)
ok = 0;
}
if (ok) {
cout << "Yes\n";
return 0;
}
cout << "No\n";
}
| replace | 23 | 24 | 23 | 24 | -11 | |
p02760 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<vector<int>> a(3, vector<int>(3));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> a[i][j];
}
}
int N;
cin >> N;
vector<int> b(N);
for (int i = 0; i < N; i++) {
cin >> b[i];
}
vector<vector<int>> c(3, vector<int>(3));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
c[i][j] = 0;
}
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < N; j++) {
for (int k = 0; k < N; k++) {
if (a[i][j] == b[k]) {
c[i][j] = 1;
}
}
}
}
bool f = false;
for (int i = 0; i < 3; i++) {
if (c[i][0] == 1 && c[i][1] == 1 && c[i][2] == 1)
f = true;
}
for (int i = 0; i < 3; i++) {
if (c[0][i] == 1 && c[1][i] == 1 && c[2][i] == 1)
f = true;
}
if (c[0][0] == 1 && c[1][1] == 1 && c[2][2] == 1) {
f = true;
}
if (c[0][2] == 1 && c[1][1] == 1 && c[2][0] == 1) {
f = true;
}
if (f) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
vector<vector<int>> a(3, vector<int>(3));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> a[i][j];
}
}
int N;
cin >> N;
vector<int> b(N);
for (int i = 0; i < N; i++) {
cin >> b[i];
}
vector<vector<int>> c(3, vector<int>(3));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
c[i][j] = 0;
}
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < N; k++) {
if (a[i][j] == b[k]) {
c[i][j] = 1;
}
}
}
}
bool f = false;
for (int i = 0; i < 3; i++) {
if (c[i][0] == 1 && c[i][1] == 1 && c[i][2] == 1)
f = true;
}
for (int i = 0; i < 3; i++) {
if (c[0][i] == 1 && c[1][i] == 1 && c[2][i] == 1)
f = true;
}
if (c[0][0] == 1 && c[1][1] == 1 && c[2][2] == 1) {
f = true;
}
if (c[0][2] == 1 && c[1][1] == 1 && c[2][0] == 1) {
f = true;
}
if (f) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| replace | 25 | 26 | 25 | 26 | 0 | |
p02760 | C++ | Runtime Error | #include <bits/stdc++.h>
#define MAXN 100005
#define mod 1000000007
#define inf LLONG_MAX / 3
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
ll power(ll x, ll y, ll m = mod) {
ll ans = 1;
while (y > 0) {
if (y & 1) {
ans = (ans * x) % m;
}
x = (x * x) % m;
y /= 2;
}
return ans % m;
}
ll modInverse(ll a, ll m = mod) {
ll m0 = m;
ll y = 0, x = 1;
if (m == 1)
return 0;
while (a > 1) {
// q is quotient
ll q = a / m;
ll t = m;
// m is remainder now, process same as
// Euclid's algo
m = a % m, a = t;
t = y;
// Update y and x
y = x - q * y;
x = t;
}
// Make x positive
if (x < 0)
x += m0;
return x;
}
ll get(string s) {
ll res = 0;
for (int i = 0; i < s.length(); i++) {
res += s[i] - '0';
res *= 10;
}
return res / 10;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t = 1;
// cin>>t;
while (t--) {
ll n, m, i, j, ans = 0;
ll a[3][3], mark[3][3];
map<ll, pll> mp;
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
cin >> a[i][j];
mark[i][j] = 0;
mp[a[i][j]] = {i, j};
}
}
cin >> n;
while (n--) {
cin >> m;
if (mp.find(m) != mp.end()) {
auto it = mp.find(m);
mark[it->second.first][it->second.second] = 1;
}
}
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
a[i][j] = mark[i][j];
// cout<<mark[i][j]<<" ";
}
// cout<<"\n";
}
if (a[0][0] + a[0][1] + a[0][2] == 3 || a[1][0] + a[1][1] + a[1][2] == 3 ||
a[2][0] + a[2][1] + a[2][2] == 3 || a[0][0] + a[1][0] + a[2][0] == 3 ||
a[0][1] + a[1][1] + a[2][1] == 3 || a[0][2] + a[1][2] + a[2][2] == 3 ||
a[0][0] + a[1][1] + a[2][2] == 3 || a[0][2] + a[1][1] + a[2][0] == 3) {
cout << "Yes";
} else {
cout << "No\n";
}
}
return 0;
}
| #include <bits/stdc++.h>
#define MAXN 100005
#define mod 1000000007
#define inf LLONG_MAX / 3
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
ll power(ll x, ll y, ll m = mod) {
ll ans = 1;
while (y > 0) {
if (y & 1) {
ans = (ans * x) % m;
}
x = (x * x) % m;
y /= 2;
}
return ans % m;
}
ll modInverse(ll a, ll m = mod) {
ll m0 = m;
ll y = 0, x = 1;
if (m == 1)
return 0;
while (a > 1) {
// q is quotient
ll q = a / m;
ll t = m;
// m is remainder now, process same as
// Euclid's algo
m = a % m, a = t;
t = y;
// Update y and x
y = x - q * y;
x = t;
}
// Make x positive
if (x < 0)
x += m0;
return x;
}
ll get(string s) {
ll res = 0;
for (int i = 0; i < s.length(); i++) {
res += s[i] - '0';
res *= 10;
}
return res / 10;
}
int main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// #endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t = 1;
// cin>>t;
while (t--) {
ll n, m, i, j, ans = 0;
ll a[3][3], mark[3][3];
map<ll, pll> mp;
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
cin >> a[i][j];
mark[i][j] = 0;
mp[a[i][j]] = {i, j};
}
}
cin >> n;
while (n--) {
cin >> m;
if (mp.find(m) != mp.end()) {
auto it = mp.find(m);
mark[it->second.first][it->second.second] = 1;
}
}
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
a[i][j] = mark[i][j];
// cout<<mark[i][j]<<" ";
}
// cout<<"\n";
}
if (a[0][0] + a[0][1] + a[0][2] == 3 || a[1][0] + a[1][1] + a[1][2] == 3 ||
a[2][0] + a[2][1] + a[2][2] == 3 || a[0][0] + a[1][0] + a[2][0] == 3 ||
a[0][1] + a[1][1] + a[2][1] == 3 || a[0][2] + a[1][2] + a[2][2] == 3 ||
a[0][0] + a[1][1] + a[2][2] == 3 || a[0][2] + a[1][1] + a[2][0] == 3) {
cout << "Yes";
} else {
cout << "No\n";
}
}
return 0;
}
| replace | 60 | 63 | 60 | 63 | TLE | |
p02761 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int n, m;
vector<int> s;
vector<int> c;
bool ok(string str) {
if (str.length() != n)
return false;
for (int j = 0; j < m; j++) {
if (str.at(s.at(j)) != to_string(c.at(j)).at(0))
return false;
}
return true;
}
int main() {
cin >> n >> m;
s.resize(m), c.resize(m);
for (int i = 0; i < n; i++) {
cin >> s.at(i) >> c.at(i);
s.at(i)--;
}
for (int i = 0; i <= 999; i++) {
if (ok(to_string(i))) {
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
} | #include <algorithm>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int n, m;
vector<int> s;
vector<int> c;
bool ok(string str) {
if (str.length() != n)
return false;
for (int j = 0; j < m; j++) {
if (str.at(s.at(j)) != to_string(c.at(j)).at(0))
return false;
}
return true;
}
int main() {
cin >> n >> m;
s.resize(m), c.resize(m);
for (int i = 0; i < m; i++) {
cin >> s.at(i) >> c.at(i);
s.at(i)--;
}
for (int i = 0; i <= 999; i++) {
if (ok(to_string(i))) {
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
} | replace | 26 | 27 | 26 | 27 | 0 | |
p02761 | C++ | Runtime Error | #include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
#define int long long
#define inf 1000000007
#define pa pair<int, int>
#define ll long long
#define pal pair<double, double>
#define ppap pair<pa, int>
#define PI 3.14159265358979323846
#define paa pair<int, char>
#define mp make_pair
#define pb push_back
#define EPS (1e-8)
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, -1, 1, 1, -1};
using namespace std;
class pa3 {
public:
int x;
int y, z;
pa3(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {}
bool operator<(const pa3 &p) const {
if (x != p.x)
return x < p.x;
if (y != p.y)
return y < p.y;
return z < p.z;
// return x != p.x ? x<p.x: y<p.y;
}
bool operator>(const pa3 &p) const {
if (x != p.x)
return x > p.x;
if (y != p.y)
return y > p.y;
return z > p.z;
// return x != p.x ? x<p.x: y<p.y;
}
bool operator==(const pa3 &p) const {
return x == p.x && y == p.y && z == p.z;
}
bool operator!=(const pa3 &p) const {
return !(x == p.x && y == p.y && z == p.z);
}
};
class pa4 {
public:
int x;
int y, z, w;
pa4(int x = 0, int y = 0, int z = 0, int w = 0) : x(x), y(y), z(z), w(w) {}
bool operator<(const pa4 &p) const {
if (x != p.x)
return x < p.x;
if (y != p.y)
return y < p.y;
if (z != p.z)
return z < p.z;
return w < p.w;
// return x != p.x ? x<p.x: y<p.y;
}
bool operator>(const pa4 &p) const {
if (x != p.x)
return x > p.x;
if (y != p.y)
return y > p.y;
if (z != p.z)
return z > p.z;
return w > p.w;
// return x != p.x ? x<p.x: y<p.y;
}
bool operator==(const pa4 &p) const {
return x == p.x && y == p.y && z == p.z && w == p.w;
}
};
class pa2 {
public:
int x, y;
pa2(int x = 0, int y = 0) : x(x), y(y) {}
pa2 operator+(pa2 p) { return pa2(x + p.x, y + p.y); }
pa2 operator-(pa2 p) { return pa2(x - p.x, y - p.y); }
bool operator<(const pa2 &p) const { return y != p.y ? y < p.y : x < p.x; }
bool operator>(const pa2 &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const pa2 &p) const {
return abs(x - p.x) == 0 && abs(y - p.y) == 0;
}
bool operator!=(const pa2 &p) const {
return !(abs(x - p.x) == 0 && abs(y - p.y) == 0);
}
};
string itos(int i) {
ostringstream s;
s << i;
return s.str();
}
int gcd(int v, int b) {
if (v == 0)
return b;
if (b == 0)
return v;
if (v > b)
return gcd(b, v);
if (v == b)
return b;
if (b % v == 0)
return v;
return gcd(v, b % v);
}
int mod;
int extgcd(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int d = extgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
pa operator+(const pa &l, const pa &r) {
return {l.first + r.first, l.second + r.second};
}
pa operator-(const pa &l, const pa &r) {
return {l.first - r.first, l.second - r.second};
}
int pr[700100];
int inv[700010];
int beki(int wa, int rr, int warukazu) {
if (rr == 0)
return 1 % warukazu;
if (rr == 1)
return wa % warukazu;
wa %= warukazu;
if (rr % 2 == 1)
return ((ll)beki(wa, rr - 1, warukazu) * (ll)wa) % warukazu;
ll zx = beki(wa, rr / 2, warukazu);
return (zx * zx) % warukazu;
}
int comb(int nn, int rr) {
if (rr < 0 || rr > nn || nn < 0)
return 0;
int r = pr[nn] * inv[rr];
r %= mod;
r *= inv[nn - rr];
r %= mod;
return r;
}
void gya(int ert) {
pr[0] = 1;
for (int i = 1; i <= ert; i++) {
pr[i] = ((ll)pr[i - 1] * i) % mod;
}
inv[ert] = beki(pr[ert], mod - 2, mod);
for (int i = ert - 1; i >= 0; i--) {
inv[i] = (ll)inv[i + 1] * (i + 1) % mod;
}
}
// cin.tie(0);
// ios::sync_with_stdio(false);
// priority_queue<pa3,vector<pa3>,greater<pa3>> pq;
// sort(ve.begin(),ve.end(),greater<int>());
// mt19937(clock_per_sec);
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()) ;
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<pa> ve(m);
for (int i = 0; i < m; i++)
cin >> ve[i].first >> ve[i].second;
for (int i = 0; i <= 1000000; i++) {
string s = itos(i);
if (s.length() > n)
break;
if (s.length() < n)
continue;
bool bo = 1;
for (auto v : ve) {
if (s[v.first - 1] - '0' != ve[i].second) {
bo = 0;
}
}
if (bo) {
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
}
| #include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
#define int long long
#define inf 1000000007
#define pa pair<int, int>
#define ll long long
#define pal pair<double, double>
#define ppap pair<pa, int>
#define PI 3.14159265358979323846
#define paa pair<int, char>
#define mp make_pair
#define pb push_back
#define EPS (1e-8)
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, -1, 1, 1, -1};
using namespace std;
class pa3 {
public:
int x;
int y, z;
pa3(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {}
bool operator<(const pa3 &p) const {
if (x != p.x)
return x < p.x;
if (y != p.y)
return y < p.y;
return z < p.z;
// return x != p.x ? x<p.x: y<p.y;
}
bool operator>(const pa3 &p) const {
if (x != p.x)
return x > p.x;
if (y != p.y)
return y > p.y;
return z > p.z;
// return x != p.x ? x<p.x: y<p.y;
}
bool operator==(const pa3 &p) const {
return x == p.x && y == p.y && z == p.z;
}
bool operator!=(const pa3 &p) const {
return !(x == p.x && y == p.y && z == p.z);
}
};
class pa4 {
public:
int x;
int y, z, w;
pa4(int x = 0, int y = 0, int z = 0, int w = 0) : x(x), y(y), z(z), w(w) {}
bool operator<(const pa4 &p) const {
if (x != p.x)
return x < p.x;
if (y != p.y)
return y < p.y;
if (z != p.z)
return z < p.z;
return w < p.w;
// return x != p.x ? x<p.x: y<p.y;
}
bool operator>(const pa4 &p) const {
if (x != p.x)
return x > p.x;
if (y != p.y)
return y > p.y;
if (z != p.z)
return z > p.z;
return w > p.w;
// return x != p.x ? x<p.x: y<p.y;
}
bool operator==(const pa4 &p) const {
return x == p.x && y == p.y && z == p.z && w == p.w;
}
};
class pa2 {
public:
int x, y;
pa2(int x = 0, int y = 0) : x(x), y(y) {}
pa2 operator+(pa2 p) { return pa2(x + p.x, y + p.y); }
pa2 operator-(pa2 p) { return pa2(x - p.x, y - p.y); }
bool operator<(const pa2 &p) const { return y != p.y ? y < p.y : x < p.x; }
bool operator>(const pa2 &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const pa2 &p) const {
return abs(x - p.x) == 0 && abs(y - p.y) == 0;
}
bool operator!=(const pa2 &p) const {
return !(abs(x - p.x) == 0 && abs(y - p.y) == 0);
}
};
string itos(int i) {
ostringstream s;
s << i;
return s.str();
}
int gcd(int v, int b) {
if (v == 0)
return b;
if (b == 0)
return v;
if (v > b)
return gcd(b, v);
if (v == b)
return b;
if (b % v == 0)
return v;
return gcd(v, b % v);
}
int mod;
int extgcd(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int d = extgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
pa operator+(const pa &l, const pa &r) {
return {l.first + r.first, l.second + r.second};
}
pa operator-(const pa &l, const pa &r) {
return {l.first - r.first, l.second - r.second};
}
int pr[700100];
int inv[700010];
int beki(int wa, int rr, int warukazu) {
if (rr == 0)
return 1 % warukazu;
if (rr == 1)
return wa % warukazu;
wa %= warukazu;
if (rr % 2 == 1)
return ((ll)beki(wa, rr - 1, warukazu) * (ll)wa) % warukazu;
ll zx = beki(wa, rr / 2, warukazu);
return (zx * zx) % warukazu;
}
int comb(int nn, int rr) {
if (rr < 0 || rr > nn || nn < 0)
return 0;
int r = pr[nn] * inv[rr];
r %= mod;
r *= inv[nn - rr];
r %= mod;
return r;
}
void gya(int ert) {
pr[0] = 1;
for (int i = 1; i <= ert; i++) {
pr[i] = ((ll)pr[i - 1] * i) % mod;
}
inv[ert] = beki(pr[ert], mod - 2, mod);
for (int i = ert - 1; i >= 0; i--) {
inv[i] = (ll)inv[i + 1] * (i + 1) % mod;
}
}
// cin.tie(0);
// ios::sync_with_stdio(false);
// priority_queue<pa3,vector<pa3>,greater<pa3>> pq;
// sort(ve.begin(),ve.end(),greater<int>());
// mt19937(clock_per_sec);
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()) ;
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<pa> ve(m);
for (int i = 0; i < m; i++)
cin >> ve[i].first >> ve[i].second;
for (int i = 0; i <= 1000000; i++) {
string s = itos(i);
if (s.length() > n)
break;
if (s.length() < n)
continue;
bool bo = 1;
for (auto v : ve) {
if (s[v.first - 1] - '0' != v.second) {
bo = 0;
}
}
if (bo) {
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
}
| replace | 190 | 191 | 190 | 191 | 0 | |
p02761 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
// const ll MOD = ;
ll mod(ll A, ll M) { return (A % M + M) % M; }
const ll INF = 1LL << 60;
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll divceil(ll A, ll B) { return (A + (B - 1)) / B; }
ll myctoi(char C) { return C - '0'; }
char myitoc(ll N) { return '0' + N; }
#define FINALANS(A) \
do { \
cout << (A) << '\n'; \
exit(0); \
} while (false)
int main() {
ll N, M;
cin >> N >> M;
vector<ll> S(M), C(M);
for (ll i = 0; i < M; i++) {
cin >> S.at(i) >> C.at(i);
S.at(i)--;
}
for (ll n = 0; n < 1000; n++) {
string x = to_string(n);
if (x.size() != N)
continue;
bool ok = true;
for (ll i = 0; i < N; i++) {
if (x.at(S.at(i)) - '0' != C.at(i)) {
ok = false;
break;
}
}
if (ok)
FINALANS(n);
}
cout << -1 << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
// const ll MOD = ;
ll mod(ll A, ll M) { return (A % M + M) % M; }
const ll INF = 1LL << 60;
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll divceil(ll A, ll B) { return (A + (B - 1)) / B; }
ll myctoi(char C) { return C - '0'; }
char myitoc(ll N) { return '0' + N; }
#define FINALANS(A) \
do { \
cout << (A) << '\n'; \
exit(0); \
} while (false)
int main() {
ll N, M;
cin >> N >> M;
vector<ll> S(M), C(M);
for (ll i = 0; i < M; i++) {
cin >> S.at(i) >> C.at(i);
S.at(i)--;
}
for (ll n = 0; n < 1000; n++) {
string x = to_string(n);
if (x.size() != N)
continue;
bool ok = true;
for (ll i = 0; i < M; i++) {
if (x.at(S.at(i)) - '0' != C.at(i)) {
ok = false;
break;
}
}
if (ok)
FINALANS(n);
}
cout << -1 << endl;
} | replace | 46 | 47 | 46 | 47 | 0 | |
p02761 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
scanf("%d %d", &n, &m);
vector<int> p{1};
while (p.size() < n)
p.insert(p.begin(), p[0] * 10);
map<int, int> s;
int ans = 0;
while (m--) {
int a, b;
scanf("%d %d", &a, &b);
if (s.count(a)) {
if (s[a] != b)
return printf("-1\n"), 0;
} else {
s[a] = b;
ans += b * p[a - 1];
if (a == 1 and b == 0 and n > 1)
return printf("-1\n"), 0;
}
}
if (n > 1 and prev(s.end())->second == 0) {
ans += p[prev(s.end())->first - 2];
}
printf("%d\n", ans);
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
scanf("%d %d", &n, &m);
vector<int> p{1};
while (p.size() < n)
p.insert(p.begin(), p[0] * 10);
map<int, int> s;
int ans = 0;
while (m--) {
int a, b;
scanf("%d %d", &a, &b);
if (s.count(a)) {
if (s[a] != b)
return printf("-1\n"), 0;
} else {
s[a] = b;
ans += b * p[a - 1];
if (a == 1 and b == 0 and n > 1)
return printf("-1\n"), 0;
}
}
if (n > 1 and !s.count(1)) {
ans += p[0];
}
printf("%d\n", ans);
}
| replace | 26 | 28 | 26 | 28 | 0 | |
p02761 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define int long long
#define double long double
#define fo(a, b) for (int a = 0; a < b; a++)
#define Sort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(), a.end()), a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int, vector<int>, greater<int>>
#define PriP \
priority_queue<P<int, int>, vector<P<int, int>>, greater<P<int, int>>>
#define all(a) (a).begin(), (a).end()
int keta(int a) {
double b = a;
b = log10(b);
int c = b;
return c + 1;
}
signed main() {
int n, m;
cin >> n >> m;
V<P<int, int>> a(m);
fo(i, m) { cin >> a[i].fi >> a[i].se; }
Sort(a);
int b = 0;
fo(i, m - 1) {
if (a[i].fi == a[i + 1].fi && a[i].se != a[i].se)
b = 1;
}
if (b) {
cout << -1 << endl;
return 0;
}
uni(a);
if (n == 1 && a[0].se == 0) {
cout << 0 << endl;
return 0;
}
if (n == 2 || n == 3) {
fo(i, m) {
if (a[i].fi == 1 && a[i].se == 0) {
cout << -1 << endl;
return 0;
}
}
}
for (int i = 1; i <= 999; i++) {
if (keta(i) != n)
continue;
int d = 1;
string c = to_string(i);
fo(j, m) {
if (c[a[j].fi - 1] - '0' != a[j].se) {
d = 0;
}
}
if (d) {
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
} | #include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define int long long
#define double long double
#define fo(a, b) for (int a = 0; a < b; a++)
#define Sort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(), a.end()), a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int, vector<int>, greater<int>>
#define PriP \
priority_queue<P<int, int>, vector<P<int, int>>, greater<P<int, int>>>
#define all(a) (a).begin(), (a).end()
int keta(int a) {
double b = a;
b = log10(b);
int c = b;
return c + 1;
}
signed main() {
int n, m;
cin >> n >> m;
V<P<int, int>> a(m);
fo(i, m) { cin >> a[i].fi >> a[i].se; }
Sort(a);
int b = 0;
fo(i, m - 1) {
if (a[i].fi == a[i + 1].fi && a[i].se != a[i].se)
b = 1;
}
if (b) {
cout << -1 << endl;
return 0;
}
uni(a);
if (n == 1 && m == 0) {
cout << 0 << endl;
return 0;
}
if (n == 2 && m == 0) {
cout << 10 << endl;
return 0;
}
if (n == 3 && m == 0) {
cout << 100 << endl;
return 0;
}
if (n == 1 && a[0].se == 0) {
cout << 0 << endl;
return 0;
}
if (n == 2 || n == 3) {
fo(i, m) {
if (a[i].fi == 1 && a[i].se == 0) {
cout << -1 << endl;
return 0;
}
}
}
for (int i = 1; i <= 999; i++) {
if (keta(i) != n)
continue;
int d = 1;
string c = to_string(i);
fo(j, m) {
if (c[a[j].fi - 1] - '0' != a[j].se) {
d = 0;
}
}
if (d) {
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
}
| insert | 50 | 50 | 50 | 62 | 0 | |
p02761 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); i++)
int main() {
int N, M;
cin >> N >> M;
vector<int> seq(N, 0);
seq.at(0) = 1;
vector<int> position(M);
vector<int> change(M);
rep(i, M) { cin >> position.at(i) >> change.at(i); }
// 入力完了
int non = 0;
rep(i, M) {
rep(j, M) {
if (position.at(i) == position.at(j) && change.at(i) != change.at(j)) {
non++;
}
}
}
if (position.at(0) == 1 && change.at(0) == 0) {
if (N > 1)
non++;
}
rep(i, M) { seq.at(position.at(i) - 1) = change.at(i); }
if (non > 0)
cout << -1 << endl;
else if (N == 1 && M == 0)
cout << 0 << endl;
else {
rep(i, N) { cout << seq.at(i); }
cout << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); i++)
int main() {
int N, M;
cin >> N >> M;
vector<int> seq(N, 0);
seq.at(0) = 1;
vector<int> position(M + 10);
vector<int> change(M + 10);
rep(i, M) { cin >> position.at(i) >> change.at(i); }
// 入力完了
int non = 0;
rep(i, M) {
rep(j, M) {
if (position.at(i) == position.at(j) && change.at(i) != change.at(j)) {
non++;
}
}
}
if (position.at(0) == 1 && change.at(0) == 0) {
if (N > 1)
non++;
}
rep(i, M) { seq.at(position.at(i) - 1) = change.at(i); }
if (non > 0)
cout << -1 << endl;
else if (N == 1 && M == 0)
cout << 0 << endl;
else {
rep(i, N) { cout << seq.at(i); }
cout << endl;
}
} | replace | 8 | 10 | 8 | 10 | 0 | |
p02761 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = (0); i < (n); i++)
using namespace std;
typedef long long ll;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> s(m), c(m);
rep(i, m) cin >> s[i] >> c[i];
if (n == 1) {
int x = c[0];
rep(i, m) {
if (s[i] > n || c[i] != x) {
cout << -1 << endl;
return 0;
}
}
cout << x << endl;
} else {
int INF = 100;
vector<int> v(n, INF);
rep(i, m) {
if (s[i] > n) {
cout << -1 << endl;
return 0;
}
if (s[i] == 1 && c[i] == 0) {
cout << -1 << endl;
return 0;
}
if (v[s[i] - 1] != INF && v[s[i] - 1] != c[i]) {
cout << -1 << endl;
return 0;
}
v[s[i] - 1] = c[i];
}
int ans = 0;
int d = 1;
for (int i = n - 1; i >= 0; i--) {
if (v[i] == INF) {
if (i == 0)
ans += d;
} else {
ans += v[i] * d;
}
d *= 10;
}
cout << ans << endl;
}
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = (0); i < (n); i++)
using namespace std;
typedef long long ll;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
if (m == 0) {
if (n == 1) {
cout << 0 << endl;
return 0;
}
if (n == 2) {
cout << 10 << endl;
return 0;
}
if (n == 3) {
cout << 100 << endl;
return 0;
}
}
vector<int> s(m), c(m);
rep(i, m) cin >> s[i] >> c[i];
if (n == 1) {
int x = c[0];
rep(i, m) {
if (s[i] > n || c[i] != x) {
cout << -1 << endl;
return 0;
}
}
cout << x << endl;
} else {
int INF = 100;
vector<int> v(n, INF);
rep(i, m) {
if (s[i] > n) {
cout << -1 << endl;
return 0;
}
if (s[i] == 1 && c[i] == 0) {
cout << -1 << endl;
return 0;
}
if (v[s[i] - 1] != INF && v[s[i] - 1] != c[i]) {
cout << -1 << endl;
return 0;
}
v[s[i] - 1] = c[i];
}
int ans = 0;
int d = 1;
for (int i = n - 1; i >= 0; i--) {
if (v[i] == INF) {
if (i == 0)
ans += d;
} else {
ans += v[i] * d;
}
d *= 10;
}
cout << ans << endl;
}
} | insert | 13 | 13 | 13 | 30 | 0 | |
p02761 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll = long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define MOD 1000000007
const ll INF = 1e18;
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;
}
int main(int argc, char const *argv[]) {
int n, m;
cin >> n >> m;
vector<int> s(m), c(m);
rep(i, m) cin >> s[i] >> c[i];
int ans = -1;
for (int i = 1000; i >= 0; i--) {
string S = to_string(i);
bool ok = true;
if (sz(S) != n)
ok = false;
for (int j = 0; i < m; j++) {
if (S[s[j] - 1] != (char)(c[j] + '0'))
ok = false;
}
if (ok)
ans = i;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll = long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define MOD 1000000007
const ll INF = 1e18;
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;
}
int main(int argc, char const *argv[]) {
int n, m;
cin >> n >> m;
vector<int> s(m), c(m);
rep(i, m) cin >> s[i] >> c[i];
int ans = -1;
for (int i = 1000; i >= 0; i--) {
string S = to_string(i);
bool ok = true;
if (sz(S) != n)
ok = false;
for (int j = 0; j < m; j++) {
if (S[s[j] - 1] != (char)(c[j] + '0'))
ok = false;
}
if (ok)
ans = i;
}
cout << ans << endl;
return 0;
}
| replace | 40 | 41 | 40 | 41 | -11 | |
p02761 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> S(M);
vector<char> C(M);
for (int i = 0; i < M; i++) {
cin >> S.at(i) >> C.at(i);
}
int loop_start;
int loop_end;
if (N == 1) {
loop_start = 0;
loop_end = 10;
} else if (N == 2) {
loop_start = 10;
loop_end = 100;
} else if (N == 3) {
loop_start = 100;
loop_end = 1000;
}
bool flag = false;
int result = 1000;
for (int i = loop_start; i < loop_end; i++) {
string strwk = to_string(i);
for (int j = 0; j < M; j++) {
if (strwk.at(S.at(j)) == C.at(j)) {
if (j == M - 1) {
flag = true;
result = min(result, i);
}
} else
break;
}
}
if (M == 0) {
if (N == 1)
cout << 0 << endl;
else if (N == 2)
cout << 10 << endl;
else if (N == 3)
cout << 100 << endl;
} else if (flag)
cout << result << endl;
else
cout << -1 << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> S(M);
vector<char> C(M);
for (int i = 0; i < M; i++) {
cin >> S.at(i) >> C.at(i);
}
int loop_start;
int loop_end;
if (N == 1) {
loop_start = 0;
loop_end = 10;
} else if (N == 2) {
loop_start = 10;
loop_end = 100;
} else if (N == 3) {
loop_start = 100;
loop_end = 1000;
}
bool flag = false;
int result = 1000;
for (int i = loop_start; i < loop_end; i++) {
string strwk = to_string(i);
for (int j = 0; j < M; j++) {
if (strwk.at(S.at(j) - 1) == C.at(j)) {
if (j == M - 1) {
flag = true;
result = min(result, i);
}
} else
break;
}
}
if (M == 0) {
if (N == 1)
cout << 0 << endl;
else if (N == 2)
cout << 10 << endl;
else if (N == 3)
cout << 100 << endl;
} else if (flag)
cout << result << endl;
else
cout << -1 << endl;
return 0;
}
| replace | 34 | 35 | 34 | 35 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 3) >= this->size() (which is 3)
|
p02761 | C++ | Runtime Error | #include <iostream>
using namespace std;
#define MAX_N 3
#define MAX_M 5
int main() {
int N, M, s[MAX_M], c[MAX_M];
cin >> N >> M;
for (int i = 0; i < M; i++) {
cin >> s[i] >> c[i];
}
// N > 1のとき、先頭が0ではいけない
if (N > 1) {
for (int i = 0; i < M; i++) {
if (s[i] == 1 && c[i] == 0) {
cout << -1 << endl;
return 0;
}
}
}
// i桁目の暫定の値
int a[MAX_N];
for (int i = 0; i < N; i++) {
a[i] = -1; // 未指定の桁は-1としておく
}
// ある桁について異なる値を指定してはいけない
for (int i = 0; i < M; i++) {
// まだ指定されていない桁ならば
if (a[s[i] - 1] == -1) {
a[s[i] - 1] = c[i];
}
// 既に指定されている桁ならば
else {
// 異なる値を指定してはいけない
if (a[s[i] - 1] != c[i]) {
cout << -1 << endl;
return -1;
}
}
}
if (N == 1) {
if (a[0] == -1) {
cout << 0 << endl;
} else {
cout << a[0] << endl;
}
return 0;
}
int ans;
if (a[0] == -1) {
ans = 1;
} else {
ans = a[0];
}
for (int i = 1; i < N; i++) {
ans *= 10;
if (a[i] != -1) {
ans += a[i];
}
}
cout << ans << endl;
return 0;
} | #include <iostream>
using namespace std;
#define MAX_N 3
#define MAX_M 5
int main() {
int N, M, s[MAX_M], c[MAX_M];
cin >> N >> M;
for (int i = 0; i < M; i++) {
cin >> s[i] >> c[i];
}
// N > 1のとき、先頭が0ではいけない
if (N > 1) {
for (int i = 0; i < M; i++) {
if (s[i] == 1 && c[i] == 0) {
cout << -1 << endl;
return 0;
}
}
}
// i桁目の暫定の値
int a[MAX_N];
for (int i = 0; i < N; i++) {
a[i] = -1; // 未指定の桁は-1としておく
}
// ある桁について異なる値を指定してはいけない
for (int i = 0; i < M; i++) {
// まだ指定されていない桁ならば
if (a[s[i] - 1] == -1) {
a[s[i] - 1] = c[i];
}
// 既に指定されている桁ならば
else {
// 異なる値を指定してはいけない
if (a[s[i] - 1] != c[i]) {
cout << -1 << endl;
return 0;
}
}
}
if (N == 1) {
if (a[0] == -1) {
cout << 0 << endl;
} else {
cout << a[0] << endl;
}
return 0;
}
int ans;
if (a[0] == -1) {
ans = 1;
} else {
ans = a[0];
}
for (int i = 1; i < N; i++) {
ans *= 10;
if (a[i] != -1) {
ans += a[i];
}
}
cout << ans << endl;
return 0;
} | replace | 40 | 41 | 40 | 41 | 0 | |
p02761 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int s[10];
char c[10];
for (int i = 0; i < n; i++) {
cin >> s[i] >> c[i];
}
bool isok = false;
int start[3] = {0, 10, 100};
int end[3] = {9, 99, 999};
int ans = -1;
for (int i = start[n - 1]; i <= end[n - 1]; i++) {
string str = to_string(i);
bool isok = true;
for (int j = 0; j < m; j++) {
if (str[s[j] - 1] != c[j]) {
isok = false;
break;
}
}
if (isok) {
ans = i;
break;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int s[10];
char c[10];
for (int i = 0; i < m; i++) {
cin >> s[i] >> c[i];
}
bool isok = false;
int start[3] = {0, 10, 100};
int end[3] = {9, 99, 999};
int ans = -1;
for (int i = start[n - 1]; i <= end[n - 1]; i++) {
string str = to_string(i);
bool isok = true;
for (int j = 0; j < m; j++) {
if (str[s[j] - 1] != c[j]) {
isok = false;
break;
}
}
if (isok) {
ans = i;
break;
}
}
cout << ans << endl;
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02761 | C++ | Runtime Error | #pragma region template
#include <bits/stdc++.h>
using namespace std;
// -type-
using str = string;
using ll = int64_t;
using pii = pair<int64_t, int64_t>;
using pis = pair<int64_t, str>;
using psi = pair<str, int64_t>;
using vi = vector<int64_t>;
using vvi = vector<vector<int64_t>>;
using vs = vector<str>;
using vpii = vector<pair<int64_t, int64_t>>;
//--const
constexpr ll MOD = 1000000007;
constexpr int INFI = int(0x3f000000);
constexpr ll INF = ll(0x3f0000003f000000);
constexpr double EPS = 1e-9;
constexpr int dx[] = {0, 1, 0, -1, 1, -1, 1, -1},
dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
// clang-format off
//--define
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2,)(__VA_ARGS__)
#define repc(...) _overload3(__VA_ARGS__, _repc3, _repc2,)(__VA_ARGS__)
#define repr(...) _overload3(__VA_ARGS__, _repr3, _repr2,)(__VA_ARGS__)
#define repcr(...) _overload3(__VA_ARGS__,_repcr3,_repcr2,)(__VA_ARGS__)
#define _rep(i,k,n) for(int i=(k) , i##_len=(n); i < i##_len; ++i)
#define _rep2(i ,n) _rep(i,0,n)
#define _rep3(i,k,n) _rep(i,k,n)
#define _repc2(i ,n) _rep(i,1,n+1)
#define _repc3(i,k,n) _rep(i,k,n+1)
#define _repr(i,k,n) for(int i=(n-1), i##_len=(k); i >=i##_len; --i)
#define _repr2(i ,n) _repr(i,0,n)
#define _repr3(i,k,n) _repr(i,k,n)
#define _repcr2(i ,n) _repr(i,1,n+1)
#define _repcr3(i,k,n) _repr(i,k,n+1)
//rep-macro normal, close, reverse, close+reverse
#define all(o) begin(o), end(o)
#define sz(a) ((int)(a).size())
#define debug(...) debug_args(__LINE__, __VA_ARGS__)
#define pow2(n) (1LL<<(n))
//--functions
inline bool in(string s, string c) {return (s.find(c) != string::npos);}
inline bool in(string s, char c) {return (s.find(c) != string::npos);}
template <class T> T udiv(T a, T b) {return (a + b - 1) / b;}
template <class T> T rdiv(T a, T b) {return (a + b / 2) / b;}
void print_args(ostream&) {}
template <class S, class... T>
void print_args(ostream& out,const S& a,const T&... args) {
out << ' ' << a;
print_args(out, args...);
}
template <class S, class... T>
void print(const S& a, const T&... args) {
std::cout << a;
print_args(std::cout, args...);
std::cout << '\n';
}
template <class S, class... T>
void debug_args(const S& a, const T&... args) {
std::cout << "(L:" << std::setw(3) << a << ")";
print_args(std::cout, args...);
std::cout << '\n';
}
// clang-format on
struct setup_main {
setup_main() {
std::cin.tie(0);
std::ios::sync_with_stdio(0);
std::cout << fixed << setprecision(15);
}
} setup_main_;
ll ans(-1);
#pragma endregion
int solve(long long N, long long M, std::vector<long long> s,
std::vector<long long> c) {
if (N == 1) {
sort(all(c));
c.erase(unique(all(c)), c.end());
if (c.size() > 1)
return -1;
else
return c[0];
}
rep(i, M) if (s[i] == 1 and c[i] == 0) return -1;
array<int, 4> i = {0, 0, 0, 0};
if (N == 2) {
for (i[1] = 1; i[1] < 10; i[1]++) {
for (i[2] = 0; i[2] < 10; i[2]++) {
ll ii = i[1] * 10 + i[2];
rep(j, M) {
if (i[s[j]] != c[j])
ii = 0;
}
if (ii != 0)
return ii;
}
}
}
if (N == 3) {
for (i[1] = 1; i[1] < 10; i[1]++) {
for (i[2] = 0; i[2] < 10; i[2]++) {
for (i[3] = 0; i[3] < 10; i[3]++) {
ll ii = i[1] * 100 + i[2] * 10 + i[3];
rep(j, M) {
if (i[s[j]] != c[j])
ii = 0;
}
if (ii != 0)
return ii;
}
}
}
}
return (-1);
}
signed main() {
long long N;
scanf("%lld", &N);
long long M;
scanf("%lld", &M);
std::vector<long long> s(M);
std::vector<long long> c(M);
for (int i = 0; i < M; i++) {
scanf("%lld", &s[i]);
scanf("%lld", &c[i]);
}
print(solve(N, M, std::move(s), std::move(c)));
return 0;
}
| #pragma region template
#include <bits/stdc++.h>
using namespace std;
// -type-
using str = string;
using ll = int64_t;
using pii = pair<int64_t, int64_t>;
using pis = pair<int64_t, str>;
using psi = pair<str, int64_t>;
using vi = vector<int64_t>;
using vvi = vector<vector<int64_t>>;
using vs = vector<str>;
using vpii = vector<pair<int64_t, int64_t>>;
//--const
constexpr ll MOD = 1000000007;
constexpr int INFI = int(0x3f000000);
constexpr ll INF = ll(0x3f0000003f000000);
constexpr double EPS = 1e-9;
constexpr int dx[] = {0, 1, 0, -1, 1, -1, 1, -1},
dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
// clang-format off
//--define
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2,)(__VA_ARGS__)
#define repc(...) _overload3(__VA_ARGS__, _repc3, _repc2,)(__VA_ARGS__)
#define repr(...) _overload3(__VA_ARGS__, _repr3, _repr2,)(__VA_ARGS__)
#define repcr(...) _overload3(__VA_ARGS__,_repcr3,_repcr2,)(__VA_ARGS__)
#define _rep(i,k,n) for(int i=(k) , i##_len=(n); i < i##_len; ++i)
#define _rep2(i ,n) _rep(i,0,n)
#define _rep3(i,k,n) _rep(i,k,n)
#define _repc2(i ,n) _rep(i,1,n+1)
#define _repc3(i,k,n) _rep(i,k,n+1)
#define _repr(i,k,n) for(int i=(n-1), i##_len=(k); i >=i##_len; --i)
#define _repr2(i ,n) _repr(i,0,n)
#define _repr3(i,k,n) _repr(i,k,n)
#define _repcr2(i ,n) _repr(i,1,n+1)
#define _repcr3(i,k,n) _repr(i,k,n+1)
//rep-macro normal, close, reverse, close+reverse
#define all(o) begin(o), end(o)
#define sz(a) ((int)(a).size())
#define debug(...) debug_args(__LINE__, __VA_ARGS__)
#define pow2(n) (1LL<<(n))
//--functions
inline bool in(string s, string c) {return (s.find(c) != string::npos);}
inline bool in(string s, char c) {return (s.find(c) != string::npos);}
template <class T> T udiv(T a, T b) {return (a + b - 1) / b;}
template <class T> T rdiv(T a, T b) {return (a + b / 2) / b;}
void print_args(ostream&) {}
template <class S, class... T>
void print_args(ostream& out,const S& a,const T&... args) {
out << ' ' << a;
print_args(out, args...);
}
template <class S, class... T>
void print(const S& a, const T&... args) {
std::cout << a;
print_args(std::cout, args...);
std::cout << '\n';
}
template <class S, class... T>
void debug_args(const S& a, const T&... args) {
std::cout << "(L:" << std::setw(3) << a << ")";
print_args(std::cout, args...);
std::cout << '\n';
}
// clang-format on
struct setup_main {
setup_main() {
std::cin.tie(0);
std::ios::sync_with_stdio(0);
std::cout << fixed << setprecision(15);
}
} setup_main_;
ll ans(-1);
#pragma endregion
int solve(long long N, long long M, std::vector<long long> s,
std::vector<long long> c) {
if (N == 1) {
if (M == 0)
return 0;
sort(all(c));
c.erase(unique(all(c)), c.end());
if (c.size() > 1)
return -1;
else
return c[0];
}
rep(i, M) if (s[i] == 1 and c[i] == 0) return -1;
array<int, 4> i = {0, 0, 0, 0};
if (N == 2) {
for (i[1] = 1; i[1] < 10; i[1]++) {
for (i[2] = 0; i[2] < 10; i[2]++) {
ll ii = i[1] * 10 + i[2];
rep(j, M) {
if (i[s[j]] != c[j])
ii = 0;
}
if (ii != 0)
return ii;
}
}
}
if (N == 3) {
for (i[1] = 1; i[1] < 10; i[1]++) {
for (i[2] = 0; i[2] < 10; i[2]++) {
for (i[3] = 0; i[3] < 10; i[3]++) {
ll ii = i[1] * 100 + i[2] * 10 + i[3];
rep(j, M) {
if (i[s[j]] != c[j])
ii = 0;
}
if (ii != 0)
return ii;
}
}
}
}
return (-1);
}
signed main() {
long long N;
scanf("%lld", &N);
long long M;
scanf("%lld", &M);
std::vector<long long> s(M);
std::vector<long long> c(M);
for (int i = 0; i < M; i++) {
scanf("%lld", &s[i]);
scanf("%lld", &c[i]);
}
print(solve(N, M, std::move(s), std::move(c)));
return 0;
}
| insert | 92 | 92 | 92 | 94 | 0 | |
p02761 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> s(M), c(M);
for (int i = 0; i < N; ++i)
cin >> s[i] >> c[i], s[i]--;
auto ok = [&](int n) -> bool {
string S = to_string(n);
if (S.size() != N)
return false;
for (int i = 0; i < M; ++i) {
if (S[s[i]] != ('0' + c[i]))
return false;
}
return true;
};
for (int i = 0; i < 1010; ++i) {
if (ok(i)) {
cout << i << '\n';
return 0;
}
}
cout << -1 << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> s(M), c(M);
for (int i = 0; i < M; ++i)
cin >> s[i] >> c[i], s[i]--;
auto ok = [&](int n) -> bool {
string S = to_string(n);
if (S.size() != N)
return false;
for (int i = 0; i < M; ++i) {
if (S[s[i]] != ('0' + c[i]))
return false;
}
return true;
};
for (int i = 0; i < 1010; ++i) {
if (ok(i)) {
cout << i << '\n';
return 0;
}
}
cout << -1 << '\n';
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02761 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t N, M, t = 0;
cin >> N >> M;
vector<int> s(M), c(M);
for (int64_t i = 0; i < M; i++) {
cin >> s.at(i) >> c.at(i);
}
if (N = 1) {
for (int64_t j = 0; j < M; j++) {
if (c.at(j) != 0) {
t = 1;
break;
}
}
if (t == 0) {
cout << 0 << endl;
return 0;
}
}
for (int64_t i = pow(10, N - 1); i < pow(10, N); i++) {
t = 0;
for (int64_t j = 0; j < M; j++) {
if (i / (int)pow(10, N - s.at(j)) -
(i / (int)pow(10, N - s.at(j) + 1)) * 10 !=
c.at(j)) {
t = 1;
break;
}
}
if (t == 0) {
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t N, M, t = 0;
cin >> N >> M;
vector<int> s(M), c(M);
for (int64_t i = 0; i < M; i++) {
cin >> s.at(i) >> c.at(i);
}
if (N == 1) {
for (int64_t j = 0; j < M; j++) {
if (c.at(j) != 0) {
t = 1;
break;
}
}
if (t == 0) {
cout << 0 << endl;
return 0;
}
}
for (int64_t i = pow(10, N - 1); i < pow(10, N); i++) {
t = 0;
for (int64_t j = 0; j < M; j++) {
if (i / (int)pow(10, N - s.at(j)) -
(i / (int)pow(10, N - s.at(j) + 1)) * 10 !=
c.at(j)) {
t = 1;
break;
}
}
if (t == 0) {
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
} | replace | 10 | 11 | 10 | 11 | -8 | |
p02761 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int power(int n) {
if (n == 0)
return 0;
int res = 1;
rep(i, n) res *= 10;
return res;
}
bool check(int n, int s, int c) {
vector<int> v;
while (n) {
v.push_back(n % 10);
n /= 10;
}
reverse(all(v));
// rep(i, v.size()) cout << v[i] << " ";
if (v[s - 1] == c)
return true;
else
return false;
}
int main() {
int n, m;
cin >> n >> m;
vector<int> s(m), c(m);
rep(i, m) cin >> s[i] >> c[i];
for (int i = power(n - 1); i < power(n); i++) {
bool ok = true;
rep(j, m) {
if (!check(i, s[j], c[j]))
ok = false;
}
// cout << i << endl;
if (ok) {
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int power(int n) {
if (n == 0)
return 0;
int res = 1;
rep(i, n) res *= 10;
return res;
}
bool check(int n, int s, int c) {
vector<int> v;
if (n == 0)
v.push_back(0);
else
while (n) {
v.push_back(n % 10);
n /= 10;
}
reverse(all(v));
// rep(i, v.size()) cout << v[i] << " ";
if (v[s - 1] == c)
return true;
else
return false;
}
int main() {
int n, m;
cin >> n >> m;
vector<int> s(m), c(m);
rep(i, m) cin >> s[i] >> c[i];
for (int i = power(n - 1); i < power(n); i++) {
bool ok = true;
rep(j, m) {
if (!check(i, s[j], c[j]))
ok = false;
}
// cout << i << endl;
if (ok) {
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
} | replace | 16 | 20 | 16 | 23 | 0 | |
p02761 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
int n, m;
cin >> n >> m;
vi s(m);
vector<char> c(m);
rep(i, m) { cin >> s.at(i) >> c.at(i); }
int a, b;
if (n == 1) {
a = 0;
b = 10;
} else {
a = 1;
rep(i, n - 1) { a *= 10; }
b = a * 10;
}
for (int i = a; i < b; i++) {
string S = to_string(i);
int j = 0;
while (true) {
if (S.at(s.at(j) - 1) != c.at(j)) {
break;
} else if (j == m - 1) {
cout << S << endl;
return 0;
}
j++;
}
}
cout << -1 << endl;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
int n, m;
cin >> n >> m;
vi s(m);
vector<char> c(m);
rep(i, m) { cin >> s.at(i) >> c.at(i); }
int a, b;
if (n == 1) {
a = 0;
b = 10;
} else {
a = 1;
rep(i, n - 1) { a *= 10; }
b = a * 10;
}
if (m == 0) {
cout << a << endl;
return 0;
}
for (int i = a; i < b; i++) {
string S = to_string(i);
int j = 0;
while (true) {
if (S.at(s.at(j) - 1) != c.at(j)) {
break;
} else if (j == m - 1) {
cout << S << endl;
return 0;
}
j++;
}
}
cout << -1 << endl;
}
| insert | 22 | 22 | 22 | 26 | 0 | |
p02761 | C++ | Runtime Error | // SmartCoder
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))
#define uns(v) \
sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007
const double pi = acos(-1.0);
const double eps = 1e-11;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
indexed_set;
int main() {
std::ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, s, c;
cin >> n >> m;
vector<int> nm(n, -1);
bool found = true;
for (int i = 0; i < m; i++) {
cin >> s >> c;
s--;
if (nm[s] != -1 && (nm[s] != c)) {
found = false;
}
nm[s] = c;
}
if (!found) {
cout << "-1\n";
return 0;
}
if (n == 1) {
cout << (nm[s] == -1 ? 0 : nm[s]) << "\n";
}
if (n == 2) {
if (nm[0] == 0) {
cout << "-1\n";
return 0;
}
if (nm[0] == -1)
nm[0] = 1;
if (nm[1] == -1)
nm[1] = 0;
cout << nm[0] * 10 + nm[1] << "\n";
}
if (n == 3) {
if (nm[0] == 0) {
cout << "-1\n";
return 0;
}
if (nm[0] == -1)
nm[0] = 1;
if (nm[1] == -1)
nm[1] = 0;
if (nm[2] == -1)
nm[2] = 0;
cout << nm[0] * 100 + nm[1] * 10 + nm[2] << "\n";
}
return 0;
}
| // SmartCoder
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))
#define uns(v) \
sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007
const double pi = acos(-1.0);
const double eps = 1e-11;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
indexed_set;
int main() {
std::ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, s, c;
cin >> n >> m;
vector<int> nm(n, -1);
bool found = true;
for (int i = 0; i < m; i++) {
cin >> s >> c;
s--;
if (nm[s] != -1 && (nm[s] != c)) {
found = false;
}
nm[s] = c;
}
if (!found) {
cout << "-1\n";
return 0;
}
if (n == 1) {
cout << (nm[0] == -1 ? 0 : nm[0]) << "\n";
}
if (n == 2) {
if (nm[0] == 0) {
cout << "-1\n";
return 0;
}
if (nm[0] == -1)
nm[0] = 1;
if (nm[1] == -1)
nm[1] = 0;
cout << nm[0] * 10 + nm[1] << "\n";
}
if (n == 3) {
if (nm[0] == 0) {
cout << "-1\n";
return 0;
}
if (nm[0] == -1)
nm[0] = 1;
if (nm[1] == -1)
nm[1] = 0;
if (nm[2] == -1)
nm[2] = 0;
cout << nm[0] * 100 + nm[1] * 10 + nm[2] << "\n";
}
return 0;
}
| replace | 63 | 64 | 63 | 64 | 0 | |
p02761 | Python | Runtime Error | def main():
N, M = map(int, input().split())
P = {tuple(map(int, input().split())) for _ in range(M)}
P = sorted(P)
ans = [0 for _ in range(N)]
if N > 1 and (1, 0) in P:
print(-1)
return
if N > 1 and P[0][0] != 1:
ans[0] = 1
for i in range(len(P) - 1):
if P[i][0] == P[i + 1][0]:
print(-1)
return
for p in P:
ans[p[0] - 1] = p[1]
print("".join(map(str, ans)))
if __name__ == "__main__":
main()
| def main():
N, M = map(int, input().split())
P = {tuple(map(int, input().split())) for _ in range(M)}
P = sorted(P)
ans = [0 for _ in range(N)]
if N == 1 and M == 0:
print(0)
return
if N == 2 and M == 0:
print(10)
return
if N == 3 and M == 0:
print(100)
return
if N > 1 and (1, 0) in P:
print(-1)
return
if N > 1 and P[0][0] != 1:
ans[0] = 1
for i in range(len(P) - 1):
if P[i][0] == P[i + 1][0]:
print(-1)
return
for p in P:
ans[p[0] - 1] = p[1]
print("".join(map(str, ans)))
if __name__ == "__main__":
main()
| insert | 5 | 5 | 5 | 17 | 0 | |
p02761 | C++ | Runtime Error | #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];
vector<vector<int>> c(n);
rep(i, m) c[a[i] - 1].push_back(b[i]);
if (n > 1 && c[0].size() == 0)
c[0].push_back(1);
if (n > 1)
rep2(i, 1, n) if (c[i].size() == 0) c[i].push_back(0);
int key = 0;
rep(i, n) rep(j, c[i].size()) if (c[i][j] != c[i][0]) key = 1;
if (key == 1 || (n > 1 && c[0][0] == 0))
cout << -1 << endl;
else if (n == 3)
cout << 100 * c[0][0] + 10 * c[1][0] + c[2][0] << endl;
else if (n == 2)
cout << 10 * c[0][0] + c[1][0] << endl;
else
cout << c[0][0] << 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];
vector<vector<int>> c(n);
rep(i, m) c[a[i] - 1].push_back(b[i]);
if (n > 1 && c[0].size() == 0)
c[0].push_back(1);
if (n == 1 && c[0].size() == 0)
c[0].push_back(0);
if (n > 1)
rep2(i, 1, n) if (c[i].size() == 0) c[i].push_back(0);
int key = 0;
rep(i, n) rep(j, c[i].size()) if (c[i][j] != c[i][0]) key = 1;
if (key == 1 || (n > 1 && c[0][0] == 0))
cout << -1 << endl;
else if (n == 3)
cout << 100 * c[0][0] + 10 * c[1][0] + c[2][0] << endl;
else if (n == 2)
cout << 10 * c[0][0] + c[1][0] << endl;
else
cout << c[0][0] << endl;
} | insert | 28 | 28 | 28 | 30 | 0 | |
p02761 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll, ll>>
#define pii pair<int, int>
#define REP(i, a) for (int(i) = 0; (i) < (a); (i)++)
#define RREP(i, a) for (int(i) = a - 1; (i) >= (0); (i)--)
#define REP2(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x, 0, sizeof(x))
typedef long long ll;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, M;
cin >> N >> M;
int s[M], c[M];
REP(i, M) cin >> s[i] >> c[i];
int keta = 0;
int ans = 999999;
REP(now, 1000) {
keta = 0;
int tmp = now;
bool flg = true;
while (tmp > 0) {
tmp /= 10;
keta++;
}
if (now = 0)
keta = 1;
if (keta != N)
continue;
int cnt[keta];
tmp = now;
REP(i, 3) {
cnt[i] = tmp % 10;
tmp /= 10;
}
REP(i, M) {
if (cnt[N - s[i]] != c[i]) {
flg = false;
continue;
}
}
if (flg)
ans = min(now, ans);
}
if (ans == 999999)
cout << "-1";
else
cout << ans;
return 0;
} | #include <bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll, ll>>
#define pii pair<int, int>
#define REP(i, a) for (int(i) = 0; (i) < (a); (i)++)
#define RREP(i, a) for (int(i) = a - 1; (i) >= (0); (i)--)
#define REP2(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x, 0, sizeof(x))
typedef long long ll;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, M;
cin >> N >> M;
int s[M], c[M];
REP(i, M) cin >> s[i] >> c[i];
int keta = 0;
int ans = 999999;
REP(now, 1000) {
keta = 0;
int tmp = now;
bool flg = true;
while (tmp > 0) {
tmp /= 10;
keta++;
}
if (now == 0)
keta = 1;
if (keta != N)
continue;
int cnt[keta];
tmp = now;
REP(i, 3) {
cnt[i] = tmp % 10;
tmp /= 10;
}
REP(i, M) {
if (cnt[N - s[i]] != c[i]) {
flg = false;
continue;
}
}
if (flg)
ans = min(now, ans);
}
if (ans == 999999)
cout << "-1";
else
cout << ans;
return 0;
} | replace | 32 | 33 | 32 | 33 | TLE | |
p02761 | Python | Runtime Error | n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
for x in range(1000):
ok = True
s = str(x)
if len(s) != n:
continue
if not all([int(s[a[i][0] - 1]) == a[i][1] for i in range(m)]):
continue
print(x)
exit(1)
print(-1)
| n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
for x in range(1000):
ok = True
s = str(x)
if len(s) != n:
continue
if not all([int(s[a[i][0] - 1]) == a[i][1] for i in range(m)]):
continue
print(x)
exit(0)
print(-1)
| replace | 11 | 12 | 11 | 12 | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.