Skip to content

Commit 7ff6105

Browse files
Add files via upload
1 parent acf3e48 commit 7ff6105

File tree

4 files changed

+117
-0
lines changed

4 files changed

+117
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
for _ in range(int(input())):
2+
x = list(map(int, input().split()))
3+
print("Yes" if all([x[0] == y for y in x]) else "No")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
for _ in range(int(input())):
2+
n = int(input())
3+
x = list(map(int, input().split()))
4+
print(sum(x) - len(x) + 1)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#pragma GCC optimize("Ofast")
2+
#pragma GCC optimize("unroll-loops")
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
typedef long long ll;
7+
typedef vector<int> vi;
8+
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
9+
10+
11+
int main(){
12+
int tc;
13+
cin >> tc;
14+
while (tc--){
15+
int x;
16+
cin >> x;
17+
int total_length = 32 - __builtin_clz(x);
18+
int pc = __builtin_popcount(x);
19+
if (pc == 1 || pc == total_length) {
20+
cout << -1 << endl;
21+
continue;
22+
}
23+
24+
// negation and we change a zero to one
25+
int ans = 0;
26+
for (int i = 0; i < total_length; i++) {
27+
if (!(x & (1 << i))) {
28+
ans |= (1 << i);
29+
}
30+
}
31+
32+
for (int i = 0; i < total_length; i++) {
33+
if (!(ans & (1 << i))){
34+
ans |= (1 << i);
35+
break;
36+
}
37+
}
38+
39+
cout << ans << endl;
40+
assert((x + ans) > x^ans);
41+
assert((x ^ ans) + ans > x);
42+
assert((x ^ ans) + x > ans);
43+
}
44+
45+
return 0;
46+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#pragma GCC optimize("Ofast")
2+
#pragma GCC optimize("unroll-loops")
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
typedef long long ll;
7+
typedef vector<int> vi;
8+
#define fast_cin() \
9+
ios_base::sync_with_stdio(false); \
10+
cin.tie(NULL); \
11+
cout.tie(NULL);
12+
13+
ll isqrt(ll n) {
14+
ll hi = n < 1e8 ? n : 1e8;
15+
ll lo = 0;
16+
while (lo < hi) {
17+
ll mid = (hi + lo + 1) / 2;
18+
if (mid * mid <= n) {
19+
lo = mid;
20+
} else {
21+
hi = mid - 1;
22+
}
23+
}
24+
return lo;
25+
}
26+
27+
int main() {
28+
fast_cin();
29+
int tc;
30+
cin >> tc;
31+
32+
while (tc--) {
33+
unordered_map<ll, ll> cnt;
34+
ll n, m;
35+
cin >> n >> m;
36+
vector<ll> a(n);
37+
for (ll& x : a) {
38+
cin >> x;
39+
}
40+
vector<ll> r(n);
41+
for (ll& x : r) {
42+
cin >> x;
43+
}
44+
45+
for (int i = 0; i < n; i++) {
46+
ll center = a[i];
47+
ll rad = r[i];
48+
49+
for (ll x = center - rad; x <= center + rad; x++) {
50+
ll s = isqrt(rad * rad - (x - center) * (x - center));
51+
cnt[x] = max(cnt[x], s * 2 + 1);
52+
}
53+
}
54+
55+
ll ans = 0;
56+
for (auto& [k, v] : cnt) {
57+
ans += v;
58+
}
59+
60+
cout << ans << endl;
61+
}
62+
63+
return 0;
64+
}

0 commit comments

Comments
 (0)