voidadd(int p, int v); intquery(int p); } usingnamespace BIT;
voidCDQ(int l, int r){ if (l == r) return; int m = (l + r) >> 1; CDQ(l, m), CDQ(m + 1, r); std::sort(s + l, s + m + 1, cmp2); std::sort(s + m + 1, s + r + 1, cmp2); int i = l; for (int j = m + 1; j <= r; ++j) { for (; s[i].b <= s[j].b && i <= m; ++i) add(s[i].c, s[i].w); s[j].cnt += query(s[j].c); } for (int j = l; j < i; ++j) add(s[j].c, -s[j].w); }
intmain(){ cin >> M >> K; for (int i = 1; i <= M; ++i) cin >> z[i].a >> z[i].b >> z[i].c; std::sort(z + 1, z + M + 1, cmp1); for (int i = 1, j = 1; i <= M; ++i, ++j) if (z[i].a != z[i + 1].a || z[i].b != z[i + 1].b || z[i].c != z[i + 1].c) s[++N] = z[i], s[N].w = j, j = 0;
CDQ(1, N); for (int i = 1; i <= N; ++i) ans[s[i].cnt + s[i].w - 1] += s[i].w;
for (int i = 0; i < M; ++i) cout << ans[i] << '\n'; cout.flush(); return0; }
intmaxbit(int *z, int N){ int ans = 0, mx = *std::max_element(z + 1, z + N + 1); do ++ans; while (mx /= 10); return ans; }
voidrsort(int* z, int N){ int d = maxbit(z, N); for (int r = 1, n; d; --d, r *= 10) { n = 0; memset(l, 0, sizeof(int) * 10); for (int i = 1, t; i <= N; ++i) { t = z[i] / r % 10; c[t][++l[t]] = z[i]; } for (int i = 0; i < 10; ++i) for (int j = 1; j <= l[i]; ++j) z[++n] = c[i][j], c[i][j] = 0; } }
inline ll Mul(ll a, ll b, ll m){ a %= m, b %= m; if (m <= 1000000000) return a * b % m; if (m <= 1000000000000) return (((a * (b >> 20) % m) << 20) + a * (b & ((1 << 20) - 1))) % m; ll d = floor(a * (ldb)b / m + 0.5); ll ans = (a * b - d * m) % m; if (ans < 0) ans += m; return0; }
std::bitset<3003> vis; int N, M, tot, cnt[3003], head[3003], dis[3003], d[3003];
structEdge { int nxt, to, w; } e[6003];
voidaddEdge(int u, int v, int w); boolspfa(); voiddijkstra(int s);
intmain(){ cin >> N >> M; for (int u, v, w; M; --M) { cin >> u >> v >> w; addEdge(u, v, w); } if (!spfa()) returnputs("-1"), 0; for (int i, u = 1; u <= N; ++u) for (i = head[u]; i; i = e[i].nxt) e[i].w += d[u] - d[e[i].to]; for (int i = 1; i <= N; ++i) { dijkstra(i); ll ans = 0; for (int j = 1; j <= N; ++j) if (dis[j] == inf) ans += j * 1000000000ll; else ans += 1ll * j * (dis[j] - d[i] + d[j]); cout << ans << '\n'; } cout.flush(); return0; }
voiddfs1(int u){ for (int i = 1; i <= 18; ++i) fa[u][i] = fa[fa[u][i - 1]][i - 1]; mxd[u] = dep[u] = dep[fa[u][0]] + 1; for (int i = head[u], v; i; i = e[i].nxt) { dfs1(v = e[i].to); if (dmax(mxd[u], mxd[v])) son[u] = v; } }
voiddfs2(int u, int t, int up){ top[u] = t; dfn[u] = ++dft, D[dft] = u, U[dft] = up; if (!son[u]) return; dfs2(son[u], t, fa[up][0]); for (int i = head[u], v; i; i = e[i].nxt) if ((v = e[i].to) != son[u]) dfs2(v, v, v); }
intquery(int u, int k){ if (!k) return u; u = fa[u][lg[k]]; k -= (1 << lg[k]) + dep[u] - dep[top[u]]; u = top[u]; return k >= 0 ? U[dfn[u] + k] : D[dfn[u] - k]; }
ll EXCRT(){ ll M = 1, ans = 0, a, b, c, x, y, g; for (int i = 1; i <= N; ++i) { a = M, b = m[i], c = Mod(r[i] - ans, b); exgcd(a, b, g, x, y); // if (c % gcd) return -1; ans += Mul(x, c / g, b / g) * M; ans = Mod(ans, M *= b / g); } returnMod(ans, M); }
intmain(){ cin >> N; for (int i = 1; i <= N; ++i) cin >> m[i] >> r[i]; printf("%lld", EXCRT()); return0; }
ll solve(int l, int r){ ll ans = 0; for (int i = l; i <= r; ++i) ans = std::max(ans, 1ll * ++c_[z[i]] * z_[z[i]]); for (int i = l; i <= r; ++i) --c_[z[i]]; return ans; }
voidprocess(){ for (int i = 1, j = 1, l, r; i <= num && j <= M; ++i) { memset(c + 1, 0, sizeof(int) * N); r = R[i]; now = 0; for (; bel[q[j].l] == i; ++j) { if (q[j].r < r) { ans[q[j].id] = solve(q[j].l, q[j].r); continue; } l = R[i] + 1; while (r < q[j].r) add(++r); ll t = now; while (l > q[j].l) add(--l); ans[q[j].id] = now, now = t; while (l <= R[i]) --c[z[l++]]; } } }
intsolve(int l, int r){ int ans = 0; for (int i = l; i <= r; ++i) { dmax(mx_[z[i]], i); dmin(mn_[z[i]], i); dmax(ans, mx_[z[i]] - mn_[z[i]]); } for (int i = l; i <= r; ++i) mx_[z[i]] = 0, mn_[z[i]] = inf; return ans; }
voidprocess(){ memset(mn_ + 1, 0x3f, sizeof(int) * N); for (int i = 1, j = 1, t, l, r; i <= num && j <= M; ++i) { memset(mx + 1, 0, sizeof(int) * N); memset(mn + 1, 0x3f, sizeof(int) * N); r = R[i]; now = 0; for (; bel[q[j].l] == i; ++j) { if (q[j].r < r) { ans[q[j].id] = solve(q[j].l, q[j].r); continue; } l = R[i] + 1; while (r < q[j].r) addR(++r); t = now; while (l > q[j].l) addL(--l); ans[q[j].id] = now, now = t; while (l <= R[i]) delL(l++); } } }