Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
fix: Relaxed test constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
thirofoo committed Aug 1, 2024
1 parent a853b0e commit ccb4446
Show file tree
Hide file tree
Showing 47 changed files with 1,399,375 additions and 1,532,125 deletions.
19 changes: 10 additions & 9 deletions solitary-socks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,27 @@ Ambiguous
### 入力例 2

```txt
1000 9
9
2 1 2
1 1 2 1 1000
1 2 3 1 500
1 2 3 501 1000
1 2 3 501 1000
1 1 3 1 60
1 1 2 1 30
1 2 3 31 60
1 2 3 31 60
2 1 2
2 1 2
2 1 3
2 2 3
```

### 出力例 2

```txt
Ambiguous
500
500
1000
500
30
30
60
30
```

同じクエリが何度も出現する場合もあるので注意してください。
Expand Down
45 changes: 22 additions & 23 deletions solitary-socks/sol-cpp-ac/main.cc
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#include <bits/stdc++.h>
using namespace std;

const int bit_size = 3000;
using ll = long long;
struct weighted_dsu {
public:
weighted_dsu(): _n(0) {}
explicit weighted_dsu(int n): _n(n), parent_or_size(n, -1), diff_weight(n, 0) {}
explicit weighted_dsu(ll n): _n(n), parent_or_size(n, -1), diff_weight(n, 0) {}

ll merge(ll a, ll b, ll w) {
assert(0 <= a && a < _n);
assert(0 <= b && b < _n);

int merge(int a, int b, bitset<bit_size> w) {
w ^= weight(a);
w ^= weight(b);

int x = leader(a), y = leader(b);
ll x = leader(a), y = leader(b);
if(x == y) return x;
if(-parent_or_size[x] < -parent_or_size[y]) swap(x, y);

Expand All @@ -22,38 +25,41 @@ struct weighted_dsu {
return x;
}

bool same(int a, int b) {
bool same(ll a, ll b) {
assert(0 <= a && a < _n);
assert(0 <= b && b < _n);
return leader(a) == leader(b);
}

int leader(int a) {
ll leader(ll a) {
assert(0 <= a && a < _n);
if(parent_or_size[a] < 0) return a;
int r = leader(parent_or_size[a]);
ll r = leader(parent_or_size[a]);
diff_weight[a] ^= diff_weight[parent_or_size[a]];
return parent_or_size[a] = r;
}

bitset<bit_size> weight(int x) {
ll weight(ll x) {
leader(x); // 経路圧縮
return diff_weight[x];
}

bitset<bit_size> diff(int x, int y) {
ll diff(ll x, ll y) {
return weight(y) ^ weight(x);
}

private:
int _n;
vector<int> parent_or_size;
vector<bitset<bit_size>> diff_weight;
ll _n;
vector<ll> parent_or_size;
vector<ll> diff_weight;
};

int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);

int n, q;
cin >> n >> q;
int q;
cin >> q;
vector<int> comp;
vector<tuple<int, int, int, int, int>> query;
for(int i = 0; i < q; i++) {
Expand All @@ -71,19 +77,12 @@ int main() {
R = lower_bound(comp.begin(), comp.end(), R) - comp.begin();
}

vector<bitset<bit_size>> masks;
for(int i = 0; i <= bit_size; i++) {
bitset<bit_size> mask(0);
for(int j = 0; j < i; j++) mask.set(j);
masks.emplace_back(mask);
}

weighted_dsu uf(comp.size());
for(auto& [t, L, R, l, r]: query) {
if(t == 1) uf.merge(L, R, masks[l - 1] ^ masks[r]);
if(t == 1) uf.merge(L, R, (1LL << r) - (1LL << (l-1)));
else {
if(!uf.same(L, R)) cout << "Ambiguous\n";
else cout << uf.diff(L, R).count() << "\n";
else cout << __builtin_popcountll(uf.diff(L, R)) << '\n';
}
}

Expand Down
22 changes: 8 additions & 14 deletions solitary-socks/sol-cpp-partial1/main.cc
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include <bits/stdc++.h>
using namespace std;

const int bit_size = 3000;
using ll = long long;

int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);

int n, q;
cin >> n >> q;
int q;
cin >> q;
vector<int> comp;
vector<tuple<int, int, int, int, int>> query;
for(int i = 0; i < q; i++) {
Expand All @@ -25,13 +26,6 @@ int main() {
R = lower_bound(comp.begin(), comp.end(), R) - comp.begin();
}

vector<bitset<bit_size>> masks;
for(int i = 0; i <= bit_size; i++) {
bitset<bit_size> mask(0);
for(int j = 0; j < i; j++) mask.set(j);
masks.emplace_back(mask);
}

vector<vector<tuple<int, int, int>>> Graph(comp.size());
for(auto& [t, L, R, l, r]: query) {
if(t == 1) {
Expand All @@ -41,23 +35,23 @@ int main() {
else {
// 愚直に Graph 上を探索
vector<bool> visited(comp.size(), false);
queue<pair<int, bitset<bit_size>>> que;
que.push({L, masks[0]});
queue<pair<int, ll>> que;
que.push({L, 0});

bool arrived = false;
while(!que.empty()) {
auto [now, bit] = que.front();
que.pop();
if(now == R) {
cout << bit.count() << '\n';
cout << __builtin_popcountll(bit) << '\n';
arrived = true;
break;
}
if(visited[now]) continue;
visited[now] = true;
for(auto [to, nl, nr]: Graph[now]) {
if(visited[to]) continue;
que.push({to, bit ^ (masks[nl - 1] ^ masks[nr])});
que.push({to, bit ^ ((1LL << nr) - (1LL << (nl - 1)))});
}
}
if(!arrived) cout << "Ambiguous\n";
Expand Down
3 changes: 0 additions & 3 deletions solitary-socks/sol-cpp-tle-unused_bitset/SOLUTION

This file was deleted.

115 changes: 0 additions & 115 deletions solitary-socks/sol-cpp-tle-unused_bitset/main.cc

This file was deleted.

13 changes: 3 additions & 10 deletions solitary-socks/sol-pypy-ac/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ def main():
data = input().split()

index = 0
n = int(data[index])
q = int(data[index + 1])
index += 2
q = int(data[index])
index += 1

comp = []
query = []
Expand All @@ -66,25 +65,19 @@ def main():
if t == 1:
l = int(data[index])
r = int(data[index + 1])
l -= 1
r -= 1
index += 2
comp.extend([L, R])
query.append((t, L, R, l, r))

comp = sorted(set(comp))
comp_map = {v: i for i, v in enumerate(comp)}
masks = [[0] * n for _ in range(n)]
for i in range(n):
for j in range(i, n):
masks[i][j] = (1 << (j - i + 1)) - 1 << i

uf = WeightedDSU(len(comp))
for t, L, R, l, r in query:
L = comp_map[L]
R = comp_map[R]
if t == 1:
uf.merge(L, R, masks[l][r])
uf.merge(L, R, (1 << r) - (1 << (l - 1)))
else:
if uf.same(L, R):
print(uf.diff(L, R).bit_count())
Expand Down
14 changes: 3 additions & 11 deletions solitary-socks/sol-pypy-partial1/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ def main():
input = sys.stdin.read
data = input().split()

n = int(data[0])
q = int(data[1])
index = 2
q = int(data[0])
index = 1

comp = []
query = []
Expand All @@ -36,21 +35,14 @@ def main():
R = comp_map[R]
query[i] = (t, L, R, l, r)

masks = []
for i in range(n + 1):
mask = [0] * n
for j in range(i):
mask[j] = 1
masks.append(mask)

Graph = [[] for _ in range(len(comp))]
for t, L, R, l, r in query:
if t == 1:
Graph[L].append((R, l, r))
Graph[R].append((L, l, r))
else:
visited = [False] * len(comp)
que = deque([(L, [0] * n)])
que = deque([(L, [0] * 60)])

arrived = False
while que:
Expand Down
3 changes: 0 additions & 3 deletions solitary-socks/sol-pypy-tle-unused_bitset/SOLUTION

This file was deleted.

Loading

0 comments on commit ccb4446

Please sign in to comment.