版本比较
小心失心疯
正文
增加 8 行删除 8 行
36 行未改动37383940414142434445454647484934 行未改动8485868788888990919293949596979798991001011021031041041051061071088 行未改动11711811912012112112212312412523 行未改动1491501511521531531541551561573 行未改动1611621631641651651661671681692 行未改动36 行未改动#endiftemplate<class T>constexpr T lowbit(T x){return x&-x;}template<class T>constexpr T lg(T x){return x?__lg(x):0;}template<class T>constexpr T ctz(T x){return x?__builtin_ctzll(x):0;}template<class T1,class T2>ostream&operator<<(ostream&out,const pair<T1,T2>&p) template<class T1,class T2>ostream&operator<<(ostream&out,const pair<T1,T2>&p){return out<<"("<<p.first<<", "<<p.second<<")";}template<class T1,class T2>istream&operator>>(istream&in,pair<T1,T2>&p){return in>>p.first>>p.second;}template<class T>ostream&operator<<(ostream&out,const vector<T>&v) template<class T>ostream&operator<<(ostream&out,const vector<T>&v){out<<"[";for(int i=0,n=v.size();i<n;++i<n?(out<<", "):out)out<<v[i];return out<<"]";}mt19937 rand32(seed());mt19937_64 rand64(seed());#undef assert34 行未改动//#define int long longconst int N = 1e5 + 5;
int n, a, b, g, h[N], d[N];void exgcd(int128 a, int128 b, int128& x, int128& y) void exgcd(int128 a, int128 b, int128& x, int128& y){b ? (exgcd(b, a % b, y, x), y -= a / b * x) : (x = 1, y = 0);}tuple<int128, int128, int128> info[N];int128 _abs(int128 x) {return x >= 0 ? x : -x;} // 不手写你会失心疯的
void _main() { cin >> n >> a >> b, g = gcd(a, b); for (int i = 1; i <= n; i++) { cin >> h[i]; if (h[i] % g) return cout << -1, void(); if (h[i] % g) return cout << -1, void(); h[i] /= g; } for (int i = 1; i <= n + 1; i++) d[i] = h[i] - h[i - 1]; n++, a /= g, b /= g; if (a < b) swap(a, b); int128 x0, y0; exgcd(a, b, x0, y0);
int128 cost = 0, cur = 0; auto work1 = [&]() -> void { for (int i = 1; i <= n; i++) { // x * a + y * b = -d[i]8 行未改动 }; work1(); int offset = -(cur / b), dir = offset < 0 ? -1 : 1; if (offset == 0) return cout << static_cast<u64>(cost / 2), void();
vector<pair<int128, int128>> vec; auto work2 = [&]() -> void { for (int i = 1; i <= n; i++) { auto [x, y, p] = info[i];23 行未改动 } } }; work2();
sort(vec.begin(), vec.end()); int128 res = cost, need = _abs(offset); for (auto [val, cnt] : vec) { int128 w = min(cnt, need);3 行未改动} signed main() { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr), cerr.tie(nullptr); cout << 'D'; return 0;
int t = 1; for (/*cin >> t*/; t--; ) _main(); return 0;}
2 行未改动