File tree Expand file tree Collapse file tree 6 files changed +236
-0
lines changed
Expand file tree Collapse file tree 6 files changed +236
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+
3+ void solve () {
4+ int a, b, c;
5+ std::cin >> a >> b >> c;
6+
7+ if (a == b || b == c || a == c) {
8+ std::cout << " Yes\n " ;
9+ } else {
10+ std::cout << " No\n " ;
11+ }
12+ }
13+
14+ int main () {
15+ std::ios::sync_with_stdio (false );
16+ std::cin.tie (nullptr );
17+
18+ solve ();
19+ }
Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+
3+ void solve () {
4+ int n, m, k;
5+ std::cin >> n >> m >> k;
6+
7+ std::vector<int > cnt (n + 1 );
8+ while (k--) {
9+ int a, b;
10+ std::cin >> a >> b;
11+ cnt[a] += 1 ;
12+ if (cnt[a] == m) {
13+ std::cout << a << " " ;
14+ }
15+ }
16+ }
17+
18+ int main () {
19+ std::ios::sync_with_stdio (false );
20+ std::cin.tie (nullptr );
21+
22+ solve ();
23+ }
Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+
3+ void solve () {
4+ int n;
5+ std::cin >> n;
6+
7+ std::vector<uint8_t > vis (n + 1 );
8+ std::vector<int > layer;
9+
10+ std::vector<std::vector<int >> adj (n + 1 );
11+ for (int i = 1 ; i <= n; ++i) {
12+ int a, b;
13+ std::cin >> a >> b;
14+
15+ if (a == 0 ) {
16+ vis[i] = true ;
17+ layer.push_back (i);
18+ } else {
19+ adj[a].push_back (i);
20+ adj[b].push_back (i);
21+ }
22+ }
23+
24+ while (!layer.empty ()) {
25+ std::vector<int > next_layer;
26+ for (int x : layer) {
27+ for (int to : adj[x]) {
28+ if (!vis[to]) {
29+ vis[to] = true ;
30+ next_layer.push_back (to);
31+ }
32+ }
33+ }
34+ std::swap (layer, next_layer);
35+ }
36+
37+ std::cout << std::count (vis.begin (), vis.end (), true ) << ' \n ' ;
38+ }
39+
40+ int main () {
41+ std::ios::sync_with_stdio (false );
42+ std::cin.tie (nullptr );
43+
44+ solve ();
45+ }
Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+
3+ void solve () {
4+ int h, w;
5+ std::cin >> h >> w;
6+
7+ std::vector<int > a (h);
8+ for (int i = 0 ; i < h; ++i) {
9+ std::string str;
10+ std::cin >> str;
11+ for (int j = 0 ; j < w; ++j) {
12+ if (str[j] == ' #' ) {
13+ a[i] |= 1 << j;
14+ }
15+ }
16+ }
17+
18+ std::vector<int > dp (1 << w);
19+ for (int S = 0 ; S < (1 << w); ++S) {
20+ dp[S] = __builtin_popcount (S ^ a[0 ]);
21+ }
22+
23+ auto check = [w](int S, int T) -> bool {
24+ for (int i = 0 ; i + 1 < w; ++i) {
25+ if (((S >> i) & 3 ) == 3 && ((T >> i) & 3 ) == 3 ) {
26+ return false ;
27+ }
28+ }
29+ return true ;
30+ };
31+
32+ for (int i = 1 ; i < h; ++i) {
33+ std::vector<int > next_dp (1 << w);
34+ for (int S = 0 ; S < (1 << w); ++S) {
35+ int min = dp[0 ];
36+ for (int T = 0 ; T < (1 << w); ++T) {
37+ if (dp[T] < min && check (S, T)) {
38+ min = dp[T];
39+ }
40+ }
41+ next_dp[S] = min + __builtin_popcount (S ^ a[i]);
42+ }
43+ dp = std::move (next_dp);
44+ }
45+
46+ std::cout << std::ranges::min (dp) << ' \n ' ;
47+ }
48+
49+ int main () {
50+ std::ios::sync_with_stdio (false );
51+ std::cin.tie (nullptr );
52+
53+ int t;
54+ std::cin >> t;
55+
56+ while (t--) solve ();
57+ }
Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+
3+ using fp = long double ;
4+ using i64 = int64_t ;
5+
6+ void solve () {
7+ int n, k, x;
8+ std::cin >> n >> k >> x;
9+
10+ std::vector<int > a (n);
11+ for (int &i : a) std::cin >> i;
12+
13+ auto check = [&](fp v) -> bool {
14+ i64 c = 0 ;
15+ int g = 0 ;
16+ for (int i : a) {
17+ if (i >= v) {
18+ c += (1LL << (63 - __builtin_clzll (i / v)));
19+ g += 1 ;
20+ }
21+ }
22+
23+ if (k <= c - g) return g + k >= x;
24+ return c - (k - (c - g)) >= x;
25+ };
26+
27+ fp l = 0 , r = std::ranges::max (a);
28+ while (r - l > 1e-10 ) {
29+ fp mid = (l + r) / 2 ;
30+ if (check (mid)) l = mid;
31+ else r = mid;
32+ }
33+
34+ std::cout << l << ' \n ' ;
35+ }
36+
37+ int main () {
38+ std::ios::sync_with_stdio (false );
39+ std::cin.tie (nullptr );
40+
41+ std::cout << std::fixed << std::setprecision (12 );
42+
43+ int t;
44+ std::cin >> t;
45+
46+ while (t--) solve ();
47+ }
Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+
3+ using u64 = uint64_t ;
4+ std::mt19937_64 rng (std::random_device{}());
5+
6+ void solve () {
7+ int n, q;
8+ std::cin >> n >> q;
9+
10+ std::vector<u64 > tr (n + 1 );
11+ auto update = [&](int x, u64 k) {
12+ for (; x <= n; x += x & -x) tr[x] ^= k;
13+ };
14+ auto query = [&](int x) {
15+ u64 res = 0 ;
16+ for (; x; x -= x & -x) res ^= tr[x];
17+ return res;
18+ };
19+
20+ while (q--) {
21+ int a, b;
22+ std::cin >> a >> b;
23+
24+ if (a > b) {
25+ std::swap (a, b);
26+ }
27+
28+ if (query (a) != query (b)) {
29+ std::cout << " No\n " ;
30+ continue ;
31+ }
32+
33+ std::cout << " Yes\n " ;
34+ const u64 h = rng ();
35+ update (a, h);
36+ update (b, h);
37+ }
38+ }
39+
40+ int main () {
41+ std::ios::sync_with_stdio (false );
42+ std::cin.tie (nullptr );
43+
44+ solve ();
45+ }
You can’t perform that action at this time.
0 commit comments