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
p03099
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 505, M = 50005, R = 100; const ll inf = 0x3f3f3f3f3f3f3f3fll; int read() { int f = 1, g = 0; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); ch = getchar()) g = g * 10 + ch - '0'; return f * g; } void chkmax(int &x, int y) { if (x < y) x = y; } void chkmin(int &x, int y) { if (x > y) x = y; } int n, m; struct jew { int x, y; ll w; } a[N]; struct node { char typ; int x, r; } b[N]; ll cost, ans; int S, T, cnt, fir[N], fr[N], siz; struct edge { int u, v; ll w; int fl, nex; } e[M]; void add(int u, int v, ll w, int fl) { e[++siz] = (edge){u, v, w, fl, fir[u]}; fir[u] = siz; e[++siz] = (edge){v, u, -w, 0, fir[v]}; fir[v] = siz; } ll dist[N]; int que[N * 50]; bool inq[N]; void dec(int x, int fl) { e[x].fl -= fl; e[x ^ 1].fl += fl; } bool spfa() { memset(dist, 0xc0, 8 * (cnt + 1)); memset(inq, 0, cnt + 1); int l = 1, r = 1; que[l] = S; dist[S] = 0; inq[S] = 1; while (l <= r) { int x = que[l]; for (int i = fir[x]; i; i = e[i].nex) if ((e[i].fl) && (dist[e[i].v] < dist[x] + e[i].w)) { if (!inq[e[i].v]) { que[++r] = e[i].v; inq[e[i].v] = 1; } dist[e[i].v] = dist[x] + e[i].w; fr[e[i].v] = i; } inq[x] = 0; l++; } return dist[T] > (ll)0xc0c0c0c0c0c0c0c0ll; } int update() { int t = 0x3f3f3f3f; for (int i = fr[T]; i; i = fr[e[i].u]) t = min(t, e[i].fl); cost += t * dist[T]; for (int i = fr[T]; i; i = fr[e[i].u]) dec(i, t); return t; } int dinic() { int flow = 0; while (spfa()) flow += update(); return flow; } int ml[N], mr[N], mu[N], md[N]; void calc(int L) { memset(fir, 0, sizeof(fir)); siz = 1; S = 0; T = cnt = L * 2 + R * 2 + 1; for (int i = 1; i <= n; i++) add(a[i].x, a[i].y + R, a[i].w, 1); for (int i = 1; i <= L; i++) { ml[i] = mu[i] = 1, mr[i] = md[i] = R; add(S, R * 2 + i, 0, 1); add(R * 2 + L + i, T, 0, 1); } for (int i = 1; i <= m; i++) if (b[i].r >= L) continue; else if (b[i].typ == 'L') chkmax(ml[b[i].r + 1], b[i].x + 1); else if (b[i].typ == 'R') chkmin(mr[L - b[i].r], b[i].x - 1); else if (b[i].typ == 'D') chkmax(mu[b[i].r + 1], b[i].x + 1); else if (b[i].typ == 'U') chkmin(md[L - b[i].r], b[i].x - 1); for (int i = 2; i <= L; i++) chkmax(ml[i], ml[i - 1]), chkmax(mu[i], mu[i - 1]); for (int i = L - 1; i; i--) chkmin(md[i], md[i + 1]), chkmin(md[i], md[i + 1]); for (int i = 1; i <= L; i++) { for (int j = ml[i]; j <= mr[i]; j++) add(R * 2 + i, j, 0, 1); for (int j = mu[i]; j <= md[i]; j++) add(j + R, R * 2 + L + i, 0, 1); } cost = 0; if (dinic() == L) ans = max(ans, cost); // for (int i=1;i<=n;i++) if (!e[i*2].fl) printf("%d ",i); // printf("\n"); } int main() { n = read(); for (int i = 1; i <= n; i++) scanf(" %d %d %lld", &a[i].x, &a[i].y, &a[i].w); m = read(); for (int i = 1; i <= m; i++) scanf(" %c %d %d", &b[i].typ, &b[i].x, &b[i].r); for (int i = 1; i <= n; i++) calc(i); printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 505, M = 50005, R = 100; const ll inf = 0x3f3f3f3f3f3f3f3fll; int read() { int f = 1, g = 0; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); ch = getchar()) g = g * 10 + ch - '0'; return f * g; } void chkmax(int &x, int y) { if (x < y) x = y; } void chkmin(int &x, int y) { if (x > y) x = y; } int n, m; struct jew { int x, y; ll w; } a[N]; struct node { char typ; int x, r; } b[N]; ll cost, ans; int S, T, cnt, fir[N], fr[N], siz; struct edge { int u, v; ll w; int fl, nex; } e[M]; void add(int u, int v, ll w, int fl) { e[++siz] = (edge){u, v, w, fl, fir[u]}; fir[u] = siz; e[++siz] = (edge){v, u, -w, 0, fir[v]}; fir[v] = siz; } ll dist[N]; int que[N * 50]; bool inq[N]; void dec(int x, int fl) { e[x].fl -= fl; e[x ^ 1].fl += fl; } bool spfa() { memset(dist, 0xc0, 8 * (cnt + 1)); memset(inq, 0, cnt + 1); int l = 1, r = 1; que[l] = S; dist[S] = 0; inq[S] = 1; while (l <= r) { int x = que[l]; for (int i = fir[x]; i; i = e[i].nex) if ((e[i].fl) && (dist[e[i].v] < dist[x] + e[i].w)) { if (!inq[e[i].v]) { que[++r] = e[i].v; inq[e[i].v] = 1; } dist[e[i].v] = dist[x] + e[i].w; fr[e[i].v] = i; } inq[x] = 0; l++; } return dist[T] > (ll)0xc0c0c0c0c0c0c0c0ll; } int update() { int t = 0x3f3f3f3f; for (int i = fr[T]; i; i = fr[e[i].u]) t = min(t, e[i].fl); cost += t * dist[T]; for (int i = fr[T]; i; i = fr[e[i].u]) dec(i, t); return t; } int dinic() { int flow = 0; while (spfa()) flow += update(); return flow; } int ml[N], mr[N], mu[N], md[N]; void calc(int L) { memset(fir, 0, sizeof(fir)); siz = 1; S = 0; T = cnt = L * 2 + R * 2 + 1; for (int i = 1; i <= n; i++) add(a[i].x, a[i].y + R, a[i].w, 1); for (int i = 1; i <= L; i++) { ml[i] = mu[i] = 1, mr[i] = md[i] = R; add(S, R * 2 + i, 0, 1); add(R * 2 + L + i, T, 0, 1); } for (int i = 1; i <= m; i++) if (b[i].r >= L) continue; else if (b[i].typ == 'L') chkmax(ml[b[i].r + 1], b[i].x + 1); else if (b[i].typ == 'R') chkmin(mr[L - b[i].r], b[i].x - 1); else if (b[i].typ == 'D') chkmax(mu[b[i].r + 1], b[i].x + 1); else if (b[i].typ == 'U') chkmin(md[L - b[i].r], b[i].x - 1); for (int i = 2; i <= L; i++) chkmax(ml[i], ml[i - 1]), chkmax(mu[i], mu[i - 1]); for (int i = L - 1; i; i--) chkmin(mr[i], mr[i + 1]), chkmin(md[i], md[i + 1]); for (int i = 1; i <= L; i++) { for (int j = ml[i]; j <= mr[i]; j++) add(R * 2 + i, j, 0, 1); for (int j = mu[i]; j <= md[i]; j++) add(j + R, R * 2 + L + i, 0, 1); } cost = 0; if (dinic() == L) { ans = max(ans, cost); // for (int i=1;i<=n;i++) if (!e[i*2].fl) printf("%d ",i); // printf("\n"); } } int main() { n = read(); for (int i = 1; i <= n; i++) scanf(" %d %d %lld", &a[i].x, &a[i].y, &a[i].w); m = read(); for (int i = 1; i <= m; i++) scanf(" %c %d %d", &b[i].typ, &b[i].x, &b[i].r); for (int i = 1; i <= n; i++) calc(i); printf("%lld\n", ans); return 0; }
[ "identifier.change", "call.arguments.change" ]
910,854
910,855
u933584582
cpp
p03099
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MV = 815; const int ME = 1200006; const ll oo = 1e18; template <typename T> void cmin(T &x, const T &y) { if (y < x) x = y; } template <typename T> void cmax(T &x, const T &y) { if (y > x) x = y; } template <typename T> void read(T &x) { x = 0; char c = getchar(); bool f = 0; while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') f = 1, c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); if (f) x = -x; } struct edge { int u, v, f; ll c; int n; edge(const int &u0 = 0, const int &v0 = 0, const ll &f0 = 0, const ll &c0 = 0, const int &n0 = 0) : u(u0), v(v0), f(f0), c(c0), n(n0) {} }; struct GRAPH { edge e[ME]; int fst[MV], lnum; void init() { memset(fst, 0xff, sizeof(fst)); lnum = -1; } GRAPH() { init(); } void addeg(int nu, int nv, ll nc, int nf) { e[++lnum] = edge(nu, nv, nf, nc, fst[nu]), fst[nu] = lnum; e[++lnum] = edge(nv, nu, 0, -nc, fst[nv]), fst[nv] = lnum; } int que[MV], inq[MV], cur[MV]; ll dis[MV]; bool spfa(int frm, int tar) { int h = 1, t = 1, x, y; memset(dis, 0x9f, sizeof(dis)); dis[frm] = 0; que[h] = frm; inq[frm] = 1; while (h >= t) { x = que[(t++) % MV]; inq[x] = 0; for (int i = fst[x]; ~i; i = e[i].n) { y = e[i].v; if (e[i].f && dis[y] < dis[x] + e[i].c) { dis[y] = dis[x] + e[i].c; if (!inq[y]) que[(++h) % MV] = y, inq[y] = 1; } } } return (dis[tar] > -oo); } int dinic(int x, int t, int f) { if (x == t) return f; int a, y, now = 0; inq[x] = 1; for (int &i = cur[x]; ~i; i = e[i].n) { y = e[i].v; if (dis[y] == dis[x] + e[i].c && e[i].f && !inq[y]) { a = dinic(y, t, min(e[i].f, f - now)); now += a; e[i].f -= a; e[i ^ 1].f += a; if (now == f) break; } } inq[x] = 0; return now; } pair<int, ll> costf(int s, int t) { ll cost = 0; int flow = 0; while (spfa(s, t)) { memmove(cur, fst, sizeof(cur)); int new_flow = dinic(s, t, ME); cost += dis[t] * new_flow; flow += new_flow; } return make_pair(flow, cost); } } G; int n, m; int lx[MV], rx[MV]; int ly[MV], ry[MV]; int px[MV], py[MV]; ll pv[MV]; char qc[MV]; int qa[MV], qb[MV]; int global_s, global_t; void input() { read(n); for (int i = 1; i <= n; i++) read(px[i]), read(py[i]), read(pv[i]); read(m); for (int i = 1; i <= n; i++) lx[i] = 1, rx[i] = 100, ly[i] = 1, ry[i] = 100; for (int i = 1; i <= m; i++) { qc[i] = getchar(); while (!isalpha(qc[i])) qc[i] = getchar(); read(qa[i]), read(qb[i]); } } void build(int num) { for (int i = 1; i <= num; i++) lx[i] = ly[i] = 1, rx[i] = ry[i] = 100; for (int i = 1; i <= m; i++) { if (qb[i] > num) continue; if (qc[i] == 'L') cmax(lx[qb[i] + 1], qa[i] + 1); if (qc[i] == 'R') cmin(rx[num - qb[i]], qa[i] - 1); if (qc[i] == 'D') cmax(ly[qb[i] + 1], qa[i] + 1); if (qc[i] == 'U') cmin(ry[num - qb[i]], qa[i] - 1); } for (int i = 1; i <= num; i++) cmax(lx[i], lx[i - 1]), cmax(ly[i], ly[i - 1]); for (int i = num; i >= 1; i--) cmin(rx[i], rx[i + 1]), cmin(ry[i], ry[i + 1]); G.init(); for (int i = 1; i <= num; i++) { for (int j = 1; j <= n; j++) { if (lx[i] <= px[j] && px[j] <= rx[i]) G.addeg(i, num * 2 + j, 0, 1); if (ly[i] <= py[j] && py[j] <= ry[i]) G.addeg(num * 2 + n + j, num + i, 0, 1); } } for (int i = 1; i <= n; i++) G.addeg(num * 2 + i, num * 2 + n + i, pv[i], 1); global_s = num * 2 + n * 2 + 1, global_t = global_s + 1; for (int i = 1; i <= num; i++) G.addeg(global_s, i, 0, 1), G.addeg(num + i, global_t, 0, 1); } void work() { ll ans = 0; for (int i = 1; i <= n; i++) { build(i); auto ret = G.costf(global_s, global_t); if (ret.first != i) break; else cmax(ans, ret.second); } printf("%lld\n", ans); } int main() { input(); work(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MV = 815; const int ME = 1200006; const ll oo = 1e18; template <typename T> void cmin(T &x, const T &y) { if (y < x) x = y; } template <typename T> void cmax(T &x, const T &y) { if (y > x) x = y; } template <typename T> void read(T &x) { x = 0; char c = getchar(); bool f = 0; while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') f = 1, c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); if (f) x = -x; } struct edge { int u, v, f; ll c; int n; edge(const int &u0 = 0, const int &v0 = 0, const ll &f0 = 0, const ll &c0 = 0, const int &n0 = 0) : u(u0), v(v0), f(f0), c(c0), n(n0) {} }; struct GRAPH { edge e[ME]; int fst[MV], lnum; void init() { memset(fst, 0xff, sizeof(fst)); lnum = -1; } GRAPH() { init(); } void addeg(int nu, int nv, ll nc, int nf) { e[++lnum] = edge(nu, nv, nf, nc, fst[nu]), fst[nu] = lnum; e[++lnum] = edge(nv, nu, 0, -nc, fst[nv]), fst[nv] = lnum; } int que[MV], inq[MV], cur[MV]; ll dis[MV]; bool spfa(int frm, int tar) { int h = 1, t = 1, x, y; memset(dis, 0x9f, sizeof(dis)); dis[frm] = 0; que[h] = frm; inq[frm] = 1; while (h >= t) { x = que[(t++) % MV]; inq[x] = 0; for (int i = fst[x]; ~i; i = e[i].n) { y = e[i].v; if (e[i].f && dis[y] < dis[x] + e[i].c) { dis[y] = dis[x] + e[i].c; if (!inq[y]) que[(++h) % MV] = y, inq[y] = 1; } } } return (dis[tar] > -oo); } int dinic(int x, int t, int f) { if (x == t) return f; int a, y, now = 0; inq[x] = 1; for (int &i = cur[x]; ~i; i = e[i].n) { y = e[i].v; if (dis[y] == dis[x] + e[i].c && e[i].f && !inq[y]) { a = dinic(y, t, min(e[i].f, f - now)); now += a; e[i].f -= a; e[i ^ 1].f += a; if (now == f) break; } } inq[x] = 0; return now; } pair<int, ll> costf(int s, int t) { ll cost = 0; int flow = 0; while (spfa(s, t)) { memmove(cur, fst, sizeof(cur)); int new_flow = dinic(s, t, ME); cost += dis[t] * new_flow; flow += new_flow; } return make_pair(flow, cost); } } G; int n, m; int lx[MV], rx[MV]; int ly[MV], ry[MV]; int px[MV], py[MV]; ll pv[MV]; char qc[MV]; int qa[MV], qb[MV]; int global_s, global_t; void input() { read(n); for (int i = 1; i <= n; i++) read(px[i]), read(py[i]), read(pv[i]); read(m); for (int i = 1; i <= n; i++) lx[i] = 1, rx[i] = 100, ly[i] = 1, ry[i] = 100; for (int i = 1; i <= m; i++) { qc[i] = getchar(); while (!isalpha(qc[i])) qc[i] = getchar(); read(qa[i]), read(qb[i]); } } void build(int num) { for (int i = 0; i <= num + 1; i++) lx[i] = ly[i] = 1, rx[i] = ry[i] = 100; for (int i = 1; i <= m; i++) { if (qb[i] > num) continue; if (qc[i] == 'L') cmax(lx[qb[i] + 1], qa[i] + 1); if (qc[i] == 'R') cmin(rx[num - qb[i]], qa[i] - 1); if (qc[i] == 'D') cmax(ly[qb[i] + 1], qa[i] + 1); if (qc[i] == 'U') cmin(ry[num - qb[i]], qa[i] - 1); } for (int i = 1; i <= num; i++) cmax(lx[i], lx[i - 1]), cmax(ly[i], ly[i - 1]); for (int i = num; i >= 1; i--) cmin(rx[i], rx[i + 1]), cmin(ry[i], ry[i + 1]); G.init(); for (int i = 1; i <= num; i++) { for (int j = 1; j <= n; j++) { if (lx[i] <= px[j] && px[j] <= rx[i]) G.addeg(i, num * 2 + j, 0, 1); if (ly[i] <= py[j] && py[j] <= ry[i]) G.addeg(num * 2 + n + j, num + i, 0, 1); } } for (int i = 1; i <= n; i++) G.addeg(num * 2 + i, num * 2 + n + i, pv[i], 1); global_s = num * 2 + n * 2 + 1, global_t = global_s + 1; for (int i = 1; i <= num; i++) G.addeg(global_s, i, 0, 1), G.addeg(num + i, global_t, 0, 1); } void work() { ll ans = 0; for (int i = 1; i <= n; i++) { build(i); auto ret = G.costf(global_s, global_t); if (ret.first != i) break; else cmax(ans, ret.second); } printf("%lld\n", ans); } int main() { input(); work(); return 0; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "control_flow.loop.for.condition.change", "misc.off_by_one" ]
910,862
910,863
u781735900
cpp
p03099
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MV = 815; const int ME = 1200006; const ll oo = 1e18; template <typename T> void cmin(T &x, const T &y) { if (y < x) x = y; } template <typename T> void cmax(T &x, const T &y) { if (y > x) x = y; } template <typename T> void read(T &x) { x = 0; char c = getchar(); bool f = 0; while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') f = 1, c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); if (f) x = -x; } struct edge { int u, v, f; ll c; int n; edge(const int &u0 = 0, const int &v0 = 0, const ll &f0 = 0, const ll &c0 = 0, const int &n0 = 0) : u(u0), v(v0), f(f0), c(c0), n(n0) {} }; struct GRAPH { edge e[ME]; int fst[MV], lnum; void init() { memset(fst, 0xff, sizeof(fst)); lnum = -1; } GRAPH() { init(); } void addeg(int nu, int nv, int nc, int nf) { e[++lnum] = edge(nu, nv, nf, nc, fst[nu]), fst[nu] = lnum; e[++lnum] = edge(nv, nu, 0, -nc, fst[nv]), fst[nv] = lnum; } int que[MV], inq[MV], cur[MV]; ll dis[MV]; bool spfa(int frm, int tar) { int h = 1, t = 1, x, y; memset(dis, 0x9f, sizeof(dis)); dis[frm] = 0; que[h] = frm; inq[frm] = 1; while (h >= t) { x = que[(t++) % MV]; inq[x] = 0; for (int i = fst[x]; ~i; i = e[i].n) { y = e[i].v; if (e[i].f && dis[y] < dis[x] + e[i].c) { dis[y] = dis[x] + e[i].c; if (!inq[y]) que[(++h) % MV] = y, inq[y] = 1; } } } return (dis[tar] > -oo); } int dinic(int x, int t, int f) { if (x == t) return f; int a, y, now = 0; inq[x] = 1; for (int &i = cur[x]; ~i; i = e[i].n) { y = e[i].v; if (dis[y] == dis[x] + e[i].c && e[i].f && !inq[y]) { a = dinic(y, t, min(e[i].f, f - now)); now += a; e[i].f -= a; e[i ^ 1].f += a; if (now == f) break; } } inq[x] = 0; return now; } pair<int, ll> costf(int s, int t) { ll cost = 0; int flow = 0; while (spfa(s, t)) { memmove(cur, fst, sizeof(cur)); int new_flow = dinic(s, t, ME); cost += dis[t] * new_flow; flow += new_flow; } return make_pair(flow, cost); } } G; int n, m; int lx[MV], rx[MV]; int ly[MV], ry[MV]; int px[MV], py[MV]; ll pv[MV]; char qc[MV]; int qa[MV], qb[MV]; int global_s, global_t; void input() { read(n); for (int i = 1; i <= n; i++) read(px[i]), read(py[i]), read(pv[i]); read(m); for (int i = 1; i <= n; i++) lx[i] = 1, rx[i] = 100, ly[i] = 1, ry[i] = 100; for (int i = 1; i <= m; i++) { qc[i] = getchar(); while (!isalpha(qc[i])) qc[i] = getchar(); read(qa[i]), read(qb[i]); } } void build(int num) { for (int i = 1; i <= num; i++) lx[i] = ly[i] = 1, rx[i] = ry[i] = 100; for (int i = 1; i <= m; i++) { if (qb[i] > num) continue; if (qc[i] == 'L') cmax(lx[qb[i] + 1], qa[i] + 1); if (qc[i] == 'R') cmin(rx[num - qb[i]], qa[i] - 1); if (qc[i] == 'D') cmax(ly[qb[i] + 1], qa[i] + 1); if (qc[i] == 'U') cmin(ry[num - qb[i]], qa[i] - 1); } for (int i = 1; i <= num; i++) cmax(lx[i], lx[i - 1]), cmax(ly[i], ly[i - 1]); for (int i = num; i >= 1; i--) cmin(rx[i], rx[i + 1]), cmin(ry[i], ry[i + 1]); G.init(); for (int i = 1; i <= num; i++) { for (int j = 1; j <= n; j++) { if (lx[i] <= px[j] && px[j] <= rx[i]) G.addeg(i, num * 2 + j, 0, 1); if (ly[i] <= py[j] && py[j] <= ry[i]) G.addeg(num * 2 + n + j, num + i, 0, 1); } } for (int i = 1; i <= n; i++) G.addeg(num * 2 + i, num * 2 + n + i, pv[i], 1); global_s = num * 2 + n * 2 + 1, global_t = global_s + 1; for (int i = 1; i <= num; i++) G.addeg(global_s, i, 0, 1), G.addeg(num + i, global_t, 0, 1); } void work() { ll ans = 0; for (int i = 1; i <= n; i++) { build(i); auto ret = G.costf(global_s, global_t); if (ret.first != i) break; else cmax(ans, ret.second); } printf("%lld\n", ans); } int main() { input(); work(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MV = 815; const int ME = 1200006; const ll oo = 1e18; template <typename T> void cmin(T &x, const T &y) { if (y < x) x = y; } template <typename T> void cmax(T &x, const T &y) { if (y > x) x = y; } template <typename T> void read(T &x) { x = 0; char c = getchar(); bool f = 0; while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') f = 1, c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); if (f) x = -x; } struct edge { int u, v, f; ll c; int n; edge(const int &u0 = 0, const int &v0 = 0, const ll &f0 = 0, const ll &c0 = 0, const int &n0 = 0) : u(u0), v(v0), f(f0), c(c0), n(n0) {} }; struct GRAPH { edge e[ME]; int fst[MV], lnum; void init() { memset(fst, 0xff, sizeof(fst)); lnum = -1; } GRAPH() { init(); } void addeg(int nu, int nv, ll nc, int nf) { e[++lnum] = edge(nu, nv, nf, nc, fst[nu]), fst[nu] = lnum; e[++lnum] = edge(nv, nu, 0, -nc, fst[nv]), fst[nv] = lnum; } int que[MV], inq[MV], cur[MV]; ll dis[MV]; bool spfa(int frm, int tar) { int h = 1, t = 1, x, y; memset(dis, 0x9f, sizeof(dis)); dis[frm] = 0; que[h] = frm; inq[frm] = 1; while (h >= t) { x = que[(t++) % MV]; inq[x] = 0; for (int i = fst[x]; ~i; i = e[i].n) { y = e[i].v; if (e[i].f && dis[y] < dis[x] + e[i].c) { dis[y] = dis[x] + e[i].c; if (!inq[y]) que[(++h) % MV] = y, inq[y] = 1; } } } return (dis[tar] > -oo); } int dinic(int x, int t, int f) { if (x == t) return f; int a, y, now = 0; inq[x] = 1; for (int &i = cur[x]; ~i; i = e[i].n) { y = e[i].v; if (dis[y] == dis[x] + e[i].c && e[i].f && !inq[y]) { a = dinic(y, t, min(e[i].f, f - now)); now += a; e[i].f -= a; e[i ^ 1].f += a; if (now == f) break; } } inq[x] = 0; return now; } pair<int, ll> costf(int s, int t) { ll cost = 0; int flow = 0; while (spfa(s, t)) { memmove(cur, fst, sizeof(cur)); int new_flow = dinic(s, t, ME); cost += dis[t] * new_flow; flow += new_flow; } return make_pair(flow, cost); } } G; int n, m; int lx[MV], rx[MV]; int ly[MV], ry[MV]; int px[MV], py[MV]; ll pv[MV]; char qc[MV]; int qa[MV], qb[MV]; int global_s, global_t; void input() { read(n); for (int i = 1; i <= n; i++) read(px[i]), read(py[i]), read(pv[i]); read(m); for (int i = 1; i <= n; i++) lx[i] = 1, rx[i] = 100, ly[i] = 1, ry[i] = 100; for (int i = 1; i <= m; i++) { qc[i] = getchar(); while (!isalpha(qc[i])) qc[i] = getchar(); read(qa[i]), read(qb[i]); } } void build(int num) { for (int i = 0; i <= num + 1; i++) lx[i] = ly[i] = 1, rx[i] = ry[i] = 100; for (int i = 1; i <= m; i++) { if (qb[i] > num) continue; if (qc[i] == 'L') cmax(lx[qb[i] + 1], qa[i] + 1); if (qc[i] == 'R') cmin(rx[num - qb[i]], qa[i] - 1); if (qc[i] == 'D') cmax(ly[qb[i] + 1], qa[i] + 1); if (qc[i] == 'U') cmin(ry[num - qb[i]], qa[i] - 1); } for (int i = 1; i <= num; i++) cmax(lx[i], lx[i - 1]), cmax(ly[i], ly[i - 1]); for (int i = num; i >= 1; i--) cmin(rx[i], rx[i + 1]), cmin(ry[i], ry[i + 1]); G.init(); for (int i = 1; i <= num; i++) { for (int j = 1; j <= n; j++) { if (lx[i] <= px[j] && px[j] <= rx[i]) G.addeg(i, num * 2 + j, 0, 1); if (ly[i] <= py[j] && py[j] <= ry[i]) G.addeg(num * 2 + n + j, num + i, 0, 1); } } for (int i = 1; i <= n; i++) G.addeg(num * 2 + i, num * 2 + n + i, pv[i], 1); global_s = num * 2 + n * 2 + 1, global_t = global_s + 1; for (int i = 1; i <= num; i++) G.addeg(global_s, i, 0, 1), G.addeg(num + i, global_t, 0, 1); } void work() { ll ans = 0; for (int i = 1; i <= n; i++) { build(i); auto ret = G.costf(global_s, global_t); if (ret.first != i) break; else cmax(ans, ret.second); } printf("%lld\n", ans); } int main() { input(); work(); return 0; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "control_flow.loop.for.condition.change", "misc.off_by_one" ]
910,864
910,863
u781735900
cpp
p03099
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MV = 815; const int ME = 1200006; const ll oo = 1e18; template <typename T> void cmin(T &x, const T &y) { if (y < x) x = y; } template <typename T> void cmax(T &x, const T &y) { if (y > x) x = y; } template <typename T> void read(T &x) { x = 0; char c = getchar(); bool f = 0; while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') f = 1, c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); if (f) x = -x; } struct edge { int u, v, f; ll c; int n; edge(const int &u0 = 0, const int &v0 = 0, const ll &f0 = 0, const ll &c0 = 0, const int &n0 = 0) : u(u0), v(v0), f(f0), c(c0), n(n0) {} }; struct GRAPH { edge e[ME]; int fst[MV], lnum; void init() { memset(fst, 0xff, sizeof(fst)); lnum = -1; } GRAPH() { init(); } void addeg(int nu, int nv, int nc, int nf) { e[++lnum] = edge(nu, nv, nf, nc, fst[nu]), fst[nu] = lnum; e[++lnum] = edge(nv, nu, 0, -nc, fst[nv]), fst[nv] = lnum; } int que[MV], inq[MV], cur[MV]; ll dis[MV]; bool spfa(int frm, int tar) { int h = 1, t = 1, x, y; memset(dis, 0x9f, sizeof(dis)); dis[frm] = 0; que[h] = frm; inq[frm] = 1; while (h >= t) { x = que[(t++) % MV]; inq[x] = 0; for (int i = fst[x]; ~i; i = e[i].n) { y = e[i].v; if (e[i].f && dis[y] < dis[x] + e[i].c) { dis[y] = dis[x] + e[i].c; if (!inq[y]) que[(++h) % MV] = y, inq[y] = 1; } } } return (dis[tar] > -oo); } int dinic(int x, int t, int f) { if (x == t) return f; int a, y, now = 0; inq[x] = 1; for (int &i = cur[x]; ~i; i = e[i].n) { y = e[i].v; if (dis[y] == dis[x] + e[i].c && e[i].f && !inq[y]) { a = dinic(y, t, min(e[i].f, f - now)); now += a; e[i].f -= a; e[i ^ 1].f += a; if (now == f) break; } } inq[x] = 0; return now; } pair<int, ll> costf(int s, int t) { ll cost = 0; int flow = 0; while (spfa(s, t)) { memmove(cur, fst, sizeof(cur)); int new_flow = dinic(s, t, ME); cost += dis[t] * new_flow; flow += new_flow; } return make_pair(flow, cost); } } G; int n, m; int lx[MV], rx[MV]; int ly[MV], ry[MV]; int px[MV], py[MV]; ll pv[MV]; char qc[MV]; int qa[MV], qb[MV]; int global_s, global_t; void input() { read(n); for (int i = 1; i <= n; i++) read(px[i]), read(py[i]), read(pv[i]); read(m); for (int i = 1; i <= n; i++) lx[i] = 1, rx[i] = 100, ly[i] = 1, ry[i] = 100; for (int i = 1; i <= m; i++) { qc[i] = getchar(); while (!isalpha(qc[i])) qc[i] = getchar(); read(qa[i]), read(qb[i]); } } void build(int num) { for (int i = 1; i <= num; i++) lx[i] = ly[i] = 1, rx[i] = ry[i] = 100; for (int i = 1; i <= m; i++) { if (qb[i] > num) continue; if (qc[i] == 'L') cmax(lx[qb[i] + 1], qa[i] + 1); if (qc[i] == 'R') cmin(rx[num - qb[i]], qa[i] - 1); if (qc[i] == 'D') cmax(ly[qb[i] + 1], qa[i] + 1); if (qc[i] == 'U') cmin(ry[num - qb[i]], qa[i] - 1); } for (int i = 1; i <= num; i++) cmax(lx[i], lx[i - 1]), cmax(ly[i], ly[i - 1]); for (int i = num; i >= 1; i--) cmin(rx[i], rx[i + 1]), cmin(ry[i], ry[i + 1]); G.init(); for (int i = 1; i <= num; i++) { for (int j = 1; j <= n; j++) { if (lx[i] <= px[j] && px[j] <= rx[i]) G.addeg(i, num * 2 + j, 0, 1); if (ly[i] <= py[j] && py[j] <= ry[i]) G.addeg(num * 2 + n + j, num + i, 0, 1); } } for (int i = 1; i <= n; i++) G.addeg(num * 2 + i, num * 2 + n + i, pv[i], 1); global_s = num * 2 + n * 2 + 1, global_t = global_s + 1; for (int i = 1; i <= num; i++) G.addeg(global_s, i, 0, 1), G.addeg(num + i, global_t, 0, 1); } void work() { ll ans = 0; for (int i = 1; i <= n; i++) { build(i); auto ret = G.costf(global_s, global_t); if (ret.first != i) break; else cmax(ans, ret.second); } printf("%lld\n", ans); } int main() { input(); work(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MV = 815; const int ME = 1200006; const ll oo = 1e18; template <typename T> void cmin(T &x, const T &y) { if (y < x) x = y; } template <typename T> void cmax(T &x, const T &y) { if (y > x) x = y; } template <typename T> void read(T &x) { x = 0; char c = getchar(); bool f = 0; while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') f = 1, c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); if (f) x = -x; } struct edge { int u, v, f; ll c; int n; edge(const int &u0 = 0, const int &v0 = 0, const ll &f0 = 0, const ll &c0 = 0, const int &n0 = 0) : u(u0), v(v0), f(f0), c(c0), n(n0) {} }; struct GRAPH { edge e[ME]; int fst[MV], lnum; void init() { memset(fst, 0xff, sizeof(fst)); lnum = -1; } GRAPH() { init(); } void addeg(int nu, int nv, ll nc, int nf) { e[++lnum] = edge(nu, nv, nf, nc, fst[nu]), fst[nu] = lnum; e[++lnum] = edge(nv, nu, 0, -nc, fst[nv]), fst[nv] = lnum; } int que[MV], inq[MV], cur[MV]; ll dis[MV]; bool spfa(int frm, int tar) { int h = 1, t = 1, x, y; memset(dis, 0x9f, sizeof(dis)); dis[frm] = 0; que[h] = frm; inq[frm] = 1; while (h >= t) { x = que[(t++) % MV]; inq[x] = 0; for (int i = fst[x]; ~i; i = e[i].n) { y = e[i].v; if (e[i].f && dis[y] < dis[x] + e[i].c) { dis[y] = dis[x] + e[i].c; if (!inq[y]) que[(++h) % MV] = y, inq[y] = 1; } } } return (dis[tar] > -oo); } int dinic(int x, int t, int f) { if (x == t) return f; int a, y, now = 0; inq[x] = 1; for (int &i = cur[x]; ~i; i = e[i].n) { y = e[i].v; if (dis[y] == dis[x] + e[i].c && e[i].f && !inq[y]) { a = dinic(y, t, min(e[i].f, f - now)); now += a; e[i].f -= a; e[i ^ 1].f += a; if (now == f) break; } } inq[x] = 0; return now; } pair<int, ll> costf(int s, int t) { ll cost = 0; int flow = 0; while (spfa(s, t)) { memmove(cur, fst, sizeof(cur)); int new_flow = dinic(s, t, ME); cost += dis[t] * new_flow; flow += new_flow; } return make_pair(flow, cost); } } G; int n, m; int lx[MV], rx[MV]; int ly[MV], ry[MV]; int px[MV], py[MV]; ll pv[MV]; char qc[MV]; int qa[MV], qb[MV]; int global_s, global_t; void input() { read(n); for (int i = 1; i <= n; i++) read(px[i]), read(py[i]), read(pv[i]); read(m); for (int i = 1; i <= n; i++) lx[i] = 1, rx[i] = 100, ly[i] = 1, ry[i] = 100; for (int i = 1; i <= m; i++) { qc[i] = getchar(); while (!isalpha(qc[i])) qc[i] = getchar(); read(qa[i]), read(qb[i]); } } void build(int num) { for (int i = 1; i <= num; i++) lx[i] = ly[i] = 1, rx[i] = ry[i] = 100; for (int i = 1; i <= m; i++) { if (qb[i] > num) continue; if (qc[i] == 'L') cmax(lx[qb[i] + 1], qa[i] + 1); if (qc[i] == 'R') cmin(rx[num - qb[i]], qa[i] - 1); if (qc[i] == 'D') cmax(ly[qb[i] + 1], qa[i] + 1); if (qc[i] == 'U') cmin(ry[num - qb[i]], qa[i] - 1); } for (int i = 2; i <= num; i++) cmax(lx[i], lx[i - 1]), cmax(ly[i], ly[i - 1]); for (int i = num - 1; i >= 1; i--) cmin(rx[i], rx[i + 1]), cmin(ry[i], ry[i + 1]); G.init(); for (int i = 1; i <= num; i++) { for (int j = 1; j <= n; j++) { if (lx[i] <= px[j] && px[j] <= rx[i]) G.addeg(i, num * 2 + j, 0, 1); if (ly[i] <= py[j] && py[j] <= ry[i]) G.addeg(num * 2 + n + j, num + i, 0, 1); } } for (int i = 1; i <= n; i++) G.addeg(num * 2 + i, num * 2 + n + i, pv[i], 1); global_s = num * 2 + n * 2 + 1, global_t = global_s + 1; for (int i = 1; i <= num; i++) G.addeg(global_s, i, 0, 1), G.addeg(num + i, global_t, 0, 1); } void work() { ll ans = 0; for (int i = 1; i <= n; i++) { build(i); auto ret = G.costf(global_s, global_t); if (ret.first != i) break; else cmax(ans, ret.second); } printf("%lld\n", ans); } int main() { input(); work(); return 0; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
910,864
910,865
u781735900
cpp
p03099
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct edge { int v, nxt, f; ll c; } e[2 * 80 * 80 * 8 + 10]; int head[410], tot, cur[410]; inline void init() { tot = 1; memset(head, 0, sizeof head); } inline void addedge(int u, int v, int f, ll c) { e[++tot] = edge{v, head[u], f, c}; head[u] = tot; e[++tot] = edge{u, head[v], 0, -c}; head[v] = tot; } int n, m, x[100], y[100]; ll v[100]; struct node { char type; int key, val; } a[325]; ll dis[410]; int inq[410]; int s, t; inline bool spfa() { memset(dis, ~0x3f, sizeof dis); queue<int> q; q.push(s); dis[s] = 0; inq[s] = 1; while (!q.empty()) { int now = q.front(); q.pop(); for (int i = head[now]; i; i = e[i].nxt) { if (e[i].f && dis[now] + e[i].c > dis[e[i].v]) { dis[e[i].v] = dis[now] + e[i].c; if (!inq[e[i].v]) inq[e[i].v] = 1, q.push(e[i].v); } } inq[now] = 0; } return memcpy(cur, head, sizeof cur), dis[t] >= -1e18; } int ansf, insta[410]; ll ansc; inline int dfs(int now, int limit) { if (now == t) return limit; insta[now] = 1; int ans = 0; for (int &i = cur[now]; i; i = e[i].nxt) { if (e[i].f == 0 || dis[now] + e[i].c != dis[e[i].v] || insta[e[i].v]) continue; int tmp = dfs(e[i].v, min(limit, e[i].f)); ans += tmp, limit -= tmp; ansc += tmp * e[i].c; e[i].f -= tmp; e[i ^ 1].f += tmp; if (limit == 0) return insta[now] = 0, ans; } return insta[now] = 0, ans; } inline void work() { ansf = ansc = 0; while (spfa()) ansf += dfs(s, 1e9); } int l[100], r[100]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d%lld", x + i, y + i, v + i); scanf("%d", &m); for (int i = 1; i <= m; i++) scanf("%s%d%d", &a[i].type, &a[i].key, &a[i].val); ll ans = 0; for (int k = 1; k <= n; k++) { init(); for (int i = 1; i <= n; i++) l[i] = 0, r[i] = 100; for (int i = 1; i <= m; i++) { switch (a[i].type) { case 'L': { for (int j = a[i].val + 1; j <= k; j++) l[j] = max(l[j], a[i].key + 1); break; } case 'R': { for (int j = 1; j <= k - a[i].val; j++) r[j] = min(r[j], a[i].key); break; } } } for (int i = 1; i <= k; i++) for (int j = 1; j <= n; j++) if (x[j] >= l[i] && x[j] <= r[i]) addedge(i, j + k, 1, 0); for (int i = 1; i <= n; i++) l[i] = 0, r[i] = 100; for (int i = 1; i <= m; i++) { switch (a[i].type) { case 'D': { for (int j = a[i].val + 1; j <= k; j++) l[j] = max(l[j], a[i].key + 1); break; } case 'U': { for (int j = 1; j <= k - a[i].val; j++) r[j] = min(r[j], a[i].key - 1); break; } } } for (int i = 1; i <= k; i++) for (int j = 1; j <= n; j++) if (y[j] >= l[i] && y[j] <= r[i]) addedge(j + k + n, i + k + n + n, 1, 0); s = 0, t = k + k + n + n + 1; for (int i = 1; i <= k; i++) addedge(s, i, 1, 0), addedge(i + n + n + k, t, 1, 0); for (int i = 1; i <= n; i++) addedge(i + k, i + k + n, 1, v[i]); work(); if (ansf != k) continue; ans = max(ans, ansc); } return cout << ans << endl, 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct edge { int v, nxt, f; ll c; } e[2 * 80 * 80 * 8 + 10]; int head[410], tot, cur[410]; inline void init() { tot = 1; memset(head, 0, sizeof head); } inline void addedge(int u, int v, int f, ll c) { e[++tot] = edge{v, head[u], f, c}; head[u] = tot; e[++tot] = edge{u, head[v], 0, -c}; head[v] = tot; } int n, m, x[100], y[100]; ll v[100]; struct node { char type; int key, val; } a[325]; ll dis[410]; int inq[410]; int s, t; inline bool spfa() { memset(dis, ~0x3f, sizeof dis); queue<int> q; q.push(s); dis[s] = 0; inq[s] = 1; while (!q.empty()) { int now = q.front(); q.pop(); for (int i = head[now]; i; i = e[i].nxt) { if (e[i].f && dis[now] + e[i].c > dis[e[i].v]) { dis[e[i].v] = dis[now] + e[i].c; if (!inq[e[i].v]) inq[e[i].v] = 1, q.push(e[i].v); } } inq[now] = 0; } return memcpy(cur, head, sizeof cur), dis[t] >= -1e18; } int ansf, insta[410]; ll ansc; inline int dfs(int now, int limit) { if (now == t) return limit; insta[now] = 1; int ans = 0; for (int &i = cur[now]; i; i = e[i].nxt) { if (e[i].f == 0 || dis[now] + e[i].c != dis[e[i].v] || insta[e[i].v]) continue; int tmp = dfs(e[i].v, min(limit, e[i].f)); ans += tmp, limit -= tmp; ansc += tmp * e[i].c; e[i].f -= tmp; e[i ^ 1].f += tmp; if (limit == 0) return insta[now] = 0, ans; } return insta[now] = 0, ans; } inline void work() { ansf = ansc = 0; while (spfa()) ansf += dfs(s, 1e9); } int l[100], r[100]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d%lld", x + i, y + i, v + i); scanf("%d", &m); for (int i = 1; i <= m; i++) scanf("%s%d%d", &a[i].type, &a[i].key, &a[i].val); ll ans = 0; for (int k = 1; k <= n; k++) { init(); for (int i = 1; i <= n; i++) l[i] = 0, r[i] = 100; for (int i = 1; i <= m; i++) { switch (a[i].type) { case 'L': { for (int j = a[i].val + 1; j <= k; j++) l[j] = max(l[j], a[i].key + 1); break; } case 'R': { for (int j = 1; j <= k - a[i].val; j++) r[j] = min(r[j], a[i].key - 1); break; } } } for (int i = 1; i <= k; i++) for (int j = 1; j <= n; j++) if (x[j] >= l[i] && x[j] <= r[i]) addedge(i, j + k, 1, 0); for (int i = 1; i <= n; i++) l[i] = 0, r[i] = 100; for (int i = 1; i <= m; i++) { switch (a[i].type) { case 'D': { for (int j = a[i].val + 1; j <= k; j++) l[j] = max(l[j], a[i].key + 1); break; } case 'U': { for (int j = 1; j <= k - a[i].val; j++) r[j] = min(r[j], a[i].key - 1); break; } } } for (int i = 1; i <= k; i++) for (int j = 1; j <= n; j++) if (y[j] >= l[i] && y[j] <= r[i]) addedge(j + k + n, i + k + n + n, 1, 0); s = 0, t = k + k + n + n + 1; for (int i = 1; i <= k; i++) addedge(s, i, 1, 0), addedge(i + n + n + k, t, 1, 0); for (int i = 1; i <= n; i++) addedge(i + k, i + k + n, 1, v[i]); work(); if (ansf != k) continue; ans = max(ans, ansc); } return cout << ans << endl, 0; }
[ "call.arguments.add" ]
910,866
910,867
u462564510
cpp
p03099
#include <bits/stdc++.h> using namespace std; const int N = 85 * 2 + 5; const int M = N * N; typedef long long LL; const LL Base = 1e15, INF = 1e18; int n, v, m, T[N], a[N], b[N], num, L[N], R[N], U[N], D[N]; char s[N]; long long ans = 0; struct NODE { int x, y; long long v; void input() { scanf("%d%d", &x, &y); scanf("%lld", &v); } } P[N]; int chg(char c) { if (c == 'L') return 0; if (c == 'R') return 1; if (c == 'D') return 2; return 3; } namespace CostFlow { int fir[N], ne[M], to[M], C[M], cnt, s, t, vis[N], tim, pre[N]; LL dis[N], Cost[M], res; void init() { res = 0; memset(fir, 0, sizeof(fir)); cnt = 1; } void add(int x, int y, int fl, LL Co) { ne[++cnt] = fir[x]; fir[x] = cnt; to[cnt] = y; C[cnt] = fl; Cost[cnt] = Co; } void link(int x, int y, int fl, LL Co) { add(x, y, fl, Co); add(y, x, 0, -Co); } #define Foreachson(i, x) for (int i = fir[x]; i; i = ne[i]) bool inq[N]; bool SPFA(int s, int t) { queue<int> q; while (!q.empty()) q.pop(); for (int i = s; i <= t; ++i) dis[i] = -1, inq[i] = 0, pre[i] = 0; dis[s] = 0; q.push(s); inq[s] = 1; while (!q.empty()) { int ind = q.front(); inq[ind] = 0; q.pop(); Foreachson(i, ind) if (C[i]) { int V = to[i]; if (dis[V] < dis[ind] + Cost[i]) { dis[V] = dis[ind] + Cost[i]; pre[V] = i; if (!inq[V]) q.push(V), inq[V] = 1; } } } if (dis[t] == -1) return 0; return 1; } LL CostFlow() { LL res = 0; int tot = 0; while (SPFA(s, t)) { res += dis[t]; ++tot; int now = t; while (now != s) { --C[pre[now]]; ++C[pre[now] ^ 1]; now = to[pre[now] ^ 1]; } } // cerr << tot << endl; return res; } } // namespace CostFlow LL solve(int num) { for (int i = 1; i <= num; ++i) L[i] = D[i] = 0, R[i] = U[i] = 101; for (int i = 1; i <= m; ++i) { if (b[i] >= num) continue; if (T[i] == 0) L[b[i] + 1] = max(L[b[i] + 1], a[i] + 1); if (T[i] == 2) D[b[i] + 1] = max(D[b[i] + 1], a[i] + 1); if (T[i] == 1) R[num - b[i]] = min(R[num - b[i]], a[i] - 1); if (T[i] == 3) U[num - b[i]] = min(U[num - b[i]], a[i] - 1); } for (int i = 1; i < num; ++i) { L[i + 1] = max(L[i + 1], L[i]); D[i + 1] = max(D[i + 1], D[i]); } for (int i = num - 1; i >= 1; --i) { U[i] = min(U[i], U[i + 1]); R[i] = min(R[i], R[i + 1]); } CostFlow ::init(); int s = 1, t = 2 * num + 2 * n + 2; CostFlow ::s = 1, CostFlow ::t = 2 * num + 2 * n + 2; for (int i = 1; i <= num; ++i) CostFlow ::link(s, 2 * n + 1 + i, 1, 0), CostFlow ::link(2 * n + 1 + num + i, t, 1, 0); for (int i = 1; i <= n; ++i) { CostFlow ::link(i * 2, i * 2 + 1, 1, P[i].v); for (int j = 1; j <= num; ++j) { if (L[j] <= P[i].x && P[i].x <= R[j]) { CostFlow ::link(2 * n + 1 + j, i * 2, 1, 0); } if (D[j] <= P[i].y && P[i].y <= U[j]) { CostFlow ::link(i * 2 + 1, 2 * n + num + 1 + j, 1, 0); } } } LL res = CostFlow ::CostFlow(); // cerr << num <<" " << res << endl; return res; } int main(void) { cin >> n; for (int i = 1; i <= n; ++i) P[i].input(); cin >> m; for (int i = 1; i <= m; ++i) { scanf("%s", s); T[i] = chg(s[0]); scanf("%d%d", &a[i], &b[i]); } for (num = 1; num <= n; ++num) { ans = max(ans, solve(num)); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 85 * 4 + 5; const int M = N * N; typedef long long LL; const LL Base = 1e15, INF = 1e18; int n, v, m, T[N], a[N], b[N], num, L[N], R[N], U[N], D[N]; char s[N]; long long ans = 0; struct NODE { int x, y; long long v; void input() { scanf("%d%d", &x, &y); scanf("%lld", &v); } } P[N]; int chg(char c) { if (c == 'L') return 0; if (c == 'R') return 1; if (c == 'D') return 2; return 3; } namespace CostFlow { int fir[N], ne[M], to[M], C[M], cnt, s, t, vis[N], tim, pre[N]; LL dis[N], Cost[M], res; void init() { res = 0; memset(fir, 0, sizeof(fir)); cnt = 1; } void add(int x, int y, int fl, LL Co) { ne[++cnt] = fir[x]; fir[x] = cnt; to[cnt] = y; C[cnt] = fl; Cost[cnt] = Co; } void link(int x, int y, int fl, LL Co) { add(x, y, fl, Co); add(y, x, 0, -Co); } #define Foreachson(i, x) for (int i = fir[x]; i; i = ne[i]) bool inq[N]; bool SPFA(int s, int t) { queue<int> q; while (!q.empty()) q.pop(); for (int i = s; i <= t; ++i) dis[i] = -INF, inq[i] = 0, pre[i] = 0; dis[s] = 0; q.push(s); inq[s] = 1; while (!q.empty()) { int ind = q.front(); inq[ind] = 0; q.pop(); Foreachson(i, ind) if (C[i]) { int V = to[i]; if (dis[V] < dis[ind] + Cost[i]) { dis[V] = dis[ind] + Cost[i]; pre[V] = i; if (!inq[V]) q.push(V), inq[V] = 1; } } } if (dis[t] == -INF) return 0; return 1; } LL CostFlow() { LL res = 0; int tot = 0; while (SPFA(s, t)) { res += dis[t]; ++tot; int now = t; while (now != s) { --C[pre[now]]; ++C[pre[now] ^ 1]; now = to[pre[now] ^ 1]; } } // cerr << tot << endl; return res; } } // namespace CostFlow LL solve(int num) { for (int i = 1; i <= num; ++i) L[i] = D[i] = 0, R[i] = U[i] = 101; for (int i = 1; i <= m; ++i) { if (b[i] >= num) continue; if (T[i] == 0) L[b[i] + 1] = max(L[b[i] + 1], a[i] + 1); if (T[i] == 2) D[b[i] + 1] = max(D[b[i] + 1], a[i] + 1); if (T[i] == 1) R[num - b[i]] = min(R[num - b[i]], a[i] - 1); if (T[i] == 3) U[num - b[i]] = min(U[num - b[i]], a[i] - 1); } for (int i = 1; i < num; ++i) { L[i + 1] = max(L[i + 1], L[i]); D[i + 1] = max(D[i + 1], D[i]); } for (int i = num - 1; i >= 1; --i) { U[i] = min(U[i], U[i + 1]); R[i] = min(R[i], R[i + 1]); } CostFlow ::init(); int s = 1, t = 2 * num + 2 * n + 2; CostFlow ::s = 1, CostFlow ::t = 2 * num + 2 * n + 2; for (int i = 1; i <= num; ++i) CostFlow ::link(s, 2 * n + 1 + i, 1, 0), CostFlow ::link(2 * n + 1 + num + i, t, 1, 0); for (int i = 1; i <= n; ++i) { CostFlow ::link(i * 2, i * 2 + 1, 1, P[i].v); for (int j = 1; j <= num; ++j) { if (L[j] <= P[i].x && P[i].x <= R[j]) { CostFlow ::link(2 * n + 1 + j, i * 2, 1, 0); } if (D[j] <= P[i].y && P[i].y <= U[j]) { CostFlow ::link(i * 2 + 1, 2 * n + num + 1 + j, 1, 0); } } } LL res = CostFlow ::CostFlow(); // cerr << num <<" " << res << endl; return res; } int main(void) { cin >> n; for (int i = 1; i <= n; ++i) P[i].input(); cin >> m; for (int i = 1; i <= m; ++i) { scanf("%s", s); T[i] = chg(s[0]); scanf("%d%d", &a[i], &b[i]); } for (num = 1; num <= n; ++num) { ans = max(ans, solve(num)); } cout << ans << endl; }
[ "literal.number.change", "expression.operation.binary.change", "assignment.value.change", "identifier.replace.add", "literal.replace.remove", "control_flow.branch.if.condition.change" ]
910,876
910,877
u016166866
cpp
p03099
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (ll(i) = (0); (i) < (n); ++i) #define REV(i, n) for (ll(i) = (n)-1; (i) >= 0; --i) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define SHOW1d(v, n) \ { \ REP(WW, n) cerr << v[WW] << ' '; \ cerr << endl << endl; \ } #define SHOW2d(v, WW, HH) \ { \ REP(W_, WW) { \ REP(H_, HH) cerr << v[W_][H_] << ' '; \ cerr << endl; \ } \ cerr << endl; \ } #define ALL(v) v.begin(), v.end() #define Decimal fixed << setprecision(20) #define INF 1000000000 #define LLINF 1000000000000000000LL #define MOD 1000000007 #define fastcin() \ cin.tie(0); \ ios::sync_with_stdio(false) typedef long long ll; typedef pair<ll, ll> P; class minCostFlow { struct edge { ll to, cap, cost, rev; }; ll V; vector<vector<edge>> G; vector<ll> dist; vector<ll> prevv; vector<ll> preve; public: minCostFlow(ll n) : G(n), dist(n), prevv(n), preve(n), V(n) {} void addEdge(ll from, ll to, ll cap, ll cost) { G[from].push_back((edge){to, cap, cost, (ll)G[to].size()}); G[to].push_back((edge){from, 0, -cost, (ll)G[from].size() - 1}); } ll solve(ll s, ll t, ll f) { ll ret = 0; while (f > 0) { fill(dist.begin(), dist.end(), LLINF); dist[s] = 0; bool update = true; while (update) { update = false; for (ll v = 0; v < V; v++) { if (dist[v] == LLINF) continue; for (ll i = 0; i < G[v].size(); i++) { edge &e = G[v][i]; if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) { dist[e.to] = dist[v] + e.cost; prevv[e.to] = v; preve[e.to] = i; update = true; } } } } if (dist[t] == LLINF) { return LLINF; //流せない } ll d = f; for (ll v = t; v != s; v = prevv[v]) { d = min(d, G[prevv[v]][preve[v]].cap); } f -= d; ret += d * dist[t]; for (ll v = t; v != s; v = prevv[v]) { edge &e = G[prevv[v]][preve[v]]; e.cap -= d; G[v][e.rev].cap += d; } } return ret; } }; ll check(vector<pair<P, ll>> v, vector<pair<char, P>> t, int k) { ll cost = 1000000000000000LL; int n = v.size(); int m = t.size(); vector<P> ver(k, MP(0, LLINF)); vector<P> hor(k, MP(0, LLINF)); REP(i, m) { char c = t[i].FI; P p = t[i].SE; if (c == 'L') { if (p.SE >= k) continue; hor[p.SE].FI = max(hor[p.SE].FI, p.FI + 1); } else if (c == 'R') { if (k - p.SE - 1 < 0) continue; hor[k - p.SE - 1].SE = min(hor[k - p.SE - 1].SE, p.FI - 1); } else if (c == 'D') { if (p.SE >= k) continue; ver[p.SE].FI = max(ver[p.SE].FI, p.FI + 1); } else { if (k - p.SE - 1 < 0) continue; ver[k - p.SE - 1].SE = min(ver[k - p.SE - 1].SE, p.FI - 1); } } REP(i, k - 1) { ver[i + 1].FI = max(ver[i + 1].FI, ver[i].FI); hor[i + 1].FI = max(hor[i + 1].FI, hor[i].FI); ver[k - i - 2].SE = min(ver[k - i - 2].SE, ver[k - i - 1].SE); hor[k - i - 2].SE = min(hor[k - i - 2].SE, hor[k - i - 1].SE); } // REP(i, k)cout << "(" << hor[i].FI << ", " << hor[i].SE << ") ";cout << // endl; REP(i, k)cout << "(" << ver[i].FI << ", " << ver[i].SE << ") ";cout << // endl; minCostFlow mcf(2 * (n + m) + 10); ll s = 2 * (m + n); ll g = 2 * (m + n) + 1; REP(i, k) { ll idA = 2 * n + i; ll idB = 2 * n + m + i; mcf.addEdge(s, idA, 1, 0); mcf.addEdge(idB, g, 1, 0); } REP(i, n) { P now = v[i].FI; ll val = v[i].SE; ll idA = i; ll idB = i + n; mcf.addEdge(idA, idB, 1, cost - val); REP(j, m) { ll idC = 2 * n + j; ll idD = 2 * n + m + j; if (now.FI >= hor[j].FI && now.FI <= hor[j].SE) { mcf.addEdge(idC, idA, 1, 0); } if (now.SE >= ver[j].FI && now.SE <= ver[j].SE) { mcf.addEdge(idB, idD, 1, 0); } } } ll ret = k * cost - mcf.solve(s, g, k); // cout << "check " << k << " " << ret << endl; return ret; } int main() { ll n; cin >> n; vector<pair<P, ll>> v(n); REP(i, n) cin >> v[i].FI.FI >> v[i].FI.SE >> v[i].SE; ll m; cin >> m; vector<pair<char, P>> t(m); REP(i, m) cin >> t[i].FI >> t[i].SE.FI >> t[i].SE.SE; ll ans = 0; for (ll i = 1; i <= n; i++) { ans = max(ans, check(v, t, i)); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (ll(i) = (0); (i) < (n); ++i) #define REV(i, n) for (ll(i) = (n)-1; (i) >= 0; --i) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define SHOW1d(v, n) \ { \ REP(WW, n) cerr << v[WW] << ' '; \ cerr << endl << endl; \ } #define SHOW2d(v, WW, HH) \ { \ REP(W_, WW) { \ REP(H_, HH) cerr << v[W_][H_] << ' '; \ cerr << endl; \ } \ cerr << endl; \ } #define ALL(v) v.begin(), v.end() #define Decimal fixed << setprecision(20) #define INF 1000000000 #define LLINF 1000000000000000000LL #define MOD 1000000007 #define fastcin() \ cin.tie(0); \ ios::sync_with_stdio(false) typedef long long ll; typedef pair<ll, ll> P; class minCostFlow { struct edge { ll to, cap, cost, rev; }; ll V; vector<vector<edge>> G; vector<ll> dist; vector<ll> prevv; vector<ll> preve; public: minCostFlow(ll n) : G(n), dist(n), prevv(n), preve(n), V(n) {} void addEdge(ll from, ll to, ll cap, ll cost) { G[from].push_back((edge){to, cap, cost, (ll)G[to].size()}); G[to].push_back((edge){from, 0, -cost, (ll)G[from].size() - 1}); } ll solve(ll s, ll t, ll f) { ll ret = 0; while (f > 0) { fill(dist.begin(), dist.end(), LLINF); dist[s] = 0; bool update = true; while (update) { update = false; for (ll v = 0; v < V; v++) { if (dist[v] == LLINF) continue; for (ll i = 0; i < G[v].size(); i++) { edge &e = G[v][i]; if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) { dist[e.to] = dist[v] + e.cost; prevv[e.to] = v; preve[e.to] = i; update = true; } } } } if (dist[t] == LLINF) { return LLINF; //流せない } ll d = f; for (ll v = t; v != s; v = prevv[v]) { d = min(d, G[prevv[v]][preve[v]].cap); } f -= d; ret += d * dist[t]; for (ll v = t; v != s; v = prevv[v]) { edge &e = G[prevv[v]][preve[v]]; e.cap -= d; G[v][e.rev].cap += d; } } return ret; } }; ll check(vector<pair<P, ll>> v, vector<pair<char, P>> t, int k) { ll cost = 1000000000000000LL; int n = v.size(); int m = t.size(); vector<P> ver(k, MP(0, LLINF)); vector<P> hor(k, MP(0, LLINF)); REP(i, m) { char c = t[i].FI; P p = t[i].SE; if (c == 'L') { if (p.SE >= k) continue; hor[p.SE].FI = max(hor[p.SE].FI, p.FI + 1); } else if (c == 'R') { if (k - p.SE - 1 < 0) continue; hor[k - p.SE - 1].SE = min(hor[k - p.SE - 1].SE, p.FI - 1); } else if (c == 'D') { if (p.SE >= k) continue; ver[p.SE].FI = max(ver[p.SE].FI, p.FI + 1); } else { if (k - p.SE - 1 < 0) continue; ver[k - p.SE - 1].SE = min(ver[k - p.SE - 1].SE, p.FI - 1); } } REP(i, k - 1) { ver[i + 1].FI = max(ver[i + 1].FI, ver[i].FI); hor[i + 1].FI = max(hor[i + 1].FI, hor[i].FI); ver[k - i - 2].SE = min(ver[k - i - 2].SE, ver[k - i - 1].SE); hor[k - i - 2].SE = min(hor[k - i - 2].SE, hor[k - i - 1].SE); } // REP(i, k)cout << "(" << hor[i].FI << ", " << hor[i].SE << ") ";cout << // endl; REP(i, k)cout << "(" << ver[i].FI << ", " << ver[i].SE << ") ";cout << // endl; minCostFlow mcf(2 * (n + k) + 10); ll s = 2 * (k + n); ll g = 2 * (k + n) + 1; REP(i, k) { ll idA = 2 * n + i; ll idB = 2 * n + k + i; mcf.addEdge(s, idA, 1, 0); mcf.addEdge(idB, g, 1, 0); } REP(i, n) { P now = v[i].FI; ll val = v[i].SE; ll idA = i; ll idB = i + n; mcf.addEdge(idA, idB, 1, cost - val); REP(j, k) { ll idC = 2 * n + j; ll idD = 2 * n + k + j; if (now.FI >= hor[j].FI && now.FI <= hor[j].SE) { mcf.addEdge(idC, idA, 1, 0); } if (now.SE >= ver[j].FI && now.SE <= ver[j].SE) { mcf.addEdge(idB, idD, 1, 0); } } } ll ret = k * cost - mcf.solve(s, g, k); // cout << "check " << k << " " << ret << endl; return ret; } int main() { ll n; cin >> n; vector<pair<P, ll>> v(n); REP(i, n) cin >> v[i].FI.FI >> v[i].FI.SE >> v[i].SE; ll m; cin >> m; vector<pair<char, P>> t(m); REP(i, m) cin >> t[i].FI >> t[i].SE.FI >> t[i].SE.SE; ll ans = 0; for (ll i = 1; i <= n; i++) { ans = max(ans, check(v, t, i)); } cout << ans << endl; return 0; }
[ "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
910,891
910,892
u382880969
cpp
p03099
#include <algorithm> #include <cassert> #include <cstdio> #include <cstring> #include <queue> #include <vector> #define pb push_back #define fir first #define sec second #define forto(_) for (int e = last[_], v = E[e].to; e; v = E[e = E[e].next].to) #define forback(_) for (int _ = T; _ ^ S; _ = pre[_]) typedef long long LL; const int kMaxn = 85, kMaxe = 2e4; const LL kInf64 = 1e15 + 5; typedef std::pair<int, int> Pii; typedef int IArn[kMaxn]; typedef int IArv[kMaxn << 2]; struct Edge { int to, capt; LL cost; int next; } E[kMaxe << 1]; int n, m, tote, S, T; IArn X, Y, L, R, U, D; IArv last, pre, pree; LL V[kMaxn], dist[kMaxn << 2]; std::vector<Pii> con[4]; char IN[5]; inline void AddEdge(int u, int v, int cap, LL cst) { E[++tote] = (Edge){v, cap, cst, last[u]}, last[u] = tote; assert(E[tote].cost == cst); E[++tote] = (Edge){u, 0, -cst, last[v]}, last[v] = tote; } template <typename T> void Umin(T &x, T y) { x > y ? x = y : 0; } template <typename T> void Umax(T &x, T y) { x < y ? x = y : 0; } LL Mcf(int); int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d%lld", X + i, Y + i, V + i); } scanf("%d", &m); for (int i = 0, ai, bi; i < m; i++) { scanf("%s%d%d", IN, &ai, &bi); switch (IN[0]) { case 'L': con[0].pb(Pii(ai, bi)); break; case 'R': con[1].pb(Pii(ai, bi)); break; case 'D': con[2].pb(Pii(ai, bi)); break; case 'U': con[3].pb(Pii(ai, bi)); break; } } for (int i = 1; i <= n; i++) { L[i] = D[i] = 1; } for (auto &p : con[0]) { Umax(L[p.sec + 1], p.fir + 1); } for (auto &p : con[2]) { Umax(D[p.sec + 1], p.fir + 1); } for (int i = 1; i <= n; i++) { Umax(L[i], L[i - 1]); Umax(D[i], D[i - 1]); } LL ans = 0; for (int k = 1; k <= n; k++) { for (int i = 1; i <= k; i++) { R[i] = U[i] = 1000; } for (auto &p : con[1]) { if (k <= p.sec) continue; Umin(R[k - p.sec], p.fir - 1); } for (auto &p : con[3]) { if (k <= p.sec) continue; Umin(U[k - p.sec], p.fir - 1); } for (int i = k - 1; i > 0; i--) { Umin(R[i], R[i + 1]); Umin(U[i], U[i + 1]); } tote = 1; memset(last, 0, sizeof last); T = (S = k + n + n + k + 1) + 1; for (int i = 1; i <= k; i++) { AddEdge(S, i, 1, 0); AddEdge(k + n + n + i, T, 1, 0); for (int j = 1; j <= n; j++) { if (L[i] <= X[j] && X[j] <= R[i]) { AddEdge(i, k + j, 1, 0); } if (D[i] <= Y[j] && Y[j] <= U[i]) { AddEdge(k + n + j, k + n + n + i, 1, 0); } } } for (int i = 1; i <= n; i++) { AddEdge(k + i, k + n + i, 1, kInf64 - V[i]); } ans = std::max(ans, Mcf(k)); } printf("%lld\n", ans); return 0; } bool Spfa() { static std::queue<int> que; static int inque[kMaxn << 2]; memset(pre, 0xff, sizeof pre); memset(dist, 0x7f, sizeof dist); for (dist[S] = 0, que.push(S), inque[S] = 1; !que.empty();) { int u = que.front(); que.pop(); forto(u) { if (E[e].capt > 0 && dist[v] > dist[u] + E[e].cost) { dist[v] = dist[u] + E[e].cost; pre[v] = u, pree[v] = e; if (!inque[v]) { que.push(v), inque[v] = 1; } } } inque[u] = 0; } return ~pre[T]; } LL Mcf(int maxf) { LL tot = 0, sumf = 0; while (Spfa()) { int flow = 100000; forback(u) { flow = std::min(flow, E[pree[u]].capt); } tot += 1ll * flow * dist[T], sumf += flow; forback(u) { E[pree[u]].capt -= flow; E[pree[u] ^ 1].capt += flow; } } return sumf >= maxf ? maxf * kInf64 - tot : 0; }
#include <algorithm> #include <cassert> #include <cstdio> #include <cstring> #include <queue> #include <vector> #define pb push_back #define fir first #define sec second #define forto(_) for (int e = last[_], v = E[e].to; e; v = E[e = E[e].next].to) #define forback(_) for (int _ = T; _ ^ S; _ = pre[_]) typedef long long LL; const int kMaxn = 85, kMaxe = 2e4; const LL kInf64 = 1e15 + 5; typedef std::pair<int, int> Pii; typedef int IArn[kMaxn]; typedef int IArv[kMaxn << 2]; struct Edge { int to, capt; LL cost; int next; } E[kMaxe << 1]; int n, m, tote, S, T; IArn X, Y, L, R, U, D; IArv last, pre, pree; LL V[kMaxn], dist[kMaxn << 2]; std::vector<Pii> con[4]; char IN[5]; inline void AddEdge(int u, int v, int cap, LL cst) { E[++tote] = (Edge){v, cap, cst, last[u]}, last[u] = tote; assert(E[tote].cost == cst); E[++tote] = (Edge){u, 0, -cst, last[v]}, last[v] = tote; } template <typename T> void Umin(T &x, T y) { x > y ? x = y : 0; } template <typename T> void Umax(T &x, T y) { x < y ? x = y : 0; } LL Mcf(int); int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d%lld", X + i, Y + i, V + i); } scanf("%d", &m); for (int i = 0, ai, bi; i < m; i++) { scanf("%s%d%d", IN, &ai, &bi); switch (IN[0]) { case 'L': con[0].pb(Pii(ai, bi)); break; case 'R': con[1].pb(Pii(ai, bi)); break; case 'D': con[2].pb(Pii(ai, bi)); break; case 'U': con[3].pb(Pii(ai, bi)); break; } } for (int i = 0; i <= n; i++) { L[i] = D[i] = 1; } for (auto &p : con[0]) { Umax(L[p.sec + 1], p.fir + 1); } for (auto &p : con[2]) { Umax(D[p.sec + 1], p.fir + 1); } for (int i = 1; i <= n; i++) { Umax(L[i], L[i - 1]); Umax(D[i], D[i - 1]); } LL ans = 0; for (int k = 1; k <= n; k++) { for (int i = 1; i <= k; i++) { R[i] = U[i] = 100; } for (auto &p : con[1]) { if (k <= p.sec) continue; Umin(R[k - p.sec], p.fir - 1); } for (auto &p : con[3]) { if (k <= p.sec) continue; Umin(U[k - p.sec], p.fir - 1); } for (int i = k - 1; i > 0; i--) { Umin(R[i], R[i + 1]); Umin(U[i], U[i + 1]); } tote = 1; memset(last, 0, sizeof last); T = (S = k + n + n + k + 1) + 1; for (int i = 1; i <= k; i++) { AddEdge(S, i, 1, 0); AddEdge(k + n + n + i, T, 1, 0); for (int j = 1; j <= n; j++) { if (L[i] <= X[j] && X[j] <= R[i]) { AddEdge(i, k + j, 1, 0); } if (D[i] <= Y[j] && Y[j] <= U[i]) { AddEdge(k + n + j, k + n + n + i, 1, 0); } } } for (int i = 1; i <= n; i++) { AddEdge(k + i, k + n + i, 1, kInf64 - V[i]); } ans = std::max(ans, Mcf(k)); } printf("%lld\n", ans); return 0; } bool Spfa() { static std::queue<int> que; static int inque[kMaxn << 2]; memset(pre, 0xff, sizeof pre); memset(dist, 0x7f, sizeof dist); for (dist[S] = 0, que.push(S), inque[S] = 1; !que.empty();) { int u = que.front(); que.pop(); forto(u) { if (E[e].capt > 0 && dist[v] > dist[u] + E[e].cost) { dist[v] = dist[u] + E[e].cost; pre[v] = u, pree[v] = e; if (!inque[v]) { que.push(v), inque[v] = 1; } } } inque[u] = 0; } return ~pre[T]; } LL Mcf(int maxf) { LL tot = 0, sumf = 0; while (Spfa()) { int flow = 100000; forback(u) { flow = std::min(flow, E[pree[u]].capt); } tot += 1ll * flow * dist[T], sumf += flow; forback(u) { E[pree[u]].capt -= flow; E[pree[u] ^ 1].capt += flow; } } return sumf >= maxf ? maxf * kInf64 - tot : 0; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change", "assignment.value.change" ]
910,893
910,894
u190597469
cpp
p03099
#include <algorithm> #include <cstdio> #include <cstring> #include <queue> using namespace std; const int INF(0X3F3F3F3F); typedef long long int LL; namespace G { const int Max_V(85 * 2); const int Max_E(85 * 30); int V, S, T, Head[Max_V], Total, To[Max_E], Next[Max_E], Cap[Max_E], Flow[Max_E]; LL Weight[Max_E]; void clear() { for (int i = 1; i <= V; ++i) Head[i] = 0; for (int i = 2; i <= Total + 1; ++i) To[i] = Next[i] = Cap[i] = Flow[i] = Weight[i] = 0; V = S = T = Total = 0; } inline void Add_Edge(int tot, int s, int t, int c, LL w) { To[tot] = t, Next[tot] = Head[s], Head[s] = tot, Cap[tot] = c, Flow[tot] = 0, Weight[tot] = w; } inline void Add_Link(int s, int t, int c, LL w) { Total += 2, Add_Edge(Total, s, t, c, w), Add_Edge(Total ^ 1, t, s, 0, -w); } LL Dist[Max_V]; bool InQ[Max_V], done[Max_V]; bool SPFA() { queue<int> Q; memset(Dist, -0X3F, sizeof(Dist)), Dist[S] = 0LL; memset(done, false, sizeof(done)), Q.push(S), InQ[S] = true; for (int u; Q.empty() == false;) { u = Q.front(), Q.pop(), InQ[u] = false, done[u] = true; for (int i = Head[u], v; i; i = Next[i]) if (Cap[i] > Flow[i] && Dist[v = To[i]] < Dist[u] + Weight[i]) { Dist[v] = Dist[u] + Weight[i]; if (!InQ[v]) Q.push(v), InQ[v] = true; } } return done[T]; } int Cur[Max_V]; int DFS(int u, int a) { if (u == T || a == 0) return a; int Ans(0); done[u] = true; for (int &i = Cur[u], v, f; i; i = Next[i]) if (Dist[v = To[i]] == Dist[u] + Weight[i] && !done[v] && (f = DFS(v, min(a, Cap[i] - Flow[i]))) > 0) { Ans += f, Flow[i] += f, Flow[i ^ 1] -= f; if ((a -= f) == 0) break; } done[u] = false; return Ans; } void MCMF(int &FLOW, LL &COST) { for (int f; SPFA();) { for (int i = 1; i <= V; ++i) Cur[i] = Head[i], done[i] = false; FLOW -= (f = DFS(S, INF)), COST += Dist[T] * f; } } } // namespace G const int Max_N(85); const int Max_M(325); int N, X[Max_N], Y[Max_N], PX[Max_N], PY[Max_N], XL[Max_N], XR[Max_N], YL[Max_N], YR[Max_N], M, T[Max_M], A[Max_M], B[Max_M]; LL V[Max_N], Ans; inline bool comp_X(int a, int b) { return X[a] < X[b]; } inline bool comp_Y(int a, int b) { return Y[a] < Y[b]; } /* 枚举选的宝石总数Sum,那么可以变成对于每个前缀选的宝石数量都有一个区间的限制。在X轴和Y轴上分别可以列出方程 X轴的方程组: 0 = 0 X[1] = XV[1] X[1] + X[2] = XV[2] ... X[1] + X[2] + ... + X[N] = Sum Y轴的方程组: 0 = 0 Y[1] = YV[1] Y[1] + Y[2] = YV[2] ... Y[1] + Y[2] + ... + Y[N] = Sum 对于每个XV[i],有XL[i] <= XV[i] <= XR[i]的限制;对于每个YV[i],有YL[i] <= YV[i] <= YR[i]的限制 对于每个轴的方程组,两两差分。那么每个XV和YV出现了恰好两次,系数分别是+1和-1。每个X和Y出现了恰好一次 那么对于点(x, y),X[x]和Y[y]是同一个变量。所以这些变量可以看做出现了恰好两次,系数分别是+1和-1 然后用流量平衡建图,可以得到一个最大费用可行流问题 */ int main() { scanf("%d", &N); for (int i = 1; i <= N; ++i) scanf("%d%d%lld", X + i, Y + i, V + i), PX[i] = PY[i] = i; sort(PX + 1, PX + 1 + N, comp_X), sort(PY + 1, PY + 1 + N, comp_Y); scanf("%d", &M); for (int i = 1; i <= M; ++i) { char op[10]; scanf("%s%d%d", op, A + i, B + i); if (*op == 'L') T[i] = 1; if (*op == 'R') T[i] = 2; if (*op == 'D') T[i] = 3; if (*op == 'U') T[i] = 4; } for (int Sum = 1; Sum <= N; ++Sum) { XL[0] = YL[0] = XR[0] = YR[0] = 0; for (int i = 1; i <= N - 1; ++i) XL[i] = YL[i] = 0, XR[i] = YR[i] = Sum; XL[N] = YL[N] = XR[N] = YR[N]; for (int i = 1; i <= M; ++i) { if (T[i] == 1) if (X[PX[1]] <= A[i]) for (int j = 1; j <= N; ++j) if (j == N || X[PX[j + 1]] > A[i]) { XR[j] = min(XR[j], B[i]); break; } if (T[i] == 2) if (A[i] <= X[PX[N]]) for (int j = N - 1; j >= 0; --j) if (j == 0 || A[i] > X[PX[j]]) { XL[j] = max(XL[j], Sum - B[i]); break; } if (T[i] == 3) if (Y[PY[1]] <= A[i]) for (int j = 1; j <= N; ++j) if (j == N || Y[PY[j + 1]] > A[i]) { YR[j] = min(YR[j], B[i]); break; } if (T[i] == 4) if (A[i] <= Y[PY[N]]) for (int j = N - 1; j >= 0; --j) if (j == 0 || A[i] > Y[PY[j]]) { YL[j] = max(YL[j], Sum - B[i]); break; } } for (int i = 0; i <= N; ++i) if (XL[i] > XR[i] || YL[i] > YR[i]) goto loop; int FLOW(0); LL COST(0LL); G::clear(), G::V = N + N + 2, G::S = N + N + 1, G::T = N + N + 2; for (int i = 1, x, y; i <= N; ++i) { for (x = 1; x <= N; ++x) if (PX[x] == i) break; for (y = 1; y <= N; ++y) if (PY[y] == i) break; COST += V[i], ++FLOW, G::Add_Link(G::S, x, 1, 0LL), G::Add_Link(N + y, G::T, 1, 0LL); G::Add_Link(x, N + y, 1, -V[i]); } for (int i = 1; i <= N - 1; ++i) { if (XL[i]) G::Add_Link(G::S, i + 1, XL[i], 0LL), G::Add_Link(i, G::T, XL[i], 0LL), FLOW += XL[i]; if (XR[i] - XL[i]) G::Add_Link(i, i + 1, XR[i] - XL[i], 0LL); } for (int i = 1; i <= N - 1; ++i) { if (YL[i]) G::Add_Link(G::S, N + i, YL[i], 0LL), G::Add_Link(N + (i + 1), G::T, YL[i], 0LL), FLOW += YL[i]; if (YR[i] - YL[i]) G::Add_Link(N + (i + 1), N + i, YR[i] - YL[i], 0LL); } FLOW += Sum, G::Add_Link(N, G::T, Sum, 0LL), G::Add_Link(G::S, N + N, Sum, 0LL); G::MCMF(FLOW, COST); if (FLOW) goto loop; Ans = max(Ans, COST); } loop: printf("%lld", Ans); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <queue> using namespace std; const int INF(0X3F3F3F3F); typedef long long int LL; namespace G { const int Max_V(85 * 2); const int Max_E(85 * 30); int V, S, T, Head[Max_V], Total, To[Max_E], Next[Max_E], Cap[Max_E], Flow[Max_E]; LL Weight[Max_E]; void clear() { for (int i = 1; i <= V; ++i) Head[i] = 0; for (int i = 2; i <= Total + 1; ++i) To[i] = Next[i] = Cap[i] = Flow[i] = Weight[i] = 0; V = S = T = Total = 0; } inline void Add_Edge(int tot, int s, int t, int c, LL w) { To[tot] = t, Next[tot] = Head[s], Head[s] = tot, Cap[tot] = c, Flow[tot] = 0, Weight[tot] = w; } inline void Add_Link(int s, int t, int c, LL w) { Total += 2, Add_Edge(Total, s, t, c, w), Add_Edge(Total ^ 1, t, s, 0, -w); } LL Dist[Max_V]; bool InQ[Max_V], done[Max_V]; bool SPFA() { queue<int> Q; memset(Dist, -0X3F, sizeof(Dist)), Dist[S] = 0LL; memset(done, false, sizeof(done)), Q.push(S), InQ[S] = true; for (int u; Q.empty() == false;) { u = Q.front(), Q.pop(), InQ[u] = false, done[u] = true; for (int i = Head[u], v; i; i = Next[i]) if (Cap[i] > Flow[i] && Dist[v = To[i]] < Dist[u] + Weight[i]) { Dist[v] = Dist[u] + Weight[i]; if (!InQ[v]) Q.push(v), InQ[v] = true; } } return done[T]; } int Cur[Max_V]; int DFS(int u, int a) { if (u == T || a == 0) return a; int Ans(0); done[u] = true; for (int &i = Cur[u], v, f; i; i = Next[i]) if (Dist[v = To[i]] == Dist[u] + Weight[i] && !done[v] && (f = DFS(v, min(a, Cap[i] - Flow[i]))) > 0) { Ans += f, Flow[i] += f, Flow[i ^ 1] -= f; if ((a -= f) == 0) break; } done[u] = false; return Ans; } void MCMF(int &FLOW, LL &COST) { for (int f; SPFA();) { for (int i = 1; i <= V; ++i) Cur[i] = Head[i], done[i] = false; FLOW -= (f = DFS(S, INF)), COST += Dist[T] * f; } } } // namespace G const int Max_N(85); const int Max_M(325); int N, X[Max_N], Y[Max_N], PX[Max_N], PY[Max_N], XL[Max_N], XR[Max_N], YL[Max_N], YR[Max_N], M, T[Max_M], A[Max_M], B[Max_M]; LL V[Max_N], Ans; inline bool comp_X(int a, int b) { return X[a] < X[b]; } inline bool comp_Y(int a, int b) { return Y[a] < Y[b]; } /* 枚举选的宝石总数Sum,那么可以变成对于每个前缀选的宝石数量都有一个区间的限制。在X轴和Y轴上分别可以列出方程 X轴的方程组: 0 = 0 X[1] = XV[1] X[1] + X[2] = XV[2] ... X[1] + X[2] + ... + X[N] = Sum Y轴的方程组: 0 = 0 Y[1] = YV[1] Y[1] + Y[2] = YV[2] ... Y[1] + Y[2] + ... + Y[N] = Sum 对于每个XV[i],有XL[i] <= XV[i] <= XR[i]的限制;对于每个YV[i],有YL[i] <= YV[i] <= YR[i]的限制 对于每个轴的方程组,两两差分。那么每个XV和YV出现了恰好两次,系数分别是+1和-1。每个X和Y出现了恰好一次 那么对于点(x, y),X[x]和Y[y]是同一个变量。所以这些变量可以看做出现了恰好两次,系数分别是+1和-1 然后用流量平衡建图,可以得到一个最大费用可行流问题 */ int main() { scanf("%d", &N); for (int i = 1; i <= N; ++i) scanf("%d%d%lld", X + i, Y + i, V + i), PX[i] = PY[i] = i; sort(PX + 1, PX + 1 + N, comp_X), sort(PY + 1, PY + 1 + N, comp_Y); scanf("%d", &M); for (int i = 1; i <= M; ++i) { char op[10]; scanf("%s%d%d", op, A + i, B + i); if (*op == 'L') T[i] = 1; if (*op == 'R') T[i] = 2; if (*op == 'D') T[i] = 3; if (*op == 'U') T[i] = 4; } for (int Sum = 1; Sum <= N; ++Sum) { XL[0] = YL[0] = XR[0] = YR[0] = 0; for (int i = 1; i <= N - 1; ++i) XL[i] = YL[i] = 0, XR[i] = YR[i] = Sum; XL[N] = YL[N] = XR[N] = YR[N] = Sum; for (int i = 1; i <= M; ++i) { if (T[i] == 1) if (X[PX[1]] <= A[i]) for (int j = 1; j <= N; ++j) if (j == N || X[PX[j + 1]] > A[i]) { XR[j] = min(XR[j], B[i]); break; } if (T[i] == 2) if (A[i] <= X[PX[N]]) for (int j = N - 1; j >= 0; --j) if (j == 0 || A[i] > X[PX[j]]) { XL[j] = max(XL[j], Sum - B[i]); break; } if (T[i] == 3) if (Y[PY[1]] <= A[i]) for (int j = 1; j <= N; ++j) if (j == N || Y[PY[j + 1]] > A[i]) { YR[j] = min(YR[j], B[i]); break; } if (T[i] == 4) if (A[i] <= Y[PY[N]]) for (int j = N - 1; j >= 0; --j) if (j == 0 || A[i] > Y[PY[j]]) { YL[j] = max(YL[j], Sum - B[i]); break; } } for (int i = 0; i <= N; ++i) if (XL[i] > XR[i] || YL[i] > YR[i]) goto loop; int FLOW(0); LL COST(0LL); G::clear(), G::V = N + N + 2, G::S = N + N + 1, G::T = N + N + 2; for (int i = 1, x, y; i <= N; ++i) { for (x = 1; x <= N; ++x) if (PX[x] == i) break; for (y = 1; y <= N; ++y) if (PY[y] == i) break; COST += V[i], ++FLOW, G::Add_Link(G::S, x, 1, 0LL), G::Add_Link(N + y, G::T, 1, 0LL); G::Add_Link(x, N + y, 1, -V[i]); } for (int i = 1; i <= N - 1; ++i) { if (XL[i]) G::Add_Link(G::S, i + 1, XL[i], 0LL), G::Add_Link(i, G::T, XL[i], 0LL), FLOW += XL[i]; if (XR[i] - XL[i]) G::Add_Link(i, i + 1, XR[i] - XL[i], 0LL); } for (int i = 1; i <= N - 1; ++i) { if (YL[i]) G::Add_Link(G::S, N + i, YL[i], 0LL), G::Add_Link(N + (i + 1), G::T, YL[i], 0LL), FLOW += YL[i]; if (YR[i] - YL[i]) G::Add_Link(N + (i + 1), N + i, YR[i] - YL[i], 0LL); } FLOW += Sum, G::Add_Link(N, G::T, Sum, 0LL), G::Add_Link(G::S, N + N, Sum, 0LL); G::MCMF(FLOW, COST); if (FLOW) goto loop; Ans = max(Ans, COST); } loop: printf("%lld", Ans); return 0; }
[ "assignment.change" ]
910,899
910,900
u710399266
cpp
p03099
#include <algorithm> #include <cstdio> #include <cstring> #include <queue> using namespace std; const int INF(0X3F3F3F3F); typedef long long int LL; namespace G { const int Max_V(85 * 2); const int Max_E(85 * 10); int V, S, T, Head[Max_V], Total, To[Max_E], Next[Max_E], Cap[Max_E], Flow[Max_E]; LL Weight[Max_E]; void clear() { for (int i = 1; i <= V; ++i) Head[i] = 0; for (int i = 2; i <= Total + 1; ++i) To[i] = Next[i] = Cap[i] = Flow[i] = Weight[i] = 0; V = S = T = Total = 0; } inline void Add_Edge(int tot, int s, int t, int c, LL w) { To[tot] = t, Next[tot] = Head[s], Head[s] = tot, Cap[tot] = c, Flow[tot] = 0, Weight[tot] = w; } inline void Add_Link(int s, int t, int c, LL w) { Total += 2, Add_Edge(Total, s, t, c, w), Add_Edge(Total ^ 1, t, s, 0, -w); } LL Dist[Max_V]; bool InQ[Max_V], done[Max_V]; bool SPFA() { queue<int> Q; memset(Dist, -0X3F, sizeof(Dist)), Dist[S] = 0LL; memset(done, false, sizeof(done)), Q.push(S), InQ[S] = true; for (int u; Q.empty() == false;) { u = Q.front(), Q.pop(), InQ[u] = false, done[u] = true; for (int i = Head[u], v; i; i = Next[i]) if (Cap[i] > Flow[i] && Dist[v = To[i]] < Dist[u] + Weight[i]) { Dist[v] = Dist[u] + Weight[i]; if (!InQ[v]) Q.push(v), InQ[v] = true; } } return done[T]; } int Cur[Max_V]; int DFS(int u, int a) { if (u == T || a == 0) return a; int Ans(0); done[u] = true; for (int &i = Cur[u], v, f; i; i = Next[i]) if (Dist[v = To[i]] == Dist[u] + Weight[i] && !done[v] && (f = DFS(v, min(a, Cap[i] - Flow[i]))) > 0) { Ans += f, Flow[i] += f, Flow[i ^ 1] -= f; if ((a -= f) == 0) break; } done[u] = false; return Ans; } void MCMF(int &FLOW, LL &COST) { for (int f; SPFA();) { for (int i = 1; i <= V; ++i) Cur[i] = Head[i], done[i] = false; FLOW -= (f = DFS(S, INF)), COST += Dist[T] * f; } } } // namespace G const int Max_N(85); const int Max_M(325); int N, X[Max_N], Y[Max_N], PX[Max_N], PY[Max_N], XL[Max_N], XR[Max_N], YL[Max_N], YR[Max_N], M, T[Max_M], A[Max_M], B[Max_M]; LL V[Max_N], Ans; inline bool comp_X(int a, int b) { return X[a] < X[b]; } inline bool comp_Y(int a, int b) { return Y[a] < Y[b]; } /* 枚举选的宝石总数Sum,那么可以变成对于每个前缀选的宝石数量都有一个区间的限制。在X轴和Y轴上分别可以列出方程 X轴的方程组: 0 = 0 X[1] = XV[1] X[1] + X[2] = XV[2] ... X[1] + X[2] + ... + X[N] = Sum Y轴的方程组: 0 = 0 Y[1] = YV[1] Y[1] + Y[2] = YV[2] ... Y[1] + Y[2] + ... + Y[N] = Sum 对于每个XV[i],有XL[i] <= XV[i] <= XR[i]的限制;对于每个YV[i],有YL[i] <= YV[i] <= YR[i]的限制 对于每个轴的方程组,两两差分。那么每个XV和YV出现了恰好两次,系数分别是+1和-1。每个X和Y出现了恰好一次 那么对于点(x, y),X[x]和Y[y]是同一个变量。所以这些变量可以看做出现了恰好两次,系数分别是+1和-1 然后用流量平衡建图,可以得到一个最大费用可行流问题 */ int main() { scanf("%d", &N); for (int i = 1; i <= N; ++i) scanf("%d%d%lld", X + i, Y + i, V + i), PX[i] = PY[i] = i; sort(PX + 1, PX + 1 + N, comp_X), sort(PY + 1, PY + 1 + N, comp_Y); scanf("%d", &M); for (int i = 1; i <= M; ++i) { char op[10]; scanf("%s%d%d", op, A + i, B + i); if (*op == 'L') T[i] = 1; if (*op == 'R') T[i] = 2; if (*op == 'D') T[i] = 3; if (*op == 'U') T[i] = 4; } for (int Sum = 1; Sum <= N; ++Sum) { XL[0] = YL[0] = XR[0] = YR[0] = 0; for (int i = 1; i <= N - 1; ++i) XL[i] = YL[i] = 0, XR[i] = YR[i] = Sum; XL[N] = YL[N] = XR[N] = YR[N]; for (int i = 1; i <= M; ++i) { if (T[i] == 1) if (X[PX[1]] <= A[i]) for (int j = 1; j <= N; ++j) if (j == N || X[PX[j + 1]] > A[i]) { XR[j] = min(XR[j], B[i]); break; } if (T[i] == 2) if (A[i] <= X[PX[N]]) for (int j = N - 1; j >= 0; --j) if (j == 0 || A[i] > X[PX[j]]) { XL[j] = max(XL[j], Sum - B[i]); break; } if (T[i] == 3) if (Y[PY[1]] <= A[i]) for (int j = 1; j <= N; ++j) if (j == N || Y[PY[j + 1]] > A[i]) { YR[j] = min(YR[j], B[i]); break; } if (T[i] == 4) if (A[i] <= Y[PY[N]]) for (int j = N - 1; j >= 0; --j) if (j == 0 || A[i] > Y[PY[j]]) { YL[j] = max(YL[j], Sum - B[i]); break; } } for (int i = 0; i <= N; ++i) if (XL[i] > XR[i] || YL[i] > YR[i]) goto loop; int FLOW(0); LL COST(0LL); G::clear(), G::V = N + N + 2, G::S = N + N + 1, G::T = N + N + 2; for (int i = 1, x, y; i <= N; ++i) { for (x = 1; x <= N; ++x) if (PX[x] == i) break; for (y = 1; y <= N; ++y) if (PY[y] == i) break; COST += V[i], ++FLOW, G::Add_Link(G::S, x, 1, 0LL), G::Add_Link(N + y, G::T, 1, 0LL); G::Add_Link(x, N + y, 1, -V[i]); } for (int i = 1; i <= N - 1; ++i) { if (XL[i]) G::Add_Link(G::S, i + 1, XL[i], 0LL), G::Add_Link(i, G::T, XL[i], 0LL), FLOW += XL[i]; if (XR[i] - XL[i]) G::Add_Link(i, i + 1, XR[i] - XL[i], 0LL); } for (int i = 1; i <= N - 1; ++i) { if (YL[i]) G::Add_Link(G::S, N + i, YL[i], 0LL), G::Add_Link(N + (i + 1), G::T, YL[i], 0LL), FLOW += YL[i]; if (YR[i] - YL[i]) G::Add_Link(N + (i + 1), N + i, YR[i] - YL[i], 0LL); } FLOW += Sum, G::Add_Link(N, G::T, Sum, 0LL), G::Add_Link(G::S, N + N, Sum, 0LL); G::MCMF(FLOW, COST); if (FLOW) goto loop; Ans = max(Ans, COST); } loop: printf("%lld", Ans); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <queue> using namespace std; const int INF(0X3F3F3F3F); typedef long long int LL; namespace G { const int Max_V(85 * 2); const int Max_E(85 * 30); int V, S, T, Head[Max_V], Total, To[Max_E], Next[Max_E], Cap[Max_E], Flow[Max_E]; LL Weight[Max_E]; void clear() { for (int i = 1; i <= V; ++i) Head[i] = 0; for (int i = 2; i <= Total + 1; ++i) To[i] = Next[i] = Cap[i] = Flow[i] = Weight[i] = 0; V = S = T = Total = 0; } inline void Add_Edge(int tot, int s, int t, int c, LL w) { To[tot] = t, Next[tot] = Head[s], Head[s] = tot, Cap[tot] = c, Flow[tot] = 0, Weight[tot] = w; } inline void Add_Link(int s, int t, int c, LL w) { Total += 2, Add_Edge(Total, s, t, c, w), Add_Edge(Total ^ 1, t, s, 0, -w); } LL Dist[Max_V]; bool InQ[Max_V], done[Max_V]; bool SPFA() { queue<int> Q; memset(Dist, -0X3F, sizeof(Dist)), Dist[S] = 0LL; memset(done, false, sizeof(done)), Q.push(S), InQ[S] = true; for (int u; Q.empty() == false;) { u = Q.front(), Q.pop(), InQ[u] = false, done[u] = true; for (int i = Head[u], v; i; i = Next[i]) if (Cap[i] > Flow[i] && Dist[v = To[i]] < Dist[u] + Weight[i]) { Dist[v] = Dist[u] + Weight[i]; if (!InQ[v]) Q.push(v), InQ[v] = true; } } return done[T]; } int Cur[Max_V]; int DFS(int u, int a) { if (u == T || a == 0) return a; int Ans(0); done[u] = true; for (int &i = Cur[u], v, f; i; i = Next[i]) if (Dist[v = To[i]] == Dist[u] + Weight[i] && !done[v] && (f = DFS(v, min(a, Cap[i] - Flow[i]))) > 0) { Ans += f, Flow[i] += f, Flow[i ^ 1] -= f; if ((a -= f) == 0) break; } done[u] = false; return Ans; } void MCMF(int &FLOW, LL &COST) { for (int f; SPFA();) { for (int i = 1; i <= V; ++i) Cur[i] = Head[i], done[i] = false; FLOW -= (f = DFS(S, INF)), COST += Dist[T] * f; } } } // namespace G const int Max_N(85); const int Max_M(325); int N, X[Max_N], Y[Max_N], PX[Max_N], PY[Max_N], XL[Max_N], XR[Max_N], YL[Max_N], YR[Max_N], M, T[Max_M], A[Max_M], B[Max_M]; LL V[Max_N], Ans; inline bool comp_X(int a, int b) { return X[a] < X[b]; } inline bool comp_Y(int a, int b) { return Y[a] < Y[b]; } /* 枚举选的宝石总数Sum,那么可以变成对于每个前缀选的宝石数量都有一个区间的限制。在X轴和Y轴上分别可以列出方程 X轴的方程组: 0 = 0 X[1] = XV[1] X[1] + X[2] = XV[2] ... X[1] + X[2] + ... + X[N] = Sum Y轴的方程组: 0 = 0 Y[1] = YV[1] Y[1] + Y[2] = YV[2] ... Y[1] + Y[2] + ... + Y[N] = Sum 对于每个XV[i],有XL[i] <= XV[i] <= XR[i]的限制;对于每个YV[i],有YL[i] <= YV[i] <= YR[i]的限制 对于每个轴的方程组,两两差分。那么每个XV和YV出现了恰好两次,系数分别是+1和-1。每个X和Y出现了恰好一次 那么对于点(x, y),X[x]和Y[y]是同一个变量。所以这些变量可以看做出现了恰好两次,系数分别是+1和-1 然后用流量平衡建图,可以得到一个最大费用可行流问题 */ int main() { scanf("%d", &N); for (int i = 1; i <= N; ++i) scanf("%d%d%lld", X + i, Y + i, V + i), PX[i] = PY[i] = i; sort(PX + 1, PX + 1 + N, comp_X), sort(PY + 1, PY + 1 + N, comp_Y); scanf("%d", &M); for (int i = 1; i <= M; ++i) { char op[10]; scanf("%s%d%d", op, A + i, B + i); if (*op == 'L') T[i] = 1; if (*op == 'R') T[i] = 2; if (*op == 'D') T[i] = 3; if (*op == 'U') T[i] = 4; } for (int Sum = 1; Sum <= N; ++Sum) { XL[0] = YL[0] = XR[0] = YR[0] = 0; for (int i = 1; i <= N - 1; ++i) XL[i] = YL[i] = 0, XR[i] = YR[i] = Sum; XL[N] = YL[N] = XR[N] = YR[N] = Sum; for (int i = 1; i <= M; ++i) { if (T[i] == 1) if (X[PX[1]] <= A[i]) for (int j = 1; j <= N; ++j) if (j == N || X[PX[j + 1]] > A[i]) { XR[j] = min(XR[j], B[i]); break; } if (T[i] == 2) if (A[i] <= X[PX[N]]) for (int j = N - 1; j >= 0; --j) if (j == 0 || A[i] > X[PX[j]]) { XL[j] = max(XL[j], Sum - B[i]); break; } if (T[i] == 3) if (Y[PY[1]] <= A[i]) for (int j = 1; j <= N; ++j) if (j == N || Y[PY[j + 1]] > A[i]) { YR[j] = min(YR[j], B[i]); break; } if (T[i] == 4) if (A[i] <= Y[PY[N]]) for (int j = N - 1; j >= 0; --j) if (j == 0 || A[i] > Y[PY[j]]) { YL[j] = max(YL[j], Sum - B[i]); break; } } for (int i = 0; i <= N; ++i) if (XL[i] > XR[i] || YL[i] > YR[i]) goto loop; int FLOW(0); LL COST(0LL); G::clear(), G::V = N + N + 2, G::S = N + N + 1, G::T = N + N + 2; for (int i = 1, x, y; i <= N; ++i) { for (x = 1; x <= N; ++x) if (PX[x] == i) break; for (y = 1; y <= N; ++y) if (PY[y] == i) break; COST += V[i], ++FLOW, G::Add_Link(G::S, x, 1, 0LL), G::Add_Link(N + y, G::T, 1, 0LL); G::Add_Link(x, N + y, 1, -V[i]); } for (int i = 1; i <= N - 1; ++i) { if (XL[i]) G::Add_Link(G::S, i + 1, XL[i], 0LL), G::Add_Link(i, G::T, XL[i], 0LL), FLOW += XL[i]; if (XR[i] - XL[i]) G::Add_Link(i, i + 1, XR[i] - XL[i], 0LL); } for (int i = 1; i <= N - 1; ++i) { if (YL[i]) G::Add_Link(G::S, N + i, YL[i], 0LL), G::Add_Link(N + (i + 1), G::T, YL[i], 0LL), FLOW += YL[i]; if (YR[i] - YL[i]) G::Add_Link(N + (i + 1), N + i, YR[i] - YL[i], 0LL); } FLOW += Sum, G::Add_Link(N, G::T, Sum, 0LL), G::Add_Link(G::S, N + N, Sum, 0LL); G::MCMF(FLOW, COST); if (FLOW) goto loop; Ans = max(Ans, COST); } loop: printf("%lld", Ans); return 0; }
[ "literal.number.change", "call.arguments.change", "expression.operation.binary.change", "assignment.change" ]
910,901
910,900
u710399266
cpp
p03100
#include <bits/stdc++.h> #define ll long long #define ld long double #define pint pair<int, int> #define mk(x, y) make_pair(x, y) #define fir first #define sec second #define Rep(x, y, z) for (int x = y; x <= z; ++x) #define Red(x, y, z) for (int x = y; x >= z; --x) using namespace std; const int MAXN = 3e5 + 5; char buf[1 << 12], *p1 = buf, *p2 = buf, nc; int ny; inline char gc() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 12, stdin), p1 == p2) ? EOF : *p1++; } // inline char gc(){return getchar();} inline int read() { int x = 0; ny = 1; while (nc = gc(), (nc < 48 || nc > 57) && nc != EOF) if (nc == 45) ny = -1; if (nc < 0) return nc; x = nc - 48; while (nc = gc(), 47 < nc && nc < 58 && nc != EOF) x = (x << 3) + (x << 1) + (nc ^ 48); return x * ny; } int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); } int fa[MAXN], n, m, k, Mod, g, v, vis[2][MAXN * 5]; vector<pint> G[MAXN]; inline int id(int x, int y, int z) { return (x - 1) * 6 + 2 * y + z + 1; } inline void pre(int s, int Mod) { for (int i = 0, j = s; i < (Mod << 1); j = (j * 2) % Mod, i++) vis[i & 1][j] = 1; } int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); } inline int Merge(int x, int y) { fa[gf(y)] = gf(x); } int main() { // freopen("std.in","r",stdin); // freopen("std.out","w",stdout); n = read(), m = read(), k = read(), Mod = read(); for (int last = -1, i = 1; i <= m; i++) { int x = read(), y = read(), z = read(); G[x].push_back(mk(y, z)), G[y].push_back(mk(x, z)); if (~last) g = gcd(g, z - last); last = z; } if (!g) g = Mod; Mod = gcd(Mod, 3 * g), v = G[1][0].sec % g, pre(v, Mod); Rep(i, 1, 6 * n) fa[i] = i; Rep(i, 1, n) for (int j = 0, len = G[i].size(); j < len; j++) { int y = G[i][j].fir, v = G[i][j].sec / g; Rep(k, 0, 2) Merge(id(i, k, 0), id(y, (2 * k + v) % 3, 1)), Merge(id(i, k, 1), id(y, (2 * k + v) % 3, 0)); } Rep(i, 1, k) { int x = read(), y = read(), z = (read() + v) % Mod, flg = 0; Rep(j, 0, 2) Rep(k, 0, 1) if (vis[k][(z - j * g % Mod + Mod) % Mod] && gf(id(y, 0, 0)) == gf(id(x, j, k))) flg = 1; puts(flg ? "YES" : "NO"); } return 0; }
#include <bits/stdc++.h> #define ll long long #define ld long double #define pint pair<int, int> #define mk(x, y) make_pair(x, y) #define fir first #define sec second #define Rep(x, y, z) for (int x = y; x <= z; ++x) #define Red(x, y, z) for (int x = y; x >= z; --x) using namespace std; const int MAXN = 3e5 + 5; char buf[1 << 12], *p1 = buf, *p2 = buf, nc; int ny; inline char gc() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 12, stdin), p1 == p2) ? EOF : *p1++; } // inline char gc(){return getchar();} inline int read() { int x = 0; ny = 1; while (nc = gc(), (nc < 48 || nc > 57) && nc != EOF) if (nc == 45) ny = -1; if (nc < 0) return nc; x = nc - 48; while (nc = gc(), 47 < nc && nc < 58 && nc != EOF) x = (x << 3) + (x << 1) + (nc ^ 48); return x * ny; } int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); } int fa[MAXN], n, m, k, Mod, g, v, vis[2][MAXN * 5]; vector<pint> G[MAXN]; inline int id(int x, int y, int z) { return (x - 1) * 6 + 2 * y + z + 1; } inline void pre(int s, int Mod) { for (int i = 0, j = s; i < (Mod << 1); j = (j * 2) % Mod, i++) vis[i & 1][j] = 1; } int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); } inline void Merge(int x, int y) { fa[gf(y)] = gf(x); } int main() { // freopen("std.in","r",stdin); // freopen("std.out","w",stdout); n = read(), m = read(), k = read(), Mod = read(); for (int last = -1, i = 1; i <= m; i++) { int x = read(), y = read(), z = read(); G[x].push_back(mk(y, z)), G[y].push_back(mk(x, z)); if (~last) g = gcd(g, abs(z - last)); last = z; } if (!g) g = Mod; Mod = gcd(Mod, 3 * g), v = G[1][0].sec % g, pre(v, Mod); Rep(i, 1, 6 * n) fa[i] = i; Rep(i, 1, n) for (int j = 0, len = G[i].size(); j < len; j++) { int y = G[i][j].fir, v = G[i][j].sec / g; Rep(k, 0, 2) Merge(id(i, k, 0), id(y, (2 * k + v) % 3, 1)), Merge(id(i, k, 1), id(y, (2 * k + v) % 3, 0)); } Rep(i, 1, k) { int x = read(), y = read(), z = (read() + v) % Mod, flg = 0; Rep(j, 0, 2) Rep(k, 0, 1) if (vis[k][(z - j * g % Mod + Mod) % Mod] && gf(id(y, 0, 0)) == gf(id(x, j, k))) flg = 1; puts(flg ? "YES" : "NO"); } return 0; }
[ "function.return_type.change", "call.add", "call.arguments.change" ]
910,915
910,914
u710376653
cpp
p03100
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <vector> using namespace std; #define LL long long #define fgx cerr << "--------------" << endl; #define dgx cerr << "==============" << endl; inline int read() { int x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return x * f; } const int MAXN = 1000010; const int INF = 2147483600; int N, M, Q, Mod; int fa[MAXN + 1]; bool f[2][MAXN + 1]; int a[MAXN + 1], b[MAXN + 1], c[MAXN + 1]; inline int gcd(int a, int b) { if (!b) return a; return gcd(b, a % b); } inline int Id(int x, int y, int z) { return x * 6 + y * 2 + z; } inline int find(int x) { return (fa[x] == x ? fa[x] : (fa[x] = find(fa[x]))); } inline void link(int u, int v) { if (find(u) == find(v)) return; fa[find(v)] = find(u); } int main() { // freopen(".in","r",stdin); // freopen(".out","w",stdout); N = read(), M = read(), Q = read(), Mod = read(); int g = 0; for (int i = 1; i <= M; i++) { a[i] = read(), b[i] = read(), c[i] = read(); g = gcd(g, abs(c[i] - c[1])); } if (!g) g = Mod; Mod = gcd(Mod, 3 * g); LL z = c[1] % Mod; for (int i = 0; i < 6 * N; i++) fa[i] = i; for (int i = 1; i <= M; i++) { int u = a[i] - 1, v = b[i] - 1, w = ((c[i] - z) / g) % 3; for (int x = 0; x < 3; x++) { link(Id(u, x, 0), Id(v, (x * 2 + w) % 3, 1)); link(Id(u, x, 1), Id(v, (x * 2 + w) % 3, 0)); link(Id(v, x, 0), Id(u, (x * 2 + w) % 3, 1)); link(Id(v, x, 1), Id(u, (x * 2 + w) % 3, 0)); } } for (int i = 0, nw = z; i < (Mod << 1); nw = (nw << 1) % Mod, i++) f[i & 1][nw] = 1; while (Q--) { bool can = 0; int u = read(), v = read(), r = read(); --u; --v; for (int j = 0; j < 2; j++) for (int k = 0; k < 3; k++) { if (find(Id(v, 0, 0)) == find(Id(u, k, j))) { can |= f[j][(r + z + (3 - k) * g) % Mod]; } } if (can) puts("YES"); else puts("NO"); } return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <vector> using namespace std; #define LL long long #define fgx cerr << "--------------" << endl; #define dgx cerr << "==============" << endl; inline int read() { int x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return x * f; } const int MAXN = 1000010; const int INF = 2147483600; int N, M, Q, Mod; int fa[MAXN + 1]; bool f[2][MAXN + 1]; int a[MAXN + 1], b[MAXN + 1], c[MAXN + 1]; inline int gcd(int a, int b) { if (!b) return a; return gcd(b, a % b); } inline int Id(int x, int y, int z) { return x * 6 + y * 2 + z; } inline int find(int x) { return (fa[x] == x ? fa[x] : (fa[x] = find(fa[x]))); } inline void link(int u, int v) { if (find(u) == find(v)) return; fa[find(v)] = find(u); } int main() { // freopen(".in","r",stdin); // freopen(".out","w",stdout); N = read(), M = read(), Q = read(), Mod = read(); int g = 0; for (int i = 1; i <= M; i++) { a[i] = read(), b[i] = read(), c[i] = read(); g = gcd(g, abs(c[i] - c[1])); } if (!g) g = Mod; Mod = gcd(Mod, 3 * g); LL z = c[1] % g; for (int i = 0; i < 6 * N; i++) fa[i] = i; for (int i = 1; i <= M; i++) { int u = a[i] - 1, v = b[i] - 1, w = ((c[i] - z) / g) % 3; for (int x = 0; x < 3; x++) { link(Id(u, x, 0), Id(v, (x * 2 + w) % 3, 1)); link(Id(u, x, 1), Id(v, (x * 2 + w) % 3, 0)); link(Id(v, x, 0), Id(u, (x * 2 + w) % 3, 1)); link(Id(v, x, 1), Id(u, (x * 2 + w) % 3, 0)); } } for (int i = 0, nw = z; i < (Mod << 1); nw = (nw << 1) % Mod, i++) f[i & 1][nw] = 1; while (Q--) { bool can = 0; int u = read(), v = read(), r = read(); --u; --v; for (int j = 0; j < 2; j++) for (int k = 0; k < 3; k++) { if (find(Id(v, 0, 0)) == find(Id(u, k, j))) { can |= f[j][(r + z + (3 - k) * g) % Mod]; } } if (can) puts("YES"); else puts("NO"); } return 0; }
[ "identifier.change", "expression.operation.binary.change" ]
910,916
910,917
u702906763
cpp
p03100
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <vector> using namespace std; #define LL long long #define fgx cerr << "--------------" << endl; #define dgx cerr << "==============" << endl; inline int read() { int x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return x * f; } const int MAXN = 1000010; const int INF = 2147483600; int N, M, Q, Mod; int fa[MAXN + 1]; bool f[2][MAXN + 1]; int a[MAXN + 1], b[MAXN + 1], c[MAXN + 1]; inline int gcd(int a, int b) { if (!b) return a; return gcd(b, a % b); } inline int Id(int x, int y, int z) { return x * 6 + y * 2 + z; } inline int find(int x) { return (fa[x] == x ? fa[x] : (fa[x] = find(fa[x]))); } inline void link(int u, int v) { if (find(u) == find(v)) return; fa[find(v)] = find(u); } int main() { // freopen(".in","r",stdin); // freopen(".out","w",stdout); N = read(), M = read(), Q = read(), Mod = read(); int g = 0; for (int i = 1; i <= M; i++) { a[i] = read(), b[i] = read(), c[i] = read(); g = gcd(g, abs(c[i] - c[1])); } if (!g) g = Mod; Mod = gcd(Mod, 3 * g); LL z = c[1] % Mod; for (int i = 0; i < 6 * N; i++) fa[i] = i; for (int i = 1; i <= M; i++) { int u = a[i] - 1, v = b[i] - 1, w = ((c[i] - z) / g) % 3; for (int x = 0; x < 3; x++) { link(Id(u, x, 0), Id(v, (x * 2 + w) % 3, 1)); link(Id(u, x, 1), Id(v, (x * 2 + w) % 3, 0)); link(Id(v, x, 0), Id(u, (x * 2 + w) % 3, 1)); link(Id(v, x, 1), Id(u, (x * 2 + w) % 3, 0)); } } for (int i = 0, nw = 1; i < (Mod << 1); nw = (nw << 1) % Mod, i++) f[i & 1][nw] = 1; while (Q--) { bool can = 0; int u = read(), v = read(), r = read(); --u; --v; for (int j = 0; j < 2; j++) for (int k = 0; k < 3; k++) { if (find(Id(v, 0, 0)) == find(Id(u, k, j))) { can |= f[j][(r + z + (3 - k) * g) % Mod]; } } if (can) puts("YES"); else puts("NO"); } return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <vector> using namespace std; #define LL long long #define fgx cerr << "--------------" << endl; #define dgx cerr << "==============" << endl; inline int read() { int x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return x * f; } const int MAXN = 1000010; const int INF = 2147483600; int N, M, Q, Mod; int fa[MAXN + 1]; bool f[2][MAXN + 1]; int a[MAXN + 1], b[MAXN + 1], c[MAXN + 1]; inline int gcd(int a, int b) { if (!b) return a; return gcd(b, a % b); } inline int Id(int x, int y, int z) { return x * 6 + y * 2 + z; } inline int find(int x) { return (fa[x] == x ? fa[x] : (fa[x] = find(fa[x]))); } inline void link(int u, int v) { if (find(u) == find(v)) return; fa[find(v)] = find(u); } int main() { // freopen(".in","r",stdin); // freopen(".out","w",stdout); N = read(), M = read(), Q = read(), Mod = read(); int g = 0; for (int i = 1; i <= M; i++) { a[i] = read(), b[i] = read(), c[i] = read(); g = gcd(g, abs(c[i] - c[1])); } if (!g) g = Mod; Mod = gcd(Mod, 3 * g); LL z = c[1] % g; for (int i = 0; i < 6 * N; i++) fa[i] = i; for (int i = 1; i <= M; i++) { int u = a[i] - 1, v = b[i] - 1, w = ((c[i] - z) / g) % 3; for (int x = 0; x < 3; x++) { link(Id(u, x, 0), Id(v, (x * 2 + w) % 3, 1)); link(Id(u, x, 1), Id(v, (x * 2 + w) % 3, 0)); link(Id(v, x, 0), Id(u, (x * 2 + w) % 3, 1)); link(Id(v, x, 1), Id(u, (x * 2 + w) % 3, 0)); } } for (int i = 0, nw = z; i < (Mod << 1); nw = (nw << 1) % Mod, i++) f[i & 1][nw] = 1; while (Q--) { bool can = 0; int u = read(), v = read(), r = read(); --u; --v; for (int j = 0; j < 2; j++) for (int k = 0; k < 3; k++) { if (find(Id(v, 0, 0)) == find(Id(u, k, j))) { can |= f[j][(r + z + (3 - k) * g) % Mod]; } } if (can) puts("YES"); else puts("NO"); } return 0; }
[ "identifier.change", "expression.operation.binary.change", "variable_declaration.value.change", "identifier.replace.add", "literal.replace.remove", "control_flow.loop.for.initializer.change" ]
910,919
910,917
u702906763
cpp
p03100
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #define fi first #define se second #define N 1000005 using namespace std; typedef long long ll; template <class T> inline void read(T &x) { char ch; bool flag = false; while (!isdigit(ch = getchar())) flag |= ch == '-'; for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48)) ; if (flag) x = -x; } inline int input() { int x; char ch; bool flag = false; while (!isdigit(ch = getchar())) flag |= ch == '-'; for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48)) ; return flag ? -x : x; } int mod; inline int add(int x, int y) { x += y; return x >= mod ? x - mod : x; } inline void inc(int &x, int y) { x += y; x -= x >= mod ? mod : 0; } inline int Power(int x, int y) { int res = 1; while (y) { if (y & 1) res = (ll)res * x % mod; x = (ll)x * x % mod, y >>= 1; } return res; } template <class T> void chkmax(T &x, T y) { x = x > y ? x : y; } template <class T> void chkmin(T &x, T y) { x = x < y ? x : y; } template <class T> T gcd(T x, T y) { return !y ? x : gcd(y, x % y); } int n, m, q; int u[N], v[N], c[N]; bool pd[2][N]; int fa[N]; int g, z; int Id(int x, int y, int z) { return (x - 1) * 6 + y * 3 + z; } int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } void merge(int x, int y) { fa[find(x)] = find(y); } int main() { ios::sync_with_stdio(false); cin >> n >> m >> q >> mod; for (int i = 1; i <= m; ++i) { cin >> u[i] >> v[i] >> c[i]; g = gcd(g, abs(c[i] - c[1])); } if (!g) g = mod; mod = gcd(mod, g * 3); z = c[1] % g; for (int i = 1; i <= n * 6; ++i) fa[i] = i; for (int i = 1; i <= m; ++i) { int w = (c[i] - z) / g; for (int p = 0; p <= 1; ++p) for (int q = 0; q <= 2; ++q) { merge(Id(u[i], p, q), Id(v[i], 1 - p, (2 * q + w) % 3)); merge(Id(v[i], p, q), Id(u[i], 1 - p, (2 * q + w) % 3)); } } for (int i = 0, Pow = z; i < mod << 1; ++i, (Pow <<= 1) %= mod) pd[i & 1][Pow] = true; while (q--) { int s, t, r; cin >> s >> t >> r; bool flag = false; for (int p : {0, 1}) for (int q : {0, 2}) if (find(Id(t, 0, 0)) == find(Id(s, p, q))) flag |= pd[p][(r + z + (3 - q) * g) % mod]; puts(flag ? "YES" : "NO"); } return 0; }
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #define fi first #define se second #define N 1000005 using namespace std; typedef long long ll; template <class T> inline void read(T &x) { char ch; bool flag = false; while (!isdigit(ch = getchar())) flag |= ch == '-'; for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48)) ; if (flag) x = -x; } inline int input() { int x; char ch; bool flag = false; while (!isdigit(ch = getchar())) flag |= ch == '-'; for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48)) ; return flag ? -x : x; } int mod; inline int add(int x, int y) { x += y; return x >= mod ? x - mod : x; } inline void inc(int &x, int y) { x += y; x -= x >= mod ? mod : 0; } inline int Power(int x, int y) { int res = 1; while (y) { if (y & 1) res = (ll)res * x % mod; x = (ll)x * x % mod, y >>= 1; } return res; } template <class T> void chkmax(T &x, T y) { x = x > y ? x : y; } template <class T> void chkmin(T &x, T y) { x = x < y ? x : y; } template <class T> T gcd(T x, T y) { return !y ? x : gcd(y, x % y); } int n, m, q; int u[N], v[N], c[N]; bool pd[2][N]; int fa[N]; int g, z; int Id(int x, int y, int z) { return (x - 1) * 6 + y * 3 + z; } int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } void merge(int x, int y) { fa[find(x)] = find(y); } int main() { ios::sync_with_stdio(false); cin >> n >> m >> q >> mod; for (int i = 1; i <= m; ++i) { cin >> u[i] >> v[i] >> c[i]; g = gcd(g, abs(c[i] - c[1])); } if (!g) g = mod; mod = gcd(mod, g * 3); z = c[1] % g; for (int i = 1; i <= n * 6; ++i) fa[i] = i; for (int i = 1; i <= m; ++i) { int w = (c[i] - z) / g; for (int p = 0; p <= 1; ++p) for (int q = 0; q <= 2; ++q) { merge(Id(u[i], p, q), Id(v[i], 1 - p, (2 * q + w) % 3)); merge(Id(v[i], p, q), Id(u[i], 1 - p, (2 * q + w) % 3)); } } for (int i = 0, Pow = z; i < mod << 1; ++i, (Pow <<= 1) %= mod) pd[i & 1][Pow] = true; while (q--) { int s, t, r; cin >> s >> t >> r; bool flag = false; for (int p : {0, 1}) for (int q : {0, 1, 2}) if (find(Id(t, 0, 0)) == find(Id(s, p, q))) flag |= pd[p][(r + z + (3 - q) * g) % mod]; puts(flag ? "YES" : "NO"); } return 0; }
[]
910,922
910,923
u018679195
cpp
p03100
#include <bits/stdc++.h> #define N 5000005 using namespace std; int n, m, q; int z, g, mod; int u[N], v[N], w[N]; int fa[N * 6]; bool vis[2][N]; template <class T> inline void read(T &x) { char c; int sign = 1; while ((c = getchar()) > '9' || c < '0') if (c == '-') sign = -1; x = c - 48; while ((c = getchar()) >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - 48; x *= sign; } int getid(int x, int p, int q) { return (x - 1) * 6 + p * 3 + q + 1; } int gcd(int a, int b) { return (!b) ? a : gcd(b, a % b); } int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } void merge(int x, int y) { if (find(x) != find(y)) fa[find(x)] = find(y); } int main() { read(n); read(m); read(q); read(mod); for (int i = 1; i <= m; ++i) { read(u[i]); read(v[i]); read(w[i]); g = gcd(g, w[i] - w[1]); } if (!g) g = mod; mod = gcd(mod, 3 * g); z = w[1] % g; for (int i = 1; i <= 6 * n; ++i) fa[i] = i; for (int i = 1; i <= m; ++i) { int c = (w[i] - z) / g; for (int p = 0; p <= 1; ++p) //次幂 { for (int q = 0; q <= 2; ++q) //常数 { merge(getid(u[i], p, q), getid(v[i], p ^ 1, (q * 2 + c) % 3)); merge(getid(v[i], p, q), getid(u[i], p ^ 1, (q * 2 + c) % 3)); } } } for (int i = 0, j = z; i < (mod * 2); ++i, j = j * 2 % mod) vis[i & 1][j] = 1; while (q--) { int s, t, r; read(s); read(t); read(r); bool ok = 0; for (int p = 0; p <= 1; ++p) { for (int q = 0; q <= 2; ++q) { if (find(getid(t, 0, 0)) == find(getid(s, p, q))) { ok |= vis[p][(r + z + (3 - q) * g) % mod]; } } } puts(ok ? "YES" : "NO"); } return 0; }
#include <bits/stdc++.h> #define N 1000005 using namespace std; int n, m, q; int z, g, mod; int u[N], v[N], w[N]; int fa[N * 6]; bool vis[2][N]; template <class T> inline void read(T &x) { char c; int sign = 1; while ((c = getchar()) > '9' || c < '0') if (c == '-') sign = -1; x = c - 48; while ((c = getchar()) >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - 48; x *= sign; } int getid(int x, int p, int q) { return (x - 1) * 6 + p * 3 + q + 1; } int gcd(int a, int b) { return (!b) ? a : gcd(b, a % b); } int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } void merge(int x, int y) { if (find(x) != find(y)) fa[find(x)] = find(y); } int main() { read(n); read(m); read(q); read(mod); for (int i = 1; i <= m; ++i) { read(u[i]); read(v[i]); read(w[i]); g = gcd(g, abs(w[i] - w[1])); } if (!g) g = mod; mod = gcd(mod, 3 * g); z = w[1] % g; for (int i = 1; i <= 6 * n; ++i) fa[i] = i; for (int i = 1; i <= m; ++i) { int c = (w[i] - z) / g; for (int p = 0; p <= 1; ++p) //次幂 { for (int q = 0; q <= 2; ++q) //常数 { merge(getid(u[i], p, q), getid(v[i], p ^ 1, (q * 2 + c) % 3)); merge(getid(v[i], p, q), getid(u[i], p ^ 1, (q * 2 + c) % 3)); } } } for (int i = 0, j = z; i < (mod * 2); ++i, j = j * 2 % mod) vis[i & 1][j] = 1; while (q--) { int s, t, r; read(s); read(t); read(r); bool ok = 0; for (int p = 0; p <= 1; ++p) { for (int q = 0; q <= 2; ++q) { if (find(getid(t, 0, 0)) == find(getid(s, p, q))) { ok |= vis[p][(r + z + (3 - q) * g) % mod]; } } } puts(ok ? "YES" : "NO"); } return 0; }
[ "preprocessor.define.value.change", "literal.integer.change", "call.add", "call.arguments.change" ]
910,927
910,928
u996413591
cpp
p03100
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #define N (100010) #define M () #define inf (0x7f7f7f7f) #define rg register int #define Label puts("NAIVE") #define spa print(' ') #define ent print('\n') #define rand() (((rand()) << (15)) ^ (rand())) #define file(s) freopen(s ".in", "r", stdin), freopen(s ".out", "w", stdout) typedef long double ld; typedef long long LL; typedef unsigned long long ull; using namespace std; namespace fastIO1 { inline char read() { static const int IN_LEN = 1000000; static char buf[IN_LEN], *s, *t; return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++); } template <class T> inline void read(T &x) { static bool iosig; static char c; for (iosig = false, c = read(); !isdigit(c); c = read()) { if (c == '-') iosig = true; if (c == -1) return; } for (x = 0; isdigit(c); c = read()) x = ((x + (x << 2)) << 1) + (c ^ '0'); if (iosig) x = -x; } inline char readc(char &c) { for (c = read(); !isalpha(c) && !isdigit(c); c = read()) if (c == -1) return 0; } const int OUT_LEN = 10000000; char obuf[OUT_LEN], *ooh = obuf; inline void print(char c) { if (ooh == obuf + OUT_LEN) fwrite(obuf, 1, OUT_LEN, stdout), ooh = obuf; *ooh++ = c; } template <class T> inline void print(T x) { static int buf[30], cnt; if (x == 0) print('0'); else { if (x < 0) print('-'), x = -x; for (cnt = 0; x; x /= 10) buf[++cnt] = x % 10 + 48; while (cnt) print((char)buf[cnt--]); } } inline void flush() { fwrite(obuf, 1, ooh - obuf, stdout); } } // namespace fastIO1 namespace fastIO2 { template <class T> inline void read(T &x) { static bool iosig; static char c; for (iosig = false, c = getchar(); !isdigit(c); c = getchar()) { if (c == '-') iosig = true; if (c == -1) return; } for (x = 0; isdigit(c); c = getchar()) x = ((x + (x << 2)) << 1) + (c ^ '0'); if (iosig) x = -x; } } // namespace fastIO2 using namespace fastIO1; struct edge { int x, y, c; } e[N]; int n, m, g, P, Q, fa[N], pos[N][2][3], res, tot; bool can[1000010][2]; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int ask(int x) { return fa[x] == x ? x : fa[x] = ask(fa[x]); } void unite(int x, int y) { x = ask(x), y = ask(y); if (x != y) fa[x] = y; } int main() { read(n), read(m), read(Q), read(P), g = P; for (int i = 1; i <= m; i++) read(e[i].x), read(e[i].y), read(e[i].c), g = gcd(g, (int)abs(e[i].c - e[1].c)); // cout<<g<<endl; P = gcd(P, 3 * g), res = e[1].c % g; for (int i = 1; i <= n * 6; i++) fa[i] = i; for (int i = 0, x = res; i <= P; i++, x = (x + x) % P) can[x][i & 1] = 1; for (int i = 1; i <= n; i++) for (int j = 0; j <= 1; j++) for (int k = 0; k <= 2; k++) pos[i][j][k] = ++tot; for (int i = 1; i <= m; i++) { int w = (e[i].c - res) % P / g, x = e[i].x, y = e[i].y; for (int j = 0; j <= 1; j++) for (int k = 0; k <= 2; k++) unite(pos[x][j][k], pos[y][j ^ 1][(2 * k + w) % 3]); } while (Q--) { int x, y, z; bool fl = 0; read(x), read(y), read(z); for (int i = 0; i <= 1; i++) for (int j = 0; j <= 2; j++) fl |= (ask(pos[y][0][0]) == ask(pos[x][i][j])) && can[(z + res + (3 - j) * g) % P][i]; puts(fl ? "Yes" : "No"); } }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #define N (500010) #define M () #define inf (0x7f7f7f7f) #define rg register int #define Label puts("NAIVE") #define spa print(' ') #define ent print('\n') #define rand() (((rand()) << (15)) ^ (rand())) #define file(s) freopen(s ".in", "r", stdin), freopen(s ".out", "w", stdout) typedef long double ld; typedef long long LL; typedef unsigned long long ull; using namespace std; namespace fastIO1 { inline char read() { static const int IN_LEN = 1000000; static char buf[IN_LEN], *s, *t; return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++); } template <class T> inline void read(T &x) { static bool iosig; static char c; for (iosig = false, c = read(); !isdigit(c); c = read()) { if (c == '-') iosig = true; if (c == -1) return; } for (x = 0; isdigit(c); c = read()) x = ((x + (x << 2)) << 1) + (c ^ '0'); if (iosig) x = -x; } inline char readc(char &c) { for (c = read(); !isalpha(c) && !isdigit(c); c = read()) if (c == -1) return 0; } const int OUT_LEN = 10000000; char obuf[OUT_LEN], *ooh = obuf; inline void print(char c) { if (ooh == obuf + OUT_LEN) fwrite(obuf, 1, OUT_LEN, stdout), ooh = obuf; *ooh++ = c; } template <class T> inline void print(T x) { static int buf[30], cnt; if (x == 0) print('0'); else { if (x < 0) print('-'), x = -x; for (cnt = 0; x; x /= 10) buf[++cnt] = x % 10 + 48; while (cnt) print((char)buf[cnt--]); } } inline void flush() { fwrite(obuf, 1, ooh - obuf, stdout); } } // namespace fastIO1 namespace fastIO2 { template <class T> inline void read(T &x) { static bool iosig; static char c; for (iosig = false, c = getchar(); !isdigit(c); c = getchar()) { if (c == '-') iosig = true; if (c == -1) return; } for (x = 0; isdigit(c); c = getchar()) x = ((x + (x << 2)) << 1) + (c ^ '0'); if (iosig) x = -x; } } // namespace fastIO2 using namespace fastIO1; struct edge { int x, y, c; } e[N]; int n, m, g, P, Q, fa[N], pos[N][2][3], res, tot; bool can[1000010][2]; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int ask(int x) { return fa[x] == x ? x : fa[x] = ask(fa[x]); } void unite(int x, int y) { x = ask(x), y = ask(y); if (x != y) fa[x] = y; } int main() { // freopen("01.txt","r",stdin); // freopen("my.out","w",stdout); read(n), read(m), read(Q), read(P), g = P; for (int i = 1; i <= m; i++) read(e[i].x), read(e[i].y), read(e[i].c), g = gcd(g, (int)abs(e[i].c - e[1].c)); // cout<<g<<endl; P = gcd(P, 3 * g), res = e[1].c % g; for (int i = 1; i <= n * 6; i++) fa[i] = i; for (int i = 0, x = res; i <= P; i++, x = (x + x) % P) can[x][i & 1] = 1; for (int i = 1; i <= n; i++) for (int j = 0; j <= 1; j++) for (int k = 0; k <= 2; k++) pos[i][j][k] = ++tot; for (int i = 1; i <= m; i++) { int w = (e[i].c - res) % P / g, x = e[i].x, y = e[i].y; for (int j = 0; j <= 1; j++) for (int k = 0; k <= 2; k++) unite(pos[x][j][k], pos[y][j ^ 1][(2 * k + w) % 3]); } while (Q--) { int x, y, z; bool fl = 0; read(x), read(y), read(z); for (int i = 0; i <= 1; i++) for (int j = 0; j <= 2; j++) fl |= (ask(pos[y][0][0]) == ask(pos[x][i][j])) && can[(z + res + (3 - j) * g) % P][i]; puts(fl ? "YES" : "NO"); } }
[ "preprocessor.define.value.change", "literal.integer.change", "literal.string.change", "literal.string.case.change", "call.arguments.change", "io.output.change" ]
910,933
910,932
u293624543
cpp
p03100
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 5; const int MAXP = 1e6 + 5; typedef long long ll; template <typename T> void chkmax(T &x, T y) { x = max(x, y); } template <typename T> void chkmin(T &x, T y) { x = min(x, y); } template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; } int n, m, q, P, f[MAXN]; int tot, point[MAXN][2][3]; int x[MAXN], y[MAXN], w[MAXN]; int find(int x) { if (f[x] == x) return x; else return f[x] = find(f[x]); } void merge(int x, int y) { f[find(x)] = find(y); } bool same(int x, int y) { return find(x) == find(y); } bool vis[2][MAXP]; int main() { read(n), read(m), read(q), read(P); int g = P; for (int i = 1; i <= m; i++) { read(x[i]), read(y[i]), read(w[i]); g = __gcd(g, w[i] - w[1]); } P = __gcd(3 * g, P); for (int i = 1; i <= n; i++) for (int p = 0; p <= 1; p++) for (int q = 0; q <= 2; q++) { point[i][p][q] = ++tot; f[tot] = tot; } int z = w[1] % g; for (int x = z, i = 0; i <= P; i++, x = 2 * x % P) vis[i & 1][x] = true; for (int i = 1; i <= m; i++) { int tx = x[i], ty = y[i]; int tw = (w[i] - z) % P / g; for (int p = 0; p <= 1; p++) for (int q = 0; q <= 2; q++) merge(point[tx][p][q], point[ty][p ^ 1][(2 * q + tw) % 3]); } for (int i = 1; i <= q; i++) { bool res = false; int s, t, r; read(s), read(t), read(r); for (int p = 0; p <= 1; p++) for (int q = 0; q <= 2; q++) res |= same(point[t][0][0], point[s][p][q]) && vis[p][(r + z + (3 - q) * g) % P]; if (res) puts("YES"); else puts("NO"); } return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 5; const int MAXP = 1e6 + 5; typedef long long ll; template <typename T> void chkmax(T &x, T y) { x = max(x, y); } template <typename T> void chkmin(T &x, T y) { x = min(x, y); } template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; } int n, m, q, P, f[MAXN]; int tot, point[MAXN][2][3]; int x[MAXN], y[MAXN], w[MAXN]; int find(int x) { if (f[x] == x) return x; else return f[x] = find(f[x]); } void merge(int x, int y) { f[find(x)] = find(y); } bool same(int x, int y) { return find(x) == find(y); } bool vis[2][MAXP]; int main() { read(n), read(m), read(q), read(P); int g = P; for (int i = 1; i <= m; i++) { read(x[i]), read(y[i]), read(w[i]); g = __gcd(g, abs(w[i] - w[1])); } P = __gcd(3 * g, P); for (int i = 1; i <= n; i++) for (int p = 0; p <= 1; p++) for (int q = 0; q <= 2; q++) { point[i][p][q] = ++tot; f[tot] = tot; } int z = w[1] % g; for (int x = z, i = 0; i <= P; i++, x = 2 * x % P) vis[i & 1][x] = true; for (int i = 1; i <= m; i++) { int tx = x[i], ty = y[i]; int tw = (w[i] - z) % P / g; for (int p = 0; p <= 1; p++) for (int q = 0; q <= 2; q++) merge(point[tx][p][q], point[ty][p ^ 1][(2 * q + tw) % 3]); } for (int i = 1; i <= q; i++) { bool res = false; int s, t, r; read(s), read(t), read(r); for (int p = 0; p <= 1; p++) for (int q = 0; q <= 2; q++) res |= same(point[t][0][0], point[s][p][q]) && vis[p][(r + z + (3 - q) * g) % P]; if (res) puts("YES"); else puts("NO"); } return 0; }
[ "call.add", "call.arguments.change" ]
910,934
910,935
u744755176
cpp
p03100
#include <algorithm> #include <cstdio> #include <cstring> using namespace std; int gcd(int a, int b) { if (!b) return a; return gcd(b, a % b); } int n, m, q, mod, b[1000010][3], g, f[1000010], z; int find(int x) { if (x != f[x]) return f[x] = find(f[x]); return x; } inline int id(int v, int p, int q) { return (v - 1) * 6 + p * 3 + q; } void merge(int x, int y) { if (find(x) != find(y)) f[find(x)] = find(y); } bool check[2][1000010]; int main() { scanf("%d %d %d %d", &n, &m, &q, &mod); int x, y, w; for (int i = 1; i <= m; ++i) { scanf("%d %d %d", &x, &y, &w); b[i][0] = x, b[i][1] = y, b[i][2] = w; g = gcd(w - b[1][2], g); } if (!g) g = mod; mod = gcd(mod, 3 * g); z = b[1][2] % g; for (int i = 1; i <= 6 * n; ++i) f[i] = i; for (int i = 1; i <= m; ++i) { w = (b[i][2] - z) / g; for (int j = 0; j <= 2; ++j) { merge(id(b[i][0], 0, j), id(b[i][1], 1, (2 * j + w) % 3)); merge(id(b[i][0], 1, j), id(b[i][1], 0, (2 * j + w) % 3)); merge(id(b[i][1], 0, j), id(b[i][0], 1, (2 * j + w) % 3)); merge(id(b[i][1], 1, j), id(b[i][0], 0, (2 * j + w) % 3)); } } for (int i = 0, j = z; i < mod * 2; ++i, (j <<= 1) %= mod) check[i & 1][j] = 1; while (q--) { bool flag = 0; scanf("%d %d %d", &x, &y, &w); for (int p = 0; p <= 1; ++p) for (int q = 0; q <= 2; ++q) if (find(id(y, 0, 0)) == find(id(x, p, q))) flag |= check[p][(w + z + (3 - q) * g) % mod]; flag ? puts("YES") : puts("NO"); } return 0; }
#include <algorithm> #include <cstdio> #include <cstring> using namespace std; int gcd(int a, int b) { if (!b) return a; return gcd(b, a % b); } int n, m, q, mod, b[50050][3], g, f[300030], z; int find(int x) { if (x != f[x]) return f[x] = find(f[x]); return x; } inline int id(int v, int p, int q) { return (v - 1) * 6 + p * 3 + q; } void merge(int x, int y) { if (find(x) != find(y)) f[find(x)] = find(y); } bool check[2][1000010]; int main() { scanf("%d %d %d %d", &n, &m, &q, &mod); int x, y, w; for (int i = 1; i <= m; ++i) { scanf("%d %d %d", &x, &y, &w); b[i][0] = x, b[i][1] = y, b[i][2] = w; g = gcd(abs(w - b[1][2]), g); } if (!g) g = mod; mod = gcd(mod, 3 * g); z = b[1][2] % g; for (int i = 1; i <= 6 * n; ++i) f[i] = i; for (int i = 1; i <= m; ++i) { w = (b[i][2] - z) / g; for (int j = 0; j <= 2; ++j) { merge(id(b[i][0], 0, j), id(b[i][1], 1, (2 * j + w) % 3)); merge(id(b[i][0], 1, j), id(b[i][1], 0, (2 * j + w) % 3)); merge(id(b[i][1], 0, j), id(b[i][0], 1, (2 * j + w) % 3)); merge(id(b[i][1], 1, j), id(b[i][0], 0, (2 * j + w) % 3)); } } for (int i = 0, j = z; i < mod * 2; ++i, (j <<= 1) %= mod) check[i & 1][j] = 1; while (q--) { bool flag = 0; scanf("%d %d %d", &x, &y, &w); for (int p = 0; p <= 1; ++p) for (int q = 0; q <= 2; ++q) if (find(id(y, 0, 0)) == find(id(x, p, q))) flag |= check[p][(w + z + (3 - q) * g) % mod]; flag ? puts("YES") : puts("NO"); } return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "call.add", "call.arguments.change" ]
910,939
910,940
u361707943
cpp
p03100
#include <algorithm> #include <cstdio> #include <cstring> using namespace std; int gcd(int a, int b) { if (!b) return a; return gcd(b, a % b); } int n, m, q, mod, b[50050][3], g, f[300030], z; int find(int x) { if (x != f[x]) return f[x] = find(f[x]); return x; } inline int id(int v, int p, int q) { return (v - 1) * 6 + p * 3 + q; } void merge(int x, int y) { if (find(x) != find(y)) f[find(x)] = find(y); } bool check[2][1000010]; int main() { scanf("%d %d %d %d", &n, &m, &q, &mod); int x, y, w; for (int i = 1; i <= m; ++i) { scanf("%d %d %d", &x, &y, &w); b[i][0] = x, b[i][1] = y, b[i][2] = w; g = gcd(w - b[1][2], g); } if (!g) g = mod; mod = gcd(mod, 3 * g); z = b[1][2] % g; for (int i = 1; i <= 6 * n; ++i) f[i] = i; for (int i = 1; i <= m; ++i) { w = (b[i][2] - z) / g; for (int j = 0; j <= 2; ++j) { merge(id(b[i][0], 0, j), id(b[i][1], 1, (2 * j + w) % 3)); merge(id(b[i][0], 1, j), id(b[i][1], 0, (2 * j + w) % 3)); merge(id(b[i][1], 0, j), id(b[i][0], 1, (2 * j + w) % 3)); merge(id(b[i][1], 1, j), id(b[i][0], 0, (2 * j + w) % 3)); } } for (int i = 0, j = z; i < mod * 2; ++i, (j <<= 1) %= mod) check[i & 1][j] = 1; while (q--) { bool flag = 0; scanf("%d %d %d", &x, &y, &w); for (int p = 0; p <= 1; ++p) for (int q = 0; q <= 2; ++q) if (find(id(y, 0, 0)) == find(id(x, p, q))) flag |= check[p][(w + z + (3 - q) * g) % mod]; flag ? puts("YES") : puts("NO"); } return 0; }
#include <algorithm> #include <cstdio> #include <cstring> using namespace std; int gcd(int a, int b) { if (!b) return a; return gcd(b, a % b); } int n, m, q, mod, b[50050][3], g, f[300030], z; int find(int x) { if (x != f[x]) return f[x] = find(f[x]); return x; } inline int id(int v, int p, int q) { return (v - 1) * 6 + p * 3 + q; } void merge(int x, int y) { if (find(x) != find(y)) f[find(x)] = find(y); } bool check[2][1000010]; int main() { scanf("%d %d %d %d", &n, &m, &q, &mod); int x, y, w; for (int i = 1; i <= m; ++i) { scanf("%d %d %d", &x, &y, &w); b[i][0] = x, b[i][1] = y, b[i][2] = w; g = gcd(abs(w - b[1][2]), g); } if (!g) g = mod; mod = gcd(mod, 3 * g); z = b[1][2] % g; for (int i = 1; i <= 6 * n; ++i) f[i] = i; for (int i = 1; i <= m; ++i) { w = (b[i][2] - z) / g; for (int j = 0; j <= 2; ++j) { merge(id(b[i][0], 0, j), id(b[i][1], 1, (2 * j + w) % 3)); merge(id(b[i][0], 1, j), id(b[i][1], 0, (2 * j + w) % 3)); merge(id(b[i][1], 0, j), id(b[i][0], 1, (2 * j + w) % 3)); merge(id(b[i][1], 1, j), id(b[i][0], 0, (2 * j + w) % 3)); } } for (int i = 0, j = z; i < mod * 2; ++i, (j <<= 1) %= mod) check[i & 1][j] = 1; while (q--) { bool flag = 0; scanf("%d %d %d", &x, &y, &w); for (int p = 0; p <= 1; ++p) for (int q = 0; q <= 2; ++q) if (find(id(y, 0, 0)) == find(id(x, p, q))) flag |= check[p][(w + z + (3 - q) * g) % mod]; flag ? puts("YES") : puts("NO"); } return 0; }
[ "call.arguments.add", "call.arguments.change" ]
910,941
910,940
u361707943
cpp
p03100
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; struct Edge { int fr, to, v; } e[N << 1]; int n, m, q, mod, g, z; int id[N][2][3], icnt, par[N * 6]; int can[2][1000010]; int find(int x) { if (par[x] != x) { return par[x] = find(par[x]); } return par[x]; } void merge(int x, int y) { x = find(x), y = find(y); if (x != y) { par[x] = y; } } int main() { scanf("%d%d%d%d", &n, &m, &q, &mod); for (int i = 1; i <= m; i++) { scanf("%d%d%d", &e[i].fr, &e[i].to, &e[i].v); g = __gcd(g, abs(e[i].v - e[1].v)); } if (!g) g = mod; mod = __gcd(mod, 3 * g); z = e[1].v % g; for (int i = 1; i <= n; i++) for (int j = 0; j < 2; j++) for (int k = 0; k < 3; k++) id[i][j][k] = ++icnt; for (int i = 1; i <= icnt; i++) par[i] = i; int mul = z; for (int i = 0; i <= (mod << 1); i++) { can[i & 1][mul] = 1; mul = 2 * mul % mod; } for (int i = 1; i <= m; i++) { int more = ((e[i].v - z) / g); for (int p = 0; p < 2; p++) for (int q = 0; q < 3; q++) { merge(id[e[i].fr][p][q], id[e[i].to][p ^ 1][(2 * q + more) % 3]); merge(id[e[i].to][p][q], id[e[i].fr][p ^ 1][(2 * q + more) % 3]); } } while (q--) { int s, t, r; scanf("%d%d%d", &s, &t, &r); int ret = 0; for (int p = 0; p < 2; p++) for (int q = 0; q < 3; q++) if (find(id[t][0][0]) == find(id[s][p][q])) { ret = can[p][(r + z + (3 - q) * g) % mod]; if (ret) break; } puts(ret ? "YES" : "NO"); } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; struct Edge { int fr, to, v; } e[N << 1]; int n, m, q, mod, g, z; int id[N][2][3], icnt, par[N * 6]; int can[2][1000010]; int find(int x) { if (par[x] != x) { return par[x] = find(par[x]); } return par[x]; } void merge(int x, int y) { x = find(x), y = find(y); if (x ^ y) { par[x] = y; } } int main() { scanf("%d%d%d%d", &n, &m, &q, &mod); for (int i = 1; i <= m; i++) { scanf("%d%d%d", &e[i].fr, &e[i].to, &e[i].v); g = __gcd(g, abs(e[i].v - e[1].v)); } if (!g) g = mod; mod = __gcd(mod, 3 * g); z = e[1].v % g; for (int i = 1; i <= n; i++) for (int j = 0; j < 2; j++) for (int k = 0; k < 3; k++) id[i][j][k] = ++icnt; for (int i = 1; i <= icnt; i++) par[i] = i; int mul = z; for (int i = 0; i <= (mod << 1); i++) { can[i & 1][mul] = 1; mul = 2 * mul % mod; } for (int i = 1; i <= m; i++) { int more = ((e[i].v - z) / g); for (int p = 0; p < 2; p++) for (int q = 0; q < 3; q++) { merge(id[e[i].fr][p][q], id[e[i].to][p ^ 1][(2 * q + more) % 3]); merge(id[e[i].to][p][q], id[e[i].fr][p ^ 1][(2 * q + more) % 3]); } } while (q--) { int s, t, r; scanf("%d%d%d", &s, &t, &r); int ret = 0; for (int p = 0; p < 2; p++) for (int q = 0; q < 3; q++) if (find(id[t][0][0]) == find(id[s][p][q])) { ret |= can[p][(r + z + (3 - q) * g) % mod]; if (ret) break; } puts(ret ? "YES" : "NO"); } return 0; }
[ "control_flow.branch.if.condition.change", "assignment.value.change" ]
910,946
910,947
u076784075
cpp
p03100
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; struct Edge { int fr, to, v; } e[N << 1]; int n, m, q, mod, g, z; int id[N][2][3], icnt, par[N * 6]; int can[2][1000010]; int find(int x) { if (par[x] != x) { return par[x] = find(par[x]); } return par[x]; } void merge(int x, int y) { x = find(x), y = find(y); if (x ^ y) { par[x] = y; } } int main() { scanf("%d%d%d%d", &n, &m, &q, &mod); for (int i = 1; i <= m; i++) { scanf("%d%d%d", &e[i].fr, &e[i].to, &e[i].v); g = __gcd(g, abs(e[i].v - e[1].v)); } if (!g) g = mod; mod = __gcd(mod, 3 * g); z = e[1].v % g; for (int i = 1; i <= n; i++) for (int j = 0; j < 2; j++) for (int k = 0; k < 3; k++) id[i][j][k] = ++icnt; for (int i = 1; i <= icnt; i++) par[i] = i; int mul = z; for (int i = 0; i <= (mod << 1); i++) { can[i & 1][mul] = 1; mul = 2 * mul % mod; } for (int i = 1; i <= m; i++) { int more = ((e[i].v - z) / g); for (int p = 0; p < 2; p++) for (int q = 0; q < 3; q++) { merge(id[e[i].fr][p][q], id[e[i].to][p ^ 1][(2 * q + more) % 3]); merge(id[e[i].to][p][q], id[e[i].fr][p ^ 1][(2 * q + more) % 3]); } } while (q--) { int s, t, r; scanf("%d%d%d", &s, &t, &r); int ret = 0; for (int p = 0; p < 2; p++) for (int q = 0; q < 3; q++) if (find(id[t][0][0]) == find(id[s][p][q])) { ret = can[p][(r + z + (3 - q) * g) % mod]; if (ret) break; } puts(ret ? "YES" : "NO"); } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; struct Edge { int fr, to, v; } e[N << 1]; int n, m, q, mod, g, z; int id[N][2][3], icnt, par[N * 6]; int can[2][1000010]; int find(int x) { if (par[x] != x) { return par[x] = find(par[x]); } return par[x]; } void merge(int x, int y) { x = find(x), y = find(y); if (x ^ y) { par[x] = y; } } int main() { scanf("%d%d%d%d", &n, &m, &q, &mod); for (int i = 1; i <= m; i++) { scanf("%d%d%d", &e[i].fr, &e[i].to, &e[i].v); g = __gcd(g, abs(e[i].v - e[1].v)); } if (!g) g = mod; mod = __gcd(mod, 3 * g); z = e[1].v % g; for (int i = 1; i <= n; i++) for (int j = 0; j < 2; j++) for (int k = 0; k < 3; k++) id[i][j][k] = ++icnt; for (int i = 1; i <= icnt; i++) par[i] = i; int mul = z; for (int i = 0; i <= (mod << 1); i++) { can[i & 1][mul] = 1; mul = 2 * mul % mod; } for (int i = 1; i <= m; i++) { int more = ((e[i].v - z) / g); for (int p = 0; p < 2; p++) for (int q = 0; q < 3; q++) { merge(id[e[i].fr][p][q], id[e[i].to][p ^ 1][(2 * q + more) % 3]); merge(id[e[i].to][p][q], id[e[i].fr][p ^ 1][(2 * q + more) % 3]); } } while (q--) { int s, t, r; scanf("%d%d%d", &s, &t, &r); int ret = 0; for (int p = 0; p < 2; p++) for (int q = 0; q < 3; q++) if (find(id[t][0][0]) == find(id[s][p][q])) { ret |= can[p][(r + z + (3 - q) * g) % mod]; if (ret) break; } puts(ret ? "YES" : "NO"); } return 0; }
[ "assignment.value.change" ]
910,948
910,947
u076784075
cpp
p03100
#include <bits/stdc++.h> using namespace std; const int N = 5e4 + 10; struct Edge { int fr, to, v; } e[N << 1]; int n, m, q, mod, g, z; int id[N][2][3], icnt, par[N * 6]; int can[2][1000010]; int find(int x) { if (par[x] != x) { return par[x] = find(par[x]); } return par[x]; } void merge(int x, int y) { x = find(x), y = find(y); if (x ^ y) { par[x] = y; } } int main() { scanf("%d%d%d%d", &n, &m, &q, &mod); for (int i = 1; i <= m; i++) { scanf("%d%d%d", &e[i].fr, &e[i].to, &e[i].v); g = __gcd(g, abs(e[i].v - e[1].v)); } if (!g) g = mod; mod = __gcd(mod, 3 * g); z = e[1].v % g; for (int i = 1; i <= n; i++) for (int j = 0; j < 2; j++) for (int k = 0; k < 3; k++) id[i][j][k] = ++icnt; for (int i = 1; i <= icnt; i++) par[i] = i; int mul = z; for (int i = 0; i <= (mod << 1); i++) { can[i & 1][mul] = 1; mul = 2 * mul % mod; } for (int i = 1; i <= m; i++) { int more = ((e[i].v - z) / g); for (int p = 0; p < 2; p++) for (int q = 0; q < 3; q++) { merge(id[e[i].fr][p][q], id[e[i].to][p ^ 1][(2 * q + more) % 3]); merge(id[e[i].to][p][q], id[e[i].fr][p ^ 1][(2 * q + more) % 3]); } } while (q--) { int s, t, r; scanf("%d%d%d", &s, &t, &r); int ret = 0; for (int p = 0; p < 2; p++) for (int q = 0; q < 3; q++) if (find(id[t][0][0]) == find(id[s][p][q])) { ret = can[p][(r + z + (3 - q) * g) % mod]; if (ret) break; } puts(ret ? "YES" : "NO"); } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; struct Edge { int fr, to, v; } e[N << 1]; int n, m, q, mod, g, z; int id[N][2][3], icnt, par[N * 6]; int can[2][1000010]; int find(int x) { if (par[x] != x) { return par[x] = find(par[x]); } return par[x]; } void merge(int x, int y) { x = find(x), y = find(y); if (x ^ y) { par[x] = y; } } int main() { scanf("%d%d%d%d", &n, &m, &q, &mod); for (int i = 1; i <= m; i++) { scanf("%d%d%d", &e[i].fr, &e[i].to, &e[i].v); g = __gcd(g, abs(e[i].v - e[1].v)); } if (!g) g = mod; mod = __gcd(mod, 3 * g); z = e[1].v % g; for (int i = 1; i <= n; i++) for (int j = 0; j < 2; j++) for (int k = 0; k < 3; k++) id[i][j][k] = ++icnt; for (int i = 1; i <= icnt; i++) par[i] = i; int mul = z; for (int i = 0; i <= (mod << 1); i++) { can[i & 1][mul] = 1; mul = 2 * mul % mod; } for (int i = 1; i <= m; i++) { int more = ((e[i].v - z) / g); for (int p = 0; p < 2; p++) for (int q = 0; q < 3; q++) { merge(id[e[i].fr][p][q], id[e[i].to][p ^ 1][(2 * q + more) % 3]); merge(id[e[i].to][p][q], id[e[i].fr][p ^ 1][(2 * q + more) % 3]); } } while (q--) { int s, t, r; scanf("%d%d%d", &s, &t, &r); int ret = 0; for (int p = 0; p < 2; p++) for (int q = 0; q < 3; q++) if (find(id[t][0][0]) == find(id[s][p][q])) { ret |= can[p][(r + z + (3 - q) * g) % mod]; if (ret) break; } puts(ret ? "YES" : "NO"); } return 0; }
[ "literal.number.change", "expression.operation.binary.change", "assignment.value.change" ]
910,949
910,947
u076784075
cpp
p03100
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> using namespace std; const int Q = 1 << 19; int fa[Q]; int gf(int x) { return fa[x] == x ? x : (fa[x] = gf(fa[x])); } int X[Q], Y[Q], Z[Q]; int MOD; int id(int x, int y, int z) { return (x - 1) * 6 + y * 2 + z; } void Merge(int x, int y) { x = gf(x), y = gf(y); fa[x] = y; } int had[2][1 << 21]; void Deal(int x, int y, int z) { for (int q = 0; q < 3; q++) for (int p = 0; p < 2; p++) Merge(id(x, q, p), id(y, ((q << 1) + z) % 3, p ^ 1)); } int main() { int n, m, q, gg = -1; scanf("%d%d%d%d", &n, &m, &q, &MOD); for (int i = 1; i <= (n + 1) * 6; i++) fa[i] = i; for (int i = 1; i <= m; i++) { scanf("%d%d%d", &X[i], &Y[i], &Z[i]); if (i > 1) { int v = abs(Z[i] - Z[1]); gg = gg < 0 ? v : __gcd(gg, v); } } if (!gg) gg = Z[1]; MOD = __gcd(MOD, 3 * gg); int zz = Z[1] % gg; for (int i = 1; i <= m; i++) { int x = X[i], y = Y[i], z = (Z[i] - zz) / gg % 3; Deal(x, y, z), Deal(y, x, z); } for (int i = 0, j = zz % MOD; i < (MOD << 1); i++, j = (j << 1) % MOD) had[i & 1][j] = 1; while (q--) { int s, t, r, als = 0; scanf("%d%d%d", &s, &t, &r); for (int q = 0; q < 3; q++) for (int p = 0; p < 2; p++) if (gf(id(t, 0, 0)) == gf(id(s, q, p)) && had[p][(r + zz + (3 - q) * gg) % MOD]) { als = 1; break; } puts(als ? "YES" : "NO"); } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> using namespace std; const int Q = 1 << 19; int fa[Q]; int gf(int x) { return fa[x] == x ? x : (fa[x] = gf(fa[x])); } int X[Q], Y[Q], Z[Q]; int MOD; int id(int x, int y, int z) { return (x - 1) * 6 + y * 2 + z; } void Merge(int x, int y) { x = gf(x), y = gf(y); fa[x] = y; } int had[2][1 << 21]; void Deal(int x, int y, int z) { for (int q = 0; q < 3; q++) for (int p = 0; p < 2; p++) Merge(id(x, q, p), id(y, ((q << 1) + z) % 3, p ^ 1)); } int main() { int n, m, q, gg = -1; scanf("%d%d%d%d", &n, &m, &q, &MOD); for (int i = 1; i <= (n + 1) * 6; i++) fa[i] = i; for (int i = 1; i <= m; i++) { scanf("%d%d%d", &X[i], &Y[i], &Z[i]); if (i > 1) { int v = abs(Z[i] - Z[1]); gg = gg < 0 ? v : __gcd(gg, v); } } if (!gg) gg = MOD; MOD = __gcd(MOD, 3 * gg); int zz = Z[1] % gg; for (int i = 1; i <= m; i++) { int x = X[i], y = Y[i], z = (Z[i] - zz) / gg % 3; Deal(x, y, z), Deal(y, x, z); } for (int i = 0, j = zz % MOD; i < (MOD << 1); i++, j = (j << 1) % MOD) had[i & 1][j] = 1; while (q--) { int s, t, r, als = 0; scanf("%d%d%d", &s, &t, &r); for (int q = 0; q < 3; q++) for (int p = 0; p < 2; p++) if (gf(id(t, 0, 0)) == gf(id(s, q, p)) && had[p][(r + zz + (3 - q) * gg) % MOD]) { als = 1; break; } puts(als ? "YES" : "NO"); } return 0; }
[ "assignment.value.change" ]
910,953
910,954
u140310696
cpp
p03100
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int, int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define eps 1e-10 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template <class T> void read(T &res) { res = 0; T f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template <class T> void out(T x) { if (x < 0) { x = -x; putchar('-'); } if (x >= 10) { out(x / 10); } putchar('0' + x % 10); } const int maxn = 5e5 + 5, maxm = 1e6 + 5; ; int N, M, Q, MOD, f[maxn], t[maxn], v[maxn]; int fa[maxm * 6], z, g; bool able[2][maxm]; int id(int u, int p, int q) { return (u - 1) * 6 + p * 3 + q + 1; } int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int getfa(int u) { return u == fa[u] ? u : fa[u] = getfa(fa[u]); } void Merge(int u, int v) { fa[getfa(u)] = getfa(v); } void Init() { read(N); read(M); read(Q); read(MOD); read(f[1]); read(t[1]); read(v[1]); g = MOD; for (int i = 2; i <= M; ++i) { read(f[i]); read(t[i]); read(v[i]); g = gcd(g, abs(v[i] - v[1])); } MOD = gcd(MOD, 3 * g); z = v[1] % g; int T = id(N, 1, 2); for (int i = 1; i <= T; ++i) fa[i] = i; for (int i = 1; i <= N; ++i) { int w = (v[i] / g) % 3; for (int p = 0; p < 2; ++p) { for (int q = 0; q < 3; ++q) { Merge(id(f[i], p, q), id(t[i], p ^ 1, (q * 2 + w) % 3)); Merge(id(t[i], p, q), id(f[i], p ^ 1, (q * 2 + w) % 3)); } } } for (int i = 0, j = z; i < MOD; ++i, j = j * 2 % MOD) able[i & 1][j] = 1; } void Solve() { int s, t, r; for (int i = 1; i <= Q; ++i) { read(s); read(t); read(r); bool res = 0; for (int p = 0; p < 2; ++p) { for (int q = 0; q < 3; ++q) { if (getfa(id(t, 0, 0)) == getfa(id(s, p, q))) { if (able[p][(r + z + (3 - q) * g) % MOD]) res = 1; } } } if (res) puts("YES"); else puts("NO"); } } int main() { #ifdef ivorysi freopen("f1.in", "r", stdin); #endif Init(); Solve(); }
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int, int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define eps 1e-10 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template <class T> void read(T &res) { res = 0; T f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template <class T> void out(T x) { if (x < 0) { x = -x; putchar('-'); } if (x >= 10) { out(x / 10); } putchar('0' + x % 10); } const int maxn = 5e5 + 5, maxm = 1e6 + 5; ; int N, M, Q, MOD, f[maxn], t[maxn], v[maxn]; int fa[maxm * 6], z, g; bool able[2][maxm]; int id(int u, int p, int q) { return (u - 1) * 6 + p * 3 + q + 1; } int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int getfa(int u) { return u == fa[u] ? u : fa[u] = getfa(fa[u]); } void Merge(int u, int v) { fa[getfa(u)] = getfa(v); } void Init() { read(N); read(M); read(Q); read(MOD); read(f[1]); read(t[1]); read(v[1]); g = MOD; for (int i = 2; i <= M; ++i) { read(f[i]); read(t[i]); read(v[i]); g = gcd(g, abs(v[i] - v[1])); } MOD = gcd(MOD, 3 * g); z = v[1] % g; int T = id(N, 1, 2); for (int i = 1; i <= T; ++i) fa[i] = i; for (int i = 1; i <= M; ++i) { int w = (v[i] / g) % 3; for (int p = 0; p < 2; ++p) { for (int q = 0; q < 3; ++q) { Merge(id(f[i], p, q), id(t[i], p ^ 1, (q * 2 + w) % 3)); Merge(id(t[i], p, q), id(f[i], p ^ 1, (q * 2 + w) % 3)); } } } for (int i = 0, j = z; i < MOD; ++i, j = j * 2 % MOD) able[i & 1][j] = 1; } void Solve() { int s, t, r; for (int i = 1; i <= Q; ++i) { read(s); read(t); read(r); bool res = 0; for (int p = 0; p < 2; ++p) { for (int q = 0; q < 3; ++q) { if (getfa(id(t, 0, 0)) == getfa(id(s, p, q))) { if (able[p][(r + z + (3 - q) * g) % MOD]) res = 1; } } } if (res) puts("YES"); else puts("NO"); } } int main() { #ifdef ivorysi freopen("f1.in", "r", stdin); #endif Init(); Solve(); }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
910,955
910,956
u845980916
cpp
p03100
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int, int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define eps 1e-10 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template <class T> void read(T &res) { res = 0; T f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template <class T> void out(T x) { if (x < 0) { x = -x; putchar('-'); } if (x >= 10) { out(x / 10); } putchar('0' + x % 10); } const int maxn = 5e5 + 5, maxm = 1e6 + 5; ; int N, M, Q, MOD, f[maxn], t[maxn], v[maxn]; int fa[maxm * 3], z, g; bool able[2][maxm]; int id(int u, int p, int q) { return (u - 1) * 6 + p * 3 + q + 1; } int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int getfa(int u) { return u == fa[u] ? u : fa[u] = getfa(fa[u]); } void Merge(int u, int v) { fa[getfa(u)] = getfa(v); } void Init() { read(N); read(M); read(Q); read(MOD); read(f[1]); read(t[1]); read(v[1]); g = MOD; for (int i = 2; i <= M; ++i) { read(f[i]); read(t[i]); read(v[i]); g = gcd(g, abs(v[i] - v[1])); } MOD = gcd(MOD, 3 * g); z = v[1] % g; int T = id(N, 1, 2); for (int i = 1; i <= T; ++i) fa[i] = i; for (int i = 1; i <= N; ++i) { int w = (v[i] / g) % 3; for (int p = 0; p < 2; ++p) { for (int q = 0; q < 3; ++q) { Merge(id(f[i], p, q), id(t[i], p ^ 1, (q * 2 + w) % 3)); Merge(id(t[i], p, q), id(f[i], p ^ 1, (q * 2 + w) % 3)); } } } for (int i = 0, j = z; i < MOD; ++i, j = j * 2 % MOD) able[i & 1][j] = 1; } void Solve() { int s, t, r; for (int i = 1; i <= Q; ++i) { read(s); read(t); read(r); bool res = 0; for (int p = 0; p < 2; ++p) { for (int q = 0; q < 3; ++q) { if (getfa(id(t, 0, 0)) == getfa(id(s, p, q))) { if (able[p][(r + z + (3 - q) * g) % MOD]) res = 1; } } } if (res) puts("YES"); else puts("NO"); } } int main() { #ifdef ivorysi freopen("f1.in", "r", stdin); #endif Init(); Solve(); }
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int, int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define eps 1e-10 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template <class T> void read(T &res) { res = 0; T f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template <class T> void out(T x) { if (x < 0) { x = -x; putchar('-'); } if (x >= 10) { out(x / 10); } putchar('0' + x % 10); } const int maxn = 5e5 + 5, maxm = 1e6 + 5; ; int N, M, Q, MOD, f[maxn], t[maxn], v[maxn]; int fa[maxm * 6], z, g; bool able[2][maxm]; int id(int u, int p, int q) { return (u - 1) * 6 + p * 3 + q + 1; } int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int getfa(int u) { return u == fa[u] ? u : fa[u] = getfa(fa[u]); } void Merge(int u, int v) { fa[getfa(u)] = getfa(v); } void Init() { read(N); read(M); read(Q); read(MOD); read(f[1]); read(t[1]); read(v[1]); g = MOD; for (int i = 2; i <= M; ++i) { read(f[i]); read(t[i]); read(v[i]); g = gcd(g, abs(v[i] - v[1])); } MOD = gcd(MOD, 3 * g); z = v[1] % g; int T = id(N, 1, 2); for (int i = 1; i <= T; ++i) fa[i] = i; for (int i = 1; i <= M; ++i) { int w = (v[i] / g) % 3; for (int p = 0; p < 2; ++p) { for (int q = 0; q < 3; ++q) { Merge(id(f[i], p, q), id(t[i], p ^ 1, (q * 2 + w) % 3)); Merge(id(t[i], p, q), id(f[i], p ^ 1, (q * 2 + w) % 3)); } } } for (int i = 0, j = z; i < MOD; ++i, j = j * 2 % MOD) able[i & 1][j] = 1; } void Solve() { int s, t, r; for (int i = 1; i <= Q; ++i) { read(s); read(t); read(r); bool res = 0; for (int p = 0; p < 2; ++p) { for (int q = 0; q < 3; ++q) { if (getfa(id(t, 0, 0)) == getfa(id(s, p, q))) { if (able[p][(r + z + (3 - q) * g) % MOD]) res = 1; } } } if (res) puts("YES"); else puts("NO"); } } int main() { #ifdef ivorysi freopen("f1.in", "r", stdin); #endif Init(); Solve(); }
[ "literal.number.change", "expression.operation.binary.change", "identifier.change", "control_flow.loop.for.condition.change" ]
910,957
910,956
u845980916
cpp
p03100
#include <algorithm> #include <cstdio> #include <cstring> #define fo(i, a, b) for (int i = a; i <= b; i++) #define fd(i, a, b) for (int i = a; i >= b; i--) using namespace std; const int N = 1e6 + 5; int n, m, q, mod, s, t, r, u[N], v[N], c[N], g, fa[N]; bool can[2][N]; int Id(int x, int y, int z) { return (x - 1) * 6 + y * 3 + z; } int get(int x) { return fa[x] == x ? x : fa[x] = get(fa[x]); } void link(int x, int y) { x = get(x); y = get(y); if (x == y) return; fa[x] = y; } int main() { scanf("%d%d%d%d", &n, &m, &q, &mod); fo(i, 1, m) { scanf("%d%d%d", &u[i], &v[i], &c[i]); g = __gcd(g, c[i] - c[1]); } if (!g) g = mod; mod = __gcd(mod, 3 * g); int z = c[1] % g; fo(i, 0, 6 * n) fa[i] = i; fo(i, 1, m) { int w = (c[i] - z) / g; fo(p, 0, 1) fo(q, 0, 2) { link(Id(u[i], p, q), Id(v[i], 1 - p, (2 * q + w) % 3)); link(Id(v[i], p, q), Id(u[i], 1 - p, (2 * q + w) % 3)); } } for (int i = 0, j = z; i < mod << 1; i++, (j <<= 1) %= mod) can[i & 1][j] = 1; for (; q; q--) { scanf("%d%d%d", &s, &t, &r); int ret = 0; fo(p, 0, 1) fo(q, 0, 2) if (get(Id(t, 0, 0)) == get(Id(s, p, q))) ret |= can[p][(r + z + (3 - q) * g) % mod]; puts(ret ? "YES" : "NO"); } return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #define fo(i, a, b) for (int i = a; i <= b; i++) #define fd(i, a, b) for (int i = a; i >= b; i--) using namespace std; const int N = 1e6 + 5; int n, m, q, mod, s, t, r, u[N], v[N], c[N], g, fa[N]; bool can[2][N]; int Id(int x, int y, int z) { return (x - 1) * 6 + y * 3 + z; } int get(int x) { return fa[x] == x ? x : fa[x] = get(fa[x]); } void link(int x, int y) { x = get(x); y = get(y); if (x == y) return; fa[x] = y; } int main() { scanf("%d%d%d%d", &n, &m, &q, &mod); fo(i, 1, m) { scanf("%d%d%d", &u[i], &v[i], &c[i]); g = __gcd(g, abs(c[i] - c[1])); } if (!g) g = mod; mod = __gcd(mod, 3 * g); int z = c[1] % g; fo(i, 0, 6 * n) fa[i] = i; fo(i, 1, m) { int w = (c[i] - z) / g; fo(p, 0, 1) fo(q, 0, 2) { link(Id(u[i], p, q), Id(v[i], 1 - p, (2 * q + w) % 3)); link(Id(v[i], p, q), Id(u[i], 1 - p, (2 * q + w) % 3)); } } for (int i = 0, j = z; i < mod << 1; i++, (j <<= 1) %= mod) can[i & 1][j] = 1; for (; q; q--) { scanf("%d%d%d", &s, &t, &r); int ret = 0; fo(p, 0, 1) fo(q, 0, 2) if (get(Id(t, 0, 0)) == get(Id(s, p, q))) ret |= can[p][(r + z + (3 - q) * g) % mod]; puts(ret ? "YES" : "NO"); } return 0; }
[ "call.add", "call.arguments.change" ]
910,960
910,961
u924601814
cpp
p03100
#include <bits/stdc++.h> #define mp make_pair #define mt make_tuple #define pb push_back #define fi first #define se second #define sz(a) int(a.size()) #define clr(a) memset(a, 0, sizeof(a)) #define all(a) a.begin(), a.end() using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, int> pli; const int inf = 1e9; const ll Inf = 1e18; int mod; template <typename T = int> T gi() { T x = 0, o = 1; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') o = -1, ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * o; } template <typename T> bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }; template <typename T> bool chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; }; int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; } int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; } void inc(int &a, int b) { a = (a + b >= mod ? a + b - mod : a + b); } void dec(int &a, int b) { a = (a - b < 0 ? a - b + mod : a - b); } string to_string(string s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.fi) + "," + to_string(p.se) + ")"; } template <typename T> string to_string(T v) { int fst = 1; string ret = "{"; for (auto x : v) { if (!fst) ret += ","; fst = 0, ret += to_string(x); } ret += "}"; return ret; } void dbg_out() { cerr << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << " " << to_string(H); dbg_out(T...); } #define dbg(...) cerr << "{" << #__VA_ARGS__ << "}:", dbg_out(__VA_ARGS__) template <typename T> int qpow(int a, T b) { int ret = 1; while (b) { if (b & 1) ret = 1ll * ret * a % mod; a = 1ll * a * a % mod, b >>= 1; } return ret; } const int N = 1e6 + 10; namespace dsu { int fa[N]; int getf(int x) { return x == fa[x] ? x : fa[x] = getf(fa[x]); } bool merge(int x, int y) { x = getf(x), y = getf(y); if (x == y) return 0; fa[y] = x; return 1; } void init(int n) { for (int i = 0; i < n; i++) fa[i] = i; } bool connected(int x, int y) { return getf(x) == getf(y); } } // namespace dsu int n, m, q, g = 0, z, a[N], b[N], c[N]; bool ispw[2][N]; int id(int u, int p, int q) { return 6 * u + 2 * q + p; } int main() { n = gi(), m = gi(), q = gi(), mod = gi(); for (int i = 1; i <= m; i++) { a[i] = gi() - 1, b[i] = gi() - 1, c[i] = gi(); g = __gcd(g, c[i] - c[1]); } if (!g) g = mod; mod = __gcd(mod, 3 * g); z = c[1] % g; dsu::init(6 * n); for (int i = 1; i <= m; i++) { int w = (c[i] - z) / g % 3; for (int p = 0; p < 2; p++) for (int q = 0; q < 3; q++) { dsu::merge(id(a[i], p, q), id(b[i], p ^ 1, (2 * q + w) % 3)); dsu::merge(id(b[i], p, q), id(a[i], p ^ 1, (2 * q + w) % 3)); } } for (int i = 0, j = z % mod; !ispw[i & 1][j]; i++, j = 2ll * j % mod) ispw[i & 1][j] = 1; while (q--) { int s = gi() - 1, t = gi() - 1, r = gi(); bool ans = 0; for (int p = 0; p < 2; p++) for (int q = 0; q < 3; q++) { if (dsu::connected(id(t, 0, 0), id(s, p, q))) { if (ispw[p & 1][(r + z - q * g + 3 * g) % mod]) ans = 1; } } puts(ans ? "YES" : "NO"); } return 0; }
#include <bits/stdc++.h> #define mp make_pair #define mt make_tuple #define pb push_back #define fi first #define se second #define sz(a) int(a.size()) #define clr(a) memset(a, 0, sizeof(a)) #define all(a) a.begin(), a.end() using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, int> pli; const int inf = 1e9; const ll Inf = 1e18; int mod; template <typename T = int> T gi() { T x = 0, o = 1; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') o = -1, ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * o; } template <typename T> bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }; template <typename T> bool chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; }; int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; } int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; } void inc(int &a, int b) { a = (a + b >= mod ? a + b - mod : a + b); } void dec(int &a, int b) { a = (a - b < 0 ? a - b + mod : a - b); } string to_string(string s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.fi) + "," + to_string(p.se) + ")"; } template <typename T> string to_string(T v) { int fst = 1; string ret = "{"; for (auto x : v) { if (!fst) ret += ","; fst = 0, ret += to_string(x); } ret += "}"; return ret; } void dbg_out() { cerr << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << " " << to_string(H); dbg_out(T...); } #define dbg(...) cerr << "{" << #__VA_ARGS__ << "}:", dbg_out(__VA_ARGS__) template <typename T> int qpow(int a, T b) { int ret = 1; while (b) { if (b & 1) ret = 1ll * ret * a % mod; a = 1ll * a * a % mod, b >>= 1; } return ret; } const int N = 1e6 + 10; namespace dsu { int fa[N]; int getf(int x) { return x == fa[x] ? x : fa[x] = getf(fa[x]); } bool merge(int x, int y) { x = getf(x), y = getf(y); if (x == y) return 0; fa[y] = x; return 1; } void init(int n) { for (int i = 0; i < n; i++) fa[i] = i; } bool connected(int x, int y) { return getf(x) == getf(y); } } // namespace dsu int n, m, q, g = 0, z, a[N], b[N], c[N]; bool ispw[2][N]; int id(int u, int p, int q) { return 6 * u + 2 * q + p; } int main() { n = gi(), m = gi(), q = gi(), mod = gi(); for (int i = 1; i <= m; i++) { a[i] = gi() - 1, b[i] = gi() - 1, c[i] = gi(); g = __gcd(g, abs(c[i] - c[1])); } if (!g) g = mod; mod = __gcd(mod, 3 * g); z = c[1] % g; dsu::init(6 * n); for (int i = 1; i <= m; i++) { int w = (c[i] - z) / g % 3; for (int p = 0; p < 2; p++) for (int q = 0; q < 3; q++) { dsu::merge(id(a[i], p, q), id(b[i], p ^ 1, (2 * q + w) % 3)); dsu::merge(id(b[i], p, q), id(a[i], p ^ 1, (2 * q + w) % 3)); } } for (int i = 0, j = z % mod; !ispw[i & 1][j]; i++, j = 2ll * j % mod) ispw[i & 1][j] = 1; while (q--) { int s = gi() - 1, t = gi() - 1, r = gi(); bool ans = 0; for (int p = 0; p < 2; p++) for (int q = 0; q < 3; q++) { if (dsu::connected(id(t, 0, 0), id(s, p, q))) { if (ispw[p & 1][(r + z - q * g + 3 * g) % mod]) ans = 1; } } puts(ans ? "YES" : "NO"); } return 0; }
[ "call.add", "call.arguments.change" ]
910,962
910,963
u030892114
cpp
p03100
#include <bits/stdc++.h> #define mp make_pair #define mt make_tuple #define pb push_back #define fi first #define se second #define sz(a) int(a.size()) #define clr(a) memset(a, 0, sizeof(a)) #define all(a) a.begin(), a.end() using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, int> pli; const int inf = 1e9; const ll Inf = 1e18; int mod; template <typename T = int> T gi() { T x = 0, o = 1; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') o = -1, ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * o; } template <typename T> bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }; template <typename T> bool chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; }; int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; } int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; } void inc(int &a, int b) { a = (a + b >= mod ? a + b - mod : a + b); } void dec(int &a, int b) { a = (a - b < 0 ? a - b + mod : a - b); } string to_string(string s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.fi) + "," + to_string(p.se) + ")"; } template <typename T> string to_string(T v) { int fst = 1; string ret = "{"; for (auto x : v) { if (!fst) ret += ","; fst = 0, ret += to_string(x); } ret += "}"; return ret; } void dbg_out() { cerr << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << " " << to_string(H); dbg_out(T...); } #define dbg(...) cerr << "{" << #__VA_ARGS__ << "}:", dbg_out(__VA_ARGS__) template <typename T> int qpow(int a, T b) { int ret = 1; while (b) { if (b & 1) ret = 1ll * ret * a % mod; a = 1ll * a * a % mod, b >>= 1; } return ret; } const int N = 1e6 + 10; namespace dsu { int fa[N]; int getf(int x) { return x == fa[x] ? x : fa[x] = getf(fa[x]); } bool merge(int x, int y) { x = getf(x), y = getf(y); if (x == y) return 0; fa[y] = x; return 1; } void init(int n) { for (int i = 0; i < n; i++) fa[i] = i; } bool connected(int x, int y) { return getf(x) == getf(y); } } // namespace dsu int n, m, q, g = 0, z, a[N], b[N], c[N]; bool ispw[2][N]; int id(int u, int p, int q) { return 6 * u + 2 * q + p; } int main() { n = gi(), m = gi(), q = gi(), mod = gi(); for (int i = 1; i <= m; i++) { a[i] = gi() - 1, b[i] = gi() - 1, c[i] = gi(); g = __gcd(g, c[i] - c[1]); } if (!g) g = mod; mod = __gcd(mod, 3 * g); z = c[1] % g; dsu::init(6 * n); for (int i = 1; i <= m; i++) { int w = (c[i] - z) / g % 3; for (int p = 0; p < 2; p++) for (int q = 0; q < 3; q++) { dsu::merge(id(a[i], p, q), id(b[i], p ^ 1, (2 * q + w) % 3)); dsu::merge(id(b[i], p, q), id(a[i], p ^ 1, (2 * q + w) % 3)); } } for (int i = 0, j = z; !ispw[i & 1][j]; i++, j = 2ll * j % mod) ispw[i & 1][j] = 1; while (q--) { int s = gi() - 1, t = gi() - 1, r = gi(); bool ans = 0; for (int p = 0; p < 2; p++) for (int q = 0; q < 3; q++) { if (dsu::connected(id(t, 0, 0), id(s, p, q))) { if (ispw[p & 1][(r + z - q * g + 3 * g) % mod]) ans = 1; } } puts(ans ? "YES" : "NO"); } return 0; }
#include <bits/stdc++.h> #define mp make_pair #define mt make_tuple #define pb push_back #define fi first #define se second #define sz(a) int(a.size()) #define clr(a) memset(a, 0, sizeof(a)) #define all(a) a.begin(), a.end() using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, int> pli; const int inf = 1e9; const ll Inf = 1e18; int mod; template <typename T = int> T gi() { T x = 0, o = 1; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') o = -1, ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * o; } template <typename T> bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }; template <typename T> bool chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; }; int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; } int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; } void inc(int &a, int b) { a = (a + b >= mod ? a + b - mod : a + b); } void dec(int &a, int b) { a = (a - b < 0 ? a - b + mod : a - b); } string to_string(string s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.fi) + "," + to_string(p.se) + ")"; } template <typename T> string to_string(T v) { int fst = 1; string ret = "{"; for (auto x : v) { if (!fst) ret += ","; fst = 0, ret += to_string(x); } ret += "}"; return ret; } void dbg_out() { cerr << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << " " << to_string(H); dbg_out(T...); } #define dbg(...) cerr << "{" << #__VA_ARGS__ << "}:", dbg_out(__VA_ARGS__) template <typename T> int qpow(int a, T b) { int ret = 1; while (b) { if (b & 1) ret = 1ll * ret * a % mod; a = 1ll * a * a % mod, b >>= 1; } return ret; } const int N = 1e6 + 10; namespace dsu { int fa[N]; int getf(int x) { return x == fa[x] ? x : fa[x] = getf(fa[x]); } bool merge(int x, int y) { x = getf(x), y = getf(y); if (x == y) return 0; fa[y] = x; return 1; } void init(int n) { for (int i = 0; i < n; i++) fa[i] = i; } bool connected(int x, int y) { return getf(x) == getf(y); } } // namespace dsu int n, m, q, g = 0, z, a[N], b[N], c[N]; bool ispw[2][N]; int id(int u, int p, int q) { return 6 * u + 2 * q + p; } int main() { n = gi(), m = gi(), q = gi(), mod = gi(); for (int i = 1; i <= m; i++) { a[i] = gi() - 1, b[i] = gi() - 1, c[i] = gi(); g = __gcd(g, abs(c[i] - c[1])); } if (!g) g = mod; mod = __gcd(mod, 3 * g); z = c[1] % g; dsu::init(6 * n); for (int i = 1; i <= m; i++) { int w = (c[i] - z) / g % 3; for (int p = 0; p < 2; p++) for (int q = 0; q < 3; q++) { dsu::merge(id(a[i], p, q), id(b[i], p ^ 1, (2 * q + w) % 3)); dsu::merge(id(b[i], p, q), id(a[i], p ^ 1, (2 * q + w) % 3)); } } for (int i = 0, j = z % mod; !ispw[i & 1][j]; i++, j = 2ll * j % mod) ispw[i & 1][j] = 1; while (q--) { int s = gi() - 1, t = gi() - 1, r = gi(); bool ans = 0; for (int p = 0; p < 2; p++) for (int q = 0; q < 3; q++) { if (dsu::connected(id(t, 0, 0), id(s, p, q))) { if (ispw[p & 1][(r + z - q * g + 3 * g) % mod]) ans = 1; } } puts(ans ? "YES" : "NO"); } return 0; }
[ "call.add", "call.arguments.change", "control_flow.loop.for.initializer.change", "assignment.change" ]
910,964
910,963
u030892114
cpp
p03100
#include <algorithm> #include <cstdio> using namespace std; int gi() { int x = 0, w = 1; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') w = 0, ch = getchar(); while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); return w ? x : -x; } const int N = 1e6 + 5; int n, m, q, mod, a[N], b[N], c[N], g, z, fa[N], chk[2][N]; int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } void link(int x, int y) { fa[find(x)] = find(y); } int id(int u, int x, int y) { return u * 6 + x * 2 + y; } int main() { n = gi(); m = gi(); q = gi(); mod = gi(); for (int i = 1; i <= m; ++i) { a[i] = gi(), b[i] = gi(), c[i] = gi(); g = __gcd(g, c[i] - c[1]); } if (!g) g = mod; mod = __gcd(mod, 3 * g); z = c[1] % g; for (int i = 0; i < n * 6; ++i) fa[i] = i; for (int i = 1; i <= m; ++i) { int u = a[i] - 1, v = b[i] - 1, w = (c[i] - z) / g % 3; for (int x = 0; x < 3; ++x) { link(id(u, x, 0), id(v, (2 * x + w) % 3, 1)); link(id(u, x, 1), id(v, (2 * x + w) % 3, 0)); link(id(v, x, 0), id(u, (2 * x + w) % 3, 1)); link(id(v, x, 1), id(u, (2 * x + w) % 3, 0)); } } for (int i = 0, j = z; i < mod << 1; ++i, j = (j << 1) % mod) chk[i & 1][j] = 1; while (q--) { int s = gi() - 1, t = gi() - 1, r = gi(), res = 0; for (int x = 0; x < 3; ++x) for (int y = 0; y < 2; ++y) if (find(id(t, 0, 0)) == find(id(s, x, y))) res |= chk[y][(r + z + (3 - x) * g) % mod]; puts(res ? "YES" : "NO"); } return 0; }
#include <algorithm> #include <cstdio> using namespace std; int gi() { int x = 0, w = 1; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') w = 0, ch = getchar(); while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); return w ? x : -x; } const int N = 1e6 + 5; int n, m, q, mod, a[N], b[N], c[N], g, z, fa[N], chk[2][N]; int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } void link(int x, int y) { fa[find(x)] = find(y); } int id(int u, int x, int y) { return u * 6 + x * 2 + y; } int main() { n = gi(); m = gi(); q = gi(); mod = gi(); for (int i = 1; i <= m; ++i) { a[i] = gi(), b[i] = gi(), c[i] = gi(); g = __gcd(g, abs(c[i] - c[1])); } if (!g) g = mod; mod = __gcd(mod, 3 * g); z = c[1] % g; for (int i = 0; i < n * 6; ++i) fa[i] = i; for (int i = 1; i <= m; ++i) { int u = a[i] - 1, v = b[i] - 1, w = (c[i] - z) / g % 3; for (int x = 0; x < 3; ++x) { link(id(u, x, 0), id(v, (2 * x + w) % 3, 1)); link(id(u, x, 1), id(v, (2 * x + w) % 3, 0)); link(id(v, x, 0), id(u, (2 * x + w) % 3, 1)); link(id(v, x, 1), id(u, (2 * x + w) % 3, 0)); } } for (int i = 0, j = z; i < mod << 1; ++i, j = (j << 1) % mod) chk[i & 1][j] = 1; while (q--) { int s = gi() - 1, t = gi() - 1, r = gi(), res = 0; for (int x = 0; x < 3; ++x) for (int y = 0; y < 2; ++y) if (find(id(t, 0, 0)) == find(id(s, x, y))) res |= chk[y][(r + z + (3 - x) * g) % mod]; puts(res ? "YES" : "NO"); } return 0; }
[ "call.add", "call.arguments.change" ]
910,969
910,970
u459210307
cpp
p03100
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x, to) for (x = 0; x < (to); x++) #define FORR(x, arr) for (auto &x : arr) #define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++) #define ALL(a) (a.begin()), (a.end()) #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) //------------------------------------------------------- int N, M, Q; int mo; int A[101010], B[101010], C[101010]; int ok[1010101][2]; template <int um> class UF { public: vector<int> par, rank, cnt; UF() { par = rank = vector<int>(um, 0); cnt = vector<int>(um, 1); for (int i = 0; i < um; i++) par[i] = i; } void reinit() { int i; FOR(i, um) rank[i] = 0, cnt[i] = 1, par[i] = i; } int operator[](int x) { return (par[x] == x) ? (x) : (par[x] = operator[](par[x])); } int count(int x) { return cnt[operator[](x)]; } int operator()(int x, int y) { if ((x = operator[](x)) == (y = operator[](y))) return x; cnt[y] = cnt[x] = cnt[x] + cnt[y]; if (rank[x] > rank[y]) return par[x] = y; rank[x] += rank[x] == rank[y]; return par[y] = x; } }; UF<303030> uf; int id(int v, int p, int par) { return v * 6 + p % 3 * 2 + par; } void solve() { int i, j, k, l, r, x, y; string s; cin >> N >> M >> Q >> mo; int G = 0; FOR(i, M) { cin >> A[i] >> B[i] >> C[i]; A[i]--; B[i]--; if (i) G = __gcd(G, abs(C[i] - C[0])); } if (G == 0) G = mo; mo = __gcd(mo, 3 * G); int c = C[0] % (3 * G); // if(c==0) c=G; ll a = c; FOR(i, mo) { ok[a][i % 2] = 1; a = a * 2 % mo; } FOR(i, M) { C[i] = (C[i] - c + 3 * G) / G % 3; FOR(x, 3) { uf(id(A[i], x, 0), id(B[i], 2 * x + C[i], 1)); uf(id(A[i], x, 1), id(B[i], 2 * x + C[i], 0)); uf(id(B[i], x, 0), id(A[i], 2 * x + C[i], 1)); uf(id(B[i], x, 1), id(A[i], 2 * x + C[i], 0)); } } FOR(i, Q) { cin >> x >> y >> r; x--, y--; int ret = 0; FOR(j, 3) FOR(k, 2) if (uf[id(y, 0, 0)] == uf[id(x, j, k)]) { int dif = (r + c - j * G + 3 * G + 3 * mo) % mo; if (ok[dif][k]) ret = 1; } if (ret) cout << "YES" << endl; else cout << "NO" << endl; } } int main(int argc, char **argv) { string s; int i; if (argc == 1) ios::sync_with_stdio(false), cin.tie(0); FOR(i, argc - 1) s += argv[i + 1], s += '\n'; FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin); cout.tie(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x, to) for (x = 0; x < (to); x++) #define FORR(x, arr) for (auto &x : arr) #define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++) #define ALL(a) (a.begin()), (a.end()) #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) //------------------------------------------------------- int N, M, Q; int mo; int A[101010], B[101010], C[101010]; int ok[1010101][2]; template <int um> class UF { public: vector<int> par, rank, cnt; UF() { par = rank = vector<int>(um, 0); cnt = vector<int>(um, 1); for (int i = 0; i < um; i++) par[i] = i; } void reinit() { int i; FOR(i, um) rank[i] = 0, cnt[i] = 1, par[i] = i; } int operator[](int x) { return (par[x] == x) ? (x) : (par[x] = operator[](par[x])); } int count(int x) { return cnt[operator[](x)]; } int operator()(int x, int y) { if ((x = operator[](x)) == (y = operator[](y))) return x; cnt[y] = cnt[x] = cnt[x] + cnt[y]; if (rank[x] > rank[y]) return par[x] = y; rank[x] += rank[x] == rank[y]; return par[y] = x; } }; UF<303030> uf; int id(int v, int p, int par) { return v * 6 + p % 3 * 2 + par; } void solve() { int i, j, k, l, r, x, y; string s; cin >> N >> M >> Q >> mo; int G = 0; FOR(i, M) { cin >> A[i] >> B[i] >> C[i]; A[i]--; B[i]--; if (i) G = __gcd(G, abs(C[i] - C[0])); } if (G == 0) G = mo; mo = __gcd(mo, 3 * G); int c = C[0] % (3 * G); ll a = c; FOR(i, 2 * mo) { ok[a][i % 2] = 1; a = a * 2 % mo; } FOR(i, M) { C[i] = (C[i] - c + 3 * G) / G % 3; FOR(x, 3) { uf(id(A[i], x, 0), id(B[i], 2 * x + C[i], 1)); uf(id(A[i], x, 1), id(B[i], 2 * x + C[i], 0)); uf(id(B[i], x, 0), id(A[i], 2 * x + C[i], 1)); uf(id(B[i], x, 1), id(A[i], 2 * x + C[i], 0)); } } FOR(i, Q) { cin >> x >> y >> r; x--, y--; int ret = 0; FOR(j, 3) FOR(k, 2) if (uf[id(y, 0, 0)] == uf[id(x, j, k)]) { int dif = (r + c - j * G + 3 * G + 3 * mo) % mo; if (ok[dif][k]) ret = 1; } if (ret) cout << "YES" << endl; else cout << "NO" << endl; } } int main(int argc, char **argv) { string s; int i; if (argc == 1) ios::sync_with_stdio(false), cin.tie(0); FOR(i, argc - 1) s += argv[i + 1], s += '\n'; FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin); cout.tie(0); solve(); return 0; }
[ "expression.operation.binary.add" ]
910,971
910,972
u452725238
cpp
p03101
#include <iostream> #include <vector> using namespace std; int main() { int H, W; cin >> H >> W; int h, w; cin >> h >> w; cout << H * W - W * h - H * w + min(h, w) << endl; }
#include <iostream> #include <vector> using namespace std; int main() { int H, W; cin >> H >> W; int h, w; cin >> h >> w; cout << H * W - W * h - H * w + h * w << endl; }
[ "call.remove", "io.output.change", "call.arguments.change" ]
910,977
910,978
u503221936
cpp
p03101
#include <algorithm> #include <cmath> #include <complex> #include <functional> #include <iostream> #include <limits> #include <numeric> #include <sstream> #include <string> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int H, W; cin >> H >> W; int h, w; cin >> h >> w; cout << (H - h) * W - w; return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <functional> #include <iostream> #include <limits> #include <numeric> #include <sstream> #include <string> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int H, W; cin >> H >> W; int h, w; cin >> h >> w; cout << (H - h) * W - (H - h) * w; return 0; }
[ "expression.operation.binary.add" ]
910,987
910,988
u557207741
cpp
p03101
#include <iostream> using namespace std; int main() { int a, b; int c, d; cin >> a >> b >> c >> d; int k = a * b; // kはマスの総数 k = k - b * c; //これで行の分が引かれた。 k = k - a * d; //これで重複している分を含む列の分が引かれた。 k = k + c; cout << k; return 0; }
#include <iostream> using namespace std; int main() { int a, b; int c, d; cin >> a >> b >> c >> d; int k = a * b; // kはマスの総数 k = k - b * c; //これで行の分が引かれた。 k = k - a * d; //これで重複している分を含む列の分が引かれた。 k = k + c * d; cout << k; return 0; }
[ "assignment.change" ]
910,989
910,990
u818967913
cpp
p03101
#include <bits/stdc++.h> using namespace std; int main() { int H, W, h, w; cin >> H >> W >> h >> w; int x = h * W + w * H - h + w; cout << H * W - x << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int H, W, h, w; cin >> H >> W >> h >> w; int x = h * W + w * H - h * w; cout << H * W - x << endl; }
[ "expression.operator.arithmetic.change", "expression.operation.binary.change" ]
910,991
910,992
u758405447
cpp
p03101
#include <algorithm> #include <array> #include <bitset> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <stdint.h> #include <string> #include <time.h> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using ll = long long; using ull = unsigned long long; using uint = unsigned int; using ldouble = long double; // BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, // doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, // heirokenshutu, topologicalsort, kyourenketuseibun #define PRI(s) cout << s << endl #define PRIY PRI("Yes") #define PRIN PRI("No") int ctoi(char c) { switch (c) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; default: cout << "ERR_ctoi" << endl; return -1; } } int main() { int H, W, h, w; cin >> H >> W >> h >> w; PRI(H * w + W * h - w * h); return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <stdint.h> #include <string> #include <time.h> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using ll = long long; using ull = unsigned long long; using uint = unsigned int; using ldouble = long double; // BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, // doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, // heirokenshutu, topologicalsort, kyourenketuseibun #define PRI(s) cout << s << endl #define PRIY PRI("Yes") #define PRIN PRI("No") int ctoi(char c) { switch (c) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; default: cout << "ERR_ctoi" << endl; return -1; } } int main() { int H, W, h, w; cin >> H >> W >> h >> w; PRI(H * W - (H * w + W * h - w * h)); return 0; }
[ "call.arguments.add", "call.arguments.change" ]
910,995
910,996
u539145601
cpp
p03103
#include <bits/stdc++.h> using namespace std; typedef long long ll; pair<unsigned int, unsigned int> a[100001]; int main(int, char **) { ll n, m; cin >> n >> m; ll ans = 0; ll x = 0; for (int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second; sort(a, a + n); for (int i = 0; i < n; ++i) { if ((x + a[i].second) >= m) { ans += ((m - x) * a[i].first); cout << ans << endl; break; } x += a[i].second; ans += (a[i].first * a[i].second); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; pair<ll, ll> a[100002]; int main(int, char **) { ll n, m; cin >> n >> m; ll ans = 0; ll x = 0; for (int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second; sort(a, a + n); for (int i = 0; i < n; ++i) { if ((x + a[i].second) >= m) { ans += ((m - x) * a[i].first); cout << ans << endl; break; } x += a[i].second; ans += (a[i].first * a[i].second); } return 0; }
[ "variable_declaration.type.narrow.change", "literal.number.change", "variable_declaration.array_dimensions.change" ]
911,006
911,007
u869644355
cpp
p03103
#include <algorithm> #include <cstdio> #include <vector> typedef struct { long long int price; long long int number; } shop; bool operator<(const shop &left, const shop &right) { return left.price < right.price; } int main() { long long int i, n, m; std::vector<shop> data; shop a; scanf("%d %d", &n, &m); for (i = 0; i < n; i++) { scanf("%d %d", &(a.price), &(a.number)); data.push_back(a); } std::sort(data.begin(), data.end()); long long int ret = 0; for (i = 0; i < n; i++) { a = data[i]; if (a.number >= m) { ret += a.price * m; break; } else { ret += a.price * a.number; m -= a.number; } } printf("%lld\n", ret); return 0; }
#include <algorithm> #include <cstdio> #include <vector> typedef struct { long long int price; long long int number; } shop; bool operator<(const shop &left, const shop &right) { return left.price < right.price; } int main() { int i, n, m; std::vector<shop> data; shop a; scanf("%d %d", &n, &m); for (i = 0; i < n; i++) { scanf("%lld %lld", &(a.price), &(a.number)); data.push_back(a); } std::sort(data.begin(), data.end()); long long int ret = 0; for (i = 0; i < n; i++) { a = data[i]; if (a.number >= m) { ret += a.price * m; break; } else { ret += a.price * a.number; m -= a.number; } } printf("%lld\n", ret); return 0; }
[ "literal.string.change", "call.arguments.change" ]
911,020
911,021
u651808137
cpp
p03103
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (long long i = 0; i < n; i++) int main() { int N, M; cin >> N >> M; int a, b; vector<pair<int, int>> AB(N); rep(i, N) { cin >> a >> b; AB[i] = make_pair(a, b); } sort(AB.begin(), AB.end()); int n = 0, kingaku = 0; rep(i, N) { if (n + AB[i].second >= M) { kingaku = kingaku + (M - n) * AB[i].first; break; } else { n += AB[i].second; kingaku = kingaku + AB[i].second * AB[i].first; } } cout << kingaku; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (long long i = 0; i < n; i++) int main() { int N, M; cin >> N >> M; int a, b; vector<pair<long long, long long>> AB(N); rep(i, N) { cin >> a >> b; AB[i] = make_pair(a, b); } sort(AB.begin(), AB.end()); long long n = 0, kingaku = 0; rep(i, N) { if (n + AB[i].second >= M) { kingaku = kingaku + (M - n) * AB[i].first; break; } else { n += AB[i].second; kingaku = kingaku + AB[i].second * AB[i].first; } } cout << kingaku; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
911,022
911,023
u209857301
cpp
p03103
#include "iostream" #include <algorithm> #include <bitset> #include <cctype> #include <cstring> #include <iomanip> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <vector> using namespace std; using ll = long long; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define MOD 1000000007 int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0}; int main(int argc, char const *argv[]) { int n, m; ll ans = 0, cnt = 0; pll data[100010]; std::cin >> n >> m; for (int i = 0; i < n; i++) std::cin >> data[i].first >> data[i].second; sort(data, data + n); for (int i = 0; i < n; i++) { if (cnt + data[i].second > m) { ll p = 0; while (cnt < m) { cnt++; ans += data[i].first; } std::cout << ans << '\n'; return 0; } else { cnt += data[i].second; ans += data[i].second * data[i].first; } } return 0; }
#include "iostream" #include <algorithm> #include <bitset> #include <cctype> #include <cstring> #include <iomanip> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <vector> using namespace std; using ll = long long; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define MOD 1000000007 int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0}; int main(int argc, char const *argv[]) { int n, m; ll ans = 0, cnt = 0; pll data[100010]; std::cin >> n >> m; for (int i = 0; i < n; i++) std::cin >> data[i].first >> data[i].second; sort(data, data + n); for (int i = 0; i < n; i++) { if (cnt + data[i].second >= m) { ll p = 0; while (cnt < m) { cnt++; ans += data[i].first; } std::cout << ans << '\n'; return 0; } else { cnt += data[i].second; ans += data[i].second * data[i].first; } } return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
911,026
911,027
u863279562
cpp
p03103
#include <algorithm> #include <cstdio> #include <map> #include <vector> using namespace std; int main(void) { int n, m; scanf("%d %d\n", &n, &m); vector<pair<int, int>> vc(n); for (int i = 0; i < n; i++) { int a, b; scanf("%d %d\n", &a, &b); vc[i] = make_pair(a, b); } sort(vc.begin(), vc.end()); long long money = 0; for (int i = 0; i < n; i++) { if (m <= vc[i].second) { money += vc[i].first * m; break; } m -= vc[i].second; money += (long long)vc[i].first * vc[i].second; } printf("%lld\n", money); return 0; }
#include <algorithm> #include <cstdio> #include <map> #include <vector> using namespace std; int main(void) { int n, m; scanf("%d %d\n", &n, &m); vector<pair<int, int>> vc(n); for (int i = 0; i < n; i++) { int a, b; scanf("%d %d\n", &a, &b); vc[i] = make_pair(a, b); } sort(vc.begin(), vc.end()); long long money = 0; for (int i = 0; i < n; i++) { if (m <= vc[i].second) { money += (long long)vc[i].first * m; break; } m -= vc[i].second; money += (long long)vc[i].first * vc[i].second; } printf("%lld\n", money); return 0; }
[ "type_conversion.add" ]
911,030
911,031
u436042324
cpp
p03103
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #define poi 1000 using namespace std; struct girl { int x, y; bool operator<(girl b) const { return x < b.x; } } a[poi]; inline int re() { char c = getchar(); int x = 0, k = 1; while (c < '0' || c > '9') { if (c == '-') k = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + c - '0'; c = getchar(); } return x * k; } void wr(int x) { if (x < 0) putchar('-'), x = -x; if (x > 9) wr(x / 10); putchar(x % 10 + '0'); } signed main() { int n = re(), m = re(), ans = 0; for (int i = 1; i <= n; i++) a[i].x = re(), a[i].y = re(); sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) { if (m - a[i].y < 0) { ans += a[i].x * m; break; } ans += a[i].x * a[i].y; m -= a[i].y; } wr(ans); return 0; } /* */
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #define poi 1000000 #define int long long using namespace std; struct girl { int x, y; bool operator<(girl b) const { return x < b.x; } } a[poi]; inline int re() { char c = getchar(); int x = 0, k = 1; while (c < '0' || c > '9') { if (c == '-') k = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + c - '0'; c = getchar(); } return x * k; } void wr(int x) { if (x < 0) putchar('-'), x = -x; if (x > 9) wr(x / 10); putchar(x % 10 + '0'); } signed main() { int n = re(), m = re(), ans = 0; for (int i = 1; i <= n; i++) a[i].x = re(), a[i].y = re(); sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) { if (m - a[i].y < 0) { ans += a[i].x * m; break; } ans += a[i].x * a[i].y; m -= a[i].y; } wr(ans); return 0; } /* */
[ "preprocessor.define.value.change", "literal.integer.change" ]
911,044
911,045
u584337457
cpp
p03103
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; int n, m; struct qwq { int mon, num; }; qwq a[100005]; long long sum; int cmp(qwq a, qwq b) { return a.mon < b.mon; } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i].mon >> a[i].num; } sort(a + 1, a + n + 1, cmp); for (int i = 1; i <= n; i++) { m -= a[i].num; if (m <= 0) { sum += a[i].mon * (m + a[i].num); break; } else { sum += a[i].mon * a[i].num; } } cout << sum; return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; long long n, m; struct qwq { long long mon, num; }; qwq a[100005]; long long sum; long long cmp(qwq a, qwq b) { return a.mon < b.mon; } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i].mon >> a[i].num; } sort(a + 1, a + n + 1, cmp); for (int i = 1; i <= n; i++) { m -= a[i].num; if (m <= 0) { sum += a[i].mon * (m + a[i].num); break; } else { sum += a[i].mon * a[i].num; } } cout << sum; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
911,060
911,061
u275358946
cpp
p03103
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> #define fi first #define se second #define pb push_back using namespace std; const long long MOD = (long long)1e9 + 7; int n, m, a, b; vector<pair<int, int>> vec; long long ans; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a >> b; vec.pb({a, b}); } sort(vec.begin(), vec.end()); vec.pb({0, 0}); int cur = 0, cnt = 0; while (1) { if (cnt + vec[cur].se <= m) { cnt += vec[cur].se; ans += vec[cur].fi * 1LL * vec[cur].se; } else { ans += vec[cur].fi * 1LL * (m - cnt); break; } cur++; } cout << ans << "\n"; // system("pause"); return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> #define fi first #define se second #define pb push_back using namespace std; const long long MOD = (long long)1e9 + 7; int n, m, a, b; vector<pair<int, int>> vec; long long ans; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a >> b; vec.pb({a, b}); } sort(vec.begin(), vec.end()); vec.pb({0, 1}); int cur = 0, cnt = 0; while (1) { if (cnt + vec[cur].se <= m) { cnt += vec[cur].se; ans += vec[cur].fi * 1LL * vec[cur].se; } else { ans += vec[cur].fi * 1LL * (m - cnt); break; } cur++; } cout << ans << "\n"; // system("pause"); return 0; }
[ "literal.number.change", "call.arguments.change" ]
911,062
911,063
u398025421
cpp
p03103
#include <algorithm> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; #define modulo 1000000007 // 10^9 + 7 #define INF 1000000000 // 10^9 #define LLINF 1LL << 60 pair<int, ll> drink[100000]; // first = 値段 // second = 数 int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; for (int i = 0; i < N; i++) { cin >> drink[i].first >> drink[i].second; } sort(drink, drink + N); ll ans = 0LL; for (int i = 0; i < N && M > 0; i++) { if (M >= drink[i].second) { M -= drink[i].second; ans += drink[i].first * drink[i].second; } else { // M < drink[i].second ans += drink[i].first * M; M = 0; } } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; #define modulo 1000000007 // 10^9 + 7 #define INF 1000000000 // 10^9 #define LLINF 1LL << 60 pair<ll, ll> drink[100000]; // first = 値段 // second = 数 int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, M; cin >> N >> M; for (int i = 0; i < N; i++) { cin >> drink[i].first >> drink[i].second; } sort(drink, drink + N); ll ans = 0LL; for (int i = 0; i < N && M > 0; i++) { if (M >= drink[i].second) { M -= drink[i].second; ans += drink[i].first * drink[i].second; } else { // M < drink[i].second ans += drink[i].first * M; M = 0; } } cout << ans << endl; return 0; }
[ "variable_declaration.type.change" ]
911,066
911,067
u774652316
cpp
p03103
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define rc(x) return cout << x << endl, 0 #define pb push_back #define dbg(x) cout << #x << '=' << x << '\n'; #define ll long long #define sz size() #define x first #define y second #define pi pair<int, int> #define pii pair<pi, pi> #define vi vector<int> #define in insert #define er erase #define fd find int a, b, c, d; int gcd(int x, int y) { if (x > y) swap(x, y); if (x == y) return x; if (x == 1) return 1; return gcd(y % x, x); } int n, m; int32_t main() { ios_base ::sync_with_stdio(0); cin.tie(); cout.tie(); cin >> n >> m; vector<pi> v(n); for (int i = 0; i < n; i++) cin >> v[i].x >> v[i].y; sort(v.begin(), v.end()); int ans = 0, i = 0; while (m) { if (m > v[i].y) { m -= v[i].y; ans += v[i].y * v[i].x; } else { ans += m * v[i].x; m = 0; } i++; } cout << ans; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define rc(x) return cout << x << endl, 0 #define pb push_back #define dbg(x) cout << #x << '=' << x << '\n'; #define ll long long #define sz size() #define x first #define y second #define int ll #define pi pair<int, int> #define pii pair<pi, pi> #define vi vector<int> #define in insert #define er erase #define fd find int a, b, c, d; int gcd(int x, int y) { if (x > y) swap(x, y); if (x == y) return x; if (x == 1) return 1; return gcd(y % x, x); } int n, m; int32_t main() { ios_base ::sync_with_stdio(0); cin.tie(); cout.tie(); cin >> n >> m; vector<pi> v(n); for (int i = 0; i < n; i++) cin >> v[i].x >> v[i].y; sort(v.begin(), v.end()); int ans = 0, i = 0; while (m) { if (m > v[i].y) { m -= v[i].y; ans += v[i].y * v[i].x; } else { ans += m * v[i].x; m = 0; } i++; } cout << ans; }
[]
911,074
911,075
u392848063
cpp
p03103
#include <algorithm> #include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; typedef long long ll; #define mfor(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) mfor(i, 0, n) #define all(x) (x).begin(), (x).end() bool comp(const vector<int> &x, const vector<int> &y) { return x[2] > y[2]; } typedef pair<int, int> P; bool pairComp(const P &x, const P &y) { return x.first < y.first; } int main(void) { int N, M; cin >> N >> M; vector<P> ab; rep(i, N) { int A, B; cin >> A >> B; ab.push_back(make_pair(A, B)); } sort(ab.begin(), ab.end(), pairComp); int ans = 0; rep(i, N) { if (M <= 0) { continue; } if (M < ab[i].second) { ans += M * ab[i].first; M = 0; } else { ans += ab[i].first * ab[i].second; M -= ab[i].second; } } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; typedef long long ll; #define mfor(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) mfor(i, 0, n) #define all(x) (x).begin(), (x).end() bool comp(const vector<int> &x, const vector<int> &y) { return x[2] > y[2]; } typedef pair<ll, ll> P; bool pairComp(const P &x, const P &y) { return x.first < y.first; } int main(void) { ll N, M; cin >> N >> M; vector<P> ab; rep(i, N) { ll A, B; cin >> A >> B; ab.push_back(make_pair(A, B)); } sort(ab.begin(), ab.end(), pairComp); ll ans = 0; rep(i, N) { if (M <= 0) { continue; } if (M < ab[i].second) { ans += M * ab[i].first; M = 0; } else { ans += ab[i].first * ab[i].second; M -= ab[i].second; } } cout << ans << endl; return 0; }
[ "variable_declaration.type.change" ]
911,085
911,086
u819688111
cpp
p03103
#include <algorithm> #include <iostream> #include <map> #include <vector> using namespace std; int main() { int N, M, bot = 0, ans = 0; cin >> N >> M; vector<pair<int, int>> p(N); for (int i = 0; i < N; ++i) cin >> p[i].first >> p[i].second; sort(p.begin(), p.end()); for (int i = 0; i < N; ++i) { bot += p[i].second; ans += p[i].first * p[i].second; if (bot > M) { ans -= p[i].first * (bot - M); break; } } cout << ans << endl; }
#include <algorithm> #include <iostream> #include <map> #include <vector> using namespace std; int main() { long long int N, M, bot = 0, ans = 0; cin >> N >> M; vector<pair<long long int, long long int>> p(N); for (int i = 0; i < N; ++i) cin >> p[i].first >> p[i].second; sort(p.begin(), p.end()); for (int i = 0; i < N; ++i) { bot += p[i].second; ans += p[i].first * p[i].second; if (bot > M) { ans -= p[i].first * (bot - M); break; } } cout << ans << endl; }
[ "variable_declaration.type.widen.change" ]
911,093
911,094
u739362834
cpp
p03103
#include <algorithm> #include <array> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <set> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; int main() { int n, m; cin >> n >> m; vector<pair<int, int>> AB(n); for (int i = 0; i < n; i++) { cin >> AB[i].first >> AB[i].second; } sort(AB.begin(), AB.end()); unsigned long sum = 0; int num = 0; for (int i = 0; i < n; i++) { if (num + AB[i].second >= m) { sum += AB[i].first * (m - num); cout << sum << endl; return 0; } else { sum += AB[i].first * AB[i].second; num += AB[i].second; } } }
#include <algorithm> #include <array> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <set> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; int main() { int n, m; cin >> n >> m; vector<pair<long long, int>> AB(n); for (int i = 0; i < n; i++) { cin >> AB[i].first >> AB[i].second; } sort(AB.begin(), AB.end()); long long sum = 0; int num = 0; for (int i = 0; i < n; i++) { if (num + AB[i].second >= m) { sum += AB[i].first * (m - num); cout << sum << endl; return 0; } else { sum += AB[i].first * AB[i].second; num += AB[i].second; } } }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
911,095
911,096
u572012241
cpp
p03103
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int n, m; cin >> n >> m; vector<pair<int, int>> a(n); for (int i = 0; i < n; i++) { cin >> a.at(i).first >> a.at(i).second; } sort(a.begin(), a.begin()); long long int ans = 0; for (int i = 0; i < n; i++) { if (m > a.at(i).second) { ans += a.at(i).second * a.at(i).first; m -= a.at(i).second; } else { ans += m * a.at(i).first; break; } } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int n, m; cin >> n >> m; vector<pair<long int, int>> a(n); for (int i = 0; i < n; i++) { cin >> a.at(i).first >> a.at(i).second; } sort(a.begin(), a.end()); long long int ans = 0; for (int i = 0; i < n; i++) { if (m > a.at(i).second) { ans += a.at(i).second * a.at(i).first; m -= a.at(i).second; } else { ans += m * a.at(i).first; break; } } cout << ans << endl; }
[ "variable_declaration.type.widen.change", "call.function.change", "call.arguments.change" ]
911,097
911,098
u620242073
cpp
p03103
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> ii; int main() { int n, m; cin >> n >> m; ii arr[n]; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; arr[i] = make_pair(a, b); } sort(arr, arr + n); int ans = 0, a = 0; while (m > 0) { m -= arr[a].second; if (m < 0) ans += m * arr[a].first; ans += arr[a].second * arr[a].first; a++; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; typedef pair<long long, long long> ii; int main() { int n, m; cin >> n >> m; ii arr[n]; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; arr[i] = make_pair(a, b); } sort(arr, arr + n); long long ans = 0, a = 0; while (m > 0) { m -= arr[a].second; if (m < 0) ans += m * arr[a].first; ans += arr[a].second * arr[a].first; a++; } cout << ans; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
911,101
911,102
u712999358
cpp
p03103
#define TEST #include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; vector<pair<int, int>> s(N); for (int i = 0; i < N; i++) { s[i] = make_pair(0, 0); cin >> s[i].first >> s[i].second; } sort(s.begin(), s.end()); #ifdef TEST for (int i = 0; i < N; i++) cout << s[i].first << " " << s[i].second << endl; #endif long cost = 0; for (int i = 0; i < N; i++) { if (M > s[i].second) { M -= s[i].second; cost += static_cast<long>(s[i].first) * s[i].second; } else { cost += static_cast<long>(s[i].first) * M; M = 0; } if (M == 0) break; } cout << cost << endl; return 0; }
//#define TEST #include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; vector<pair<int, int>> s(N); for (int i = 0; i < N; i++) { s[i] = make_pair(0, 0); cin >> s[i].first >> s[i].second; } sort(s.begin(), s.end()); #ifdef TEST for (int i = 0; i < N; i++) cout << s[i].first << " " << s[i].second << endl; #endif long cost = 0; for (int i = 0; i < N; i++) { if (M > s[i].second) { M -= s[i].second; cost += static_cast<long>(s[i].first) * s[i].second; } else { cost += static_cast<long>(s[i].first) * M; M = 0; } if (M == 0) break; } cout << cost << endl; return 0; }
[]
911,117
911,118
u177907787
cpp
p03103
#include <algorithm> #include <cstdio> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int N, M; cin >> N >> M; vector<int> A(N), B(N); for (int i = 0; i < N; i++) { cin >> A[i] >> B[i]; } vector<pair<int, int>> AB(N); for (int i = 0; i < N; i++) { AB[i] = make_pair(A[i], B[i]); } sort(AB.begin(), AB.end()); long long ans = 0; for (int i = 0; i < N; i++) { int buy = min(M, AB[i].second); ans += buy * AB[i].first; M -= buy; } cout << ans << endl; }
#include <algorithm> #include <cstdio> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int N, M; cin >> N >> M; vector<int> A(N), B(N); for (int i = 0; i < N; i++) { cin >> A[i] >> B[i]; } vector<pair<int, int>> AB(N); for (int i = 0; i < N; i++) { AB[i] = make_pair(A[i], B[i]); } sort(AB.begin(), AB.end()); long long ans = 0; for (int i = 0; i < N; i++) { int buy = min(M, AB[i].second); ans += (long long)buy * AB[i].first; M -= buy; } cout << ans << endl; }
[ "type_conversion.add" ]
911,130
911,131
u539485388
cpp
p03103
#include <algorithm> #include <bits/stdc++.h> #include <iostream> #include <map> #include <stdio.h> #include <vector> using namespace std; int main() { int N, M; cin >> N >> M; vector<pair<int, int>> pairs(N); int B[N]; int A[N]; for (int i = 0; i < N; i++) { cin >> A[i]; cin >> B[i]; pairs[i] = make_pair(A[i], B[i]); } sort(pairs.begin(), pairs.end()); long long ans = 0; for (int i = 0; i < N; i++) { if (M <= pairs[i].second) { ans += M * pairs[i].first; break; } else { ans += pairs[i].first * pairs[i].second; M -= pairs[i].second; } } cout << ans << endl; }
#include <algorithm> #include <bits/stdc++.h> #include <iostream> #include <map> #include <stdio.h> #include <vector> using namespace std; int main() { int N, M; cin >> N >> M; vector<pair<long, long>> pairs(N); int B[N]; int A[N]; for (int i = 0; i < N; i++) { cin >> A[i]; cin >> B[i]; pairs[i] = make_pair(A[i], B[i]); } sort(pairs.begin(), pairs.end()); long long ans = 0; for (int i = 0; i < N; i++) { if (M <= pairs[i].second) { ans += M * pairs[i].first; break; } else { ans += pairs[i].first * pairs[i].second; M -= pairs[i].second; } } cout << ans << endl; }
[ "variable_declaration.type.primitive.change" ]
911,134
911,135
u806159048
cpp
p03103
#include <algorithm> #include <cstdio> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int N, M; cin >> N >> M; vector<int> A(N), B(N); for (int i = 0; i < N; i++) { cin >> A[i] >> B[i]; } vector<pair<int, int>> AB(N); for (int i = 0; i < N; i++) { AB[i] = make_pair(A[i], B[i]); } sort(AB.begin(), AB.end()); long long ans = 0; for (int i = 0; i < N; i++) { int buy = min(M, AB[i].second); ans += buy * AB[i].first; M -= buy; } cout << ans << endl; }
#include <algorithm> #include <cstdio> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int N, M; cin >> N >> M; vector<int> A(N), B(N); for (int i = 0; i < N; i++) { cin >> A[i] >> B[i]; } // pair<int, int> は int2つの型 vector<pair<int, int>> AB(N); for (int i = 0; i < N; i++) { AB[i] = make_pair(A[i], B[i]); } sort(AB.begin(), AB.end()); long long ans = 0; for (int i = 0; i < N; i++) { //このお店で購入する数を決める int buy = min(M, AB[i].second); //買った金額を加算する ans += (long long)buy * AB[i].first; //残り本数を減らす M -= buy; } cout << ans << endl; }
[ "type_conversion.add" ]
911,140
911,141
u845620905
cpp
p03103
#include <algorithm> #include <iostream> #include <vector> using namespace std; unsigned long N, M; typedef pair<long long, long long> X; vector<X> AB; int main() { cin >> N; cin >> M; for (int i = 0; i < N; i++) { long long a; cin >> a; long long b; cin >> b; AB.push_back(X(a, b)); } sort(AB.begin(), AB.end()); long long ans = 0; for (int i = 0; i < N; i++) { if (M - AB[i].second >= 0) { ans += AB[i].first * AB[i].second; M -= AB[i].second; if (M < 0) M = 0; } else { ans += AB[i].first * M; M = 0; } } printf("%lld\n", ans); return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; long N, M; typedef pair<long long, long long> X; vector<X> AB; int main() { cin >> N; cin >> M; for (int i = 0; i < N; i++) { long long a; cin >> a; long long b; cin >> b; AB.push_back(X(a, b)); } sort(AB.begin(), AB.end()); long long ans = 0; for (int i = 0; i < N; i++) { if (M - AB[i].second >= 0) { ans += AB[i].first * AB[i].second; M -= AB[i].second; if (M < 0) M = 0; } else { ans += AB[i].first * M; M = 0; } } printf("%lld\n", ans); return 0; }
[ "variable_declaration.type.narrow.change" ]
911,142
911,143
u543255423
cpp
p03103
#include <algorithm> #include <stdio.h> #include <utility> typedef long long ll; using namespace std; int main(void) { ll i, j, k, n, m, ans = 0, now = 0; scanf("%lld%lld", &n, &m); pair<ll, ll> d[n]; for (i = 0; i < n; ++i) scanf("%lld%lld", &d[i].first, &d[i].second); sort(d, d + n); for (i = 0; now < m; ++i) { if (now + d[i].second < m) now += d[i].second, ans += d[i].first * d[i].second; else ans += d[i].first * (m - d[i].second), now = m; } printf("%lld", ans); return 0; }
#include <algorithm> #include <stdio.h> #include <utility> typedef long long ll; using namespace std; int main(void) { ll i, j, k, n, m, ans = 0, now = 0; scanf("%lld%lld", &n, &m); pair<ll, ll> d[n]; for (i = 0; i < n; ++i) scanf("%lld%lld", &d[i].first, &d[i].second); sort(d, d + n); for (i = 0; now < m; ++i) { if (now + d[i].second < m) now += d[i].second, ans += d[i].first * d[i].second; else ans += d[i].first * (m - now), now = m; } printf("%lld", ans); return 0; }
[ "assignment.value.change", "expression.operation.binary.change" ]
911,144
911,145
u440920318
cpp
p03103
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<pair<int, int>> v; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; v.push_back(make_pair(a, b)); } sort(v.begin(), v.end()); int sum = 0; long long ans = 0; for (int i = 0; i < n; i++) { int an = v[i].first, bn = v[i].second; if (sum + bn >= m) { cout << ans + an * (m - sum) << endl; return 0; } else { ans += bn * an; sum += bn; } } }
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; vector<pair<int, int>> v; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; v.push_back(make_pair(a, b)); } sort(v.begin(), v.end()); long long sum = 0; long long ans = 0; for (int i = 0; i < n; i++) { long long an = v[i].first, bn = v[i].second; if (sum + bn >= m) { cout << ans + an * (m - sum) << endl; return 0; } else { ans += bn * an; sum += bn; } } }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
911,163
911,165
u357265888
cpp
p03103
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<pair<int, int>> a(n); for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; } sort(a.begin(), a.end()); int ans = 0; for (int i = 0; i < n; i++) { if (a[i].second >= m) { ans += a[i].first * m; cout << ans << endl; return 0; } m -= a[i].second; ans += a[i].first * a[i].second; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long n, m; cin >> n >> m; vector<pair<long, long>> a(n); for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; } sort(a.begin(), a.end()); long ans = 0; for (int i = 0; i < n; i++) { if (a[i].second >= m) { ans += a[i].first * m; cout << ans << endl; return 0; } m -= a[i].second; ans += a[i].first * a[i].second; } return 0; }
[ "variable_declaration.type.primitive.change" ]
911,169
911,170
u388552482
cpp
p03103
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> using namespace std; int main() { int n, m; cin >> n >> m; map<long long, long long> mp; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; mp[a] = b; } long long ans = 0; for (auto i = mp.begin(); i != mp.end(); i++) { if (m <= i->second) { ans += i->first * m; break; } else { ans += i->first * i->second; m -= i->second; } } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> using namespace std; int main() { int n, m; cin >> n >> m; map<long long, long long> mp; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; mp[a] += b; } long long ans = 0; for (auto i = mp.begin(); i != mp.end(); i++) { if (m <= i->second) { ans += i->first * m; m = 0; break; } else { ans += i->first * i->second; m -= i->second; } } cout << ans << endl; }
[ "assignment.value.change", "assignment.add" ]
911,171
911,172
u553605501
cpp
p03103
#include <bits/stdc++.h> using namespace std; int main() { long N, M; cin >> N >> M; vector<pair<long, long>> S(N); for (auto &i : S) cin >> i.first >> i.second; sort(S.begin(), S.end()); long ans(0); for (const auto &i : S) { long k = min(M, i.second); ans += k * i.second; M -= k; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long N, M; cin >> N >> M; vector<pair<long, long>> S(N); for (auto &i : S) cin >> i.first >> i.second; sort(S.begin(), S.end()); long ans(0); for (const auto &i : S) { long k = min(M, i.second); ans += k * i.first; M -= k; } cout << ans << endl; return 0; }
[ "assignment.value.change", "expression.operation.binary.change" ]
911,185
911,186
u462437857
cpp
p03103
#include <algorithm> #include <stdio.h> #include <vector> using namespace std; typedef long long llong; struct DrinkInfo { llong price; llong stock; DrinkInfo(llong inPrice, llong inStock) { price = inPrice; stock = inStock; } }; // DrinkInfoを値段で比較。ソートするために用意 bool cmpPrice(const DrinkInfo &a, const DrinkInfo &b) { return a.price < b.price; } int main() { int N, M; scanf("%d %d", &N, &M); vector<DrinkInfo> drinkInfo; llong price; llong stock; for (int i = 0; i < N; i++) { scanf("%d %d", &price, &stock); drinkInfo.push_back(DrinkInfo(price, stock)); } llong currentTotalPrice = 0; llong currentTotalNumber = 0; sort(drinkInfo.begin(), drinkInfo.end(), cmpPrice); for (auto itr : drinkInfo) { if (currentTotalNumber + itr.stock >= M) { currentTotalPrice = currentTotalPrice + itr.price * (M - currentTotalNumber); currentTotalNumber = M; break; } else { currentTotalPrice = currentTotalPrice + itr.price * itr.stock; currentTotalNumber = currentTotalNumber + itr.stock; } } // 出力 printf("%lld\n", currentTotalPrice); return 0; }
#include <algorithm> #include <stdio.h> #include <vector> using namespace std; typedef long long llong; struct DrinkInfo { llong price; llong stock; DrinkInfo(llong inPrice, llong inStock) { price = inPrice; stock = inStock; } }; // DrinkInfoを値段で比較。ソートするために用意 bool cmpPrice(const DrinkInfo &a, const DrinkInfo &b) { return a.price < b.price; } int main() { llong N, M; scanf("%lld %lld", &N, &M); vector<DrinkInfo> drinkInfo; llong price; llong stock; for (int i = 0; i < N; i++) { scanf("%lld %lld", &price, &stock); drinkInfo.push_back(DrinkInfo(price, stock)); } llong currentTotalPrice = 0; llong currentTotalNumber = 0; sort(drinkInfo.begin(), drinkInfo.end(), cmpPrice); for (auto itr : drinkInfo) { if (currentTotalNumber + itr.stock >= M) { currentTotalPrice = currentTotalPrice + itr.price * (M - currentTotalNumber); currentTotalNumber = M; break; } else { currentTotalPrice = currentTotalPrice + itr.price * itr.stock; currentTotalNumber = currentTotalNumber + itr.stock; } } // 出力 printf("%lld\n", currentTotalPrice); return 0; }
[ "variable_declaration.type.change", "literal.string.change", "call.arguments.change" ]
911,189
911,190
u727116332
cpp
p03103
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; int main() { ll n, m; map<ll, ll> mp; cin >> n >> m; for (int i = 0; i < n; i++) { ll a; ll b; cin >> a >> b; if (mp.count(a)) { mp.at(a) += b; n--; } else mp.insert(make_pair(a, b)); } ll l = 0, ans = 0; for (auto itr = mp.begin(); itr != mp.end(); itr++) { if (l + itr->second >= m) { ans += (m - l) * itr->first; break; } else { l += itr->second; ans += itr->first * itr->second; } } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; int main() { ll n, m; map<ll, ll> mp; cin >> n >> m; for (int i = 0; i < n; i++) { ll a; ll b; cin >> a >> b; if (mp.count(a)) { mp.at(a) += b; } else mp.insert(make_pair(a, b)); } ll l = 0, ans = 0; for (auto itr = mp.begin(); itr != mp.end(); itr++) { if (l + itr->second >= m) { ans += (m - l) * itr->first; break; } else { l += itr->second; ans += itr->first * itr->second; } } cout << ans << endl; }
[ "expression.unary.arithmetic.remove" ]
911,193
911,194
u012298376
cpp
p03103
#include <algorithm> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; int main() { long long N, M, a, b; long long money = 0; map<long long, long long> shop; cin >> N >> M; for (long long i = 0; i < N; i++) { cin >> a >> b; if (shop.count(a)) { shop[a] = shop[a] + b; } else { shop[a] = b; } } for (auto x : shop) { if (x.second > M) { money += x.first * M; std::cout << money; return 0; } else { money += x.first * x.second; M -= x.second; } } }
#include <algorithm> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; int main() { long long N, M, a, b; long long money = 0; map<long long, long long> shop; cin >> N >> M; for (long long i = 0; i < N; i++) { cin >> a >> b; if (shop.count(a)) { shop[a] = shop[a] + b; } else { shop[a] = b; } } for (auto x : shop) { if (x.second >= M) { money += x.first * M; std::cout << money; return 0; } else { money += x.first * x.second; M -= x.second; } } }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
911,207
911,208
u973004633
cpp
p03103
#include <iostream> #include <map> int main() { long long int n, m, sum = 0, add = 0; std::cin >> n >> m; std::map<long long int, long long int> mp; for (int i = 0; i < n; i++) { int g, p; std::cin >> g >> p; mp[g] = p; } // std::cout << mp[2] << std::endl; for (auto itr = mp.begin(); itr != mp.end(); ++itr) { sum += (itr->first) * (itr->second); // std::cout << (itr->first)<<" "<<(itr->second) << std::endl; // std::cout << sum << std::endl; add += (itr->second); if (add > m) { sum = sum - ((add - m) * (itr->first)); break; } } std::cout << sum << std::endl; return 0; }
#include <iostream> #include <map> int main() { long long int n, m, sum = 0, add = 0; std::cin >> n >> m; std::map<long long int, long long int> mp; for (int i = 0; i < n; i++) { int g, p; std::cin >> g >> p; // mp[g] = p; mp[g] = mp[g] + p; } // std::cout << mp[2] << std::endl; for (auto itr = mp.begin(); itr != mp.end(); ++itr) { sum += (itr->first) * (itr->second); // std::cout << (itr->first)<<" "<<(itr->second) << std::endl; // std::cout << sum << std::endl; add += (itr->second); if (add > m) { sum = sum - ((add - m) * (itr->first)); break; } } std::cout << sum << std::endl; return 0; }
[ "assignment.change" ]
911,209
911,210
u210398438
cpp
p03103
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N, M; cin >> N >> M; vector<pair<int, int>> P(N); for (int i = 0; i < N; i++) cin >> P[i].first >> P[i].second; sort(P.begin(), P.end()); ll ans = 0; for (int i = 0; i < N; i++) { if (M >= P[i].second) { ans += (long long)P[i].first * P[i].second; } else { ans += P[i].first * M; break; } M -= P[i].second; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N, M; cin >> N >> M; vector<pair<int, int>> P(N); for (int i = 0; i < N; i++) cin >> P[i].first >> P[i].second; sort(P.begin(), P.end()); ll ans = 0; for (int i = 0; i < N; i++) { if (M >= P[i].second) { ans += (long long)P[i].first * P[i].second; } else { ans += (long long)P[i].first * M; break; } M -= P[i].second; } cout << ans << endl; return 0; }
[ "type_conversion.add" ]
911,217
911,218
u077536797
cpp
p03103
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstdlib> #include <cstring> #include <iostream> #include <numeric> #include <string> #include <vector> using namespace std; typedef long long ll; struct Shop { int price; int quantity; bool operator<(const Shop &right) const { return price < right.price; } }; int main() { int N; ll M; cin >> N >> M; vector<Shop> shops(N); for (int i = 0; i < N; i++) { cin >> shops[i].price >> shops[i].quantity; } sort(shops.begin(), shops.end()); ll money = 0; for (int i = 0; i < N; i++) { if (shops[i].quantity <= M) { money += shops[i].quantity * shops[i].price; M -= shops[i].quantity; } else { money += M * shops[i].price; break; } if (M <= 0) { break; } } cout << money << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstdlib> #include <cstring> #include <iostream> #include <numeric> #include <string> #include <vector> using namespace std; typedef long long ll; struct Shop { ll price; ll quantity; bool operator<(const Shop &right) const { return price < right.price; } }; int main() { int N; ll M; cin >> N >> M; vector<Shop> shops(N); for (int i = 0; i < N; i++) { cin >> shops[i].price >> shops[i].quantity; } sort(shops.begin(), shops.end()); ll money = 0; for (int i = 0; i < N; i++) { if (shops[i].quantity <= M) { money += shops[i].quantity * shops[i].price; M -= shops[i].quantity; } else { money += M * shops[i].price; break; } if (M <= 0) { break; } } cout << money << endl; return 0; }
[]
911,221
911,222
u223160139
cpp
p03103
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstdlib> #include <cstring> #include <iostream> #include <numeric> #include <string> #include <vector> using namespace std; typedef long long ll; struct Shop { int price; int quantity; bool operator<(const Shop &right) const { return price < right.price; } }; int main() { int N, M; cin >> N >> M; vector<Shop> shops(N); for (int i = 0; i < N; i++) { cin >> shops[i].price >> shops[i].quantity; } sort(shops.begin(), shops.end()); ll money = 0; for (int i = 0; i < N; i++) { if (shops[i].quantity <= M) { money += shops[i].quantity * shops[i].price; M -= shops[i].quantity; } else { money += M * shops[i].price; break; } if (M <= 0) { break; } } cout << money << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstdlib> #include <cstring> #include <iostream> #include <numeric> #include <string> #include <vector> using namespace std; typedef long long ll; struct Shop { ll price; ll quantity; bool operator<(const Shop &right) const { return price < right.price; } }; int main() { int N; ll M; cin >> N >> M; vector<Shop> shops(N); for (int i = 0; i < N; i++) { cin >> shops[i].price >> shops[i].quantity; } sort(shops.begin(), shops.end()); ll money = 0; for (int i = 0; i < N; i++) { if (shops[i].quantity <= M) { money += shops[i].quantity * shops[i].price; M -= shops[i].quantity; } else { money += M * shops[i].price; break; } if (M <= 0) { break; } } cout << money << endl; return 0; }
[]
911,223
911,222
u223160139
cpp
p03103
#include <algorithm> #include <iostream> #include <math.h> #include <string.h> #include <vector> typedef long long ll; using namespace std; int main() { int N, M, tmp; ll ans = 0; cin >> N >> M; typedef pair<ll, ll> pair; vector<pair> pair_vec; for (int i = 0; i < N; i++) { ll tmp1, tmp2; cin >> tmp1 >> tmp2; pair_vec.push_back(pair(tmp1, tmp2)); } std::sort(pair_vec.begin(), pair_vec.end(), [](const pair &x, const pair &y) { return x.second < y.second; }); tmp = M; for (auto &i : pair_vec) { if (tmp - i.first >= 0) { ans += i.first * i.second; tmp -= i.second; } else { ans += tmp * i.first; break; } } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <math.h> #include <string.h> #include <vector> typedef long long ll; using namespace std; int main() { int N, M, tmp; ll ans = 0; cin >> N >> M; typedef pair<ll, ll> pair; vector<pair> pair_vec; for (int i = 0; i < N; i++) { ll tmp1, tmp2; cin >> tmp1 >> tmp2; pair_vec.push_back(pair(tmp1, tmp2)); } std::sort(pair_vec.begin(), pair_vec.end(), [](const pair &x, const pair &y) { return x.first < y.first; }); tmp = M; for (auto &i : pair_vec) { if (tmp - i.second >= 0) { ans += i.first * i.second; tmp -= i.second; } else { ans += tmp * i.first; break; } } cout << ans << endl; return 0; }
[ "call.arguments.change", "function.return_value.change", "expression.operation.binary.change", "control_flow.branch.if.condition.change" ]
911,224
911,225
u831873811
cpp
p03103
#include <algorithm> #include <cmath> #include <iostream> #include <list> #include <map> #include <string> #include <vector> using namespace std; int main() { int n, m; cin >> n >> m; struct s { int price; int num; }; vector<s> sp; int a, b; for (int i = 0; i < n; i++) { cin >> a >> b; sp.push_back({a, b}); } sort(sp.begin(), sp.end(), [](const s &x, s &y) { return x.price < y.price; }); long long x = 0; long long y = 0; int i = 0; while (x < m) { s shohin = sp[i]; if (x + shohin.num <= m) { y += shohin.price * shohin.num; x += shohin.num; } else { y += shohin.price * (m - x); x = m; } i++; } cout << y << endl; }
#include <algorithm> #include <cmath> #include <iostream> #include <list> #include <map> #include <string> #include <vector> using namespace std; int main() { int n, m; cin >> n >> m; struct s { long long price; long long num; }; vector<s> sp; int a, b; for (int i = 0; i < n; i++) { cin >> a >> b; sp.push_back({a, b}); } sort(sp.begin(), sp.end(), [](const s &x, s &y) { return x.price < y.price; }); long long x = 0; long long y = 0; long long i = 0; while (x < m) { s shohin = sp[i]; if (x + shohin.num <= m) { y += shohin.price * shohin.num; x += shohin.num; } else { y += shohin.price * (m - x); x = m; } i++; } cout << y << endl; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
911,232
911,233
u713830790
cpp
p03103
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <stdio.h> #include <string> #include <vector> using namespace std; int main(void) { int n, m, i, j; cin >> n >> m; long long int a[n], b[n]; vector<pair<long long int, long long int>> aa(n); for (i = 0; i < n; i++) { cin >> a[i] >> b[i]; aa[i] = make_pair(a[i], b[i]); } sort(aa.begin(), aa.end()); int ans = 0; i = 0; while (m > 0) { if (m >= aa[i].second) { ans += aa[i].first * aa[i].second; m -= aa[i].second; } else { ans += aa[i].first * m; break; } i++; } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <stdio.h> #include <string> #include <vector> using namespace std; int main(void) { int n, m, i, j; cin >> n >> m; long long int a[n], b[n]; vector<pair<long long int, long long int>> aa(n); for (i = 0; i < n; i++) { cin >> a[i] >> b[i]; aa[i] = make_pair(a[i], b[i]); } sort(aa.begin(), aa.end()); long long int ans = 0; i = 0; while (m > 0) { if (m >= aa[i].second) { ans += aa[i].first * aa[i].second; m -= aa[i].second; } else { ans += aa[i].first * m; break; } i++; } cout << ans << endl; return 0; }
[ "variable_declaration.type.widen.change" ]
911,234
911,235
u299725342
cpp
p03103
#include <bits/stdc++.h> #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 FORR(i, m, n) for (int i = m; i >= n; i--) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define llong long long #define pb(a) push_back(a) #define INF 999999999 using namespace std; typedef pair<int, int> P; typedef pair<llong, llong> LP; typedef pair<int, P> PP; typedef pair<llong, LP> LPP; int dy[] = {0, 0, 1, -1, 0}; int dx[] = {1, -1, 0, 0, 0}; // 入れ子のコンテナの表示関数. void print_list(const vector<vector<llong>> &v_list) { for (vector<vector<llong>>::const_iterator p = v_list.begin(); p != v_list.end(); ++p) { for (vector<llong>::const_iterator q = p->begin(); q != p->end(); ++q) cout << *q << " "; cout << endl; } } // 和の比較関数. template <class T> bool less_summation(const vector<T> &a, const vector<T> &b) { return a[0] < b[0]; } int main() { vector<vector<llong>> source; llong n, m; llong ans = 0; scanf("%d %d", &n, &m); source.resize(n); for (llong i = 0; i < n; i++) { source[i].resize(2); } for (llong k = 0; k < n; k++) { for (llong s = 0; s < 2; s++) { llong temp; scanf("%d", &temp); source[k][s] = temp; } } sort(source.begin(), source.end(), less_summation<llong>); llong num = 0; for (llong i = 0; i < n; i++) { llong tn = 0; tn = min(m - num, source[i][1]); ans += tn * source[i][0]; num += tn; } cout << ans << endl; }
#include <bits/stdc++.h> #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 FORR(i, m, n) for (int i = m; i >= n; i--) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define llong long long #define pb(a) push_back(a) #define INF 999999999 using namespace std; typedef pair<int, int> P; typedef pair<llong, llong> LP; typedef pair<int, P> PP; typedef pair<llong, LP> LPP; int dy[] = {0, 0, 1, -1, 0}; int dx[] = {1, -1, 0, 0, 0}; // 入れ子のコンテナの表示関数. void print_list(const vector<vector<llong>> &v_list) { for (vector<vector<llong>>::const_iterator p = v_list.begin(); p != v_list.end(); ++p) { for (vector<llong>::const_iterator q = p->begin(); q != p->end(); ++q) cout << *q << " "; cout << endl; } } // 和の比較関数. template <class T> bool less_summation(const vector<T> &a, const vector<T> &b) { return a[0] < b[0]; } int main() { vector<vector<llong>> source; llong n, m; llong ans = 0; scanf("%lld %lld", &n, &m); source.resize(n); for (llong i = 0; i < n; i++) { source[i].resize(2); } for (llong k = 0; k < n; k++) { for (llong s = 0; s < 2; s++) { llong temp; scanf("%lld", &temp); source[k][s] = temp; } } sort(source.begin(), source.end(), less_summation<llong>); llong num = 0; for (llong i = 0; i < n; i++) { llong tn = 0; tn = min(m - num, source[i][1]); ans += tn * source[i][0]; num += tn; } cout << ans << endl; }
[ "literal.string.change", "call.arguments.change" ]
911,238
911,239
u978036461
cpp
p03103
#include <bits/stdc++.h> #define ALL(v) v.begin(), v.end() using namespace std; typedef long long ll; // Compiler version g++ 6.3.0 struct drink { int v; int h; drink(int inputted_v, int inputted_h) { v = inputted_v; h = inputted_h; } bool operator<(const drink &another) const { return v < another.v; }; }; int main() { ll n, m, ans = 0; cin >> n >> m; vector<drink> a; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; drink z = {x, y}; a.push_back(z); } sort(a.begin(), a.end()); for (auto itr : a) { if (itr.h < m) { m -= itr.h; ans += itr.v * itr.h; } else { ans += itr.h * m; cout << ans << endl; return 0; } } }
#include <bits/stdc++.h> #define ALL(v) v.begin(), v.end() using namespace std; typedef long long ll; // Compiler version g++ 6.3.0 struct drink { ll v; ll h; drink(ll inputted_v, ll inputted_h) { v = inputted_v; h = inputted_h; } bool operator<(const drink &another) const { return v < another.v; }; }; int main() { ll n, m, ans = 0; cin >> n >> m; vector<drink> a; for (int i = 0; i < n; i++) { ll x, y; cin >> x >> y; drink z = {x, y}; a.push_back(z); } sort(a.begin(), a.end()); for (auto itr : a) { if (itr.h < m) { m -= itr.h; ans += itr.v * itr.h; } else { ans += itr.v * m; cout << ans << endl; return 0; } } }
[ "variable_declaration.type.change", "assignment.value.change", "expression.operation.binary.change" ]
911,245
911,244
u483156389
cpp
p03103
#include <algorithm> #include <cmath> #include <iostream> #include <iterator> #include <map> #include <math.h> #include <stdio.h> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; #define REP(var, n) for (decltype(n) var = 0; var < (n); var++) #define RREP(var, n) \ for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--) #define FOR(var, a, b) for (auto var = (a); var < (b); var++) #define RFOR(var, a, b) for (auto var = b - 1; var != a; var--) #define all(c) begin(c), end(c) #define vmax(c) *max_element(all(c)) #define vmin(c) *min_element(all(c)) template <typename T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) { if (!v.empty()) { out << '['; std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", ")); out << "\b\b]"; } return out; } template <typename T1, typename T2> std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p) { out << "[" << p.first << ", " << p.second << "]"; return out; } template <typename T1, typename T2> std::ostream &operator<<(std::ostream &out, const std::map<T1, T2> &map) { for (typename std::map<T1, T2>::const_iterator it = map.begin(); it != map.end(); ++it) { out << (*it); } return out; } typedef long long int ll; typedef vector<int> vi; typedef vector<ll> vll; const long long INF = 0x3f3f3f3f3f3f3f3f; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; // 2次元配列を作る // vector<vi> my_vector(n, vi(m, 0)); // 多次元配列の dump // for (auto v : my_vector) { // cout << v; // } ll solve() { ll N, M; cin >> N >> M; // cout << N << M; vector<vll> costs(N, vll(2, 0)); REP(i, N) { cin >> costs[i][0] >> costs[i][1]; } sort(all(costs), [](auto &x, auto &y) { return x[0] < y[0]; }); ll total = 0; ll cnt = 0; REP(i, N) { ll c = costs[i][0]; ll q = costs[i][1]; ll buy; // cout << cnt << "," << total << "," << c << "," << q << endl; if (cnt + q > M) { buy = M - cnt; total = total + buy * c; return total; } else { buy = q; total = total + buy * c; cnt = cnt + q; } } return 0; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); // solve(); cout << solve(); }
#include <algorithm> #include <cmath> #include <iostream> #include <iterator> #include <map> #include <math.h> #include <stdio.h> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; #define REP(var, n) for (decltype(n) var = 0; var < (n); var++) #define RREP(var, n) \ for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--) #define FOR(var, a, b) for (auto var = (a); var < (b); var++) #define RFOR(var, a, b) for (auto var = b - 1; var != a; var--) #define all(c) begin(c), end(c) #define vmax(c) *max_element(all(c)) #define vmin(c) *min_element(all(c)) template <typename T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) { if (!v.empty()) { out << '['; std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", ")); out << "\b\b]"; } return out; } template <typename T1, typename T2> std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p) { out << "[" << p.first << ", " << p.second << "]"; return out; } template <typename T1, typename T2> std::ostream &operator<<(std::ostream &out, const std::map<T1, T2> &map) { for (typename std::map<T1, T2>::const_iterator it = map.begin(); it != map.end(); ++it) { out << (*it); } return out; } typedef long long int ll; typedef vector<int> vi; typedef vector<ll> vll; const long long INF = 0x3f3f3f3f3f3f3f3f; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; // 2次元配列を作る // vector<vi> my_vector(n, vi(m, 0)); // 多次元配列の dump // for (auto v : my_vector) { // cout << v; // } ll solve() { ll N, M; cin >> N >> M; // cout << N << M; vector<vll> costs(N, vll(2, 0)); REP(i, N) { cin >> costs[i][0] >> costs[i][1]; } sort(all(costs), [](auto &x, auto &y) { return x[0] < y[0]; }); ll total = 0; ll cnt = 0; REP(i, N) { ll c = costs[i][0]; ll q = costs[i][1]; ll buy; // cout << cnt << "," << total << "," << c << "," << q << endl; if (cnt + q >= M) { buy = M - cnt; total = total + buy * c; return total; } else { buy = q; total = total + buy * c; cnt = cnt + q; } } return 0; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); // solve(); cout << solve(); }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
911,248
911,249
u346050999
cpp
p03103
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int cost[n], weight[n]; vector<pair<int, int>> vp; for (int i = 0; i < n; ++i) { cin >> cost[i] >> weight[i]; vp.push_back({cost[i], i}); } sort(vp.begin(), vp.end()); long long ans = 0ll; for (int i = 0; i < n; ++i) { int idx = vp[i].second; int x = min(m, weight[idx]); m -= x; ans += cost[idx] * x * 1ll; if (m <= 0) break; } return cout << ans << "\n", 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int cost[n], weight[n]; vector<pair<int, int>> vp; for (int i = 0; i < n; ++i) { cin >> cost[i] >> weight[i]; vp.push_back({cost[i], i}); } sort(vp.begin(), vp.end()); long long ans = 0ll; for (int i = 0; i < n; ++i) { int idx = vp[i].second; long long x = min(m, weight[idx]); m -= x; ans += cost[idx] * 1ll * x * 1ll; if (m <= 0) break; } return cout << ans << "\n", 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change", "assignment.change" ]
911,270
911,271
u592629796
cpp
p03103
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define Abs(x) ((x) < 0 ? (x) * -1 : (x)) #define rep(x, y) for ((x) = 0; (x) < (y); (x)++) #define repin(x, y) for ((x) = 0; (x) <= (y); (x)++) #define nep(x, y) for ((x) = (y)-1; 0 <= (x); (x)--) #define nepi(x, y, z) for ((x) = (y)-1; (z) <= (x); (x)--) #define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++) #define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++) #define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z)) #define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s)) #define repiins(x, y, z, s) for ((x) = (z); (x) <= (y); (x) += (s)) #define repit(x) \ for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++) #define repit2(x) \ for (__typeof((x).begin()) it2 = (x).begin(); it2 != (x).end(); it2++) #define nepit(x) \ for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++) #define All(x) (x).begin(), (x).end() #define Mem0(x) memset(x, 0, sizeof(x)) #define Mem1(x) memset(x, -1, sizeof(x)) #define Unique(v) v.resize(unique(All(v)) - v.begin()) #define peq(p0, p1) (p0.first == p1.first && p0.second == p1.second) #define End '\n' #define Out(x) cout << (x) << End #define OutP(p, sep, end) cout << p.first << sep << p.second << end template <typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; } template <typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; } template <typename T> using V = vector<T>; template <typename T> using VV = V<V<T>>; #define Sort(v) sort(All(v)) #define SortR(v) sort(All(v), std::greater<__typeof(v[0])>()) #define Sart(a) sort(a, a + sizeof(a) / sizeof(__typeof(a))); #define SartR(a) \ sort(a, a + sizeof(a) / sizeof(__typeof(a)), std::greater<__typeof(a[0])>()) #define pb push_back #define mp make_pair #define X first #define Y second #define lb std::lower_bound #define ub std::upper_bound #define lbi(v, x) lb(All(v), (x)) - v.begin() #define ubi(v, x) ub(All(v), (x)) - v.begin() static const ll MOD = 1e9 + 7; static const double PI = 3.141592653589793; #define LOCAL 0 int main() { #if LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); freopen("debug.txt", "w", stderr); #endif cin.tie(0); ios::sync_with_stdio(false); // std::cout.precision(18); ll n, m; cin >> n >> m; pair<ll, ll> p[n]; ll cost = 0; ll i; rep(i, n) cin >> p[i].X >> p[i].Y; Sart(p); rep(i, n) { if (m <= p[i].Y) { cost += p[i].X * m; break; } else { cost += p[i].X * p[i].Y; m -= p[i].Y; } } Out(cost); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define Abs(x) ((x) < 0 ? (x) * -1 : (x)) #define rep(x, y) for ((x) = 0; (x) < (y); (x)++) #define repin(x, y) for ((x) = 0; (x) <= (y); (x)++) #define nep(x, y) for ((x) = (y)-1; 0 <= (x); (x)--) #define nepi(x, y, z) for ((x) = (y)-1; (z) <= (x); (x)--) #define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++) #define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++) #define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z)) #define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s)) #define repiins(x, y, z, s) for ((x) = (z); (x) <= (y); (x) += (s)) #define repit(x) \ for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++) #define repit2(x) \ for (__typeof((x).begin()) it2 = (x).begin(); it2 != (x).end(); it2++) #define nepit(x) \ for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++) #define All(x) (x).begin(), (x).end() #define Mem0(x) memset(x, 0, sizeof(x)) #define Mem1(x) memset(x, -1, sizeof(x)) #define Unique(v) v.resize(unique(All(v)) - v.begin()) #define peq(p0, p1) (p0.first == p1.first && p0.second == p1.second) #define End '\n' #define Out(x) cout << (x) << End #define OutP(p, sep, end) cout << p.first << sep << p.second << end template <typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; } template <typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; } template <typename T> using V = vector<T>; template <typename T> using VV = V<V<T>>; #define Sort(v) sort(All(v)) #define SortR(v) sort(All(v), std::greater<__typeof(v[0])>()) #define Sart(a) sort(a, a + sizeof(a) / sizeof(__typeof(a[0]))); #define SartR(a) \ sort(a, a + sizeof(a) / sizeof(__typeof(a[0])), \ std::greater<__typeof(a[0])>()) #define pb push_back #define mp make_pair #define X first #define Y second #define lb std::lower_bound #define ub std::upper_bound #define lbi(v, x) lb(All(v), (x)) - v.begin() #define ubi(v, x) ub(All(v), (x)) - v.begin() static const ll MOD = 1e9 + 7; static const double PI = 3.141592653589793; #define LOCAL 0 int main() { #if LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); freopen("debug.txt", "w", stderr); #endif cin.tie(0); ios::sync_with_stdio(false); // std::cout.precision(18); ll n, m; cin >> n >> m; pair<ll, ll> p[n]; ll cost = 0; ll i; rep(i, n) cin >> p[i].X >> p[i].Y; Sart(p); rep(i, n) { if (m <= p[i].Y) { cost += p[i].X * m; break; } else { cost += p[i].X * p[i].Y; m -= p[i].Y; } } Out(cost); return 0; }
[]
911,272
911,273
u518883877
cpp
p03103
#include <algorithm> #include <bitset> #include <cmath> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define INF 100000000 #define ll long long int using namespace std; int main() { ll N, M; cin >> N >> M; ll need = 0; vector<pair<int, int>> mise(0); for (int i = 0; i < N; i++) { ll aaa, bbb; cin >> aaa >> bbb; mise.push_back(make_pair(aaa, bbb)); } // firstが小さい順、secondが小さい順にソート sort(mise.begin(), mise.end()); int it = 0; for (;;) { if (M < mise[it].second) { need += M * mise[it].first; break; } else { M = M - mise[it].second; need += mise[it].second * mise[it].first; it++; } } cout << need << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define INF 100000000 #define ll long long int using namespace std; int main() { ll N, M; cin >> N >> M; ll need = 0; vector<pair<ll, ll>> mise(0); for (int i = 0; i < N; i++) { ll aaa, bbb; cin >> aaa >> bbb; mise.push_back(make_pair(aaa, bbb)); } // firstが小さい順、secondが小さい順にソート sort(mise.begin(), mise.end()); int it = 0; for (;;) { if (M <= mise[it].second) { need += M * mise[it].first; break; } else { M = M - mise[it].second; need += mise[it].second * mise[it].first; it++; } } cout << need << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
911,280
911,281
u617525345
cpp
p03103
#include <bits/stdc++.h> using namespace std; int n, m; long long ans; pair<int, int> p[101010]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for (int i = 0; i < n; i++) { cin >> p[i].first >> p[i].second; } sort(p, p + n); for (int i = 0; i < n; i++) { if (!m) { return cout << ans << '\n', 0; } if (m >= p[i].second) { ans += (p[i].first * p[i].second); m -= p[i].second; } else { ans += (p[i].first * m); m = 0; } } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int n, m; long long ans; pair<int, int> p[101010]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for (int i = 0; i < n; i++) { cin >> p[i].first >> p[i].second; } sort(p, p + n); for (int i = 0; i < n; i++) { if (!m) { return cout << ans << '\n', 0; } if (m >= p[i].second) { ans += (p[i].first * 1LL * p[i].second); m -= p[i].second; } else { ans += (p[i].first * 1LL * m); m = 0; } } cout << ans << '\n'; return 0; }
[ "assignment.change" ]
911,292
911,293
u580075993
cpp
p03103
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; int main() { int n, m; cin >> n >> m; vector<pair<int, int>> v; for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; v.push_back({a, b}); } sort(v.begin(), v.end()); ll ans = 0, i = 0; while (m >= 0) { if (v[i].second < m) { ans += v[i].first * v[i].second; m -= v[i].second; } else { ans += v[i].first * m; break; } i++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; int main() { int n, m; cin >> n >> m; vector<pair<ll, ll>> v; for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; v.push_back({a, b}); } sort(v.begin(), v.end()); ll ans = 0, i = 0; while (m >= 0) { if (v[i].second < m) { ans += v[i].first * v[i].second; m -= v[i].second; } else { ans += v[i].first * m; break; } i++; } cout << ans << endl; }
[]
911,306
911,307
u402472923
cpp
p03103
#include <bits/stdc++.h> using ll = long long; using namespace std; #define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++) #define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++) #define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--) #define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--) #define MP(a, b) make_pair((a), (b)) #define PB(a) push_back((a)) #define all(v) (v).begin(), (v).end() #define PERM(v) next_permutation(all(v)) #define UNIQUE(v) \ sort(all(v)); \ (v).erase(unique(all(v)), v.end()) #define CIN(type, x) \ type x; \ cin >> x #define TRUE__ "Yes" #define FALSE__ "No" #define PRINT(f) \ if ((f)) { \ cout << (TRUE__) << endl; \ } else { \ cout << FALSE__ << endl; \ } #define YES(f) \ if ((f)) { \ cout << "YES" << endl; \ } else { \ cout << "NO" << endl; \ } #define Yes(f) \ if ((f)) { \ cout << "Yes" << endl; \ } else { \ cout << "No" << endl; \ } #define MINV(v) min_element(all(v)) #define MAXV(v) max_element(all(v)) #define MIN3(a, b, c) min(min(a, b), c) #define MIN4(a, b, c, d) min(MIN3(a, b, c), d) #define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e) #define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f) #define MAX3(a, b, c) max(max(a, b), c) #define MAX4(a, b, c, d) max(MAX3(a, b, c), d) #define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e) #define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f) #define RANGE(a, b, c) ((a) <= (b) && (b) < (c)) #define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f))) #define chmin(a, b) a = min(a, (b)) #define chmin3(a, b, c) a = MIN3(a, (b), (c)) #define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d)) #define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e)) #define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f)) #define chmax(a, b) a = max(a, (b)) #define chmax3(a, b, c) a = MAX3(a, (b), (c)) #define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d)) #define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e)) #define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f)) #define fcout cout << fixed << setprecision(12) #define RS resize #define CINV(v, N) \ do { \ v.RS(N); \ rep(i, N) cin >> v[i]; \ } while (0); #define RCINV(v, N) \ do { \ v.RS(N); \ rrep(i, N) cin >> v[i]; \ } while (0); #define MOD 1000000007 template <class T> inline T GET() { T x; cin >> x; return x; } void init(); void solve(); signed main() { init(); solve(); } void init() { ll N, M; cin >> N >> M; vector<pair<ll, ll>> A; rep(i, N) { ll a, b; cin >> a >> b; A.PB(MP(a, b)); } sort(all(A)); ll cnt = 0; ll res = 0; rep(i, N) { cnt += A[i].second; if (cnt >= M) { cnt -= A[i].second; cout << res + (M - cnt) * A[i].first << endl; } res += A[i].first * A[i].second; } } void solve() {}
#include <bits/stdc++.h> using ll = long long; using namespace std; #define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++) #define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++) #define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--) #define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--) #define MP(a, b) make_pair((a), (b)) #define PB(a) push_back((a)) #define all(v) (v).begin(), (v).end() #define PERM(v) next_permutation(all(v)) #define UNIQUE(v) \ sort(all(v)); \ (v).erase(unique(all(v)), v.end()) #define CIN(type, x) \ type x; \ cin >> x #define TRUE__ "Yes" #define FALSE__ "No" #define PRINT(f) \ if ((f)) { \ cout << (TRUE__) << endl; \ } else { \ cout << FALSE__ << endl; \ } #define YES(f) \ if ((f)) { \ cout << "YES" << endl; \ } else { \ cout << "NO" << endl; \ } #define Yes(f) \ if ((f)) { \ cout << "Yes" << endl; \ } else { \ cout << "No" << endl; \ } #define MINV(v) min_element(all(v)) #define MAXV(v) max_element(all(v)) #define MIN3(a, b, c) min(min(a, b), c) #define MIN4(a, b, c, d) min(MIN3(a, b, c), d) #define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e) #define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f) #define MAX3(a, b, c) max(max(a, b), c) #define MAX4(a, b, c, d) max(MAX3(a, b, c), d) #define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e) #define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f) #define RANGE(a, b, c) ((a) <= (b) && (b) < (c)) #define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f))) #define chmin(a, b) a = min(a, (b)) #define chmin3(a, b, c) a = MIN3(a, (b), (c)) #define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d)) #define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e)) #define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f)) #define chmax(a, b) a = max(a, (b)) #define chmax3(a, b, c) a = MAX3(a, (b), (c)) #define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d)) #define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e)) #define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f)) #define fcout cout << fixed << setprecision(12) #define RS resize #define CINV(v, N) \ do { \ v.RS(N); \ rep(i, N) cin >> v[i]; \ } while (0); #define RCINV(v, N) \ do { \ v.RS(N); \ rrep(i, N) cin >> v[i]; \ } while (0); #define MOD 1000000007 template <class T> inline T GET() { T x; cin >> x; return x; } void init(); void solve(); signed main() { init(); solve(); } void init() { ll N, M; cin >> N >> M; vector<pair<ll, ll>> A; rep(i, N) { ll a, b; cin >> a >> b; A.PB(MP(a, b)); } sort(all(A)); ll cnt = 0; ll res = 0; rep(i, N) { cnt += A[i].second; if (cnt >= M) { cnt -= A[i].second; cout << res + (M - cnt) * A[i].first << endl; return; } res += A[i].first * A[i].second; } } void solve() {}
[ "control_flow.return.add" ]
911,312
911,313
u946322619
cpp
p03103
#include <bits/stdc++.h> using ll = long long; using namespace std; #define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++) #define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++) #define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--) #define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--) #define MP(a, b) make_pair((a), (b)) #define PB(a) push_back((a)) #define all(v) (v).begin(), (v).end() #define PERM(v) next_permutation(all(v)) #define UNIQUE(v) \ sort(all(v)); \ (v).erase(unique(all(v)), v.end()) #define CIN(type, x) \ type x; \ cin >> x #define TRUE__ "Yes" #define FALSE__ "No" #define PRINT(f) \ if ((f)) { \ cout << (TRUE__) << endl; \ } else { \ cout << FALSE__ << endl; \ } #define YES(f) \ if ((f)) { \ cout << "YES" << endl; \ } else { \ cout << "NO" << endl; \ } #define Yes(f) \ if ((f)) { \ cout << "Yes" << endl; \ } else { \ cout << "No" << endl; \ } #define MINV(v) min_element(all(v)) #define MAXV(v) max_element(all(v)) #define MIN3(a, b, c) min(min(a, b), c) #define MIN4(a, b, c, d) min(MIN3(a, b, c), d) #define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e) #define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f) #define MAX3(a, b, c) max(max(a, b), c) #define MAX4(a, b, c, d) max(MAX3(a, b, c), d) #define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e) #define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f) #define RANGE(a, b, c) ((a) <= (b) && (b) < (c)) #define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f))) #define chmin(a, b) a = min(a, (b)) #define chmin3(a, b, c) a = MIN3(a, (b), (c)) #define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d)) #define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e)) #define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f)) #define chmax(a, b) a = max(a, (b)) #define chmax3(a, b, c) a = MAX3(a, (b), (c)) #define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d)) #define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e)) #define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f)) #define fcout cout << fixed << setprecision(12) #define RS resize #define CINV(v, N) \ do { \ v.RS(N); \ rep(i, N) cin >> v[i]; \ } while (0); #define RCINV(v, N) \ do { \ v.RS(N); \ rrep(i, N) cin >> v[i]; \ } while (0); #define MOD 1000000007 template <class T> inline T GET() { T x; cin >> x; return x; } void init(); void solve(); signed main() { init(); solve(); } void init() { int N, M; cin >> N >> M; vector<pair<ll, ll>> A; rep(i, N) { ll a, b; cin >> a >> b; A.PB(MP(a, b)); } sort(all(A)); int cnt = 0; ll res = 0; rep(i, N) { cnt += A[i].second; if (cnt >= M) { cnt -= A[i].second; cout << res + (M - cnt) * A[i].first << endl; } res += A[i].first * A[i].second; } } void solve() {}
#include <bits/stdc++.h> using ll = long long; using namespace std; #define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++) #define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++) #define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--) #define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--) #define MP(a, b) make_pair((a), (b)) #define PB(a) push_back((a)) #define all(v) (v).begin(), (v).end() #define PERM(v) next_permutation(all(v)) #define UNIQUE(v) \ sort(all(v)); \ (v).erase(unique(all(v)), v.end()) #define CIN(type, x) \ type x; \ cin >> x #define TRUE__ "Yes" #define FALSE__ "No" #define PRINT(f) \ if ((f)) { \ cout << (TRUE__) << endl; \ } else { \ cout << FALSE__ << endl; \ } #define YES(f) \ if ((f)) { \ cout << "YES" << endl; \ } else { \ cout << "NO" << endl; \ } #define Yes(f) \ if ((f)) { \ cout << "Yes" << endl; \ } else { \ cout << "No" << endl; \ } #define MINV(v) min_element(all(v)) #define MAXV(v) max_element(all(v)) #define MIN3(a, b, c) min(min(a, b), c) #define MIN4(a, b, c, d) min(MIN3(a, b, c), d) #define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e) #define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f) #define MAX3(a, b, c) max(max(a, b), c) #define MAX4(a, b, c, d) max(MAX3(a, b, c), d) #define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e) #define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f) #define RANGE(a, b, c) ((a) <= (b) && (b) < (c)) #define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f))) #define chmin(a, b) a = min(a, (b)) #define chmin3(a, b, c) a = MIN3(a, (b), (c)) #define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d)) #define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e)) #define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f)) #define chmax(a, b) a = max(a, (b)) #define chmax3(a, b, c) a = MAX3(a, (b), (c)) #define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d)) #define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e)) #define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f)) #define fcout cout << fixed << setprecision(12) #define RS resize #define CINV(v, N) \ do { \ v.RS(N); \ rep(i, N) cin >> v[i]; \ } while (0); #define RCINV(v, N) \ do { \ v.RS(N); \ rrep(i, N) cin >> v[i]; \ } while (0); #define MOD 1000000007 template <class T> inline T GET() { T x; cin >> x; return x; } void init(); void solve(); signed main() { init(); solve(); } void init() { ll N, M; cin >> N >> M; vector<pair<ll, ll>> A; rep(i, N) { ll a, b; cin >> a >> b; A.PB(MP(a, b)); } sort(all(A)); ll cnt = 0; ll res = 0; rep(i, N) { cnt += A[i].second; if (cnt >= M) { cnt -= A[i].second; cout << res + (M - cnt) * A[i].first << endl; return; } res += A[i].first * A[i].second; } } void solve() {}
[ "variable_declaration.type.change", "control_flow.return.add" ]
911,314
911,313
u946322619
cpp
p03103
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #define rt register int #define l putchar('\n') #define ll long long #define r read() #define p 998244353 using namespace std; inline ll read() { ll x = 0; char zf = 1; char ch = getchar(); while (ch != '-' && !isdigit(ch)) ch = getchar(); if (ch == '-') zf = -1, ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return x * zf; } void write(ll y) { if (y < 0) putchar('-'), y = -y; if (y > 9) write(y / 10); putchar(y % 10 + 48); } void writeln(const ll y) { write(y); putchar('\n'); } int i, j, k, m, n, x, y, z, cnt, sum; struct drin { ll x, y; bool operator<(const drin s) const { return y < s.y; } } a[100010]; int main() { n = r; m = r; for (rt i = 1; i <= n; i++) a[i].x = r, a[i].y = r; sort(a + 1, a + n + 1); ll cos = 0; for (rt i = 1; i <= n; i++) { if (m >= a[i].y) cos += a[i].x * a[i].y, m -= a[i].y; else cos += m * a[i].x, m = 0; if (!m) break; } cout << cos; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #define rt register int #define l putchar('\n') #define ll long long #define r read() #define p 998244353 using namespace std; inline ll read() { ll x = 0; char zf = 1; char ch = getchar(); while (ch != '-' && !isdigit(ch)) ch = getchar(); if (ch == '-') zf = -1, ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return x * zf; } void write(ll y) { if (y < 0) putchar('-'), y = -y; if (y > 9) write(y / 10); putchar(y % 10 + 48); } void writeln(const ll y) { write(y); putchar('\n'); } int i, j, k, m, n, x, y, z, cnt, sum; struct drin { ll x, y; bool operator<(const drin s) const { return x < s.x; } } a[100010]; int main() { n = r; m = r; for (rt i = 1; i <= n; i++) a[i].x = r, a[i].y = r; sort(a + 1, a + n + 1); ll cos = 0; for (rt i = 1; i <= n; i++) { if (m >= a[i].y) cos += a[i].x * a[i].y, m -= a[i].y; else cos += m * a[i].x, m = 0; if (!m) break; } cout << cos; return 0; }
[ "identifier.change", "function.return_value.change", "expression.operation.binary.change" ]
911,319
911,320
u178311310
cpp
p03103
#include "bits/stdc++.h" #define in std::cin #define out std::cout #define rep(i, N) for (LL i = 0; i < N; ++i) typedef long long int LL; int main() { LL N, M; in >> N >> M; std::vector<LL> A(N), B(N); rep(i, N) in >> A[i] >> B[i]; std::vector<std::pair<LL, LL>> store; rep(i, N) store.push_back(std::make_pair(A[i], B[i])); std::sort(store.begin(), store.end()); LL sum = 0, ans = 0; rep(i, N) { if (ans == M) break; LL want = M - sum; LL can = std::min(want, store[i].second); ans += store[i].first * can; sum += can; } out << ans << std::endl; }
#include "bits/stdc++.h" #define in std::cin #define out std::cout #define rep(i, N) for (LL i = 0; i < N; ++i) typedef long long int LL; int main() { LL N, M; in >> N >> M; std::vector<LL> A(N), B(N); rep(i, N) in >> A[i] >> B[i]; std::vector<std::pair<LL, LL>> store; rep(i, N) store.push_back(std::make_pair(A[i], B[i])); std::sort(store.begin(), store.end()); LL sum = 0, ans = 0; rep(i, N) { if (sum == M) break; LL want = M - sum; LL can = std::min(want, store[i].second); ans += store[i].first * can; sum += can; } out << ans << std::endl; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
911,323
911,324
u660613376
cpp
p03103
// #include C/C++ { #include <bits/stdc++.h> // } using namespace std; // #typedef { typedef long long int64; typedef pair<int, int> PII; typedef pair<int64, int64> PLL; // } #define DEBUG_MODE // #parameter{ #ifdef DEBUG_MODE #define TYPE decltype #define RF(filename) \ { freopen((filename), "r", stdin); } #define WF(filename) \ { freopen((filename), "w", stdout); } #define DF(filename) \ { freopen((filename), "w", stderr); } #define eprintf printf #else #define TYPE __typeof #define RF(filename) \ { ; } #define WF(filename) \ { ; } #define DF(filename) \ { ; } #define eprintf(...) #define fprintf(...) #endif // #define { #define SZ(a) ((int)(a).size()) #define X first #define Y second #define MP make_pair #define L(x) ((x) << 1) #define R(x) ((x) << 1 | 1) #define max3(x, y, z) (max(max((x), (y)), (z))) #define min3(x, y, z) (min(min((x), (y)), (z))) #define BIT(x, i) (((x) >> (i)) & 1) #define ALL(it) (it).begin(), (it).end() #define FILL(__space, __val) memset(__space, __val, sizeof(__space)) #define MOVE(__spaceTo, __spaceFrom) \ memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo)) #define UNIQUE(__vector) \ sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin()) #define FOR(it, c) \ for (TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++) ///////////////////////////////////////////////////////////// const double PI = acos(-1.0); const double EPS = 1e-6; #define MAX_N 100005 #define MAX_M 5005 #define MOD (int)(1e9 + 7) #define INF ((1 << 30) - 1) #define BINF ((1LL << 62) - 1LL) #define NONE -1 #define NIL 0 // } ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// int main() { RF("input.txt"); // WF("output.txt"); DF("err.txt"); int N, M; scanf("%d %d", &N, &M); PII a[MAX_N]; for (int i = 0; i < N; i++) scanf("%d %d", &a[i].X, &a[i].Y); sort(a, a + N); int64 res = 0LL; for (int i = 0; i < N; i++) { res += 1LL * min(M, a[i].Y) * a[i].X; M -= min(M, a[i].Y); if (M == 0) break; } printf("%lld\n", res); return 0; }
// #include C/C++ { #include <bits/stdc++.h> // } using namespace std; // #typedef { typedef long long int64; typedef pair<int, int> PII; typedef pair<int64, int64> PLL; // } // #parameter{ #ifdef DEBUG_MODE #define TYPE decltype #define RF(filename) \ { freopen((filename), "r", stdin); } #define WF(filename) \ { freopen((filename), "w", stdout); } #define DF(filename) \ { freopen((filename), "w", stderr); } #define eprintf printf #else #define TYPE __typeof #define RF(filename) \ { ; } #define WF(filename) \ { ; } #define DF(filename) \ { ; } #define eprintf(...) #define fprintf(...) #endif // #define { #define SZ(a) ((int)(a).size()) #define X first #define Y second #define MP make_pair #define L(x) ((x) << 1) #define R(x) ((x) << 1 | 1) #define max3(x, y, z) (max(max((x), (y)), (z))) #define min3(x, y, z) (min(min((x), (y)), (z))) #define BIT(x, i) (((x) >> (i)) & 1) #define ALL(it) (it).begin(), (it).end() #define FILL(__space, __val) memset(__space, __val, sizeof(__space)) #define MOVE(__spaceTo, __spaceFrom) \ memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo)) #define UNIQUE(__vector) \ sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin()) #define FOR(it, c) \ for (TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++) ///////////////////////////////////////////////////////////// const double PI = acos(-1.0); const double EPS = 1e-6; #define MAX_N 100005 #define MAX_M 5005 #define MOD (int)(1e9 + 7) #define INF ((1 << 30) - 1) #define BINF ((1LL << 62) - 1LL) #define NONE -1 #define NIL 0 // } ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// int main() { RF("input.txt"); // WF("output.txt"); DF("err.txt"); int N, M; scanf("%d %d", &N, &M); PII a[MAX_N]; for (int i = 0; i < N; i++) scanf("%d %d", &a[i].X, &a[i].Y); sort(a, a + N); int64 res = 0LL; for (int i = 0; i < N; i++) { res += 1LL * min(M, a[i].Y) * a[i].X; M -= min(M, a[i].Y); if (M == 0) break; } printf("%lld\n", res); return 0; }
[]
911,325
911,326
u379993235
cpp
p03104
#include <algorithm> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; #define fi first #define se second #define mp make_pair #define mt make_tuple #define pqueue priority_queue const int inf = 1e9 + 7; const ll mod = 1e9 + 7; const ll mod1 = 998244353; const ll big = 1e18; const double PI = 2 * asin(1); int main() { ll A, B; cin >> A >> B; ll ans; ll num; if (A % 2 == 0) { if (B % 2 == 0) { num = (B - A) / 2; num %= 2; ans = B ^ num; } else { num = (B - A + 1) / 2; num %= 2; ans = num; } } else { if (B % 2 == 0) { num = (B - A) / 2; num %= 2; ans = A ^ B ^ num; } else { num = (B - A - 1) / 2; num %= 2; ans = A ^ num; } } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; #define fi first #define se second #define mp make_pair #define mt make_tuple #define pqueue priority_queue const int inf = 1e9 + 7; const ll mod = 1e9 + 7; const ll mod1 = 998244353; const ll big = 1e18; const double PI = 2 * asin(1); int main() { ll A, B; cin >> A >> B; ll ans; ll num; if (A % 2 == 0) { if (B % 2 == 0) { num = (B - A) / 2; num %= 2; ans = B ^ num; } else { num = (B - A + 1) / 2; num %= 2; ans = num; } } else { if (B % 2 == 0) { num = (B - A) / 2; num %= 2; ans = A ^ B ^ num; } else { num = (B - A) / 2; num %= 2; ans = A ^ num; } } cout << ans << endl; }
[ "expression.operation.binary.remove" ]
911,331
911,332
u860546679
cpp
p03104
#include <algorithm> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; #define fi first #define se second #define mp make_pair #define mt make_tuple #define pqueue priority_queue const int inf = 1e9 + 7; const ll mod = 1e9 + 7; const ll mod1 = 998244353; const ll big = 1e18; const double PI = 2 * asin(1); int main() { ll A, B; cin >> A >> B; ll ans; ll num; if (A % 2 == 0) { if (B % 2 == 0) { num = (B - A) / 2; num %= 2; ans = B ^ num; } else { num = (B - A) / 2; num %= 2; ans = num; } } else { if (B % 2 == 0) { num = (B - A) / 2; num %= 2; ans = A ^ B ^ num; } else { num = (B - A - 1) / 2; num %= 2; ans = A ^ num; } } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; #define fi first #define se second #define mp make_pair #define mt make_tuple #define pqueue priority_queue const int inf = 1e9 + 7; const ll mod = 1e9 + 7; const ll mod1 = 998244353; const ll big = 1e18; const double PI = 2 * asin(1); int main() { ll A, B; cin >> A >> B; ll ans; ll num; if (A % 2 == 0) { if (B % 2 == 0) { num = (B - A) / 2; num %= 2; ans = B ^ num; } else { num = (B - A + 1) / 2; num %= 2; ans = num; } } else { if (B % 2 == 0) { num = (B - A) / 2; num %= 2; ans = A ^ B ^ num; } else { num = (B - A) / 2; num %= 2; ans = A ^ num; } } cout << ans << endl; }
[ "assignment.change", "expression.operation.binary.remove" ]
911,333
911,332
u860546679
cpp
p03104
#include <iostream> using namespace std; int main() { long A, B; cin >> A >> B; long num; long ans; if (A % 2 == 0) { if (B % 2 == 0) { num = B - A; if (num % 4 == 0) { ans = 0; } else { ans = 1; } ans = ans ^ B; } else { num = B - A - 1; if (num % 4 == 0) { ans = 0; } else { ans = 1; } } } else { if (B % 2 == 0) { num = B - A - 1; if (num % 4 == 0) { ans = 0; } else { ans = 1; } ans = ans ^ A; ans = ans ^ B; } else { num = B - A; if (num % 4 == 0) { ans = 0; } else { ans = 1; } ans = ans ^ A; } } cout << ans << endl; }
#include <iostream> using namespace std; int main() { long A, B; cin >> A >> B; long num; long ans; /* long ans1=A; for(long i=A+1;i<=B;++i){ ans1=ans1^i; } */ if (A % 2 == 0) { if (B % 2 == 0) { num = B - A; if (num % 4 == 0) { ans = 0; } else { ans = 1; } ans = ans ^ B; } else { num = B - A + 1; if (num % 4 == 0) { ans = 0; } else { ans = 1; } } } else { if (B % 2 == 0) { num = B - A - 1; if (num % 4 == 0) { ans = 0; } else { ans = 1; } ans = ans ^ A; ans = ans ^ B; } else { num = B - A; if (num % 4 == 0) { ans = 0; } else { ans = 1; } ans = ans ^ A; } } cout << ans << endl; // cout<<ans1<<endl; }
[ "misc.opposites", "expression.operator.arithmetic.change", "assignment.value.change", "expression.operation.binary.change" ]
911,334
911,335
u860546679
cpp
p03104
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, n, j) for (int i = (j); i < (n); ++i) #define ssort(n) sort((n).begin(), (n).end()) #define rsort(n) sort((n).begin(), (n).end(), greater<int>()) #define mp make_pair using ll = long long; using ld = long double; typedef pair<int, int> P; typedef pair<P, int> COST; #define repl(i, n) for (ll i = 0; i < (n); ++i) #define Yes cout << "Yes" << endl #define No cout << "No" << endl #define YES cout << "YES" << endl #define NO cout << "NO" << endl using Graf = vector<vector<int>>; #define MAX 1000000007 class Calc_Mod { // calculate mod public: unsigned int mod = 1000000007; ll plus_mod(ll a, ll b) { return (a + b) % mod; } ll minus_mod(ll a, ll b) { return (a - b) % mod; } ll multi_mod(ll a, ll b) { return a * b % mod; } ll LSM(ll a, int b) { // a^b%mod queue<int> q; while (b >= 1) { q.push(b % 2); b /= 2; } ll ans = 1; while (!q.empty()) { if (q.front() == 1) { ans = multi_mod(ans, a); } a = multi_mod(a, a); q.pop(); } return ans; } ll div_mod(ll a, ll b) { // a/b return multi_mod(a, LSM(b, mod - 2)); } ll combi(ll a, ll b) { // aCb ll ans = 1; ll kaijo = 1; rep(i, b) { ans = multi_mod(ans, a - i); kaijo = multi_mod(kaijo, b - i); } ans = div_mod(ans, kaijo); return ans; } }; int main() { ll a, b; cin >> a >> b; bool flag = false; bool flag_3 = false; if (a % 2 == 0) { flag = true; } if (flag == false && a % 3 == 0) { flag_3 = true; } ll num; int dist; ll ans; if (flag == true) { num = (b - a) / 4; num = a + 4 * num; ans = num; dist = (b - a) % 4; rep(i, dist) { ans ^= (num + i + 1); } } else { if (flag_3 == false) { num = (b - a) / 3; num = a + 3 * num; dist = (b - a) % 3; ans = num; rep(i, dist) { ans ^= (num + i + 1); } } else { num = (b - a) / 4; num = a + 4 * num; dist = (b - a) % 4; ans = a; rep(i, dist) { ans ^= (num + i + 1); } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, n, j) for (int i = (j); i < (n); ++i) #define ssort(n) sort((n).begin(), (n).end()) #define rsort(n) sort((n).begin(), (n).end(), greater<int>()) #define mp make_pair using ll = long long; using ld = long double; typedef pair<int, int> P; typedef pair<P, int> COST; #define repl(i, n) for (ll i = 0; i < (n); ++i) #define Yes cout << "Yes" << endl #define No cout << "No" << endl #define YES cout << "YES" << endl #define NO cout << "NO" << endl using Graf = vector<vector<int>>; #define MAX 1000000007 class Calc_Mod { // calculate mod public: unsigned int mod = 1000000007; ll plus_mod(ll a, ll b) { return (a + b) % mod; } ll minus_mod(ll a, ll b) { return (a - b) % mod; } ll multi_mod(ll a, ll b) { return a * b % mod; } ll LSM(ll a, int b) { // a^b%mod queue<int> q; while (b >= 1) { q.push(b % 2); b /= 2; } ll ans = 1; while (!q.empty()) { if (q.front() == 1) { ans = multi_mod(ans, a); } a = multi_mod(a, a); q.pop(); } return ans; } ll div_mod(ll a, ll b) { // a/b return multi_mod(a, LSM(b, mod - 2)); } ll combi(ll a, ll b) { // aCb ll ans = 1; ll kaijo = 1; rep(i, b) { ans = multi_mod(ans, a - i); kaijo = multi_mod(kaijo, b - i); } ans = div_mod(ans, kaijo); return ans; } }; int main() { ll a, b; cin >> a >> b; bool flag = false; bool flag_3 = false; if (a % 2 == 0) { flag = true; } if (flag == false && a != 1) { flag_3 = true; } ll num; int dist; ll ans; if (flag == true) { num = (b - a) / 4; num = a + 4 * num; ans = num; dist = (b - a) % 4; rep(i, dist) { ans ^= (num + i + 1); } } else { if (flag_3 == false) { num = (b - a) / 3; num = a + 3 * num; dist = (b - a) % 3; ans = num; rep(i, dist) { ans ^= (num + i + 1); } } else { num = (b - a) / 4; num = a + 4 * num; dist = (b - a) % 4; ans = a; rep(i, dist) { ans ^= (num + i + 1); } } } cout << ans << endl; }
[ "expression.operation.binary.remove" ]
911,342
911,343
u149757670
cpp
p03104
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; int main() { long long a, b; cin >> a >> b; if (a % 2 == 0) { if (b % 2 == 0) { cout << b + ((b - a) / 2) % 2 << endl; } else if (b % 2 == 1) { cout << (b / 2 - a / 2 + 1) % 2 << endl; } } else if (a % 2 == 1) { if (b % 2 == 1) { cout << 2 * (b / 2) + (b / 2 - a / 2 + 1) % 2 << endl; } else if (b % 2 == 0) { long long ans = (b / 2) ^ (a / 2); cout << 2 * ans + (b / 2 - a / 2) % 2 << endl; } } }
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; int main() { long long a, b; cin >> a >> b; if (a % 2 == 0) { if (b % 2 == 0) { cout << b + ((b - a) / 2) % 2 << endl; } else if (b % 2 == 1) { cout << (b / 2 - a / 2 + 1) % 2 << endl; } } else if (a % 2 == 1) { if (b % 2 == 1) { cout << 2 * (a / 2) + (b / 2 - a / 2 + 1) % 2 << endl; } else if (b % 2 == 0) { long long ans = (b / 2) ^ (a / 2); cout << 2 * ans + (b / 2 - a / 2) % 2 << endl; } } }
[ "identifier.change", "io.output.change" ]
911,351
911,352
u013069672
cpp
p03104
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; int main() { long long a, b; cin >> a >> b; if (a % 2 == 0) { if (b % 2 == 0) { cout << b + ((b - a) / 2) % 2 << endl; } else if (b % 2 == 1) { cout << (b / 2 - a / 2) % 2 << endl; } } else if (a % 2 == 1) { if (b % 2 == 1) { cout << 2 * (b / 2) + (b / 2 - a / 2 + 1) % 2 << endl; } else if (b % 2 == 0) { long long ans = (b / 2) ^ (a / 2); cout << 2 * ans + (b / 2 - a / 2) % 2 << endl; } } }
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; int main() { long long a, b; cin >> a >> b; if (a % 2 == 0) { if (b % 2 == 0) { cout << b + ((b - a) / 2) % 2 << endl; } else if (b % 2 == 1) { cout << (b / 2 - a / 2 + 1) % 2 << endl; } } else if (a % 2 == 1) { if (b % 2 == 1) { cout << 2 * (a / 2) + (b / 2 - a / 2 + 1) % 2 << endl; } else if (b % 2 == 0) { long long ans = (b / 2) ^ (a / 2); cout << 2 * ans + (b / 2 - a / 2) % 2 << endl; } } }
[ "identifier.change", "io.output.change" ]
911,353
911,352
u013069672
cpp
p03104
#include <bits/stdc++.h> using namespace std; using ll = long long; #define For(i, a, b) for (ll i = (a); i < (b); ++i) #define rep(i, n) For(i, 0, n) #define debug(x) cerr << #x << " = " << (x) << endl; #define leftunique(a) \ { \ sort((a).begin(), (a).end()); \ (a).erase(unique((a).begin(), (a).end()), (a).end()); \ } 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; } static const ll INF = 1LL << 60; // Write From this Line int main() { ll A, B; cin >> A >> B; // [0,B]で立っている個数を各位ごとにみた後で // [0,A-1]で立っている個数を引いて上げればいい A--; vector<ll> bit(65, 0); rep(i, 64) { if (i == 0) { bit[i] += (B + 1) / 2; continue; } ll k = pow(2, i); bit[i] += k * (B / (k * 2)); if (B % (k * 2) != 0) { ll tmp = (B + 1) % (k * 2); tmp -= k; tmp = max(tmp, (ll)0); bit[i] += tmp; } } rep(i, 45) { if (i == 0) { bit[i] -= (A + 1) / 2; continue; } ll k = pow(2, i); bit[i] -= k * (A / (k * 2)); if (A % (k * 2) != 0) { ll tmp = (A + 1) % (k * 2); tmp -= k; tmp = max(tmp, (ll)0); bit[i] -= tmp; } } ll ans = 0; rep(i, 64) { if (bit[i] % 2 == 1) { ans += pow(2, i); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define For(i, a, b) for (ll i = (a); i < (b); ++i) #define rep(i, n) For(i, 0, n) #define debug(x) cerr << #x << " = " << (x) << endl; #define leftunique(a) \ { \ sort((a).begin(), (a).end()); \ (a).erase(unique((a).begin(), (a).end()), (a).end()); \ } 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; } static const ll INF = 1LL << 60; // Write From this Line int main() { ll A, B; cin >> A >> B; // [0,B]で立っている個数を各位ごとにみた後で // [0,A-1]で立っている個数を引いて上げればいい A--; vector<ll> bit(65, 0); rep(i, 63) { if (i == 0) { bit[i] += (B + 1) / 2; continue; } ll k = pow(2, i); bit[i] += k * (B / (k * 2)); if (B % (k * 2) != 0) { ll tmp = (B + 1) % (k * 2); tmp -= k; tmp = max(tmp, (ll)0); bit[i] += tmp; } } rep(i, 63) { if (i == 0) { bit[i] -= (A + 1) / 2; continue; } ll k = pow(2, i); bit[i] -= k * (A / (k * 2)); if (A % (k * 2) != 0) { ll tmp = (A + 1) % (k * 2); tmp -= k; tmp = max(tmp, (ll)0); bit[i] -= tmp; } } ll ans = 0; rep(i, 63) { if (bit[i] % 2 == 1) { ans += pow(2, i); } } cout << ans << endl; }
[ "literal.number.change", "call.arguments.change" ]
911,354
911,355
u298620933
cpp
p03104
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); ll A, B; cin >> A >> B; ll ans = 0; for (ll i = 1; i < 50; i++) { ll x = 1LL << i; ll ya = A % x; ll yb = B % x; ll za = (A / x) * x / 2LL; ll zb = (B / x) * x / 2LL; if (ya >= x / 2LL) { za += ya - (x / 2LL - 1LL); } if (yb >= x / 2LL) { zb += yb - (x / 2LL - 1LL); } ll z = zb - za; z %= 2LL; ans += z << (i - 1); } ans ^= A; cerr << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); ll A, B; cin >> A >> B; ll ans = 0; for (ll i = 1; i < 50; i++) { ll x = 1LL << i; ll ya = A % x; ll yb = B % x; ll za = (A / x) * x / 2LL; ll zb = (B / x) * x / 2LL; if (ya >= x / 2LL) { za += ya - (x / 2LL - 1LL); } if (yb >= x / 2LL) { zb += yb - (x / 2LL - 1LL); } ll z = zb - za; z %= 2LL; ans += z << (i - 1); } ans ^= A; cout << ans << endl; }
[ "identifier.change", "io.output.change" ]
911,356
911,357
u412039195
cpp
p03104
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll solve(ll x) { if (x % 2 == 0) { ll tmp; if ((x / 2) % 2 == 0) { tmp = 0; return x ^ tmp; } else { tmp = 1; return x ^ tmp; } } else { if ((x / 2) % 2 == 0) { return 0; } else { return 1; } } } int main() { cin.tie(0); ios::sync_with_stdio(false); ll a, b; cin >> a >> b; a = solve(a - 1); b = solve(b); ll ans = a ^ b; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll solve(ll x) { if (x % 2 == 0) { ll tmp; if ((x / 2) % 2 == 0) { tmp = 0; return x ^ tmp; } else { tmp = 1; return x ^ tmp; } } else { if (((x + 1) / 2) % 2 == 0) { return 0; } else { return 1; } } } int main() { cin.tie(0); ios::sync_with_stdio(false); ll a, b; cin >> a >> b; a = solve(a - 1); b = solve(b); ll ans = a ^ b; cout << ans << endl; }
[ "control_flow.branch.if.condition.change" ]
911,366
911,367
u989306199
cpp
p03104
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define endl '\n' #define int long long #define P pair<int, int> signed main() { int a, b; cin >> a >> b; int x = 0, y = 0; // x = F(0,A-1) y = F(0,B); int acnt = a; int bcnt = b + 1; if (acnt % 2 == 0) { if ((acnt / 2) % 2 == 0) x = 0; else x = 1; } else { if ((acnt / 2) % 2 == 0) x = a - 1; else { x = 1 ^ (a - 1); } } if (bcnt % 2 == 0) { if ((bcnt / 2) % 2 == 0) y = 0; else y = 1; } else { if ((bcnt / 2) % 2 == 0) y = b; else { y = 1 & b; } } int ans = x ^ y; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define endl '\n' #define int long long #define P pair<int, int> signed main() { int a, b; cin >> a >> b; int x = 0, y = 0; // x = F(0,A-1) y = F(0,B); int acnt = a; int bcnt = b + 1; if (acnt % 2 == 0) { if ((acnt / 2) % 2 == 0) x = 0; else x = 1; } else { if ((acnt / 2) % 2 == 0) x = a - 1; else { x = 1 ^ (a - 1); } } if (bcnt % 2 == 0) { if ((bcnt / 2) % 2 == 0) y = 0; else y = 1; } else { if ((bcnt / 2) % 2 == 0) y = b; else { y = 1 ^ b; } } int ans = x ^ y; cout << ans << endl; }
[ "assignment.value.change", "expression.operation.binary.change" ]
911,368
911,369
u862412671
cpp
p03104
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i, s, n) for (int i = s; i < (n); ++i) #define ALL(v) (v).begin(), (v).end() using namespace std; typedef long long ll; static const int INTINF = (2147483647); static const ll LLINF = (9223372036854775807); static const int MAX = 1e5 + 1; static const ll MOD = 1e9 + 7; namespace Printer { void print(vector<int> v) { rep(i, v.size()) { if (i) cout << " "; cout << v[i]; } cout << endl; } void print(vector<vector<int>> vv) { rep(i, vv.size()) { rep(j, vv[i].size()) { if (j) cout << " "; cout << vv[i][j]; } cout << endl; } } void print(pair<int, int> p) { cout << "(" << p.first << ", " << p.second << ")" << endl; } }; // namespace Printer //--global--// //----------// int main(int argc, const char *argv[]) { //提出時、消す----// //--------------// ll a, b; cin >> a >> b; ll ans = 0; if (abs(a - b) > 10) { ll tmp = 0; ll a2 = a; ll b2 = b; if (a2 % 2 == 1) { ans ^= a2; a2++; } if (b2 % 2 == 0) { ans ^= b2; b2--; } tmp = (b2 + 1 - a2) % 2; ans ^= tmp; } else { for (ll i = a; i <= b; i++) { ans ^= i; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i, s, n) for (int i = s; i < (n); ++i) #define ALL(v) (v).begin(), (v).end() using namespace std; typedef long long ll; static const int INTINF = (2147483647); static const ll LLINF = (9223372036854775807); static const int MAX = 1e5 + 1; static const ll MOD = 1e9 + 7; namespace Printer { void print(vector<int> v) { rep(i, v.size()) { if (i) cout << " "; cout << v[i]; } cout << endl; } void print(vector<vector<int>> vv) { rep(i, vv.size()) { rep(j, vv[i].size()) { if (j) cout << " "; cout << vv[i][j]; } cout << endl; } } void print(pair<int, int> p) { cout << "(" << p.first << ", " << p.second << ")" << endl; } }; // namespace Printer //--global--// //----------// int main(int argc, const char *argv[]) { //提出時、消す----// //--------------// ll a, b; cin >> a >> b; ll ans = 0; if (abs(a - b) > 10) { ll tmp = 0; ll a2 = a; ll b2 = b; if (a2 % 2 == 1) { ans ^= a2; a2++; } if (b2 % 2 == 0) { ans ^= b2; b2--; } tmp = (b2 + 1 - a2) / 2 % 2; // cout << a2 << ", " << b2 << endl; // cout << tmp << endl; ans ^= tmp; } else { for (ll i = a; i <= b; i++) { ans ^= i; } } cout << ans << endl; return 0; }
[ "assignment.change" ]
911,415
911,416
u895382169
cpp
p03104
#include <bits/stdc++.h> using namespace std; #define rep(i, s, n) for (int i = (s); i < (n); ++i) #define rem(i, s, n) for (int i = (s); i >= (n); --i) using ll = long long; int main() { ll a, b; cin >> a >> b; ll ans; if (a % 2 == 0) { if (b % 2 == 0) { if (((b - a) / 2) % 2 == 0) { ans = b; } else { ans = (1 ^ b); } } else { if (((b - a) / 2) % 2 == 0) { ans = 0; } else { ans = 1; } } } else { if (b % 2 == 1) { if (((b - a) / 2) % 2 == 0) { ans = a; } else { ans = (1 ^ a); } } else { if (((b - a) / 2) % 2 == 0) { ans = (a ^ b); } else { ans = (a ^ b ^ 1); } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, s, n) for (int i = (s); i < (n); ++i) #define rem(i, s, n) for (int i = (s); i >= (n); --i) using ll = long long; int main() { ll a, b; cin >> a >> b; ll ans; if (a % 2 == 0) { if (b % 2 == 0) { if (((b - a) / 2) % 2 == 0) { ans = b; } else { ans = (1 ^ b); } } else { if (((b - a) / 2) % 2 == 0) { ans = 1; } else { ans = 0; } } } else { if (b % 2 == 1) { if (((b - a) / 2) % 2 == 0) { ans = a; } else { ans = (1 ^ a); } } else { if (((b - a) / 2) % 2 == 0) { ans = (a ^ b); } else { ans = (a ^ b ^ 1); } } } cout << ans << endl; return 0; }
[ "literal.number.change", "assignment.value.change" ]
911,440
911,441
u526854325
cpp
p03104
#include <bits/stdc++.h> main() { long a, b, ans = 0; std::cin >> a >> b; if (b % 2 == 0) ans = ans ^ b; if (a % 2 == 1) ans = ans ^ (a - 1); ans = ((b + 1) / 2) % 2 ^ ans; ans = ((a + 1) / 2) % 2 ^ ans; std::cout << ans; }
#include <bits/stdc++.h> main() { long a, b, ans = 0; std::cin >> a >> b; if (b % 2 == 0) ans = ans ^ b; if (a % 2 == 1) ans = ans ^ (a - 1); ans = (((b + 1) / 2) % 2) ^ ans; ans = ((a / 2) % 2) ^ ans; std::cout << ans; }
[]
911,442
911,443
u499009346
cpp
p03104
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; int main() { ll A, B; cin >> A >> B; ll sumA = 0, sumB = 0; if (A % 2 == 0) { if ((A / 2) % 2 == 1) { sumA = 1; } else { sumA = 0; } } else if (A % 2 == 1) { if ((A / 2) % 2 == 1) { sumA = 1 ^ (A - 1); } else { sumA = 0 ^ (A - 1); } } if (B % 2 == 1) { if ((B / 2) % 2 == 1) { sumB = 1; } else { sumB = 0; } } else if (B % 2 == 0) { if ((B / 2) % 2 == 1) { sumB = 1 ^ B; } else { sumB = 0 ^ B; } } ll ans = sumA ^ sumB; // cout << sumA << endl; // cout << sumB << endl; cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; int main() { ll A, B; cin >> A >> B; ll sumA = 0, sumB = 0; if (A % 2 == 0) { if ((A / 2) % 2 == 1) { sumA = 1; } else { sumA = 0; } } else if (A % 2 == 1) { if ((A / 2) % 2 == 1) { sumA = 1 ^ (A - 1); } else { sumA = 0 ^ (A - 1); } } if (B % 2 == 1) { if ((B / 2) % 2 == 1) { sumB = 0; } else { sumB = 1; } } else if (B % 2 == 0) { if ((B / 2) % 2 == 1) { sumB = 1 ^ B; } else { sumB = 0 ^ B; } } ll ans = sumA ^ sumB; // cout << sumA << endl; // cout << sumB << endl; cout << ans << endl; }
[ "literal.number.change", "assignment.value.change" ]
911,450
911,451
u801083963
cpp
p03104
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; const int INF = 1001001001; #define rep(i, n) for (ll i = 0; i < (int)(n); i++) int main() { vector<ll> v(2); vector<ll> d(2); cin >> v[0] >> v[1]; if (v[0] > 0) v[0]--; // vector<ll>v(b+1); rep(i, 2) { ll c = v[i] % 4; ll now; if (c == 0) now = v[i]; if (c == 1) now = 1; if (c == 2) now = (v[i] ^ 1); d[i] = now; // cout<<now<<endl; } ll ans = d[1] ^ d[0]; cout << ans; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; const int INF = 1001001001; #define rep(i, n) for (ll i = 0; i < (int)(n); i++) int main() { vector<ll> v(2); vector<ll> d(2); cin >> v[0] >> v[1]; if (v[0] > 0) v[0]--; // vector<ll>v(b+1); rep(i, 2) { ll c = v[i] % 4; ll now = 0; if (c == 0) now = v[i]; if (c == 1) now = 1; if (c == 2) now = (v[i] ^ 1); d[i] = now; // cout<<now<<endl; } ll ans = d[1] ^ d[0]; cout << ans; }
[ "variable_declaration.value.change" ]
911,478
911,479
u289381123
cpp
p03104
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) using ll = long long; using P = pair<int, ll>; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll binary(ll bina) { ll ans = 0; for (ll i = 0; bina > 0; i++) { ans = ans + (bina % 2) * pow(10, i); bina = bina / 2; } return ans; } int main() { ll A, B; cin >> A >> B; ll C, D; bool a = false; bool b = false; if (A % 2 == 1) { //奇数 a = true; C = A + 1; } if (B % 2 == 0) { //偶数 b = true; D = B - 1; } ll ans; ll c; if (a && b) { c = (B - A - 1) / 2; if (c % 2 == 0) ans = A ^ B; else ans = A ^ 1 ^ B; } else if (a && !b) { c = (B - A) / 2; if (c % 2 == 0) ans = A + 0; else ans = A + 1; } else if (!a && b) { c = (B - A) / 2; if (c % 2 == 0) ans = B + 0; else ans = B + 1; } else { c = (B - A + 1) / 2; if (c % 2 == 0) ans = 0; else ans = 1; } cout << ans << endl; return 0; } // Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) using ll = long long; using P = pair<int, ll>; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll binary(ll bina) { ll ans = 0; for (ll i = 0; bina > 0; i++) { ans = ans + (bina % 2) * pow(10, i); bina = bina / 2; } return ans; } int main() { ll A, B; cin >> A >> B; ll C, D; bool a = false; bool b = false; if (A % 2 == 1) { //奇数 a = true; C = A + 1; } if (B % 2 == 0) { //偶数 b = true; D = B - 1; } ll ans; ll c; if (a && b) { c = (B - A - 1) / 2; if (c % 2 == 0) ans = A ^ B; else ans = A ^ 1 ^ B; } else if (a && !b) { c = (B - A) / 2; if (c % 2 == 0) ans = A + 0; else ans = A ^ 1; } else if (!a && b) { c = (B - A) / 2; if (c % 2 == 0) ans = B + 0; else ans = B ^ 1; } else { c = (B - A + 1) / 2; if (c % 2 == 0) ans = 0; else ans = 1; } cout << ans << endl; return 0; } // Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること
[ "assignment.value.change", "expression.operation.binary.change" ]
911,485
911,486
u717037783
cpp
p03104
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef pair<int, int> P; int main() { ll A, B; cin >> A >> B; ll ans; if (A % 2 == 0 && B % 2 == 0) { // A: even B:even if (((B - A) / 2) % 2 == 0) { ans = 0 ^ B; } else { ans = 1 ^ B; } } else if (A % 2 == 0 && B % 2 != 0) { // A:even B:odd if (((B - A + 1) / 2) % 2 == 0) { ans = 0; } else { ans = 1; } } else if (A % 2 != 0 && B % 2 == 0) { // A:off B:even if (((B - A - 1) / 2) % 2 == 0) { ans = A ^ B; } else { ans = A ^ 1 ^ B; } } else { // A, B:odd if (((B - A) / 2) % 2 == 0) { ans = A; } else { ans = A + 1; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef pair<int, int> P; int main() { ll A, B; cin >> A >> B; ll ans; if (A % 2 == 0 && B % 2 == 0) { // A: even B:even if (((B - A) / 2) % 2 == 0) { ans = 0 ^ B; } else { ans = 1 ^ B; } } else if (A % 2 == 0 && B % 2 != 0) { // A:even B:odd if (((B - A + 1) / 2) % 2 == 0) { ans = 0; } else { ans = 1; } } else if (A % 2 != 0 && B % 2 == 0) { // A:off B:even if (((B - A - 1) / 2) % 2 == 0) { ans = A ^ B; } else { ans = A ^ 1 ^ B; } } else { // A, B:odd if (((B - A) / 2) % 2 == 0) { ans = A; } else { ans = A ^ 1; } } cout << ans << endl; }
[ "assignment.value.change", "expression.operation.binary.change" ]
911,497
911,498
u872158847
cpp