Skip to content

Commit 60ffd08

Browse files
committed
🎨
1 parent c32b0ab commit 60ffd08

File tree

4 files changed

+149
-0
lines changed

4 files changed

+149
-0
lines changed

‎atcoder/ARC/arc171/a.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import math
2+
3+
t = int(input())
4+
5+
def solve(n, a, b):
6+
flag = True
7+
if a > n:
8+
flag = False
9+
n -= a
10+
if b > n * math.ceil(n / 2):
11+
flag = False
12+
if flag:
13+
return "Yes"
14+
else:
15+
return "No"
16+
17+
ans = []
18+
19+
for _ in range(t):
20+
n, a, b = map(int, input().split())
21+
ans.append(solve(n, a, b))
22+
23+
print(*ans, sep="\n")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from collections import defaultdict
2+
3+
n = int(input())
4+
a = [int(input()) for _ in range(n)]
5+
6+
counter = defaultdict(int)
7+
for ai in a:
8+
counter[ai] += 1
9+
10+
ans = 0
11+
for i in range(n):
12+
for j in range(i, n):
13+
aij = a[i] * a[j]
14+
if aij in counter:
15+
if i == j:
16+
ans += counter[aij]
17+
else:
18+
ans += counter[aij] * 2
19+
print(ans)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define endl "\n"
4+
using ll = long long;
5+
using P = pair<ll, ll>;
6+
7+
const ll infll = (1LL << 62) - 1;
8+
const int inf = (1 << 30) - 1;
9+
10+
struct IoSetup {
11+
IoSetup() {
12+
cin.tie(nullptr);
13+
ios::sync_with_stdio(false);
14+
cout << fixed << setprecision(10);
15+
cerr << fixed << setprecision(10);
16+
}
17+
} iosetup;
18+
19+
template< typename T1, typename T2 >
20+
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
21+
22+
template< typename T1, typename T2 >
23+
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
24+
25+
void fail() {
26+
cout << -1 << endl;
27+
exit(0);
28+
}
29+
30+
int modulo(string s, int mod) {
31+
int res = 0;
32+
for (int i = 0; i < s.size(); i++) {
33+
res = (res * 10 + s[i] - '0') % mod;
34+
}
35+
return res;
36+
}
37+
38+
39+
int main(){
40+
cin >> n;
41+
vector<int> a(n);
42+
for (int i = 0; i < n; i++) cin >> a[i];
43+
44+
int mod = 10000007;
45+
vector<int> mod_a(n);
46+
std::map<int, int> mp;
47+
for (int i = 0; i < n; i++) {
48+
int a_mod = a[i] % mod;
49+
mod_a[i] = a_mod;
50+
mp[a_mod]++;
51+
}
52+
53+
int ans = 0;
54+
for (int i = 0; i < n; i++){
55+
for(int j = 0; j < n; j++){
56+
int mod_aij = (mod_a[i] * mod_a[j]) % mod;
57+
ans += mp[mod_aij];
58+
}
59+
}
60+
count << ans << endl;
61+
}

‎atcoder/abc/abc301-400/abc339/g.py

+46
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
from bisect import bisect
2+
from heapq import merge
3+
4+
class MergeSortTree:
5+
def __init__(self, N, A):
6+
self.tree_size = 2**(N-1).bit_length()
7+
self.tree = [None]*(2*self.tree_size)
8+
for i, a in enumerate(A):
9+
self.tree[self.tree_size-1+i] = [a]
10+
for i in range(N, self.tree_size):
11+
self.tree[self.tree_size-1+i] = []
12+
for i in range(self.tree_size-2, -1, -1):
13+
*self.tree[i], = merge(self.tree[2*i+1], self.tree[2*i+2])
14+
15+
# count elements A_i s.t. A_i <= k for i in [l, r)
16+
def query1(self, l, r, k):
17+
L = l + self.tree_size
18+
R = r + self.tree_size
19+
s = 0
20+
while L < R:
21+
if R & 1:
22+
R -= 1
23+
s += bisect(self.tree[R-1], k-1)
24+
if L & 1:
25+
s += bisect(self.tree[L-1], k-1)
26+
L += 1
27+
L >>= 1; R >>= 1
28+
return s
29+
30+
# count elements A_i s.t. a <= A_i < b for i in [l, r)
31+
def query(self, l, r, a, b):
32+
L = l + self.tree_size
33+
R = r + self.tree_size
34+
s = 0
35+
while L < R:
36+
if R & 1:
37+
R -= 1
38+
s += bisect(self.tree[R-1], b-1) - bisect(self.tree[R-1], a-1)
39+
if L & 1:
40+
s += bisect(self.tree[L-1], b-1) - bisect(self.tree[L-1], a-1)
41+
L += 1
42+
L >>= 1; R >>= 1
43+
return s
44+
145
n = int(input())
246
a = list(map(int, input().split()))
347
q = int(input())
@@ -12,6 +56,8 @@ def decode(alpha, beta, gamma, pre_b):
1256
x = gamma ^ pre_b
1357
return l, r, x
1458

59+
60+
1561
ans = []
1662
pre_b = 0
1763
for query in queries:

0 commit comments

Comments
 (0)