版本比较
题解 P2371 【[国家集训队]墨墨的等式】
正文
增加 7 行删除 7 行
62 行未改动6364656667676869707110 行未改动8283848586868788899090919293949596979898991001001011021031041051061071061071081091101112 行未改动62 行未改动 head[u] = tot;}
inline void spfa(int s) { for (int i = 0; i < mn; ++i) dis[i] = INF + 1;//初始化 for (int i = 0; i < mn; ++i) dis[i] = INF + 1;//初始化 queue<int> q; dis[s] = 0;//满足模 mn 等于 0 的最小的 B 是 0 q.push(s); for (; !q.empty(); ) {10 行未改动 } }}
inline LL query(LL x) {//求出 0 ~ x 中符合条件的 B 的数量 inline LL query(LL x) {//求出 0 ~ x 中符合条件的 B 的数量 LL res = 0; for (int i = 0; i < mn; ++i) if (dis[i] <= x) res += (x - dis[i]) / mn + 1;//累加答案 res += (x - dis[i]) / mn + 1;//累加答案 return res;}
int main() { read(n), read(l), read(r); for (int x, i = 1; i <= n; ++i) { read(x); if (x) {//a[i] = 0 可以跳过,因为没有贡献 if (x) {//a[i] = 0 可以跳过,因为没有贡献 a[++m] = x; mn = min(mn, x);//求出最小且非 0 的 a[i] 作为 mn 的值 mn = min(mn, x);//求出最小且非 0 的 a[i] 作为 mn 的值 } } n = m; for (int i = 0; i < mn; ++i) for (int j = 1; j <= n; ++j) if (a[j] != mn)//自己向自己没必要连边 addEdge(i, (i + a[j]) % mn, a[j]);//连有向边 if (a[j] != mn)//自己向自己没必要连边 addEdge(i, (i + a[j]) % mn, a[j]);//连有向边 spfa(0);//从 0 开始 write(query(r) - query(l - 1)); putchar('\n'); return 0;2 行未改动