Datasets:

problem_id
stringlengths
6
6
buggy_code
stringlengths
8
526k
fixed_code
stringlengths
12
526k
labels
listlengths
0
15
buggy_submission_id
int64
1
1.54M
fixed_submission_id
int64
2
1.54M
user_id
stringlengths
10
10
language
stringclasses
9 values
p03112
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(void) { const ll MINUSINF = -1e11; const ll INF = 1e11; int A, B; int Q; cin >> A >> B; cin >> Q; ll s[A + 2], t[B + 2]; s[0] = MINUSINF; s[A + 1] = INF; t[0] = MINUSINF; t[A + 1] = INF; for (int i = 1; i <= A; i++) cin >> s[i]; for (int i = 1; i <= B; i++) cin >> t[i]; for (int i = 0; i < Q; i++) { ll x; cin >> x; ll *lA, *rA; rA = upper_bound(s, s + A + 2, x); lA = rA - 1; ll *lB, *rB; rB = upper_bound(t, t + B + 2, x); lB = rB - 1; ll ans = 0; ans = abs(x - *lA) + abs(*lA - *lB); // lA -> lB ans = min(ans, abs(x - *lA) + abs(*lA - *rB)); // lA -> rB ans = min(ans, abs(x - *rA) + abs(*rA - *lB)); // rA -> lB ans = min(ans, abs(x - *rA) + abs(*rA - *rB)); // rA -> rB ans = min(ans, abs(x - *lB) + abs(*lB - *lA)); // lB -> lA ans = min(ans, abs(x - *lB) + abs(*lB - *rA)); // lB -> rA ans = min(ans, abs(x - *rB) + abs(*rB - *lA)); // rB -> lA ans = min(ans, abs(x - *rB) + abs(*rB - *rA)); // rB -> rA printf("lld\n", ans); // cout << ans << endl; // cout << "x: " << x << ", lA: " << *lA << ", rA: " << *rA << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(void) { const ll MINUSINF = -1e11; const ll INF = 1e11; int A, B; int Q; cin >> A >> B; cin >> Q; ll s[A + 2], t[B + 2]; s[0] = MINUSINF; s[A + 1] = INF; t[0] = MINUSINF; t[A + 1] = INF; for (int i = 1; i <= A; i++) cin >> s[i]; for (int i = 1; i <= B; i++) cin >> t[i]; for (int i = 0; i < Q; i++) { ll x; cin >> x; ll *lA, *rA; rA = upper_bound(s, s + A + 1, x); lA = rA - 1; ll *lB, *rB; rB = upper_bound(t, t + B + 1, x); lB = rB - 1; ll ans = 0; ans = abs(x - *lA) + abs(*lA - *lB); // lA -> lB ans = min(ans, abs(x - *lA) + abs(*lA - *rB)); // lA -> rB ans = min(ans, abs(x - *rA) + abs(*rA - *lB)); // rA -> lB ans = min(ans, abs(x - *rA) + abs(*rA - *rB)); // rA -> rB ans = min(ans, abs(x - *lB) + abs(*lB - *lA)); // lB -> lA ans = min(ans, abs(x - *lB) + abs(*lB - *rA)); // lB -> rA ans = min(ans, abs(x - *rB) + abs(*rB - *lA)); // rB -> lA ans = min(ans, abs(x - *rB) + abs(*rB - *rA)); // rB -> rA printf("%lld\n", ans); // cout << ans << endl; // cout << "x: " << x << ", lA: " << *lA << ", rA: " << *rA << endl; } return 0; }
[ "literal.number.change", "assignment.value.change", "call.arguments.change", "expression.operation.binary.change", "literal.string.change", "io.output.change" ]
924,480
924,479
u998251394
cpp
p03112
// // main.cpp // #include <algorithm> #include <array> #include <assert.h> #include <iostream> #include <limits> #include <math.h> #include <memory> #include <queue> #include <random> #include <set> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using ll = long long; using ull = unsigned long long; template <typename Monoid> struct SegmentTree { using Op = function<Monoid(const Monoid &lhs, const Monoid &rhs)>; size_t width; vector<Monoid> node; Op op; Monoid unit; SegmentTree(const vector<Monoid> &elems, Op op, Monoid unit) : op(op), unit(unit) { width = 1; while (width < elems.size()) { width *= 2; } node.resize(2 * width - 1, unit); for (size_t i = 0; i < elems.size(); i++) { node[i + width - 1] = elems[i]; } for (size_t i = width - 2; i != numeric_limits<size_t>::max(); i--) { node[i] = op(node[2 * i + 1], node[2 * i + 2]); } } void update(size_t idx, Monoid elem) { idx += width - 1; node[idx] = elem; while (idx >= 1) { idx = (idx - 1) / 2; node[idx] = op(node[2 * idx + 1], node[2 * idx + 2]); } } Monoid query(size_t a, size_t b, size_t root) const { assert(0 <= a && b <= width); size_t left = root, right = root; while (left < width - 1) { left = 2 * left + 1; } left -= (width - 1); while (right < width - 1) { right = 2 * right + 2; } right -= (width - 1); right++; if (right <= a || b <= left) { return unit; } if (a <= left && right <= b) { return node[root]; } Monoid ans_l = query(a, b, 2 * root + 1); Monoid ans_r = query(a, b, 2 * root + 2); return op(ans_l, ans_r); } }; int main() { int A, B, Q; cin >> A >> B >> Q; struct PointInfo { ll pos; ll length_to_neighbour; }; vector<PointInfo> shrines; vector<PointInfo> temples; for (int i = 0; i < A; i++) { ll pos; cin >> pos; shrines.push_back(PointInfo{pos, numeric_limits<ll>::max()}); } for (int i = 0; i < B; i++) { ll pos; cin >> pos; temples.push_back(PointInfo{pos, numeric_limits<ll>::max()}); } sort(shrines.begin(), shrines.end(), [](PointInfo lhs, PointInfo rhs) { return lhs.pos < rhs.pos; }); sort(temples.begin(), temples.end(), [](PointInfo lhs, PointInfo rhs) { return lhs.pos < rhs.pos; }); int cnt = 0; while (cnt < 2) { vector<PointInfo> *this_points = nullptr; vector<PointInfo> *that_points = nullptr; if (cnt == 0) { this_points = &shrines; that_points = &temples; } else { this_points = &temples; that_points = &shrines; } for (PointInfo &sh : *this_points) { auto first_it = partition_point(that_points->begin(), that_points->end(), [&sh](PointInfo elm) { return elm.pos < sh.pos; }); if (first_it == that_points->begin()) { sh.length_to_neighbour = min(sh.length_to_neighbour, first_it->pos - sh.pos); } else if (first_it == that_points->end()) { auto it = prev(first_it); sh.length_to_neighbour = min(sh.length_to_neighbour, sh.pos - it->pos); } else { sh.length_to_neighbour = min(sh.length_to_neighbour, first_it->pos - sh.pos); sh.length_to_neighbour = min(sh.length_to_neighbour, sh.pos - prev(first_it)->pos); } } cnt++; } vector<PointInfo> merged = move(shrines); copy(temples.begin(), temples.end(), back_inserter(merged)); sort(merged.begin(), merged.end(), [](PointInfo lhs, PointInfo rhs) { return lhs.pos < rhs.pos; }); vector<ll> left_costs; vector<ll> right_costs; for (PointInfo pt : merged) { left_costs.push_back(-pt.pos + pt.length_to_neighbour); right_costs.push_back(pt.pos + pt.length_to_neighbour); } SegmentTree<ll> left_tree( left_costs, [](ll lhs, ll rhs) { return min(lhs, rhs); }, numeric_limits<ll>::max()); SegmentTree<ll> right_tree( right_costs, [](ll lhs, ll rhs) { return min(lhs, rhs); }, numeric_limits<ll>::max()); for (int i = 0; i < Q; i++) { ll X; cin >> X; auto first_it = partition_point(merged.begin(), merged.end(), [X](PointInfo elm) { return elm.pos < X; }); ll left_cost = left_tree.query(0, distance(merged.begin(), first_it), 0) + X; ll right_cost = right_tree.query(distance(merged.begin(), first_it), merged.size(), 0) - X; cout << min(left_cost, right_cost) << endl; } }
// // main.cpp // #include <algorithm> #include <array> #include <assert.h> #include <iostream> #include <limits> #include <math.h> #include <memory> #include <queue> #include <random> #include <set> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using ll = long long; using ull = unsigned long long; template <typename Monoid> struct SegmentTree { using Op = function<Monoid(const Monoid &lhs, const Monoid &rhs)>; size_t width; vector<Monoid> node; Op op; Monoid unit; SegmentTree(const vector<Monoid> &elems, Op op, Monoid unit) : op(op), unit(unit) { width = 1; while (width < elems.size()) { width *= 2; } node.resize(2 * width - 1, unit); for (size_t i = 0; i < elems.size(); i++) { node[i + width - 1] = elems[i]; } for (size_t i = width - 2; i != numeric_limits<size_t>::max(); i--) { node[i] = op(node[2 * i + 1], node[2 * i + 2]); } } void update(size_t idx, Monoid elem) { idx += width - 1; node[idx] = elem; while (idx >= 1) { idx = (idx - 1) / 2; node[idx] = op(node[2 * idx + 1], node[2 * idx + 2]); } } Monoid query(size_t a, size_t b, size_t root) const { assert(0 <= a && b <= width); size_t left = root, right = root; while (left < width - 1) { left = 2 * left + 1; } left -= (width - 1); while (right < width - 1) { right = 2 * right + 2; } right -= (width - 1); right++; if (right <= a || b <= left) { return unit; } if (a <= left && right <= b) { return node[root]; } Monoid ans_l = query(a, b, 2 * root + 1); Monoid ans_r = query(a, b, 2 * root + 2); return op(ans_l, ans_r); } }; int main() { int A, B, Q; cin >> A >> B >> Q; struct PointInfo { ll pos; ll length_to_neighbour; }; vector<PointInfo> shrines; vector<PointInfo> temples; for (int i = 0; i < A; i++) { ll pos; cin >> pos; shrines.push_back(PointInfo{pos, numeric_limits<ll>::max()}); } for (int i = 0; i < B; i++) { ll pos; cin >> pos; temples.push_back(PointInfo{pos, numeric_limits<ll>::max()}); } sort(shrines.begin(), shrines.end(), [](PointInfo lhs, PointInfo rhs) { return lhs.pos < rhs.pos; }); sort(temples.begin(), temples.end(), [](PointInfo lhs, PointInfo rhs) { return lhs.pos < rhs.pos; }); int cnt = 0; while (cnt < 2) { vector<PointInfo> *this_points = nullptr; vector<PointInfo> *that_points = nullptr; if (cnt == 0) { this_points = &shrines; that_points = &temples; } else { this_points = &temples; that_points = &shrines; } for (PointInfo &sh : *this_points) { auto first_it = partition_point(that_points->begin(), that_points->end(), [&sh](PointInfo elm) { return elm.pos < sh.pos; }); if (first_it == that_points->begin()) { sh.length_to_neighbour = min(sh.length_to_neighbour, first_it->pos - sh.pos); } else if (first_it == that_points->end()) { auto it = prev(first_it); sh.length_to_neighbour = min(sh.length_to_neighbour, sh.pos - it->pos); } else { sh.length_to_neighbour = min(sh.length_to_neighbour, first_it->pos - sh.pos); sh.length_to_neighbour = min(sh.length_to_neighbour, sh.pos - prev(first_it)->pos); } } cnt++; } vector<PointInfo> merged = move(shrines); copy(temples.begin(), temples.end(), back_inserter(merged)); sort(merged.begin(), merged.end(), [](PointInfo lhs, PointInfo rhs) { return lhs.pos < rhs.pos; }); vector<ll> left_costs; vector<ll> right_costs; for (PointInfo pt : merged) { left_costs.push_back(-pt.pos + pt.length_to_neighbour); right_costs.push_back(pt.pos + pt.length_to_neighbour); } SegmentTree<ll> left_tree( left_costs, [](ll lhs, ll rhs) { return min(lhs, rhs); }, numeric_limits<ll>::max() / 2); SegmentTree<ll> right_tree( right_costs, [](ll lhs, ll rhs) { return min(lhs, rhs); }, numeric_limits<ll>::max() / 2); for (int i = 0; i < Q; i++) { ll X; cin >> X; auto first_it = partition_point(merged.begin(), merged.end(), [X](PointInfo elm) { return elm.pos < X; }); ll left_cost = left_tree.query(0, distance(merged.begin(), first_it), 0) + X; ll right_cost = right_tree.query(distance(merged.begin(), first_it), merged.size(), 0) - X; cout << min(left_cost, right_cost) << endl; } }
[ "assignment.change" ]
924,492
924,493
u578938637
cpp
p03112
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < n; i++) #define SORT(x) sort(x.begin(), x.end()) using namespace std; typedef long long ll; ll minl(ll a, ll b) { if (a < b) return a; else return b; } int main() { ll A, B, Q; cin >> A >> B >> Q; vector<ll> s(A), t(B), x(Q); rep(i, A) cin >> s[i]; rep(i, B) cin >> t[i]; rep(i, Q) cin >> x[i]; SORT(t); SORT(s); map<ll, ll> stot; map<ll, ll> ttos; rep(i, A) { auto pos = lower_bound(t.begin(), t.end(), s[i]); int a, b; a = distance(t.begin(), pos); if (a) b = a - 1; else b = a; stot[s[i]] = minl(abs(s[i] - t[a]), abs(s[i] - t[b])); } rep(i, B) { auto pos = lower_bound(s.begin(), s.end(), t[i]); int a, b; a = distance(s.begin(), pos); if (a) b = a - 1; else b = a; ttos[t[i]] = minl(abs(t[i] - s[a]), abs(t[i] - s[b])); } ll ans, sans, tans; rep(i, Q) { vector<ll>::iterator spos = lower_bound(s.begin(), s.end(), x[i]); vector<ll>::iterator tpos = lower_bound(t.begin(), t.end(), x[i]); ll a, b, c, d; a = distance(s.begin(), spos); if (A == 1) a = a - 1; if (a) b = a - 1; else b = a; sans = minl(ll(abs(x[i] - s[a]) + stot[s[a]]), ll(abs(x[i] - s[b]) + stot[s[b]])); c = distance(t.begin(), tpos); if (c) d = c - 1; else d = c; tans = minl(ll(abs(x[i] - t[c]) + ttos[t[c]]), ll(abs(x[i] - t[d]) + ttos[t[d]])); ans = minl(sans, tans); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < n; i++) #define SORT(x) sort(x.begin(), x.end()) using namespace std; typedef long long ll; ll minl(ll a, ll b) { if (a < b) return a; else return b; } int main() { ll A, B, Q; cin >> A >> B >> Q; vector<ll> s(A), t(B), x(Q); rep(i, A) cin >> s[i]; rep(i, B) cin >> t[i]; rep(i, Q) cin >> x[i]; SORT(t); SORT(s); map<ll, ll> stot; map<ll, ll> ttos; rep(i, A) { auto pos = lower_bound(t.begin(), t.end(), s[i]); int a, b; a = distance(t.begin(), pos); if (a) b = a - 1; else b = a; stot[s[i]] = minl(abs(s[i] - t[a]), abs(s[i] - t[b])); } rep(i, B) { auto pos = lower_bound(s.begin(), s.end(), t[i]); int a, b; a = distance(s.begin(), pos); if (a) b = a - 1; else b = a; ttos[t[i]] = minl(abs(t[i] - s[a]), abs(t[i] - s[b])); } ll ans, sans, tans; rep(i, Q) { vector<ll>::iterator spos = lower_bound(s.begin(), s.end(), x[i]); vector<ll>::iterator tpos = lower_bound(t.begin(), t.end(), x[i]); ll a, b, c, d; a = distance(s.begin(), spos); if (a > A - 1) a = a - 1; if (a) b = a - 1; else b = a; sans = minl(ll(abs(x[i] - s[a]) + stot[s[a]]), ll(abs(x[i] - s[b]) + stot[s[b]])); c = distance(t.begin(), tpos); if (c) d = c - 1; else d = c; tans = minl(ll(abs(x[i] - t[c]) + ttos[t[c]]), ll(abs(x[i] - t[d]) + ttos[t[d]])); ans = minl(sans, tans); cout << ans << endl; } return 0; }
[ "control_flow.branch.if.condition.change" ]
924,494
924,495
u703503553
cpp
p03112
#include <algorithm> #include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <iomanip> //do setprecision #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define FOR(i, b, e) for (int i = (b); i < (e); ++i) #define FORQ(i, b, e) for (int i = (b); i <= (e); ++i) #define FORD(i, b, e) for (int i = (b)-1; i >= (e); --i) #define REP(x, n) for (int x = 0; x < (n); ++x) #define ST first #define ND second #define PB push_back #define PF push_front #define MP make_pair #define LL long long #define ULL unsigned LL #define LD long double #define pii pair<int, int> #define pll pair<LL, LL> #define vi vector<int> #define vii vector<vi> const double pi = 3.14159265358979323846264; const int mod = 1000000007; LL d(LL a, LL b, LL c) { return abs(b - a) + abs(c - b); } int main() { // cin.tie(0); // ios::sync_with_stdio(false); // std::cout << std::fixed; // std::cout << std::setprecision(12); // std::cout << std::defaultfloat; int a, b, q; cin >> a >> b >> q; vector<LL> s(a + 3); vector<LL> t(b + 3); s[0] = t[0] = -mod * 10001LL; s[1] = t[1] = -mod * 10000LL; s[a + 2] = t[b + 2] = mod * 10000LL; s[a + 3] = t[b + 3] = mod * 10001LL; FOR(i, 0, a) { cin >> s[i + 2]; } FOR(j, 0, b) { cin >> t[j + 2]; } FOR(i, 0, q) { LL x; cin >> x; auto si = lower_bound(s.begin(), s.end(), x) - s.begin(); auto ti = lower_bound(t.begin(), t.end(), x) - t.begin(); if (s[si] == x) { cout << min(abs(x - t[ti]), abs(x - t[ti - 1])) << endl; } else if (t[ti] == x) { cout << min(abs(x - s[si]), abs(x - s[si - 1])) << endl; } else { cout << min(min(min(d(x, s[si], t[ti]), d(x, s[si - 1], t[ti - 1])), min(d(x, s[si - 1], t[ti]), d(x, s[si], t[ti - 1]))), min(min(d(x, t[ti], s[si]), d(x, t[ti], s[si - 1])), min(d(x, t[ti - 1], s[si]), d(x, t[ti - 1], s[si - 1])))) << endl; } } return 0; }
#include <algorithm> #include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <iomanip> //do setprecision #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define FOR(i, b, e) for (int i = (b); i < (e); ++i) #define FORQ(i, b, e) for (int i = (b); i <= (e); ++i) #define FORD(i, b, e) for (int i = (b)-1; i >= (e); --i) #define REP(x, n) for (int x = 0; x < (n); ++x) #define ST first #define ND second #define PB push_back #define PF push_front #define MP make_pair #define LL long long #define ULL unsigned LL #define LD long double #define pii pair<int, int> #define pll pair<LL, LL> #define vi vector<int> #define vii vector<vi> const double pi = 3.14159265358979323846264; const int mod = 1000000007; LL d(LL a, LL b, LL c) { return abs(b - a) + abs(c - b); } int main() { // cin.tie(0); // ios::sync_with_stdio(false); // std::cout << std::fixed; // std::cout << std::setprecision(12); // std::cout << std::defaultfloat; int a, b, q; cin >> a >> b >> q; vector<LL> s(a + 4); vector<LL> t(b + 4); s[0] = t[0] = -mod * 10001LL; s[1] = t[1] = -mod * 10000LL; s[a + 2] = t[b + 2] = mod * 10000LL; s[a + 3] = t[b + 3] = mod * 10001LL; FOR(i, 0, a) { cin >> s[i + 2]; } FOR(j, 0, b) { cin >> t[j + 2]; } FOR(i, 0, q) { LL x; cin >> x; auto si = lower_bound(s.begin(), s.end(), x) - s.begin(); auto ti = lower_bound(t.begin(), t.end(), x) - t.begin(); if (s[si] == x) { cout << min(abs(x - t[ti]), abs(x - t[ti - 1])) << endl; } else if (t[ti] == x) { cout << min(abs(x - s[si]), abs(x - s[si - 1])) << endl; } else { cout << min(min(min(d(x, s[si], t[ti]), d(x, s[si - 1], t[ti - 1])), min(d(x, s[si - 1], t[ti]), d(x, s[si], t[ti - 1]))), min(min(d(x, t[ti], s[si]), d(x, t[ti], s[si - 1])), min(d(x, t[ti - 1], s[si]), d(x, t[ti - 1], s[si - 1])))) << endl; } } return 0; }
[ "literal.number.change", "call.arguments.change", "expression.operation.binary.change" ]
924,498
924,499
u404075706
cpp
p03112
#include <bits/stdc++.h> #define PI acos(-1) #define mp make_pair #define pb push_back #define all(a) (a).begin(), (a).end() #define srt(a) sort(all(a)) #define mem(a, h) memset(a, (h), sizeof(a)) #define f first #define s second #define MOD 1000000007 #define MOD1 998244353 #define EPS 1e-9 #define fore(i, b, e) for (ll i = b; i < e; i++) #define forg(i, b, e, m) for (ll i = b; i < e; i += m) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> ii; typedef vector<ll> vi; typedef vector<ii> vii; typedef vector<ll> vll; const ll tam = 10000010; int main() { ios::sync_with_stdio(false); cin.tie(0); // freopen("asd.txt", "r", stdin); // freopen("asd.txt", "w", stdout); ll a, b, q; ll x; cin >> a >> b >> q; set<ll> a1, a2, b1, b2; while (a--) { cin >> x; a1.insert(x); a2.insert(-x); } while (b--) { cin >> x; b1.insert(x); b2.insert(-x); } while (q--) { cin >> x; ll res = MOD; if (a1.lower_bound(x) != a1.end()) { ll x1 = *a1.lower_bound(x); if (b1.lower_bound(x1) != b1.end()) { res = min(res, abs(x - x1) + abs(x1 - *b1.lower_bound(x1))); } if (b2.lower_bound(-x1) != b2.end()) { res = min(res, abs(x - x1) + abs(x1 + *b2.lower_bound(-x1))); } } if (a2.lower_bound(-x) != a2.end()) { ll x1 = -*a2.lower_bound(-x); if (b1.lower_bound(x1) != b1.end()) { res = min(res, abs(x - x1) + abs(x1 - *b1.lower_bound(x1))); } if (b2.lower_bound(-x1) != b2.end()) { res = min(res, abs(x - x1) + abs(x1 + *b2.lower_bound(-x1))); } } if (b1.lower_bound(x) != b1.end()) { ll x1 = *b1.lower_bound(x); if (a1.lower_bound(x1) != a1.end()) { res = min(res, abs(x - x1) + abs(x1 - *a1.lower_bound(x1))); } if (a2.lower_bound(-x1) != a2.end()) { res = min(res, abs(x - x1) + abs(x1 + *a2.lower_bound(-x1))); } } if (b2.lower_bound(-x) != b2.end()) { ll x1 = -*b2.lower_bound(-x); if (a1.lower_bound(x1) != a1.end()) { res = min(res, abs(x - x1) + abs(x1 - *a1.lower_bound(x1))); } if (a2.lower_bound(-x1) != a2.end()) { res = min(res, abs(x - x1) + abs(x1 + *a2.lower_bound(-x1))); } } cout << res << '\n'; } return 0; } // read the question correctly (is y a vowel? what are the exact constralls?) // look out for SPECIAL CASES (n=1?) and overflow (ll vs ll?) ARRAY OUT OF // BOUNDSS2
#include <bits/stdc++.h> #define PI acos(-1) #define mp make_pair #define pb push_back #define all(a) (a).begin(), (a).end() #define srt(a) sort(all(a)) #define mem(a, h) memset(a, (h), sizeof(a)) #define f first #define s second #define MOD 1000000007 #define MOD1 998244353 #define EPS 1e-9 #define fore(i, b, e) for (ll i = b; i < e; i++) #define forg(i, b, e, m) for (ll i = b; i < e; i += m) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> ii; typedef vector<ll> vi; typedef vector<ii> vii; typedef vector<ll> vll; const ll tam = 10000010; int main() { ios::sync_with_stdio(false); cin.tie(0); // freopen("asd.txt", "r", stdin); // freopen("asd.txt", "w", stdout); ll a, b, q; ll x; cin >> a >> b >> q; set<ll> a1, a2, b1, b2; while (a--) { cin >> x; a1.insert(x); a2.insert(-x); } while (b--) { cin >> x; b1.insert(x); b2.insert(-x); } while (q--) { cin >> x; ll res = 1e15; if (a1.lower_bound(x) != a1.end()) { ll x1 = *a1.lower_bound(x); if (b1.lower_bound(x1) != b1.end()) { res = min(res, abs(x - x1) + abs(x1 - *b1.lower_bound(x1))); } if (b2.lower_bound(-x1) != b2.end()) { res = min(res, abs(x - x1) + abs(x1 + *b2.lower_bound(-x1))); } } if (a2.lower_bound(-x) != a2.end()) { ll x1 = -*a2.lower_bound(-x); if (b1.lower_bound(x1) != b1.end()) { res = min(res, abs(x - x1) + abs(x1 - *b1.lower_bound(x1))); } if (b2.lower_bound(-x1) != b2.end()) { res = min(res, abs(x - x1) + abs(x1 + *b2.lower_bound(-x1))); } } if (b1.lower_bound(x) != b1.end()) { ll x1 = *b1.lower_bound(x); if (a1.lower_bound(x1) != a1.end()) { res = min(res, abs(x - x1) + abs(x1 - *a1.lower_bound(x1))); } if (a2.lower_bound(-x1) != a2.end()) { res = min(res, abs(x - x1) + abs(x1 + *a2.lower_bound(-x1))); } } if (b2.lower_bound(-x) != b2.end()) { ll x1 = -*b2.lower_bound(-x); if (a1.lower_bound(x1) != a1.end()) { res = min(res, abs(x - x1) + abs(x1 - *a1.lower_bound(x1))); } if (a2.lower_bound(-x1) != a2.end()) { res = min(res, abs(x - x1) + abs(x1 + *a2.lower_bound(-x1))); } } cout << res << '\n'; } return 0; } // read the question correctly (is y a vowel? what are the exact constralls?) // look out for SPECIAL CASES (n=1?) and overflow (ll vs ll?) ARRAY OUT OF // BOUNDSS2
[ "variable_declaration.value.change", "identifier.replace.remove", "literal.replace.add" ]
924,502
924,503
u736250852
cpp
p03112
#include <algorithm> #include <cmath> #include <fstream> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <vector> #define REP(i, n) for (int(i) = 0; (i) < (n); (i)++) using namespace std; using ll = long long; using P = pair<int, int>; using TP = tuple<ll, ll, ll>; ll MOD = 1e9 + 7; ll INF = 1LL << 58; int main() { cin.tie(0); ios::sync_with_stdio(false); int A, B, Q; cin >> A >> B >> Q; vector<ll> s(A), t(B); REP(i, A) { cin >> s[i]; } REP(i, B) { cin >> t[i]; } s.push_back(INF); s.push_back(-INF); t.push_back(INF); t.push_back(-INF); sort(s.begin(), s.end()); sort(t.begin(), t.end()); REP(i, Q) { ll x; cin >> x; ll res = INF; REP(j, 2) { ll first = (j ? (upper_bound(s.begin(), s.end(), x) - s.begin() - 1) : (lower_bound(s.begin(), s.end(), x) - s.begin())); first = s[first]; REP(k, 2) { ll second = (k ? (upper_bound(t.begin(), t.end(), first) - t.begin() - 1) : (lower_bound(t.begin(), t.end(), first) - t.begin())); second = t[second]; res = min(res, abs(x - first) + abs(first - second)); } } REP(j, 2) { ll first = (j ? (upper_bound(t.begin(), t.end(), x) - t.begin() - 1) : (lower_bound(t.begin(), t.end(), x) - t.begin())); first = s[first]; REP(k, 2) { ll second = (k ? (upper_bound(s.begin(), s.end(), first) - s.begin() - 1) : (lower_bound(s.begin(), s.end(), first) - s.begin())); second = t[second]; res = min(res, abs(x - first) + abs(first - second)); } } cout << res << endl; } return 0; }
#include <algorithm> #include <cmath> #include <fstream> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <vector> #define REP(i, n) for (int(i) = 0; (i) < (n); (i)++) using namespace std; using ll = long long; using P = pair<int, int>; using TP = tuple<ll, ll, ll>; ll MOD = 1e9 + 7; ll INF = 1LL << 58; int main() { cin.tie(0); ios::sync_with_stdio(false); int A, B, Q; cin >> A >> B >> Q; vector<ll> s(A), t(B); REP(i, A) { cin >> s[i]; } REP(i, B) { cin >> t[i]; } s.push_back(INF); s.push_back(-INF); t.push_back(INF); t.push_back(-INF); sort(s.begin(), s.end()); sort(t.begin(), t.end()); REP(i, Q) { ll x; cin >> x; ll res = INF; REP(j, 2) { ll first = (j ? (upper_bound(s.begin(), s.end(), x) - s.begin() - 1) : (lower_bound(s.begin(), s.end(), x) - s.begin())); first = s[first]; REP(k, 2) { ll second = (k ? (upper_bound(t.begin(), t.end(), first) - t.begin() - 1) : (lower_bound(t.begin(), t.end(), first) - t.begin())); second = t[second]; res = min(res, abs(x - first) + abs(first - second)); } } REP(j, 2) { ll first = (j ? (upper_bound(t.begin(), t.end(), x) - t.begin() - 1) : (lower_bound(t.begin(), t.end(), x) - t.begin())); first = t[first]; REP(k, 2) { ll second = (k ? (upper_bound(s.begin(), s.end(), first) - s.begin() - 1) : (lower_bound(s.begin(), s.end(), first) - s.begin())); second = s[second]; res = min(res, abs(x - first) + abs(first - second)); } } cout << res << endl; } return 0; }
[ "assignment.value.change", "identifier.change" ]
924,510
924,511
u432194969
cpp
p03112
#include <algorithm> #include <bits/stdc++.h> #include <vector> using namespace std; using ll = long long; 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__) const long long inf = 1LL << 60; const long long mod = 1e9 + 7; int main() { int A, B, Q; ll x; cin >> A >> B >> Q; vector<ll> SH(A + 2); vector<ll> TE(B + 2); ll d1, d2, ret; SH[0] = -inf; rep(i, 1, A + 1) cin >> SH[i]; SH[A + 1] = inf; TE[0] = -inf; rep(i, 1, B + 1) cin >> TE[i]; TE[B + 1] = inf; rep(i, Q) { cin >> x; auto sl = lower_bound(SH.begin(), SH.end(), x); auto tl = lower_bound(TE.begin(), TE.end(), x); ret = inf; rep(j, 2) { rep(k, 2) { ll d1 = abs(*(sl + j) - x) + abs(*(sl + j) - *(tl + k)); ll d2 = abs(*(tl + k) - x) + abs(*(sl + j) - *(tl + k)); ret = min(ret, min(d1, d2)); } } printf("%lld\n", ret); } }
#include <algorithm> #include <bits/stdc++.h> #include <vector> using namespace std; using ll = long long; 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__) const long long inf = 1LL << 60; const long long mod = 1e9 + 7; int main() { int A, B, Q; ll x; cin >> A >> B >> Q; vector<ll> SH(A + 2); vector<ll> TE(B + 2); ll d1, d2, ret; SH[0] = -inf; rep(i, 1, A + 1) cin >> SH[i]; SH[A + 1] = inf; TE[0] = -inf; rep(i, 1, B + 1) cin >> TE[i]; TE[B + 1] = inf; rep(i, Q) { cin >> x; auto sl = lower_bound(SH.begin(), SH.end(), x); auto tl = lower_bound(TE.begin(), TE.end(), x); ret = inf; rep(j, 2) { rep(k, 2) { ll d1 = abs(*(sl - j) - x) + abs(*(sl - j) - *(tl - k)); ll d2 = abs(*(tl - k) - x) + abs(*(sl - j) - *(tl - k)); ret = min(ret, min(d1, d2)); } } printf("%lld\n", ret); } }
[ "misc.opposites", "expression.operator.arithmetic.change", "call.arguments.change", "expression.operation.binary.change" ]
924,512
924,513
u573154728
cpp
p03112
#include <bits/stdc++.h> using namespace std; #define INF 1e14 + 1 typedef long long ll; template <class T> int former(const vector<T> &v, T x) { return upper_bound(v.begin(), v.end(), x) - v.begin() - 1; } template <class T> int latter(const vector<T> &v, T x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); } int main() { ll A, B, Q; cin >> A >> B >> Q; vector<ll> s(A), t(B), xx(Q); for (int i = 0; i < A; i++) cin >> s[i]; for (int i = 0; i < B; i++) cin >> t[i]; for (int i = 0; i < Q; i++) cin >> xx[i]; s.push_back(INF); s.push_back(-INF); t.push_back(INF); t.push_back(-INF); sort(t.begin(), t.end()); sort(s.begin(), s.end()); for (int i = 0; i < Q; i++) { long long x = xx[i]; long long res = INF; for (int i = 0; i < 2; i++) { long long first = (i ? s[former(s, x)] : s[latter(s, x)]); for (int j = 0; j < 2; j++) { long long second = (j ? t[former(t, first)] : t[latter(t, first)]); res = min(res, abs(x - first) + abs(first - second)); } } for (int i = 0; i < 2; i++) { long long first = (i ? t[former(s, x)] : t[latter(s, x)]); for (int j = 0; j < 2; j++) { long long second = (j ? s[former(s, first)] : s[latter(s, first)]); res = min(res, abs(x - first) + abs(first - second)); } } cout << res << endl; } }
#include <bits/stdc++.h> using namespace std; #define INF 1e14 + 1 typedef long long ll; template <class T> int former(const vector<T> &v, T x) { return upper_bound(v.begin(), v.end(), x) - v.begin() - 1; } template <class T> int latter(const vector<T> &v, T x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); } int main() { ll A, B, Q; cin >> A >> B >> Q; vector<ll> s(A), t(B), xx(Q); for (int i = 0; i < A; i++) cin >> s[i]; for (int i = 0; i < B; i++) cin >> t[i]; for (int i = 0; i < Q; i++) cin >> xx[i]; s.push_back(INF); s.push_back(-INF); t.push_back(INF); t.push_back(-INF); sort(t.begin(), t.end()); sort(s.begin(), s.end()); for (int i = 0; i < Q; i++) { long long x = xx[i]; long long res = INF; for (int i = 0; i < 2; i++) { long long first = (i ? s[former(s, x)] : s[latter(s, x)]); for (int j = 0; j < 2; j++) { long long second = (j ? t[former(t, first)] : t[latter(t, first)]); res = min(res, abs(x - first) + abs(first - second)); } } for (int i = 0; i < 2; i++) { long long first = (i ? t[former(t, x)] : t[latter(t, x)]); for (int j = 0; j < 2; j++) { long long second = (j ? s[former(s, first)] : s[latter(s, first)]); res = min(res, abs(x - first) + abs(first - second)); } } cout << res << endl; } }
[ "identifier.change", "variable_access.subscript.index.change", "call.arguments.change" ]
924,518
924,519
u624923345
cpp
p03112
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; using P = pair<ll, ll>; #define rep(i, x) for (ll i = 0; i < (ll)(x); i++) #define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--) #define _upgrade \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define all(x) (x).begin(), (x).end() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); template <class T1, class T2> void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <class T1, class T2> void chmax(T1 &a, T2 b) { if (a < b) a = b; } // ll gcd(ll a, ll b){return b?gcd(b,a%b):a;} // ll lcm(ll x, ll y) {return x / gcd(x, y) * y;} int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; const ll mod = 1e9 + 7; const ll INF = 1LL << 60; const double PI = 3.14159265358979323846; // ****************************************CODE***************************************// template <class T> int former(const vector<T> &v, T x) { return upper_bound(v.begin(), v.end(), x) - v.begin() - 1; } template <class T> int latter(const vector<T> &v, T x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); } int main() { int A, B, Q; cin >> A >> B >> Q; vector<long long> s(A), t(B); for (int i = 0; i < A; i++) cin >> s[i]; for (int i = 0; i < B; i++) cin >> t[i]; s.push_back(INF); s.push_back(-INF); sort(all(s)); t.push_back(INF); s.push_back(-INF); sort(all(t)); for (int k = 0; k < Q; ++k) { long long x; cin >> x; long long res = INF; for (int i = 0; i < 2; i++) { long long first = (i ? s[former(s, x)] : s[latter(s, x)]); for (int j = 0; j < 2; j++) { long long second = (j ? t[former(t, first)] : t[latter(t, first)]); chmin(res, abs(x - first) + abs(first - second)); } } for (int i = 0; i < 2; i++) { long long first = (i ? t[former(t, x)] : t[latter(t, x)]); for (int j = 0; j < 2; j++) { long long second = (j ? s[former(s, first)] : s[latter(s, first)]); chmin(res, abs(x - first) + abs(first - second)); } } cout << res << endl; } }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; using P = pair<ll, ll>; #define rep(i, x) for (ll i = 0; i < (ll)(x); i++) #define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--) #define _upgrade \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define all(x) (x).begin(), (x).end() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); template <class T1, class T2> void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <class T1, class T2> void chmax(T1 &a, T2 b) { if (a < b) a = b; } // ll gcd(ll a, ll b){return b?gcd(b,a%b):a;} // ll lcm(ll x, ll y) {return x / gcd(x, y) * y;} int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; const ll mod = 1e9 + 7; const ll INF = 1LL << 60; const double PI = 3.14159265358979323846; // ****************************************CODE***************************************// template <class T> int former(const vector<T> &v, T x) { return upper_bound(v.begin(), v.end(), x) - v.begin() - 1; } template <class T> int latter(const vector<T> &v, T x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); } int main() { int A, B, Q; cin >> A >> B >> Q; vector<long long> s(A), t(B); for (int i = 0; i < A; i++) cin >> s[i]; for (int i = 0; i < B; i++) cin >> t[i]; s.push_back(INF); s.push_back(-INF); sort(all(s)); t.push_back(INF); t.push_back(-INF); sort(all(t)); for (int k = 0; k < Q; ++k) { long long x; cin >> x; long long res = INF; for (int i = 0; i < 2; i++) { long long first = (i ? s[former(s, x)] : s[latter(s, x)]); for (int j = 0; j < 2; j++) { long long second = (j ? t[former(t, first)] : t[latter(t, first)]); chmin(res, abs(x - first) + abs(first - second)); } } for (int i = 0; i < 2; i++) { long long first = (i ? t[former(t, x)] : t[latter(t, x)]); for (int j = 0; j < 2; j++) { long long second = (j ? s[former(s, first)] : s[latter(s, first)]); chmin(res, abs(x - first) + abs(first - second)); } } cout << res << endl; } }
[ "identifier.change" ]
924,524
924,525
u195054737
cpp
p03112
#include <bits/stdc++.h> using namespace std; #define int long long vector<int> s, t; void solve() { int x; cin >> x; int ans = 1e18; int sitr = lower_bound(s.begin(), s.end(), x) - s.begin(); int titr = lower_bound(t.begin(), t.end(), x) - t.begin(); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { ans = min(ans, abs(x - s[sitr - i]) + abs(t[titr - j] - s[sitr - i])); ans = min(ans, abs(x - t[titr - j]) + abs(t[titr - j] - s[sitr - i])); } } cout << ans << endl; } signed main() { int a, b, q; cin >> a >> b >> q; s.resize(a); t.resize(b); for (int i = 0; i < a; i++) cin >> s[i]; for (int i = 0; i < b; i++) cin >> t[i]; s.push_back(-1e18); s.push_back(-1e18); s.push_back(1e18); t.push_back(1e18); sort(s.begin(), s.end()); sort(t.begin(), t.end()); while (q--) { solve(); } }
#include <bits/stdc++.h> using namespace std; #define int long long vector<int> s, t; void solve() { int x; cin >> x; int ans = 1e18; int sitr = lower_bound(s.begin(), s.end(), x) - s.begin(); int titr = lower_bound(t.begin(), t.end(), x) - t.begin(); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { ans = min(ans, abs(x - s[sitr - i]) + abs(t[titr - j] - s[sitr - i])); ans = min(ans, abs(x - t[titr - j]) + abs(t[titr - j] - s[sitr - i])); } } cout << ans << endl; } signed main() { int a, b, q; cin >> a >> b >> q; s.resize(a); t.resize(b); for (int i = 0; i < a; i++) cin >> s[i]; for (int i = 0; i < b; i++) cin >> t[i]; s.push_back(-1e18); t.push_back(-1e18); s.push_back(1e18); t.push_back(1e18); sort(s.begin(), s.end()); sort(t.begin(), t.end()); while (q--) { solve(); } }
[ "identifier.change" ]
924,529
924,530
u862412671
cpp
p03112
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (n); ++i) const long long INF = 1LL << 58; /* * * 最適解は以下のいずれかの形であることはわかる まずいずれかの「神社」を訪れて、そこから最も近い「寺」に訪れる まずいずれかの「寺」を訪れて、そこから最も近い「神社」に訪れる ここで、1 個目の場合について、最初に訪れる神社が必ずしも初期位置から最も近い位置がよいわけではないことに注意する。なぜなら、初期位置から最も近い神社に行っても、そこから最寄りの寺がすごく遠いかもしれない!!!!!!!! しかしそれでも、 初期位置から前方の最寄りの神社 初期位置から後方の最寄りの神社 以外を狙う意味はないことがわかる。何故なら、これら以外の神社に行こうと思うと、「前方最寄り」「後方最寄り」のうちのいずれか一方には既に通りかかることになるからだ。 というわけで初回の行動は以下の 4 パターンで、2 回目の行動はそこから最寄りの「寺」か「神社」に行けばよい。 最初に前方最寄りの神社に行く 最初に後方最寄りの神社に行く 最初に前方最寄りの寺に行く 最初に後方最寄りの寺に行く * * */ // aを常に小さい値にする template <class T> void chmin(T &a, T b) { if (a > b) a = b; } // 二分探索 前方のindexを返すもの(自分自身を含む) 前方: -INF側のこと template <class T> int former(const vector<T> &v, T x) { return upper_bound(v.begin(), v.end(), x) - v.begin() - 1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す } // 二分探索 後方のindexを返すもの(自分自身を含む)後方: INF側のこと template <class T> int latter(const vector<T> &v, T x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : // key以上の要素の内の一番左側のイテレータを返す } int main() { int A, B, Q; cin >> A >> B >> Q; vector<long long> s(A), t(B); rep(i, A) cin >> s[i]; rep(i, B) cin >> t[i]; // 二分探索は配列外の目盛にアクセスする場合はあるので、番兵をいれておく s.push_back(INF); s.push_back(-INF); sort(s.begin(), s.end()); t.push_back(INF); t.push_back(-INF); sort(t.begin(), t.end()); rep(_, Q) { ll x; cin >> x; // かかる距離を保持する変数 resultの略 ll res = INF; // 最初に s に訪れる(前方にいくか、後方に行くかで場合分け) for (int i = 0; i < 2; ++i) { ll first; if (i) { first = s[former(s, x)]; } else { first = s[latter(s, x)]; } // 次に t (現在地の前後を調べて近い方に行く) for (int j = 0; j < 2; ++j) { ll second; if (i) { second = t[former(t, first)]; } else { second = t[latter(t, first)]; } chmin(res, abs(x - first) + abs(first - second)); } } // 最初に s に訪れる(前方にいくか、後方に行くかで場合分け) for (int i = 0; i < 2; ++i) { ll first; if (i) { first = t[former(t, x)]; } else { first = t[latter(t, x)]; } // 次に t (現在地の前後を調べて近い方に行く) for (int j = 0; j < 2; ++j) { ll second; if (i) { second = s[former(s, first)]; } else { second = s[latter(s, first)]; } chmin(res, abs(x - first) + abs(first - second)); } } cout << res << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (n); ++i) const long long INF = 1LL << 58; /* * * 最適解は以下のいずれかの形であることはわかる まずいずれかの「神社」を訪れて、そこから最も近い「寺」に訪れる まずいずれかの「寺」を訪れて、そこから最も近い「神社」に訪れる ここで、1 個目の場合について、最初に訪れる神社が必ずしも初期位置から最も近い位置がよいわけではないことに注意する。なぜなら、初期位置から最も近い神社に行っても、そこから最寄りの寺がすごく遠いかもしれない!!!!!!!! しかしそれでも、 初期位置から前方の最寄りの神社 初期位置から後方の最寄りの神社 以外を狙う意味はないことがわかる。何故なら、これら以外の神社に行こうと思うと、「前方最寄り」「後方最寄り」のうちのいずれか一方には既に通りかかることになるからだ。 というわけで初回の行動は以下の 4 パターンで、2 回目の行動はそこから最寄りの「寺」か「神社」に行けばよい。 最初に前方最寄りの神社に行く 最初に後方最寄りの神社に行く 最初に前方最寄りの寺に行く 最初に後方最寄りの寺に行く * * */ // aを常に小さい値にする template <class T> void chmin(T &a, T b) { if (a > b) a = b; } // 二分探索 前方のindexを返すもの(自分自身を含む) 前方: -INF側のこと template <class T> int former(const vector<T> &v, T x) { return upper_bound(v.begin(), v.end(), x) - v.begin() - 1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す } // 二分探索 後方のindexを返すもの(自分自身を含む)後方: INF側のこと template <class T> int latter(const vector<T> &v, T x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : // key以上の要素の内の一番左側のイテレータを返す } int main() { int A, B, Q; cin >> A >> B >> Q; vector<ll> s(A), t(B); rep(i, A) cin >> s[i]; rep(i, B) cin >> t[i]; // 二分探索は配列外の目盛にアクセスする場合はあるので、番兵をいれておく s.push_back(INF); s.push_back(-INF); sort(s.begin(), s.end()); t.push_back(INF); t.push_back(-INF); sort(t.begin(), t.end()); rep(_, Q) { ll x; cin >> x; // かかる距離を保持する変数 resultの略 ll res = INF; // 最初に s に訪れる(前方にいくか、後方に行くかで場合分け) for (int i = 0; i < 2; ++i) { ll first; if (i) { first = s[former(s, x)]; } else { first = s[latter(s, x)]; } // 次に t (現在地の前後を調べて近い方に行く) for (int j = 0; j < 2; ++j) { ll second; if (j) { second = t[former(t, first)]; } else { second = t[latter(t, first)]; } chmin(res, abs(x - first) + abs(first - second)); } } // 最初に s に訪れる(前方にいくか、後方に行くかで場合分け) for (int i = 0; i < 2; ++i) { ll first; if (i) { first = t[former(t, x)]; } else { first = t[latter(t, x)]; } // 次に t (現在地の前後を調べて近い方に行く) for (int j = 0; j < 2; ++j) { ll second; if (j) { second = s[former(s, first)]; } else { second = s[latter(s, first)]; } chmin(res, abs(x - first) + abs(first - second)); } } cout << res << endl; } }
[ "variable_declaration.type.narrow.change", "identifier.change", "control_flow.branch.if.condition.change" ]
924,533
924,534
u067267880
cpp
p03112
#include <bits/stdc++.h> using namespace std; template <class T> void ckmin(T &a, T b) { a = min(a, b); } template <class T> void ckmax(T &a, T b) { a = max(a, b); } #define pb push_back #define mp make_pair #define cotu cout #define itn int #define Red \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define F first #define S second #define sz(x) (int)x.size() #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < n; ++i) #define repr(i, n) for (int i = n - 1; i >= 0; --i) #define Rep(i, a, n) for (int i = (a); i <= (n); ++i) #define repst(i, n) for (auto it = n.begin(); it != n.end(); ++it) #define Repr(i, a, n) for (int i = (n); i >= (a); --i) #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; const int inf = int(1e9); const int mod = inf + 7; const int N = 1e6 + 555; // TL MB const double PI = acos(-1.0); void mul(ll &x, ll y) { x *= y; if (x >= mod) x %= mod; } void add(ll &x, ll y) { x += y; if (x >= mod) x -= mod; if (x < 0) x += mod; } ll bp(ll a, ll n) { ll r = 1; while (n) { if (n & 1) mul(r, a); mul(a, a); n >>= 1; } return r; } ll get(ll x, ll y, ll z) { return abs(x - y) + abs(y - z); } ll s[N], t[N], x[N]; void solve() { int a, b, q; cin >> a >> b >> q; rep(i, a + a) s[i] = 1e18; rep(i, b + b) t[i] = 1e18; rep(i, a) cin >> s[i]; rep(i, b) cin >> t[i]; sort(s, s + a); sort(t, t + b); rep(i, q) { ll res = 1e12; cin >> x[i]; int p1 = lower_bound(s, s + a, x[i]) - s; if (p1 != a) { int p2 = lower_bound(t, t + b, s[p1]) - t; if (p2 != b) { res = min(res, get(x[i], s[p1], t[p2])); } if (p2 != 0) { res = min(res, get(x[i], s[p1], t[p2 - 1])); } } if (p1 != 0) { int p2 = lower_bound(t, t + b, s[p1 - 1]) - t; if (p2 != b) { res = min(res, get(x[i], s[p1 - 1], t[p2])); } if (p2 != 0) { res = min(res, get(x[i], s[p1 - 1], t[p2 - 1])); } } p1 = lower_bound(t, t + b, x[i]) - t; if (p1 != b) { int p2 = lower_bound(s, s + a, s[p1]) - s; if (p2 != a) { res = min(res, get(x[i], t[p1], s[p2])); } if (p2 != 0) { res = min(res, get(x[i], t[p1], s[p2 - 1])); } } if (p1 != 0) { int p2 = lower_bound(s, s + a, t[p1 - 1]) - s; if (p2 != a) { res = min(res, get(x[i], t[p1 - 1], s[p2])); } if (p2 != 0) { res = min(res, get(x[i], t[p1 - 1], s[p2 - 1])); } } cout << res << '\n'; } } int main() { Red; // int T; cin >> T; while(T--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> void ckmin(T &a, T b) { a = min(a, b); } template <class T> void ckmax(T &a, T b) { a = max(a, b); } #define pb push_back #define mp make_pair #define cotu cout #define itn int #define Red \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define F first #define S second #define sz(x) (int)x.size() #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < n; ++i) #define repr(i, n) for (int i = n - 1; i >= 0; --i) #define Rep(i, a, n) for (int i = (a); i <= (n); ++i) #define repst(i, n) for (auto it = n.begin(); it != n.end(); ++it) #define Repr(i, a, n) for (int i = (n); i >= (a); --i) #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; const int inf = int(1e9); const int mod = inf + 7; const int N = 1e6 + 555; // TL MB const double PI = acos(-1.0); void mul(ll &x, ll y) { x *= y; if (x >= mod) x %= mod; } void add(ll &x, ll y) { x += y; if (x >= mod) x -= mod; if (x < 0) x += mod; } ll bp(ll a, ll n) { ll r = 1; while (n) { if (n & 1) mul(r, a); mul(a, a); n >>= 1; } return r; } ll get(ll x, ll y, ll z) { return abs(x - y) + abs(y - z); } ll s[N], t[N], x[N]; void solve() { int a, b, q; cin >> a >> b >> q; rep(i, a + a) s[i] = 1e18; rep(i, b + b) t[i] = 1e18; rep(i, a) cin >> s[i]; rep(i, b) cin >> t[i]; sort(s, s + a); sort(t, t + b); rep(i, q) { ll res = 1e12; cin >> x[i]; int p1 = lower_bound(s, s + a, x[i]) - s; if (p1 != a) { int p2 = lower_bound(t, t + b, s[p1]) - t; if (p2 != b) { res = min(res, get(x[i], s[p1], t[p2])); } if (p2 != 0) { res = min(res, get(x[i], s[p1], t[p2 - 1])); } } if (p1 != 0) { int p2 = lower_bound(t, t + b, s[p1 - 1]) - t; if (p2 != b) { res = min(res, get(x[i], s[p1 - 1], t[p2])); } if (p2 != 0) { res = min(res, get(x[i], s[p1 - 1], t[p2 - 1])); } } p1 = lower_bound(t, t + b, x[i]) - t; if (p1 != b) { int p2 = lower_bound(s, s + a, t[p1]) - s; if (p2 != a) { res = min(res, get(x[i], t[p1], s[p2])); } if (p2 != 0) { res = min(res, get(x[i], t[p1], s[p2 - 1])); } } if (p1 != 0) { int p2 = lower_bound(s, s + a, t[p1 - 1]) - s; if (p2 != a) { res = min(res, get(x[i], t[p1 - 1], s[p2])); } if (p2 != 0) { res = min(res, get(x[i], t[p1 - 1], s[p2 - 1])); } } cout << res << '\n'; } } int main() { Red; // int T; cin >> T; while(T--) solve(); return 0; }
[ "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
924,535
924,536
u235396011
cpp
p03112
#include <bits/stdc++.h> using namespace std; //#define int long long #define ll long long #define all(v) (v).begin(), (v).end() #define rep(i, n) for (int i = 0; i < n; ++i) #define rep1(i, n) for (int i = 1; i < n; ++i) #define exrep(i, a, b) for (ll i = a; i <= b; i++) #define out(x) cout << x << end #define EPS (1e-7) #define gearup \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); typedef pair<ll, ll> P; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef vector<vector<vector<ll>>> vvvl; ll MOD = 1000000007; const long long L_INF = 1LL << 60; const int INF = 2147483647; // 2^31-1 const double PI = acos(-1); // cout<<fixed<<setprecision(10); 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; } template <class T> void debug(T v) { rep(i, v.size()) cout << v[i] << " "; cout << endl; } const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; signed main() { gearup; int a, b, q; cin >> a >> b >> q; vl s(a + 2, L_INF), t(b + 2, L_INF); s[0] = -L_INF; t[0] = L_INF; rep1(i, a + 1) cin >> s[i]; rep1(i, b + 1) cin >> t[i]; rep(i, q) { ll x; cin >> x; ll s_idx = lower_bound(all(s), x) - s.begin(); ll t_idx = lower_bound(all(t), x) - t.begin(); ll res = L_INF; for (int j = s_idx - 1; j <= s_idx; j++) { for (int k = t_idx - 1; k <= t_idx; k++) { res = min(res, abs(x - s[j]) + abs(s[j] - t[k])); res = min(res, abs(x - t[k]) + abs(s[j] - t[k])); } } cout << res << endl; } }
#include <bits/stdc++.h> using namespace std; //#define int long long #define ll long long #define all(v) (v).begin(), (v).end() #define rep(i, n) for (int i = 0; i < n; ++i) #define rep1(i, n) for (int i = 1; i < n; ++i) #define exrep(i, a, b) for (ll i = a; i <= b; i++) #define out(x) cout << x << end #define EPS (1e-7) #define gearup \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); typedef pair<ll, ll> P; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef vector<vector<vector<ll>>> vvvl; ll MOD = 1000000007; const long long L_INF = 1LL << 60; const int INF = 2147483647; // 2^31-1 const double PI = acos(-1); // cout<<fixed<<setprecision(10); 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; } template <class T> void debug(T v) { rep(i, v.size()) cout << v[i] << " "; cout << endl; } const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; signed main() { gearup; int a, b, q; cin >> a >> b >> q; vl s(a + 2, L_INF), t(b + 2, L_INF); s[0] = -L_INF; t[0] = -L_INF; rep1(i, a + 1) cin >> s[i]; rep1(i, b + 1) cin >> t[i]; rep(i, q) { ll x; cin >> x; ll s_idx = lower_bound(all(s), x) - s.begin(); ll t_idx = lower_bound(all(t), x) - t.begin(); ll res = L_INF; for (int j = s_idx - 1; j <= s_idx; j++) { for (int k = t_idx - 1; k <= t_idx; k++) { res = min(res, abs(x - s[j]) + abs(s[j] - t[k])); res = min(res, abs(x - t[k]) + abs(s[j] - t[k])); } } cout << res << endl; } }
[ "expression.operation.unary.add" ]
924,539
924,540
u929582923
cpp
p03112
#include <bits/stdc++.h> using namespace std; //#include <boost/multiprecision/cpp_int.hpp> // using multiInt = boost::multiprecision::cpp_int; using ll = long long int; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; template <typename Q_temp> using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>; const int INF = (int)1e9; const ll LINF = (ll)4e18; const ll MOD = (ll)(1e9 + 7); const double PI = acos(-1.0); const int limit = 200010; #define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i) #define rep(i, n) REP(i, 0, n) #define MP make_pair #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl #define all(v) v.begin(), v.end() #define NP(v) next_permutation(all(v)) #define dbg(x_) cerr << #x_ << ":" << x_ << endl; #define dbg2(x_) \ for (auto a_ : x_) \ cerr << a_ << " "; \ cerr << endl; #define dbg3(x_, sx_) \ rep(i, sx_) cerr << x_[i] << " "; \ cerr << endl; vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0}; vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0}; //------------------------------------------------------ int main() { cin.tie(0); ios::sync_with_stdio(false); ll a, b, q; cin >> a >> b >> q; vector<ll> s(a + 2), t(b + 2); s[0] = t[0] = -LINF, s[a + 1] = t[b + 1] = LINF; for (int i = 1; i <= a; ++i) cin >> s[i]; for (int i = 1; i <= b; ++i) cin >> t[i]; rep(query, q) { ll x; cin >> x; auto itr_sh = lower_bound(all(s), x); auto itr_te = lower_bound(all(t), x); ll L_sh = x - *(itr_sh - 1); ll L_te = x - *(itr_te - 1); ll R_sh = *itr_sh - x; ll R_te = *itr_te - x; ll LL = max(L_sh, L_te); ll RR = max(R_sh, R_te); ll Ls_Rt = 2 * L_sh + R_te; ll Rt_Ls = L_sh + 2 * R_te; ll Lt_Rs = 2 * L_te + R_sh; ll Rs_Lt = L_te + 2 * R_sh; cout << min({LL, RR, Ls_Rt, Rt_Ls, Lt_Rs, Rs_Lt}) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; //#include <boost/multiprecision/cpp_int.hpp> // using multiInt = boost::multiprecision::cpp_int; using ll = long long int; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; template <typename Q_temp> using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>; const int INF = (int)1e9; const ll LINF = (ll)1e18; const ll MOD = (ll)(1e9 + 7); const double PI = acos(-1.0); const int limit = 200010; #define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i) #define rep(i, n) REP(i, 0, n) #define MP make_pair #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl #define all(v) v.begin(), v.end() #define NP(v) next_permutation(all(v)) #define dbg(x_) cerr << #x_ << ":" << x_ << endl; #define dbg2(x_) \ for (auto a_ : x_) \ cerr << a_ << " "; \ cerr << endl; #define dbg3(x_, sx_) \ rep(i, sx_) cerr << x_[i] << " "; \ cerr << endl; vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0}; vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0}; //------------------------------------------------------ int main() { cin.tie(0); ios::sync_with_stdio(false); ll a, b, q; cin >> a >> b >> q; vector<ll> s(a + 2), t(b + 2); s[0] = t[0] = -LINF, s[a + 1] = t[b + 1] = LINF; for (int i = 1; i <= a; ++i) cin >> s[i]; for (int i = 1; i <= b; ++i) cin >> t[i]; rep(query, q) { ll x; cin >> x; auto itr_sh = lower_bound(all(s), x); auto itr_te = lower_bound(all(t), x); ll L_sh = x - *(itr_sh - 1); ll L_te = x - *(itr_te - 1); ll R_sh = *itr_sh - x; ll R_te = *itr_te - x; ll LL = max(L_sh, L_te); ll RR = max(R_sh, R_te); ll Ls_Rt = 2 * L_sh + R_te; ll Rt_Ls = L_sh + 2 * R_te; ll Lt_Rs = 2 * L_te + R_sh; ll Rs_Lt = L_te + 2 * R_sh; cout << min({LL, RR, Ls_Rt, Rt_Ls, Lt_Rs, Rs_Lt}) << endl; } return 0; }
[ "literal.number.change" ]
924,541
924,542
u878615689
cpp
p03112
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (ll i = 0; i < n; i++) #define repl(i, l, r) for (ll i = (l); i < (r); i++) #define per(i, n) for (ll i = n - 1; i >= 0; i--) #define perl(i, r, l) for (ll i = r - 1; i >= l; i--) #define fi first #define se second #define mp make_pair #define pb push_back #define ins insert #define pqueue(x) priority_queue<x, vector<x>, greater<x>> #define all(x) (x).begin(), (x).end() #define CST(x) cout << fixed << setprecision(x) #define vtpl(x, y, z) vector<tuple<x, y, z>> //#define at(x,i) get<i>(x);// #define rev(x) reverse(x); using ll = long long; using vl = vector<ll>; using vvl = vector<vector<ll>>; using pl = pair<ll, ll>; using vpl = vector<pl>; using vvpl = vector<vpl>; const ll MOD = 1000000007; const ll MOD9 = 998244353; const int inf = 1e9 + 10; const ll INF = 4e18; const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1}; const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1}; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { ll a, b, q; cin >> a >> b >> q; vl s(a), t(b); rep(i, a) cin >> s[i]; rep(i, b) cin >> t[i]; rep(i, q) { ll x; cin >> x; ll sr = lower_bound(all(s), x) - s.begin(); ll sl = sr - 1; ll tr = lower_bound(all(t), x) - t.begin(); ll tl = tr - 1; ll ans = INF; if (sl >= 0 && tl >= 0) { ll l = min(s[sl], t[tl]); chmin(ans, x - l); } if (sr < a && tl >= 0) { ll l = s[sr] - t[tl] + min(s[sr] - x, x - t[tl]); chmin(ans, l); } if (sr < a && tr < b) { ll l = max(s[sl], t[tl]); chmin(ans, l - x); } if (sl >= 0 && tr < b) { ll l = t[tr] - s[sl] + min(t[tr] - x, x - s[sl]); chmin(ans, l); } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (ll i = 0; i < n; i++) #define repl(i, l, r) for (ll i = (l); i < (r); i++) #define per(i, n) for (ll i = n - 1; i >= 0; i--) #define perl(i, r, l) for (ll i = r - 1; i >= l; i--) #define fi first #define se second #define mp make_pair #define pb push_back #define ins insert #define pqueue(x) priority_queue<x, vector<x>, greater<x>> #define all(x) (x).begin(), (x).end() #define CST(x) cout << fixed << setprecision(x) #define vtpl(x, y, z) vector<tuple<x, y, z>> //#define at(x,i) get<i>(x);// #define rev(x) reverse(x); using ll = long long; using vl = vector<ll>; using vvl = vector<vector<ll>>; using pl = pair<ll, ll>; using vpl = vector<pl>; using vvpl = vector<vpl>; const ll MOD = 1000000007; const ll MOD9 = 998244353; const int inf = 1e9 + 10; const ll INF = 4e18; const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1}; const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1}; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { ll a, b, q; cin >> a >> b >> q; vl s(a), t(b); rep(i, a) cin >> s[i]; rep(i, b) cin >> t[i]; rep(i, q) { ll x; cin >> x; ll sr = lower_bound(all(s), x) - s.begin(); ll sl = sr - 1; ll tr = lower_bound(all(t), x) - t.begin(); ll tl = tr - 1; ll ans = INF; if (sl >= 0 && tl >= 0) { ll l = min(s[sl], t[tl]); chmin(ans, x - l); } if (sr < a && tl >= 0) { ll l = s[sr] - t[tl] + min(s[sr] - x, x - t[tl]); chmin(ans, l); } if (sr < a && tr < b) { ll l = max(s[sr], t[tr]); chmin(ans, l - x); } if (sl >= 0 && tr < b) { ll l = t[tr] - s[sl] + min(t[tr] - x, x - s[sl]); chmin(ans, l); } cout << ans << endl; } }
[ "identifier.change", "variable_access.subscript.index.change", "call.arguments.change" ]
924,545
924,546
u160429264
cpp
p03112
#include <algorithm> #include <cstdlib> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; #define rep(i, n) for (long int i = 0; i < n; i++) int main() { long int a, b, q; cin >> a >> b >> q; long int s[a]; rep(i, a) cin >> s[i]; long int t[b]; rep(i, b) cin >> t[i]; sort(s, s + a); sort(t, t + b); long int x1[q]; rep(i, q) cin >> x1[i]; rep(i, q) { long int x = x1[i]; long int idx1 = lower_bound(s, s + a, x) - s; long int idx3 = lower_bound(t, t + b, x) - t; long int ans; ans = 10000000000000000; if (idx1 < a && idx3 < b) { ans = min(ans, max(s[idx1] - x, t[idx3] - x)); } if (idx1 > 0 && idx3 > 0) { ans = min(ans, max(x - s[idx1 - 1], x - t[idx3 - 1])); } if (idx1 < a && idx3 > 0) { ans = min(ans, min(s[idx1] - x, (x - t[idx3 - 1]) * 2 + max(s[idx1] - x, x - t[idx3 - 1]))); } if (idx1 > 0 && idx3 < b) { ans = min(ans, min(x - s[idx1 - 1], t[idx3] - x) * 2 + max(x - s[idx1 - 1], t[idx3] - x)); } cout << ans << endl; } }
#include <algorithm> #include <cstdlib> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; #define rep(i, n) for (long int i = 0; i < n; i++) int main() { long int a, b, q; cin >> a >> b >> q; long int s[a]; rep(i, a) cin >> s[i]; long int t[b]; rep(i, b) cin >> t[i]; sort(s, s + a); sort(t, t + b); long int x1[q]; rep(i, q) cin >> x1[i]; rep(i, q) { long int x = x1[i]; long int idx1 = lower_bound(s, s + a, x) - s; long int idx3 = lower_bound(t, t + b, x) - t; long int ans; ans = 10000000000000000; if (idx1 < a && idx3 < b) { ans = min(ans, max(s[idx1] - x, t[idx3] - x)); } if (idx1 > 0 && idx3 > 0) { ans = min(ans, max(x - s[idx1 - 1], x - t[idx3 - 1])); } if (idx1 < a && idx3 > 0) { ans = min(ans, min(s[idx1] - x, x - t[idx3 - 1]) * 2 + max(s[idx1] - x, x - t[idx3 - 1])); } if (idx1 > 0 && idx3 < b) { ans = min(ans, min(x - s[idx1 - 1], t[idx3] - x) * 2 + max(x - s[idx1 - 1], t[idx3] - x)); } cout << ans << endl; } }
[ "call.arguments.change" ]
924,549
924,550
u416773418
cpp
p03112
#include <algorithm> #include <cstdlib> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { long int a, b, q; cin >> a >> b >> q; long int s[a]; rep(i, a) cin >> s[i]; long int t[b]; rep(i, b) cin >> t[i]; sort(s, s + a); sort(t, t + b); long int x1[q]; rep(i, q) cin >> x1[i]; rep(i, q) { long int x = x1[i]; int idx1 = lower_bound(s, s + a, x) - s; int idx3 = lower_bound(t, t + b, x) - t; long int ans; ans = 10000000000000000; if (idx1 < a && idx3 < b) { ans = min(ans, max(s[idx1] - x, t[idx3] - x)); } if (idx1 > 0 && idx3 > 0) { ans = min(ans, max(x - s[idx1 - 1], x - t[idx3 - 1])); } if (idx1 < a && idx3 > 0) { ans = min(ans, min(s[idx1] - x, (x - t[idx3 - 1]) * 2 + max(s[idx1] - x, x - t[idx3 - 1]))); } if (idx1 > 0 && idx3 < b) { ans = min(ans, min(x - s[idx1 - 1], t[idx3] - x) * 2 + max(x - s[idx1 - 1], t[idx3] - x)); } cout << ans << endl; } }
#include <algorithm> #include <cstdlib> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; #define rep(i, n) for (long int i = 0; i < n; i++) int main() { long int a, b, q; cin >> a >> b >> q; long int s[a]; rep(i, a) cin >> s[i]; long int t[b]; rep(i, b) cin >> t[i]; sort(s, s + a); sort(t, t + b); long int x1[q]; rep(i, q) cin >> x1[i]; rep(i, q) { long int x = x1[i]; long int idx1 = lower_bound(s, s + a, x) - s; long int idx3 = lower_bound(t, t + b, x) - t; long int ans; ans = 10000000000000000; if (idx1 < a && idx3 < b) { ans = min(ans, max(s[idx1] - x, t[idx3] - x)); } if (idx1 > 0 && idx3 > 0) { ans = min(ans, max(x - s[idx1 - 1], x - t[idx3 - 1])); } if (idx1 < a && idx3 > 0) { ans = min(ans, min(s[idx1] - x, x - t[idx3 - 1]) * 2 + max(s[idx1] - x, x - t[idx3 - 1])); } if (idx1 > 0 && idx3 < b) { ans = min(ans, min(x - s[idx1 - 1], t[idx3] - x) * 2 + max(x - s[idx1 - 1], t[idx3] - x)); } cout << ans << endl; } }
[ "variable_declaration.type.widen.change", "call.arguments.change" ]
924,551
924,550
u416773418
cpp
p03112
#include "bits/stdc++.h" using namespace std; const long long INF = 20000000001; void Main() { int a, b, q; cin >> a >> b >> q; vector<long long> s, t; for (int i = 0; i < a; i++) { long long tmp; cin >> tmp; s.push_back(tmp); } for (int i = 0; i < b; i++) { long long tmp; cin >> tmp; t.push_back(tmp); } sort(s.begin(), s.end()); sort(t.begin(), t.end()); for (int i = 0; i < q; i++) { long long x; cin >> x; int sl = -1, sr = s.size(); while (sr - sl > 1) { int c = (sl + sr) / 2; if (x <= s[c]) sr = c; else sl = c; } int tl = -1, tr = s.size(); while (tr - tl > 1) { int c = (tl + tr) / 2; if (x <= t[c]) tr = c; else tl = c; } long long ans = INF; if (sr < s.size() && tr < t.size()) { ans = min(ans, abs(s[sr] - x) + abs(t[tr] - s[sr])); } if (sr < s.size() && tr > 0) { ans = min(ans, abs(s[sr] - x) + abs(t[tr - 1] - s[sr])); } if (sr > 0 && tr < t.size()) { ans = min(ans, abs(s[sr - 1] - x) + abs(t[tr] - s[sr - 1])); } if (sr > 0 && tr > 0) { ans = min(ans, abs(s[sr - 1] - x) + abs(t[tr - 1] - s[sr - 1])); } if (sr < s.size() && tr < t.size()) { ans = min(ans, abs(t[tr] - x) + abs(s[sr] - t[tr])); } if (tr < t.size() && sr > 0) { ans = min(ans, abs(t[tr] - x) + abs(s[sr - 1] - t[tr])); } if (tr > 0 && sr < s.size()) { ans = min(ans, abs(t[tr - 1] - x) + abs(s[sr] - t[tr - 1])); } if (tr > 0 && sr > 0) { ans = min(ans, abs(t[tr - 1] - x) + abs(s[sr - 1] - t[tr - 1])); } cout << ans << endl; } } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(15); Main(); return 0; }
#include "bits/stdc++.h" using namespace std; const long long INF = 20000000001; void Main() { int a, b, q; cin >> a >> b >> q; vector<long long> s, t; for (int i = 0; i < a; i++) { long long tmp; cin >> tmp; s.push_back(tmp); } for (int i = 0; i < b; i++) { long long tmp; cin >> tmp; t.push_back(tmp); } sort(s.begin(), s.end()); sort(t.begin(), t.end()); for (int i = 0; i < q; i++) { long long x; cin >> x; int sl = -1, sr = s.size(); while (sr - sl > 1) { int c = (sl + sr) / 2; if (x <= s[c]) sr = c; else sl = c; } int tl = -1, tr = t.size(); while (tr - tl > 1) { int c = (tl + tr) / 2; if (x <= t[c]) tr = c; else tl = c; } long long ans = INF; if (sr < s.size() && tr < t.size()) { ans = min(ans, abs(s[sr] - x) + abs(t[tr] - s[sr])); } if (sr < s.size() && tr > 0) { ans = min(ans, abs(s[sr] - x) + abs(t[tr - 1] - s[sr])); } if (sr > 0 && tr < t.size()) { ans = min(ans, abs(s[sr - 1] - x) + abs(t[tr] - s[sr - 1])); } if (sr > 0 && tr > 0) { ans = min(ans, abs(s[sr - 1] - x) + abs(t[tr - 1] - s[sr - 1])); } if (sr < s.size() && tr < t.size()) { ans = min(ans, abs(t[tr] - x) + abs(s[sr] - t[tr])); } if (tr < t.size() && sr > 0) { ans = min(ans, abs(t[tr] - x) + abs(s[sr - 1] - t[tr])); } if (tr > 0 && sr < s.size()) { ans = min(ans, abs(t[tr - 1] - x) + abs(s[sr] - t[tr - 1])); } if (tr > 0 && sr > 0) { ans = min(ans, abs(t[tr - 1] - x) + abs(s[sr - 1] - t[tr - 1])); } cout << ans << endl; } } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(15); Main(); return 0; }
[ "identifier.change" ]
924,557
924,558
u931698099
cpp
p03112
#include <bits/stdc++.h> using namespace std; #define ALL(a) (a).begin(), (a).end() typedef long long ll; typedef pair<ll, ll> P; const ll MOD = 1e9 + 7; const ll inf = 1LL << 60; const int int_inf = 100000000; const double eps = 1e-9; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { int a, b, q; cin >> a >> b >> q; vector<int> s(a), t(b); for (int i = 0; i < a; i++) cin >> s[i]; for (int i = 0; i < b; i++) cin >> t[i]; for (int i = 0; i < q; i++) { int x; cin >> x; int left_s, right_s, left_t, right_t; right_s = lower_bound(ALL(s), x) - s.begin(); left_s = right_s - 1; right_t = lower_bound(ALL(t), x) - t.begin(); left_t = right_t - 1; // cout << left_s << " " << right_s << " " << left_t << " " << right_t << // endl; int ans = int_inf; // right right if (right_s < a and right_t < b) chmin(ans, max(s[right_s], t[right_t]) - x); // left left if (left_s >= 0 and left_t >= 0) chmin(ans, x - min(s[left_s], t[left_t])); // right left if (right_s < a and left_t >= 0) { ans = min({ans, (s[right_s] - x) * 2 + x - t[left_t], (x - t[left_t]) * 2 + s[right_s] - x}); } // left right if (left_s >= 0 and right_t < b) { ans = min({ans, (x - s[left_s]) * 2 + t[right_t] - x, (t[right_t] - x) * 2 + x - s[left_s]}); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ALL(a) (a).begin(), (a).end() typedef long long ll; typedef pair<ll, ll> P; const ll MOD = 1e9 + 7; const ll inf = 1LL << 60; const int int_inf = 100000000; const double eps = 1e-9; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { int a, b, q; cin >> a >> b >> q; vector<ll> s(a), t(b); for (int i = 0; i < a; i++) cin >> s[i]; for (int i = 0; i < b; i++) cin >> t[i]; for (int i = 0; i < q; i++) { ll x; cin >> x; int left_s, right_s, left_t, right_t; right_s = lower_bound(ALL(s), x) - s.begin(); left_s = right_s - 1; right_t = lower_bound(ALL(t), x) - t.begin(); left_t = right_t - 1; // cout << left_s << " " << right_s << " " << left_t << " " << right_t << // endl; ll ans = inf; // right right if (right_s < a and right_t < b) chmin(ans, max(s[right_s], t[right_t]) - x); // left left if (left_s >= 0 and left_t >= 0) chmin(ans, x - min(s[left_s], t[left_t])); // right left if (right_s < a and left_t >= 0) { ans = min({ans, (s[right_s] - x) * 2 + x - t[left_t], (x - t[left_t]) * 2 + s[right_s] - x}); } // left right if (left_s >= 0 and right_t < b) { ans = min({ans, (x - s[left_s]) * 2 + t[right_t] - x, (t[right_t] - x) * 2 + x - s[left_s]}); } cout << ans << endl; } return 0; }
[ "variable_declaration.type.change", "variable_declaration.value.change", "identifier.change" ]
924,559
924,560
u831873811
cpp
p03112
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(vec) vec.begin(), vec.end() typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; const ll mod = 1e9 + 7; const ll inf = 1ll << 60; int main() { int a, b, q; cin >> a >> b >> q; vector<ll> s(a + 4); s[0] = -inf - 1; s[1] = -inf; s[a + 2] = inf; s[a + 3] = inf + 1; vector<ll> t(b + 4); t[0] = -inf - 1; t[1] = -inf; t[b + 2] = inf; t[b + 3] = inf + 1; for (int i = 2; i <= a + 1; i++) cin >> s[i]; for (int i = 2; i <= b + 1; i++) cin >> t[i]; vector<ll> x(q); rep(i, q) cin >> x[i]; rep(i, q) { ll a1 = *lower_bound(all(s), x[i]); ll b1 = *prev(lower_bound(all(s), x[i]), 1); ll c1 = *lower_bound(all(t), a1); ll d1 = *prev(lower_bound(all(t), a1), 1); ll e1 = *lower_bound(all(t), b1); ll f1 = *prev(lower_bound(all(t), b1), 1); ll dist1 = inf; chmin(dist1, abs(x[i] - a1) + abs(a1 - c1)); chmin(dist1, abs(x[i] - a1) + abs(a1 - d1)); chmin(dist1, abs(x[i] - b1) + abs(b1 - e1)); chmin(dist1, abs(x[i] - b1) + abs(b1 - f1)); ll a2 = *lower_bound(all(t), x[i]); ll b2 = *prev(lower_bound(all(t), x[i]), 1); ll c2 = *lower_bound(all(s), a2); ll d2 = *prev(lower_bound(all(s), a2), 1); ll e2 = *lower_bound(all(s), b2); ll f2 = *prev(lower_bound(all(s), b2), 1); ll dist2 = inf; chmin(dist2, abs(x[i] - a2) + abs(a2 - c2)); chmin(dist2, abs(x[i] - a2) + abs(a2 - d2)); chmin(dist2, abs(x[i] - b2) + abs(b2 - e2)); chmin(dist2, abs(x[i] - b2) + abs(b2 - f2)); ll ans = min(dist1, dist2); cout << ans << endl; } }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(vec) vec.begin(), vec.end() typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; const ll mod = 1e9 + 7; const ll inf = 1ll << 60; int main() { int a, b, q; cin >> a >> b >> q; vector<ll> s(a + 4); s[0] = -inf - 1; s[1] = -inf; s[a + 2] = inf; s[a + 3] = inf + 1; vector<ll> t(b + 4); t[0] = -inf - 1; t[1] = -inf; t[b + 2] = inf; t[b + 3] = inf + 1; for (int i = 2; i <= a + 1; i++) cin >> s[i]; for (int i = 2; i <= b + 1; i++) cin >> t[i]; vector<ll> x(q); rep(i, q) cin >> x[i]; rep(i, q) { ll a1 = *lower_bound(all(s), x[i]); ll b1 = *prev(lower_bound(all(s), x[i]), 1); ll c1 = *lower_bound(all(t), a1); ll d1 = *prev(lower_bound(all(t), a1), 1); ll e1 = *lower_bound(all(t), b1); ll f1 = *prev(lower_bound(all(t), b1), 1); ll dist1 = inf; chmin(dist1, abs(x[i] - a1) + abs(a1 - c1)); chmin(dist1, abs(x[i] - a1) + abs(a1 - d1)); chmin(dist1, abs(x[i] - b1) + abs(b1 - e1)); chmin(dist1, abs(x[i] - b1) + abs(b1 - f1)); ll a2 = *lower_bound(all(t), x[i]); ll b2 = *prev(lower_bound(all(t), x[i]), 1); ll c2 = *lower_bound(all(s), a2); ll d2 = *prev(lower_bound(all(s), a2), 1); ll e2 = *lower_bound(all(s), b2); ll f2 = *prev(lower_bound(all(s), b2), 1); ll dist2 = inf; chmin(dist2, abs(x[i] - a2) + abs(a2 - c2)); chmin(dist2, abs(x[i] - a2) + abs(a2 - d2)); chmin(dist2, abs(x[i] - b2) + abs(b2 - e2)); chmin(dist2, abs(x[i] - b2) + abs(b2 - f2)); ll ans = min(dist1, dist2); cout << ans << endl; } }
[]
924,561
924,562
u136342563
cpp
p03112
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll inf = 1e15; const int maxn = 1e5 + 7; typedef long long ll; int T; int a, b, c, n; ll la[maxn], lb[maxn], x, ans; double pi = 3.14159265359; double d, r; int main() { scanf("%d%d%d", &a, &b, &c); for (int i = 0; i < a; i++) scanf("%lld", &la[i]); for (int i = 0; i < b; i++) scanf("%lld", &lb[i]); while (c--) { scanf("%lld", &x); ans = inf; int aa = lower_bound(la, la + a, x) - la; int bb = lower_bound(lb, lb + b, x) - lb; // cout<<bL<<" "<<bR<<endl; if (aa < a && bb < b) ans = min(ans, max(la[aa], lb[bb]) - x); if (aa && bb) ans = min(ans, x - min(la[aa - 1], lb[bb - 1])); if (aa && bb < b) ans = min(ans, max(x - la[aa - 1], lb[bb] - x) + min(x - la[aa - 1], lb[bb] - x)); if (aa < a && bb) ans = min(ans, max(x - lb[bb - 1], la[aa] - x) + min(x - lb[bb - 1], la[aa] - x)); printf("%lld\n", ans); } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll inf = 1e15; const int maxn = 1e5 + 7; typedef long long ll; int T; int a, b, c, n; ll la[maxn], lb[maxn], x, ans; double pi = 3.14159265359; double d, r; int main() { scanf("%d%d%d", &a, &b, &c); for (int i = 0; i < a; i++) scanf("%lld", &la[i]); for (int i = 0; i < b; i++) scanf("%lld", &lb[i]); while (c--) { scanf("%lld", &x); ans = inf; int aa = lower_bound(la, la + a, x) - la; int bb = lower_bound(lb, lb + b, x) - lb; // cout<<bL<<" "<<bR<<endl; if (aa < a && bb < b) ans = min(ans, max(la[aa], lb[bb]) - x); if (aa && bb) ans = min(ans, x - min(la[aa - 1], lb[bb - 1])); if (aa && bb < b) ans = min(ans, max(x - la[aa - 1], lb[bb] - x) + 2 * min(x - la[aa - 1], lb[bb] - x)); if (aa < a && bb) ans = min(ans, max(x - lb[bb - 1], la[aa] - x) + 2 * min(x - lb[bb - 1], la[aa] - x)); printf("%lld\n", ans); } }
[ "assignment.change" ]
924,563
924,564
u551243477
cpp
p03112
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; #define INF LONG_MAX #define MOD 1000000007 #define rng(a) a.begin(), a.end() #define rrng(a) a.end(), a.begin() #define rep(i, N) for (int i = 0; i < N; i++) int main() { ios::sync_with_stdio(false); cin.tie(0); int A, B, Q; cin >> A >> B >> Q; vector<ll> s(A), t(B), x(Q); for (int i = 0; i < A; i++) cin >> s[i]; for (int i = 0; i < B; i++) cin >> t[i]; for (int i = 0; i < Q; i++) cin >> x[i]; sort(rng(s)); sort(rng(t)); for (int i = 0; i < Q; i++) { auto sp = lower_bound(rng(s), x[i]); auto tp = lower_bound(rng(t), x[i]); ll ans = LONG_MAX; // sr->t if (sp < s.end()) { auto p = lower_bound(rng(t), *sp); ll D = abs(x[i] - *sp); if (p < t.end()) ans = min(ans, abs(*sp - *p) + D); if (p > t.begin()) ans = min(ans, abs(*(p - 1) - *sp) + D); } // sl->t if (sp > s.begin()) { sp--; auto p = lower_bound(rng(t), *sp); ll D = abs(x[i] - *sp); if (p < t.end()) ans = min(ans, abs(*sp - *p) + D); if (p > t.begin()) ans = min(ans, abs(*(p - 1) - *sp) + D); } // tr->s if (tp < t.end()) { auto p = lower_bound(rng(s), *tp); ll D = abs(x[i] - *tp); if (p < s.end()) ans = min(ans, abs(*tp - *p) + D); if (p > s.begin()) ans = min(ans, abs(*(p - 1) - *tp) + D); } // tl->s if (tp > t.begin()) { tp--; auto p = lower_bound(rng(s), *tp); ll D = abs(x[i] - *tp); if (p < t.end()) ans = min(ans, abs(*tp - *p) + D); if (p > t.begin()) ans = min(ans, abs(*(p - 1) - *tp) + D); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; #define INF LONG_MAX #define MOD 1000000007 #define rng(a) a.begin(), a.end() #define rrng(a) a.end(), a.begin() #define rep(i, N) for (int i = 0; i < N; i++) int main() { ios::sync_with_stdio(false); cin.tie(0); int A, B, Q; cin >> A >> B >> Q; vector<ll> s(A), t(B), x(Q); for (int i = 0; i < A; i++) cin >> s[i]; for (int i = 0; i < B; i++) cin >> t[i]; for (int i = 0; i < Q; i++) cin >> x[i]; sort(rng(s)); sort(rng(t)); for (int i = 0; i < Q; i++) { auto sp = lower_bound(rng(s), x[i]); auto tp = lower_bound(rng(t), x[i]); ll ans = LONG_MAX; // sr->t if (sp < s.end()) { auto p = lower_bound(rng(t), *sp); ll D = abs(x[i] - *sp); if (p < t.end()) ans = min(ans, abs(*sp - *p) + D); if (p > t.begin()) ans = min(ans, abs(*(p - 1) - *sp) + D); } // sl->t if (sp > s.begin()) { sp--; auto p = lower_bound(rng(t), *sp); ll D = abs(x[i] - *sp); if (p < t.end()) ans = min(ans, abs(*sp - *p) + D); if (p > t.begin()) ans = min(ans, abs(*(p - 1) - *sp) + D); } // tr->s if (tp < t.end()) { auto p = lower_bound(rng(s), *tp); ll D = abs(x[i] - *tp); if (p < s.end()) ans = min(ans, abs(*tp - *p) + D); if (p > s.begin()) ans = min(ans, abs(*(p - 1) - *tp) + D); } // tl->s if (tp > t.begin()) { tp--; auto p = lower_bound(rng(s), *tp); ll D = abs(x[i] - *tp); if (p < s.end()) ans = min(ans, abs(*tp - *p) + D); if (p > s.begin()) ans = min(ans, abs(*(p - 1) - *tp) + D); } cout << ans << endl; } return 0; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
924,565
924,566
u864171425
cpp
p03112
/* これを入れて実行 g++ code.cpp ./a.out */ #include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> #define all(x) (x).begin(), (x).end() using namespace std; typedef long long ll; typedef long double ld; int dy4[4] = {-1, 0, +1, 0}; int dx4[4] = {0, +1, 0, -1}; int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const long long INF = 1LL << 60; const ll MOD = 1e9 + 7; bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) { return f.second > s.second; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll nCr(ll n, ll r) { if (r == 0 || r == n) { return 1; } else if (r == 1) { return n; } return (nCr(n - 1, r) + nCr(n - 1, r - 1)); } ll nPr(ll n, ll r) { r = n - r; ll ret = 1; for (ll i = n; i >= r + 1; i--) ret *= i; return ret; } //-----------------------ここから----------- int main(void) { int a, b, q; cin >> a >> b >> q; vector<ll> s(a); vector<ll> t(a); for (int i = 0; i < a; i++) cin >> s[i]; for (int i = 0; i < b; i++) cin >> t[i]; vector<ll> qu(q); for (int i = 0; i < q; i++) cin >> qu[i]; for (int i = 0; i < q; i++) { ll x = qu[i]; ll nearsb = lower_bound(all(s), x) - s.begin() - 1; ll nearsf = nearsb + 1; ll neartb = lower_bound(all(t), x) - t.begin() - 1; ll neartf = nearsb + 1; ll ans = INF; if (nearsb >= 0 && neartb >= 0) { ans = min(ans, max(abs(x - s[nearsb]), abs(x - t[neartb]))); } if (nearsf < a && neartf < b) { ans = min(ans, max(abs(x - s[nearsf]), abs(x - t[neartf]))); } if (nearsb >= 0 && neartf < b) { ans = min(ans, abs(x - s[nearsb]) * 2 + abs(x - t[neartf])); ans = min(ans, abs(x - s[nearsb]) + abs(x - t[neartf]) * 2); } if (nearsf < a && neartb >= 0) { ans = min(ans, abs(x - s[nearsf]) * 2 + abs(x - t[neartb])); ans = min(ans, abs(x - s[nearsf]) + abs(x - t[neartb]) * 2); } cout << ans << endl; } }
/* これを入れて実行 g++ code.cpp ./a.out */ #include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> #define all(x) (x).begin(), (x).end() using namespace std; typedef long long ll; typedef long double ld; int dy4[4] = {-1, 0, +1, 0}; int dx4[4] = {0, +1, 0, -1}; int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const long long INF = 1LL << 60; const ll MOD = 1e9 + 7; bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) { return f.second > s.second; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll nCr(ll n, ll r) { if (r == 0 || r == n) { return 1; } else if (r == 1) { return n; } return (nCr(n - 1, r) + nCr(n - 1, r - 1)); } ll nPr(ll n, ll r) { r = n - r; ll ret = 1; for (ll i = n; i >= r + 1; i--) ret *= i; return ret; } //-----------------------ここから----------- int main(void) { int a, b, q; cin >> a >> b >> q; vector<ll> s(a); vector<ll> t(b); for (int i = 0; i < a; i++) cin >> s[i]; for (int i = 0; i < b; i++) cin >> t[i]; vector<ll> qu(q); for (int i = 0; i < q; i++) cin >> qu[i]; for (int i = 0; i < q; i++) { ll x = qu[i]; ll nearsb = lower_bound(all(s), x) - s.begin() - 1; ll nearsf = nearsb + 1; ll neartb = lower_bound(all(t), x) - t.begin() - 1; ll neartf = neartb + 1; ll ans = INF; if (nearsb >= 0 && neartb >= 0) { ans = min(ans, max(abs(x - s[nearsb]), abs(x - t[neartb]))); } if (nearsf < a && neartf < b) { ans = min(ans, max(abs(x - s[nearsf]), abs(x - t[neartf]))); } if (nearsb >= 0 && neartf < b) { ans = min(ans, abs(x - s[nearsb]) * 2 + abs(x - t[neartf])); ans = min(ans, abs(x - s[nearsb]) + abs(x - t[neartf]) * 2); } if (nearsf < a && neartb >= 0) { ans = min(ans, abs(x - s[nearsf]) * 2 + abs(x - t[neartb])); ans = min(ans, abs(x - s[nearsf]) + abs(x - t[neartb]) * 2); } cout << ans << endl; } }
[ "identifier.change", "expression.operation.binary.change" ]
924,571
924,572
u845000384
cpp
p03112
/* これを入れて実行 g++ code.cpp ./a.out */ #include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> #define all(x) (x).begin(), (x).end() using namespace std; typedef long long ll; typedef long double ld; int dy4[4] = {-1, 0, +1, 0}; int dx4[4] = {0, +1, 0, -1}; int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const long long INF = 1LL << 60; const ll MOD = 1e9 + 7; bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) { return f.second > s.second; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll nCr(ll n, ll r) { if (r == 0 || r == n) { return 1; } else if (r == 1) { return n; } return (nCr(n - 1, r) + nCr(n - 1, r - 1)); } ll nPr(ll n, ll r) { r = n - r; ll ret = 1; for (ll i = n; i >= r + 1; i--) ret *= i; return ret; } //-----------------------ここから----------- int main(void) { int a, b, q; cin >> a >> b >> q; vector<ll> s(a); vector<ll> t(a); for (int i = 0; i < a; i++) cin >> s[i]; for (int i = 0; i < b; i++) cin >> t[i]; vector<ll> qu(q); for (int i = 0; i < q; i++) cin >> qu[i]; for (int i = 0; i < q; i++) { ll x = qu[i]; ll nearsb = lower_bound(all(s), x) - s.begin() - 1; ll nearsf = nearsb + 1; ll neartb = lower_bound(all(t), x) - t.begin() - 1; ll neartf = nearsb + 1; ll ans = INF; if (nearsb >= 0 && neartb >= 0) { ans = min(ans, max(abs(x - s[nearsb]), abs(x - t[neartb]))); } if (nearsf < a && neartf < b) { ans = min(ans, max(abs(x - s[nearsb]), abs(x - t[neartb]))); } if (nearsb >= 0 && neartf < b) { ans = min(ans, abs(x - s[nearsb]) * 2 + abs(x - t[neartf])); ans = min(ans, abs(x - s[nearsb]) + abs(x - t[neartf]) * 2); } if (nearsf < a && neartb >= 0) { ans = min(ans, abs(x - s[nearsf]) * 2 + abs(x - t[neartb])); ans = min(ans, abs(x - s[nearsf]) + abs(x - t[neartb]) * 2); } cout << ans << endl; } }
/* これを入れて実行 g++ code.cpp ./a.out */ #include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> #define all(x) (x).begin(), (x).end() using namespace std; typedef long long ll; typedef long double ld; int dy4[4] = {-1, 0, +1, 0}; int dx4[4] = {0, +1, 0, -1}; int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const long long INF = 1LL << 60; const ll MOD = 1e9 + 7; bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) { return f.second > s.second; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll nCr(ll n, ll r) { if (r == 0 || r == n) { return 1; } else if (r == 1) { return n; } return (nCr(n - 1, r) + nCr(n - 1, r - 1)); } ll nPr(ll n, ll r) { r = n - r; ll ret = 1; for (ll i = n; i >= r + 1; i--) ret *= i; return ret; } //-----------------------ここから----------- int main(void) { int a, b, q; cin >> a >> b >> q; vector<ll> s(a); vector<ll> t(b); for (int i = 0; i < a; i++) cin >> s[i]; for (int i = 0; i < b; i++) cin >> t[i]; vector<ll> qu(q); for (int i = 0; i < q; i++) cin >> qu[i]; for (int i = 0; i < q; i++) { ll x = qu[i]; ll nearsb = lower_bound(all(s), x) - s.begin() - 1; ll nearsf = nearsb + 1; ll neartb = lower_bound(all(t), x) - t.begin() - 1; ll neartf = neartb + 1; ll ans = INF; if (nearsb >= 0 && neartb >= 0) { ans = min(ans, max(abs(x - s[nearsb]), abs(x - t[neartb]))); } if (nearsf < a && neartf < b) { ans = min(ans, max(abs(x - s[nearsf]), abs(x - t[neartf]))); } if (nearsb >= 0 && neartf < b) { ans = min(ans, abs(x - s[nearsb]) * 2 + abs(x - t[neartf])); ans = min(ans, abs(x - s[nearsb]) + abs(x - t[neartf]) * 2); } if (nearsf < a && neartb >= 0) { ans = min(ans, abs(x - s[nearsf]) * 2 + abs(x - t[neartb])); ans = min(ans, abs(x - s[nearsf]) + abs(x - t[neartb]) * 2); } cout << ans << endl; } }
[ "identifier.change", "expression.operation.binary.change", "assignment.value.change", "variable_access.subscript.index.change", "call.arguments.change" ]
924,573
924,572
u845000384
cpp
p03112
#include <bits/stdc++.h> using namespace std; using lint = long long; const lint inf = 1LL << 60; const lint mod = 1000000007; template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; } template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); lint a, b, q; cin >> a >> b >> q; vector<lint> s(a), t(b), x(q); for (int i = 0; i < a; ++i) { cin >> s[i]; } for (int i = 0; i < b; ++i) { cin >> t[i]; } for (int i = 0; i < q; ++i) { cin >> x[i]; } for (int i = 0; i < q; ++i) { lint ret = 1e15; lint rs = -1, ls = -1, rt = -1, lt = -1; auto its = lower_bound(s.begin(), s.end(), x[i]); if (its != s.end()) rs = *its; if (its != s.begin()) ls = *prev(its); auto itt = lower_bound(t.begin(), t.end(), x[i]); if (itt != t.end()) rt = *itt; if (itt != t.begin()) lt = *prev(itt); if (ls != -1 && lt != -1) { chmin(ret, x[i] - min(ls, lt)); } if (rs != -1 && rt != -1) { chmin(ret, max(rs, rt) - x[i]); } if (ls != -1 && rt != -1) { chmin(ret, min(x[i] - ls, rt - x[i]) + (rt - ls)); } if (rs != -1 && lt != -1) { chmin(ret, min(x[i] - rs, lt - x[i]) + (rs - lt)); } cout << ret << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; using lint = long long; const lint inf = 1LL << 60; const lint mod = 1000000007; template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; } template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); lint a, b, q; cin >> a >> b >> q; vector<lint> s(a), t(b), x(q); for (int i = 0; i < a; ++i) { cin >> s[i]; } for (int i = 0; i < b; ++i) { cin >> t[i]; } for (int i = 0; i < q; ++i) { cin >> x[i]; } for (int i = 0; i < q; ++i) { lint ret = 1e15; lint rs = -1, ls = -1, rt = -1, lt = -1; auto its = lower_bound(s.begin(), s.end(), x[i]); if (its != s.end()) rs = *its; if (its != s.begin()) ls = *prev(its); auto itt = lower_bound(t.begin(), t.end(), x[i]); if (itt != t.end()) rt = *itt; if (itt != t.begin()) lt = *prev(itt); if (ls != -1 && lt != -1) { chmin(ret, x[i] - min(ls, lt)); } if (rs != -1 && rt != -1) { chmin(ret, max(rs, rt) - x[i]); } if (ls != -1 && rt != -1) { chmin(ret, min(x[i] - ls, rt - x[i]) + (rt - ls)); } if (rs != -1 && lt != -1) { chmin(ret, min(x[i] - lt, rs - x[i]) + (rs - lt)); } cout << ret << "\n"; } return 0; }
[ "call.arguments.change", "call.arguments.add" ]
924,574
924,575
u756088996
cpp
p03112
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int A, B, Q; cin >> A >> B >> Q; vector<ll> s(A + 2), t(B + 2); s[0] = -1e18; s[A + 1] = 1e18; t[0] = s[0]; t[B + 1] = s[A + 1]; for (int i = 1; i < A + 1; i++) cin >> s[i]; for (int i = 1; i < B + 1; i++) cin >> t[i]; sort(s.begin(), s.end()); sort(t.begin(), t.end()); while (Q--) { ll x; cin >> x; int sR = lower_bound(s.begin(), s.end(), x) - s.begin(); int tR = lower_bound(t.begin(), t.end(), x) - t.begin(); ll ans = 1e18; for (int j = -1; j < 1; j++) { for (int k = -1; k < 1; k++) { int xs = s[sR + j], xt = t[tR + k]; ans = min(ans, min(abs(x - xs), abs(x - xt)) + abs(xs - xt)); } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int A, B, Q; cin >> A >> B >> Q; vector<ll> s(A + 2), t(B + 2); s[0] = -1e18; s[A + 1] = 1e18; t[0] = s[0]; t[B + 1] = s[A + 1]; for (int i = 1; i < A + 1; i++) cin >> s[i]; for (int i = 1; i < B + 1; i++) cin >> t[i]; sort(s.begin(), s.end()); sort(t.begin(), t.end()); while (Q--) { ll x; cin >> x; auto sR = lower_bound(s.begin(), s.end(), x) - s.begin(); auto tR = lower_bound(t.begin(), t.end(), x) - t.begin(); ll ans = 1e18; for (int j = -1; j < 1; j++) { for (int k = -1; k < 1; k++) { auto xs = s[sR + j], xt = t[tR + k]; ans = min(ans, min(abs(x - xs), abs(x - xt)) + abs(xs - xt)); } } cout << ans << endl; } return 0; }
[]
924,584
924,585
u519194615
cpp
p03112
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <iomanip> #include <iostream> #include <numeric> #include <queue> #include <string> #include <tuple> #include <vector> #define rep(i, n) for (ll i = 0; i < n; i++) #define dup(x, y) (((x) + (y)-1) / (y)) // dup * y >= x なる最小のdup. using namespace std; typedef long long ll; typedef unsigned long long ull; using Graph = vector<vector<ll>>; // std::cout<<std::fixed<<std::setprecision(10); int main() { ll A, B, Q; cin >> A >> B >> Q; // vector<pair<ll, ll>> s(A), t(B); // s_i とそれに最も近いt_iまでの距離 // vector<ll> x(Q); vector<pair<ll, ll>> arr; rep(i, A) { ll d; cin >> d; arr.push_back(make_pair(d, -1)); } rep(i, B) { ll d; cin >> d; arr.push_back(make_pair(d, -2)); } vector<ll> X(Q); rep(i, Q) { cin >> X[i]; arr.push_back(make_pair(X[i], i)); } ll s1, sA, t1, tB; s1 = arr[0].first; sA = arr[A - 1].first; t1 = arr[A].first; tB = arr[A + B - 1].first; sort(arr.begin(), arr.end()); ll x[Q][4]; // s0 < x < s1, t2 < x < t3 ll ns = s1; ll nt = t1; rep(i, A + B + Q) { if (arr[i].second >= 0) { x[arr[i].second][0] = ns; x[arr[i].second][2] = nt; } else if (arr[i].second == -1) { // s ns = arr[i].first; } else if (arr[i].second == -2) { nt = arr[i].first; } } ns = sA; nt = tB; for (ll i = A + B + Q - 1; i >= 0; i--) { if (arr[i].second > 0) { x[arr[i].second][1] = ns; x[arr[i].second][3] = nt; } else if (arr[i].second == -1) { // s ns = arr[i].first; } else if (arr[i].second == -2) { nt = arr[i].first; } } rep(i, Q) { ll ret0 = abs(X[i] - x[i][0]) + abs(x[i][0] - x[i][2]); ret0 = min(ret0, abs(X[i] - x[i][1]) + abs(x[i][1] - x[i][2])); ret0 = min(ret0, abs(X[i] - x[i][0]) + abs(x[i][0] - x[i][3])); ret0 = min(ret0, abs(X[i] - x[i][1]) + abs(x[i][1] - x[i][3])); ret0 = min(ret0, abs(X[i] - x[i][2]) + abs(x[i][2] - x[i][0])); ret0 = min(ret0, abs(X[i] - x[i][3]) + abs(x[i][3] - x[i][0])); ret0 = min(ret0, abs(X[i] - x[i][2]) + abs(x[i][2] - x[i][1])); ret0 = min(ret0, abs(X[i] - x[i][3]) + abs(x[i][3] - x[i][1])); cout << ret0 << endl; } return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <iomanip> #include <iostream> #include <numeric> #include <queue> #include <string> #include <tuple> #include <vector> #define rep(i, n) for (ll i = 0; i < n; i++) #define dup(x, y) (((x) + (y)-1) / (y)) // dup * y >= x なる最小のdup. using namespace std; typedef long long ll; typedef unsigned long long ull; using Graph = vector<vector<ll>>; // std::cout<<std::fixed<<std::setprecision(10); int main() { ll A, B, Q; cin >> A >> B >> Q; // vector<pair<ll, ll>> s(A), t(B); // s_i とそれに最も近いt_iまでの距離 // vector<ll> x(Q); vector<pair<ll, ll>> arr; rep(i, A) { ll d; cin >> d; arr.push_back(make_pair(d, -1)); } rep(i, B) { ll d; cin >> d; arr.push_back(make_pair(d, -2)); } vector<ll> X(Q); rep(i, Q) { cin >> X[i]; arr.push_back(make_pair(X[i], i)); } ll s1, sA, t1, tB; s1 = arr[0].first; sA = arr[A - 1].first; t1 = arr[A].first; tB = arr[A + B - 1].first; sort(arr.begin(), arr.end()); ll x[Q][4]; // s0 < x < s1, t2 < x < t3 ll ns = s1; ll nt = t1; rep(i, A + B + Q) { if (arr[i].second >= 0) { x[arr[i].second][0] = ns; x[arr[i].second][2] = nt; } else if (arr[i].second == -1) { // s ns = arr[i].first; } else if (arr[i].second == -2) { nt = arr[i].first; } } ns = sA; nt = tB; for (ll i = A + B + Q - 1; i >= 0; i--) { if (arr[i].second >= 0) { x[arr[i].second][1] = ns; x[arr[i].second][3] = nt; } else if (arr[i].second == -1) { ns = arr[i].first; } else if (arr[i].second == -2) { nt = arr[i].first; } } rep(i, Q) { ll ret0 = abs(X[i] - x[i][0]) + abs(x[i][0] - x[i][2]); ret0 = min(ret0, abs(X[i] - x[i][1]) + abs(x[i][1] - x[i][2])); ret0 = min(ret0, abs(X[i] - x[i][0]) + abs(x[i][0] - x[i][3])); ret0 = min(ret0, abs(X[i] - x[i][1]) + abs(x[i][1] - x[i][3])); ret0 = min(ret0, abs(X[i] - x[i][2]) + abs(x[i][2] - x[i][0])); ret0 = min(ret0, abs(X[i] - x[i][3]) + abs(x[i][3] - x[i][0])); ret0 = min(ret0, abs(X[i] - x[i][2]) + abs(x[i][2] - x[i][1])); ret0 = min(ret0, abs(X[i] - x[i][3]) + abs(x[i][3] - x[i][1])); cout << ret0 << endl; } return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
924,588
924,589
u017293723
cpp
p03112
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; struct edge { ll to, cost; }; #define rep(i, n) for (ll i = 0; i < n; ++i) #define rep1(i, n) for (ll i = 1; i <= n; ++i) #define eachdo(e, array) for (const auto &e : array) #define upper_index(v, a) \ (ll) distance(v.begin(), upper_bound((v).begin(), (v).end(), a)) #define lower_index(v, a) \ (ll) distance(v.begin(), lower_bound((v).begin(), (v).end(), a)) 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; } const int inf = 1 << 28; const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; struct Graph { public: ll V; vector<vector<edge>> G; vector<vector<ll>> Gmat; Graph(ll node) { V = node; G.resize(V); } void add(ll from, ll to, ll cost = 1) { G[from].push_back({to, cost}); } vector<vector<ll>> WarshallFloyd() { Gmat.resize(V); rep(i, V) { Gmat[i].resize(V, INF); eachdo(e, G[i]) { Gmat[i][e.to] = e.cost; } } vector<vector<ll>> dist = Gmat; rep(i, V) dist[i][i] = 0; rep(k, V) rep(i, V) rep(j, V) chmin(dist[i][j], dist[i][k] + dist[k][j]); return dist; } vector<ll> dijkstra(ll start) { vector<ll> dist(V, INF); priority_queue<P, vector<P>, greater<P>> que; dist[start] = 0; que.push(P(0, start)); while (!que.empty()) { P p = que.top(); que.pop(); ll v = p.second; if (dist[v] < p.first) continue; rep(i, G[v].size()) { edge e = G[v][i]; if (dist[v] + e.cost < dist[e.to]) { dist[e.to] = dist[v] + e.cost; que.push(P(dist[e.to], e.to)); } } } return dist; } }; class UnionFind { public: vector<ll> par; vector<ll> siz; // Constructor UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); for (ll i = 0; i < sz_; ++i) par[i] = i; } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } }; struct SegmentTree { private: ll unit = 0; ll op(ll a, ll b) { return a + b; } ll n; vector<ll> node; public: SegmentTree(vector<ll> v) { ll sz = (ll)v.size(); n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1, unit); for (ll i = 0; i < sz; i++) node[i + n - 1] = v[i]; for (ll i = n - 2; i >= 0; i--) node[i] = op(node[2 * i + 1], node[2 * i + 2]); } void update(ll x, ll val) { x += n - 1; node[x] += val; while (x > 0) { x = (x - 1) / 2; node[x] = op(node[2 * x + 1], node[2 * x + 2]); } } ll query(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return unit; if (a <= l && r <= b) return node[k]; ll vl = query(a, b, 2 * k + 1, l, (l + r) / 2); ll vr = query(a, b, 2 * k + 2, (l + r) / 2, r); return op(vl, vr); } }; struct LazySegmentTree { private: ll n; vector<ll> node, lazy; public: LazySegmentTree(vector<ll> v) { ll sz = (ll)v.size(); n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1); lazy.resize(2 * n - 1); for (ll i = 0; i < sz; i++) node[i + n - 1] = v[i]; for (ll i = n - 2; i >= 0; i--) node[i] = node[2 * i + 1] + node[2 * i + 2]; } void lazyEval(ll k, ll l, ll r) { if (lazy[k] != 0) { node[k] += lazy[k]; if (r - l > 1) { lazy[2 * k + 1] += lazy[k] / 2; lazy[2 * k + 2] += lazy[k] / 2; } lazy[k] = 0; } } void update(ll a, ll b, ll x, ll k = 0, ll l = 0, ll r = -1) { if (r < 0) r = n; lazyEval(k, l, r); if (b <= l || r <= a) return; if (a <= l && r <= b) { lazy[k] += (r - l) * x; lazyEval(k, l, r); } else { update(a, b, x, 2 * k + 1, l, (l + r) / 2); update(a, b, x, 2 * k + 2, (l + r) / 2, r); node[k] = node[2 * k + 1] + node[2 * k + 2]; } } ll query(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) { if (r < 0) r = n; if (b <= l || r <= a) return 0; lazyEval(k, l, r); if (a <= l && r <= b) return node[k]; ll vl = query(a, b, 2 * k + 1, l, (l + r) / 2); ll vr = query(a, b, 2 * k + 2, (l + r) / 2, r); return vl + vr; } ll at(ll a) { return query(a, a + 1); } }; ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } void division(unordered_map<ll, ll> &hash, ll num) { while (1 < num) { bool flag = true; ll t = (ll)pow(num, 1 / 2.0) + 1; for (ll i = 2; i < t; ++i) { if (num % i == 0) { flag = false; if (!hash.count(i)) { hash[i] = 1; } else { hash[i] += 1; } num /= i; break; } } if (flag) { if (!hash.count(num)) { hash[num] = 1; } else { hash[num] += 1; } return; } } return; } int main() { ll A, B, Q; cin >> A >> B >> Q; vector<ll> s(A + 2), t(B + 2); s[0] = -INF; s[A + 1] = INF; t[0] = -INF; t[B + 1] = INF; rep1(i, A) cin >> s[i]; rep1(i, B) cin >> t[i]; rep(i, Q) { ll x; cin >> x; ll p = lower_index(s, x); ll q = lower_index(t, x); ll res = INF; chmin(res, abs(s[p] - x) + abs(s[p] - t[q])); chmin(res, abs(s[p - 1] - x) + abs(s[p - 1] - t[q])); chmin(res, abs(s[p] - x) + abs(s[p] - t[q - 1])); chmin(res, abs(s[p - 1] - x) + abs(s[p - 1] - t[q - 1])); chmin(res, abs(t[q] - x) + abs(t[q] - s[p])); chmin(res, abs(t[q - 1] - x) + abs(t[q - 1] - s[p])); chmin(res, abs(t[q] - x) + abs(t[q] - s[p - 1])); chmin(res, abs(t[q - 1] - x) + abs(t[q - 1] - s[p - 1])); printf("%lld", res); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; struct edge { ll to, cost; }; #define rep(i, n) for (ll i = 0; i < n; ++i) #define rep1(i, n) for (ll i = 1; i <= n; ++i) #define eachdo(e, array) for (const auto &e : array) #define upper_index(v, a) \ (ll) distance(v.begin(), upper_bound((v).begin(), (v).end(), a)) #define lower_index(v, a) \ (ll) distance(v.begin(), lower_bound((v).begin(), (v).end(), a)) 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; } const int inf = 1 << 28; const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; struct Graph { public: ll V; vector<vector<edge>> G; vector<vector<ll>> Gmat; Graph(ll node) { V = node; G.resize(V); } void add(ll from, ll to, ll cost = 1) { G[from].push_back({to, cost}); } vector<vector<ll>> WarshallFloyd() { Gmat.resize(V); rep(i, V) { Gmat[i].resize(V, INF); eachdo(e, G[i]) { Gmat[i][e.to] = e.cost; } } vector<vector<ll>> dist = Gmat; rep(i, V) dist[i][i] = 0; rep(k, V) rep(i, V) rep(j, V) chmin(dist[i][j], dist[i][k] + dist[k][j]); return dist; } vector<ll> dijkstra(ll start) { vector<ll> dist(V, INF); priority_queue<P, vector<P>, greater<P>> que; dist[start] = 0; que.push(P(0, start)); while (!que.empty()) { P p = que.top(); que.pop(); ll v = p.second; if (dist[v] < p.first) continue; rep(i, G[v].size()) { edge e = G[v][i]; if (dist[v] + e.cost < dist[e.to]) { dist[e.to] = dist[v] + e.cost; que.push(P(dist[e.to], e.to)); } } } return dist; } }; class UnionFind { public: vector<ll> par; vector<ll> siz; // Constructor UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); for (ll i = 0; i < sz_; ++i) par[i] = i; } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } }; struct SegmentTree { private: ll unit = 0; ll op(ll a, ll b) { return a + b; } ll n; vector<ll> node; public: SegmentTree(vector<ll> v) { ll sz = (ll)v.size(); n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1, unit); for (ll i = 0; i < sz; i++) node[i + n - 1] = v[i]; for (ll i = n - 2; i >= 0; i--) node[i] = op(node[2 * i + 1], node[2 * i + 2]); } void update(ll x, ll val) { x += n - 1; node[x] += val; while (x > 0) { x = (x - 1) / 2; node[x] = op(node[2 * x + 1], node[2 * x + 2]); } } ll query(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return unit; if (a <= l && r <= b) return node[k]; ll vl = query(a, b, 2 * k + 1, l, (l + r) / 2); ll vr = query(a, b, 2 * k + 2, (l + r) / 2, r); return op(vl, vr); } }; struct LazySegmentTree { private: ll n; vector<ll> node, lazy; public: LazySegmentTree(vector<ll> v) { ll sz = (ll)v.size(); n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1); lazy.resize(2 * n - 1); for (ll i = 0; i < sz; i++) node[i + n - 1] = v[i]; for (ll i = n - 2; i >= 0; i--) node[i] = node[2 * i + 1] + node[2 * i + 2]; } void lazyEval(ll k, ll l, ll r) { if (lazy[k] != 0) { node[k] += lazy[k]; if (r - l > 1) { lazy[2 * k + 1] += lazy[k] / 2; lazy[2 * k + 2] += lazy[k] / 2; } lazy[k] = 0; } } void update(ll a, ll b, ll x, ll k = 0, ll l = 0, ll r = -1) { if (r < 0) r = n; lazyEval(k, l, r); if (b <= l || r <= a) return; if (a <= l && r <= b) { lazy[k] += (r - l) * x; lazyEval(k, l, r); } else { update(a, b, x, 2 * k + 1, l, (l + r) / 2); update(a, b, x, 2 * k + 2, (l + r) / 2, r); node[k] = node[2 * k + 1] + node[2 * k + 2]; } } ll query(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) { if (r < 0) r = n; if (b <= l || r <= a) return 0; lazyEval(k, l, r); if (a <= l && r <= b) return node[k]; ll vl = query(a, b, 2 * k + 1, l, (l + r) / 2); ll vr = query(a, b, 2 * k + 2, (l + r) / 2, r); return vl + vr; } ll at(ll a) { return query(a, a + 1); } }; ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } void division(unordered_map<ll, ll> &hash, ll num) { while (1 < num) { bool flag = true; ll t = (ll)pow(num, 1 / 2.0) + 1; for (ll i = 2; i < t; ++i) { if (num % i == 0) { flag = false; if (!hash.count(i)) { hash[i] = 1; } else { hash[i] += 1; } num /= i; break; } } if (flag) { if (!hash.count(num)) { hash[num] = 1; } else { hash[num] += 1; } return; } } return; } int main() { ll A, B, Q; cin >> A >> B >> Q; vector<ll> s(A + 2), t(B + 2); s[0] = -INF; s[A + 1] = INF; t[0] = -INF; t[B + 1] = INF; rep1(i, A) cin >> s[i]; rep1(i, B) cin >> t[i]; rep(i, Q) { ll x; cin >> x; ll p = lower_index(s, x); ll q = lower_index(t, x); ll res = INF; chmin(res, abs(s[p] - x) + abs(s[p] - t[q])); chmin(res, abs(s[p - 1] - x) + abs(s[p - 1] - t[q])); chmin(res, abs(s[p] - x) + abs(s[p] - t[q - 1])); chmin(res, abs(s[p - 1] - x) + abs(s[p - 1] - t[q - 1])); chmin(res, abs(t[q] - x) + abs(t[q] - s[p])); chmin(res, abs(t[q - 1] - x) + abs(t[q - 1] - s[p])); chmin(res, abs(t[q] - x) + abs(t[q] - s[p - 1])); chmin(res, abs(t[q - 1] - x) + abs(t[q - 1] - s[p - 1])); printf("%lld\n", res); } return 0; }
[ "literal.string.change", "call.arguments.change", "io.output.change", "io.output.newline.add" ]
924,590
924,591
u926099741
cpp
p03112
/*{{{*/ #include <algorithm> #include <assert.h> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <limits.h> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define FOR(I, A, B) for (int I = (A); I <= (B); ++I) #define FORS(I, S) for (int I = 0; S[I]; ++I) #define RS(X) scanf("%s", (X)) #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 CASET \ int ___T; \ scanf("%d", &___T); \ for (int cs = 1; cs <= ___T; cs++) #define MP make_pair #define PB push_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define F first #define S second using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef long double LD; typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<PII> VPII; typedef pair<LL, LL> PLL; typedef vector<PLL> VPLL; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(LL &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template <class T, class... U> void R(T &head, U &...tail) { _R(head); R(tail...); } template <class T> void _W(const T &x) { cout << x; } void _W(const int &x) { printf("%d", x); } void _W(const LL &x) { printf("%lld", x); } void _W(const double &x) { printf("%.16f", x); } void _W(const char &x) { putchar(x); } void _W(const char *x) { printf("%s", x); } template <class T, class U> void _W(const pair<T, U> &x) { _W(x.F); putchar(' '); _W(x.S); } template <class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); } void W() {} template <class T, class... U> void W(const T &head, const U &...tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); } #ifdef HOME #define DEBUG(...) \ { \ printf("# "); \ printf(__VA_ARGS__); \ puts(""); \ } #else #define DEBUG(...) #endif int MOD = 1e9 + 7; void ADD(LL &x, LL v) { x = (x + v) % MOD; if (x < 0) x += MOD; } /*}}}*/ const int SIZE = 1e6 + 10; VL s, t; int main() { int A, B, Q; R(A, B, Q); s.PB(-1e12); REP(i, A) { LL x; R(x); s.PB(x); } s.PB(1e12); t.PB(-1e12); REP(i, B) { LL x; R(x); t.PB(x); } t.PB(1e12); REP(cs, Q) { int x; R(x); auto it1 = lower_bound(ALL(s), x); LL v1 = x - *prev(it1); LL v2 = *it1 - x; auto it2 = lower_bound(ALL(t), x); LL v3 = x - *prev(it2); LL v4 = *it2 - x; LL an = max(v2, v4); an = min(an, max(v1, v3)); an = min(an, v1 + v4 + min(v1, v4)); an = min(an, v2 + v3 + min(v2, v3)); W(an); } return 0; }
/*{{{*/ #include <algorithm> #include <assert.h> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <limits.h> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define FOR(I, A, B) for (int I = (A); I <= (B); ++I) #define FORS(I, S) for (int I = 0; S[I]; ++I) #define RS(X) scanf("%s", (X)) #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 CASET \ int ___T; \ scanf("%d", &___T); \ for (int cs = 1; cs <= ___T; cs++) #define MP make_pair #define PB push_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define F first #define S second using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef long double LD; typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<PII> VPII; typedef pair<LL, LL> PLL; typedef vector<PLL> VPLL; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(LL &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template <class T, class... U> void R(T &head, U &...tail) { _R(head); R(tail...); } template <class T> void _W(const T &x) { cout << x; } void _W(const int &x) { printf("%d", x); } void _W(const LL &x) { printf("%lld", x); } void _W(const double &x) { printf("%.16f", x); } void _W(const char &x) { putchar(x); } void _W(const char *x) { printf("%s", x); } template <class T, class U> void _W(const pair<T, U> &x) { _W(x.F); putchar(' '); _W(x.S); } template <class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); } void W() {} template <class T, class... U> void W(const T &head, const U &...tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); } #ifdef HOME #define DEBUG(...) \ { \ printf("# "); \ printf(__VA_ARGS__); \ puts(""); \ } #else #define DEBUG(...) #endif int MOD = 1e9 + 7; void ADD(LL &x, LL v) { x = (x + v) % MOD; if (x < 0) x += MOD; } /*}}}*/ const int SIZE = 1e6 + 10; VL s, t; int main() { int A, B, Q; R(A, B, Q); s.PB(-1e12); REP(i, A) { LL x; R(x); s.PB(x); } s.PB(1e12); t.PB(-1e12); REP(i, B) { LL x; R(x); t.PB(x); } t.PB(1e12); REP(cs, Q) { LL x; R(x); auto it1 = lower_bound(ALL(s), x); LL v1 = x - *prev(it1); LL v2 = *it1 - x; auto it2 = lower_bound(ALL(t), x); LL v3 = x - *prev(it2); LL v4 = *it2 - x; // W(v1,v2,v3,v4); LL an = max(v2, v4); an = min(an, max(v1, v3)); an = min(an, v1 + v4 + min(v1, v4)); an = min(an, v2 + v3 + min(v2, v3)); W(an); } return 0; }
[ "variable_declaration.type.change" ]
924,602
924,603
u284124505
cpp
p03112
/*Function Template*/ #include <bits/stdc++.h> using namespace std; typedef long long int ll; const int MAX = 510000; const int MOD = 1000000007; #define rep(i, n) for (ll i = 0; i < (n); i++) #define ALL(a) (a).begin(), (a).end() #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); ll fac[MAX], finv[MAX], inv[MAX]; const ll INF = 1LL << 58; template <class T> int former(const vector<T> &v, T x) { return upper_bound(v.begin(), v.end(), x) - v.begin() - 1; } template <class T> int latter(const vector<T> &v, T x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll Len(ll n) { ll s = 0; while (n != 0) s++, n /= 10; return s; } ll Sint(ll n) { ll m = 0, s = 0, a = n; while (a != 0) s++, a /= 10; for (ll i = s - 1; i >= 0; i--) m += n / ((ll)pow(10, i)) - (n / ((ll)pow(10, i + 1))) * 10; return m; } ll Svec(vector<ll> v) { ll n = 0; for (ll i = 0; i < v.size(); i++) n += v[i]; return n; } ll GCD(ll a, ll b) { ll r, tmp; /*自然数 a > b を確認・入替*/ if (a < b) { tmp = a, a = b, b = tmp; } /*ユークリッドの互除法*/ r = a % b; while (r != 0) { a = b, b = r, r = a % b; } return b; } ll LCM(ll a, ll b) { ll c = a, d = b, r, tmp; /*自然数 a > b を確認・入替*/ if (a < b) { tmp = a, a = b, b = tmp; } /*ユークリッドの互除法*/ r = a % b; while (r != 0) { a = b, b = r, r = a % b; } return c / b * d; } ll Factorial(ll n) { ll m = 1; while (n >= 1) m *= n, n--; return m; } vector<pair<char, ll>> runlength(string s, vector<pair<char, ll>> p) { ll x = 1; if (s.size() == 1) { p.push_back(pair<char, ll>(s[0], 1)); return p; } for (ll i = 0; i < s.size() - 1; i++) { if (s[i] == s[i + 1]) { x++; if (i == s.size() - 2) { p.push_back(pair<char, ll>(s[i], x)); } } else { p.push_back(pair<char, ll>(s[i], x)); x = 1; if (i == s.size() - 2) { p.push_back(pair<char, ll>(s[s.size() - 1], x)); } } } return p; } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } const int MAX_N = 100010; vector<bool> sieve_of_eratosthenes() { vector<bool> isPrime(MAX_N + 1, true); for (int i = 2; i <= MAX_N; i++) { if (isPrime[i]) { for (int j = 2 * i; j <= MAX_N; j += i) { isPrime[j] = false; } } } return isPrime; } /*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/ int main() { IOS; ll a, b, q; cin >> a >> b >> q; vector<ll> s(a), t(b); rep(i, a) cin >> s[i]; rep(i, b) cin >> t[i]; s.push_back(INF); s.push_back(-INF); sort(ALL(s)); t.push_back(INF); t.push_back(-INF); sort(ALL(t)); rep(_, q) { ll x; cin >> x; ll res = INF; rep(i, 2) { ll first = (i ? s[former(s, x)] : s[latter(s, x)]); rep(j, 2) { ll second = (j ? t[former(t, first)] : t[latter(t, second)]); chmin(res, abs(x - first) + abs(first - second)); } } rep(i, 2) { ll first = (i ? t[former(t, x)] : t[latter(t, x)]); rep(j, 2) { ll second = (j ? s[former(s, first)] : s[latter(s, first)]); chmin(res, abs(x - first) + abs(first - second)); } } cout << res << endl; } }
/*Function Template*/ #include <bits/stdc++.h> using namespace std; typedef long long int ll; const int MAX = 510000; const int MOD = 1000000007; #define rep(i, n) for (ll i = 0; i < (n); i++) #define ALL(a) (a).begin(), (a).end() #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); ll fac[MAX], finv[MAX], inv[MAX]; const long long INF = 1LL << 58; template <class T> int former(const vector<T> &v, T x) { return upper_bound(v.begin(), v.end(), x) - v.begin() - 1; } template <class T> int latter(const vector<T> &v, T x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll Len(ll n) { ll s = 0; while (n != 0) s++, n /= 10; return s; } ll Sint(ll n) { ll m = 0, s = 0, a = n; while (a != 0) s++, a /= 10; for (ll i = s - 1; i >= 0; i--) m += n / ((ll)pow(10, i)) - (n / ((ll)pow(10, i + 1))) * 10; return m; } ll Svec(vector<ll> v) { ll n = 0; for (ll i = 0; i < v.size(); i++) n += v[i]; return n; } ll GCD(ll a, ll b) { ll r, tmp; /*自然数 a > b を確認・入替*/ if (a < b) { tmp = a, a = b, b = tmp; } /*ユークリッドの互除法*/ r = a % b; while (r != 0) { a = b, b = r, r = a % b; } return b; } ll LCM(ll a, ll b) { ll c = a, d = b, r, tmp; /*自然数 a > b を確認・入替*/ if (a < b) { tmp = a, a = b, b = tmp; } /*ユークリッドの互除法*/ r = a % b; while (r != 0) { a = b, b = r, r = a % b; } return c / b * d; } ll Factorial(ll n) { ll m = 1; while (n >= 1) m *= n, n--; return m; } vector<pair<char, ll>> runlength(string s, vector<pair<char, ll>> p) { ll x = 1; if (s.size() == 1) { p.push_back(pair<char, ll>(s[0], 1)); return p; } for (ll i = 0; i < s.size() - 1; i++) { if (s[i] == s[i + 1]) { x++; if (i == s.size() - 2) { p.push_back(pair<char, ll>(s[i], x)); } } else { p.push_back(pair<char, ll>(s[i], x)); x = 1; if (i == s.size() - 2) { p.push_back(pair<char, ll>(s[s.size() - 1], x)); } } } return p; } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } const int MAX_N = 100010; vector<bool> sieve_of_eratosthenes() { vector<bool> isPrime(MAX_N + 1, true); for (int i = 2; i <= MAX_N; i++) { if (isPrime[i]) { for (int j = 2 * i; j <= MAX_N; j += i) { isPrime[j] = false; } } } return isPrime; } /*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/ int main() { IOS; ll a, b, q; cin >> a >> b >> q; vector<ll> s(a), t(b); rep(i, a) cin >> s[i]; rep(i, b) cin >> t[i]; s.push_back(INF); s.push_back(-INF); sort(ALL(s)); t.push_back(INF); t.push_back(-INF); sort(ALL(t)); rep(_, q) { ll x; cin >> x; ll res = INF; rep(i, 2) { ll first = (i ? s[former(s, x)] : s[latter(s, x)]); rep(j, 2) { ll second = (j ? t[former(t, first)] : t[latter(t, first)]); chmin(res, abs(x - first) + abs(first - second)); } } rep(i, 2) { ll first = (i ? t[former(t, x)] : t[latter(t, x)]); rep(j, 2) { ll second = (j ? s[former(s, first)] : s[latter(s, first)]); chmin(res, abs(x - first) + abs(first - second)); } } cout << res << endl; } }
[ "variable_declaration.type.widen.change", "identifier.change", "variable_access.subscript.index.change", "call.arguments.change" ]
924,604
924,605
u264265458
cpp
p03112
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef uint64_t u64; typedef int64_t s64; typedef uint32_t u32; typedef int32_t s32; typedef vector<s32> vs32; typedef vector<u32> vu32; typedef vector<s64> vs64; typedef vector<u64> vu64; const double PI = 3.14159265358979323846; #define MAX(x, y) ((x) < (y) ? (y) : (x)) #define MIN(x, y) ((x) > (y) ? (y) : (x)) #define rep(i, N) for (int i = 0; i < N; ++i) #define CEIL(x, y) (((x) + (y)-1) / (y)) #define MOD 1000000007ULL int main() { cin.tie(0); ios::sync_with_stdio(false); int A, B, Q; cin >> A >> B >> Q; vs64 sh(A); rep(i, A) cin >> sh[i]; vs64 te(B); rep(i, B) cin >> te[i]; vs64 x(Q); rep(i, Q) cin >> x[i]; sort(sh.begin(), sh.end()); sort(te.begin(), te.end()); vector<pair<s64, s64>> s2t(A); rep(i, A) { auto it = lower_bound(te.begin(), te.end(), sh[i]); if (it == te.begin()) { s2t[i] = make_pair(sh[i], abs(sh[i] - te[0])); } else if (it == te.end()) { s2t[i] = make_pair(sh[i], abs(sh[i] - te[B - 1])); } else { int temp = MIN(abs(sh[i] - *it), abs(sh[i] - *(it - 1))); s2t[i] = make_pair(sh[i], temp); } } vector<pair<s64, s64>> t2s(B); rep(i, B) { auto it = lower_bound(sh.begin(), sh.end(), te[i]); if (it == sh.begin()) { t2s[i] = make_pair(te[i], abs(te[i] - sh[0])); } else if (it == sh.end()) { t2s[i] = make_pair(te[i], abs(te[i] - sh[A - 1])); } else { int temp = MIN(abs(te[i] - *it), abs(te[i] - *(it - 1))); t2s[i] = make_pair(te[i], temp); } } // cout << "s2t\n"; // rep (i, A) // { // cout << "s, dis = " << s2t[i].first << ", " << s2t[i].second << "\n"; // } // cout << "t2s\n"; // rep (i, A) // { // cout << "t, dis = " << t2s[i].first << ", " << t2s[i].second << "\n"; // } s64 ans; rep(i, Q) { auto its = lower_bound(s2t.begin(), s2t.end(), pair<s64, s64>(x[i], -1), [](const pair<s64, s64> &xx, const pair<s64, s64> &yy) { return xx.first < yy.first; }); s64 temps; if (its == s2t.begin()) temps = abs(x[i] - its->first) + its->second; else if (its == s2t.end()) temps = abs(x[i] - s2t[A - 1].first) + s2t[A - 1].second; else { temps = MIN(abs(x[i] - its->first) + its->second, abs(x[i] - (its - 1)->first) + (its - 1)->second); } auto itt = lower_bound(t2s.begin(), t2s.end(), pair<s64, s64>(x[i], -1), [](const pair<s64, s64> &xx, const pair<s64, s64> &yy) { return xx.first < yy.first; }); s64 tempt; if (itt == t2s.begin()) tempt = abs(x[i] - itt->first) + itt->second; else if (itt == t2s.end()) tempt = abs(x[i] - t2s[A - 1].first) + t2s[A - 1].second; else { tempt = MIN(abs(x[i] - itt->first) + itt->second, abs(x[i] - (itt - 1)->first) + (itt - 1)->second); } // cout << "Q" << i << ": " << temps << ", " << tempt << "\n"; ans = MIN(temps, tempt); cout << ans << "\n"; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef uint64_t u64; typedef int64_t s64; typedef uint32_t u32; typedef int32_t s32; typedef vector<s32> vs32; typedef vector<u32> vu32; typedef vector<s64> vs64; typedef vector<u64> vu64; const double PI = 3.14159265358979323846; #define MAX(x, y) ((x) < (y) ? (y) : (x)) #define MIN(x, y) ((x) > (y) ? (y) : (x)) #define rep(i, N) for (int i = 0; i < N; ++i) #define CEIL(x, y) (((x) + (y)-1) / (y)) #define MOD 1000000007ULL int main() { cin.tie(0); ios::sync_with_stdio(false); int A, B, Q; cin >> A >> B >> Q; vs64 sh(A); rep(i, A) cin >> sh[i]; vs64 te(B); rep(i, B) cin >> te[i]; vs64 x(Q); rep(i, Q) cin >> x[i]; sort(sh.begin(), sh.end()); sort(te.begin(), te.end()); vector<pair<s64, s64>> s2t(A); rep(i, A) { auto it = lower_bound(te.begin(), te.end(), sh[i]); if (it == te.begin()) { s2t[i] = make_pair(sh[i], abs(sh[i] - te[0])); } else if (it == te.end()) { s2t[i] = make_pair(sh[i], abs(sh[i] - te[B - 1])); } else { int temp = MIN(abs(sh[i] - *it), abs(sh[i] - *(it - 1))); s2t[i] = make_pair(sh[i], temp); } } vector<pair<s64, s64>> t2s(B); rep(i, B) { auto it = lower_bound(sh.begin(), sh.end(), te[i]); if (it == sh.begin()) { t2s[i] = make_pair(te[i], abs(te[i] - sh[0])); } else if (it == sh.end()) { t2s[i] = make_pair(te[i], abs(te[i] - sh[A - 1])); } else { int temp = MIN(abs(te[i] - *it), abs(te[i] - *(it - 1))); t2s[i] = make_pair(te[i], temp); } } // cout << "s2t\n"; // rep (i, A) // { // cout << "s, dis = " << s2t[i].first << ", " << s2t[i].second << "\n"; // } // cout << "t2s\n"; // rep (i, A) // { // cout << "t, dis = " << t2s[i].first << ", " << t2s[i].second << "\n"; // } s64 ans; rep(i, Q) { auto its = lower_bound(s2t.begin(), s2t.end(), pair<s64, s64>(x[i], -1), [](const pair<s64, s64> &xx, const pair<s64, s64> &yy) { return xx.first < yy.first; }); s64 temps; if (its == s2t.begin()) temps = abs(x[i] - its->first) + its->second; else if (its == s2t.end()) temps = abs(x[i] - s2t[A - 1].first) + s2t[A - 1].second; else { temps = MIN(abs(x[i] - its->first) + its->second, abs(x[i] - (its - 1)->first) + (its - 1)->second); } auto itt = lower_bound(t2s.begin(), t2s.end(), pair<s64, s64>(x[i], -1), [](const pair<s64, s64> &xx, const pair<s64, s64> &yy) { return xx.first < yy.first; }); s64 tempt; if (itt == t2s.begin()) tempt = abs(x[i] - itt->first) + itt->second; else if (itt == t2s.end()) tempt = abs(x[i] - t2s[B - 1].first) + t2s[B - 1].second; else { tempt = MIN(abs(x[i] - itt->first) + itt->second, abs(x[i] - (itt - 1)->first) + (itt - 1)->second); } // cout << "Q" << i << ": " << temps << ", " << tempt << "\n"; ans = MIN(temps, tempt); cout << ans << "\n"; } return 0; }
[ "assignment.value.change", "variable_access.subscript.index.change", "call.arguments.change", "expression.operation.binary.change", "identifier.change" ]
924,608
924,609
u806999568
cpp
p03112
#include <bits/stdc++.h> using namespace std; #define int long long // #define double long double #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORR(i, a, b) for (int i = (a); i > (b); --i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOREACH(x, a) for (auto &(x) : (a)) #define VECCIN(x) \ for (auto &youso_ : (x)) \ cin >> youso_ #define bitcnt(x) __builtin_popcount(x) #define lbit(x) __builtin_ffsll(x) #define rbit(x) __builtin_clzll(x) #define SZ(x) ((long long)(x).size()) #define fi first #define se second #define All(a) (a).begin(), (a).end() #define rAll(a) (a).rbegin(), (a).rend() #define cinfast() cin.tie(0), ios::sync_with_stdio(false) #define PERM(c) \ sort(All(c)); \ for (bool cp = true; cp; cp = next_permutation(All(c))) #define MKORDER(n) \ vector<int> od(n); \ iota(All(od), 0LL); template <typename T = long long> inline T IN() { T x; cin >> x; return (x); } inline void CIN() {} template <class Head, class... Tail> inline void CIN(Head &&head, Tail &&...tail) { cin >> head; CIN(move(tail)...); } #define CCIN(...) \ char __VA_ARGS__; \ CIN(__VA_ARGS__) #define DCIN(...) \ double __VA_ARGS__; \ CIN(__VA_ARGS__) #define LCIN(...) \ long long __VA_ARGS__; \ CIN(__VA_ARGS__) #define SCIN(...) \ string __VA_ARGS__; \ CIN(__VA_ARGS__) #define Yes(a) cout << (a ? "Yes" : "No") << "\n" #define YES(a) cout << (a ? "YES" : "NO") << "\n" #define Printv(v) \ { \ FOREACH(x, v) { cout << x << " "; } \ cout << "\n"; \ } template <typename T = string> inline void eputs(T s) { cout << s << "\n"; exit(0); } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>; template <typename T> using PQ = priority_queue<T>; typedef long long ll; typedef vector<ll> VL; typedef vector<VL> VVL; typedef pair<ll, ll> PL; typedef vector<PL> VPL; typedef vector<bool> VB; typedef vector<double> VD; typedef vector<string> VS; const int INF = 1e9; const int MOD = 1e9 + 7; // const int MOD = 998244353; const ll LINF = 1e18; const double PI = atan(1.0) * 4.0; const ll dw[] = {1, 1, 0, -1, -1, -1, 0, 1}; const ll dh[] = {0, 1, 1, 1, 0, -1, -1, -1}; #define PI 3.141592653589793238 ll A, B, Q; VL s, t; signed main() { cin >> A >> B >> Q; s.resize(A); t.resize(B); VECCIN(s); s.emplace_back(LINF), s.emplace_back(-LINF); VECCIN(t); t.emplace_back(LINF), s.emplace_back(-LINF); sort(All(s)); sort(All(t)); REP(i, Q) { LCIN(x); ll sidx = lower_bound(All(s), x) - s.begin(); ll tidx = lower_bound(All(t), x) - t.begin(); ll res = LINF; res = min(res, max(abs(x - s[sidx]), abs(x - t[tidx]))); res = min(res, abs(x - s[sidx - 1]) + abs(x - t[tidx]) + min(abs(x - s[sidx - 1]), abs(x - t[tidx]))); res = min(res, abs(x - s[sidx]) + abs(x - t[tidx - 1]) + min(abs(x - s[sidx]), abs(x - t[tidx - 1]))); res = min(res, max(abs(x - s[sidx - 1]), abs(x - t[tidx - 1]))); cout << res << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long // #define double long double #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORR(i, a, b) for (int i = (a); i > (b); --i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOREACH(x, a) for (auto &(x) : (a)) #define VECCIN(x) \ for (auto &youso_ : (x)) \ cin >> youso_ #define bitcnt(x) __builtin_popcount(x) #define lbit(x) __builtin_ffsll(x) #define rbit(x) __builtin_clzll(x) #define SZ(x) ((long long)(x).size()) #define fi first #define se second #define All(a) (a).begin(), (a).end() #define rAll(a) (a).rbegin(), (a).rend() #define cinfast() cin.tie(0), ios::sync_with_stdio(false) #define PERM(c) \ sort(All(c)); \ for (bool cp = true; cp; cp = next_permutation(All(c))) #define MKORDER(n) \ vector<int> od(n); \ iota(All(od), 0LL); template <typename T = long long> inline T IN() { T x; cin >> x; return (x); } inline void CIN() {} template <class Head, class... Tail> inline void CIN(Head &&head, Tail &&...tail) { cin >> head; CIN(move(tail)...); } #define CCIN(...) \ char __VA_ARGS__; \ CIN(__VA_ARGS__) #define DCIN(...) \ double __VA_ARGS__; \ CIN(__VA_ARGS__) #define LCIN(...) \ long long __VA_ARGS__; \ CIN(__VA_ARGS__) #define SCIN(...) \ string __VA_ARGS__; \ CIN(__VA_ARGS__) #define Yes(a) cout << (a ? "Yes" : "No") << "\n" #define YES(a) cout << (a ? "YES" : "NO") << "\n" #define Printv(v) \ { \ FOREACH(x, v) { cout << x << " "; } \ cout << "\n"; \ } template <typename T = string> inline void eputs(T s) { cout << s << "\n"; exit(0); } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>; template <typename T> using PQ = priority_queue<T>; typedef long long ll; typedef vector<ll> VL; typedef vector<VL> VVL; typedef pair<ll, ll> PL; typedef vector<PL> VPL; typedef vector<bool> VB; typedef vector<double> VD; typedef vector<string> VS; const int INF = 1e9; const int MOD = 1e9 + 7; // const int MOD = 998244353; const ll LINF = 1e18; const double PI = atan(1.0) * 4.0; const ll dw[] = {1, 1, 0, -1, -1, -1, 0, 1}; const ll dh[] = {0, 1, 1, 1, 0, -1, -1, -1}; #define PI 3.141592653589793238 ll A, B, Q; VL s, t; signed main() { cin >> A >> B >> Q; s.resize(A); t.resize(B); VECCIN(s); s.emplace_back(LINF), s.emplace_back(-LINF); VECCIN(t); t.emplace_back(LINF), t.emplace_back(-LINF); sort(All(s)); sort(All(t)); REP(i, Q) { LCIN(x); ll sidx = lower_bound(All(s), x) - s.begin(); ll tidx = lower_bound(All(t), x) - t.begin(); ll res = LINF; res = min(res, max(abs(x - s[sidx]), abs(x - t[tidx]))); res = min(res, abs(x - s[sidx - 1]) + abs(x - t[tidx]) + min(abs(x - s[sidx - 1]), abs(x - t[tidx]))); res = min(res, abs(x - s[sidx]) + abs(x - t[tidx - 1]) + min(abs(x - s[sidx]), abs(x - t[tidx - 1]))); res = min(res, max(abs(x - s[sidx - 1]), abs(x - t[tidx - 1]))); cout << res << "\n"; } return 0; }
[ "identifier.change" ]
924,624
924,625
u139031151
cpp
p03112
#include <bits/stdc++.h> using namespace std; #define int long long // #define double long double #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORR(i, a, b) for (int i = (a); i > (b); --i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOREACH(x, a) for (auto &(x) : (a)) #define VECCIN(x) \ for (auto &youso_ : (x)) \ cin >> youso_ #define bitcnt(x) __builtin_popcount(x) #define lbit(x) __builtin_ffsll(x) #define rbit(x) __builtin_clzll(x) #define SZ(x) ((long long)(x).size()) #define fi first #define se second #define All(a) (a).begin(), (a).end() #define rAll(a) (a).rbegin(), (a).rend() #define cinfast() cin.tie(0), ios::sync_with_stdio(false) #define PERM(c) \ sort(All(c)); \ for (bool cp = true; cp; cp = next_permutation(All(c))) #define MKORDER(n) \ vector<int> od(n); \ iota(All(od), 0LL); template <typename T = long long> inline T IN() { T x; cin >> x; return (x); } inline void CIN() {} template <class Head, class... Tail> inline void CIN(Head &&head, Tail &&...tail) { cin >> head; CIN(move(tail)...); } #define CCIN(...) \ char __VA_ARGS__; \ CIN(__VA_ARGS__) #define DCIN(...) \ double __VA_ARGS__; \ CIN(__VA_ARGS__) #define LCIN(...) \ long long __VA_ARGS__; \ CIN(__VA_ARGS__) #define SCIN(...) \ string __VA_ARGS__; \ CIN(__VA_ARGS__) #define Yes(a) cout << (a ? "Yes" : "No") << "\n" #define YES(a) cout << (a ? "YES" : "NO") << "\n" #define Printv(v) \ { \ FOREACH(x, v) { cout << x << " "; } \ cout << "\n"; \ } template <typename T = string> inline void eputs(T s) { cout << s << "\n"; exit(0); } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>; template <typename T> using PQ = priority_queue<T>; typedef long long ll; typedef vector<ll> VL; typedef vector<VL> VVL; typedef pair<ll, ll> PL; typedef vector<PL> VPL; typedef vector<bool> VB; typedef vector<double> VD; typedef vector<string> VS; const int INF = 1e9; const int MOD = 1e9 + 7; // const int MOD = 998244353; const ll LINF = 1e18; const double PI = atan(1.0) * 4.0; const ll dw[] = {1, 1, 0, -1, -1, -1, 0, 1}; const ll dh[] = {0, 1, 1, 1, 0, -1, -1, -1}; #define PI 3.141592653589793238 ll A, B, Q; VL s, t; signed main() { cin >> A >> B >> Q; cinfast(); s.resize(A); t.resize(B); VECCIN(s); s.emplace_back(LINF), s.emplace_back(-LINF); VECCIN(t); t.emplace_back(LINF), s.emplace_back(-LINF); sort(All(s)); sort(All(t)); REP(i, Q) { LCIN(x); ll sidx = lower_bound(All(s), x) - s.begin(); ll tidx = lower_bound(All(t), x) - t.begin(); ll res = LINF; res = min(res, max(abs(x - s[sidx]), abs(x - t[tidx]))); res = min(res, abs(x - s[sidx - 1]) + abs(x - t[tidx]) + min(abs(x - s[sidx - 1]), abs(x - t[tidx]))); res = min(res, abs(x - s[sidx]) + abs(x - t[tidx - 1]) + min(abs(x - s[sidx]), abs(x - t[tidx - 1]))); res = min(res, max(abs(x - s[sidx - 1]), abs(x - t[tidx - 1]))); cout << res << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long // #define double long double #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORR(i, a, b) for (int i = (a); i > (b); --i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOREACH(x, a) for (auto &(x) : (a)) #define VECCIN(x) \ for (auto &youso_ : (x)) \ cin >> youso_ #define bitcnt(x) __builtin_popcount(x) #define lbit(x) __builtin_ffsll(x) #define rbit(x) __builtin_clzll(x) #define SZ(x) ((long long)(x).size()) #define fi first #define se second #define All(a) (a).begin(), (a).end() #define rAll(a) (a).rbegin(), (a).rend() #define cinfast() cin.tie(0), ios::sync_with_stdio(false) #define PERM(c) \ sort(All(c)); \ for (bool cp = true; cp; cp = next_permutation(All(c))) #define MKORDER(n) \ vector<int> od(n); \ iota(All(od), 0LL); template <typename T = long long> inline T IN() { T x; cin >> x; return (x); } inline void CIN() {} template <class Head, class... Tail> inline void CIN(Head &&head, Tail &&...tail) { cin >> head; CIN(move(tail)...); } #define CCIN(...) \ char __VA_ARGS__; \ CIN(__VA_ARGS__) #define DCIN(...) \ double __VA_ARGS__; \ CIN(__VA_ARGS__) #define LCIN(...) \ long long __VA_ARGS__; \ CIN(__VA_ARGS__) #define SCIN(...) \ string __VA_ARGS__; \ CIN(__VA_ARGS__) #define Yes(a) cout << (a ? "Yes" : "No") << "\n" #define YES(a) cout << (a ? "YES" : "NO") << "\n" #define Printv(v) \ { \ FOREACH(x, v) { cout << x << " "; } \ cout << "\n"; \ } template <typename T = string> inline void eputs(T s) { cout << s << "\n"; exit(0); } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>; template <typename T> using PQ = priority_queue<T>; typedef long long ll; typedef vector<ll> VL; typedef vector<VL> VVL; typedef pair<ll, ll> PL; typedef vector<PL> VPL; typedef vector<bool> VB; typedef vector<double> VD; typedef vector<string> VS; const int INF = 1e9; const int MOD = 1e9 + 7; // const int MOD = 998244353; const ll LINF = 1e18; const double PI = atan(1.0) * 4.0; const ll dw[] = {1, 1, 0, -1, -1, -1, 0, 1}; const ll dh[] = {0, 1, 1, 1, 0, -1, -1, -1}; #define PI 3.141592653589793238 ll A, B, Q; VL s, t; signed main() { cin >> A >> B >> Q; s.resize(A); t.resize(B); VECCIN(s); s.emplace_back(LINF), s.emplace_back(-LINF); VECCIN(t); t.emplace_back(LINF), t.emplace_back(-LINF); sort(All(s)); sort(All(t)); REP(i, Q) { LCIN(x); ll sidx = lower_bound(All(s), x) - s.begin(); ll tidx = lower_bound(All(t), x) - t.begin(); ll res = LINF; res = min(res, max(abs(x - s[sidx]), abs(x - t[tidx]))); res = min(res, abs(x - s[sidx - 1]) + abs(x - t[tidx]) + min(abs(x - s[sidx - 1]), abs(x - t[tidx]))); res = min(res, abs(x - s[sidx]) + abs(x - t[tidx - 1]) + min(abs(x - s[sidx]), abs(x - t[tidx - 1]))); res = min(res, max(abs(x - s[sidx - 1]), abs(x - t[tidx - 1]))); cout << res << "\n"; } return 0; }
[ "call.remove", "identifier.change" ]
924,626
924,625
u139031151
cpp
p03112
#include <bits/stdc++.h> using namespace std; int main() { int A, B, Q; cin >> A >> B >> Q; vector<long long> s(A + 2), t(B + 2), x(Q); for (int i = 0; i < A; i++) cin >> s.at(i); for (int i = 0; i < B; i++) cin >> t.at(i); for (int i = 0; i < Q; i++) cin >> x.at(i); long long INF = 1LL << 50; s.at(A) = INF; s.at(A + 1) = -INF; t.at(B) = INF; t.at(B + 1) = -INF; sort(s.begin(), s.end()); sort(t.begin(), t.end()); for (int i = 0; i < Q; i++) { vector<long long> sh(2), te(2); int sh_idx = lower_bound(sh.begin(), sh.end(), x.at(i)) - sh.begin(); sh.at(0) = s.at(sh_idx - 1); // west side sh.at(1) = s.at(sh_idx); // east side int te_idx = lower_bound(te.begin(), te.end(), x.at(i)) - te.begin(); te.at(0) = t.at(te_idx - 1); te.at(1) = t.at(te_idx); long long ans = 1LL << 50; for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { ans = min(ans, abs(sh.at(j) - x.at(i)) + abs(te.at(k) - sh.at(j))); ans = min(ans, abs(te.at(k) - x.at(i)) + abs(te.at(k) - sh.at(j))); } } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int A, B, Q; cin >> A >> B >> Q; vector<long long> s(A + 2), t(B + 2), x(Q); for (int i = 0; i < A; i++) cin >> s.at(i); for (int i = 0; i < B; i++) cin >> t.at(i); for (int i = 0; i < Q; i++) cin >> x.at(i); long long INF = 1LL << 50; s.at(A) = INF; s.at(A + 1) = -INF; t.at(B) = INF; t.at(B + 1) = -INF; sort(s.begin(), s.end()); sort(t.begin(), t.end()); for (int i = 0; i < Q; i++) { vector<long long> sh(2), te(2); int sh_idx = lower_bound(s.begin(), s.end(), x.at(i)) - s.begin(); sh.at(0) = s.at(sh_idx - 1); // west side sh.at(1) = s.at(sh_idx); // east side int te_idx = lower_bound(t.begin(), t.end(), x.at(i)) - t.begin(); te.at(0) = t.at(te_idx - 1); te.at(1) = t.at(te_idx); long long ans = 1LL << 50; for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { ans = min(ans, abs(sh.at(j) - x.at(i)) + abs(te.at(k) - sh.at(j))); ans = min(ans, abs(te.at(k) - x.at(i)) + abs(te.at(k) - sh.at(j))); } } cout << ans << endl; } }
[ "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
924,629
924,630
u642120132
cpp
p03112
#include <algorithm> #include <cmath> #include <cstdio> #include <fstream> #include <iostream> #include <set> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define repn(i, n) for (int i = 1; i <= n; i++) #define lint long long #define all(x) (x).begin(), (x).end() inline void logger() { cout << endl; } template <typename A, typename... B> void logger(const A &a, const B &...b) { cout << a << " , "; logger(b...); } int main() { int A, B, Q; cin >> A >> B >> Q; vector<lint> s(A); vector<lint> t(B); rep(i, A) cin >> s[i]; rep(i, B) cin >> t[i]; rep(i, Q) { lint x; cin >> x; auto itr1 = lower_bound(all(s), x); auto itr2 = lower_bound(all(t), x); lint sr, sl, tr, tl; sr = 1e12; tr = 1e12; sl = -1e12; tl = -1e12; if (itr1 != s.end()) sr = *itr1; if (itr2 != t.end()) tr = *itr2; if (itr1 != s.begin()) sl = *(--itr1); if (itr2 != t.begin()) tl = *(--itr2); lint ans; if ((sl >= tl && sr <= tr) || (sl <= tr && sr >= tr)) { ans = min(x - min(sl, tl), max(sr, tr) - x); } else { ans = min(x - min(sl, tl), max(sr, tr) - x); ans = min(ans, x - 2 * max(sl, tl) + min(sr, tr)); ans = min(ans, 2 * min(sr, tr) - x - max(sl, tl)); } cout << ans << endl; } }
#include <algorithm> #include <cmath> #include <cstdio> #include <fstream> #include <iostream> #include <set> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define repn(i, n) for (int i = 1; i <= n; i++) #define lint long long #define all(x) (x).begin(), (x).end() inline void logger() { cout << endl; } template <typename A, typename... B> void logger(const A &a, const B &...b) { cout << a << " , "; logger(b...); } int main() { int A, B, Q; cin >> A >> B >> Q; vector<lint> s(A); vector<lint> t(B); rep(i, A) cin >> s[i]; rep(i, B) cin >> t[i]; rep(i, Q) { lint x; cin >> x; auto itr1 = lower_bound(all(s), x); auto itr2 = lower_bound(all(t), x); lint sr, sl, tr, tl; sr = 1e12; tr = 1e12; sl = -1e12; tl = -1e12; if (itr1 != s.end()) sr = *itr1; if (itr2 != t.end()) tr = *itr2; if (itr1 != s.begin()) sl = *(--itr1); if (itr2 != t.begin()) tl = *(--itr2); lint ans; if ((sl >= tl && sr <= tr) || (sl <= tl && sr >= tr)) { ans = min(x - min(sl, tl), max(sr, tr) - x); } else { ans = min(x - min(sl, tl), max(sr, tr) - x); ans = min(ans, x - 2 * max(sl, tl) + min(sr, tr)); ans = min(ans, 2 * min(sr, tr) - x - max(sl, tl)); } cout << ans << endl; } }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
924,636
924,637
u632094970
cpp
p03112
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int mod = 1000000007; int main() { ios::sync_with_stdio(false); int n, m, q; cin >> n >> m >> q; vector<ll> a(n + 2), b(m + 2); ll x; a[0] = b[0] = -1ll * mod * mod; a[n + 1] = b[m + 1] = 1ll * mod * mod; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= m; i++) cin >> b[i]; while (q--) { cin >> x; ll l1 = *--lower_bound(a.begin(), a.end(), x), r1 = *lower_bound(a.begin(), a.end(), x), l2 = *--lower_bound(b.begin(), b.end(), x), r2 = *lower_bound(b.begin(), b.end(), x); cout << min({abs(x - l1) + abs(l1 - l2), abs(x - l1) + abs(l1 - r2), abs(x - r1) + abs(r1 - l2), abs(x - r1) + abs(r1 - r2), abs(x - l2) + abs(l2 - l1), abs(x - l2) + abs(l2 - r1), abs(x - r2) + abs(r2 - l1), abs(x - r2) + abs(r2 - l2)}) << '\n'; } }
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int mod = 1000000007; int main() { ios::sync_with_stdio(false); int n, m, q; cin >> n >> m >> q; vector<ll> a(n + 2), b(m + 2); ll x; a[0] = b[0] = -1ll * mod * mod; a[n + 1] = b[m + 1] = 1ll * mod * mod; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= m; i++) cin >> b[i]; while (q--) { cin >> x; ll l1 = *--lower_bound(a.begin(), a.end(), x), r1 = *lower_bound(a.begin(), a.end(), x), l2 = *--lower_bound(b.begin(), b.end(), x), r2 = *lower_bound(b.begin(), b.end(), x); cout << min({abs(x - l1) + abs(l1 - l2), abs(x - l1) + abs(l1 - r2), abs(x - r1) + abs(r1 - l2), abs(x - r1) + abs(r1 - r2), abs(x - l2) + abs(l2 - l1), abs(x - l2) + abs(l2 - r1), abs(x - r2) + abs(r2 - l1), abs(x - r2) + abs(r2 - r1)}) << '\n'; } }
[ "identifier.change", "io.output.change" ]
924,638
924,639
u151855078
cpp
p03111
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<int, double> Pid; typedef pair<double, int> Pdi; typedef pair<ll, int> Pl; const double PI = 3.1415926535897932; // acos(-1) const double EPS = 1e-15; const int INF = 1001001001; const ll mod = 1e+9 + 7; #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define chadd(x, y) x = (x + y) % mod int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<ll> len(3); for (int i = 0; i < 3; ++i) cin >> len[i]; vector<ll> l(n); int limit = 1; for (int i = 0; i < n; ++i) { cin >> l[i]; limit *= 4; } ll res = 1e+15; for (int i = 0; i < limit; ++i) { int foo = i; int id = 0; vector<vector<ll>> hoge(4); while (foo > 0) { hoge[foo % 4].push_back(l[id++]); foo /= 4; } if (hoge[0].size() == 0 || hoge[1].size() == 0 || hoge[2].size() == 0) continue; ll score = 0; for (int s = 0; s < 3; ++s) { ll sum = accumulate(hoge[s].begin(), hoge[s].end(), 0ll); score += 10ll * (hoge[s].size() - 1); score += abs(sum - len[s]); } chmin(res, score); } cout << res << endl; }
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<int, double> Pid; typedef pair<double, int> Pdi; typedef pair<ll, int> Pl; const double PI = 3.1415926535897932; // acos(-1) const double EPS = 1e-15; const int INF = 1001001001; const ll mod = 1e+9 + 7; #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define chadd(x, y) x = (x + y) % mod int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<ll> len(3); for (int i = 0; i < 3; ++i) cin >> len[i]; vector<ll> l(n); int limit = 1; for (int i = 0; i < n; ++i) { cin >> l[i]; limit *= 4; } ll res = 1e+15; for (int i = 0; i < limit; ++i) { int foo = i; int id = 0; vector<vector<ll>> hoge(4); while (id < n) { hoge[foo % 4].push_back(l[id++]); foo /= 4; } if (hoge[0].size() == 0 || hoge[1].size() == 0 || hoge[2].size() == 0) continue; ll score = 0; for (int s = 0; s < 3; ++s) { ll sum = accumulate(hoge[s].begin(), hoge[s].end(), 0ll); score += 10ll * (hoge[s].size() - 1); score += abs(sum - len[s]); } chmin(res, score); } cout << res << endl; }
[ "control_flow.loop.for.condition.change" ]
924,640
924,641
u190018920
cpp
p03111
#include <iostream> #include <string> #include <vector> const int INF = 1000000000; int n; int target[3]; std::vector<int> l; // ref : https://img.atcoder.jp/abc119/editorial.pdf // ref : https://drken1215.hatenablog.com/entry/2019/02/24/224100 /* 延長、縮小は合成の前後どっちでやろうが同じ -> 合成魔法を一切これ以降使用しない場合に限り延長、縮小魔法を使用としても一般性は失われない 目的を達成するに当たって竹はA, B, Cの材料or一切使わないの4通り -> N本あるので4^N通り そこで合成するペアだけ全探索すればあとは目標の長さを得るためのコストを計算すればok */ int solve(int i = 0, int a = 0, int b = 0, int c = 0) { if (i == n) { // どれも目標の長さを作るのに使っていない場合はダメ if (!a || !b || !c) return INF; else return std::abs(a - target[0]) + std::abs(b - target[1]) + std::abs(c - target[2]); } int cost = INF; cost = std::min(cost, solve(i + 1, a, b, c)); // この竹を使わない // 以降使う, このとき最初の1本目は合成できていないので+10しないことに注意 cost = std::min(cost, solve(i + 1, a + l[i], b, c) + (a ? 10 : 0)); cost = std::min(cost, solve(i + 1, a, b + l[i], c) + (b ? 10 : 0)); cost = std::min(cost, solve(i + 1, a, b, c + l[i]) + (c ? 10 : 0)); return cost; } int main() { std::cin >> n; l.assign(3, 0); for (int i = 0; i < 3; i++) std::cin >> target[i]; for (int i = 0; i < n; i++) { std::cin >> l[i]; } std::cout << solve() << std::endl; return 0; }
#include <iostream> #include <string> #include <vector> const int INF = 1000000000; int n; int target[3]; std::vector<int> l; // ref : https://img.atcoder.jp/abc119/editorial.pdf // ref : https://drken1215.hatenablog.com/entry/2019/02/24/224100 /* 延長、縮小は合成の前後どっちでやろうが同じ -> 合成魔法を一切これ以降使用しない場合に限り延長、縮小魔法を使用としても一般性は失われない 目的を達成するに当たって竹はA, B, Cの材料or一切使わないの4通り -> N本あるので4^N通り そこで合成するペアだけ全探索すればあとは目標の長さを得るためのコストを計算すればok */ int solve(int i = 0, int a = 0, int b = 0, int c = 0) { if (i == n) { // どれも目標の長さを作るのに使っていない場合はダメ if (!a || !b || !c) return INF; else return std::abs(a - target[0]) + std::abs(b - target[1]) + std::abs(c - target[2]); } int cost = INF; cost = std::min(cost, solve(i + 1, a, b, c)); // この竹を使わない // 以降使う, このとき最初の1本目は合成できていないので+10しないことに注意 cost = std::min(cost, solve(i + 1, a + l[i], b, c) + (a ? 10 : 0)); cost = std::min(cost, solve(i + 1, a, b + l[i], c) + (b ? 10 : 0)); cost = std::min(cost, solve(i + 1, a, b, c + l[i]) + (c ? 10 : 0)); return cost; } int main() { std::cin >> n; l.assign(n, 0); for (int i = 0; i < 3; i++) std::cin >> target[i]; for (int i = 0; i < n; i++) { std::cin >> l[i]; } std::cout << solve() << std::endl; return 0; }
[ "identifier.replace.add", "literal.replace.remove", "call.arguments.change" ]
924,642
924,643
u390165589
cpp
p03111
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> P; typedef pair<ll, ll> Pll; using Graph = vector<vector<int>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define Rep(i, k, n) for (int i = k; i < (int)(n); i++) #define RRep(i, k, n) for (int i = k; i > (int)(n); i--) #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl #define ALL(a) (a).begin(), (a).end() #define rALL(a) (a).rbegin(), (a).rend() template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long INF = 1LL << 60; const int MOD = 1000000007; const double PI = acos(-1); // 3.14~ const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int n, A, B, C; vector<int> l; int rec(int i, int a, int b, int c) { if (i == n) { if (!a || !b || !c) return MOD; return abs(a - A) + abs(b - B) + abs(c - C); } int ans = rec(i + 1, a, b, c); chmin(ans, rec(i + 1, a + l[i], b, c) + (a ? 10 : 0)); chmin(ans, rec(i + 1, a, b + l[i], c) + (b ? 10 : 0)); chmin(ans, rec(i + 1, a, b, c + l[i]) + (c ? 10 : 0)); COUT(ans); return ans; } int main() { cin >> n >> A >> B >> C; l.resize(n); rep(i, n) cin >> l[i]; cout << rec(0, 0, 0, 0) << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> P; typedef pair<ll, ll> Pll; using Graph = vector<vector<int>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define Rep(i, k, n) for (int i = k; i < (int)(n); i++) #define RRep(i, k, n) for (int i = k; i > (int)(n); i--) #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl #define ALL(a) (a).begin(), (a).end() #define rALL(a) (a).rbegin(), (a).rend() template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long INF = 1LL << 60; const int MOD = 1000000007; const double PI = acos(-1); // 3.14~ const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int n, A, B, C; vector<int> l; int rec(int i, int a, int b, int c) { if (i == n) { if (!a || !b || !c) return MOD; return abs(a - A) + abs(b - B) + abs(c - C); } int ans = rec(i + 1, a, b, c); chmin(ans, rec(i + 1, a + l[i], b, c) + (a ? 10 : 0)); chmin(ans, rec(i + 1, a, b + l[i], c) + (b ? 10 : 0)); chmin(ans, rec(i + 1, a, b, c + l[i]) + (c ? 10 : 0)); return ans; } int main() { cin >> n >> A >> B >> C; l.resize(n); rep(i, n) cin >> l[i]; cout << rec(0, 0, 0, 0) << endl; }
[ "call.remove" ]
924,644
924,645
u011716617
cpp
p03111
#include <cmath> #include <iostream> using namespace std; const int INF = 1e9; int calc_mp(int *take, int a, int b, int c) { if (take[0] == 0 || take[1] == 0 || take[2] == 0) { return INF; } return std::abs(take[0] - a) + std::abs(take[1] - b) + std::abs(take[2] - c); } void copy(int *l, int *m) { m[0] = l[0]; m[1] = l[1]; m[2] = l[2]; } int mp_min = INF; int search(int *l, int n, int i, int *take, int a, int b, int c, int tmp_mp) { if (i == n) { int mp = calc_mp(take, a, b, c) + tmp_mp - 31; if (mp < mp_min) { mp_min = mp; } return 0; } int li = l[i]; search(l, n, i + 1, take, a, b, c, tmp_mp); int t2[3]; copy(take, t2); t2[0] += li; search(l, n, i + 1, t2, a, b, c, tmp_mp + 10); int t3[3]; copy(take, t3); t3[1] += li; search(l, n, i + 1, t3, a, b, c, tmp_mp + 10); int t4[3]; copy(take, t4); t4[2] += li; search(l, n, i + 1, t4, a, b, c, tmp_mp + 10); return mp_min; } int main() { ios::sync_with_stdio(false); int n, a, b, c; cin >> n >> a >> b >> c; int l[8]; for (int i = 0; i < n; i++) { int li; cin >> li; l[i] = li; } int take[3] = {0}; cout << search(l, n, 0, take, a, b, c, 0); }
#include <cmath> #include <iostream> using namespace std; const int INF = 1e9; int calc_mp(int *take, int a, int b, int c) { if (take[0] == 0 || take[1] == 0 || take[2] == 0) { return INF; } return std::abs(take[0] - a) + std::abs(take[1] - b) + std::abs(take[2] - c); } void copy(int *l, int *m) { m[0] = l[0]; m[1] = l[1]; m[2] = l[2]; } int mp_min = INF; int search(int *l, int n, int i, int *take, int a, int b, int c, int tmp_mp) { if (i == n) { int mp = calc_mp(take, a, b, c) + tmp_mp - 30; if (mp < mp_min) { mp_min = mp; } return 0; } int li = l[i]; search(l, n, i + 1, take, a, b, c, tmp_mp); int t2[3]; copy(take, t2); t2[0] += li; search(l, n, i + 1, t2, a, b, c, tmp_mp + 10); int t3[3]; copy(take, t3); t3[1] += li; search(l, n, i + 1, t3, a, b, c, tmp_mp + 10); int t4[3]; copy(take, t4); t4[2] += li; search(l, n, i + 1, t4, a, b, c, tmp_mp + 10); return mp_min; } int main() { ios::sync_with_stdio(false); int n, a, b, c; cin >> n >> a >> b >> c; int l[8]; for (int i = 0; i < n; i++) { int li; cin >> li; l[i] = li; } int take[3] = {0}; cout << search(l, n, 0, take, a, b, c, 0); }
[ "literal.number.change", "expression.operation.binary.change" ]
924,657
924,658
u313766957
cpp
p03111
#include <bits/stdc++.h> #include <cassert> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; struct Edge { int to; int weight; Edge(int t, int w) : to(t), weight(w) {} }; using Graph = vector<vector<Edge>>; // using Graph = vector<vector<int>>; const long long INF = 1LL << 60; const int INT_INF = 1000000000; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; // int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1}; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<int> A(3); for (auto &it : A) cin >> it; vector<int> l(N); for (auto &it : l) cin >> it; int res = 1 << 29; vector<int> bit(3); for (bit[0] = 1; bit[0] < (1 << N); bit[0]++) { // 0は含めない for (bit[1] = 1; bit[1] < (1 << N); bit[1]++) { if (bit[1] & bit[0]) continue; for (bit[2] = 1; bit[2] < (1 << N); bit[2]++) { if (bit[2] & bit[0]) continue; if (bit[2] & bit[0]) continue; // sums: A ~ Cに選んだ竹の長さの合計 nums: A ~ Cに選んだ竹の数 vector<int> sums(3, 0), nums(3, 0); for (int i = 0; i < N; i++) { for (int j = 0; j < 3; j++) { if (bit[j] & (1 << i)) { sums[j] += l[i]; nums[j]++; } } } int score = 0; for (int i = 0; i < 3; i++) { score += abs(sums[i] - A[i]); // +1, -1のコスト score += (nums[i] - 1) * 10; // 合体のコスト } res = min(res, score); } } } cout << res << endl; return 0; }
#include <bits/stdc++.h> #include <cassert> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; struct Edge { int to; int weight; Edge(int t, int w) : to(t), weight(w) {} }; using Graph = vector<vector<Edge>>; // using Graph = vector<vector<int>>; const long long INF = 1LL << 60; const int INT_INF = 1000000000; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; // int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1}; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<int> A(3); for (auto &it : A) cin >> it; vector<int> l(N); for (auto &it : l) cin >> it; int res = 1 << 29; vector<int> bit(3); for (bit[0] = 1; bit[0] < (1 << N); bit[0]++) { // 0は含めない for (bit[1] = 1; bit[1] < (1 << N); bit[1]++) { if (bit[1] & bit[0]) continue; for (bit[2] = 1; bit[2] < (1 << N); bit[2]++) { if (bit[2] & bit[0]) continue; if (bit[2] & bit[1]) continue; // sums: A ~ Cに選んだ竹の長さの合計 nums: A ~ Cに選んだ竹の数 vector<int> sums(3, 0), nums(3, 0); for (int i = 0; i < N; i++) { for (int j = 0; j < 3; j++) { if (bit[j] & (1 << i)) { sums[j] += l[i]; nums[j]++; } } } int score = 0; for (int i = 0; i < 3; i++) { score += abs(sums[i] - A[i]); // +1, -1のコスト score += (nums[i] - 1) * 10; // 合体のコスト } res = min(res, score); } } } cout << res << endl; return 0; }
[ "literal.number.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
924,665
924,666
u665871498
cpp
p03111
#include <bits/stdc++.h> #include <cassert> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; struct Edge { int to; int weight; Edge(int t, int w) : to(t), weight(w) {} }; using Graph = vector<vector<Edge>>; // using Graph = vector<vector<int>>; const long long INF = 1LL << 60; const int INT_INF = 1000000000; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; // int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1}; int N, A, B, C; vector<int> l; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int rec(int i, int a, int b, int c) { if (i == N) { if (!a || !b || !c) return INF; return abs(a - A) + abs(b - B) + abs(c - C); } int res = rec(i + 1, a, b, c); // 今ある竹を使用しない場合 // A, B, Cに使う場合 // (a ? 10 : // 0)とかは最初の1本目は合体コストなし,2本目から10かかることを意味する chmin(res, rec(i + 1, a + l[i], b, c) + (a ? 10 : 0)); // 各場合についてresと比較していく chmin(res, rec(i + 1, a, b + l[i], c) + (b ? 10 : 0)); chmin(res, rec(i + 1, a, b, c + l[i]) + (c ? 10 : 0)); return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> A >> B >> C; l.resize(N); for (auto &it : l) cin >> it; cout << rec(0, 0, 0, 0) << endl; return 0; }
#include <bits/stdc++.h> #include <cassert> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; struct Edge { int to; int weight; Edge(int t, int w) : to(t), weight(w) {} }; using Graph = vector<vector<Edge>>; // using Graph = vector<vector<int>>; const long long INF = 1LL << 60; const int INT_INF = 1000000000; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; // int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1}; int N, A, B, C; vector<int> l; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } ll rec(int i, int a, int b, int c) { if (i == N) { if (!a || !b || !c) return INF; return abs(a - A) + abs(b - B) + abs(c - C); } ll res = rec(i + 1, a, b, c); // 今ある竹を使用しない場合 // A, B, Cに使う場合 // (a ? 10 : // 0)とかは最初の1本目は合体コストなし,2本目から10かかることを意味する chmin(res, rec(i + 1, a + l[i], b, c) + (a ? 10 : 0)); // 各場合についてresと比較していく chmin(res, rec(i + 1, a, b + l[i], c) + (b ? 10 : 0)); chmin(res, rec(i + 1, a, b, c + l[i]) + (c ? 10 : 0)); return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> A >> B >> C; l.resize(N); for (auto &it : l) cin >> it; cout << rec(0, 0, 0, 0) << endl; return 0; }
[ "variable_declaration.type.change" ]
924,667
924,668
u665871498
cpp
p03111
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, a, b) for (int i = a; i < (int)b; ++i) #define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i) using ll = long long; using ld = long double; const ll INF = 1e18; const int Inf = 1e9; const double EPS = 1e-9; const int MOD = 1e9 + 7; int n, a, b, c; vector<int> l; int dfs(int cur = 0, int x = 0, int y = 0, int z = 0) { if (cur == n) { if (!x || !b || !c) return Inf; return abs(x - a) + abs(y - b) + abs(z - c); } int res = Inf; res = min(res, dfs(cur + 1, x + l[cur], y, z) + 10); res = min(res, dfs(cur + 1, x, y + l[cur], z) + 10); res = min(res, dfs(cur + 1, x, y, z + l[cur]) + 10); res = min(res, dfs(cur + 1, x, y, z)); return res; } int main() { cin.tie(nullptr); ios::sync_with_stdio(0); cin >> n >> a >> b >> c; l.resize(n); rep(i, n) cin >> l[i]; cout << dfs() - 30 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, a, b) for (int i = a; i < (int)b; ++i) #define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i) using ll = long long; using ld = long double; const ll INF = 1e18; const int Inf = 1e9; const double EPS = 1e-9; const int MOD = 1e9 + 7; int n, a, b, c; vector<int> l; int dfs(int cur = 0, int x = 0, int y = 0, int z = 0) { if (cur == n) { if (!x || !y || !z) return Inf; return abs(x - a) + abs(y - b) + abs(z - c); } int res = Inf; res = min(res, dfs(cur + 1, x + l[cur], y, z) + 10); res = min(res, dfs(cur + 1, x, y + l[cur], z) + 10); res = min(res, dfs(cur + 1, x, y, z + l[cur]) + 10); res = min(res, dfs(cur + 1, x, y, z)); return res; } int main() { cin.tie(nullptr); ios::sync_with_stdio(0); cin >> n >> a >> b >> c; l.resize(n); rep(i, n) cin >> l[i]; cout << dfs() - 30 << endl; return 0; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
924,669
924,670
u940569542
cpp
p03111
#include <algorithm> #include <bitset> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <math.h> #include <queue> #include <set> #include <stdlib.h> #include <string> #include <utility> #include <vector> using namespace std; typedef long long int ll; typedef long double ld; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long INF = 1LL << 60; typedef pair<ll, ll> pairs; vector<pairs> p; bool pairCompare(const pair<double, ll> &firstElof, const pair<double, ll> &secondElof) { return firstElof.first < secondElof.first; } bool pairCompareSecond(const pair<double, ll> &firstElof, const pair<double, ll> &secondElof) { return firstElof.second < secondElof.second; } #define MAX_N 100100 #define MOD 1000000007 bool x[MAX_N]; ll num[MAX_N]; ll fibl[MAX_N] = {0}; // 四方向への移動ベクトル const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; ll fib(ll a) { if (fibl[a] != 0) return fibl[a]; if (a == 0) { return 0; } else if (a == 1) { return 1; } return fibl[a] = fib(a - 1) + fib(a - 2); } ll eratosthenes(ll n) { int p = 0; for (ll i = 0; i <= n; ++i) x[i] = true; x[0] = x[1] = false; for (int i = 2; i <= n; ++i) { if (x[i]) { p++; for (int j = 2 * i; j <= n; j += i) x[j] = false; } num[i] = p; } return p; } ll gcd(ll a, ll b) { if (a % b == 0) return (b); else return (gcd(b, a % b)); } ll keta(ll N) { int tmp{}; while (N > 0) { tmp += (N % 10); N /= 10; } N = tmp; return N; } void base_num(ll data, ll base) { if (data == 0) return; ll next = abs(data) % abs(base); if (data < 0) next = (abs(base) - next) % abs(base); base_num((data - next) / base, base); cout << next; } ll nx[9], n, A, B, C; ll dfs(ll co, ll a, ll b, ll c) { ll r0, r1, r2, r3; if (co == n) { ll x = 30; if (min(min(a, b), c) > 0) { return abs(a - A) + abs(b - B) + abs(c - C) - x; } } r0 = dfs(co + 1, a, b, c); r1 = dfs(co + 1, a + nx[co], b, c) + 10; r2 = dfs(co + 1, a, b + nx[co], c) + 10; r3 = dfs(co + 1, a, b, c + nx[co]) + 10; return min(min(r0, r1), min(r2, r3)); } int main() { cin >> n >> A >> B >> C; for (ll i = 0; i < n; i++) { cin >> nx[i]; } cout << dfs(0, 0, 0, 0) << endl; }
#include <algorithm> #include <bitset> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <math.h> #include <queue> #include <set> #include <stdlib.h> #include <string> #include <utility> #include <vector> using namespace std; typedef long long int ll; typedef long double ld; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long INF = 1LL << 60; typedef pair<ll, ll> pairs; vector<pairs> p; bool pairCompare(const pair<double, ll> &firstElof, const pair<double, ll> &secondElof) { return firstElof.first < secondElof.first; } bool pairCompareSecond(const pair<double, ll> &firstElof, const pair<double, ll> &secondElof) { return firstElof.second < secondElof.second; } #define MAX_N 100100 #define MOD 1000000007 bool x[MAX_N]; ll num[MAX_N]; ll fibl[MAX_N] = {0}; // 四方向への移動ベクトル const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; ll fib(ll a) { if (fibl[a] != 0) return fibl[a]; if (a == 0) { return 0; } else if (a == 1) { return 1; } return fibl[a] = fib(a - 1) + fib(a - 2); } ll eratosthenes(ll n) { int p = 0; for (ll i = 0; i <= n; ++i) x[i] = true; x[0] = x[1] = false; for (int i = 2; i <= n; ++i) { if (x[i]) { p++; for (int j = 2 * i; j <= n; j += i) x[j] = false; } num[i] = p; } return p; } ll gcd(ll a, ll b) { if (a % b == 0) return (b); else return (gcd(b, a % b)); } ll keta(ll N) { int tmp{}; while (N > 0) { tmp += (N % 10); N /= 10; } N = tmp; return N; } void base_num(ll data, ll base) { if (data == 0) return; ll next = abs(data) % abs(base); if (data < 0) next = (abs(base) - next) % abs(base); base_num((data - next) / base, base); cout << next; } ll nx[9], n, A, B, C; ll dfs(ll co, ll a, ll b, ll c) { ll r0, r1, r2, r3; if (co == n) { ll x = 30; if (min(min(a, b), c) > 0) { return abs(a - A) + abs(b - B) + abs(c - C) - x; } else { return INF; } } r0 = dfs(co + 1, a, b, c); r1 = dfs(co + 1, a + nx[co], b, c) + 10; r2 = dfs(co + 1, a, b + nx[co], c) + 10; r3 = dfs(co + 1, a, b, c + nx[co]) + 10; return min(min(r0, r1), min(r2, r3)); } int main() { cin >> n >> A >> B >> C; for (ll i = 0; i < n; i++) { cin >> nx[i]; } cout << dfs(0, 0, 0, 0) << endl; }
[ "control_flow.branch.else.add", "control_flow.return.add" ]
924,686
924,687
u273928723
cpp
p03111
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) const int INF = INT_MAX; int N, A, B, C; vector<int> l; int dfs(int i, int a, int b, int c) { if (i == N) { if (!a || !b || !c) return INF; else return abs(A - a) + abs(B - b) + abs(C - c); } int res = dfs(i + 1, a, b, c); res = min(res, dfs(i + 1, a + l[i], b, c) + (a ? 10 : 0)); res = min(res, dfs(i + 1, a, b + l[i], c) + (b ? 10 : 0)); res = min(res, dfs(i + 1, a, b, c + l[i]) + (c ? 10 : 0)); return res; } int main() { cin >> N >> A >> B >> C; l.resize(N); rep(i, N) { cin >> l[i]; } cout << dfs(0, 0, 0, 0) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) const long long INF = 1 << 29; int N, A, B, C; vector<int> l; int dfs(int i, int a, int b, int c) { if (i == N) { if (!a || !b || !c) return INF; else return abs(A - a) + abs(B - b) + abs(C - c); } int res = dfs(i + 1, a, b, c); res = min(res, dfs(i + 1, a + l[i], b, c) + (a ? 10 : 0)); res = min(res, dfs(i + 1, a, b + l[i], c) + (b ? 10 : 0)); res = min(res, dfs(i + 1, a, b, c + l[i]) + (c ? 10 : 0)); return res; } int main() { cin >> N >> A >> B >> C; l.resize(N); rep(i, N) { cin >> l[i]; } cout << dfs(0, 0, 0, 0) << endl; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change", "identifier.replace.remove", "literal.replace.add" ]
924,688
924,689
u702686470
cpp
p03111
#include <bits/stdc++.h> using namespace std; #define ll long long ll MIN(ll a, ll b) { return a < b ? a : b; } ll a, b, c, n; ll *arr; ll Synthetic(ll x, ll y, ll z, ll i) { if (i == n) { if (x < 0 || y < 0 || z < 0) return 1e12; else return abs(a - x) + abs(b - y) + abs(c - z); } ll op1 = Synthetic(x, y, z, i + 1); ll op2 = Synthetic(x + arr[i], y, z, i + 1) + (x > 0 ? 10 : 0); ll op3 = Synthetic(x, y + arr[i], z, i + 1) + (y > 0 ? 10 : 0); ll op4 = Synthetic(x, y, z + arr[i], i + 1) + (z > 0 ? 10 : 0); return MIN(op1, MIN(op2, MIN(op3, op4))); } int main() { cin >> n >> a >> b >> c; arr = new ll[n]; for (ll i = 0; i < n; i++) { cin >> arr[i]; } cout << Synthetic(0, 0, 0, 0); cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long ll MIN(ll a, ll b) { return a < b ? a : b; } ll a, b, c, n; ll *arr; ll Synthetic(ll x, ll y, ll z, ll i) { if (i == n) { if (x <= 0 || y <= 0 || z <= 0) return 1e12; return abs(a - x) + abs(b - y) + abs(c - z); } ll op1 = Synthetic(x, y, z, i + 1); ll op2 = Synthetic(x + arr[i], y, z, i + 1) + (x > 0 ? 10 : 0); ll op3 = Synthetic(x, y + arr[i], z, i + 1) + (y > 0 ? 10 : 0); ll op4 = Synthetic(x, y, z + arr[i], i + 1) + (z > 0 ? 10 : 0); return MIN(op1, MIN(op2, MIN(op3, op4))); } int main() { cin >> n >> a >> b >> c; arr = new ll[n]; for (ll i = 0; i < n; i++) { cin >> arr[i]; } cout << Synthetic(0, 0, 0, 0); cout << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "control_flow.branch.else.remove" ]
924,698
924,699
u017126309
cpp
p03111
#include <bits/stdc++.h> #include <iostream> using namespace std; using ll = int64_t; #define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順 int N, A, B, C; vector<int> L(8); int DFS(int cur, int a, int b, int c) { if (cur == N) { if ((a & b & c) == 0) return 1 << 30; else return abs(A - a) + abs(B - b) + abs(C - c) - 30; } int r0, r1, r2, r3; r0 = DFS(cur + 1, a, b, c); r1 = DFS(cur + 1, a + L[cur], b, c) + 10; r2 = DFS(cur + 1, a, b + L[cur], c) + 10; r3 = DFS(cur + 1, a, b, c + L[cur]) + 10; int r4 = min({r0, r1, r2, r3}); // printf("%d %d %d %d: %d\n", cur, a, b, c, r4); return r4; } int main() { cin >> N >> A >> B >> C; rep(i, N) cin >> L.at(i); cout << DFS(0, 0, 0, 0) << endl; }
#include <bits/stdc++.h> #include <iostream> using namespace std; using ll = int64_t; #define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順 int N, A, B, C; vector<int> L(8); int DFS(int cur, int a, int b, int c) { if (cur == N) { if (min({a, b, c}) == 0) return 1 << 30; else return abs(A - a) + abs(B - b) + abs(C - c) - 30; } int r0, r1, r2, r3; r0 = DFS(cur + 1, a, b, c); r1 = DFS(cur + 1, a + L[cur], b, c) + 10; r2 = DFS(cur + 1, a, b + L[cur], c) + 10; r3 = DFS(cur + 1, a, b, c + L[cur]) + 10; int r4 = min({r0, r1, r2, r3}); // printf("%d %d %d %d: %d\n", cur, a, b, c, r4); return r4; } int main() { cin >> N >> A >> B >> C; rep(i, N) cin >> L.at(i); cout << DFS(0, 0, 0, 0) << endl; }
[ "call.add", "control_flow.branch.if.condition.change" ]
924,704
924,705
u823855263
cpp
p03111
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(x) (x).begin(), (x).end() typedef long long ll; typedef pair<int, int> P; typedef vector<vector<int>> Matrix; static const int INF = 1 << 29; int N, A, B, C; int l[8]; int dfs(int a, int b, int c, int i) { int minv = INF; if (i == N) return ((a == 0 || b == 0 || c == 0) ? INF : abs(a - A) + abs(b - B) + abs(c - C) - 30); minv = min(minv, dfs(a + l[i], b, c, i + 1) + 10); minv = min(minv, dfs(a, b + l[i], c, i + 1) + 10); minv = min(minv, dfs(a, b, c + l[i], i + 1) + 10); minv = min(minv, dfs(a, b, c, i + 1) + 10); return minv; } int main() { cin >> N >> A >> B >> C; rep(i, N) cin >> l[i]; cout << dfs(0, 0, 0, 0) << endl; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(x) (x).begin(), (x).end() typedef long long ll; typedef pair<int, int> P; typedef vector<vector<int>> Matrix; static const int INF = 1 << 29; int N, A, B, C; int l[8]; int dfs(int a, int b, int c, int i) { int minv = INF; if (i == N) return ((a == 0 || b == 0 || c == 0) ? INF : abs(a - A) + abs(b - B) + abs(c - C) - 30); minv = min(minv, dfs(a + l[i], b, c, i + 1) + 10); minv = min(minv, dfs(a, b + l[i], c, i + 1) + 10); minv = min(minv, dfs(a, b, c + l[i], i + 1) + 10); minv = min(minv, dfs(a, b, c, i + 1)); return minv; } int main() { cin >> N >> A >> B >> C; rep(i, N) cin >> l[i]; cout << dfs(0, 0, 0, 0) << endl; }
[ "expression.operation.binary.remove" ]
924,708
924,709
u263000123
cpp
p03111
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(x) (x).begin(), (x).end() typedef long long ll; typedef pair<int, int> P; typedef vector<vector<int>> Matrix; static const int INF = 1 << 29; int N, A, B, C; int l[8]; int dfs(int a, int b, int c, int i) { int minv = INF; if (i == N) return ((a == 0 || b == 0 || c == 0) ? INF : abs(a - A) + abs(b - B) + abs(c - C) - 30); minv = min(minv, dfs(a + l[i], b, c, i + 1) + 10); minv = min(minv, dfs(a, b + l[i], c, i + 1) + 10); minv = min(minv, dfs(a, b, c + l[i], i + 1) + 10); minv = min(minv, dfs(a, b, c, i + 1) + 10); // return minv; } int main() { cin >> N >> A >> B >> C; rep(i, N) cin >> l[i]; cout << dfs(0, 0, 0, 0) << endl; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(x) (x).begin(), (x).end() typedef long long ll; typedef pair<int, int> P; typedef vector<vector<int>> Matrix; static const int INF = 1 << 29; int N, A, B, C; int l[8]; int dfs(int a, int b, int c, int i) { int minv = INF; if (i == N) return ((a == 0 || b == 0 || c == 0) ? INF : abs(a - A) + abs(b - B) + abs(c - C) - 30); minv = min(minv, dfs(a + l[i], b, c, i + 1) + 10); minv = min(minv, dfs(a, b + l[i], c, i + 1) + 10); minv = min(minv, dfs(a, b, c + l[i], i + 1) + 10); minv = min(minv, dfs(a, b, c, i + 1)); return minv; } int main() { cin >> N >> A >> B >> C; rep(i, N) cin >> l[i]; cout << dfs(0, 0, 0, 0) << endl; }
[ "expression.operation.binary.remove", "control_flow.return.add" ]
924,710
924,709
u263000123
cpp
p03112
//解説読了後の実装 #include <algorithm> #include <cstdlib> #include <iostream> #include <vector> using namespace std; vector<long long int> s; vector<long long int> t; // index が条件を満たすかどうか bool isOKs(int index, long long key) { if (s[index] > key) return true; else return false; } bool isOKt(int index, long long key) { if (t[index] > key) return true; else return false; } // 汎用的な二分探索のテンプレ int binary_searchs(long long key) { int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1 int right = (int)s.size(); // 「index = // a.size()-1」が条件を満たさないこともあるので、初期値は // a.size() /* どんな二分探索でもここの書き方を変えずにできる! */ while (right - left > 1) { int mid = left + (right - left) / 2; if (isOKs(mid, key)) right = mid; else left = mid; } /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */ return right; } int binary_searcht(long long key) { int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1 int right = (int)t.size(); // 「index = // a.size()-1」が条件を満たさないこともあるので、初期値は // a.size() /* どんな二分探索でもここの書き方を変えずにできる! */ while (right - left > 1) { int mid = left + (right - left) / 2; if (isOKt(mid, key)) right = mid; else left = mid; } /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */ return right; } int main() { int A, B, Q; cin >> A >> B >> Q; long long st, tt; for (int i = 0; i < A; i++) { cin >> st; s.push_back(st); } for (int i = 0; i < B; i++) { cin >> tt; t.push_back(tt); } long long x; for (int i = 0; i < Q; i++) { cin >> x; int idxs = binary_searchs(x); int idxt = binary_searcht(x); long long answer = 1000000000000000000; for (int j = idxs - 1; j <= idxs; j++) { for (int k = idxt - 1; k <= idxt; k++) { if (j >= s.size() || k >= t.size()) continue; long long d1 = abs(s[j] - x) + abs(t[k] - s[j]); long long d2 = abs(t[k] - x) + abs(s[j] - t[k]); min({answer, d1, d2}); } } cout << answer << endl; } return 0; }
//解説読了後の実装 #include <algorithm> #include <cstdlib> #include <iostream> #include <vector> using namespace std; vector<long long int> s; vector<long long int> t; // index が条件を満たすかどうか bool isOKs(int index, long long key) { if (s[index] > key) return true; else return false; } bool isOKt(int index, long long key) { if (t[index] > key) return true; else return false; } // 汎用的な二分探索のテンプレ int binary_searchs(long long key) { int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1 int right = (int)s.size(); // 「index = // a.size()-1」が条件を満たさないこともあるので、初期値は // a.size() /* どんな二分探索でもここの書き方を変えずにできる! */ while (right - left > 1) { int mid = left + (right - left) / 2; if (isOKs(mid, key)) right = mid; else left = mid; } /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */ return right; } int binary_searcht(long long key) { int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1 int right = (int)t.size(); // 「index = // a.size()-1」が条件を満たさないこともあるので、初期値は // a.size() /* どんな二分探索でもここの書き方を変えずにできる! */ while (right - left > 1) { int mid = left + (right - left) / 2; if (isOKt(mid, key)) right = mid; else left = mid; } /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */ return right; } int main() { int A, B, Q; cin >> A >> B >> Q; long long st, tt; for (int i = 0; i < A; i++) { cin >> st; s.push_back(st); } for (int i = 0; i < B; i++) { cin >> tt; t.push_back(tt); } long long x; for (int i = 0; i < Q; i++) { cin >> x; int idxs = binary_searchs(x); int idxt = binary_searcht(x); long long answer = 1000000000000000000; for (int j = idxs - 1; j <= idxs; j++) { for (int k = idxt - 1; k <= idxt; k++) { if (j >= s.size() || k >= t.size()) continue; long long d1 = abs(s[j] - x) + abs(t[k] - s[j]); long long d2 = abs(t[k] - x) + abs(s[j] - t[k]); answer = min({answer, d1, d2}); } } cout << answer << endl; } return 0; }
[ "assignment.change" ]
924,715
924,716
u707498674
cpp
p03112
#include <algorithm> #include <iostream> #include <vector> using namespace std; void chmin(long long &a, long long b) { if (a > b) a = b; } const long long INF = 1LL << 59; // 前方の index int former(const vector<long long> &v, long long x) { return (int)(upper_bound(v.begin(), v.end(), x) - v.begin()) - 1; } // 後方の index int latter(const vector<long long> &v, long long x) { return (int)(lower_bound(v.begin(), v.end(), x) - v.begin()); } int main() { int A, B, Q; cin >> A >> B >> Q; vector<long long> s(A), t(B); for (int i = 0; i < A; ++i) cin >> s[i]; for (int i = 0; i < B; ++i) cin >> t[i]; s.push_back(INF); s.push_back(-INF); t.push_back(INF); t.push_back(-INF); sort(s.begin(), s.end()); sort(t.begin(), t.end()); for (int _ = 0; _ < Q; ++_) { long long x; cin >> x; long long res = INF; // 最初に s (前方に行くか後方に行くか場合分け) for (int fl = 0; fl < 2; ++fl) { int sid = (fl == 0 ? former(s, x) : latter(s, x)); // t の前か後ろか for (int fl2 = 0; fl2 < 2; ++fl2) { int tid = (fl2 == 0 ? former(t, s[sid]) : latter(s, s[sid])); chmin(res, abs(x - s[sid]) + abs(s[sid] - t[tid])); } } // 最初に t (前方に行くか後方に行くか場合分け) for (int fl = 0; fl < 2; ++fl) { int tid = (fl == 0 ? former(t, x) : latter(t, x)); // t の前か後ろか for (int fl2 = 0; fl2 < 2; ++fl2) { int sid = (fl2 == 0 ? former(s, t[tid]) : latter(s, t[tid])); chmin(res, abs(x - t[tid]) + abs(t[tid] - s[sid])); } } cout << res << endl; } }
#include <algorithm> #include <iostream> #include <vector> using namespace std; void chmin(long long &a, long long b) { if (a > b) a = b; } const long long INF = 1LL << 59; // 前方の index int former(const vector<long long> &v, long long x) { return (int)(upper_bound(v.begin(), v.end(), x) - v.begin()) - 1; } // 後方の index int latter(const vector<long long> &v, long long x) { return (int)(lower_bound(v.begin(), v.end(), x) - v.begin()); } int main() { int A, B, Q; cin >> A >> B >> Q; vector<long long> s(A), t(B); for (int i = 0; i < A; ++i) cin >> s[i]; for (int i = 0; i < B; ++i) cin >> t[i]; s.push_back(INF); s.push_back(-INF); t.push_back(INF); t.push_back(-INF); sort(s.begin(), s.end()); sort(t.begin(), t.end()); for (int _ = 0; _ < Q; ++_) { long long x; cin >> x; long long res = INF; // 最初に s (前方に行くか後方に行くか場合分け) for (int fl = 0; fl < 2; ++fl) { int sid = (fl == 0 ? former(s, x) : latter(s, x)); // t の前か後ろか for (int fl2 = 0; fl2 < 2; ++fl2) { int tid = (fl2 == 0 ? former(t, s[sid]) : latter(t, s[sid])); chmin(res, abs(x - s[sid]) + abs(s[sid] - t[tid])); } } // 最初に t (前方に行くか後方に行くか場合分け) for (int fl = 0; fl < 2; ++fl) { int tid = (fl == 0 ? former(t, x) : latter(t, x)); // t の前か後ろか for (int fl2 = 0; fl2 < 2; ++fl2) { int sid = (fl2 == 0 ? former(s, t[tid]) : latter(s, t[tid])); chmin(res, abs(x - t[tid]) + abs(t[tid] - s[sid])); } } cout << res << endl; } }
[ "identifier.change", "call.arguments.change" ]
924,719
924,720
u692336506
cpp
p03112
#include <algorithm> #include <cmath> #include <iostream> #include <limits.h> #include <vector> using namespace std; int A, B, Q; vector<long long> s, t, x; int main() { cin >> A >> B >> Q; s.resize(A + 2); t.resize(B + 2); x.resize(Q); s[0] = LLONG_MIN / 4; s[A + 1] = LLONG_MAX / 4; t[0] = LLONG_MIN / 4; s[B + 1] = LLONG_MAX / 4; for (int i = 1; i <= A; i++) cin >> s[i]; for (int i = 1; i <= B; i++) cin >> t[i]; for (int i = 0; i < Q; i++) cin >> x[i]; long long s_n[2], t_n[2]; long long ans, d1, d2; for (int i = 0; i < Q; i++) { auto it = lower_bound(s.begin(), s.end(), x[i]); s_n[1] = it - s.begin(); s_n[0] = s_n[1] - 1; it = lower_bound(t.begin(), t.end(), x[i]); t_n[1] = it - t.begin(); t_n[0] = t_n[1] - 1; ans = LLONG_MAX / 2; for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { d1 = abs(x[i] - s[s_n[j]]) + abs(s[s_n[j]] - t[t_n[k]]); d2 = abs(x[i] - t[t_n[j]]) + abs(t[t_n[j]] - s[s_n[k]]); ans = min({ans, d1, d2}); } } cout << ans << endl; } return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <limits.h> #include <vector> using namespace std; int A, B, Q; vector<long long> s, t, x; int main() { cin >> A >> B >> Q; s.resize(A + 2); t.resize(B + 2); x.resize(Q); s[0] = LLONG_MIN / 4; s[A + 1] = LLONG_MAX / 4; t[0] = LLONG_MIN / 4; t[B + 1] = LLONG_MAX / 4; for (int i = 1; i <= A; i++) cin >> s[i]; for (int i = 1; i <= B; i++) cin >> t[i]; for (int i = 0; i < Q; i++) cin >> x[i]; long long s_n[2], t_n[2]; long long ans, d1, d2; for (int i = 0; i < Q; i++) { auto it = lower_bound(s.begin(), s.end(), x[i]); s_n[1] = it - s.begin(); s_n[0] = s_n[1] - 1; it = lower_bound(t.begin(), t.end(), x[i]); t_n[1] = it - t.begin(); t_n[0] = t_n[1] - 1; ans = LLONG_MAX / 2; for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { d1 = abs(x[i] - s[s_n[j]]) + abs(s[s_n[j]] - t[t_n[k]]); d2 = abs(x[i] - t[t_n[j]]) + abs(t[t_n[j]] - s[s_n[k]]); ans = min({ans, d1, d2}); } } cout << ans << endl; } return 0; }
[ "assignment.variable.change", "identifier.change" ]
924,725
924,726
u604023588
cpp
p03112
#include <algorithm> #include <cmath> #include <iostream> #include <numeric> #include <string> #include <vector> using namespace std; typedef long long int ll; const int INF = 1 << 30; const long long LINF = 1LL << 60; int main() { int a, b, q; cin >> a >> b >> q; vector<ll> s(a), t(b); for (int i = 0; i < a; i++) { cin >> s[i]; } for (int i = 0; i < b; i++) { cin >> t[i]; } for (int i = 0; i < q; i++) { ll x, ans = LINF; cin >> x; auto itr1 = lower_bound(begin(s), end(s), x); auto itr2 = lower_bound(begin(t), end(t), x); if (itr1 != end(s)) { if (itr2 != end(t)) { ans = min(ans, max(abs(*itr1 - x), abs(*itr2 - x))); } if (itr2 != begin(s)) { ans = min(ans, min(abs(*itr1 - x) * 2 + abs(*(itr2 - 1) - x), abs(*itr1 - x) + abs(*(itr2 - 1) - x) * 2)); } } if (itr1 != begin(s)) { if (itr2 != begin(t)) { ans = min(ans, max(abs(*(itr1 - 1) - x), abs(*(itr2 - 1) - x))); } if (itr2 != end(s)) { ans = min(ans, min(abs(*(itr1 - 1) - x) * 2 + abs(*itr2 - x), abs(*(itr1 - 1) - x) + abs(*itr2 - x) * 2)); } } cout << ans << endl; } return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <numeric> #include <string> #include <vector> using namespace std; typedef long long int ll; const int INF = 1 << 30; const long long LINF = 1LL << 60; int main() { int a, b, q; cin >> a >> b >> q; vector<ll> s(a), t(b); for (int i = 0; i < a; i++) { cin >> s[i]; } for (int i = 0; i < b; i++) { cin >> t[i]; } for (int i = 0; i < q; i++) { ll x, ans = LINF; cin >> x; auto itr1 = lower_bound(begin(s), end(s), x); auto itr2 = lower_bound(begin(t), end(t), x); if (itr1 != end(s)) { if (itr2 != end(t)) { ans = min(ans, max(abs(*itr1 - x), abs(*itr2 - x))); } if (itr2 != begin(t)) { ans = min(ans, min(abs(*itr1 - x) * 2 + abs(*(itr2 - 1) - x), abs(*itr1 - x) + abs(*(itr2 - 1) - x) * 2)); } } if (itr1 != begin(s)) { if (itr2 != begin(t)) { ans = min(ans, max(abs(*(itr1 - 1) - x), abs(*(itr2 - 1) - x))); } if (itr2 != end(t)) { ans = min(ans, min(abs(*(itr1 - 1) - x) * 2 + abs(*itr2 - x), abs(*(itr1 - 1) - x) + abs(*itr2 - x) * 2)); } } cout << ans << endl; } return 0; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
924,737
924,738
u480806810
cpp
p03112
#include <bits/stdc++.h> int a, b, q; long long s[100005], t[100005]; int main() { std::cin >> a >> b >> q; for (int i = 0; i < a; ++i) std::cin >> s[i]; for (int i = 0; i < b; ++i) std::cin >> t[i]; std::sort(s, s + a); std::sort(t, t + b); for (int i = 0; i < q; ++i) { long long x; std::cin >> x; auto r1 = std::distance(s, std::lower_bound(s, s + a, x)); decltype(r1) r2; if (r1 > 0) r2 = r1 - 1; else r2 = r1; if (r1 >= a) r1 = r2; auto l1 = std::distance(t, std::lower_bound(t, t + a, x)); decltype(l1) l2; if (l1 > 0) l2 = l1 - 1; else l2 = l1; if (l2 >= b) l1 = l2; long long ans = LLONG_MAX; long long r[] = {s[r1], s[r2]}; long long l[] = {t[l1], t[l2]}; for (int j = 0; j < 2; ++j) for (int k = 0; k < 2; ++k) { auto d1 = std::abs(r[j] - x) + std::abs(l[k] - r[j]); auto d2 = std::abs(l[k] - x) + std::abs(r[j] - l[k]); ans = std::min({ans, d1, d2}); } std::cout << ans << std::endl; } return 0; }
#include <bits/stdc++.h> int a, b, q; long long s[100005], t[100005]; int main() { std::cin >> a >> b >> q; for (int i = 0; i < a; ++i) std::cin >> s[i]; for (int i = 0; i < b; ++i) std::cin >> t[i]; std::sort(s, s + a); std::sort(t, t + b); for (int i = 0; i < q; ++i) { long long x; std::cin >> x; auto r1 = std::distance(s, std::lower_bound(s, s + a, x)); decltype(r1) r2; if (r1 > 0) r2 = r1 - 1; else r2 = r1; if (r1 >= a) r1 = r2; auto l1 = std::distance(t, std::lower_bound(t, t + b, x)); decltype(l1) l2; if (l1 > 0) l2 = l1 - 1; else l2 = l1; if (l2 >= b) l1 = l2; long long ans = LLONG_MAX; long long r[] = {s[r1], s[r2]}; long long l[] = {t[l1], t[l2]}; for (int j = 0; j < 2; ++j) for (int k = 0; k < 2; ++k) { auto d1 = std::abs(r[j] - x) + std::abs(l[k] - r[j]); auto d2 = std::abs(l[k] - x) + std::abs(r[j] - l[k]); ans = std::min({ans, d1, d2}); } std::cout << ans << std::endl; } return 0; }
[ "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
924,744
924,745
u640248738
cpp
p03112
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ull, ull> pullull; typedef pair<ll, int> plli; typedef pair<int, pii> pipii; typedef vector<vector<int>> mati; typedef vector<vector<double>> matd; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<vector<vector<ll>>> vvvll; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef vector<vector<vector<bool>>> vvvb; #define FOR(i, x, y) for (ll i = (ll)x; i < (ll)y; ++i) #define REP(i, y) FOR(i, 0, y) template <typename T> void vec_print(vector<T> VEC) { REP(i, VEC.size()) { cout << VEC[i] << " "; } cout << "\n"; }; template <typename T> void mat_print(vector<vector<T>> MAT){ REP(i, MAT.size()){REP(j, MAT[i].size()){cout << MAT[i][j] << " "; } cout << "\n"; } } ; template <typename CLASS1, typename CLASS2> class HOGE { public: CLASS1 key; CLASS2 value; HOGE(void) { return; }; HOGE(CLASS1 key, CLASS2 value) { this->key = key; this->value = value; }; ~HOGE(void) { return; }; void print(void) { cout << "key : " << key << ", value : " << value << "\n"; return; }; bool operator==(const HOGE &obj) { return (this->value == obj.value); }; bool operator<(const HOGE &obj) { return (this->value < obj.value); }; bool operator>(const HOGE &obj) { return (this->value > obj.value); }; }; constexpr int INF = (1 << 30); constexpr ll INFLL = 1LL << 62; constexpr long double EPS = 1e-12; constexpr ll MOD = (ll)((1E+9) + 7); ll st_search(ll xi, vll &st, ll start, ll end) { if (end - start <= 1) { if (abs(st[start] - xi) < abs(st[end] - xi)) return start; else return end; } ll middle = (start + end) / 2; if (st[middle] < xi) return st_search(xi, st, middle, end); else return st_search(xi, st, start, middle); } int main() { cin.tie(0); // cut the cin and cout (default, std::flush is performed after // std::cin) ios::sync_with_stdio( false); // cut the iostream and stdio (DON'T endl; BUT "\n";) ll A, B, Q; cin >> A >> B >> Q; vll s(A); REP(i, A) { cin >> s[i]; } vll t(B); REP(i, B) { cin >> t[i]; } vll x(Q); REP(i, Q) { cin >> x[i]; } // 1st search, the nearest temple vll sl(A, INFLL); REP(i, A) { ll t_near = st_search(s[i], t, 0, B - 1); sl[i] = abs(s[i] - t[t_near]); } // 2nd search, vll tl(B, INFLL); REP(i, B) { ll s_near = st_search(t[i], s, 0, A - 1); tl[i] = abs(t[i] - s[s_near]); } REP(i, Q) { // nearest temple ll s_near = st_search(x[i], s, 0, A - 1); ll ans = abs(s[s_near] - x[i]) + sl[s_near]; if (s_near < A - 1) { ans = min(ans, abs(s[s_near + 1] - x[i]) + sl[s_near + 1]); } else if (s_near > 0) { ans = min(ans, abs(s[s_near - 1] - x[i]) + sl[s_near - 1]); } ll t_near = st_search(x[i], t, 0, B - 1); ans = min(ans, abs(t[t_near] - x[i]) + tl[t_near]); if (t_near < B - 1) { ans = min(ans, abs(t[t_near + 1] - x[i]) + tl[t_near + 1]); } else if (t_near > 0) { ans = min(ans, abs(t[t_near - 1] - x[i]) + tl[t_near - 1]); } cout << ans << "\n"; } return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ull, ull> pullull; typedef pair<ll, int> plli; typedef pair<int, pii> pipii; typedef vector<vector<int>> mati; typedef vector<vector<double>> matd; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<vector<vector<ll>>> vvvll; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef vector<vector<vector<bool>>> vvvb; #define FOR(i, x, y) for (ll i = (ll)x; i < (ll)y; ++i) #define REP(i, y) FOR(i, 0, y) template <typename T> void vec_print(vector<T> VEC) { REP(i, VEC.size()) { cout << VEC[i] << " "; } cout << "\n"; }; template <typename T> void mat_print(vector<vector<T>> MAT){ REP(i, MAT.size()){REP(j, MAT[i].size()){cout << MAT[i][j] << " "; } cout << "\n"; } } ; template <typename CLASS1, typename CLASS2> class HOGE { public: CLASS1 key; CLASS2 value; HOGE(void) { return; }; HOGE(CLASS1 key, CLASS2 value) { this->key = key; this->value = value; }; ~HOGE(void) { return; }; void print(void) { cout << "key : " << key << ", value : " << value << "\n"; return; }; bool operator==(const HOGE &obj) { return (this->value == obj.value); }; bool operator<(const HOGE &obj) { return (this->value < obj.value); }; bool operator>(const HOGE &obj) { return (this->value > obj.value); }; }; constexpr int INF = (1 << 30); constexpr ll INFLL = 1LL << 62; constexpr long double EPS = 1e-12; constexpr ll MOD = (ll)((1E+9) + 7); ll st_search(ll xi, vll &st, ll start, ll end) { if (end - start <= 1) { if (abs(st[start] - xi) < abs(st[end] - xi)) return start; else return end; } ll middle = (start + end) / 2; if (st[middle] < xi) return st_search(xi, st, middle, end); else return st_search(xi, st, start, middle); } int main() { cin.tie(0); // cut the cin and cout (default, std::flush is performed after // std::cin) ios::sync_with_stdio( false); // cut the iostream and stdio (DON'T endl; BUT "\n";) ll A, B, Q; cin >> A >> B >> Q; vll s(A); REP(i, A) { cin >> s[i]; } vll t(B); REP(i, B) { cin >> t[i]; } vll x(Q); REP(i, Q) { cin >> x[i]; } // 1st search, the nearest temple vll sl(A, INFLL); REP(i, A) { ll t_near = st_search(s[i], t, 0, B - 1); sl[i] = abs(s[i] - t[t_near]); } // 2nd search, vll tl(B, INFLL); REP(i, B) { ll s_near = st_search(t[i], s, 0, A - 1); tl[i] = abs(t[i] - s[s_near]); } REP(i, Q) { // nearest temple ll s_near = st_search(x[i], s, 0, A - 1); ll ans = abs(s[s_near] - x[i]) + sl[s_near]; if (s_near < A - 1) { ans = min(ans, abs(s[s_near + 1] - x[i]) + sl[s_near + 1]); } if (s_near > 0) { ans = min(ans, abs(s[s_near - 1] - x[i]) + sl[s_near - 1]); } ll t_near = st_search(x[i], t, 0, B - 1); ans = min(ans, abs(t[t_near] - x[i]) + tl[t_near]); if (t_near < B - 1) { ans = min(ans, abs(t[t_near + 1] - x[i]) + tl[t_near + 1]); } if (t_near > 0) { ans = min(ans, abs(t[t_near - 1] - x[i]) + tl[t_near - 1]); } cout << ans << "\n"; } return 0; }
[ "control_flow.branch.if.replace.add", "control_flow.branch.else_if.replace.remove" ]
924,748
924,749
u355335354
cpp
p03112
#define _CRT_SECURE_NO_WARNINGS /* include ***********************/ #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> /* define *************************/ // for #define REP(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++) #define REPS(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++) #define RREP(i, n) for (int i = (int)(n)-1; i >= 0; i--) #define RREPS(i, n) for (int i = (int)(n); i > 0; i--) #define FOR(i, s, n) \ for (int i = (int)(s), i##_len = (int)(n); i < i##_len; i++) #define RFOR(i, s, n) \ for (int i = (int)(s)-1, i##_len = (int)(n); i >= i##_len; i--) // printf #define PRINTD(d) printf("%d\n", (d)) #define PRINTL(d) printf("%lld\n", (d)) // memset #define m0(s) memset(s, 0, sizeof(s)) #define ml(s) memset(s, 63, sizeof(s)) #define fill(s, c) memset(s, c, sizeof(s)) #define INF 1e9 #define MOD 1000000007 typedef long long ll; typedef unsigned long long ull; int a, b, q; ll s[200000], t[200000]; ll x; int diff[4][2] = { {0, -1}, {-1, 0}, {1, 0}, {0, 1}, }; ll Min(ll a, ll b) { return (a) < (b) ? (a) : (b); } ll Max(ll a, ll b) { return (a) > (b) ? (a) : (b); } void Swap(int *a, int *b) { int tmp = *a; *a = *b; *b = tmp; } void hSwap(ll x[], int i, int j) { ll temp; temp = x[i]; x[i] = x[j]; x[j] = temp; } void ShowData(ll x[], int left, int right) { int i; for (i = left; i <= right; i++) printf("%lld ", x[i]); printf("\n"); } void QSort(ll x[], int left, int right, int n) { int i, j; //左端,右端 ll pivot; //軸 i = left; j = right; pivot = x[(left + right) / 2]; while (1) { if (n > 0) { // n>0なら昇順、n<=0なら降順 while ((x[i] < pivot) && (i <= right)) i++; //軸値より大きい要素 while ((pivot < x[j]) && (i <= right)) j--; //軸値より小さい要素 } else { while ((x[i] > pivot) && (i <= right)) i++; //軸値より小さい要素 while ((pivot > x[j]) && (i <= right)) j--; //軸値より大きい要素 } if (i >= j) break; hSwap(x, i, j); i++; j--; } // ShowData(x, left, right); if (left < i - 1) QSort(x, left, i - 1, n); if (j + 1 < right) QSort(x, j + 1, right, n); } int binary_search(ll ary[], ll key, int left, int right) { if (right < left) return -1; int mid = left + (right - left) / 2; if (ary[mid] > key) { if (mid - 1 < left) return mid - 1; return binary_search(ary, key, left, mid - 1); } else if (ary[mid] < key) { if (mid + 1 > right) return mid; return binary_search(ary, key, mid + 1, right); } else { return mid; } } ll absl(ll num) { if (num < 0) return -num; return num; } int main() { scanf("%d%d%d", &a, &b, &q); REP(i, a) { scanf("%lld", &s[i]); } REP(i, b) { scanf("%lld", &t[i]); } QSort(s, 0, a - 1, 1); QSort(t, 0, a - 1, 1); // ShowData(s, 0, a - 1); // ShowData(t, 0, b - 1); REP(i, q) { scanf("%lld", &x); int o = binary_search(s, x, 0, a - 1); int p = binary_search(t, x, 0, b - 1); // printf("o=%d p=%d\n", o, p); ll u[2], v[2]; u[0] = ((o == -1) ? -1e15 : s[o]); v[0] = ((p == -1) ? -1e15 : t[p]); u[1] = ((o == a - 1) ? 1e15 : s[o + 1]); v[1] = ((p == b - 1) ? 1e15 : t[p + 1]); // printf("%lld %lld %lld %lld\n", u[0], v[1], u[0], v[1]); ll ans = 1e18; REP(i, 2) { REP(j, 2) { ans = Min(ans, absl(x - u[i]) + absl(u[i] - v[j])); ans = Min(ans, absl(x - v[j]) + absl(v[j] - u[i])); } } PRINTL(ans); } }
#define _CRT_SECURE_NO_WARNINGS /* include ***********************/ #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> /* define *************************/ // for #define REP(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++) #define REPS(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++) #define RREP(i, n) for (int i = (int)(n)-1; i >= 0; i--) #define RREPS(i, n) for (int i = (int)(n); i > 0; i--) #define FOR(i, s, n) \ for (int i = (int)(s), i##_len = (int)(n); i < i##_len; i++) #define RFOR(i, s, n) \ for (int i = (int)(s)-1, i##_len = (int)(n); i >= i##_len; i--) // printf #define PRINTD(d) printf("%d\n", (d)) #define PRINTL(d) printf("%lld\n", (d)) // memset #define m0(s) memset(s, 0, sizeof(s)) #define ml(s) memset(s, 63, sizeof(s)) #define fill(s, c) memset(s, c, sizeof(s)) #define INF 1e9 #define MOD 1000000007 typedef long long ll; typedef unsigned long long ull; int a, b, q; ll s[200000], t[200000]; ll x; int diff[4][2] = { {0, -1}, {-1, 0}, {1, 0}, {0, 1}, }; ll Min(ll a, ll b) { return (a) < (b) ? (a) : (b); } ll Max(ll a, ll b) { return (a) > (b) ? (a) : (b); } void Swap(int *a, int *b) { int tmp = *a; *a = *b; *b = tmp; } void hSwap(ll x[], int i, int j) { ll temp; temp = x[i]; x[i] = x[j]; x[j] = temp; } void ShowData(ll x[], int left, int right) { int i; for (i = left; i <= right; i++) printf("%lld ", x[i]); printf("\n"); } void QSort(ll x[], int left, int right, int n) { int i, j; //左端,右端 ll pivot; //軸 i = left; j = right; pivot = x[(left + right) / 2]; while (1) { if (n > 0) { // n>0なら昇順、n<=0なら降順 while ((x[i] < pivot) && (i <= right)) i++; //軸値より大きい要素 while ((pivot < x[j]) && (i <= right)) j--; //軸値より小さい要素 } else { while ((x[i] > pivot) && (i <= right)) i++; //軸値より小さい要素 while ((pivot > x[j]) && (i <= right)) j--; //軸値より大きい要素 } if (i >= j) break; hSwap(x, i, j); i++; j--; } // ShowData(x, left, right); if (left < i - 1) QSort(x, left, i - 1, n); if (j + 1 < right) QSort(x, j + 1, right, n); } int binary_search(ll ary[], ll key, int left, int right) { if (right < left) return -1; int mid = left + (right - left) / 2; if (ary[mid] > key) { if (mid - 1 < left) return mid - 1; return binary_search(ary, key, left, mid - 1); } else if (ary[mid] < key) { if (mid + 1 > right) return mid; return binary_search(ary, key, mid + 1, right); } else { return mid; } } ll absl(ll num) { if (num < 0) return -num; return num; } int main() { scanf("%d%d%d", &a, &b, &q); REP(i, a) { scanf("%lld", &s[i]); } REP(i, b) { scanf("%lld", &t[i]); } QSort(s, 0, a - 1, 1); QSort(t, 0, b - 1, 1); // ShowData(s, 0, a - 1); // ShowData(t, 0, b - 1); REP(i, q) { scanf("%lld", &x); int o = binary_search(s, x, 0, a - 1); int p = binary_search(t, x, 0, b - 1); // printf("o=%d p=%d\n", o, p); ll u[2], v[2]; u[0] = ((o == -1) ? -1e15 : s[o]); v[0] = ((p == -1) ? -1e15 : t[p]); u[1] = ((o == a - 1) ? 1e15 : s[o + 1]); v[1] = ((p == b - 1) ? 1e15 : t[p + 1]); // printf("%lld %lld %lld %lld\n", u[0], v[1], u[0], v[1]); ll ans = 1e18; REP(i, 2) { REP(j, 2) { ans = Min(ans, absl(x - u[i]) + absl(u[i] - v[j])); ans = Min(ans, absl(x - v[j]) + absl(v[j] - u[i])); } } PRINTL(ans); } }
[ "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
924,750
924,751
u539339654
cpp
p03112
#include <algorithm> #include <cmath> #include <cstdio> #include <vector> typedef long long ll; using namespace std; int main() { int a, b, q; ll x, l[2], r[2], ans; vector<ll> s, t; scanf("%d %d %d", &a, &b, &q); s.resize(a); t.resize(b); for (int i = 0; i < a; i++) { scanf("%lld", &s[i]); } for (int i = 0; i < b; i++) { scanf("%lld", &t[i]); } for (int i = 0; i < q; i++) { scanf("%lld", &x); decltype(s)::iterator it = lower_bound(s.begin(), s.end(), x); decltype(t)::iterator it2 = lower_bound(t.begin(), t.end(), x); if (it == s.end()) { it--; l[0] = r[0] = *it; it++; } else if (it == s.begin()) { l[0] = r[0] = *it; } else { r[0] = *it; it--; l[0] = *it; } if (it2 == t.end()) { it2--; l[1] = r[1] = *it2; it2++; } else if (it2 == t.begin()) { l[1] = r[1] = *it2; } else { r[1] = *it2; it2--; l[1] = *it2; } ans = llabs(l[0] - l[1]) + min(llabs(l[0] - x), llabs(l[1] - x)); ans = min(ans, llabs(l[0] - r[1]) + min(llabs(l[0] - x), llabs(r[1] - x))); ans = min(ans, llabs(r[0] - l[1]) + min(llabs(r[0] - x), llabs(l[1] - x))); ans = min(ans, llabs(r[0] - r[1]) + min(llabs(r[0] - x), llabs(r[1] - x))); printf("%d\n", ans); } }
#include <algorithm> #include <cmath> #include <cstdio> #include <vector> typedef long long ll; using namespace std; int main() { int a, b, q; ll x, l[2], r[2], ans; vector<ll> s, t; scanf("%d %d %d", &a, &b, &q); s.resize(a); t.resize(b); for (int i = 0; i < a; i++) { scanf("%lld", &s[i]); } for (int i = 0; i < b; i++) { scanf("%lld", &t[i]); } for (int i = 0; i < q; i++) { scanf("%lld", &x); decltype(s)::iterator it = lower_bound(s.begin(), s.end(), x); decltype(t)::iterator it2 = lower_bound(t.begin(), t.end(), x); if (it == s.end()) { it--; l[0] = r[0] = *it; it++; } else if (it == s.begin()) { l[0] = r[0] = *it; } else { r[0] = *it; it--; l[0] = *it; } if (it2 == t.end()) { it2--; l[1] = r[1] = *it2; it2++; } else if (it2 == t.begin()) { l[1] = r[1] = *it2; } else { r[1] = *it2; it2--; l[1] = *it2; } ans = llabs(l[0] - l[1]) + min(llabs(l[0] - x), llabs(l[1] - x)); ans = min(ans, llabs(l[0] - r[1]) + min(llabs(l[0] - x), llabs(r[1] - x))); ans = min(ans, llabs(r[0] - l[1]) + min(llabs(r[0] - x), llabs(l[1] - x))); ans = min(ans, llabs(r[0] - r[1]) + min(llabs(r[0] - x), llabs(r[1] - x))); printf("%lld\n", ans); } }
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
924,752
924,753
u855429581
cpp
p03112
#include <algorithm> #include <iostream> #include <sstream> #include <string> using namespace std; int main() { int a, b, q; cin >> a >> b >> q; long *s = new long[100000]; long *t = new long[100000]; long *x = new long[100000]; for (int i = 0; i < a; i++) cin >> s[i]; for (int i = 0; i < b; i++) cin >> t[i]; for (int i = 0; i < q; i++) cin >> x[i]; for (int i = 0; i < q; i++) { long xi = x[i]; int sa, tb; int bb = -1, ee = a; while (ee - bb > 1) { int mid = (bb + ee) / 2; if (s[mid] < xi) { bb = mid; } else { ee = mid; } } sa = bb; bb = -1, ee = b; while (ee - bb > 1) { int mid = (bb + ee) / 2; if (t[mid] < xi) { bb = mid; } else { ee = mid; } } tb = bb; long ans = 1000000000000000000; if (sa != -1 && tb != -1) { ans = min(xi - min(s[sa], t[tb]), ans); } if (sa != -1 && tb != b - 1) { ans = min(ans, xi - s[sa] + t[tb + 1] - xi + min(xi - s[sa], t[tb + 1] - xi)); } if (sa != a - 1 && tb != -1) { ans = min(ans, xi - t[tb] + s[sa + 1] - xi + min(xi - t[tb], s[sa + 1] - xi)); } if (sa != a - 1 && tb != -1) { ans = min(ans, max(s[sa + 1], t[tb + 1]) - xi); } cout << ans << endl; } return 0; }
#include <algorithm> #include <iostream> #include <sstream> #include <string> using namespace std; int main() { int a, b, q; cin >> a >> b >> q; long *s = new long[100000]; long *t = new long[100000]; long *x = new long[100000]; for (int i = 0; i < a; i++) cin >> s[i]; for (int i = 0; i < b; i++) cin >> t[i]; for (int i = 0; i < q; i++) cin >> x[i]; for (int i = 0; i < q; i++) { long xi = x[i]; int sa, tb; int bb = -1, ee = a; while (ee - bb > 1) { int mid = (bb + ee) / 2; if (s[mid] < xi) { bb = mid; } else { ee = mid; } } sa = bb; bb = -1, ee = b; while (ee - bb > 1) { int mid = (bb + ee) / 2; if (t[mid] < xi) { bb = mid; } else { ee = mid; } } tb = bb; long ans = 1000000000000000000; if (sa != -1 && tb != -1) { ans = min(xi - min(s[sa], t[tb]), ans); } if (sa != -1 && tb != b - 1) { ans = min(ans, xi - s[sa] + t[tb + 1] - xi + min(xi - s[sa], t[tb + 1] - xi)); } if (sa != a - 1 && tb != -1) { ans = min(ans, xi - t[tb] + s[sa + 1] - xi + min(xi - t[tb], s[sa + 1] - xi)); } if (sa != a - 1 && tb != b - 1) { ans = min(ans, max(s[sa + 1], t[tb + 1]) - xi); } cout << ans << endl; } return 0; }
[ "control_flow.branch.if.condition.change" ]
924,754
924,755
u088893297
cpp
p03112
#include <algorithm> #include <iostream> #include <sstream> #include <string> using namespace std; int main() { int a, b, q; cin >> a >> b >> q; long *s = new long[100000]; long *t = new long[100000]; long *x = new long[100000]; for (int i = 0; i < a; i++) cin >> s[i]; for (int i = 0; i < b; i++) cin >> t[i]; for (int i = 0; i < q; i++) cin >> x[i]; for (int i = 0; i < q; i++) { long xi = x[i]; int sa, tb; int bb = -1, ee = a; while (ee - bb > 1) { int mid = (bb + ee) / 2; if (s[mid] < xi) { bb = mid; } else { ee = mid; } } sa = bb; bb = -1, ee = b; while (ee - bb > 1) { int mid = (bb + ee) / 2; if (t[mid] < xi) { bb = mid; } else { ee = mid; } } tb = bb; long ans = 30000000000; if (sa != -1 && tb != -1) { ans = min(xi - min(s[sa], t[tb]), ans); } if (sa != -1 && tb != b - 1) { ans = min(ans, xi - s[sa] + t[tb + 1] - xi + min(xi - s[sa], t[tb + 1] - xi)); } if (sa != a - 1 && tb != -1) { ans = min(ans, xi - t[tb] + s[sa + 1] - xi + min(xi - t[tb], s[sa + 1] - xi)); } if (sa != a - 1 && tb != -1) { ans = min(ans, max(s[sa + 1], t[tb + 1]) - xi); } cout << ans << endl; } return 0; }
#include <algorithm> #include <iostream> #include <sstream> #include <string> using namespace std; int main() { int a, b, q; cin >> a >> b >> q; long *s = new long[100000]; long *t = new long[100000]; long *x = new long[100000]; for (int i = 0; i < a; i++) cin >> s[i]; for (int i = 0; i < b; i++) cin >> t[i]; for (int i = 0; i < q; i++) cin >> x[i]; for (int i = 0; i < q; i++) { long xi = x[i]; int sa, tb; int bb = -1, ee = a; while (ee - bb > 1) { int mid = (bb + ee) / 2; if (s[mid] < xi) { bb = mid; } else { ee = mid; } } sa = bb; bb = -1, ee = b; while (ee - bb > 1) { int mid = (bb + ee) / 2; if (t[mid] < xi) { bb = mid; } else { ee = mid; } } tb = bb; long ans = 1000000000000000000; if (sa != -1 && tb != -1) { ans = min(xi - min(s[sa], t[tb]), ans); } if (sa != -1 && tb != b - 1) { ans = min(ans, xi - s[sa] + t[tb + 1] - xi + min(xi - s[sa], t[tb + 1] - xi)); } if (sa != a - 1 && tb != -1) { ans = min(ans, xi - t[tb] + s[sa + 1] - xi + min(xi - t[tb], s[sa + 1] - xi)); } if (sa != a - 1 && tb != b - 1) { ans = min(ans, max(s[sa + 1], t[tb + 1]) - xi); } cout << ans << endl; } return 0; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.branch.if.condition.change" ]
924,756
924,755
u088893297
cpp
p03112
#include <algorithm> #include <iostream> #include <sstream> #include <string> using namespace std; int main() { int a, b, q; cin >> a >> b >> q; long *s = new long[100000]; long *t = new long[100000]; long *x = new long[100000]; for (int i = 0; i < a; i++) cin >> s[i]; for (int i = 0; i < b; i++) cin >> t[i]; for (int i = 0; i < q; i++) cin >> x[i]; for (int i = 0; i < q; i++) { long xi = x[i]; int sa, tb; int bb = -1, ee = a; while (ee - bb > 1) { int mid = (bb + ee) / 2; if (s[mid] < xi) { bb = mid; } else { ee = mid; } } sa = bb; bb = -1, ee = b; while (ee - bb > 1) { int mid = (bb + ee) / 2; if (t[mid] < xi) { bb = mid; } else { ee = mid; } } tb = bb; long ans = 10000000000; if (sa != -1 && tb != -1) { ans = min(xi - min(s[sa], t[tb]), ans); } if (sa != -1 && tb != b - 1) { ans = min(ans, xi - s[sa] + t[tb + 1] - xi + min(xi - s[sa], t[tb + 1] - xi)); } if (sa != a - 1 && tb != -1) { ans = min(ans, xi - t[tb] + s[sa + 1] - xi + min(xi - t[tb], s[sa + 1] - xi)); } if (sa != a - 1 && tb != -1) { ans = min(ans, max(s[sa + 1], t[tb + 1]) - xi); } cout << ans << endl; } return 0; }
#include <algorithm> #include <iostream> #include <sstream> #include <string> using namespace std; int main() { int a, b, q; cin >> a >> b >> q; long *s = new long[100000]; long *t = new long[100000]; long *x = new long[100000]; for (int i = 0; i < a; i++) cin >> s[i]; for (int i = 0; i < b; i++) cin >> t[i]; for (int i = 0; i < q; i++) cin >> x[i]; for (int i = 0; i < q; i++) { long xi = x[i]; int sa, tb; int bb = -1, ee = a; while (ee - bb > 1) { int mid = (bb + ee) / 2; if (s[mid] < xi) { bb = mid; } else { ee = mid; } } sa = bb; bb = -1, ee = b; while (ee - bb > 1) { int mid = (bb + ee) / 2; if (t[mid] < xi) { bb = mid; } else { ee = mid; } } tb = bb; long ans = 1000000000000000000; if (sa != -1 && tb != -1) { ans = min(xi - min(s[sa], t[tb]), ans); } if (sa != -1 && tb != b - 1) { ans = min(ans, xi - s[sa] + t[tb + 1] - xi + min(xi - s[sa], t[tb + 1] - xi)); } if (sa != a - 1 && tb != -1) { ans = min(ans, xi - t[tb] + s[sa + 1] - xi + min(xi - t[tb], s[sa + 1] - xi)); } if (sa != a - 1 && tb != b - 1) { ans = min(ans, max(s[sa + 1], t[tb + 1]) - xi); } cout << ans << endl; } return 0; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.branch.if.condition.change" ]
924,757
924,755
u088893297
cpp
p03112
#include <bits/stdc++.h> #define f(i, n) for (int i = 0; i < n; i++) #define F first #define S second #define mod 1000000007 #define P pair<int, int> #define int long long using namespace std; long long x[100000], y[100000], z[100000], vx[2], vy[2]; signed main() { long long a, b, c; cin >> a >> b >> c; f(i, a) cin >> x[i]; f(i, b) cin >> y[i]; f(i, c) { cin >> z[i]; long long ans = LLONG_MAX / 3; f(j, 2) { vx[j] = x[max((int)(0), min((long long)(lower_bound(x, x + a, z[i]) - x - j), a - 1))]; f(k, 2) { vy[k] = y[max( (int)(0), min((long long)(lower_bound(y, y + b, z[i]) - y - k), a - 1))]; ans = min(ans, min(abs(z[i] - vx[j]), abs(z[i] - vy[k])) + abs(vx[j] - vy[k])); } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #define f(i, n) for (int i = 0; i < n; i++) #define F first #define S second #define mod 1000000007 #define P pair<int, int> #define int long long using namespace std; long long x[100000], y[100000], z[100000], vx[2], vy[2]; signed main() { long long a, b, c; cin >> a >> b >> c; f(i, a) cin >> x[i]; f(i, b) cin >> y[i]; f(i, c) { cin >> z[i]; long long ans = LLONG_MAX / 3; f(j, 2) { vx[j] = x[max((int)(0), min((long long)(lower_bound(x, x + a, z[i]) - x - j), a - 1))]; f(k, 2) { vy[k] = y[max( (int)(0), min((long long)(lower_bound(y, y + b, z[i]) - y - k), b - 1))]; ans = min(ans, min(abs(z[i] - vx[j]), abs(z[i] - vy[k])) + abs(vx[j] - vy[k])); } } cout << ans << endl; } return 0; }
[ "assignment.value.change", "identifier.change", "variable_access.subscript.index.change", "call.arguments.change", "expression.operation.binary.change" ]
924,758
924,759
u259210975
cpp
p03112
#include <algorithm> #include <assert.h> #include <complex> #include <ctime> #include <iostream> #include <list> #include <map> #include <math.h> #include <memory.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int INF = 1e9 + 1; const ll LLINF = 1e18 + 1; int main() { int A, B, Q; cin >> A >> B >> Q; vector<ll> s(A, 0), t(B, 0); for (int i = 0; i < A; i++) cin >> s[i]; for (int i = 0; i < B; i++) cin >> t[i]; sort(s.begin(), s.end()); sort(t.begin(), t.end()); for (int i = 0; i < Q; i++) { ll x; cin >> x; ll ans = LLINF; int sp = lower_bound(s.begin(), s.end(), x) - s.begin(); int tp = lower_bound(t.begin(), t.end(), x) - t.begin(); vector<int> S, T; if (sp < A) S.push_back(sp); if (tp < B) T.push_back(tp); if (sp > 0) S.push_back(sp - 1); if (tp > 0) T.push_back(tp - 1); for (auto ss : S) { tp = lower_bound(t.begin(), t.end(), s[ss]) - t.begin(); if (tp < B) T.push_back(tp); if (tp > 0) T.push_back(sp); } for (auto tt : T) { sp = lower_bound(s.begin(), s.end(), t[tt]) - s.begin(); if (sp < A) S.push_back(sp); if (sp > 0) S.push_back(sp - 1); } for (auto ss : S) for (auto tt : T) { ans = min(ans, abs(x - s[ss]) + abs(s[ss] - t[tt])); } for (auto tt : T) for (auto ss : S) { ans = min(ans, abs(x - t[tt]) + abs(t[tt] - s[ss])); } cout << ans << endl; } return 0; }
#include <algorithm> #include <assert.h> #include <complex> #include <ctime> #include <iostream> #include <list> #include <map> #include <math.h> #include <memory.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int INF = 1e9 + 1; const ll LLINF = 1e18 + 1; int main() { int A, B, Q; cin >> A >> B >> Q; vector<ll> s(A, 0), t(B, 0); for (int i = 0; i < A; i++) cin >> s[i]; for (int i = 0; i < B; i++) cin >> t[i]; sort(s.begin(), s.end()); sort(t.begin(), t.end()); for (int i = 0; i < Q; i++) { ll x; cin >> x; ll ans = LLINF; int sp = lower_bound(s.begin(), s.end(), x) - s.begin(); int tp = lower_bound(t.begin(), t.end(), x) - t.begin(); vector<int> S, T; if (sp < A) S.push_back(sp); if (tp < B) T.push_back(tp); if (sp > 0) S.push_back(sp - 1); if (tp > 0) T.push_back(tp - 1); for (auto ss : S) { tp = lower_bound(t.begin(), t.end(), s[ss]) - t.begin(); if (tp < B) T.push_back(tp); if (tp > 0) T.push_back(tp - 1); } for (auto tt : T) { sp = lower_bound(s.begin(), s.end(), t[tt]) - s.begin(); if (sp < A) S.push_back(sp); if (sp > 0) S.push_back(sp - 1); } for (auto ss : S) for (auto tt : T) { ans = min(ans, abs(x - s[ss]) + abs(s[ss] - t[tt])); } for (auto tt : T) for (auto ss : S) { ans = min(ans, abs(x - t[tt]) + abs(t[tt] - s[ss])); } cout << ans << endl; } return 0; }
[ "call.arguments.change" ]
924,776
924,777
u262288723
cpp
p03112
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <random> #include <string> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; const int maxn = 100005; int n, m, q; ll a[maxn], b[maxn]; void pd(ll &ret, ll val) { if (ret == -1 || ret > val) ret = val; } int bs(ll a[], int n, ll val) { int l = 0, r = n - 1, ret = -1; while (l <= r) { int m = (l + r) >> 1; if (a[m] >= val) { ret = m; r = m - 1; } else l = m + 1; } return ret; } int main() { #ifdef suiyuan2009 freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin); // freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "w", stdout); #endif cin >> n >> m >> q; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; while (q--) { ll x; cin >> x; ll ret = -1; int pa = bs(a, n, x); int pb = bs(b, m, x); int la = -1; if (pa == -1) la = n - 1; else la = pa - 1; int lb = -1; if (pb == -1) lb = n - 1; else lb = pb - 1; vector<int> va = {pa, la}; vector<int> vb = {pb, lb}; for (int aa : va) for (int bb : vb) { if (aa == -1 || bb == -1) continue; ll tmp = abs(a[aa] - b[bb]) + min(abs(x - a[aa]), abs(x - b[bb])); pd(ret, tmp); } cout << ret << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <random> #include <string> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; const int maxn = 100005; int n, m, q; ll a[maxn], b[maxn]; void pd(ll &ret, ll val) { if (ret == -1L || ret > val) ret = val; } int bs(ll a[], int n, ll val) { int l = 0, r = n - 1, ret = -1; while (l <= r) { int m = (l + r) >> 1; if (a[m] >= val) { ret = m; r = m - 1; } else l = m + 1; } return ret; } int main() { #ifdef suiyuan2009 freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin); // freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "w", stdout); #endif cin >> n >> m >> q; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; while (q--) { ll x; cin >> x; ll ret = -1; int pa = bs(a, n, x); int pb = bs(b, m, x); int la = -1; if (pa == -1) la = n - 1; else la = pa - 1; int lb = -1; if (pb == -1) lb = m - 1; else lb = pb - 1; vector<int> va = {pa, la}; vector<int> vb = {pb, lb}; for (int aa : va) for (int bb : vb) { if (aa == -1 || bb == -1) continue; ll tmp = abs(a[aa] - b[bb]) + min(abs(x - a[aa]), abs(x - b[bb])); pd(ret, tmp); } cout << ret << endl; } return 0; }
[ "control_flow.branch.if.condition.change", "assignment.value.change", "identifier.change", "expression.operation.binary.change" ]
924,803
924,804
u541410431
cpp
p03112
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const int mod = 1e9 + 7; #define rep(i, a, n) for (int i = a; i < n; i++) #define per(i, a, n) for (int i = n - 1; i >= a; i--) #define pb push_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; ll qpow(ll a, ll b) { ll ans = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) ans = ans * a % mod; a = a * a % mod; } return ans; } ll gcd(ll a, ll b) { return b > 0 ? gcd(b, a % b) : a; } ll a[maxn]; ll b[maxn]; ll cal(ll x, ll y, ll t) { if (x > y) swap(x, y); // x<=y if (t <= x) return y - t; else if (t >= y) return t - x; else { return y - x + min(abs(t - x), abs(t - y)); } } int main() { ll qq, n, m, T, x; ll la, ra, lb, rb; int l, r, L, R; cin >> n >> m >> qq; rep(i, 0, n) cin >> a[i]; rep(i, 0, m) cin >> b[i]; sort(a, a + n); sort(b, b + n); ll ans; while (qq--) { // cout<<qq<<endl; ans = 1e18; cin >> x; r = lower_bound(a, a + n, x) - a; R = lower_bound(b, b + m, x) - b; l = max(0, r - 1); L = max(0, R - 1); ans = min(ans, cal(a[l], b[L], x)); ans = min(ans, cal(a[l], b[R], x)); ans = min(ans, cal(a[r], b[L], x)); ans = min(ans, cal(a[r], b[R], x)); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const int mod = 1e9 + 7; #define rep(i, a, n) for (int i = a; i < n; i++) #define per(i, a, n) for (int i = n - 1; i >= a; i--) #define pb push_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; ll qpow(ll a, ll b) { ll ans = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) ans = ans * a % mod; a = a * a % mod; } return ans; } ll gcd(ll a, ll b) { return b > 0 ? gcd(b, a % b) : a; } ll a[maxn]; ll b[maxn]; ll cal(ll x, ll y, ll t) { if (x > y) swap(x, y); // x<=y if (t <= x) return y - t; else if (t >= y) return t - x; else { return y - x + min(abs(t - x), abs(t - y)); } } int main() { ll qq, n, m, T, x; ll la, ra, lb, rb; int l, r, L, R; cin >> n >> m >> qq; rep(i, 0, n) cin >> a[i]; rep(i, 0, m) cin >> b[i]; sort(a, a + n); sort(b, b + m); ll ans; while (qq--) { // cout<<qq<<endl; ans = 1e18; cin >> x; r = lower_bound(a, a + n, x) - a; R = lower_bound(b, b + m, x) - b; l = max(0, r - 1); L = max(0, R - 1); ans = min(ans, cal(a[l], b[L], x)); ans = min(ans, cal(a[l], b[R], x)); ans = min(ans, cal(a[r], b[L], x)); ans = min(ans, cal(a[r], b[R], x)); cout << ans << endl; } return 0; }
[ "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
924,818
924,819
u384743704
cpp
p03112
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define ll long long int #define LLINF 10000000000 using namespace std; // 自作した二分探索 int my_binary_search(ll *data, int size, ll key) { int ng = -1; int ok = size; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (data[mid] < key) { ng = mid; } else { ok = mid; } } return ok; } int main() { int a, b, q; cin >> a >> b >> q; ll s[100002], t[100002]; ll result[100000]; s[0] = -LLINF; s[a + 1] = LLINF; t[0] = -LLINF; t[b + 1] = LLINF; for (int i = 1; i <= a; i++) { cin >> s[i]; } for (int i = 1; i <= b; i++) { cin >> t[i]; } ll x = 0; REP(k, q) { cin >> x; int u[2], v[2]; u[1] = my_binary_search(s, a + 2, x); u[0] = u[1] - 1; v[1] = my_binary_search(t, b + 2, x); v[0] = v[1] - 1; result[k] = LLINF; REP(i, 2) { REP(j, 2) { ll d = min(abs(x - s[u[i]]) + abs(s[u[i]] - t[v[j]]), abs(x - t[v[j]]) + abs(t[v[j]] - s[u[i]])); if (d < result[k]) { result[k] = d; } } } } REP(i, q) { cout << result[i] << endl; } }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define ll long long int #define LLINF 1000000000000000000 using namespace std; // 自作した二分探索 int my_binary_search(ll *data, int size, ll key) { int ng = -1; int ok = size; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (data[mid] < key) { ng = mid; } else { ok = mid; } } return ok; } int main() { int a, b, q; cin >> a >> b >> q; ll s[100002], t[100002]; ll result[100000]; s[0] = -LLINF; s[a + 1] = LLINF; t[0] = -LLINF; t[b + 1] = LLINF; for (int i = 1; i <= a; i++) { cin >> s[i]; } for (int i = 1; i <= b; i++) { cin >> t[i]; } ll x = 0; REP(k, q) { cin >> x; int u[2], v[2]; u[1] = my_binary_search(s, a + 2, x); u[0] = u[1] - 1; v[1] = my_binary_search(t, b + 2, x); v[0] = v[1] - 1; result[k] = LLINF; REP(i, 2) { REP(j, 2) { ll d = min(abs(x - s[u[i]]) + abs(s[u[i]] - t[v[j]]), abs(x - t[v[j]]) + abs(t[v[j]] - s[u[i]])); if (d < result[k]) { result[k] = d; } } } } REP(i, q) { cout << result[i] << endl; } }
[ "preprocessor.define.value.change", "literal.integer.change" ]
924,820
924,821
u620059302
cpp
p03112
#include <bits/stdc++.h> using namespace std; using ll = long long; ll a, b, q; int main() { cin >> a >> b >> q; vector<ll> s(a), t(b); for (int i = 0; i < a; i++) { cin >> s[i]; } for (int i = 0; i < b; i++) { cin >> t[i]; } for (int i = 0; i < q; i++) { ll x; cin >> x; vector<ll> ans; // x以上となる最小のindexを取得 auto s_ind = distance(s.begin(), lower_bound(s.begin(), s.end(), x)); auto t_ind = distance(t.begin(), lower_bound(t.begin(), t.end(), x)); if (s_ind != 0 && t_ind != 0) { ans.push_back(x - min(s[s_ind - 1], t[t_ind - 1])); } if (s_ind != a && t_ind != b) { ans.push_back(max(s[s_ind], t[t_ind])); } if (s_ind != a && t_ind != 0) { ans.push_back(2 * abs(s[s_ind] - x) + abs(t[t_ind - 1] - x)); ans.push_back(abs(s[s_ind] - x) + 2 * abs(t[t_ind - 1] - x)); } if (s_ind != 0 && t_ind != b) { ans.push_back(2 * abs(s[s_ind - 1] - x) + abs(t[t_ind] - x)); ans.push_back(abs(s[s_ind - 1] - x) + 2 * abs(t[t_ind] - x)); } sort(ans.begin(), ans.end()); cout << ans[0] << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; ll a, b, q; int main() { cin >> a >> b >> q; vector<ll> s(a), t(b); for (int i = 0; i < a; i++) { cin >> s[i]; } for (int i = 0; i < b; i++) { cin >> t[i]; } for (int i = 0; i < q; i++) { ll x; cin >> x; vector<ll> ans; // x以上となる最小のindexを取得 auto s_ind = distance(s.begin(), lower_bound(s.begin(), s.end(), x)); auto t_ind = distance(t.begin(), lower_bound(t.begin(), t.end(), x)); if (s_ind != 0 && t_ind != 0) { ans.push_back(x - min(s[s_ind - 1], t[t_ind - 1])); } if (s_ind != a && t_ind != b) { ans.push_back(max(s[s_ind], t[t_ind]) - x); } if (s_ind != a && t_ind != 0) { ans.push_back(2 * abs(s[s_ind] - x) + abs(t[t_ind - 1] - x)); ans.push_back(abs(s[s_ind] - x) + 2 * abs(t[t_ind - 1] - x)); } if (s_ind != 0 && t_ind != b) { ans.push_back(2 * abs(s[s_ind - 1] - x) + abs(t[t_ind] - x)); ans.push_back(abs(s[s_ind - 1] - x) + 2 * abs(t[t_ind] - x)); } sort(ans.begin(), ans.end()); cout << ans[0] << endl; } }
[ "expression.operation.binary.add" ]
924,832
924,833
u394482932
cpp
p03112
#include <algorithm> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <queue> #include <stack> #include <utility> #include <vector> using std::cin; using std::cout; using std::endl; int main(void) { cout << std::fixed << std::setprecision(10); cin.tie(0); std::ios::sync_with_stdio(false); int a, b, q; cin >> a >> b >> q; std::vector<int64_t> s, t; for (int i = 0; i < a; i++) { int m1; cin >> m1; s.push_back(m1); } for (int i = 0; i < b; i++) { int m1; cin >> m1; t.push_back(m1); } std::sort(s.begin(), s.end()); std::sort(t.begin(), t.end()); for (int i = 0; i < q; i++) { int64_t query; cin >> query; auto isr = std::lower_bound(s.begin(), s.end(), query); auto isl = s.end(); if (isr != s.begin()) { isl = isr; isl--; } auto itr = std::lower_bound(t.begin(), t.end(), query); auto itl = t.end(); if (itr != t.begin()) { itl = itr; itl--; } // cout << *isl << "\t" << *isr << "\t" << *itl << "\t" << *itr << endl; int64_t result = INT64_MAX; if (isl != s.end() && itl != t.end()) { int64_t temp = query - std::min(*isl, *itl); result = std::min(result, temp); } if (isr != s.end() && itr != t.end()) { int64_t temp = std::max(*isr, *itr) - query; result = std::min(result, temp); } if (isl != s.end() && itr != t.end()) { int64_t temp1 = query - *isl + *itr - *isl; int64_t temp2 = *itr - query + *itr - *isl; result = std::min({result, temp1, temp2}); } if (isr != s.end() && itl != t.end()) { int64_t temp1 = *isr - query + *isr - *itl; int64_t temp2 = query - *itl + *isr - *itl; result = std::min({result, temp1, temp2}); } cout << result << endl; } return 0; }
#include <algorithm> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <queue> #include <stack> #include <utility> #include <vector> using std::cin; using std::cout; using std::endl; int main(void) { cout << std::fixed << std::setprecision(10); cin.tie(0); std::ios::sync_with_stdio(false); int a, b, q; cin >> a >> b >> q; std::vector<int64_t> s, t; for (int i = 0; i < a; i++) { int64_t m1; cin >> m1; s.push_back(m1); } for (int i = 0; i < b; i++) { int64_t m1; cin >> m1; t.push_back(m1); } std::sort(s.begin(), s.end()); std::sort(t.begin(), t.end()); for (int i = 0; i < q; i++) { int64_t query; cin >> query; auto isr = std::lower_bound(s.begin(), s.end(), query); auto isl = s.end(); if (isr != s.begin()) { isl = isr; isl--; } auto itr = std::lower_bound(t.begin(), t.end(), query); auto itl = t.end(); if (itr != t.begin()) { itl = itr; itl--; } // cout << *isl << "\t" << *isr << "\t" << *itl << "\t" << *itr << endl; int64_t result = INT64_MAX; if (isl != s.end() && itl != t.end()) { int64_t temp = query - std::min(*isl, *itl); result = std::min(result, temp); } if (isr != s.end() && itr != t.end()) { int64_t temp = std::max(*isr, *itr) - query; result = std::min(result, temp); } if (isl != s.end() && itr != t.end()) { int64_t temp1 = query - *isl + *itr - *isl; int64_t temp2 = *itr - query + *itr - *isl; result = std::min({result, temp1, temp2}); } if (isr != s.end() && itl != t.end()) { int64_t temp1 = *isr - query + *isr - *itl; int64_t temp2 = query - *itl + *isr - *itl; result = std::min({result, temp1, temp2}); } cout << result << endl; } return 0; }
[ "variable_declaration.type.primitive.change" ]
924,834
924,835
u844133200
cpp
p03112
#include <bits/stdc++.h> #define int long long #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) #define INF LLONG_MAX #define eps LDBL_EPSILON #define moder 1000000007 #define pie 3.141592653589793238462643383279 #define P std::pair<int, int> #define prique priority_queue using namespace std; int a, b, q, s[100010], t[100010]; signed main() { cin >> a >> b >> q; rep(i, a) cin >> s[i]; rep(i, b) cin >> t[i]; sort(s, s + a); sort(t, t + b); rep(i, q) { int x; cin >> x; int ans = INF; int c[4] = {-1, -1, -1, -1}; if (lower_bound(s, s + a, x) < s + a) c[0] = *lower_bound(s, s + a, x); if (s <= lower_bound(s, s + a, x) - 1) c[1] = *(lower_bound(s, s + a, x) - 1); if (lower_bound(t, t + b, x) < t + b) c[2] = *lower_bound(t, t + b, x); if (t <= lower_bound(t, t + b, x) - 1) c[3] = *(lower_bound(t, t + b, x) - 1); if (c[1] >= 0 && c[2] >= 0) ans = min(ans, c[2] - c[1] + min(abs(x - c[2]), abs(x - c[1]))); if (c[0] >= 0 && c[3] >= 0) ans = min(ans, c[0] - c[3] + min(abs(x - c[0]), abs(x - c[3]))); if (c[0] >= 0 && t <= lower_bound(t, t + b, c[0]) && lower_bound(t, t + b, c[0]) < t + b) ans = min(ans, *lower_bound(t, t + b, c[0]) - x); if (c[1] >= 0 && t <= lower_bound(t, t + b, c[1]) - 1 && lower_bound(t, t + b, c[1]) - 1 < t + b) ans = min(ans, x - *(lower_bound(t, t + b, c[1]) - 1)); if (c[2] >= 0 && s <= lower_bound(s, s + a, c[2]) && lower_bound(s, s + a, c[2]) < s + a) ans = min(ans, *lower_bound(s, s + a, c[2]) - x); if (c[3] >= 0 && s < lower_bound(s, s + a, c[3]) - 1 && lower_bound(s, s + a, c[3]) - 1 <= s + a) ans = min(ans, x - *(lower_bound(s, s + a, c[3]) - 1)); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #define int long long #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) #define INF LLONG_MAX #define eps LDBL_EPSILON #define moder 1000000007 #define pie 3.141592653589793238462643383279 #define P std::pair<int, int> #define prique priority_queue using namespace std; int a, b, q, s[100010], t[100010]; signed main() { cin >> a >> b >> q; rep(i, a) cin >> s[i]; rep(i, b) cin >> t[i]; sort(s, s + a); sort(t, t + b); rep(i, q) { int x; cin >> x; int ans = INF; int c[4] = {-1, -1, -1, -1}; if (lower_bound(s, s + a, x) < s + a) c[0] = *lower_bound(s, s + a, x); if (s <= lower_bound(s, s + a, x) - 1) c[1] = *(lower_bound(s, s + a, x) - 1); if (lower_bound(t, t + b, x) < t + b) c[2] = *lower_bound(t, t + b, x); if (t <= lower_bound(t, t + b, x) - 1) c[3] = *(lower_bound(t, t + b, x) - 1); if (c[1] >= 0 && c[2] >= 0) ans = min(ans, c[2] - c[1] + min(abs(x - c[2]), abs(x - c[1]))); if (c[0] >= 0 && c[3] >= 0) ans = min(ans, c[0] - c[3] + min(abs(x - c[0]), abs(x - c[3]))); if (c[0] >= 0 && t <= lower_bound(t, t + b, c[0]) && lower_bound(t, t + b, c[0]) < t + b) ans = min(ans, *lower_bound(t, t + b, c[0]) - x); if (c[1] >= 0 && t <= upper_bound(t, t + b, c[1]) - 1 && lower_bound(t, t + b, c[1]) - 1 < t + b) ans = min(ans, x - *(upper_bound(t, t + b, c[1]) - 1)); if (c[2] >= 0 && s <= lower_bound(s, s + a, c[2]) && lower_bound(s, s + a, c[2]) < s + a) ans = min(ans, *lower_bound(s, s + a, c[2]) - x); if (c[3] >= 0 && s <= upper_bound(s, s + a, c[3]) - 1 && lower_bound(s, s + a, c[3]) - 1 <= s + a) ans = min(ans, x - *(upper_bound(s, s + a, c[3]) - 1)); cout << ans << endl; } return 0; }
[ "identifier.change", "call.function.change", "control_flow.branch.if.condition.change", "assignment.value.change", "call.arguments.change", "expression.operation.binary.change" ]
924,836
924,837
u379822620
cpp
p03112
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; typedef pair<int, int> P; const int INF = 0x3f3f3f3f; const int MAXN = 200000; int N, M; struct Edge { int to; int weight; int next; }; vector<Edge> edges(MAXN); vector<int> head(MAXN, -1); vector<int> matchingx(MAXN, -1); vector<int> matchingy(MAXN, -1); vector<bool> check(MAXN); vector<int> dis(MAXN); vector<bool> vis(MAXN, false); int cnt = 1; void addEdge(int from, int to, int weight) { edges[cnt].to = to; edges[cnt].weight = weight; edges[cnt].next = head[from]; head[from] = cnt++; } bool dfs(int u) { for (int i = head[u]; i != -1; i = edges[i].next) { int v = edges[i].to; if (!check[v]) { check[v] = true; if (matchingy[v] == -1 || dfs(matchingy[v])) { matchingy[v] = u; matchingx[u] = v; return true; } } } return false; } int hungarian() { int ans = 0; fill(matchingx.begin(), matchingx.end(), -1); fill(matchingy.begin(), matchingy.end(), -1); for (int u = 1; u <= N; ++u) { // if (matchingx[u] == -1) { { fill(check.begin(), check.end(), false); if (dfs(u)) { ++ans; } } } return ans; } void dijkstra(int s) { priority_queue<P, vector<P>, greater<>> que; fill(dis.begin(), dis.end(), INF); dis[s] = 0; que.push(P(0, s)); while (!que.empty()) { P p = que.top(); que.pop(); int u = p.second; if (vis[u]) continue; vis[u] = true; for (int i = head[u]; i != -1; i = edges[i].next) { int v = edges[i].to; if (dis[v] > dis[u] + edges[i].weight && !vis[v]) { dis[v] = dis[u] + edges[i].weight; que.push(P(dis[v], v)); } } } } struct TreeNode { int val; TreeNode *left = nullptr; TreeNode *right = nullptr; TreeNode(int val_) : val(val_) {} }; int main() { ll A, B, Q; cin >> A >> B >> Q; vll numsA(A); vll numsB(B); for (int i = 0; i < A; ++i) { cin >> numsA[i]; } numsA.push_back(-1); numsA.push_back(100000000000LL); for (int i = 0; i < B; ++i) { cin >> numsB[i]; } numsB.push_back(-1); numsB.push_back(100000000000LL); sort(numsA.begin(), numsA.end()); sort(numsB.begin(), numsB.end()); ll x; for (int i = 0; i < Q; ++i) { cin >> x; auto uba = upper_bound(numsA.begin(), numsA.end(), x); auto ubb = upper_bound(numsB.begin(), numsB.end(), x); auto lba = uba - 1; auto lbb = ubb - 1; vll tmpA = {*lba, *uba}; vll tmpB = {*lbb, *ubb}; ll ans = 0; ans = tmpA[1] - tmpB[0] + min(tmpA[1] - x, x - tmpB[0]); ans = min(ans, tmpB[1] - tmpA[0] + min(tmpB[1] - x, x - tmpA[0])); ans = min(ans, x - min(tmpA[0], tmpB[0])); ans = min(ans, max(tmpA[1], tmpB[1]) - x); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; typedef pair<int, int> P; const int INF = 0x3f3f3f3f; const int MAXN = 200000; int N, M; struct Edge { int to; int weight; int next; }; vector<Edge> edges(MAXN); vector<int> head(MAXN, -1); vector<int> matchingx(MAXN, -1); vector<int> matchingy(MAXN, -1); vector<bool> check(MAXN); vector<int> dis(MAXN); vector<bool> vis(MAXN, false); int cnt = 1; void addEdge(int from, int to, int weight) { edges[cnt].to = to; edges[cnt].weight = weight; edges[cnt].next = head[from]; head[from] = cnt++; } bool dfs(int u) { for (int i = head[u]; i != -1; i = edges[i].next) { int v = edges[i].to; if (!check[v]) { check[v] = true; if (matchingy[v] == -1 || dfs(matchingy[v])) { matchingy[v] = u; matchingx[u] = v; return true; } } } return false; } int hungarian() { int ans = 0; fill(matchingx.begin(), matchingx.end(), -1); fill(matchingy.begin(), matchingy.end(), -1); for (int u = 1; u <= N; ++u) { // if (matchingx[u] == -1) { { fill(check.begin(), check.end(), false); if (dfs(u)) { ++ans; } } } return ans; } void dijkstra(int s) { priority_queue<P, vector<P>, greater<>> que; fill(dis.begin(), dis.end(), INF); dis[s] = 0; que.push(P(0, s)); while (!que.empty()) { P p = que.top(); que.pop(); int u = p.second; if (vis[u]) continue; vis[u] = true; for (int i = head[u]; i != -1; i = edges[i].next) { int v = edges[i].to; if (dis[v] > dis[u] + edges[i].weight && !vis[v]) { dis[v] = dis[u] + edges[i].weight; que.push(P(dis[v], v)); } } } } struct TreeNode { int val; TreeNode *left = nullptr; TreeNode *right = nullptr; TreeNode(int val_) : val(val_) {} }; int main() { ll A, B, Q; cin >> A >> B >> Q; vll numsA(A); vll numsB(B); for (int i = 0; i < A; ++i) { cin >> numsA[i]; } numsA.push_back(-100000000000LL); numsA.push_back(100000000000LL); for (int i = 0; i < B; ++i) { cin >> numsB[i]; } numsB.push_back(-100000000000LL); numsB.push_back(100000000000LL); sort(numsA.begin(), numsA.end()); sort(numsB.begin(), numsB.end()); ll x; for (int i = 0; i < Q; ++i) { cin >> x; auto uba = upper_bound(numsA.begin(), numsA.end(), x); auto ubb = upper_bound(numsB.begin(), numsB.end(), x); auto lba = uba - 1; auto lbb = ubb - 1; vll tmpA = {*lba, *uba}; vll tmpB = {*lbb, *ubb}; ll ans = 0; ans = tmpA[1] - tmpB[0] + min(tmpA[1] - x, x - tmpB[0]); ans = min(ans, tmpB[1] - tmpA[0] + min(tmpB[1] - x, x - tmpA[0])); ans = min(ans, x - min(tmpA[0], tmpB[0])); ans = min(ans, max(tmpA[1], tmpB[1]) - x); cout << ans << endl; } return 0; }
[ "literal.number.change", "call.arguments.change", "literal.number.type.widen.change" ]
924,838
924,839
u666721654
cpp
p03112
#include <bits/stdc++.h> using namespace std; #define ll long long vector<ll> sh, tem; int a, b, q; ll get_near(ll x, vector<ll> &tem) { auto nt = lower_bound(tem.begin(), tem.end(), x); ll ret = INT_MAX; if (nt != tem.end()) { ret = *nt - x; } if (nt != tem.begin()) { nt--; ret = min(ret, x - *nt); } return ret; } int main() { cin >> a >> b >> q; for (int i = 1; i <= a; ++i) { ll loc; cin >> loc; sh.push_back(loc); } for (int i = 1; i <= b; ++i) { ll loc; cin >> loc; tem.push_back(loc); } while (q--) { ll x; cin >> x; auto ptr = lower_bound(sh.begin(), sh.end(), x); ll out = LONG_LONG_MAX; if (ptr != sh.end()) { ll t1 = *ptr - x; t1 += get_near(*ptr, tem); out = min(out, t1); } if (ptr != sh.begin()) { ptr--; ll t1 = x - *ptr; t1 += get_near(*ptr, tem); out = min(out, t1); } ptr = lower_bound(tem.begin(), tem.end(), x); if (ptr != tem.end()) { ll t1 = *ptr - x; t1 += get_near(*ptr, sh); out = min(out, t1); } if (ptr != tem.begin()) { ptr--; ll t1 = x - *ptr; t1 += get_near(*ptr, sh); out = min(out, t1); } cout << out << endl; } }
#include <bits/stdc++.h> using namespace std; #define ll long long vector<ll> sh, tem; int a, b, q; ll get_near(ll x, vector<ll> &tem) { auto nt = lower_bound(tem.begin(), tem.end(), x); ll ret = LONG_LONG_MAX; if (nt != tem.end()) { ret = *nt - x; } if (nt != tem.begin()) { nt--; ret = min(ret, x - *nt); } return ret; } int main() { cin >> a >> b >> q; for (int i = 1; i <= a; ++i) { ll loc; cin >> loc; sh.push_back(loc); } for (int i = 1; i <= b; ++i) { ll loc; cin >> loc; tem.push_back(loc); } while (q--) { ll x; cin >> x; auto ptr = lower_bound(sh.begin(), sh.end(), x); ll out = LONG_LONG_MAX; if (ptr != sh.end()) { ll t1 = *ptr - x; t1 += get_near(*ptr, tem); out = min(out, t1); } if (ptr != sh.begin()) { ptr--; ll t1 = x - *ptr; t1 += get_near(*ptr, tem); out = min(out, t1); } ptr = lower_bound(tem.begin(), tem.end(), x); if (ptr != tem.end()) { ll t1 = *ptr - x; t1 += get_near(*ptr, sh); out = min(out, t1); } if (ptr != tem.begin()) { ptr--; ll t1 = x - *ptr; t1 += get_near(*ptr, sh); out = min(out, t1); } cout << out << endl; } }
[ "variable_declaration.value.change", "identifier.change" ]
924,843
924,844
u914762730
cpp
p03112
// includes #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdint> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> // macros #define ll long long int #define pb emplace_back #define mk make_pair #define pq priority_queue #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) using namespace std; // types typedef pair<int, int> P; typedef pair<ll, int> Pl; typedef pair<ll, ll> Pll; typedef pair<double, double> Pd; // constants const int inf = 1e9; const ll linf = 1LL << 50; const double EPS = 1e-10; const int mod = 1e9 + 7; // solve 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 (a > b) { a = b; return 1; } return 0; } bool comp(const Pl &a, const Pl &b) { return a.first < b.first; } int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(false); cin.tie(0); int a, b, q; cin >> a >> b >> q; vector<ll> s(a), t(b); rep(i, a) cin >> s[i]; rep(i, b) cin >> t[i]; rep(i, q) { ll x; cin >> x; int ls = lower_bound(all(s), x) - s.begin() - 1; int rs = ls + 1; int lt = lower_bound(all(t), x) - t.begin() - 1; int rt = lt + 1; ll res = linf; if (ls >= 0 && lt >= 0) { res = min(res, x - min(s[ls], t[lt])); } if (ls >= 0 && rt < b) { res = min(res, min((ll)2 * (x - s[ls]) + t[rt] - x, (ll)2 * (t[rt] - x) + x - s[ls])); } if (rs < a && lt >= 0) { res = min(res, min((ll)2 * (x - s[lt]) + t[rs] - x, (ll)2 * (t[rs] - x) + x - s[lt])); } if (rs < a && rt < b) { res = min(res, max(s[rs], t[rt]) - x); } cout << res << endl; } return 0; }
// includes #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdint> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> // macros #define ll long long int #define pb emplace_back #define mk make_pair #define pq priority_queue #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) using namespace std; // types typedef pair<int, int> P; typedef pair<ll, int> Pl; typedef pair<ll, ll> Pll; typedef pair<double, double> Pd; // constants const int inf = 1e9; const ll linf = 1LL << 50; const double EPS = 1e-10; const int mod = 1e9 + 7; // solve 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 (a > b) { a = b; return 1; } return 0; } bool comp(const Pl &a, const Pl &b) { return a.first < b.first; } int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(false); cin.tie(0); int a, b, q; cin >> a >> b >> q; vector<ll> s(a), t(b); rep(i, a) cin >> s[i]; rep(i, b) cin >> t[i]; rep(i, q) { ll x; cin >> x; int ls = lower_bound(all(s), x) - s.begin() - 1; int rs = ls + 1; int lt = lower_bound(all(t), x) - t.begin() - 1; int rt = lt + 1; ll res = linf; if (ls >= 0 && lt >= 0) { res = min(res, x - min(s[ls], t[lt])); } if (ls >= 0 && rt < b) { res = min(res, min((ll)2 * (x - s[ls]) + t[rt] - x, (ll)2 * (t[rt] - x) + x - s[ls])); } if (rs < a && lt >= 0) { res = min(res, min((ll)2 * (x - t[lt]) + s[rs] - x, (ll)2 * (s[rs] - x) + x - t[lt])); } if (rs < a && rt < b) { res = min(res, max(s[rs], t[rt]) - x); } cout << res << endl; } return 0; }
[ "assignment.value.change", "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
924,845
924,846
u424110125
cpp
p03112
#include <iomanip> #include <iostream> //#include<cstdio> #include <algorithm> #include <cassert> #include <cmath> #include <map> #include <queue> #include <vector> using namespace std; typedef long long ll; const int Amax = 1e5; int A, B, Q; ll S[Amax], T[Amax], X[Amax]; int main() { cin >> A >> B >> Q; for (int i = 0; i < A; i++) cin >> S[i]; for (int i = 0; i < B; i++) cin >> T[i]; for (int i = 0; i < Q; i++) { cin >> X[i]; int si = lower_bound(S, S + A, X[i]) - S; int ti = lower_bound(T, T + B, X[i]) - T; ll ans = 1e18; if (si < A && ti < B) ans = min(ans, max(S[si] - X[i], T[ti] - X[i])); if (si > 0 && ti > 0) ans = min(ans, max(X[i] - S[si - 1], X[i] - T[ti - 1])); if (si > 0 && ti < B) { ans = min(ans, 2 * (X[i] - S[si - 1]) + T[ti] - X[i]); ans = min(ans, X[i] - S[si - 1] + 2 * (T[ti] - X[i])); } if (si < A && ti > 0) { ans = min(ans, 2 * (S[si] - X[i]) + X[i] - T[ti]); ans = min(ans, S[si] - X[i] + 2 * (X[i] - T[ti])); } cout << ans << endl; } return 0; }
#include <iomanip> #include <iostream> //#include<cstdio> #include <algorithm> #include <cassert> #include <cmath> #include <map> #include <queue> #include <vector> using namespace std; typedef long long ll; const int Amax = 1e5; int A, B, Q; ll S[Amax], T[Amax], X[Amax]; int main() { cin >> A >> B >> Q; for (int i = 0; i < A; i++) cin >> S[i]; for (int i = 0; i < B; i++) cin >> T[i]; for (int i = 0; i < Q; i++) { cin >> X[i]; int si = lower_bound(S, S + A, X[i]) - S; int ti = lower_bound(T, T + B, X[i]) - T; ll ans = 1e18; if (si < A && ti < B) ans = min(ans, max(S[si] - X[i], T[ti] - X[i])); if (si > 0 && ti > 0) ans = min(ans, max(X[i] - S[si - 1], X[i] - T[ti - 1])); if (si > 0 && ti < B) { ans = min(ans, 2 * (X[i] - S[si - 1]) + T[ti] - X[i]); ans = min(ans, X[i] - S[si - 1] + 2 * (T[ti] - X[i])); } if (si < A && ti > 0) { ans = min(ans, 2 * (S[si] - X[i]) + X[i] - T[ti - 1]); ans = min(ans, S[si] - X[i] + 2 * (X[i] - T[ti - 1])); } cout << ans << endl; } return 0; }
[ "assignment.change" ]
924,850
924,851
u534998883
cpp
p03112
#include <bits/stdc++.h> using namespace std; #define ll long long ll A, B, Q; ll s[100002], t[100002], x[100002]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> A >> B >> Q; s[0] = -1e18; for (int i = 1; i <= A; ++i) { cin >> s[i]; } s[A + 1] = 1e18; t[0] = -1e18; for (int i = 1; i <= B; ++i) { cin >> t[i]; } t[B + 1] = 1e18; ll s_l, s_r, t_l, t_r, x_i; for (int i = 0; i < Q; ++i) { cin >> x_i; ll *b; ll *d; b = upper_bound(s, s + A + 2, x_i) - 1; ll S[2], T[2]; S[0] = *b; S[1] - *(b + 1); d = upper_bound(t, t + B + 2, x_i) - 1; T[0] = *d; T[1] = *(d + 1); ll res = 1e18; for (int j = 0; j < 2; ++j) { for (int k = 0; k < 2; ++k) { ll d1 = abs(S[j] - x_i) + abs(T[k] - S[j]); ll d2 = abs(T[k] - x_i) + abs(S[j] - T[k]); res = min({res, d1, d2}); } } cout << res << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long ll A, B, Q; ll s[100002], t[100002], x[100002]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> A >> B >> Q; s[0] = -1e18; for (int i = 1; i <= A; ++i) { cin >> s[i]; } s[A + 1] = 1e18; t[0] = -1e18; for (int i = 1; i <= B; ++i) { cin >> t[i]; } t[B + 1] = 1e18; ll s_l, s_r, t_l, t_r, x_i; for (int i = 0; i < Q; ++i) { cin >> x_i; ll *b; ll *d; b = upper_bound(s, s + A + 2, x_i) - 1; ll S[2], T[2]; S[0] = *b; S[1] = *(b + 1); d = upper_bound(t, t + B + 2, x_i) - 1; T[0] = *d; T[1] = *(d + 1); ll res = 1e18; for (int j = 0; j < 2; ++j) { for (int k = 0; k < 2; ++k) { ll d1 = abs(S[j] - x_i) + abs(T[k] - S[j]); ll d2 = abs(T[k] - x_i) + abs(S[j] - T[k]); res = min({res, d1, d2}); } } cout << res << endl; } return 0; }
[ "expression.operation.binary.change" ]
924,852
924,853
u482969053
cpp
p03112
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; #define pb push_back #define mp make_pair #define ff first #define ss second #define lb lower_bound #define ub upper_bound typedef long long ll; typedef vector<ll> vi; typedef vector<vi> vvi; typedef pair<ll, ll> pii; typedef vector<pii> vii; typedef priority_queue<ll> pq; const int MOD = 1e9 + 7; const int INF = 2e9; const int MAX_N = 1; const ll INFL = 1e18L; int main() { ll A, B, Q; cin >> A >> B >> Q; vi s(A), t(B); for (int i = 0; i < A; i++) cin >> s[i]; for (int i = 0; i < B; i++) cin >> t[i]; for (int i = 0; i < Q; i++) { ll a, ans = INFL; cin >> a; // s -> t auto npos = lb(s.begin(), s.end(), a); auto br = npos, bl = npos - 1; if (br != s.begin()) { npos = lb(t.begin(), t.end(), *bl); auto cr = npos, cl = npos - 1; if (cr != t.begin()) { ans = min(ans, abs(a - *bl) + abs(*bl - *cl)); } else if (cr != t.end()) { ans = min(ans, abs(a - *bl) + abs(*bl - *cr)); } } if (br != s.end()) { npos = lb(t.begin(), t.end(), *br); auto cr = npos, cl = npos - 1; if (cr != t.begin()) { ans = min(ans, abs(a - *br) + abs(*br - *cl)); } else if (cr != t.end()) { ans = min(ans, abs(a - *br) + abs(*br - *cr)); } } // t -> s npos = lb(t.begin(), t.end(), a); br = npos; bl = npos - 1; if (br != t.begin()) { npos = lb(s.begin(), s.end(), *bl); auto cr = npos, cl = npos - 1; if (cr != s.begin()) { ans = min(ans, abs(a - *bl) + abs(*bl - *cl)); } else if (cr != s.end()) { ans = min(ans, abs(a - *bl) + abs(*bl - *cr)); } } if (br != t.end()) { npos = lb(s.begin(), s.end(), *br); auto cr = npos, cl = npos - 1; if (cr != s.begin()) { ans = min(ans, abs(a - *br) + abs(*br - *cl)); } else if (cr != s.end()) { ans = min(ans, abs(a - *br) + abs(*br - *cr)); } } cout << ans << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; #define pb push_back #define mp make_pair #define ff first #define ss second #define lb lower_bound #define ub upper_bound typedef long long ll; typedef vector<ll> vi; typedef vector<vi> vvi; typedef pair<ll, ll> pii; typedef vector<pii> vii; typedef priority_queue<ll> pq; const int MOD = 1e9 + 7; const int INF = 2e9; const int MAX_N = 1; const ll INFL = 1e18L; int main() { ll A, B, Q; cin >> A >> B >> Q; vi s(A), t(B); for (int i = 0; i < A; i++) cin >> s[i]; for (int i = 0; i < B; i++) cin >> t[i]; for (int i = 0; i < Q; i++) { ll a, ans = INFL; cin >> a; // s -> t auto npos = lb(s.begin(), s.end(), a); auto br = npos, bl = npos - 1; if (br != s.begin()) { npos = lb(t.begin(), t.end(), *bl); auto cr = npos, cl = npos - 1; if (cr != t.begin()) { ans = min(ans, abs(a - *bl) + abs(*bl - *cl)); } if (cr != t.end()) { ans = min(ans, abs(a - *bl) + abs(*bl - *cr)); } } if (br != s.end()) { npos = lb(t.begin(), t.end(), *br); auto cr = npos, cl = npos - 1; if (cr != t.begin()) { ans = min(ans, abs(a - *br) + abs(*br - *cl)); } if (cr != t.end()) { ans = min(ans, abs(a - *br) + abs(*br - *cr)); } } // t -> s npos = lb(t.begin(), t.end(), a); br = npos; bl = npos - 1; if (br != t.begin()) { npos = lb(s.begin(), s.end(), *bl); auto cr = npos, cl = npos - 1; if (cr != s.begin()) { ans = min(ans, abs(a - *bl) + abs(*bl - *cl)); } if (cr != s.end()) { ans = min(ans, abs(a - *bl) + abs(*bl - *cr)); } } if (br != t.end()) { npos = lb(s.begin(), s.end(), *br); auto cr = npos, cl = npos - 1; if (cr != s.begin()) { ans = min(ans, abs(a - *br) + abs(*br - *cl)); } if (cr != s.end()) { ans = min(ans, abs(a - *br) + abs(*br - *cr)); } } cout << ans << endl; } return 0; }
[ "control_flow.branch.if.replace.add", "control_flow.branch.else_if.replace.remove" ]
924,860
924,861
u581807854
cpp
p03112
#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; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define fi first #define se second #define mp make_pair #define itrfor(itr, A) for (auto itr = A.begin(); itr != A.end(); itr++) template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T>>; typedef long long llong; char moji[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; char moji2[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; char moji3[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; #define Sort(a) sort(a.begin(), a.end()); #define Reverse(a) reverse(a.begin(), a.end()); #define print(a) cout << a << endl; #define MOD llong(1e9 + 7) #define MAX int(1e5 + 5) #define debug(x) cout << #x << " = " << (x) << endl; #define pi acos(-1.0) #define int llong #define INF llong(1e17); signed main() { int a, b, q; cin >> a >> b >> q; pair<int, int> A[MAX], B[MAX]; REP(i, a) { scanf("%lld", &(A[i + 1].fi)); } REP(i, b) scanf("%lld", &(B[i + 1].fi)); A[0].fi = -INF; B[0].fi = -INF; A[0].se = INF; B[0].se = INF; A[a + 1].fi = INF; B[b + 1].fi = INF; A[a + 1].se = INF; B[b + 1].se = INF; int id = 0; while (A[1].fi > B[id + 1].fi) id++; FOR(i, 1, a + 1) { if (A[i].fi > B[id + 1].fi) id++; A[i].se = min(abs(A[i].fi - B[id].fi), abs(A[i].fi - B[id + 1].fi)); } id = 0; while (B[1].fi > A[id + 1].fi) id++; FOR(i, 1, b + 1) { if (B[i].fi > A[id + 1].fi) id++; B[i].se = min(abs(B[i].fi - A[id].fi), abs(B[i].fi - A[id + 1].fi)); } REP(i, q) { int tmp; scanf("%lld", &tmp); int ng = 0, ok = a + 1; while (ng + 1 < ok) { int mid = (ng + ok) / 2; if (A[mid].fi < tmp) ng = mid; else ok = mid; } int a_id = ok - 1; ng = 0; ok = b + 1; while (ng + 1 < ok) { int mid = (ng + ok) / 2; if (B[mid].fi < tmp) ng = mid; else ok = mid; } int b_id = ok - 1; int ans = min(abs(tmp - A[a_id].fi) + A[a_id].se, abs(tmp - B[b_id].fi) + B[b_id].se); ans = min(ans, abs(tmp - A[a_id + 1].fi) + A[a_id + 1].se); ans = min(ans, abs(tmp - B[b_id + 1].fi) + B[b_id + 1].se); /* int ans = INF; FOR(j,a_id , a_id +2){ FOR(k,b_id , b_id + 2){ int res = min( abs(A[j].fi-tmp) + abs(A[j].fi - B[k].fi), abs(B[k].fi-tmp)+ abs(A[j].fi - B[k].fi) ); ans = min(ans,res); } } */ printf("%lld\n", ans); } }
#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; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define fi first #define se second #define mp make_pair #define itrfor(itr, A) for (auto itr = A.begin(); itr != A.end(); itr++) template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T>>; typedef long long llong; char moji[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; char moji2[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; char moji3[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; #define Sort(a) sort(a.begin(), a.end()); #define Reverse(a) reverse(a.begin(), a.end()); #define print(a) cout << a << endl; #define MOD llong(1e9 + 7) #define MAX int(1e5 + 5) #define debug(x) cout << #x << " = " << (x) << endl; #define pi acos(-1.0) #define int llong #define INF llong(1e17); signed main() { int a, b, q; cin >> a >> b >> q; pair<int, int> A[MAX], B[MAX]; REP(i, a) { scanf("%lld", &(A[i + 1].fi)); } REP(i, b) scanf("%lld", &(B[i + 1].fi)); A[0].fi = -INF; B[0].fi = -INF; A[0].se = INF; B[0].se = INF; A[a + 1].fi = INF; B[b + 1].fi = INF; A[a + 1].se = INF; B[b + 1].se = INF; int id = 0; while (A[1].fi > B[id + 1].fi) id++; FOR(i, 1, a + 1) { while (A[i].fi > B[id + 1].fi) id++; A[i].se = min(abs(A[i].fi - B[id].fi), abs(A[i].fi - B[id + 1].fi)); } id = 0; while (B[1].fi > A[id + 1].fi) id++; FOR(i, 1, b + 1) { while (B[i].fi > A[id + 1].fi) id++; B[i].se = min(abs(B[i].fi - A[id].fi), abs(B[i].fi - A[id + 1].fi)); } REP(i, q) { int tmp; scanf("%lld", &tmp); int ng = 0, ok = a + 1; while (ng + 1 < ok) { int mid = (ng + ok) / 2; if (A[mid].fi < tmp) ng = mid; else ok = mid; } int a_id = ok - 1; ng = 0; ok = b + 1; while (ng + 1 < ok) { int mid = (ng + ok) / 2; if (B[mid].fi < tmp) ng = mid; else ok = mid; } int b_id = ok - 1; int ans = min(abs(tmp - A[a_id].fi) + A[a_id].se, abs(tmp - B[b_id].fi) + B[b_id].se); ans = min(ans, abs(tmp - A[a_id + 1].fi) + A[a_id + 1].se); ans = min(ans, abs(tmp - B[b_id + 1].fi) + B[b_id + 1].se); /* int ans = INF; FOR(j,a_id , a_id +2){ FOR(k,b_id , b_id + 2){ int res = min( abs(A[j].fi-tmp) + abs(A[j].fi - B[k].fi), abs(B[k].fi-tmp)+ abs(A[j].fi - B[k].fi) ); ans = min(ans,res); } } */ printf("%lld\n", ans); } }
[ "control_flow.branch.while.replace.add", "control_flow.loop.if.replace.remove" ]
924,864
924,865
u920299620
cpp
p03112
#include <bits/stdc++.h> #define ll long long #define fornum(A, B, C) for (A = B; A < C; A++) #define mp make_pair #define pii pair<int, int> #define pll pair<ll, ll> using namespace std; ///////////////////////////////////////////////////// #define INF 1e15 ll A, B, Q, s[101010], t[101010]; ll ab[101010], ba[101010]; ll ans, mk[10]; ll i, j, k; ll bs(ll a, ll b, ll *v) { ll l = 0, r = b - 1; while (l <= r) { ll c = (l + r) / 2; if (v[c] > a) { r = c - 1; } else { l = c + 1; } } return r; } inline ll dist(ll a, ll b, ll c) { return abs(a - b) + abs(b - c); } inline ll minn(ll a, ll b) { return a < b ? a : b; } int main() { scanf("%lld%lld%lld", &A, &B, &Q); fornum(i, 0, A) { scanf("%lld", &s[i + 1]); } fornum(i, 0, B) { scanf("%lld", &t[i + 1]); } s[0] = t[0] = -INF; s[A + 1] = t[B + 1] = INF; s[A + 2] = t[A + 2] = INF * 2; A += 3; B += 3; j = 0; fornum(i, 0, A) { while (t[j + 1] < s[i]) { j++; } ba[i] = j; } j = 0; fornum(i, 0, B) { while (s[j + 1] < s[i]) { j++; } ab[i] = j; } fornum(i, 0, Q) { ll x; scanf("%lld", &x); ll aa = bs(x, A, s); ll bb = bs(x, B, t); ll ans = INF; ans = minn(ans, dist(x, s[aa], t[ba[aa]])); ans = minn(ans, dist(x, s[aa], t[ba[aa] + 1])); aa++; ans = minn(ans, dist(x, s[aa], t[ba[aa]])); ans = minn(ans, dist(x, s[aa], t[ba[aa] + 1])); ans = minn(ans, dist(x, t[bb], s[ab[bb]])); ans = minn(ans, dist(x, t[bb], s[ab[bb] + 1])); bb++; ans = minn(ans, dist(x, t[bb], s[ab[bb]])); ans = minn(ans, dist(x, t[bb], s[ab[bb] + 1])); printf("%lld\n", ans); } return 0; }
#include <bits/stdc++.h> #define ll long long #define fornum(A, B, C) for (A = B; A < C; A++) #define mp make_pair #define pii pair<int, int> #define pll pair<ll, ll> using namespace std; ///////////////////////////////////////////////////// #define INF 1e15 ll A, B, Q, s[101010], t[101010]; ll ab[101010], ba[101010]; ll ans, mk[10]; ll i, j, k; ll bs(ll a, ll b, ll *v) { ll l = 0, r = b - 1; while (l <= r) { ll c = (l + r) / 2; if (v[c] > a) { r = c - 1; } else { l = c + 1; } } return r; } inline ll dist(ll a, ll b, ll c) { return abs(a - b) + abs(b - c); } inline ll minn(ll a, ll b) { return a < b ? a : b; } int main() { scanf("%lld%lld%lld", &A, &B, &Q); fornum(i, 0, A) { scanf("%lld", &s[i + 1]); } fornum(i, 0, B) { scanf("%lld", &t[i + 1]); } s[0] = t[0] = -INF; s[A + 1] = t[B + 1] = INF; s[A + 2] = t[B + 2] = INF * 2; A += 3; B += 3; j = 0; fornum(i, 0, A) { while (t[j + 1] < s[i]) { j++; } ba[i] = j; } j = 0; fornum(i, 0, B) { while (s[j + 1] < t[i]) { j++; } ab[i] = j; } fornum(i, 0, Q) { ll x; scanf("%lld", &x); ll aa = bs(x, A, s); ll bb = bs(x, B, t); ll ans = INF; ans = minn(ans, dist(x, s[aa], t[ba[aa]])); ans = minn(ans, dist(x, s[aa], t[ba[aa] + 1])); aa++; ans = minn(ans, dist(x, s[aa], t[ba[aa]])); ans = minn(ans, dist(x, s[aa], t[ba[aa] + 1])); ans = minn(ans, dist(x, t[bb], s[ab[bb]])); ans = minn(ans, dist(x, t[bb], s[ab[bb] + 1])); bb++; ans = minn(ans, dist(x, t[bb], s[ab[bb]])); ans = minn(ans, dist(x, t[bb], s[ab[bb] + 1])); printf("%lld\n", ans); } return 0; }
[ "assignment.variable.change", "identifier.change", "variable_access.subscript.index.change", "expression.operation.binary.change", "control_flow.loop.condition.change" ]
924,868
924,867
u259396003
cpp
p03112
#include <bits/stdc++.h> using namespace std; #define int long long #define all(v) (v).begin(), (v).end() template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } const int INF = 1e18; int A, B, Q; vector<int> s, t; int solve(int x) { // Right, Leftはxより右にあるか左にあるか int sRight = *lower_bound(all(s), x); int sLeft = *(upper_bound(all(s), x) - 1); int tRight = *lower_bound(all(t), x); int tLeft = *(upper_bound(all(t), x) - 1); int ret = INF; // (s, t) -> (t, s) -> x chmin(ret, abs(min(sLeft, tLeft) - x)); // s -> x -> t chmin(ret, abs(tRight - sLeft) + abs(min(x - sLeft, tRight - x))); // t -> x -> s chmin(ret, abs(sRight - sLeft) + abs(min(x - tLeft, sRight - x))); // x -> (s, t) -> (t, s) chmin(ret, abs(max(tRight, sRight) - x)); return ret; } signed main() { cin >> A >> B >> Q; s.resize(A); t.resize(B); for (int i = 0; i < A; i++) { cin >> s[i]; } for (int i = 0; i < B; i++) { cin >> t[i]; } // 番兵を設置すると値が見つからなかったときの処理が楽になる s.push_back(INF); s.push_back(-INF); t.push_back(INF); t.push_back(-INF); sort(all(t)); sort(all(s)); while (Q--) { int x; cin >> x; int ans = solve(x); cout << solve(x) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define all(v) (v).begin(), (v).end() template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } const int INF = 1e18; int A, B, Q; vector<int> s, t; int solve(int x) { // Right, Leftはxより右にあるか左にあるか int sRight = *lower_bound(all(s), x); int sLeft = *(upper_bound(all(s), x) - 1); int tRight = *lower_bound(all(t), x); int tLeft = *(upper_bound(all(t), x) - 1); int ret = INF; // (s, t) -> (t, s) -> x chmin(ret, abs(min(sLeft, tLeft) - x)); // s -> x -> t chmin(ret, abs(tRight - sLeft) + abs(min(x - sLeft, tRight - x))); // t -> x -> s chmin(ret, abs(sRight - tLeft) + abs(min(x - tLeft, sRight - x))); // x -> (s, t) -> (t, s) chmin(ret, abs(max(tRight, sRight) - x)); return ret; } signed main() { cin >> A >> B >> Q; s.resize(A); t.resize(B); for (int i = 0; i < A; i++) { cin >> s[i]; } for (int i = 0; i < B; i++) { cin >> t[i]; } // 番兵を設置すると値が見つからなかったときの処理が楽になる s.push_back(INF); s.push_back(-INF); t.push_back(INF); t.push_back(-INF); sort(all(t)); sort(all(s)); while (Q--) { int x; cin >> x; int ans = solve(x); cout << solve(x) << endl; } return 0; }
[ "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
924,876
924,877
u219873012
cpp
p03112
#include <bits/stdc++.h> using namespace std; #define int long long #define vvi vector<vector<int>> #define vec vector #define pq priority_queue #define all(v) (v).begin(), (v).end() #define uniqueV(x) \ sort(x.begin(), x.end()); \ x.erase(unique(x.begin(), x.end()), x.end()); #define rep(i, n) for (int(i) = (0); (i) < (n); ++(i)) #define repp(i, m, n) for (int(i) = (m); (i) < (n); ++(i)) #define dbg(x) cerr << #x << ": " << x << endl; #define dbg2(x, y) \ cerr << "(" << #x << ", " << #y << ") = " \ << "(" << x << ", " << y << ")" << endl; #define dbg3(x, y, z) \ cerr << "(" << #x << ", " << #y << ", " << #z << ") = " \ << "(" << x << ", " << y << ", " << z << ")" << endl; #define dbgB(value, size) cerr << #value << ": " << bitset<size>(value) << endl; #define line() cerr << "---------------" << endl; const int dx[] = {1, -1, 0, 0}; const int dy[] = {0, 0, -1, 1}; const double PI = 3.14159265358979323846; 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; } template <typename T> void print1(T begin, T end) { while (begin != end) { cout << (*begin) << " "; *begin++; } cout << endl; } template <typename T> void print2(T Array, int height, int width) { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { cout << " " << Array[i][j]; } cout << endl; } } void print() { std::cerr << endl; } template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) { std::cerr << head << " "; print(std::forward<Tail>(tail)...); } template <class T> void Add(T &a, const T &b, const T &mod = 1000000007) { int val = ((a % mod) + (b % mod)) % mod; if (val < 0) { val += mod; } a = val; } template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); } template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); } // ------------------------------------------------------------------------------------------ const int INF = 1e18; signed main() { int n, m, q; cin >> n >> m >> q; vec<int> x(n), y(n); rep(i, n) { cin >> x[i]; } rep(i, m) { cin >> y[i]; } x.push_back(INF); x.push_back(-INF); y.push_back(INF); y.push_back(-INF); sort(all(x)); sort(all(y)); while (q--) { int u; cin >> u; int s[2]; int t[2]; s[0] = *lower_bound(all(x), u); s[1] = *prev(upper_bound(all(x), u)); t[0] = *lower_bound(all(y), u); t[1] = *prev(upper_bound(all(y), u)); int ans = 8e18; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { chmin(ans, abs(u - s[i]) + abs(s[i] - t[j])); chmin(ans, abs(u - t[j]) + abs(s[i] - t[j])); } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define vvi vector<vector<int>> #define vec vector #define pq priority_queue #define all(v) (v).begin(), (v).end() #define uniqueV(x) \ sort(x.begin(), x.end()); \ x.erase(unique(x.begin(), x.end()), x.end()); #define rep(i, n) for (int(i) = (0); (i) < (n); ++(i)) #define repp(i, m, n) for (int(i) = (m); (i) < (n); ++(i)) #define dbg(x) cerr << #x << ": " << x << endl; #define dbg2(x, y) \ cerr << "(" << #x << ", " << #y << ") = " \ << "(" << x << ", " << y << ")" << endl; #define dbg3(x, y, z) \ cerr << "(" << #x << ", " << #y << ", " << #z << ") = " \ << "(" << x << ", " << y << ", " << z << ")" << endl; #define dbgB(value, size) cerr << #value << ": " << bitset<size>(value) << endl; #define line() cerr << "---------------" << endl; const int dx[] = {1, -1, 0, 0}; const int dy[] = {0, 0, -1, 1}; const double PI = 3.14159265358979323846; 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; } template <typename T> void print1(T begin, T end) { while (begin != end) { cout << (*begin) << " "; *begin++; } cout << endl; } template <typename T> void print2(T Array, int height, int width) { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { cout << " " << Array[i][j]; } cout << endl; } } void print() { std::cerr << endl; } template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) { std::cerr << head << " "; print(std::forward<Tail>(tail)...); } template <class T> void Add(T &a, const T &b, const T &mod = 1000000007) { int val = ((a % mod) + (b % mod)) % mod; if (val < 0) { val += mod; } a = val; } template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); } template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); } // ------------------------------------------------------------------------------------------ const int INF = 1e18; signed main() { int n, m, q; cin >> n >> m >> q; vec<int> x(n), y(m); rep(i, n) { cin >> x[i]; } rep(i, m) { cin >> y[i]; } x.push_back(INF); x.push_back(-INF); y.push_back(INF); y.push_back(-INF); sort(all(x)); sort(all(y)); while (q--) { int u; cin >> u; int s[2]; int t[2]; s[0] = *lower_bound(all(x), u); s[1] = *prev(upper_bound(all(x), u)); t[0] = *lower_bound(all(y), u); t[1] = *prev(upper_bound(all(y), u)); int ans = 8e18; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { chmin(ans, abs(u - s[i]) + abs(s[i] - t[j])); chmin(ans, abs(u - t[j]) + abs(s[i] - t[j])); } } cout << ans << endl; } return 0; }
[]
924,878
924,879
u219873012
cpp
p03112
#include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <map> #include <queue> #include <string> #include <tuple> #include <vector> using namespace std; vector<long long> A, B; int N, M, Q; long long solve(long long x) { int pos1 = lower_bound(A.begin(), A.end(), x) - A.begin(); int pos2 = lower_bound(B.begin(), B.end(), x) - B.begin(); vector<long long> G1, G2; if (pos1 >= 1) G1.push_back(A[pos1 - 1]); if (pos1 < A.size()) G1.push_back(A[pos1]); if (pos2 >= 1) G2.push_back(B[pos2 - 1]); if (pos2 < B.size()) G2.push_back(B[pos2]); long long ans = (1LL << 60); for (int i = 0; i < G1.size(); i++) { for (int j = 0; j < G2.size(); j++) { ans = min(ans, abs(x - G1[i]) + abs(G1[i] - G2[j])); ans = min(ans, abs(x - G2[j]) + abs(G2[j] - G1[i])); } } return ans; } int main() { cin >> N >> M >> Q; for (int i = 0; i < N; i++) { long long c; cin >> c; A.push_back(c); } for (int i = 0; i < M; i++) { long long c; cin >> c; B.push_back(c); } sort(A.begin(), A.end()); sort(B.begin(), B.end()); for (int i = 1; i <= Q; i++) { int pl; cin >> pl; cout << solve(pl) << endl; } return 0; }
#include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <map> #include <queue> #include <string> #include <tuple> #include <vector> using namespace std; vector<long long> A, B; int N, M, Q; long long solve(long long x) { int pos1 = lower_bound(A.begin(), A.end(), x) - A.begin(); int pos2 = lower_bound(B.begin(), B.end(), x) - B.begin(); vector<long long> G1, G2; if (pos1 >= 1) G1.push_back(A[pos1 - 1]); if (pos1 < A.size()) G1.push_back(A[pos1]); if (pos2 >= 1) G2.push_back(B[pos2 - 1]); if (pos2 < B.size()) G2.push_back(B[pos2]); long long ans = (1LL << 60); for (int i = 0; i < G1.size(); i++) { for (int j = 0; j < G2.size(); j++) { ans = min(ans, abs(x - G1[i]) + abs(G1[i] - G2[j])); ans = min(ans, abs(x - G2[j]) + abs(G2[j] - G1[i])); } } return ans; } int main() { cin >> N >> M >> Q; for (int i = 0; i < N; i++) { long long c; cin >> c; A.push_back(c); } for (int i = 0; i < M; i++) { long long c; cin >> c; B.push_back(c); } sort(A.begin(), A.end()); sort(B.begin(), B.end()); for (int i = 1; i <= Q; i++) { long long pl; cin >> pl; cout << solve(pl) << endl; } return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
924,884
924,885
u504103417
cpp
p03112
#include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <map> #include <queue> #include <string> #include <tuple> #include <vector> using namespace std; vector<long long> A, B; int N, M, Q; long long solve(long long x) { int pos1 = lower_bound(A.begin(), A.end(), x) - A.begin(); int pos2 = lower_bound(B.begin(), B.end(), x) - B.begin(); vector<long long> G1, G2; if (pos1 >= 1) G1.push_back(A[pos1 - 1]); if (pos1 < A.size()) G1.push_back(A[pos1]); if (pos2 >= 1) G2.push_back(B[pos2 - 1]); if (pos2 < B.size()) G2.push_back(B[pos2]); long long ans = (1LL << 60); for (int i = 0; i < G1.size(); i++) { for (int j = 0; j < G2.size(); j++) { ans = min(ans, abs(x - G1[i]) + abs(G1[i] - G2[j])); ans = min(ans, abs(x - G2[j]) + abs(G2[j] - G1[i])); } } return ans; } int main() { cin >> N >> M >> Q; for (int i = 0; i < N; i++) { int c; cin >> c; A.push_back(c); } for (int i = 0; i < M; i++) { int c; cin >> c; B.push_back(c); } sort(A.begin(), A.end()); sort(B.begin(), B.end()); for (int i = 1; i <= Q; i++) { int pl; cin >> pl; cout << solve(pl) << endl; } return 0; }
#include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <map> #include <queue> #include <string> #include <tuple> #include <vector> using namespace std; vector<long long> A, B; int N, M, Q; long long solve(long long x) { int pos1 = lower_bound(A.begin(), A.end(), x) - A.begin(); int pos2 = lower_bound(B.begin(), B.end(), x) - B.begin(); vector<long long> G1, G2; if (pos1 >= 1) G1.push_back(A[pos1 - 1]); if (pos1 < A.size()) G1.push_back(A[pos1]); if (pos2 >= 1) G2.push_back(B[pos2 - 1]); if (pos2 < B.size()) G2.push_back(B[pos2]); long long ans = (1LL << 60); for (int i = 0; i < G1.size(); i++) { for (int j = 0; j < G2.size(); j++) { ans = min(ans, abs(x - G1[i]) + abs(G1[i] - G2[j])); ans = min(ans, abs(x - G2[j]) + abs(G2[j] - G1[i])); } } return ans; } int main() { cin >> N >> M >> Q; for (int i = 0; i < N; i++) { long long c; cin >> c; A.push_back(c); } for (int i = 0; i < M; i++) { long long c; cin >> c; B.push_back(c); } sort(A.begin(), A.end()); sort(B.begin(), B.end()); for (int i = 1; i <= Q; i++) { long long pl; cin >> pl; cout << solve(pl) << endl; } return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
924,886
924,885
u504103417
cpp
p03112
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; #define pb push_back #define mp make_pair #define eps 1e-9 #define INF 1000000000 #define LLINF 1000000000000000ll #define sz(x) ((int)(x).size()) #define fi first #define sec second #define all(x) (x).begin(), (x).end() #define sq(x) ((x) * (x)) #define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++) #define repn(i, a, n) for (int(i) = (a); (i) < (int)(n); (i)++) #define EQ(a, b) (abs((a) - (b)) < eps) template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } int A, B, Q; ll s[100100], t[100100]; int main() { cin >> A >> B >> Q; for (int i = 0; i < A; i++) cin >> s[i]; for (int i = 0; i < B; i++) cin >> t[i]; for (int i = 0; i < Q; i++) { int x; cin >> x; int a = lower_bound(s, s + A, x) - s; int b = lower_bound(t, t + B, x) - t; ll ans = LLINF; for (int j = max(0, a - 1); j <= min(A - 1, a); j++) { for (int k = max(0, b - 1); k <= min(B - 1, b); k++) { ans = min(ans, abs(x - s[j]) + abs(s[j] - t[k])); ans = min(ans, abs(x - t[k]) + abs(t[k] - s[j])); } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; #define pb push_back #define mp make_pair #define eps 1e-9 #define INF 1000000000 #define LLINF 1000000000000000ll #define sz(x) ((int)(x).size()) #define fi first #define sec second #define all(x) (x).begin(), (x).end() #define sq(x) ((x) * (x)) #define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++) #define repn(i, a, n) for (int(i) = (a); (i) < (int)(n); (i)++) #define EQ(a, b) (abs((a) - (b)) < eps) template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } int A, B, Q; ll s[100100], t[100100]; int main() { cin >> A >> B >> Q; for (int i = 0; i < A; i++) cin >> s[i]; for (int i = 0; i < B; i++) cin >> t[i]; for (int i = 0; i < Q; i++) { ll x; cin >> x; int a = lower_bound(s, s + A, x) - s; int b = lower_bound(t, t + B, x) - t; ll ans = LLINF; for (int j = max(0, a - 1); j <= min(A - 1, a); j++) { for (int k = max(0, b - 1); k <= min(B - 1, b); k++) { ans = min(ans, abs(x - s[j]) + abs(s[j] - t[k])); ans = min(ans, abs(x - t[k]) + abs(t[k] - s[j])); } } cout << ans << endl; } return 0; }
[ "variable_declaration.type.change" ]
924,889
924,890
u379947938
cpp
p03112
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; #define pb push_back #define mp make_pair #define eps 1e-9 #define INF 1000000000 #define LLINF 1000000000000000ll #define sz(x) ((int)(x).size()) #define fi first #define sec second #define all(x) (x).begin(), (x).end() #define sq(x) ((x) * (x)) #define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++) #define repn(i, a, n) for (int(i) = (a); (i) < (int)(n); (i)++) #define EQ(a, b) (abs((a) - (b)) < eps) template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } int A, B, Q; int s[100100], t[100100]; int main() { cin >> A >> B >> Q; for (int i = 0; i < A; i++) cin >> s[i]; for (int i = 0; i < B; i++) cin >> t[i]; for (int i = 0; i < Q; i++) { int x; cin >> x; int a = lower_bound(s, s + A, x) - s; int b = lower_bound(t, t + B, x) - t; int ans = INF; for (int j = max(0, a - 1); j <= min(A - 1, a); j++) { for (int k = max(0, b - 1); k <= min(B - 1, b); k++) { ans = min(ans, abs(x - s[j]) + abs(s[j] - t[k])); ans = min(ans, abs(x - t[k]) + abs(t[k] - s[j])); } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; #define pb push_back #define mp make_pair #define eps 1e-9 #define INF 1000000000 #define LLINF 1000000000000000ll #define sz(x) ((int)(x).size()) #define fi first #define sec second #define all(x) (x).begin(), (x).end() #define sq(x) ((x) * (x)) #define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++) #define repn(i, a, n) for (int(i) = (a); (i) < (int)(n); (i)++) #define EQ(a, b) (abs((a) - (b)) < eps) template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } int A, B, Q; ll s[100100], t[100100]; int main() { cin >> A >> B >> Q; for (int i = 0; i < A; i++) cin >> s[i]; for (int i = 0; i < B; i++) cin >> t[i]; for (int i = 0; i < Q; i++) { ll x; cin >> x; int a = lower_bound(s, s + A, x) - s; int b = lower_bound(t, t + B, x) - t; ll ans = LLINF; for (int j = max(0, a - 1); j <= min(A - 1, a); j++) { for (int k = max(0, b - 1); k <= min(B - 1, b); k++) { ans = min(ans, abs(x - s[j]) + abs(s[j] - t[k])); ans = min(ans, abs(x - t[k]) + abs(t[k] - s[j])); } } cout << ans << endl; } return 0; }
[ "variable_declaration.type.change", "variable_declaration.value.change", "identifier.change" ]
924,891
924,890
u379947938
cpp
p03112
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define all(x) (x).begin(), (x).end() using namespace std; const int INF = 1145141919, MOD = 1e9 + 7; const long long LINF = 8931145141919364364, LMOD = 998244353; inline long long mod(long long n, long long m) { return (n % m + m) % m; } // const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1}; int main() { int a, b, q; cin >> a >> b >> q; vector<long long> s(a + 4); vector<long long> t(b + 4); s[0] = t[0] = -LINF / 2; s[1] = t[1] = -LINF / 4; rep(i, a) cin >> s[i + 2]; rep(i, b) cin >> t[i + 2]; s[a + 2] = t[a + 2] = LINF / 4; s[a + 3] = t[a + 3] = LINF / 2; while (q--) { long long ans = LINF; long long x; cin >> x; // 神社先 // 神社左 { long long sh = *(lower_bound(all(s), x) - 1); long long te = LINF; // 寺左 te = *(lower_bound(all(t), sh) - 1); ans = min(ans, abs(sh - x) + abs(sh - te)); // 寺右 te = *lower_bound(all(t), sh); ans = min(ans, abs(sh - x) + abs(sh - te)); } // 神社右 { long long sh = *lower_bound(all(s), x); long long te = LINF; // 寺左 te = *(lower_bound(all(t), sh) - 1); ans = min(ans, abs(sh - x) + abs(sh - te)); // 寺右 te = *lower_bound(all(t), sh); ans = min(ans, abs(sh - x) + abs(sh - te)); } // 寺先 // 寺左 { long long te = *(lower_bound(all(t), x) - 1); long long sh = LINF; // 神社左 sh = *(lower_bound(all(s), te) - 1); ans = min(ans, abs(te - x) + abs(sh - te)); // 神社右 sh = *lower_bound(all(s), te); ans = min(ans, abs(te - x) + abs(sh - te)); } // 寺右 { long long te = *lower_bound(all(t), x); long long sh = LINF; // 神社左 sh = *(lower_bound(all(s), te) - 1); ans = min(ans, abs(te - x) + abs(sh - te)); // 神社右 sh = *lower_bound(all(s), te); ans = min(ans, abs(te - x) + abs(sh - te)); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define all(x) (x).begin(), (x).end() using namespace std; const int INF = 1145141919, MOD = 1e9 + 7; const long long LINF = 8931145141919364364, LMOD = 998244353; inline long long mod(long long n, long long m) { return (n % m + m) % m; } // const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1}; int main() { int a, b, q; cin >> a >> b >> q; vector<long long> s(a + 4); vector<long long> t(b + 4); s[0] = t[0] = -LINF / 2; s[1] = t[1] = -LINF / 4; rep(i, a) cin >> s[i + 2]; rep(i, b) cin >> t[i + 2]; s[a + 2] = t[b + 2] = LINF / 4; s[a + 3] = t[b + 3] = LINF / 2; while (q--) { long long ans = LINF; long long x; cin >> x; // 神社先 // 神社左 { long long sh = *(lower_bound(all(s), x) - 1); long long te = LINF; // 寺左 te = *(lower_bound(all(t), sh) - 1); ans = min(ans, abs(sh - x) + abs(sh - te)); // 寺右 te = *lower_bound(all(t), sh); ans = min(ans, abs(sh - x) + abs(sh - te)); } // 神社右 { long long sh = *lower_bound(all(s), x); long long te = LINF; // 寺左 te = *(lower_bound(all(t), sh) - 1); ans = min(ans, abs(sh - x) + abs(sh - te)); // 寺右 te = *lower_bound(all(t), sh); ans = min(ans, abs(sh - x) + abs(sh - te)); } // 寺先 // 寺左 { long long te = *(lower_bound(all(t), x) - 1); long long sh = LINF; // 神社左 sh = *(lower_bound(all(s), te) - 1); ans = min(ans, abs(te - x) + abs(sh - te)); // 神社右 sh = *lower_bound(all(s), te); ans = min(ans, abs(te - x) + abs(sh - te)); } // 寺右 { long long te = *lower_bound(all(t), x); long long sh = LINF; // 神社左 sh = *(lower_bound(all(s), te) - 1); ans = min(ans, abs(te - x) + abs(sh - te)); // 神社右 sh = *lower_bound(all(s), te); ans = min(ans, abs(te - x) + abs(sh - te)); } cout << ans << endl; } return 0; }
[ "assignment.variable.change", "identifier.change", "variable_access.subscript.index.change", "expression.operation.binary.change" ]
924,892
924,893
u918753189
cpp
p03112
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(void) { int s, t, spot, val; vector<ll> arrS, arrT; cin >> s >> t >> spot; for (int i = 0; i < s; i++) { cin >> val; arrS.push_back(val); } for (int i = 0; i < t; i++) { cin >> val; arrT.push_back(val); } // lower_bound ashiglah ved hamgiin ehnii esvel svvliinh baij boloh uchraas -+ // utga ehlel togsgold nemeh arrS.push_back(-1e17); arrS.push_back(1e17); arrT.push_back(-1e17); arrT.push_back(1e17); sort(arrS.begin(), arrS.end()); sort(arrT.begin(), arrT.end()); for (int i = 0; i < spot; i++) { ll ans = 1e18; cin >> val; int ii = lower_bound(arrS.begin(), arrS.end(), val) - arrS.begin(); int jj = lower_bound(arrT.begin(), arrT.end(), val) - arrT.begin(); ll ra = arrS[ii] - val; ll rb = arrT[jj] - val; ll la = val - arrS[ii - 1]; ll lb = val - arrT[jj - 1]; // cout << ra << rb << endl; // cout << la << lb << endl; // cout << ans << endl; // ogogdson tseg ni hamag svvld esvel hamgiin ehend bh ved ehnii 2 // tootsoolloor ans = min(ans, max(ra, rb)); ans = min(ans, max(la, lb)); // tseg ni shrine temple 2 iin dund bh ved ans = min(ans, ra + lb + min(ra, lb)); ans = min(ans, la + rb + min(la, rb)); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(void) { int s, t, spot; ll val; vector<ll> arrS, arrT; cin >> s >> t >> spot; for (int i = 0; i < s; i++) { cin >> val; arrS.push_back(val); } for (int i = 0; i < t; i++) { cin >> val; arrT.push_back(val); } // lower_bound ashiglah ved hamgiin ehnii esvel svvliinh baij boloh uchraas -+ // utga ehlel togsgold nemeh arrS.push_back(-1e17); arrS.push_back(1e17); arrT.push_back(-1e17); arrT.push_back(1e17); sort(arrS.begin(), arrS.end()); sort(arrT.begin(), arrT.end()); for (int i = 0; i < spot; i++) { ll ans = 1e18; cin >> val; int ii = lower_bound(arrS.begin(), arrS.end(), val) - arrS.begin(); int jj = lower_bound(arrT.begin(), arrT.end(), val) - arrT.begin(); ll ra = arrS[ii] - val; ll rb = arrT[jj] - val; ll la = val - arrS[ii - 1]; ll lb = val - arrT[jj - 1]; // cout << ra << rb << endl; // cout << la << lb << endl; // cout << ans << endl; // ogogdson tseg ni hamag svvld esvel hamgiin ehend bh ved ehnii 2 // tootsoolloor ans = min(ans, max(ra, rb)); ans = min(ans, max(la, lb)); // tseg ni shrine temple 2 iin dund bh ved ans = min(ans, ra + lb + min(ra, lb)); ans = min(ans, la + rb + min(la, rb)); cout << ans << endl; } return 0; }
[]
924,896
924,897
u522598953
cpp
p03112
#include <bits/stdc++.h> using namespace std; // #define INF LONG_MAX #define INF 10000000000 #define ll long long int int main() { int A, B, Q; cin >> A >> B >> Q; vector<ll> s; vector<ll> t; s.push_back(-1 * INF); //二分探索用(スタート位置がs,t範囲に入るように) t.push_back(-1 * INF); for (int i = 0; i < A; i++) { ll ss; cin >> ss; s.push_back(ss); } for (int i = 0; i < B; i++) { ll tt; cin >> tt; t.push_back(tt); } s.push_back(INF); t.push_back(INF); ll ans = INF; for (int i = 0; i < Q; i++) { ll x; cin >> x; auto b = lower_bound(s.begin(), s.end(), x); auto d = lower_bound(t.begin(), t.end(), x); ll sl = *(b - 1), sr = *b; ll tl = *(d - 1), tr = *d; // printf("%ld %ld %ld %ld\n",sl,sr,tl,tr); ll res0 = abs(x - tr) + abs(tr - sl); ll res1 = sl < tl ? abs(x - sl) : abs(x - tl); ll res2 = abs(x - sr) + abs(sr - tl); ll res3 = sr < tr ? abs(x - tr) : abs(x - sr); ll res4 = abs(x - tl) + abs(tl - sr); ll res5 = abs(x - sl) + abs(sl - tr); ans = min({res0, res1, res2, res3, res4, res5}); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; // #define INF LONG_MAX #define INF 100000000000 #define ll long long int int main() { int A, B, Q; cin >> A >> B >> Q; vector<ll> s; vector<ll> t; s.push_back(-1 * INF); //二分探索用(スタート位置がs,t範囲に入るように) t.push_back(-1 * INF); for (int i = 0; i < A; i++) { ll ss; cin >> ss; s.push_back(ss); } for (int i = 0; i < B; i++) { ll tt; cin >> tt; t.push_back(tt); } s.push_back(INF); t.push_back(INF); ll ans = INF; for (int i = 0; i < Q; i++) { ll x; cin >> x; auto b = lower_bound(s.begin(), s.end(), x); auto d = lower_bound(t.begin(), t.end(), x); ll sl = *(b - 1), sr = *b; ll tl = *(d - 1), tr = *d; // printf("%ld %ld %ld %ld\n",sl,sr,tl,tr); ll res0 = abs(x - tr) + abs(tr - sl); ll res1 = sl < tl ? abs(x - sl) : abs(x - tl); ll res2 = abs(x - sr) + abs(sr - tl); ll res3 = sr < tr ? abs(x - tr) : abs(x - sr); ll res4 = abs(x - tl) + abs(tl - sr); ll res5 = abs(x - sl) + abs(sl - tr); ans = min({res0, res1, res2, res3, res4, res5}); cout << ans << endl; } return 0; }
[ "preprocessor.define.value.change", "literal.integer.change" ]
924,898
924,899
u855087874
cpp
p03112
// need #include <algorithm> #include <iostream> // data structure #include <bitset> #include <complex> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> //#include <deque> #include <array> #include <unordered_map> #include <unordered_set> #include <valarray> // stream //#include <istream> #include <sstream> //#include <ostream> #include <fstream> // etc #include <cassert> #include <chrono> #include <cmath> #include <functional> #include <iomanip> #include <numeric> #include <random> // input #define INIT \ std::ios::sync_with_stdio(false); \ std::cin.tie(0); #define VAR(type, ...) \ type __VA_ARGS__; \ MACRO_VAR_Scan(__VA_ARGS__); template <typename T> void MACRO_VAR_Scan(T &t) { std::cin >> t; } template <typename First, typename... Rest> void MACRO_VAR_Scan(First &first, Rest &...rest) { std::cin >> first; MACRO_VAR_Scan(rest...); } #define VEC_ROW(type, n, ...) \ std::vector<type> __VA_ARGS__; \ MACRO_VEC_ROW_Init(n, __VA_ARGS__); \ for (int w_ = 0; w_ < n; ++w_) { \ MACRO_VEC_ROW_Scan(w_, __VA_ARGS__); \ } template <typename T> void MACRO_VEC_ROW_Init(int n, T &t) { t.resize(n); } template <typename First, typename... Rest> void MACRO_VEC_ROW_Init(int n, First &first, Rest &...rest) { first.resize(n); MACRO_VEC_ROW_Init(n, rest...); } template <typename T> void MACRO_VEC_ROW_Scan(int p, T &t) { std::cin >> t[p]; } template <typename First, typename... Rest> void MACRO_VEC_ROW_Scan(int p, First &first, Rest &...rest) { std::cin >> first[p]; MACRO_VEC_ROW_Scan(p, rest...); } #define VEC(type, c, n) \ std::vector<type> c(n); \ for (auto &i : c) \ std::cin >> i; #define MAT(type, c, m, n) \ std::vector<std::vector<type>> c(m, std::vector<type>(n)); \ for (auto &R : c) \ for (auto &w : R) \ std::cin >> w; // output #define OUT(dist) std::cout << (dist); #define FOUT(n, dist) std::cout << std::fixed << std::setprecision(n) << (dist); #define SOUT(n, c, dist) std::cout << std::setw(n) << std::setfill(c) << (dist); #define SP std::cout << " "; #define TAB std::cout << "\t"; #define BR std::cout << "\n"; #define SPBR(w, n) std::cout << (w + 1 == n ? '\n' : ' '); #define ENDL std::cout << std::endl; #define FLUSH std::cout << std::flush; #define SHOW(dist) \ { std::cerr << #dist << "\t:" << (dist) << "\n"; } #define SHOWVECTOR(v) \ { \ std::cerr << #v << "\t:"; \ for (const auto &xxx : v) { \ std::cerr << xxx << " "; \ } \ std::cerr << "\n"; \ } #define SHOWVECTOR2(v) \ { \ std::cerr << #v << "\t:\n"; \ for (const auto &xxx : v) { \ for (const auto &yyy : xxx) { \ std::cerr << yyy << " "; \ } \ std::cerr << "\n"; \ } \ } #define SHOWQUEUE(a) \ { \ auto tmp(a); \ std::cerr << #a << "\t:"; \ while (!tmp.empty()) { \ std::cerr << tmp.front() << " "; \ tmp.pop(); \ } \ std::cerr << "\n"; \ } // utility #define ALL(a) (a).begin(), (a).end() #define FOR(w, a, n) for (int w = (a); w < (n); ++w) #define RFOR(w, a, n) for (int w = (n)-1; w >= (a); --w) #define REP(w, n) for (int w = 0; w < int(n); ++w) #define RREP(w, n) for (int w = int(n) - 1; w >= 0; --w) #define FORLL(w, a, n) for (ll w = ll(a); w < ll(n); ++w) #define RFORLL(w, a, n) for (ll w = ll(n) - 1; w >= ll(a); --w) #define REPLL(w, n) for (ll w = 0; w < ll(n); ++w) #define RREPLL(w, n) for (ll w = ll(n) - 1; w >= 0; --w) #define IN(a, x, b) (a <= x && x < b) template <class T> inline T CHMAX(T &a, const T b) { return a = (a < b) ? b : a; } template <class T> inline T CHMIN(T &a, const T b) { return a = (a > b) ? b : a; } #define EXCEPTION(msg) \ throw std::string("Exception : " msg " [ in ") + __func__ + " : " + \ std::to_string(__LINE__) + " lines ]" #define TRY(cond, msg) \ try { \ if (cond) \ EXCEPTION(msg); \ } catch (std::string s) { \ std::cerr << s << std::endl; \ } // void CHECKTIME(std::function<void()> f) { auto start = // std::chrono::system_clock::now(); f(); auto end = // std::chrono::system_clock::now(); auto res = // std::chrono::duration_cast<std::chrono::nanoseconds>((end - start)).count(); // std::cerr << "[Time:" << res << "ns (" << res / (1.0e9) << "s)]\n"; } // test template <class T> using V = std::vector<T>; template <class T> using VV = V<V<T>>; template <typename S, typename T> std::ostream &operator<<(std::ostream &os, std::pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define random_shuffle "USE std::shuffle!"; // type/const #define int ll using ll = long long; using ull = unsigned long long; using ld = long double; using PAIR = std::pair<int, int>; using PAIRLL = std::pair<ll, ll>; constexpr int INFINT = 1 << 30; // 1.07x10^ 9 constexpr int INFINT_LIM = (1LL << 31) - 1; // 2.15x10^ 9 constexpr ll INFLL = 1LL << 60; // 1.15x10^18 constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62); // 9.22x10^18 constexpr double EPS = 1e-6; constexpr int MOD = 1000000007; constexpr double PI = 3.141592653589793238462643383279; template <class T, size_t N> void FILL(T (&a)[N], const T &val) { for (auto &x : a) x = val; } template <class ARY, size_t N, size_t M, class T> void FILL(ARY (&a)[N][M], const T &val) { for (auto &b : a) FILL(b, val); } template <class T> void FILL(std::vector<T> &a, const T &val) { for (auto &x : a) x = val; } template <class ARY, class T> void FILL(std::vector<std::vector<ARY>> &a, const T &val) { for (auto &b : a) FILL(b, val); } // ------------>8------------------------------------->8------------ signed main() { INIT; VAR(int, a, b, q); VEC(int, s, a); VEC(int, t, b); REP(_, q) { VAR(int, x); auto f = [&](std::vector<int> &p) { PAIR res(-INFLL, INFLL); auto it = std::lower_bound(ALL(p), x); if (it != s.end()) res.second = *it; if (it != s.begin()) res.first = *(--it); return res; }; auto g = [&](int v, PAIR p) { return std::abs(x - v) + std::min(std::abs(v - p.first), std::abs(v - p.second)); }; auto h = [&](PAIR p, PAIR q) { return std::min(g(p.first, q), g(p.second, q)); }; auto S(f(s)); auto T(f(t)); OUT(std::min(h(S, T), h(T, S))) BR; } return 0; }
// need #include <algorithm> #include <iostream> // data structure #include <bitset> #include <complex> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> //#include <deque> #include <array> #include <unordered_map> #include <unordered_set> #include <valarray> // stream //#include <istream> #include <sstream> //#include <ostream> #include <fstream> // etc #include <cassert> #include <chrono> #include <cmath> #include <functional> #include <iomanip> #include <numeric> #include <random> // input #define INIT \ std::ios::sync_with_stdio(false); \ std::cin.tie(0); #define VAR(type, ...) \ type __VA_ARGS__; \ MACRO_VAR_Scan(__VA_ARGS__); template <typename T> void MACRO_VAR_Scan(T &t) { std::cin >> t; } template <typename First, typename... Rest> void MACRO_VAR_Scan(First &first, Rest &...rest) { std::cin >> first; MACRO_VAR_Scan(rest...); } #define VEC_ROW(type, n, ...) \ std::vector<type> __VA_ARGS__; \ MACRO_VEC_ROW_Init(n, __VA_ARGS__); \ for (int w_ = 0; w_ < n; ++w_) { \ MACRO_VEC_ROW_Scan(w_, __VA_ARGS__); \ } template <typename T> void MACRO_VEC_ROW_Init(int n, T &t) { t.resize(n); } template <typename First, typename... Rest> void MACRO_VEC_ROW_Init(int n, First &first, Rest &...rest) { first.resize(n); MACRO_VEC_ROW_Init(n, rest...); } template <typename T> void MACRO_VEC_ROW_Scan(int p, T &t) { std::cin >> t[p]; } template <typename First, typename... Rest> void MACRO_VEC_ROW_Scan(int p, First &first, Rest &...rest) { std::cin >> first[p]; MACRO_VEC_ROW_Scan(p, rest...); } #define VEC(type, c, n) \ std::vector<type> c(n); \ for (auto &i : c) \ std::cin >> i; #define MAT(type, c, m, n) \ std::vector<std::vector<type>> c(m, std::vector<type>(n)); \ for (auto &R : c) \ for (auto &w : R) \ std::cin >> w; // output #define OUT(dist) std::cout << (dist); #define FOUT(n, dist) std::cout << std::fixed << std::setprecision(n) << (dist); #define SOUT(n, c, dist) std::cout << std::setw(n) << std::setfill(c) << (dist); #define SP std::cout << " "; #define TAB std::cout << "\t"; #define BR std::cout << "\n"; #define SPBR(w, n) std::cout << (w + 1 == n ? '\n' : ' '); #define ENDL std::cout << std::endl; #define FLUSH std::cout << std::flush; #define SHOW(dist) \ { std::cerr << #dist << "\t:" << (dist) << "\n"; } #define SHOWVECTOR(v) \ { \ std::cerr << #v << "\t:"; \ for (const auto &xxx : v) { \ std::cerr << xxx << " "; \ } \ std::cerr << "\n"; \ } #define SHOWVECTOR2(v) \ { \ std::cerr << #v << "\t:\n"; \ for (const auto &xxx : v) { \ for (const auto &yyy : xxx) { \ std::cerr << yyy << " "; \ } \ std::cerr << "\n"; \ } \ } #define SHOWQUEUE(a) \ { \ auto tmp(a); \ std::cerr << #a << "\t:"; \ while (!tmp.empty()) { \ std::cerr << tmp.front() << " "; \ tmp.pop(); \ } \ std::cerr << "\n"; \ } // utility #define ALL(a) (a).begin(), (a).end() #define FOR(w, a, n) for (int w = (a); w < (n); ++w) #define RFOR(w, a, n) for (int w = (n)-1; w >= (a); --w) #define REP(w, n) for (int w = 0; w < int(n); ++w) #define RREP(w, n) for (int w = int(n) - 1; w >= 0; --w) #define FORLL(w, a, n) for (ll w = ll(a); w < ll(n); ++w) #define RFORLL(w, a, n) for (ll w = ll(n) - 1; w >= ll(a); --w) #define REPLL(w, n) for (ll w = 0; w < ll(n); ++w) #define RREPLL(w, n) for (ll w = ll(n) - 1; w >= 0; --w) #define IN(a, x, b) (a <= x && x < b) template <class T> inline T CHMAX(T &a, const T b) { return a = (a < b) ? b : a; } template <class T> inline T CHMIN(T &a, const T b) { return a = (a > b) ? b : a; } #define EXCEPTION(msg) \ throw std::string("Exception : " msg " [ in ") + __func__ + " : " + \ std::to_string(__LINE__) + " lines ]" #define TRY(cond, msg) \ try { \ if (cond) \ EXCEPTION(msg); \ } catch (std::string s) { \ std::cerr << s << std::endl; \ } // void CHECKTIME(std::function<void()> f) { auto start = // std::chrono::system_clock::now(); f(); auto end = // std::chrono::system_clock::now(); auto res = // std::chrono::duration_cast<std::chrono::nanoseconds>((end - start)).count(); // std::cerr << "[Time:" << res << "ns (" << res / (1.0e9) << "s)]\n"; } // test template <class T> using V = std::vector<T>; template <class T> using VV = V<V<T>>; template <typename S, typename T> std::ostream &operator<<(std::ostream &os, std::pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define random_shuffle "USE std::shuffle!"; // type/const #define int ll using ll = long long; using ull = unsigned long long; using ld = long double; using PAIR = std::pair<int, int>; using PAIRLL = std::pair<ll, ll>; constexpr int INFINT = 1 << 30; // 1.07x10^ 9 constexpr int INFINT_LIM = (1LL << 31) - 1; // 2.15x10^ 9 constexpr ll INFLL = 1LL << 60; // 1.15x10^18 constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62); // 9.22x10^18 constexpr double EPS = 1e-6; constexpr int MOD = 1000000007; constexpr double PI = 3.141592653589793238462643383279; template <class T, size_t N> void FILL(T (&a)[N], const T &val) { for (auto &x : a) x = val; } template <class ARY, size_t N, size_t M, class T> void FILL(ARY (&a)[N][M], const T &val) { for (auto &b : a) FILL(b, val); } template <class T> void FILL(std::vector<T> &a, const T &val) { for (auto &x : a) x = val; } template <class ARY, class T> void FILL(std::vector<std::vector<ARY>> &a, const T &val) { for (auto &b : a) FILL(b, val); } // ------------>8------------------------------------->8------------ signed main() { INIT; VAR(int, a, b, q); VEC(int, s, a); VEC(int, t, b); REP(_, q) { VAR(int, x); auto f = [&](std::vector<int> &p) { PAIR res(-INFLL, INFLL); auto it = std::lower_bound(ALL(p), x); if (it != p.end()) res.second = *it; if (it != p.begin()) res.first = *(--it); return res; }; auto g = [&](int v, PAIR p) { return std::abs(x - v) + std::min(std::abs(v - p.first), std::abs(v - p.second)); }; auto h = [&](PAIR p, PAIR q) { return std::min(g(p.first, q), g(p.second, q)); }; auto S(f(s)); auto T(f(t)); OUT(std::min(h(S, T), h(T, S))) BR; } return 0; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
924,900
924,901
u591343832
cpp
p03112
// need #include <algorithm> #include <iostream> // data structure #include <bitset> #include <complex> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> //#include <deque> #include <array> #include <unordered_map> #include <unordered_set> #include <valarray> // stream //#include <istream> #include <sstream> //#include <ostream> #include <fstream> // etc #include <cassert> #include <chrono> #include <cmath> #include <functional> #include <iomanip> #include <numeric> #include <random> // input #define INIT \ std::ios::sync_with_stdio(false); \ std::cin.tie(0); #define VAR(type, ...) \ type __VA_ARGS__; \ MACRO_VAR_Scan(__VA_ARGS__); template <typename T> void MACRO_VAR_Scan(T &t) { std::cin >> t; } template <typename First, typename... Rest> void MACRO_VAR_Scan(First &first, Rest &...rest) { std::cin >> first; MACRO_VAR_Scan(rest...); } #define VEC_ROW(type, n, ...) \ std::vector<type> __VA_ARGS__; \ MACRO_VEC_ROW_Init(n, __VA_ARGS__); \ for (int w_ = 0; w_ < n; ++w_) { \ MACRO_VEC_ROW_Scan(w_, __VA_ARGS__); \ } template <typename T> void MACRO_VEC_ROW_Init(int n, T &t) { t.resize(n); } template <typename First, typename... Rest> void MACRO_VEC_ROW_Init(int n, First &first, Rest &...rest) { first.resize(n); MACRO_VEC_ROW_Init(n, rest...); } template <typename T> void MACRO_VEC_ROW_Scan(int p, T &t) { std::cin >> t[p]; } template <typename First, typename... Rest> void MACRO_VEC_ROW_Scan(int p, First &first, Rest &...rest) { std::cin >> first[p]; MACRO_VEC_ROW_Scan(p, rest...); } #define VEC(type, c, n) \ std::vector<type> c(n); \ for (auto &i : c) \ std::cin >> i; #define MAT(type, c, m, n) \ std::vector<std::vector<type>> c(m, std::vector<type>(n)); \ for (auto &R : c) \ for (auto &w : R) \ std::cin >> w; // output #define OUT(dist) std::cout << (dist); #define FOUT(n, dist) std::cout << std::fixed << std::setprecision(n) << (dist); #define SOUT(n, c, dist) std::cout << std::setw(n) << std::setfill(c) << (dist); #define SP std::cout << " "; #define TAB std::cout << "\t"; #define BR std::cout << "\n"; #define SPBR(w, n) std::cout << (w + 1 == n ? '\n' : ' '); #define ENDL std::cout << std::endl; #define FLUSH std::cout << std::flush; #define SHOW(dist) \ { std::cerr << #dist << "\t:" << (dist) << "\n"; } #define SHOWVECTOR(v) \ { \ std::cerr << #v << "\t:"; \ for (const auto &xxx : v) { \ std::cerr << xxx << " "; \ } \ std::cerr << "\n"; \ } #define SHOWVECTOR2(v) \ { \ std::cerr << #v << "\t:\n"; \ for (const auto &xxx : v) { \ for (const auto &yyy : xxx) { \ std::cerr << yyy << " "; \ } \ std::cerr << "\n"; \ } \ } #define SHOWQUEUE(a) \ { \ auto tmp(a); \ std::cerr << #a << "\t:"; \ while (!tmp.empty()) { \ std::cerr << tmp.front() << " "; \ tmp.pop(); \ } \ std::cerr << "\n"; \ } // utility #define ALL(a) (a).begin(), (a).end() #define FOR(w, a, n) for (int w = (a); w < (n); ++w) #define RFOR(w, a, n) for (int w = (n)-1; w >= (a); --w) #define REP(w, n) for (int w = 0; w < int(n); ++w) #define RREP(w, n) for (int w = int(n) - 1; w >= 0; --w) #define FORLL(w, a, n) for (ll w = ll(a); w < ll(n); ++w) #define RFORLL(w, a, n) for (ll w = ll(n) - 1; w >= ll(a); --w) #define REPLL(w, n) for (ll w = 0; w < ll(n); ++w) #define RREPLL(w, n) for (ll w = ll(n) - 1; w >= 0; --w) #define IN(a, x, b) (a <= x && x < b) template <class T> inline T CHMAX(T &a, const T b) { return a = (a < b) ? b : a; } template <class T> inline T CHMIN(T &a, const T b) { return a = (a > b) ? b : a; } #define EXCEPTION(msg) \ throw std::string("Exception : " msg " [ in ") + __func__ + " : " + \ std::to_string(__LINE__) + " lines ]" #define TRY(cond, msg) \ try { \ if (cond) \ EXCEPTION(msg); \ } catch (std::string s) { \ std::cerr << s << std::endl; \ } // void CHECKTIME(std::function<void()> f) { auto start = // std::chrono::system_clock::now(); f(); auto end = // std::chrono::system_clock::now(); auto res = // std::chrono::duration_cast<std::chrono::nanoseconds>((end - start)).count(); // std::cerr << "[Time:" << res << "ns (" << res / (1.0e9) << "s)]\n"; } // test template <class T> using V = std::vector<T>; template <class T> using VV = V<V<T>>; template <typename S, typename T> std::ostream &operator<<(std::ostream &os, std::pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define random_shuffle "USE std::shuffle!"; // type/const #define int ll using ll = long long; using ull = unsigned long long; using ld = long double; using PAIR = std::pair<int, int>; using PAIRLL = std::pair<ll, ll>; constexpr int INFINT = 1 << 30; // 1.07x10^ 9 constexpr int INFINT_LIM = (1LL << 31) - 1; // 2.15x10^ 9 constexpr ll INFLL = 1LL << 60; // 1.15x10^18 constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62); // 9.22x10^18 constexpr double EPS = 1e-6; constexpr int MOD = 1000000007; constexpr double PI = 3.141592653589793238462643383279; template <class T, size_t N> void FILL(T (&a)[N], const T &val) { for (auto &x : a) x = val; } template <class ARY, size_t N, size_t M, class T> void FILL(ARY (&a)[N][M], const T &val) { for (auto &b : a) FILL(b, val); } template <class T> void FILL(std::vector<T> &a, const T &val) { for (auto &x : a) x = val; } template <class ARY, class T> void FILL(std::vector<std::vector<ARY>> &a, const T &val) { for (auto &b : a) FILL(b, val); } // ------------>8------------------------------------->8------------ signed main() { INIT; VAR(int, a, b, q); VEC(int, s, a); VEC(int, t, b); REP(_, q) { VAR(int, x); auto f = [&](std::vector<int> &p) { PAIR res(-INFLL, INFLL); auto it = std::lower_bound(ALL(p), x); if (it != s.end()) res.second = *it; if (it != s.begin()) res.first = *(--it); return res; }; auto g = [&](int v, PAIR p) { return std::abs(x - v) + std::min(std::abs(v - p.first), std::abs(v - p.second)); }; auto h = [&](PAIR p, PAIR q) { return std::min(g(p.first, q), g(p.second, q)); }; auto S(f(s)); auto T(f(t)); OUT(std::min(h(S, T), h(T, S))) BR; } return 0; }
// need #include <algorithm> #include <iostream> // data structure #include <bitset> #include <complex> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> //#include <deque> #include <array> #include <unordered_map> #include <unordered_set> #include <valarray> // stream //#include <istream> #include <sstream> //#include <ostream> #include <fstream> // etc #include <cassert> #include <chrono> #include <cmath> #include <functional> #include <iomanip> #include <numeric> #include <random> // input #define INIT \ std::ios::sync_with_stdio(false); \ std::cin.tie(0); #define VAR(type, ...) \ type __VA_ARGS__; \ MACRO_VAR_Scan(__VA_ARGS__); template <typename T> void MACRO_VAR_Scan(T &t) { std::cin >> t; } template <typename First, typename... Rest> void MACRO_VAR_Scan(First &first, Rest &...rest) { std::cin >> first; MACRO_VAR_Scan(rest...); } #define VEC_ROW(type, n, ...) \ std::vector<type> __VA_ARGS__; \ MACRO_VEC_ROW_Init(n, __VA_ARGS__); \ for (int w_ = 0; w_ < n; ++w_) { \ MACRO_VEC_ROW_Scan(w_, __VA_ARGS__); \ } template <typename T> void MACRO_VEC_ROW_Init(int n, T &t) { t.resize(n); } template <typename First, typename... Rest> void MACRO_VEC_ROW_Init(int n, First &first, Rest &...rest) { first.resize(n); MACRO_VEC_ROW_Init(n, rest...); } template <typename T> void MACRO_VEC_ROW_Scan(int p, T &t) { std::cin >> t[p]; } template <typename First, typename... Rest> void MACRO_VEC_ROW_Scan(int p, First &first, Rest &...rest) { std::cin >> first[p]; MACRO_VEC_ROW_Scan(p, rest...); } #define VEC(type, c, n) \ std::vector<type> c(n); \ for (auto &i : c) \ std::cin >> i; #define MAT(type, c, m, n) \ std::vector<std::vector<type>> c(m, std::vector<type>(n)); \ for (auto &R : c) \ for (auto &w : R) \ std::cin >> w; // output #define OUT(dist) std::cout << (dist); #define FOUT(n, dist) std::cout << std::fixed << std::setprecision(n) << (dist); #define SOUT(n, c, dist) std::cout << std::setw(n) << std::setfill(c) << (dist); #define SP std::cout << " "; #define TAB std::cout << "\t"; #define BR std::cout << "\n"; #define SPBR(w, n) std::cout << (w + 1 == n ? '\n' : ' '); #define ENDL std::cout << std::endl; #define FLUSH std::cout << std::flush; #define SHOW(dist) \ { std::cerr << #dist << "\t:" << (dist) << "\n"; } #define SHOWVECTOR(v) \ { \ std::cerr << #v << "\t:"; \ for (const auto &xxx : v) { \ std::cerr << xxx << " "; \ } \ std::cerr << "\n"; \ } #define SHOWVECTOR2(v) \ { \ std::cerr << #v << "\t:\n"; \ for (const auto &xxx : v) { \ for (const auto &yyy : xxx) { \ std::cerr << yyy << " "; \ } \ std::cerr << "\n"; \ } \ } #define SHOWQUEUE(a) \ { \ auto tmp(a); \ std::cerr << #a << "\t:"; \ while (!tmp.empty()) { \ std::cerr << tmp.front() << " "; \ tmp.pop(); \ } \ std::cerr << "\n"; \ } // utility #define ALL(a) (a).begin(), (a).end() #define FOR(w, a, n) for (int w = (a); w < (n); ++w) #define RFOR(w, a, n) for (int w = (n)-1; w >= (a); --w) #define REP(w, n) for (int w = 0; w < int(n); ++w) #define RREP(w, n) for (int w = int(n) - 1; w >= 0; --w) #define FORLL(w, a, n) for (ll w = ll(a); w < ll(n); ++w) #define RFORLL(w, a, n) for (ll w = ll(n) - 1; w >= ll(a); --w) #define REPLL(w, n) for (ll w = 0; w < ll(n); ++w) #define RREPLL(w, n) for (ll w = ll(n) - 1; w >= 0; --w) #define IN(a, x, b) (a <= x && x < b) template <class T> inline T CHMAX(T &a, const T b) { return a = (a < b) ? b : a; } template <class T> inline T CHMIN(T &a, const T b) { return a = (a > b) ? b : a; } #define EXCEPTION(msg) \ throw std::string("Exception : " msg " [ in ") + __func__ + " : " + \ std::to_string(__LINE__) + " lines ]" #define TRY(cond, msg) \ try { \ if (cond) \ EXCEPTION(msg); \ } catch (std::string s) { \ std::cerr << s << std::endl; \ } // void CHECKTIME(std::function<void()> f) { auto start = // std::chrono::system_clock::now(); f(); auto end = // std::chrono::system_clock::now(); auto res = // std::chrono::duration_cast<std::chrono::nanoseconds>((end - start)).count(); // std::cerr << "[Time:" << res << "ns (" << res / (1.0e9) << "s)]\n"; } // test template <class T> using V = std::vector<T>; template <class T> using VV = V<V<T>>; template <typename S, typename T> std::ostream &operator<<(std::ostream &os, std::pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define random_shuffle "USE std::shuffle!"; // type/const #define int ll using ll = long long; using ull = unsigned long long; using ld = long double; using PAIR = std::pair<int, int>; using PAIRLL = std::pair<ll, ll>; constexpr int INFINT = 1 << 30; // 1.07x10^ 9 constexpr int INFINT_LIM = (1LL << 31) - 1; // 2.15x10^ 9 constexpr ll INFLL = 1LL << 60; // 1.15x10^18 constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62); // 9.22x10^18 constexpr double EPS = 1e-6; constexpr int MOD = 1000000007; constexpr double PI = 3.141592653589793238462643383279; template <class T, size_t N> void FILL(T (&a)[N], const T &val) { for (auto &x : a) x = val; } template <class ARY, size_t N, size_t M, class T> void FILL(ARY (&a)[N][M], const T &val) { for (auto &b : a) FILL(b, val); } template <class T> void FILL(std::vector<T> &a, const T &val) { for (auto &x : a) x = val; } template <class ARY, class T> void FILL(std::vector<std::vector<ARY>> &a, const T &val) { for (auto &b : a) FILL(b, val); } // ------------>8------------------------------------->8------------ signed main() { INIT; VAR(int, a, b, q); VEC(int, s, a); VEC(int, t, b); REP(_, q) { VAR(int, x); auto f = [&](std::vector<int> &p) { PAIR res(-INFLL, INFLL); auto it = std::lower_bound(ALL(p), x); if (it != p.end()) res.second = *it; if (it != p.begin()) res.first = *(--it); return res; }; auto g = [&](int v, PAIR p) { return std::abs(x - v) + std::min(std::abs(v - p.first), std::abs(v - p.second)); }; auto h = [&](PAIR p, PAIR q) { return std::min(g(p.first, q), g(p.second, q)); }; auto S(f(s)); auto T(f(t)); OUT(std::min(h(S, T), h(T, S))) BR; } return 0; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
924,900
924,902
u591343832
cpp
p03112
#include <bits/stdc++.h> using namespace std; #define MD 1000000007 typedef long long int ll; typedef pair<ll, ll> P; template <typename T> std::string tostr(const T &t) { std::ostringstream os; os << t; return os.str(); } int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int main() { ll A, B, Q, x; cin >> A >> B >> Q; // INF用に余分に配列を用意しておく vector<ll> s(A + 2), t(B + 2); for (int i = 1; i <= A; i++) { cin >> s[i]; } s[0] = -1; s[A + 1] = 1e12; for (int i = 1; i <= B; i++) { cin >> t[i]; } t[0] = -1; t[B + 1] = 1e12; vector<ll> ans(Q); for (int i = 0; i < Q; i++) { cin >> x; // x以上の要素を持つ中で最小値のインデックス //マイナスのs.begin()をすることでインデックスにしている auto c = lower_bound(s.begin(), s.end(), x) - s.begin(); auto d = lower_bound(t.begin(), t.end(), x) - t.begin(); ll tmp = 1e18; // xちょうど,もしくは一個右側の要素を参照しているから //インデックスはc-1もしくはcしか見る必要はない for (int j = c - 1; j < c + 1; j++) { for (int k = d - 1; k < d + 1; k++) { tmp = min(tmp, abs(x - s[j]) + abs(s[j] - t[k])); tmp = min(tmp, abs(x - t[k]) + abs(t[k] - s[j])); } } ans[i] = tmp; } for (int i = 0; i < Q; i++) { cout << ans[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define MD 1000000007 typedef long long int ll; typedef pair<ll, ll> P; template <typename T> std::string tostr(const T &t) { std::ostringstream os; os << t; return os.str(); } int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int main() { ll A, B, Q, x; cin >> A >> B >> Q; // INF用に余分に配列を用意しておく vector<ll> s(A + 2), t(B + 2); for (int i = 1; i <= A; i++) { cin >> s[i]; } s[0] = -1e12; s[A + 1] = 1e12; for (int i = 1; i <= B; i++) { cin >> t[i]; } t[0] = -1e12; t[B + 1] = 1e12; vector<ll> ans(Q); for (int i = 0; i < Q; i++) { cin >> x; // x以上の要素を持つ中で最小値のインデックス //マイナスのs.begin()をすることでインデックスにしている auto c = lower_bound(s.begin(), s.end(), x) - s.begin(); auto d = lower_bound(t.begin(), t.end(), x) - t.begin(); ll tmp = 1e18; // xちょうど,もしくは一個右側の要素を参照しているから //インデックスはc-1もしくはcしか見る必要はない for (int j = c - 1; j < c + 1; j++) { for (int k = d - 1; k < d + 1; k++) { tmp = min(tmp, abs(x - s[j]) + abs(s[j] - t[k])); tmp = min(tmp, abs(x - t[k]) + abs(t[k] - s[j])); } } ans[i] = tmp; } for (int i = 0; i < Q; i++) { cout << ans[i] << endl; } return 0; }
[ "literal.number.change", "assignment.value.change" ]
924,903
924,904
u287060310
cpp
p03112
#include <bits/stdc++.h> using namespace std; const long long INF = 2E17; typedef pair<int, int> Pair; typedef long long int LL; void binarySearch(const array<LL, 100100> &L, LL x, int n, LL ret[]) { int left = 0; int right = n - 1; while (right - left != 1) { int mid = (left + right) / 2; if (x < L[mid]) { right = mid; } else left = mid; } ret[0] = L[left]; ret[1] = L[right]; } int main() { int A, B, Q; array<LL, 100100> s, t; cin >> A >> B >> Q; for (int i = 0; i < A; i++) { scanf("%lld", &s[i]); } s[A] = INF; s[A + 1] = -INF; for (int i = 0; i < B; i++) { scanf("%lld", &t[i]); } t[B] = INF; t[B + 1] = -INF; sort(s.begin(), s.begin() + A + 2); sort(t.begin(), t.begin() + A + 2); LL x; LL Jin[2]; LL Tera[2]; LL ans; for (int i = 0; i < Q; i++) { scanf("%lld", &x); binarySearch(s, x, A + 2, Jin); binarySearch(t, x, B + 2, Tera); ans = INF; for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { ans = min(ans, abs(Jin[j] - x) + abs(Tera[k] - Jin[j])); ans = min(ans, abs(Tera[k] - x) + abs(Tera[k] - Jin[j])); } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 2E17; typedef pair<int, int> Pair; typedef long long int LL; void binarySearch(const array<LL, 100100> &L, LL x, int n, LL ret[]) { int left = 0; int right = n - 1; while (right - left != 1) { int mid = (left + right) / 2; if (x < L[mid]) { right = mid; } else left = mid; } ret[0] = L[left]; ret[1] = L[right]; } int main() { int A, B, Q; array<LL, 100100> s, t; cin >> A >> B >> Q; for (int i = 0; i < A; i++) { scanf("%lld", &s[i]); } s[A] = INF; s[A + 1] = -INF; for (int i = 0; i < B; i++) { scanf("%lld", &t[i]); } t[B] = INF; t[B + 1] = -INF; sort(s.begin(), s.begin() + A + 2); sort(t.begin(), t.begin() + B + 2); LL x; LL Jin[2]; LL Tera[2]; LL ans; for (int i = 0; i < Q; i++) { scanf("%lld", &x); binarySearch(s, x, A + 2, Jin); binarySearch(t, x, B + 2, Tera); ans = INF; for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { ans = min(ans, abs(Jin[j] - x) + abs(Tera[k] - Jin[j])); ans = min(ans, abs(Tera[k] - x) + abs(Tera[k] - Jin[j])); } } cout << ans << endl; } return 0; }
[ "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
924,919
924,920
u651032293
cpp
p03112
#include <bits/stdc++.h> using namespace std; const long long INF = 2E12; typedef pair<int, int> Pair; typedef long long int LL; void binarySearch(const array<LL, 100100> &L, LL x, int n, LL ret[]) { int left = 0; int right = n - 1; while (right - left != 1) { int mid = (left + right) / 2; if (x < L[mid]) { right = mid; } else left = mid; } ret[0] = L[left]; ret[1] = L[right]; } int main() { int A, B, Q; array<LL, 100100> s, t; cin >> A >> B >> Q; for (int i = 0; i < A; i++) { scanf("%lld", &s[i]); } s[A] = INF; s[A + 1] = -INF; for (int i = 0; i < B; i++) { scanf("%lld", &t[i]); } t[B] = INF; t[B + 1] = -INF; sort(s.begin(), s.begin() + A + 2); sort(t.begin(), t.begin() + A + 2); LL x; LL Jin[2]; LL Tera[2]; LL ans; for (int i = 0; i < Q; i++) { scanf("%lld", &x); binarySearch(s, x, A + 2, Jin); binarySearch(t, x, B + 2, Tera); ans = INF; for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { ans = min(ans, abs(Jin[j] - x) + abs(Tera[k] - Jin[j])); ans = min(ans, abs(Tera[k] - x) + abs(Tera[k] - Jin[j])); } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 2E17; typedef pair<int, int> Pair; typedef long long int LL; void binarySearch(const array<LL, 100100> &L, LL x, int n, LL ret[]) { int left = 0; int right = n - 1; while (right - left != 1) { int mid = (left + right) / 2; if (x < L[mid]) { right = mid; } else left = mid; } ret[0] = L[left]; ret[1] = L[right]; } int main() { int A, B, Q; array<LL, 100100> s, t; cin >> A >> B >> Q; for (int i = 0; i < A; i++) { scanf("%lld", &s[i]); } s[A] = INF; s[A + 1] = -INF; for (int i = 0; i < B; i++) { scanf("%lld", &t[i]); } t[B] = INF; t[B + 1] = -INF; sort(s.begin(), s.begin() + A + 2); sort(t.begin(), t.begin() + B + 2); LL x; LL Jin[2]; LL Tera[2]; LL ans; for (int i = 0; i < Q; i++) { scanf("%lld", &x); binarySearch(s, x, A + 2, Jin); binarySearch(t, x, B + 2, Tera); ans = INF; for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { ans = min(ans, abs(Jin[j] - x) + abs(Tera[k] - Jin[j])); ans = min(ans, abs(Tera[k] - x) + abs(Tera[k] - Jin[j])); } } cout << ans << endl; } return 0; }
[ "literal.number.change", "variable_declaration.value.change", "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
924,921
924,920
u651032293
cpp
p03112
#include <bits/stdc++.h> using namespace std; const long long INF = 2E12; typedef pair<int, int> Pair; typedef long long int LL; void binarySearch(const array<LL, 100100> &L, LL x, int n, LL ret[]) { int left = 0; int right = n; while (right - left != 1) { int mid = (left + right) / 2; if (x < L[mid]) { right = mid; } else left = mid; } ret[0] = L[left]; ret[1] = L[right]; } int main() { int A, B, Q; array<LL, 100100> s, t; cin >> A >> B >> Q; for (int i = 0; i < A; i++) { scanf("%lld", &s[i]); } s[A] = INF; s[A + 1] = -INF; for (int i = 0; i < B; i++) { scanf("%lld", &t[i]); } t[B] = INF; t[B + 1] = -INF; sort(s.begin(), s.begin() + A + 2); sort(t.begin(), t.begin() + A + 2); LL x; LL Jin[2]; LL Tera[2]; LL ans; for (int i = 0; i < Q; i++) { scanf("%lld", &x); binarySearch(s, x, A + 2, Jin); binarySearch(t, x, B + 2, Tera); ans = INF; for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { ans = min(ans, abs(Jin[j] - x) + abs(Tera[k] - Jin[j])); ans = min(ans, abs(Tera[k] - x) + abs(Tera[k] - Jin[j])); } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 2E17; typedef pair<int, int> Pair; typedef long long int LL; void binarySearch(const array<LL, 100100> &L, LL x, int n, LL ret[]) { int left = 0; int right = n - 1; while (right - left != 1) { int mid = (left + right) / 2; if (x < L[mid]) { right = mid; } else left = mid; } ret[0] = L[left]; ret[1] = L[right]; } int main() { int A, B, Q; array<LL, 100100> s, t; cin >> A >> B >> Q; for (int i = 0; i < A; i++) { scanf("%lld", &s[i]); } s[A] = INF; s[A + 1] = -INF; for (int i = 0; i < B; i++) { scanf("%lld", &t[i]); } t[B] = INF; t[B + 1] = -INF; sort(s.begin(), s.begin() + A + 2); sort(t.begin(), t.begin() + B + 2); LL x; LL Jin[2]; LL Tera[2]; LL ans; for (int i = 0; i < Q; i++) { scanf("%lld", &x); binarySearch(s, x, A + 2, Jin); binarySearch(t, x, B + 2, Tera); ans = INF; for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { ans = min(ans, abs(Jin[j] - x) + abs(Tera[k] - Jin[j])); ans = min(ans, abs(Tera[k] - x) + abs(Tera[k] - Jin[j])); } } cout << ans << endl; } return 0; }
[ "literal.number.change", "variable_declaration.value.change", "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
924,922
924,920
u651032293
cpp
p03112
#include <bits/stdc++.h> using namespace std; const long long INF = 2E11; typedef pair<int, int> Pair; typedef long long int LL; void binarySearch(const array<LL, 100100> &L, LL x, int n, LL ret[]) { int left = 0; int right = n; while (right - left != 1) { int mid = (left + right) / 2; if (x < L[mid]) { right = mid; } else left = mid; } ret[0] = L[left]; ret[1] = L[right]; } int main() { int A, B, Q; array<LL, 100100> s, t; cin >> A >> B >> Q; for (int i = 0; i < A; i++) { scanf("%lld", &s[i]); } s[A] = INF; s[A + 1] = -INF; for (int i = 0; i < B; i++) { scanf("%lld", &t[i]); } t[B] = INF; t[B + 1] = -INF; sort(s.begin(), s.begin() + A + 2); sort(t.begin(), t.begin() + A + 2); LL x; LL Jin[2]; LL Tera[2]; LL ans; for (int i = 0; i < Q; i++) { scanf("%lld", &x); binarySearch(s, x, A + 2, Jin); binarySearch(t, x, B + 2, Tera); ans = INF; for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { ans = min(ans, abs(Jin[j] - x) + abs(Tera[k] - Jin[j])); ans = min(ans, abs(Tera[k] - x) + abs(Tera[k] - Jin[j])); } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 2E17; typedef pair<int, int> Pair; typedef long long int LL; void binarySearch(const array<LL, 100100> &L, LL x, int n, LL ret[]) { int left = 0; int right = n - 1; while (right - left != 1) { int mid = (left + right) / 2; if (x < L[mid]) { right = mid; } else left = mid; } ret[0] = L[left]; ret[1] = L[right]; } int main() { int A, B, Q; array<LL, 100100> s, t; cin >> A >> B >> Q; for (int i = 0; i < A; i++) { scanf("%lld", &s[i]); } s[A] = INF; s[A + 1] = -INF; for (int i = 0; i < B; i++) { scanf("%lld", &t[i]); } t[B] = INF; t[B + 1] = -INF; sort(s.begin(), s.begin() + A + 2); sort(t.begin(), t.begin() + B + 2); LL x; LL Jin[2]; LL Tera[2]; LL ans; for (int i = 0; i < Q; i++) { scanf("%lld", &x); binarySearch(s, x, A + 2, Jin); binarySearch(t, x, B + 2, Tera); ans = INF; for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { ans = min(ans, abs(Jin[j] - x) + abs(Tera[k] - Jin[j])); ans = min(ans, abs(Tera[k] - x) + abs(Tera[k] - Jin[j])); } } cout << ans << endl; } return 0; }
[ "literal.number.change", "variable_declaration.value.change", "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
924,923
924,920
u651032293
cpp
p03112
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) int main() { // cout.precision(11); int A, B, Q; cin >> A >> B >> Q; vector<ll> s(A + 1), t(B + 1), x(Q); s[0] = -INF; t[0] = -INF; for (int i = 0; i < A; ++i) cin >> s[i + 1]; for (int i = 0; i < B; ++i) cin >> t[i + 1]; for (int i = 0; i < Q; ++i) cin >> x[i]; for (int k = 0; k < Q; k++) { ll sp[2], tp[2]; auto sit = lower_bound(s.begin(), s.end(), x[k]); auto tit = lower_bound(t.begin(), t.end(), x[k]); sp[0] = *(sit - 1); sp[1] = *sit; tp[0] = *(tit - 1); tp[1] = *tit; ll ans = INF; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { ans = min(ans, abs(sp[i] - tp[j]) + min(abs(sp[i] - x[k]), abs(tp[j] - x[k]))); } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define EPS (1e-7) #define INF (1e16) #define PI (acos(-1)) int main() { // cout.precision(11); int A, B, Q; cin >> A >> B >> Q; vector<ll> s(A + 1), t(B + 1), x(Q); s[0] = -INF; t[0] = -INF; for (int i = 0; i < A; ++i) cin >> s[i + 1]; for (int i = 0; i < B; ++i) cin >> t[i + 1]; for (int i = 0; i < Q; ++i) cin >> x[i]; for (int k = 0; k < Q; k++) { ll sp[2], tp[2]; auto sit = lower_bound(s.begin(), s.end(), x[k]); auto tit = lower_bound(t.begin(), t.end(), x[k]); sp[0] = *(sit - 1); sp[1] = *sit; tp[0] = *(tit - 1); tp[1] = *tit; ll ans = INF; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { ans = min(ans, abs(sp[i] - tp[j]) + min(abs(sp[i] - x[k]), abs(tp[j] - x[k]))); } } cout << ans << endl; } return 0; }
[ "preprocessor.define.value.change", "literal.float.change" ]
924,941
924,942
u529560649
cpp
p03112
#include <algorithm> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <vector> using namespace std; using ll = long long; using ld = long double; using P = pair<ll, ll>; using T = tuple<ll, ll, ll>; const ll INF = 1e15; const ld eps = 1e-6; int main() { ll A, B, Q; cin >> A >> B >> Q; set<ll> ast; for (int i = 0; i < A; i++) { ll x; cin >> x; ast.insert(x); } set<ll> bst; for (int i = 0; i < B; i++) { ll x; cin >> x; bst.insert(x); } ast.insert(-INF); ast.insert(INF); bst.insert(-INF); bst.insert(INF); for (int i = 0; i < Q; i++) { ll q; cin >> q; auto ia = ast.lower_bound(q); ll ra = *ia; ia--; ll la = *ia; auto ib = bst.lower_bound(q); ll rb = *ib; ib--; ll lb = *ib; ll ans = min({max(rb, ra) - q, q - min(lb, la), min(q - la, rb - q) + rb - la, min(ra - q, q - lb) + ra - la}); cout << ans << endl; } return 0; }
#include <algorithm> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <vector> using namespace std; using ll = long long; using ld = long double; using P = pair<ll, ll>; using T = tuple<ll, ll, ll>; const ll INF = 1e15; const ld eps = 1e-6; int main() { ll A, B, Q; cin >> A >> B >> Q; set<ll> ast; for (int i = 0; i < A; i++) { ll x; cin >> x; ast.insert(x); } set<ll> bst; for (int i = 0; i < B; i++) { ll x; cin >> x; bst.insert(x); } ast.insert(-INF); ast.insert(INF); bst.insert(-INF); bst.insert(INF); for (int i = 0; i < Q; i++) { ll q; cin >> q; auto ia = ast.lower_bound(q); ll ra = *ia; ia--; ll la = *ia; auto ib = bst.lower_bound(q); ll rb = *ib; ib--; ll lb = *ib; ll ans = min({max(rb, ra) - q, q - min(lb, la), min(q - la, rb - q) + rb - la, min(ra - q, q - lb) + ra - lb}); cout << ans << endl; } return 0; }
[ "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
924,945
924,946
u287305727
cpp
p03112
#include <algorithm> #include <iostream> #include <vector> #define ll long long int using namespace std; int A, B, Q; int main() { cin >> A >> B >> Q; vector<ll> s(A), t(B), X(Q); for (int i = 0; i < A; i++) { cin >> s[i]; } for (int i = 0; i < B; i++) { cin >> t[i]; } for (int i = 0; i < Q; i++) { cin >> X[i]; } for (int i = 0; i < Q; i++) { ll x = X[i]; ll east_s, east_t, west_s, west_t; auto Iter_s = lower_bound(s.begin(), s.end(), x); auto Iter_t = lower_bound(t.begin(), t.end(), x); if (Iter_s - s.begin() == 0) { west_s = 20000000000; } else { west_s = x - s[Iter_s - s.begin() - 1]; } if (Iter_t - t.begin() == 0) { west_t = 20000000000; } else { west_t = x - t[Iter_t - t.begin() - 1]; } if (Iter_s - s.begin() == s.size()) { east_s = 20000000000; } else { east_s = s[Iter_s - s.begin()]; } if (Iter_t - t.begin() == t.size()) { east_t = 20000000000; } else { east_t = t[Iter_t - t.begin()] - x; } ll ww, ws, sw, ss; ww = max(west_t, west_s); if (west_t < east_s) { ws = 2 * west_t + east_s; } else ws = west_t + 2 * east_s; if (east_t < west_s) { sw = 2 * east_t + west_s; } else sw = east_t + 2 * west_s; ss = max(east_t, east_s); cout << min({ww, ws, sw, ss}) << endl; } return 0; }
#include <algorithm> #include <iostream> #include <vector> #define ll long long int using namespace std; int A, B, Q; int main() { cin >> A >> B >> Q; vector<ll> s(A), t(B), X(Q); for (int i = 0; i < A; i++) { cin >> s[i]; } for (int i = 0; i < B; i++) { cin >> t[i]; } for (int i = 0; i < Q; i++) { cin >> X[i]; } for (int i = 0; i < Q; i++) { ll x = X[i]; ll east_s, east_t, west_s, west_t; auto Iter_s = lower_bound(s.begin(), s.end(), x); auto Iter_t = lower_bound(t.begin(), t.end(), x); if (Iter_s - s.begin() == 0) { west_s = 20000000000; } else { west_s = x - s[Iter_s - s.begin() - 1]; } if (Iter_t - t.begin() == 0) { west_t = 20000000000; } else { west_t = x - t[Iter_t - t.begin() - 1]; } if (Iter_s - s.begin() == s.size()) { east_s = 20000000000; } else { east_s = s[Iter_s - s.begin()] - x; } if (Iter_t - t.begin() == t.size()) { east_t = 20000000000; } else { east_t = t[Iter_t - t.begin()] - x; } ll ww, ws, sw, ss; ww = max(west_t, west_s); if (west_t < east_s) { ws = 2 * west_t + east_s; } else ws = west_t + 2 * east_s; if (east_t < west_s) { sw = 2 * east_t + west_s; } else sw = east_t + 2 * west_s; ss = max(east_t, east_s); cout << min({ww, ws, sw, ss}) << endl; } return 0; }
[ "assignment.change" ]
924,947
924,948
u564056510
cpp
p03112
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int long long #define mk make_pair #define pb push_back #define pf push_front #define ff first.first #define fs first.second #define sf second.first #define ss second.second typedef pair<int, int> pii; const int mod = 1000000007; const int INF = 1000000009; const long long INFL = 1000000000000000018ll; int A, B, Q, s[100100], t[100100]; signed main() { cin >> A >> B >> Q; A++; B++; s[0] = -INFL; t[0] = -INFL; for (int i = 1; i < A; i++) { cin >> s[i]; } for (int i = 1; i < B; i++) { cin >> t[i]; } s[A] = INFL; t[A] = INFL; for (int i = 0; i < Q; i++) { int x; cin >> x; int cursr = lower_bound(s, s + A, x) - s; int cursl = cursr - 1; int curtr = lower_bound(t, t + B, x) - t; int curtl = curtr - 1; int a = s[cursr]; int b = s[cursl]; int c = t[curtr]; int d = t[curtl]; vector<int> v; v.pb(max(a, c) - x); v.pb(x - min(b, d)); v.pb(a - x + 2 * (x - d)); v.pb(x - d + 2 * (a - x)); v.pb(c - x + 2 * (x - b)); v.pb(x - b + 2 * (c - x)); sort(v.begin(), v.end()); printf("%lld\n", v[0]); } return 0; } /* */
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int long long #define mk make_pair #define pb push_back #define pf push_front #define ff first.first #define fs first.second #define sf second.first #define ss second.second typedef pair<int, int> pii; const int mod = 1000000007; const int INF = 1000000009; const long long INFL = 1000000000000000018ll; int A, B, Q, s[100100], t[100100]; signed main() { cin >> A >> B >> Q; A++; B++; s[0] = -INFL; t[0] = -INFL; for (int i = 1; i < A; i++) { cin >> s[i]; } for (int i = 1; i < B; i++) { cin >> t[i]; } s[A] = INFL; t[B] = INFL; for (int i = 0; i < Q; i++) { int x; cin >> x; int cursr = lower_bound(s, s + A, x) - s; int cursl = cursr - 1; int curtr = lower_bound(t, t + B, x) - t; int curtl = curtr - 1; int a = s[cursr]; int b = s[cursl]; int c = t[curtr]; int d = t[curtl]; vector<int> v; v.pb(max(a, c) - x); v.pb(x - min(b, d)); v.pb(a - x + 2 * (x - d)); v.pb(x - d + 2 * (a - x)); v.pb(c - x + 2 * (x - b)); v.pb(x - b + 2 * (c - x)); sort(v.begin(), v.end()); printf("%lld\n", v[0]); } return 0; } /* */
[ "assignment.variable.change", "identifier.change", "variable_access.subscript.index.change" ]
924,949
924,950
u384299515
cpp
p03112
#include <bits/stdc++.h> using namespace std; int binary_search(vector<long long> &n, int x) { int ok = (int)n.size(); int ng = -1; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (n[mid] >= x) ok = mid; else ng = mid; } if (ok == (int)n.size()) ok--; return ok; } int main() { int a, b, q; cin >> a >> b >> q; vector<long long> shrine(a); for (int i = 0; i < a; i++) cin >> shrine[i]; vector<long long> temple(b); for (int i = 0; i < b; i++) cin >> temple[i]; for (int i = 0; i < q; i++) { int x; cin >> x; vector<long long> sh(2); vector<long long> tem(2); int v, w; v = binary_search(shrine, x); w = binary_search(temple, x); sh[0] = shrine[v]; sh[1] = shrine[max(0, v - 1)]; tem[0] = temple[w]; tem[1] = temple[max(0, w - 1)]; long long ans = 1000000000000; for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { long long s = sh[j]; long long t = tem[k]; if (t > s) swap(s, t); if (x <= t || x >= s) ans = min(ans, max(abs(t - x), abs(s - x))); else if (abs(t - x) >= abs(s - x)) ans = min(ans, abs(t - x) + abs(s - x) * 2); else ans = min(ans, abs(t - x) * 2 + abs(s - x)); } } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; int binary_search(vector<long long> &n, long long x) { int ok = (int)n.size(); int ng = -1; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (n[mid] >= x) ok = mid; else ng = mid; } if (ok == (int)n.size()) ok--; return ok; } int main() { int a, b, q; cin >> a >> b >> q; vector<long long> shrine(a); for (int i = 0; i < a; i++) cin >> shrine[i]; vector<long long> temple(b); for (int i = 0; i < b; i++) cin >> temple[i]; for (int i = 0; i < q; i++) { long long x; cin >> x; vector<long long> sh(2); vector<long long> tem(2); int v, w; v = binary_search(shrine, x); w = binary_search(temple, x); sh[0] = shrine[v]; sh[1] = shrine[max(0, v - 1)]; tem[0] = temple[w]; tem[1] = temple[max(0, w - 1)]; long long ans = 1000000000000; for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { long long s = sh[j]; long long t = tem[k]; if (t > s) swap(s, t); if (x <= t || x >= s) ans = min(ans, max(abs(t - x), abs(s - x))); else if (abs(t - x) >= abs(s - x)) ans = min(ans, abs(t - x) + abs(s - x) * 2); else ans = min(ans, abs(t - x) * 2 + abs(s - x)); } } cout << ans << endl; } }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
924,985
924,984
u013408661
cpp
p03112
#include <algorithm> #include <bitset> #include <cmath> #include <iostream> #include <map> #include <string> #include <tuple> #include <vector> template <typename T> bool chmax(T &a, T b) { if (a < b) { a = b; return (true); } else { return (false); } } template <typename T> bool chmin(T &a, T b) { if (a > b) { a = b; return (true); } else { return (false); } } using namespace std; using ll = long long; using ull = unsigned long long; using Pll = pair<ll, ll>; using Pull = pair<ull, ull>; #define eb emplace_back #define pb push_back #define mp(a, b) make_pair(a, b) #define mt(...) make_tuple(__VA_ARGS__) #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define reps(i, n) for (int i = 1; i <= (int)(n); ++i) #define rrep(i, n) for (int i = (int)((n)-1); i >= 0; --i) #define rreps(i, n) for (int i = (int)((n)); i > 0; --i) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define MOD (1e9 + 7) #define INF (1e12) #define MINF (-1e12) int main() { int A, B, Q; cin >> A >> B >> Q; vector<ll> vS(A + 2); rep(i, A) { cin >> vS[i]; } vector<ll> vT(B + 2); rep(i, B) { cin >> vT[i]; } vector<ll> vX(Q); rep(i, Q) { cin >> vX[i]; } // vS, vT に正負の無限遠の点を入れておく vS[A] = MINF; vS[A + 1] = INF; vT[A] = MINF; vT[A + 1] = INF; sort(ALL(vS)); sort(ALL(vT)); for (auto &&it : vX) { // 問itに対して、一番近い左右の寺2社2を求める auto AB = upper_bound(ALL(vS), it); ll sB = *AB; ll sA = *prev(AB); auto CD = upper_bound(ALL(vT), it); ll tD = *CD; ll tC = *prev(CD); /* 上記4箇所の訪れ方の最小値を求める */ // 1. A -> C ll ac = abs(sA - it) + abs(tC - sA); // 2. A -> D ll ad = abs(sA - it) + abs(tD - sA); // 3. C -> A ll ca = abs(tC - it) + abs(sA - tC); // 4. D -> A ll da = abs(tD - it) + abs(sA - tD); // 5. B -> C ll bc = abs(sB - it) + abs(tC - sB); // 6. B -> D ll bd = abs(sB - it) + abs(tD - sB); // 7. C -> B ll cb = abs(tC - it) + abs(sB - tC); // 8. D -> B ll db = abs(tD - it) + abs(sB - tD); cout << min({ac, ad, ca, da, bc, bd, cb, db}) << endl; } return (0); }
#include <algorithm> #include <bitset> #include <cmath> #include <iostream> #include <map> #include <string> #include <tuple> #include <vector> template <typename T> bool chmax(T &a, T b) { if (a < b) { a = b; return (true); } else { return (false); } } template <typename T> bool chmin(T &a, T b) { if (a > b) { a = b; return (true); } else { return (false); } } using namespace std; using ll = long long; using ull = unsigned long long; using Pll = pair<ll, ll>; using Pull = pair<ull, ull>; #define eb emplace_back #define pb push_back #define mp(a, b) make_pair(a, b) #define mt(...) make_tuple(__VA_ARGS__) #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define reps(i, n) for (int i = 1; i <= (int)(n); ++i) #define rrep(i, n) for (int i = (int)((n)-1); i >= 0; --i) #define rreps(i, n) for (int i = (int)((n)); i > 0; --i) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define MOD (1e9 + 7) #define INF (1e12) #define MINF (-1e12) int main() { int A, B, Q; cin >> A >> B >> Q; vector<ll> vS(A + 2); rep(i, A) { cin >> vS[i]; } vector<ll> vT(B + 2); rep(i, B) { cin >> vT[i]; } vector<ll> vX(Q); rep(i, Q) { cin >> vX[i]; } // vS, vT に正負の無限遠の点を入れておく vS[A] = MINF; vS[A + 1] = INF; vT[B] = MINF; vT[B + 1] = INF; sort(ALL(vS)); sort(ALL(vT)); for (auto &&it : vX) { // 問itに対して、一番近い左右の寺2社2を求める auto AB = upper_bound(ALL(vS), it); ll sB = *AB; ll sA = *prev(AB); auto CD = upper_bound(ALL(vT), it); ll tD = *CD; ll tC = *prev(CD); /* 上記4箇所の訪れ方の最小値を求める */ // 1. A -> C ll ac = abs(sA - it) + abs(tC - sA); // 2. A -> D ll ad = abs(sA - it) + abs(tD - sA); // 3. C -> A ll ca = abs(tC - it) + abs(sA - tC); // 4. D -> A ll da = abs(tD - it) + abs(sA - tD); // 5. B -> C ll bc = abs(sB - it) + abs(tC - sB); // 6. B -> D ll bd = abs(sB - it) + abs(tD - sB); // 7. C -> B ll cb = abs(tC - it) + abs(sB - tC); // 8. D -> B ll db = abs(tD - it) + abs(sB - tD); cout << min({ac, ad, ca, da, bc, bd, cb, db}) << endl; } return (0); }
[ "assignment.variable.change", "identifier.change", "variable_access.subscript.index.change", "expression.operation.binary.change" ]
924,995
924,996
u408910484
cpp
p03112
#include <iostream> #include <vector> using namespace std; typedef long long ll; int main() { int a, b, q; cin >> a >> b >> q; vector<ll> s(a), t(b), x(q); for (auto &y : s) { cin >> y; } for (auto &y : t) { cin >> y; } for (auto &y : x) { cin >> y; } for (auto p : x) { ll rights, rightt, lefts, leftt; rights = lower_bound(s.begin(), s.end(), p) - s.begin(); rightt = lower_bound(t.begin(), t.end(), p) - t.begin(); lefts = rights - 1; leftt = rightt - 1; ll ans = -1; ll temp; if ((rights != a) * (rightt != b)) { temp = s[rights] - p; if (temp < t[rightt] - p) { temp = t[rightt] - p; } if (ans > temp) ans = temp; if (ans == -1) ans = temp; } if ((rights != 0) * (rightt != 0)) { temp = p - s[rights - 1]; if (temp < p - t[rightt - 1]) { temp = p - t[rightt - 1]; } if (ans > temp) ans = temp; if (ans == -1) ans = temp; } vector<int> av, bv; if (rights != a) { av.push_back(0); } if (rights != 0) { av.push_back(1); } if (rightt != b) { bv.push_back(0); } if (rightt != 0) { bv.push_back(1); } for (int i = 0; i < av.size(); i++) { for (int j = 0; j < bv.size(); j++) { ll y = s[rights - av[i]] - p; if (y < 0) y *= -1; ll z = t[rightt - bv[i]] - p; if (z < 0) z *= -1; if (y < z) { temp = 2 * y + z; } else { temp = 2 * z + y; } if (ans > temp) ans = temp; if (ans == -1) ans = temp; } } cout << ans << endl; } return 0; }
#include <iostream> #include <vector> using namespace std; typedef long long ll; int main() { int a, b, q; cin >> a >> b >> q; vector<ll> s(a), t(b), x(q); for (auto &y : s) { cin >> y; } for (auto &y : t) { cin >> y; } for (auto &y : x) { cin >> y; } for (auto p : x) { ll rights, rightt, lefts, leftt; rights = lower_bound(s.begin(), s.end(), p) - s.begin(); rightt = lower_bound(t.begin(), t.end(), p) - t.begin(); lefts = rights - 1; leftt = rightt - 1; ll ans = -1; ll temp; if ((rights != a) * (rightt != b)) { temp = s[rights] - p; if (temp < t[rightt] - p) { temp = t[rightt] - p; } if (ans > temp) ans = temp; if (ans == -1) ans = temp; } if ((rights != 0) * (rightt != 0)) { temp = p - s[rights - 1]; if (temp < p - t[rightt - 1]) { temp = p - t[rightt - 1]; } if (ans > temp) ans = temp; if (ans == -1) ans = temp; } vector<int> av, bv; if (rights != a) { av.push_back(0); } if (rights != 0) { av.push_back(1); } if (rightt != b) { bv.push_back(0); } if (rightt != 0) { bv.push_back(1); } for (int i = 0; i < av.size(); i++) { for (int j = 0; j < bv.size(); j++) { ll y = s[rights - av[i]] - p; if (y < 0) y *= -1; ll z = t[rightt - bv[j]] - p; if (z < 0) z *= -1; if (y < z) { temp = 2 * y + z; } else { temp = 2 * z + y; } if (ans > temp) ans = temp; if (ans == -1) ans = temp; } } cout << ans << endl; } return 0; }
[ "identifier.change", "variable_access.subscript.index.change", "expression.operation.binary.change" ]
924,997
924,998
u342703951
cpp
p03112
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; #define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i)) #define all(x) x.begin(), x.end() int main() { int a, b, q; cin >> a >> b >> q; vector<long long> s(a), t(b); rep(i, 0, a - 1) cin >> s[i]; rep(i, 0, b - 1) cin >> t[i]; rep(_, 1, q) { long long x; cin >> x; long long res = 1LL << 60; int it = lower_bound(all(s), x) - s.begin(); for (int i = max(0, it - 1); i < min(a, it + 1); ++i) { long long y = s[i]; int it2 = lower_bound(all(t), y) - t.begin(); for (int j = max(0, it2 - 1); j < min(b, it2 + 1); ++j) { res = min(res, abs(x - y) + abs(y - t[j])); } } it = lower_bound(all(t), x) - t.begin(); for (int i = max(0, it - 1); i < min(b, it + 1); ++i) { long long y = t[i]; int it2 = lower_bound(all(s), y) - s.begin(); for (int j = max(0, it2 - 1); j < min(a, it + 1); ++j) { res = min(res, abs(x - y) + abs(y - s[j])); } } cout << res << endl; } }
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; #define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i)) #define all(x) x.begin(), x.end() int main() { int a, b, q; cin >> a >> b >> q; vector<long long> s(a), t(b); rep(i, 0, a - 1) cin >> s[i]; rep(i, 0, b - 1) cin >> t[i]; rep(_, 1, q) { long long x; cin >> x; long long res = 1LL << 60; int it = lower_bound(all(s), x) - s.begin(); for (int i = max(0, it - 1); i < min(a, it + 1); ++i) { long long y = s[i]; int it2 = lower_bound(all(t), y) - t.begin(); for (int j = max(0, it2 - 1); j < min(b, it2 + 1); ++j) { res = min(res, abs(x - y) + abs(y - t[j])); } } it = lower_bound(all(t), x) - t.begin(); for (int i = max(0, it - 1); i < min(b, it + 1); ++i) { long long y = t[i]; int it2 = lower_bound(all(s), y) - s.begin(); for (int j = max(0, it2 - 1); j < min(a, it2 + 1); ++j) { res = min(res, abs(x - y) + abs(y - s[j])); } } cout << res << endl; } }
[ "identifier.change", "control_flow.loop.for.condition.change", "call.arguments.change", "expression.operation.binary.change" ]
925,003
925,004
u521389909
cpp