int l, r, mx; for(int i = 0; i < vt.size(); ++i) { l = vt[i]; if(i != vt.size() - 1) r = vt[i + 1] - 1; else r = n; mp.clear(); mx = 0; for(int j = l; j <= r; ++j) mx = max(mx, ++mp[ar[j]]); ans += mx; } if(vt.size()) { for(int i = 1; i < vt[0]; ++i) if(ar[i] == 0) ++ans; } else { for(int i = 1; i <= n; ++i) if(ar[i] == 0) ++ans; } cout << ans << '\n'; }
return0; }
D. ConstructOR
题意: 给你a,b,d,让你找一个x,满足$a|x$能整除$d$,$b|x$能整除$d$,$(1<=a,b,d<=2^{30},0<=x<=2^{60})$。 分析: 假设$aa$是第一个大于$a|b$的2的n次幂,容易想到方程$aa\times x + a|b = d \times y$,解出一个正的x,答案就是$aa\times x + a|b$,方程无解,就是-1,(答案可以取到$2^{60}$,故可以考虑这样子)。 AC代码:
usingnamespace std; #define int long long #define endl '\n' #define io ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) typedeflonglong ll;
constint maxn = 2e5 + 5; int n, m, k, x; int aa, bb, dd; int t;
ll exgcd(ll a, ll b, ll &x, ll &y) { if(b == 0) { x = 1; y = 0; return a; } ll r = exgcd(b, a % b, x, y); ll t = x; x = y; y = t - a / b * y; return r; }
signedmain() { //io; cin >> t; int a, b, c, d; int x0, y0, x1, y1; int dx, dy; while(t--) { cin >> aa >> bb >> dd; c = (aa|bb); int bas = 1; for(int i = 1; i <= 60; ++i) { bas = bas * 2ll; if(bas > c) { a = bas; break; } } c = -c; b = -dd;