Search is not available for this dataset
name
stringlengths
2
88
description
stringlengths
31
8.62k
public_tests
dict
private_tests
dict
solution_type
stringclasses
2 values
programming_language
stringclasses
5 values
solution
stringlengths
1
983k
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; ifstream fin("input.txt"); ofstream fout("output.txt"); long long fast_exp(long long base, long long exp) { long long res = 1; while (exp > 0) { if (exp % 2 == 1) res = (res * base) % 1000000007; base = (base * base) % 1000000007; exp /= 2; } return res % 1000000007; } int palindromecheck(string s) { int n = s.size(); for (int i = 0; i < n / 2; ++i) { if (s[i] != s[n - i - 1]) { return 0; } } return 1; } int gcd(int a, int b) { while (a && b) a > b ? a %= b : b %= a; return a + b; } int val(char c) { if (c >= '0' && c <= '9') return (int)c - '0'; else return (int)c - 'A' + 10; } long long pows(int a, int b) { long long res = 1; for (int i = 0; i < b; ++i) { res *= a; } return res; } long long logx(long long base, long long num) { int cnt = 0; while (num != 1) { num /= base; ++cnt; } return cnt; } long long divisibles(long long a, long long b, long long m) { if (a % m == 0) return (b / m) - (a / m) + 1; else return (b / m) - (a / m); } string bitstring(int n, int size) { string s; while (n) { s += (n % 2) + '0'; n /= 2; } while (s.size() < size) { s += '0'; } reverse(s.begin(), s.end()); return s; } vector<int> root(200001, 0); vector<int> size(200001, 1); int find(int x) { while (x != root[x]) x = root[x]; return x; } bool same(int a, int b) { return find(a) == find(b); } void unite(int a, int b) { a = find(a); b = find(b); if (size[a] < size[b]) swap(a, b); size[a] += size[b]; root[b] = a; } vector<int> vis(200001, 0); vector<int> adj[200001]; int main() { std::ios::sync_with_stdio(false); int t; cin >> t; while (t--) { int n; long long l, r; cin >> n >> l >> r; vector<long long> vec(n + 1); long long sum = 0; int j = 1; for (int i = n; i >= 1; --i) { sum += (i - 1) * 2; vec[j] = sum; if (i == 1) ++vec[j]; ++j; } long long idxl = lower_bound(vec.begin(), vec.end(), l) - vec.begin(); long long idxr = lower_bound(vec.begin(), vec.end(), r) - vec.begin(); if (vec[idxl] > l && idxl > 1) --idxl; vector<pair<long long, long long>> ans; int temp = vec[idxl]; if (idxl == 1) temp = 1; long long start; if (idxl != 1) start = vec[idxl - 1] + 1; for (int i = idxl; i <= idxr; ++i) { for (int j = i + 1; j <= n; ++j) { ans.push_back(make_pair(i, start++)); ans.push_back(make_pair(j, start++)); } if (i + 1 > n) { ans.push_back(make_pair(1, start)); } } long long begin; if (idxl == 1) { begin = l - 1; } else { for (int i = 0; i < ans.size(); ++i) { if (ans[i].second == l) { begin = i; break; } } } for (int i = begin; i <= begin + (r - l); ++i) cout << ans[i].first << " "; cout << "\n"; } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n; long long l, r; long long i; cin >> n >> l >> r; long long temp = l; long long b = 1; while (temp > 2 * (n - b) && b < n) { temp = temp - 2 * (n - b); b++; } for (i = l; i <= r && i < n * (n - 1) + 1; i++) { if (temp % 2 == 1) { printf("%I64d ", b); temp++; } else { printf("%I64d ", temp / 2 + b); if (temp / 2 + b == n) { temp = 1; b++; } else temp++; } } if (r == n * (n - 1) + 1) printf("1\n"); else printf("\n"); } return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { long long t, i, n, cnt, od, l, r, ev, g; cin >> t; while (t--) { cin >> n >> l >> r; g = 0; if (r == (n * (n - 1)) + 1) { g = 500; } i = 0; while (i <= n - 1) { if (2 * n * (i) - (i) * (i + 1) < l) { i++; } else { i--; break; } } cnt = 2 * n * i - (i) * (i + 1) + 1; od = i + 1; ev = i + 2; if (g) { r--; } while (cnt <= r) { if (cnt >= l) { if (cnt % 2 == 0) { cout << ev << " "; ev++; } else { cout << od << " "; } cnt++; } else { if (cnt % 2 == 0) { ev++; } else { ; } cnt++; } if (ev > n) { od++; ev = od + 1; } } if (g == 500) { cout << 1 << " "; } cout << "\n"; } return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int mods = 998244353; const int maxn = 1e5 + 10; const int N = 1e5 + 10; const int E = 2e5 + 10; long long n, l, r; long long k[maxn]; vector<int> ans; int main() { int T; cin >> T; while (T--) { cin >> n >> l >> r; k[1] = 1; for (int i = 2; i <= (n); ++i) { k[i] = k[i - 1] + 2 * (n - i + 1); } long long bo = n; for (int i = 1; i <= (n); ++i) { if (k[i] > l) { bo = i - 1; break; } } if (bo >= n) { printf("1\n"); continue; } long long pc = k[bo]; long long tot = 1; long long tmp; ans.clear(); while (pc <= r) { if (bo == n) { ans.push_back(1); break; } if (pc % 2 == 1) tmp = bo; else { tmp = bo + tot; tot++; } if (pc >= l) ans.push_back(tmp); pc++; if (tmp == n) { bo++; tot = 1; } } for (int i = 0; i <= (ans.size() - 1); ++i) { cout << ans[i] << " "; } cout << endl; } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; const int LM = 3e5 + 4; ll N; ll L, R; ll part[LM]; int main() { int T; scanf("%d", &T); while (T--) { scanf("%lld%lld%lld", &N, &L, &R); bool e = 0; if (R == N * (N - 1) + 1) { e = 1; R--; } for (int i = 1; i <= N - 1; i++) part[i] = part[i - 1] + (N - i) * 2; for (int i = 1; i <= N; i++) { if (L <= part[i] && R > part[i - 1]) { int v, last = i; for (int j = 1; j <= (N - i) * 2; j++) { if (j & 1) v = i; else v = ++last; if (L <= part[i - 1] + j && part[i - 1] + j <= R) printf("%d ", v); } } } if (e) printf("1 "); puts(""); } return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7, MAX = 1e5 + 5; long long powN(long long a, long long p) { if (p == 0) return 1; long long z = powN(a, p / 2); z = (z * z) % MOD; if (p % 2) z = (z * a) % MOD; return z; } vector<bool> is_prime(MAX + 1, true); void Sieve() { is_prime[0] = is_prime[1] = false; int i, j; for (i = 2; i * i <= MAX; i++) { if (is_prime[i]) { for (j = i * i; j <= MAX; j += i) { is_prime[j] = false; } } } } int main() { int t; cin >> t; while (t--) { long long n; long long l, r; cin >> n >> l >> r; long long st = n - 1; for (long long k = 1; k <= n; k++) { if ((n * 2 - k - 1) * k >= l) { st = k - 1; break; } } long long ex = (2 * n - st - 1) * (st); l -= ex; r -= ex; st++; vector<int> V = {0}; long long some = st + 1; long long tot = 0; for (int i = 1; i <= r; i++) { if (st == n) { V.push_back(1); break; } if (i % 2) V.push_back(st); else { V.push_back(some); some++; } if (i == tot + 2 * (n - st)) { tot += 2 * (n - st); st++; some = st + 1; } } for (int i = l; i <= r; i++) { printf("%d ", V[i]); } cout << endl; } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
CORRECT
java
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.FileReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); DMinimumEulerCycle solver = new DMinimumEulerCycle(); solver.solve(1, in, out); out.close(); } static class DMinimumEulerCycle { public void solve(int testNumber, Scanner sc, PrintWriter pw) { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); long a = sc.nextLong(); long b = sc.nextLong(); long[] arr = new long[n]; arr[0] = 2 * n - 2; for (int i = 1; i < n - 1; i++) arr[i] = arr[i - 1] + 2 * (n - i - 1); arr[n - 1] = arr[n - 2] + 1; int in = 0; int la = 0; int l = 0; int h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] >= a) { in = mid; h = mid - 1; } else { l = mid + 1; } } l = 0; h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] >= b) { la = mid; h = mid - 1; } else { l = mid + 1; } } for (int i = in; i <= la; i++) { int[] tmp = new int[2 * (n - i) - 2]; int idx = 0; if (i == n - 1) pw.print(1); else { for (int j = i + 2; j <= n; j++) { tmp[idx] = i + 1; if (idx + 1 < tmp.length) tmp[idx + 1] = j; idx += 2; } if (i == in) { if (i == la) { int s = (int) (a - (i == 0 ? 0 : arr[i - 1]) - 1); int e = (int) (b - (i == 0 ? 0 : arr[i - 1])); for (int j = s; j < e; j++) pw.print(tmp[j] + " "); } else { int s = (int) (a - (i == 0 ? 0 : arr[i - 1]) - 1); for (int j = s; j < tmp.length; j++) pw.print(tmp[j] + " "); } } else if (i == la) { int e = (int) (b - (i == 0 ? 0 : arr[i - 1])); for (int j = 0; j < e; j++) pw.print(tmp[j] + " "); } else { for (int j = 0; j < tmp.length; j++) pw.print(tmp[j] + " "); } } } pw.println(); } pw.flush(); } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(FileReader r) { br = new BufferedReader(r); } public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
CORRECT
java
//package com.prituladima.codeforce.contest1334; import java.io.*; import java.util.*; import java.util.function.Predicate; import static java.util.Arrays.stream; import static java.util.stream.IntStream.range; /** * Don't confuse variables in inner cycles. Don't call variable like (i j k g). Delegate methods. * -Xmx64m maximum heap size allocation * 90% errors is copy-paste, wrong indexes and TOO MUCH variables */ public class SolutionD { private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null; private static final boolean MULTI_TEST = true; private static final int BITS = 31; private static final int MODULO = (int) 1e9 + 7; private static final int INF = (int) 1e7 + 7; private static final Random rand = new Random(1278367); private static final String yes = "YES", no = "NO"; private static final int MAXN = 2 * (int) 10e5 + 10; private boolean[] used = new boolean[MAXN]; private void solveAll() { int t = MULTI_TEST ? nextInt() : 1; while (t-- > 0) { solve(); } } private long pathLen(long n) { return n * (n - 1) + 1; } private long sum(long n, long k) { return n * k - k * (k + 1) / 2; } private void solve() { long n = nextInt(); long L = nextLong(); long R = nextLong(); boolean tillEnd = false; if (R == pathLen(n)) { R--; tillEnd = true; } long curPointer = 1; long lev = 1; for (; curPointer + 2*(n - lev) < L; lev++) { curPointer += 2*(n - lev); } // lev = upperBound(); // debug("curPointer = " + curPointer); // debug("lev = " + lev); boolean trigger = true; outer: for (; lev < n; lev++) { for (long lev2 = lev + 1; lev2 <= n; curPointer++) { // if (curFrom == L && curFrom + 1 == R) { // print(lev); // print(' '); // print(lev2); // print(' '); // // } if (curPointer < L) { if (trigger) { // print(lev); // printSpace(); } else { // print(lev2); // printSpace(); lev2++; } trigger = !trigger; } else if (R < curPointer) { break outer; } else { if (trigger) { print(lev); printSpace(); } else { print(lev2); printSpace(); lev2++; } trigger = !trigger; } } } if (tillEnd) { print(1); } println(); // } // //1. /** * n vertexes * n - 1 * n - 2 * n - 3 * * r - l + 1; * 1 2 * 1 3 * 2 3 * 1 * */ // long k; // if ((L + 1) / 2 <= n - 1) { // k = 0; // } else { // long lowK = 0, highK = n; // while (highK - lowK > 1) { // long mid = lowK + (highK - lowK) / 2; // long sum = n * mid - mid * (mid + 1) / 2; // if (sum < (L + 1) / 2) {//row number // lowK = mid; // } else { // highK = mid; // } // } // k = lowK; // } // debug("k = " + k); // long P = n * k - k * (k + 1) / 2 + 1; // long diff = (L + 1) / 2 - P; // if (L % 2 == 0) { // print((k + 2 + diff) + " "); // L++; // diff++; // } // boolean oneMore = false; // boolean last = false; // if (R == n * (n - 1) + 1) { // last = true; // R--; // } else if (R % 2 == 1) { // oneMore = true; // R--; // } // while (L / 2 <= R / 2) { // print((k + 1) + " " + (k + 2 + diff) + " "); // if ((k + 2 + diff) == n) { // k++; // diff = 0; // } // L++; // L++; // diff++; // } // // // if (last) { // println(1); // } else if (oneMore) { // println((k + 1)); // } else { // println(); // } } private boolean inRange(int val, int fromInclusive, int toExclusive) { return fromInclusive <= val && val < toExclusive; } private int nextRandInt(int minInclusive, int maxExclusive) { return rand.nextInt(maxExclusive - minInclusive) + minInclusive; } /** * Graph traverses */ private void dfs(int from, boolean[] used, Graph graph) { used[from] = true; for (int to : graph.get(from)) { if (!used[to]) { dfs(to, used, graph); } } } private void dfsTree(int from, int parent, Tree tree) { for (int to : tree.get(from)) { if (parent != to) { dfsTree(to, from, tree); } } } /** * Binary searches. */ private long upperBound(long inclusiveLeft, long exclusiveRight, Predicate<Long> predicate) { while (exclusiveRight - inclusiveLeft > 1) { long middle = inclusiveLeft + (exclusiveRight - inclusiveLeft) / 2; if (predicate.test(middle)) { inclusiveLeft = middle; } else { exclusiveRight = middle; } } return inclusiveLeft; } private int lowerBound(int exclusiveLeft, int inclusiveRight, Predicate<Integer> predicate) { while (inclusiveRight - exclusiveLeft > 1) { int middle = exclusiveLeft + (inclusiveRight - exclusiveLeft) / 2; if (predicate.test(middle)) { inclusiveRight = middle; } else { exclusiveLeft = middle; } } return inclusiveRight; } private int minAns(int lev) { char[] tabs = new char[lev]; Arrays.fill(tabs, '\t'); debug(new StringBuilder().append(tabs).append(" ").append(lev)); return 0; } public static void main(String[] args) { new SolutionD().run(); } private BufferedReader reader; private PrintWriter writer; private StringTokenizer tokenizer; private void run() { try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)))) { this.writer = writer; this.reader = reader; solveAll(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } /** * Base types: Strings, int, long, double */ private String nextToken() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } private int nextInt() { return Integer.parseInt(nextToken()); } private long nextLong() { return Long.parseLong(nextToken()); } private double nextDouble() { return Double.parseDouble(nextToken()); } /** * Primitives 1D arrays: char, int, long, double */ private char[] nextCharArray() { return nextToken().toCharArray(); } private int[] nextIntArray(int size) { return stream(new int[size]).map(c -> nextInt()).toArray(); } private long[] nextLongArray(int size) { return stream(new long[size]).map(c -> nextLong()).toArray(); } private double[] nextDoubleArray(int size) { return stream(new double[size]).map(c -> nextDouble()).toArray(); } private String[] nextStringArray(int size) { return range(0, size).mapToObj(i -> nextToken()).toArray(String[]::new); } /** * Primitives 2D arrays: char, int, long, double */ private char[][] nextCharMatrix(int n) { return range(0, n).mapToObj(i -> nextToken().toCharArray()).toArray(char[][]::new); } private int[][] nextIntMatrix(final int n, final int m) { return range(0, n).mapToObj(i -> nextIntArray(m)).toArray(int[][]::new); } private long[][] nextLongMatrix(final int n, final int m) { return range(0, n).mapToObj(i -> nextLongArray(m)).toArray(long[][]::new); } private double[][] nextDoubleMatrix(final int n, final int m) { return range(0, n).mapToObj(i -> nextDoubleArray(m)).toArray(double[][]::new); } /** * Graphs */ private static class Graph extends HashMap<Integer, Collection<Integer>> { } private static class Tree extends Graph { } private Graph nextGraph(int amountOfVertexes, int amountOfEdges, boolean isDirected) { Graph graph = new Graph(); for (int i = 1; i <= amountOfVertexes; i++) { graph.put(i, new HashSet<>()); } for (int i = 1; i <= amountOfEdges; i++) { int from = nextInt(); int to = nextInt(); graph.get(from).add(to); if (!isDirected) { graph.get(to).add(from); } } return graph; } private Tree nextTree(int amountOfVertexes, boolean isDirected) { Tree tree = new Tree(); for (int i = 1; i <= amountOfVertexes; i++) { tree.put(i, new HashSet<>()); } for (int i = 1; i <= amountOfVertexes - 1; i++) { int from = nextInt(); int to = nextInt(); tree.get(from).add(to); if (!isDirected) { tree.get(to).add(from); } } return tree; } /** * Output */ private void printf(String format, Object... args) { writer.printf(format, args); } private void print(Object o) { writer.print(o); } private void printSpace() { writer.print(' '); } private void println() { writer.println(); } private void println(Object o) { writer.println(o); } private void flush() { writer.flush(); } /** * Utils */ private boolean isValidIndex(int ind, int n) { return 0 <= ind && ind < n; } private void printSeparator() { if (ONLINE_JUDGE) return; println("--------------Answer-----------------"); } private void debug(Object o) { if (ONLINE_JUDGE) return; println(o); } private void debug(int[] array) { if (ONLINE_JUDGE) return; for (int i = 0; i < array.length; i++) { print(array[i]); print(' '); } println(); } private void debug(int[][] matrix) { if (ONLINE_JUDGE) return; for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[i].length; j++) { print(matrix[i][j]); print(' '); } println(); } } private void debug(char[][] matrix) { if (ONLINE_JUDGE) return; for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[i].length; j++) { print(matrix[i][j]); print(' '); } println(); } } public static double maxn(double req, double... opt) { double max = req; for (double value : opt) max = Math.max(max, value); return max; } public static double minn(double req, double... opt) { double min = req; for (double value : opt) min = Math.min(min, value); return min; } public static double sumn(double... a) { return stream(a).sum(); } public static int maxn(int req, int... opt) { int max = req; for (int value : opt) max = Math.max(max, value); return max; } public static int minn(int req, int... opt) { int min = req; for (int value : opt) min = Math.min(min, value); return min; } public static int sumn(int... a) { return stream(a).sum(); } public static long maxn(long req, long... opt) { long max = req; for (long value : opt) max = Math.max(max, value); return max; } public static long minn(long req, long... opt) { long min = req; for (long value : opt) min = Math.min(min, value); return min; } public static long sumn(long... a) { return stream(a).sum(); } public static void sort(long[] array) { shuffle(array); Arrays.sort(array); } public static void shuffle(long[] array) { Random random = new Random(); for (int i = 0, j; i < array.length; i++) { j = i + random.nextInt(array.length - i); long buf = array[j]; array[j] = array[i]; array[i] = buf; } } public static void sort(int[] array) { shuffle(array); Arrays.sort(array); } public static void shuffle(int[] array) { Random random = new Random(); for (int i = 0, j; i < array.length; i++) { j = i + random.nextInt(array.length - i); int buf = array[j]; array[j] = array[i]; array[i] = buf; } } public static Map<Double, Integer> multiSet(double[] arr) { Map<Double, Integer> multiSet = new HashMap<>(); for (int i = 0; i < arr.length; i++) multiSet.put(arr[i], multiSet.getOrDefault(arr[i], 0) + 1); return multiSet; } public static Map<Integer, Integer> multiSet(int[] arr) { Map<Integer, Integer> multiSet = new HashMap<>(); for (int i = 0; i < arr.length; i++) multiSet.put(arr[i], multiSet.getOrDefault(arr[i], 0) + 1); return multiSet; } public static Map<Long, Integer> multiSet(long[] arr) { Map<Long, Integer> multiSet = new HashMap<>(); for (int i = 0; i < arr.length; i++) multiSet.put(arr[i], multiSet.getOrDefault(arr[i], 0) + 1); return multiSet; } public static int[] calculatePrefixSum(int[] a) { int[] pref = new int[a.length]; pref[0] = a[0]; for (int i = 1; i < a.length; i++) pref[i] = pref[i - 1] + a[i]; return pref; } public static int[] calculateSuffixSum(int[] a) { int[] suff = new int[a.length]; suff[a.length - 1] = a[a.length - 1]; for (int i = a.length - 2; i >= 0; i--) suff[i] = suff[i + 1] + a[i]; return suff; } public static long[] calculatePrefixSum(long[] a) { long[] pref = new long[a.length]; pref[0] = a[0]; for (int i = 1; i < a.length; i++) pref[i] = pref[i - 1] + a[i]; return pref; } public static long[] calculateSuffixSum(long[] a) { long[] suff = new long[a.length]; suff[a.length - 1] = a[a.length - 1]; for (int i = a.length - 2; i >= 0; i--) suff[i] = suff[i + 1] + a[i]; return suff; } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.InputMismatchException; /** * @author Mubtasim Shahriar */ public class MinEu { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader sc = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Solver solver = new Solver(); int t = sc.nextInt(); // int t = 1; while(t--!=0) { solver.solve(sc, out); } out.close(); } static class Solver { public void solve(InputReader sc, PrintWriter out) { int n = sc.nextInt(); long l = sc.nextLong(); long r = sc.nextLong(); long[] cnt = new long[n+1]; for(int i = 1; i <= n; i++) { cnt[i] = ((long)(n-i))*2l; } long[] sum = new long[n+1]; sum[1] = cnt[1]; for(int i = 2; i <= n; i++) { sum[i] = sum[i-1]+cnt[i]; } int idx = 0; for(int i = 1; i <= n; i++) { if(sum[i]>=l) { idx = i; break; } } if(idx==0) { out.println(1); return; } long from = l-sum[idx-1]; // System.out.println(sum[idx-1]); ArrayList<Long> ans = new ArrayList(); long cntu = 0; long tmp = from/2; if(from%2==0) { ans.add(tmp+idx); // tmp += idx+1; tmp++; } else tmp++; tmp += idx; long now = idx; // System.out.println(tmp); // System.out.println(ans.size()); while(true) { if(ans.size()>=r-l+1) break; boolean ok = false; // System.out.println(now); while(tmp<=n) { ans.add(now); ans.add(tmp); ok = true; tmp++; } if(!ok) break; now++; tmp = now+1; } // System.out.println("HI"); if(ans.size()<r-l+1) ans.add(1l); long cnn = 0; for(int i = 0; i < ans.size(); i++) { out.print(ans.get(i) + " "); cnn++; if(cnn==r-l+1) break; } // System.out.println("HI"); out.println(); } } static class InputReader { private boolean finished = false; private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int peek() { if (numChars == -1) { return -1; } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { return -1; } if (numChars <= 0) { return -1; } } return buf[curChar]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String nextString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) { res.appendCodePoint(c); } c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private String readLine0() { StringBuilder buf = new StringBuilder(); int c = read(); while (c != '\n' && c != -1) { if (c != '\r') { buf.appendCodePoint(c); } c = read(); } return buf.toString(); } public String readLine() { String s = readLine0(); while (s.trim().length() == 0) { s = readLine0(); } return s; } public String readLine(boolean ignoreEmptyLines) { if (ignoreEmptyLines) { return readLine(); } else { return readLine0(); } } public BigInteger readBigInteger() { try { return new BigInteger(nextString()); } catch (NumberFormatException e) { throw new InputMismatchException(); } } public char nextCharacter() { int c = read(); while (isSpaceChar(c)) { c = read(); } return (char) c; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') { return res * Math.pow(10, nextInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') { return res * Math.pow(10, nextInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public boolean isExhausted() { int value; while (isSpaceChar(value = peek()) && value != -1) { read(); } return value == -1; } public String next() { return nextString(); } public SpaceCharFilter getFilter() { return filter; } public void setFilter(SpaceCharFilter filter) { this.filter = filter; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } public int[] nextIntArray(int n){ int[] array=new int[n]; for(int i=0;i<n;++i)array[i]=nextInt(); return array; } public int[] nextSortedIntArray(int n){ int array[]=nextIntArray(n); Arrays.sort(array); return array; } public int[] nextSumIntArray(int n){ int[] array=new int[n]; array[0]=nextInt(); for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt(); return array; } public long[] nextLongArray(int n){ long[] array=new long[n]; for(int i=0;i<n;++i)array[i]=nextLong(); return array; } public long[] nextSumLongArray(int n){ long[] array=new long[n]; array[0]=nextInt(); for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt(); return array; } public long[] nextSortedLongArray(int n){ long array[]=nextLongArray(n); Arrays.sort(array); return array; } } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
python3
#!/usr/bin/env python # coding: utf-8 # In[48]: #from __future__ import print_function #from sys import stdin # In[52]: cases = int( input() ) # In[53]: def ecycle(n,l,r): cnt = r - l + 1 p = n-1 start = 1 while(l >= 2*p and p>0): l -= 2*p p -= 1 start += 1 if(start==n): start = 1 flag = l%2 nextn = start + 1 + (l-1)//2 while(cnt>0): cnt-=1 if(flag==1): print(start,end=" ") if(flag==0): print(nextn, end=" ") nextn += 1 if(nextn>n): start += 1 nextn = start + 1 flag = 0 if(start==n): start = 1 flag = 1-flag # In[54]: while(cases>0): n,l,r = map( int, input().split() ) ecycle(n,l,r) cases -= 1 # In[ ]:
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
/* *created by Kraken on 02-05-2020 at 14:27 */ //package com.kraken.cf.practice; import java.util.*; import java.io.*; public class D1334 { public static void main(String[] args) { FastReader sc = new FastReader(); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); long l = sc.nextLong(), r = sc.nextLong(); long[] block = new long[n + 1]; block[1] = 1; for (int i = 2; i <= n; i++) block[i] = 2 * (i - 1) + block[i - 1]; // System.out.println(Arrays.toString(block)); long left = findBlock(block, l); long right = findBlock(block, r); // System.out.printf("left: %d, right: %d\n", left, right); long curr = left; ArrayList<Long> path = new ArrayList<>(); while (curr <= right) { for (int i = 0, j = 2; i < curr - 2; i++, j++) { path.add(curr); path.add((long) j); } path.add(curr); path.add((long) 1); curr++; } // System.out.println(path.toString()); StringBuilder sb = new StringBuilder(); long lidx = l - block[(int) (left - 1)] - 1; if (l == 1) lidx++; for (int i = 0; i < r - l + 1; i++) { sb.append(path.get((int) (lidx + i))).append(" "); } System.out.println(sb.toString()); } } private static int findBlock(long[] a, long key) { int l = 1, r = a.length - 1; while (l < r) { int mid = l + (r - l) / 2; if (a[mid] >= key) r = mid; else l = mid + 1; } return r; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
python2
T = input() for _ in xrange(T): n, l, r = map(int, raw_input().split()) now = 0 sn = 2 result = [] need = r-l+1 while len(result) < need: if now+1 >= l: result.append("1") result.append(str(sn)) elif now + 2 >= l: result.append(str(sn)) now += 2 if (sn-2) * 2 + now < l: now += (sn-2) * 2 sn += 1 continue for i in xrange(2, sn): if now+1 >= l: result.append(str(i)) result.append(str(sn)) elif now + 2 >= l: result.append(str(sn)) now += 2 sn += 1 #print now, sn, l, r, result print " ".join(result[:need]) #10 2 5 #1 2 1 3 2 3 1 4 2 4 3 4 1 5 2 5 3 5 4 5
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using vi = vector<int>; using ld = long double; using pll = pair<ll, ll>; void buff() { ios::sync_with_stdio(false); cin.tie(nullptr); } constexpr ll MOD = 1e9 + 7; inline ll pow_mod(ll a, ll b, ll mod = MOD) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; } return res; } int main() { buff(); int t; cin >> t; for (int i = 0; i < (t); ++i) { ll n, l, r; cin >> n >> l >> r; vector<pair<ll, ll> > c(n); ll cur_start = 1; ll cur_len = 2; for (int j = 1; j < n; ++j) { c[j] = make_pair(cur_start, cur_start + cur_len - 1ll); cur_start = (cur_start + cur_len); cur_len += 2ll; } c.push_back(make_pair(c.back().second + 1, c.back().second + 1)); for (int j = 1; j <= n; ++j) { if (l > c[j].second) continue; if (r < c[j].first) break; ll first_good = max(l, c[j].first); ll last_good = min(r, c[j].second); for (ll x = first_good; x <= last_good; ++x) { if (x == c[j].first) { cout << 1ll << " "; } else { ll dist = (x - c[j].first); if (dist & 1ll) { cout << j + 1ll << " "; } else cout << (dist / 2ll + 1) << " "; } } } cout << '\n'; } return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.util.*; import java.io.*; public class Main { public static void main(String args[])throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(System.out); int t=Integer.parseInt(br.readLine()); for(int x=0;x<t;x++) { String str[]=br.readLine().split(" "); int n=Integer.parseInt(str[0]); long l=Long.parseLong(str[1]); long r=Long.parseLong(str[2]); if(l<=(n-1)*2+1) { int arr[]=new int[(int)(r-l+1)]; int ind; if(l%2==0) { arr[0]=(int)(l/2)+1; arr[1]=1; ind=1; for(int i=(int)(l/2)+2;i<=n-1&&ind<arr.length-1;i++) { if(ind<arr.length-1) arr[++ind]=i; if(ind<arr.length-1) arr[++ind]=1; } } else { arr[0]=1; ind=0; for(int i=(int)((l+1)/2)+1;i<=n-1&&ind<arr.length-1;i++) { if(ind<arr.length-1) arr[++ind]=i; if(ind<arr.length-1) arr[++ind]=1; } } if(ind<arr.length-1) arr[++ind]=n; for(int i=2;i<n&&ind<arr.length;i++) { for(int j=i+1;j<=n&&ind<arr.length-1;j++) { arr[++ind]=i; if(ind<arr.length-1) arr[++ind]=j; } } if(ind<arr.length-1) arr[++ind]=1; for(int i=0;i<arr.length;i++) pw.print(arr[i]+" "); pw.println(); } else if(l<=(n-1)*2+1+2*(n-2)) { int arr[]=new int[(int)r-(n-1)*2+5]; int ind=0; arr[0]=n; for(int i=2;i<n&&ind<arr.length;i++) { for(int j=i+1;j<=n&&ind<arr.length-1;j++) { arr[++ind]=i; if(ind<arr.length-1) arr[++ind]=j; } } for(int i=0;i<arr.length;i++) pw.print(arr[i]+" "); pw.println(); } else { long sum=2*(n-1)+1; int num=n-2; int num2=2; while(sum+2*(num)<l&&num>0) { sum=sum+2*(num); num--; num2++; } int ind=-1; int arr[]=new int[(int)(r-sum)+5]; // while(sum<=r) //{ for(int i=num2;i<n&&ind<arr.length;i++) { for(int j=i+1;j<=n&&ind<arr.length-1;j++) { arr[++ind]=i; if(ind<arr.length-1) arr[++ind]=j; } } //} if(ind<arr.length-1) arr[++ind]=1; //for(int i=0;i<arr.length;i++) //pw.print(arr[i]+" "); for(int i=(int)(l-sum);i<=(int)(r-sum);i++) pw.print(arr[i]+" "); pw.println(); } } pw.flush(); pw.close(); } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
python3
T = int(input()) for _ in range(T): n, l, r = map(int, input().split()) size = r - l + 1 st = None en = None cur = 0 offset = 0 for i in range(1, n): if st is None and l < cur + (n-i)*2: st = i offset = l - cur - 1 if en is None and r < cur + (n-i)*2: en = i cur += (n-i)*2 if st is None: st = n if en is None: en = n arr = [] for i in range(st, en): for j in range(i+1, n+1): arr.append(i) arr.append(j) if en == n: arr.append(1) else: i = en for j in range(i+1, n+1): arr.append(i) arr.append(j) print(' '.join(map(str, arr[offset:offset+size])))
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; void solve() { long long n, l, r; cin >> n >> l >> r; long long p = 0; long long s = 1; vector<int> bp; vector<long long> res; int cu = l; int a = 1; int b = n; int c = 1; while (a <= b) { long long cnt = 2 * (b - a); if (p + cnt >= l) { vector<long long> list; for (int i = a + 1; i <= b; i++) { list.push_back(a); list.push_back(i); } while (cu <= r && cu - 1 - p < list.size()) { res.push_back(list[cu - 1 - p]); cu++; } } if (cu > r) break; p += cnt; bp.push_back(c); if (c == a) { a++; c = b; } else { c = b - 1; b--; } } long long start = p; for (int k : bp) res.push_back(k); int sp = 0; if (start < l) { sp = l - start - 1; } for (int i = 0; i <= r - l; i++) { if (i != 0) cout << " "; cout << res[i + sp]; } cout << "\n"; } int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10); int T = 1; cin >> T; for (int i = 1; i <= T; i++) { solve(); } cout.flush(); return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; for (int tc = 0; tc < (t); tc += 1) { long long n, l, r; cin >> n >> l >> r; l--; long long i = 1; long long ptr = 0; while (ptr + (n - i) * 2 <= l) { ptr += (n - i) * 2; i++; } long long j = i; j += (l - ptr) / 2; if (l % 2 == 1) { cout << j + 1 << " "; j++; l++; } if (j != n) { j++; } else { i++; j = i + 1; } while (r > l) { if (r - l == 1) { cout << i; break; } cout << i << " " << j << " "; if (j != n) { j++; } else { i++; j = i + 1; } r -= 2; } cout << "\n"; } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.io.*; import java.util.*; public class Sol4{ public static void main(String[] args) throws IOException{ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { long n = sc.nextInt(); long l = Long.parseLong(sc.next()); long r = Long.parseLong(sc.next()); long idx = 1; long cnt = 2*(n-idx); while(cnt+1<l) { idx++; cnt +=(long)2*(n-idx); } cnt++; cnt-=2*(n-idx)-1; long ix = idx+1; while(cnt<r) { if(ix == n+1) { idx++; ix = idx+1; } if(cnt%2==0) { if(cnt>=l)System.out.print(ix + " "); ix++; }else { if(cnt>=l)System.out.print(idx + " "); } cnt++; } if(r == ((n)*(n-1)+1))System.out.println(1); else { if(ix == n+1) { idx++; ix = idx+1; } if(cnt%2==0) { if(cnt>=l)System.out.println(ix); }else { if(cnt>=l)System.out.println(idx); } } } sc.close(); } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.util.Scanner; public class ProblemD { public static void main(String[] args) { // TODO Auto-generated method stub Scanner s = new Scanner(System.in); int t = s.nextInt(); for(int a=0;a<t;a++) { int n = s.nextInt(); long l = s.nextLong(); long r = s.nextLong(); long[] arr = new long[n]; long sum = 0; long val = 2*(n-1); for(int i=0;i<n-1;i++) { sum += val; val -= 2; arr[i] = sum; } arr[n-1] = arr[n-2] + 1; // for(int i=0;i<n;i++) // System.out.println(arr[i]); int index = upperBound(arr, l); System.out.println(index); print(arr, l, r, index); System.out.println(); } } public static void print(long[] arr, long l, long r, int index) { int n = arr.length; if(index == n-1) { System.out.print(1+" "); return; } long val1 = index + 1, val2 = 0; long end = arr[index]; if(l%2 == 0) { val2 = n - (end-l)/2; } else { val2 = n - (end-l-1)/2; } for(long i=l;l <= Math.min(end, r);l++) { if(l%2 == 1) System.out.print(val1+" "); else { System.out.print(val2+" "); val2++; } } if(end < r) print(arr, end + 1, r, index + 1); } public static int upperBound(long[] arr, long v) { if(v > arr[arr.length-1]) return -1; if(arr[0] > v) return 0; int low = 0, high = arr.length - 1; while(low < high) { if(low == high - 1) { if(arr[low] >= v) high = low; else low = high; break; } int mid = (low + high)/2; if(arr[mid] >= v) high = mid; else low = mid + 1; } return low; } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author bhavy seth */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } static class TaskD { public void solve(int testNumber, InputReader sc, PrintWriter out) { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); long l = sc.nextLong(); long r = sc.nextLong(); int start = 0; long count = 1; if (count == l) start = 1; else { for (int i = 2; i <= n; i++) { int smalller = Math.max(0, (i - 2) * 2) + 2; if (l <= count + smalller) { start = i; break; } else { count += smalller; } } } if (start == 2 && l == 2) { out.print(2 + " "); count++; } else if (start == 1) { out.print(1 + " "); } else count++; for (int i = 2; i < start; i++) { if (count >= l && count < r) { out.print(i + " "); count++; } if (count >= l && count < r) { out.print(start + " "); count++; } if (count >= r) { break; } } if (count < r && start != 1) { count++; out.print(1 + " "); } if (count < r) { for (int i = start + 1; i <= n; i++) { for (int j = 2; j < i; j++) { if (count < r && j == 2) { out.print(i + " "); count++; } if (count >= l && count < r) { out.print(j + " "); count++; } if (count >= l && count < r) { out.print(i + " "); count++; } if (count >= r) { break; } } if (i == 2) { out.print(i + " "); count++; } if (count < r) { out.print(1 + " "); count++; } if (count >= r) break; } } out.println(); } } } static class InputReader { BufferedReader br; StringTokenizer st; public InputReader(InputStream inputStream) { br = new BufferedReader(new InputStreamReader(inputStream)); } public String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
python2
import sys from math import sqrt, floor def get_ints(): return map(int, sys.stdin.readline().strip().split()) def get_array(): return list(map(int, sys.stdin.readline().strip().split())) def input(): return sys.stdin.readline().strip() def main(): T = int(input()) while T: n, l, r = get_ints() for i in range(l, r+1): k = floor(sqrt(i - (3/4)) - 0.5) j = floor((i - k**2 - k)/2) if i&1: print int(j+1), else: print int(k+2), print T-=1 main()
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.io.*; import java.util.*; public class D { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main (String[] args) throws IOException{ FastReader s = new FastReader(); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); int t = s.nextInt();//t: number of test cases for (int i = 0; i < t; i++) { int n = s.nextInt(); double l = s.nextDouble(); double r = s.nextDouble(); boolean islLast = l == 1.0 * n * (n-1) + 1; boolean isrLast = r == 1.0 * n * (n-1) + 1; if(!islLast){ double templ_01 = Math.ceil(((2*n-1)-Math.sqrt(4*Math.pow(n,2)-4*n+1-4*l))/2); double templ_02 = (templ_01 - 1) * (2*n - templ_01); int templ_11 = (int)(templ_01); int templ_12 = (int)((l - 1 + templ_02) / 2 + templ_11 + 1); if (isrLast) r--; boolean isrOdd = r%2==1; if (isrOdd) { r--; } double tempr_01 = Math.ceil(((2*n-1)-Math.sqrt(4*Math.pow(n,2)-4*n+1-4*r))/2); double tempr_02 = (tempr_01 - 1) * (2*n - tempr_01); int tempr_11 = (int) (tempr_01); int tempr_12 = (int)((r - 1 + tempr_02) / 2 + tempr_11 + 1); if (l%2==0) { bw.write(templ_12 + " "); templ_12++; if (templ_12 > n) { templ_11 ++; templ_12 = templ_11 + 1; } } while(templ_11 < tempr_11 || templ_11 == tempr_11 && templ_12 <= tempr_12){ bw.write(templ_11 + " "); bw.write(templ_12 + " "); templ_12++; if (templ_12 > n) { templ_11 ++; templ_12 = templ_11 + 1; } } if (isrOdd) { bw.write(templ_11 + " "); } if (isrLast) { bw.write("1"); } } else bw.write("1"); bw.write("\n"); } bw.flush(); bw.close(); } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.InputMismatchException; /** * @author Mubtasim Shahriar */ public class MinEu { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader sc = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Solver solver = new Solver(); int t = sc.nextInt(); // int t = 1; while(t--!=0) { solver.solve(sc, out); } out.close(); } static class Solver { public void solve(InputReader sc, PrintWriter out) { int n = sc.nextInt(); long l = sc.nextLong(); long r = sc.nextLong(); long[] cnt = new long[n+1]; for(int i = 1; i <= n; i++) { cnt[i] = (long)(n-i)*2l; } long[] sum = new long[n+1]; sum[1] = cnt[1]; for(int i = 2; i <= n; i++) { sum[i] = sum[i-1]+cnt[i]; } int idx = 0; for(int i = 1; i <= n; i++) { if(sum[i]>=l) { idx = i; break; } } if(idx==0) { out.println(1); return; } // System.out.println(sum[n]); long from = l-cnt[idx-1]; ArrayList<Long> ans = new ArrayList(); long cntu = 0; long tmp = from/2; if(from%2==0) { ans.add(tmp+idx); // tmp += idx+1; tmp++; } else tmp++; tmp += idx; long now = idx; // System.out.println(tmp); // System.out.println(ans.size()); while(true) { if(ans.size()>=r-l+1) break; boolean ok = false; // System.out.println(now); while(tmp<=n) { ans.add(now); ans.add(tmp); ok = true; tmp++; } if(!ok) break; now++; tmp = now+1; } // System.out.println("HI"); if(ans.size()<r-l+1) ans.add(1l); long cnn = 0; for(int i = 0; i < ans.size(); i++) { out.print(ans.get(i) + " "); cnn++; if(cnn==r-l+1) break; } // System.out.println("HI"); out.println(); } } static class InputReader { private boolean finished = false; private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int peek() { if (numChars == -1) { return -1; } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { return -1; } if (numChars <= 0) { return -1; } } return buf[curChar]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String nextString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) { res.appendCodePoint(c); } c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private String readLine0() { StringBuilder buf = new StringBuilder(); int c = read(); while (c != '\n' && c != -1) { if (c != '\r') { buf.appendCodePoint(c); } c = read(); } return buf.toString(); } public String readLine() { String s = readLine0(); while (s.trim().length() == 0) { s = readLine0(); } return s; } public String readLine(boolean ignoreEmptyLines) { if (ignoreEmptyLines) { return readLine(); } else { return readLine0(); } } public BigInteger readBigInteger() { try { return new BigInteger(nextString()); } catch (NumberFormatException e) { throw new InputMismatchException(); } } public char nextCharacter() { int c = read(); while (isSpaceChar(c)) { c = read(); } return (char) c; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') { return res * Math.pow(10, nextInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') { return res * Math.pow(10, nextInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public boolean isExhausted() { int value; while (isSpaceChar(value = peek()) && value != -1) { read(); } return value == -1; } public String next() { return nextString(); } public SpaceCharFilter getFilter() { return filter; } public void setFilter(SpaceCharFilter filter) { this.filter = filter; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } public int[] nextIntArray(int n){ int[] array=new int[n]; for(int i=0;i<n;++i)array[i]=nextInt(); return array; } public int[] nextSortedIntArray(int n){ int array[]=nextIntArray(n); Arrays.sort(array); return array; } public int[] nextSumIntArray(int n){ int[] array=new int[n]; array[0]=nextInt(); for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt(); return array; } public long[] nextLongArray(int n){ long[] array=new long[n]; for(int i=0;i<n;++i)array[i]=nextLong(); return array; } public long[] nextSumLongArray(int n){ long[] array=new long[n]; array[0]=nextInt(); for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt(); return array; } public long[] nextSortedLongArray(int n){ long array[]=nextLongArray(n); Arrays.sort(array); return array; } } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
python3
# from sys import stdin,stdout # input = stdin.readline # print = stdout.write from math import * ar=[0,1] for i in range(2,100010): ar.append(i*(i-1)+1) def jg(ar,n): l=0 r=len(ar)-1 ans=-1 while(l<=r): m=(l+r)//2 if(ar[m]>=n): ans=m r=m-1 else: l=m+1 return ans # print(ar[:10]) for __ in range(int(input())): n,l,r=map(int,input().split()) for i in range(l,r+1): if(i==1): print(1,end=" ") elif(i==2): print(2,end=" ") elif(i==3): print(1,end=" ") else: a=jg(ar,i) if(i%2==0): print(a,end=" ") else: temp=i-ar[a-1] if(temp//2 + 1==a): print(1,end=" ") else: print(temp//2+1,end=" ") print()
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author bhavy seth */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } static class TaskD { public void solve(int testNumber, InputReader sc, PrintWriter out) { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); long l = sc.nextLong(); long r = sc.nextLong(); long count = 0; int start = 0; for (int i = 1; i <= n; i++) { long x = Math.max(0, (n - i) * 2); if (l <= count + x) { start = i; break; } else { count += x; } } /* if(l==count+1){ out.print(start+" "); count++; }*/ if (start == 0) out.println(1); else { for (int i = start + 1; i <= n; i++) { if (count < l) { count++; } if (l <= count) { if (count <= r) { out.print(start + " "); count++; } if (count <= r) { out.print(i + " "); count++; } } else { if (count < l) { count++; } if (l <= count) { if (count <= r) { out.print(i + " "); count++; } if (count <= r) { out.print(start + " "); count++; } } } if (count > r) { break; } } if (count < r) { for (int i = start + 1; i < n; i++) { for (int j = i + 1; j <= n; j++) { if (count <= r) { out.print(i + " "); count++; } if (count <= r) { out.print(j + " "); count++; } if (count > r) break; } if (count > r) break; } } if (count <= r) out.print(1); } out.println(); } } } static class InputReader { BufferedReader br; StringTokenizer st; public InputReader(InputStream inputStream) { br = new BufferedReader(new InputStreamReader(inputStream)); } public String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
python3
import math import sys def LFromI(I): return I*I-I def IFromL(L): return math.floor((1+math.sqrt(1+4*L))/2) def Out(l, R): curint = IFromL(l) L = LFromI(curint) curpos = L while curpos < R: for i in range(2*curint): if curpos + i >= R: break if i % 2 == 1: print(1+curint, end=' ') else: print(1+i//2, end=' ') curpos += 2*curint curint += 1 t = int(input()) for _ in range(t): n, l, r = map(int, input().split()) Out(l, r) print()
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
// import java.math.*; import java.util.*; import java.io.*; public class D { static int test = 10; // 0 for local testing, 1 for std input static BufferedReader in; static PrintWriter out = new PrintWriter(System.out); static String file = "../in"; static int inf = 1_000_000; static void swap(int[]ary, int i, int j) { int t = ary[i]; ary[i] = ary[j]; ary[j] = t; } static String[] split() throws Exception { return in.readLine().split(" "); } static int readInt() throws Exception { return Integer.valueOf(in.readLine()); } static int[] toIntArray() throws Exception { String[] sp = split(); int n = sp.length; int[] ary = new int[n]; for(int i = 0; i < n; i++) ary[i] = Integer.valueOf(sp[i]); return ary; } static long[] toLongArray() throws Exception { String[] sp = split(); int n = sp.length; long[] ary = new long[n]; for(int i = 0; i < n; i++) ary[i] = Long.valueOf(sp[i]); return ary; } public static void main(String[] args) throws Exception { int _k = Integer.valueOf("1"); if(test > 0) in = new BufferedReader(new InputStreamReader(System.in)); else in = new BufferedReader(new FileReader(file)); if(test < 0) {String[] str = in.readLine().split(" ");} /****************************************************/ /****************************************************/ /****************************************************/ /****************************************************/ int t = readInt(); for(int tt = 0; tt < t; tt++) { long[] ary = toLongArray(); long n = ary[0], L = ary[1], R = ary[2]; StringBuilder sb = new StringBuilder(); long idx = 0; while(idx * (idx + 1) < L) idx++; idx--; long offset = L - idx * (idx + 1) - 1; // now construct int len = (int)(R - L + 1); List<Long> list = new ArrayList<>(); while(list.size() < R - L + 1) { for(int i = 1; i < idx; i++) { list.add(0L + i); list.add(idx); } idx++; } int from = (int) offset; int to = from + len; for(int i = from; i < to; i++) { out.printf("%d ", list.get(i)); } out.printf("\n"); } /****************************************************/ /****************************************************/ /****************************************************/ /****************************************************/ out.flush(); } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
python2
T = input() for _ in xrange(T): n, l, r = map(int, raw_input().split()) now = 0 sn = 2 result = [] need = r-l+1 while len(result) < need: if now+1 >= l: result.append("1") result.append(str(sn)) elif now + 2 >= l: result.append(str(sn)) now += 2 if (sn-2) * 2 + now + 100 < l: now += (sn-2) * 2 sn += 1 continue for i in xrange(2, sn): if now+1 >= l: result.append(str(i)) result.append(str(sn)) elif now + 2 >= l: result.append(str(sn)) now += 2 sn += 1 #print now, sn, l, r, result print " ".join(result[:need]) #10 2 5 #1 2 1 3 2 3 1 4 2 4 3 4 1 5 2 5 3 5 4 5
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long mpow(long long a, long long b, long long p = MOD) { a = a % p; long long res = 1; while (b > 0) { if (b & 1) res = (res * a) % p; a = (a * a) % p; b = b >> 1LL; } return res % p; } const long long N = 2 * 1e5 + 2, M = 20; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { long long n, l, r; cin >> n >> l >> r; long long lol[n + 1]; lol[1] = 1; for (long long i = 2; i <= n; i++) { lol[i] = 2 + (i - 2) * 2; } long long var = -1; long long s = 0; for (long long i = 1; i <= n; i++) { s += lol[i]; if (s < l) { } else { var = i; s -= lol[i]; break; } } long long count = r - l + 1 + 2 * n + 2; vector<long long> ans; while (count > 0) { if (var == 1) { ans.push_back(var); var++; count--; continue; } ans.push_back(var); count--; if (count == 0) break; for (long long i = 2; i < var; i++) { ans.push_back(i); count--; if (count == 0) break; ans.push_back(var); count--; if (count == 0) break; } if (count == 0) { break; } ans.push_back(1); count--; if (count == 0) { break; } var++; } for (long long i = 0; i < ans.size(); i++) { s++; if (s > r) { break; } if (s >= l && s <= r) { cout << ans[i] << " "; } } cout << "\n"; } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include<bits/stdc++.h> using namespace std; #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define f first #define s second #define ll long long #define loop(i,a,b) for(ll i=a;i<b;i++) #define vi vector<int> #define vvi vector<vi> #define rloop(i,a,b) for(ll i=a;i>b;i--) #define mp make_pair #define pb push_back #define ppb pop_back #define pii pair<int,int> #define mii map<int,int> #define mll map<long long,long long> #define msi map<string,int> #define vpii vector<pair<int,int>> #define vll vector<long long> #define sz(a) int(a.size()) #define last(x) x.end() #define beg(x) x.begin() #define all(x) begin(x),end(x) #define FindInTree(m,n) m.find(n)!=m.end() #define ull unsigned long long #define inp(a,n) loop(i,0,n) cin>>a[i] #define db1(x) cerr<<#x<<" = "<<x<<endl #define db2(x,y) cerr<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl #define db3(x,y,z) cerr<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl #define divs(n,m) ((m!=0)&&(n%m==0)) #define sum(container,value) accumulate(begin(container),end(container),value) #define tr(container,it)\ for(__typeof(container.begin()) it=container.begin();it!=container.end();it++) #define print(container) tr(container,it){cout<<*it<<" ";cout.flush();}cout<<endl #define printarr(a,n) loop(i,0,n){ cout<<a[i]<<" ";cout.flush(); }cout<<endl #define ordered_set(datatype,comp) tree<datatype, null_type, comp<datatype>, rb_tree_tag, tree_order_statistics_node_update> #pragma GCC optimise ("Ofast") const int mod=1e9+7; const int N=1e5+5; const double PI=3.14159265358979311600; //int Ecycle[N]; ll binomialCoeff(ll n, ll k) { ll res = 1; if(n<k) return 0; if ( k > n - k ) k = n - k; for (ll i = 0; i < k; ++i) { res *= (n - i); res /= (i + 1); } return res; } ll countDigitsAccurate(ll num,int base) { ll cnt=0; while(num>0) { cnt++; num=num/base; } return cnt; } vll generate(ll m,ll n) { vll ans; if(n>m) { ans.pb(1); return ans; } /*if(n==2) { ans.pb(1); ans.pb(2); return ans; } else if(n>2) { v.pb(1); v.pb(n); loop(i,2,n-1) v.pb(i); ans=v; ans.pb(n-1); //print(ans); reverse(beg(v),last(v)); //copy(beg(v),last(v),last(ans)); for(ll u:v) ans.pb(u); //print(ans); ans.ppb(); }*/ loop(i,n+1,m+1) { ans.pb(n); ans.pb(i); } return ans; } vll processBeg(ll m,ll l,ll lb) { ll begPtr; vll vlb; vlb=generate(m,lb); //stack<int> stk; //cout<<"lb is: "<<lb<<endl; //print(vlb); begPtr=(2*(lb-1)*m-(lb-1)*(lb-1)-(lb-1))+1; //while(begPtr<l) //{ //stk.pop(); //begPtr++; //} vll::iterator it=beg(vlb); advance(it,l-begPtr); vll ans(it,last(vlb)); return ans; } vll processMiddle(ll m,ll start,ll stop) { vll ans,segment; loop(i,start,stop+1) { segment=generate(m,i); //copy(beg(segment),last(segment),last(ans)); for(ll u:segment) ans.pb(u); } return ans; } vll processEnd(ll m,ll r,ll ub) { ll endPtr; vll vub; vub=generate(m,ub); if(ub>m) return vub; endPtr=2*ub*m-ub*ub-ub; while(endPtr>r) { vub.ppb(); endPtr--; } return vub; } ll findInterval(ll bnd,ll m) { ll interval,Discriminant; //db1(m*m); //db1(m*m-m); Discriminant=4*(m*m-m-bnd)+1; if(Discriminant<0) return m+1; //db1(Discriminant); Discriminant=sqrtl(Discriminant); interval=ceil(m-(1+Discriminant)/2.0); //db1(Discriminant); //db1(interval); //if((interval*(interval-1))==n) //interval--; return interval; } /*void preProcess() { int term,lim,ptr,L,R,mid; cout<<"In preProcess function"<<endl; term=sqrt(N); lim=2*term+1; Ecycle[1]=1; ptr=3; L=2; R=4; while(ptr<=lim&&R<99855) { cout<<L<<" "<<R<<endl; mid=(R+L)/2; loop(i,L,mid) { if((i-L)!=1) Ecycle[i]=Ecycle[i-(ptr-2)]; else Ecycle[i]=(ptr+1)/2; } Ecycle[mid]=(ptr-1)/2; loop(i,mid+1,R+1) { Ecycle[i]=Ecycle[2*mid-i]; } ptr+=2; L=R+1; R=L+ptr-1; } Ecycle[3]=2; loop(i,1,50) { cout<<Ecycle[i]<<" "; } cout<<endl; }*/ void solve() { //Declare your variables here. ll m,l,r,endPtr,lb,ub; vll left,middle,right,ans; //Do not assign values to the variables here!!! cin>>m>>l>>r; lb=findInterval(l,m); ub=findInterval(r,m); db2(lb,ub); if(ub<lb) return; left=processBeg(m,l,lb); if((ub-lb)>1) middle=processMiddle(m,lb+1,ub-1); right=processEnd(m,r,ub); //print(left); //print(middle); //print(right); if((ub-lb)>1) { ans=left; for(ll u:middle) ans.pb(u); for(ll u:right) ans.pb(u); } else if((ub-lb)==1) { ans=left; //copy(beg(left),last(left),last(ans)); //ans.resize(sz(right)+sz(ans)+5); //copy(beg(right),last(right),last(ans)); for(ll u:right) ans.pb(u); } else { endPtr=2*ub*m-ub*ub-ub; ans=left; if(ub<=m) { while(endPtr>r) { ans.ppb(); endPtr--; } } } /*loop(i,l,r+1) { cout<<Ecycle[i]<<" "; } cout<<endl; */ //cout<<"answer is:"<<endl; print(ans); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //#ifndef ONLINE_JUDGE //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); //freopen("error.txt","w",stderr); //#endif int t=1; //cin>>t; //preProcess(); while(t--) solve(); }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.util.*; import java.io.*; import java.time.Period; public class Main { public static void main(String[] args) throws Exception { int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); long l=sc.nextLong(); long r=sc.nextLong(); int number =2; int i=1; while(l-i*2>0) { number++; l-=i*2; r-=i*2; i++; } for(;l<=r;l++) { if(l%2==0) { pw.print(number); }else { if(l==1) pw.print(1); else pw.print((l+1)/2); } if(l!=r) { pw.print(" "); } if(l-i*2>=0) { l-=i*2; r-=i*2; i++; number++; } } pw.println(); } pw.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextLongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } static class pair implements Comparable<pair> { double x; double y; public pair(int x, int y) { this.x = x; this.y = y; } public String toString() { return x + " " + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair)o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Double(x).hashCode() * 31 + new Double(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return (int) (this.y - other.y); } else { return (int) (this.x - other.x); } } } static class tuble implements Comparable<tuble> { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + " " + y + " " + z; } public int compareTo(tuble other) { if (this.x == other.x) { return this.y - other.y; } else { return this.x - other.x; } } } public static long GCD(long a, long b) { if (b == 0) return a; if (a == 0) return b; return (a > b) ? GCD(a % b, b) : GCD(a, b % a); } public static long LCM(long a, long b) { return a * b / GCD(a, b); } static long Pow(long a, int e, int mod) // O(log e) { a %= mod; long res = 1; while (e > 0) { if ((e & 1) == 1) res = (res * a) % mod; a = (a * a) % mod; e >>= 1; } return res; } static long nc(int n, int r) { if (n < r) return 0; long v = fac[n]; v *= Pow(fac[r], mod - 2, mod); v %= mod; v *= Pow(fac[n - r], mod - 2, mod); v %= mod; return v; } public static boolean isprime(long a) { if (a == 0 || a == 1) { return false; } if (a == 2) { return true; } for (int i = 2; i < Math.sqrt(a) + 1; i++) { if (a % i == 0) { return false; } } return true; } public static boolean isPal(String s) { boolean t = true; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) != s.charAt(s.length() - 1 - i)) { t = false; break; } } return t; } public static long RandomPick(long[] a) { int n = a.length; int r = rn.nextInt(n); return a[r]; } public static int RandomPick(int[] a) { int n = a.length; int r = rn.nextInt(n); return a[r]; } public static void PH(String s, boolean reverse) { prelen = s.length(); HashsArray[HashsArrayInd] = new int[prelen + 1]; prepow = new int[prelen]; if (HashsArrayInd == 0) { int[] mods = { 1173017693, 1173038827, 1173069731, 1173086977, 1173089783, 1173092147, 1173107093, 1173114391, 1173132347, 1173144367, 1173150103, 1173152611, 1173163993, 1173174127, 1173204679, 1173237343, 1173252107, 1173253331, 1173255653, 1173260183, 1173262943, 1173265439, 1173279091, 1173285331, 1173286771, 1173288593, 1173298123, 1173302129, 1173308827, 1173310451, 1173312383, 1173313571, 1173324371, 1173361529, 1173385729, 1173387217, 1173387361, 1173420799, 1173421499, 1173423077, 1173428083, 1173442159, 1173445549, 1173451681, 1173453299, 1173454729, 1173458401, 1173459491, 1173464177, 1173468943, 1173470041, 1173477947, 1173500677, 1173507869, 1173522919, 1173537359, 1173605003, 1173610253, 1173632671, 1173653623, 1173665447, 1173675577, 1173675787, 1173684683, 1173691109, 1173696907, 1173705257, 1173705523, 1173725389, 1173727601, 1173741953, 1173747577, 1173751499, 1173759449, 1173760943, 1173761429, 1173762509, 1173769939, 1173771233, 1173778937, 1173784637, 1173793289, 1173799607, 1173802823, 1173808003, 1173810919, 1173818311, 1173819293, 1173828167, 1173846677, 1173848941, 1173853249, 1173858341, 1173891613, 1173894053, 1173908039, 1173909203, 1173961541, 1173968989, 1173999193}; mod = RandomPick(mods); int[] primes = { 59, 61, 67, 71, 73, 79, 83, 89, 97, 101 }; prime = RandomPick(primes); } prepow[0] = 1; if (!reverse) { for (int i = 1; i < prelen; i++) { prepow[i] = (int) ((1l * prepow[i - 1] * prime) % mod); } for (int i = 0; i < prelen; i++) { if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z') HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i] + ((1l * s.charAt(i) - 'a' + 1) * prepow[i]) % mod) % mod); else HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i] + ((1l * s.charAt(i) - 'A' + 27) * prepow[i]) % mod) % mod); } } else { for (int i = 1; i < prelen; i++) { prepow[i] = (int) ((1l * prepow[i - 1] * prime) % mod); } for (int i = 0; i < prelen; i++) { if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z') HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i] + ((1l * s.charAt(i) - 'a' + 1) * prepow[prelen - 1 - i]) % mod) % mod); else HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i] + ((1l * s.charAt(i) - 'A' + 27) * prepow[prelen - 1 - i]) % mod) % mod); } } HashsArrayInd++; } public static int PHV(int l, int r, int n, boolean reverse) { if (l > r) { return 0; } int val = (int) ((1l * HashsArray[n - 1][r] + mod - HashsArray[n - 1][l - 1]) % mod); if (!reverse) { val = (int) ((1l * val * prepow[prelen - l]) % mod); } else { val = (int) ((1l * val * prepow[r - 1]) % mod); } return val; } static int[][] HashsArray; static int HashsArrayInd = 0; static int[] prepow; static int prelen = 0; static int prime = 31; static long fac[]; static int mod = 998244353; static Random rn = new Random(); static Scanner sc = new Scanner(System.in); static PrintWriter pw = new PrintWriter(System.out); }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.util.*; import java.io.*; public class Solution{ static PrintWriter out=new PrintWriter(System.out); public static void main (String[] args) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] input=br.readLine().trim().split(" "); int numTestCases=Integer.parseInt(input[0]); while(numTestCases-->0){ input=br.readLine().trim().split(" "); int n=Integer.parseInt(input[0]); long l=Long.parseLong(input[1]); long r=Long.parseLong(input[2]); printSequence(n,l,r); } out.flush(); out.close(); } public static void printSequence(int n,long l,long r) { ArrayList<Integer> ans=new ArrayList<>(); long totalElements=0; int blockNumber=-1; for(int i=1;i<n;i++){ totalElements+=(2*(n-i)); if(totalElements>l) { totalElements-=(2*(n-i)); blockNumber=i; break; } } long pos=totalElements+1; for(int i=blockNumber;i<n && pos<=r && blockNumber!=-1;i++){ for(int j=i+1;j<=n;j++){ if(pos>=l && pos<=r) { ans.add(i); } pos++; if(pos>=l && pos<=r){ ans.add(j); } pos++; } } if(pos<=r){ ans.add(1); } for(int i=0;i<ans.size();i++){ out.print(ans.get(i)+" "); } out.println(); } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const char sp = ' ', nl = '\n'; int read() { int s = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { s = (s << 3) + (s << 1) + ch - '0', ch = getchar(); } return s * f; } template <typename T> void read(T &s) { s = 0; char ch = getchar(); long long f = 1; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') s = (s << 3) + (s << 1) + ch - 48, ch = getchar(); s *= f; } template <typename T, typename... A> void read(T &f, A &...a) { read(f); read(a...); } void sc() {} template <class T, class... A> void sc(T &t, A &...a) { cin >> t, sc(a...); } void pr() {} template <class T, class... A> void pr(T t, A... a) { cout << t, pr(a...); } const int mod = 1e9 + 7, base = 131; int t, n; long long l, r; int main() { t = read(); while (t--) { read(n, l, r); int st = 1; long long cnt = 0; for (int i = 1; i < n; i++) { if (cnt + (2 * (n - i)) <= l) { st = i + 1; cnt += 2 * (n - i); } else break; } while (cnt < r) { if (st == n) { cnt++; if (cnt >= l && cnt <= r) pr(1, sp); } for (int i = st + 1; i <= n; i++) { cnt++; if (cnt >= l && cnt <= r) pr(st, sp); cnt++; if (cnt >= l && cnt <= r) pr(i, sp); } st++; } puts(""); } return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
python3
def main(): for _ in inputt(): n, l, r = inputi() i = 1 l -= 1 if l == n * (n - 1): print(1) continue while l >= 2 * (n - i): l -= 2 * (n - i) r -= 2 * (n - i) i += 1 j = i + 1 + l // 2 while l < r: if l % 2: print(j, end = " ") j += 1 if j > n: i += 1 j = i + 1 elif r != n * (n - 1) + 1: print(i, end = " ") else: print(1, end = " ") l += 1 print() # region M # region fastio import sys, io, os BUFSIZE = 8192 class FastIO(io.IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = io.BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(io.IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") def print(*args, **kwargs): for x in args: file.write(str(x)) file.write(kwargs.pop("end", "\n")) sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion # region import inputt = lambda t = 0: range(t) if t else range(int(input())) inputi = lambda: map(int, input().split()) inputl = lambda: list(inputi()) from math import * from heapq import * from bisect import * from itertools import * from functools import reduce, lru_cache from collections import Counter, defaultdict import re, copy, operator, cmath from builtins import * # endregion # region main if __name__ == "__main__": main() # endregion # endregion
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.io.*; import java.math.BigInteger; import java.util.*; import javax.transaction.xa.Xid; public class tr1 { static PrintWriter out; static StringBuilder sb; static int n, m; static long mod = 998244353; static int[][] memo; static String s; static HashSet<Integer> nodes; static HashSet<Integer>[] ad, tree; static boolean[] vis, taken; static int[] a; static TreeSet<Long> al; static long[] val; static ArrayList<String> aa; static char[] b; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); out = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- > 0) { n = sc.nextInt(); long l = sc.nextLong(); long r = sc.nextLong(); int[] ar = new int[(int) (r - l + 1)]; int id = 1; int af = 0; long ll = l; int las = 0; while (id<n) { long num = (n - id) * 2l; // System.out.println(ll+" "+num); if (ll <= num) { if (ll % 2 == 0) { af = (int) (ll / 2) + 1; } else { af = id; las = (int) (ll / 2) + 2; } break; } ll -= num; id++; } // System.out.println(id+" "+af+" "+las); if (af == id) { ar[0] = id; if(ar.length>1) ar[1] = las; af = ++las; for (int i = 2; i < ar.length; i += 2) { if (af > n) { id++; af = id + 1; // System.out.println(i+" "+id+" "+af); } // System.out.println(i+" "+id+" "+af); ar[i] = id; if (i + 1 < ar.length) ar[i + 1] = af; af++; } } else { ar[0] = af; if (af == n) { if(ar.length>1) ar[1] = id++; if(ar.length>2) ar[2] = id + 1; af = id + 1; af++; } else { if(ar.length>1) ar[1] = id; if(ar.length>2) ar[2] = ++af; af++; } for (int i = 3; i < ar.length; i += 2) { if (af > n) { id++; af = id + 1; } ar[i] = id; if (i + 1 < n) ar[i + 1] = af; af++; } } if (r == n * 1l * (n - 1) + 1) ar[ar.length-1] = 1; for (int i = 0; i < ar.length; i++) out.print(ar[i] + " "); out.println(); } out.flush(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream system) { br = new BufferedReader(new InputStreamReader(system)); } public Scanner(String file) throws Exception { br = new BufferedReader(new FileReader(file)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public String nextLine() throws IOException { return br.readLine(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public char nextChar() throws IOException { return next().charAt(0); } public Long nextLong() throws IOException { return Long.parseLong(next()); } public int[] nextArrInt(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextArrLong(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } public void waitForInput() throws InterruptedException { Thread.sleep(3000); } } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); size_t T; cin >> T; while (T--) { int n, l, r; cin >> n >> l >> r; int t = 1; int k = 1; while (k < l && t != n) { k += 2 * (n - t++); } if (k < l) { cout << 1 << endl; continue; } if (k > l) { k -= 2 * (n - --t); } int difference = l - k; int c = difference / 2 + t + 1; if (difference % 2 == 0) { int current = l; while (current <= r) { cout << t << " "; ++current; if (current <= r) { cout << c++ << " "; ++current; if (c > n) { c = ++t + 1; if (t == n) { if (current <= r) cout << 1; break; } } } } } else { cout << c << " "; ++l; difference = l - k; c = difference / 2 + t + 1; if (c > n) { c = t++ + 1; if (t == n) { cout << 1 << endl; break; } } int current = l; while (current <= r) { cout << t << " "; ++current; if (current <= r) { cout << c++ << " "; ++current; if (c > n) { ++t; c = t + 1; if (t == n) { if (current <= r) cout << 1; break; } } } } } cout << endl; } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.io.*; import java.util.*; public class D { static void shuffleArray(int[] arr){ Random rnd = new Random(); for(int i = arr.length; i>0; i--){ int ndx = rnd.nextInt(i+1); int tmp = arr[ndx]; arr[ndx] = arr[i]; arr[i] = tmp; } } public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); int tst = Integer.parseInt(br.readLine()); //int tst = 1; while(tst-->0){ String[] str = br.readLine().split(" "); int n = Integer.parseInt(str[0]); long l = Long.parseLong(str[1]), r = Long.parseLong(str[2]); int now = 0, i = 1; for(; i<=n; i++){ now += 2*(n-i); if(i == n) break; if(now>=l){ now -= 2*(n-i); break; } } if(i == n) sb.append(1).append('\n'); else{ now++; outer:for(; i<=n; i++){ if(i == n && now == r) sb.append(1); for(int j = i+1; j<=n; j++){ if(now>r) break outer; if(now>=l) sb.append(i+" "); now++; if(now>=l) sb.append(j+" "); now++; } } sb.append('\n'); } } System.out.println(sb); } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; vector<int> s; int n; int solve(long long x) { if (x > s[n - 1]) { return 1; } auto id = lower_bound(s.begin() + 1, s.end(), x) - s.begin(); int pos = x - s[id - 1]; if (pos & 1) { return id; } else { return (pos >> 1) + id; } } int main() { int tt; cin >> tt; while (tt--) { long long l, r; cin >> n >> l >> r; s.assign(n + 1, 0); for (int i = 1; i <= n; i++) { s[i] = s[i - 1] + (2 * (n - i)); } for (long long i = l; i <= r; i++) { cout << solve(i) << " \n"[i == r]; } } return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.io.*; import java.util.*; public class eulercycc { /* * @return Index of leftmost number >=key. Inclusive */ /* private static int bsLowerBound(int[] a, int key) { // Modified Arrays.binarySearch int low = 0; int high = a.length - 1; while (low <= high) { int mid = (low + high) >>> 1; int midVal = a[mid]; int cmp = midVal - key; if (cmp < 0) low = mid + 1; else if (cmp > 0) high = mid - 1; else if (mid != 0 && a[mid-1]==midVal) { // not lower bound high = mid-1; } else return mid; // key found } return high+1; // key not found, returns number before }*/ /** * @return Index of rightmost number <=key. Inclusive */ private static long bsLowerBound(int high, long key) { // Modified Arrays.binarySearch int low = 0; while (low <= high) { int mid = (low + high) >>> 1; long cmp = mid * (mid + 1L) - key; if (cmp < 0) { low = mid + 1; } else if (cmp > 0) { high = mid - 1; } else { return mid; // key found } } return high + 1; // key not found, returns number after } public static void main(String[] args) throws Exception { R in = new R(); int TESTCASES = in.nextInt(); StringBuilder out = new StringBuilder(); for (int TC = 0; TC < TESTCASES; TC++) { int n = in.nextInt(); long l = in.nextLong(); long r = in.nextLong(); long p = bsLowerBound(n+69, l); p-=3; for (long i = l; i <= r; i++) { // n-1 inside the partition while (i > p*(p+1)) { p++; } if ((i&1)==0) { // even out.append(p+1).append(' '); } else { out.append( (i+1-p*(p-1)) >> 1 ).append(' '); } } out.setCharAt(out.length()-1, '\n'); } System.out.print(out); System.out.flush(); } //<editor-fold desc="R"> /** * This class is for fast input. Please ignore. */ public static class R { private BufferedReader br; /** * Should be set to null at end of line */ private StringTokenizer st; public R() { br = new BufferedReader(new InputStreamReader(System.in)); } public R(String filename) throws IOException { br = new BufferedReader(new FileReader(filename + ".in")); } public R(BufferedReader reader) { br = reader; } public BufferedReader getReader() { return br; } public StringTokenizer getStringTokenizer() { return st; } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) { String s = br.readLine(); if (s == null) return null; st = new StringTokenizer(s); } return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } /** * Note: * CAN MODIFY the BufferedReader's location and the string tokenizer!!! * Recommended to only use with next(). */ public boolean lineHasNext() throws IOException { if (st == null) { String s = br.readLine(); if (s == null) return false; st = new StringTokenizer(s); } return st.hasMoreTokens(); } /** * Note: * CAN MODIFY the BufferedReader's location and the string tokenizer!!! * Recommended to only use with next(). */ public boolean hasNext() throws IOException { while (st == null || !st.hasMoreTokens()) { String s = br.readLine(); if (s == null) return false; st = new StringTokenizer(s); } return true; } /** * Skips a line. Sets st to null if has tokens left, and otherwise * reads a line. */ public void skipLine() throws IOException { if (st == null || !st.hasMoreTokens()) { br.readLine(); // Otherwise, would do nothing. } st = null; } /** * This will set st to null, and this ignores current line */ public String[] nextLine() throws IOException { String s = br.readLine(); if (s == null) return null; st = new StringTokenizer(s); ArrayList<String> result = new ArrayList<>(); while (st.hasMoreTokens()) { result.add(st.nextToken()); } st = null; return result.toArray(new String[0]); } /** * sets st to null! */ public String[] nextTower(int lines) throws IOException { String[] tower = new String[lines]; st = null; for (int i = 0; i < lines; i++) { tower[i] = br.readLine(); } return tower; } public int[] nextIntLine() throws IOException { return intArr(nextLine()); } public long[] nextLongLine() throws IOException { return longArr(nextLine()); } public int[] nextIntTower(int lines) throws IOException { return intArr(nextTower(lines)); } public long[] nextLongTower(int lines) throws IOException { return longArr(nextTower(lines)); } public int[] intArr(String[] strings) throws IOException { int[] ints = new int[strings.length]; int i = 0; for (String s : strings) { ints[i] = Integer.parseInt(s); i++; } return ints; } public long[] longArr(String[] strings) throws IOException { long[] longs = new long[strings.length]; int i = 0; for (String s : strings) { longs[i] = Long.parseLong(s); i++; } return longs; } public double[] doubleArr(String[] strings) { double[] doubles = new double[strings.length]; int i = 0; for (String s : strings) { doubles[i] = Double.parseDouble(s); i++; } return doubles; } /** * This will set st to null */ public char[] nextCharArray() throws IOException { st = null; String s = br.readLine(); return s == null ? null : s.toCharArray(); } /** * This will set st to null * Boolean at pos i true if char at pos i == c */ public boolean[] nextBoolArray(char c) throws IOException { char[] chars = nextCharArray(); if (chars == null) return null; boolean[] booleans = new boolean[chars.length]; for (int i = 0; i < chars.length; i++) { booleans[i] = chars[i] == c; } return booleans; } public int[][] next2Dint(int lines) throws IOException { int[][] result = new int[lines][]; for (int i = 0; i < lines; i++) { result[i] = nextIntLine(); } return result; } public long[][] next2Dlong(int lines) throws IOException { long[][] result = new long[lines][]; for (int i = 0; i < lines; i++) { result[i] = nextLongLine(); } return result; } public char[][] next2Dchar(int lines) throws IOException { char[][] result = new char[lines][]; for (int i = 0; i < lines; i++) { result[i] = nextCharArray(); } return result; } public boolean[][] next2Dbool(int lines, char c) throws IOException { boolean[][] result = new boolean[lines][]; for (int i = 0; i < lines; i++) { result[i] = nextBoolArray(c); } return result; } } //</editor-fold> }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxc = 1e5; int main() { int t; cin >> t; while (t--) { int k = 0; int n, l, r; cin >> n >> l >> r; for (int i = 2 * (n - 1); i; k += i, i -= 2) { for (int j = max(l, k + 1); j <= min(r, k + i); j++) { if (j % 2) cout << n - i / 2 << " "; else cout << n - i / 2 + (j - k) / 2 << " "; } } if (k + 1 == r) cout << 1; cout << endl; } return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
//#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ll long long #define pb push_back #define mem(a,x) memset(a,x,sizeof(a)) #define nl "\n" #define fout(x) fixed<<setprecision(x) #define one(x) __builtin_popcountll(x) #define F first #define S second #define or_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) // find_by_order(), order_of_key() void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << fout(10)<<x;} void __print(double x) {cerr << fout(10)<<x;} void __print(long double x) {cerr << fout(10)<<x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif const int mod=1e9+7; const double eps=1e-9; const double PI=acos(-1.0); ll qpow(ll n,ll k){ll ans=1;assert(k>=0);n%=mod;while(k>0){if(k&1)ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans%mod;} // **************************************************** const int maxn=300010; ll arr1[maxn], arr2[maxn], arr3[maxn]; int main() { fast; int tc; cin>>tc; while(tc--){ int n; cin>>n; for(int i=0; i<n; i++) cin>>arr1[i]>>arr2[i]; ll tot=0; for(int i=0; i<n; i++){ ll temp; if(i==0) temp=arr2[n-1]; else temp=arr2[i-1]; arr3[i]=max(0ll, arr1[i]-temp); tot+=arr3[i]; } ll ans=1e18; for(int i=0; i<n; i++){ ans=min(ans, tot-arr3[i]+arr1[i]); } cout<<ans<<endl; } return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; import java.util.*; public class D { void solve() throws Exception { long n = nl(); long l = nl(); long r = nl(); long h = 0L; long b = 1L; for (long i = n - 1; h + 2 * i < l && i > 0; i--) { h += 2*i; b++; } long c = b; if (b == n) { out.println(1); return; } while (h < l) { h++; if ((h & 1) == 1) { c++; } } while (h <= r) { if ((h & 1) == 1) { out.print(b + " "); } else { out.print(c + " "); c++; if (c > n) { b++; c = b + 1; if (b == n) { out.println(1); return; } } } h++; } out.println(); } void run() throws Exception { initIO(); int t = ni(); while (t-- > 0) { solve(); out.flush(); } } public static void main(String[] args) throws Exception { new D().run(); } /** * IO. */ PrintWriter out; BufferedReader br; StringTokenizer tokenizer; void initIO() { out = new PrintWriter(System.out); br = new BufferedReader(new InputStreamReader(System.in)); tokenizer = null; } int ni() throws Exception { return Integer.parseInt(ns()); } long nl() throws Exception { return Long.parseLong(ns()); } double nd() throws Exception { return Double.parseDouble(ns()); } int[] nia(int n) throws Exception { int[] x = new int[n]; for (int i = 0; i < x.length; i++) { x[i] = ni(); } return x; } long[] nla(int n) throws Exception { long[] x = new long[n]; for (int i = 0; i < x.length; i++) { x[i] = nl(); } return x; } double[] nda(int n) throws Exception { double[] x = new double[n]; for (int i = 0; i < x.length; i++) { x[i] = nd(); } return x; } String ns() throws Exception { while (tokenizer == null || !tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(br.readLine()); return tokenizer.nextToken(); } String nline() throws Exception { tokenizer = null; return br.readLine(); } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long N = 500005; const long long M = 1000000007; int main() { long long t; cin >> t; while (t--) { long long n, l, r; cin >> n >> l >> r; vector<long long> v; v.push_back(1); for (long long i = 1; i < n; i++) { v.push_back(2 * i); } reverse(v.begin(), v.end()); vector<long long> v1; v1.push_back(v[0]); long long sum = v[0]; for (long long i = 1; i < n; i++) { sum += v[i]; v1.push_back(sum); } vector<long long>::iterator it = lower_bound(v1.begin(), v1.end(), l); vector<long long>::iterator it1 = lower_bound(v1.begin(), v1.end(), r); long long z = it - v1.begin(); long long z1 = it1 - v1.begin(); long long num = v1[z]; long long num1 = v1[z1]; if (z == n - 1) { cout << 1 << endl; } else { long long chk = 0; long long a, b, c, d; if (l % 2 == 0) { long long w = num - l; b = n - w / 2; a = z + 1; } else { a = z + 1; long long w = num - l - 1; b = n - w / 2; } if (z1 == n - 1) { chk = 1; } else { c = z1 + 1; long long w = num1 - r; d = n - w / 2; } if (chk == 1) { if (l % 2 == 0) { cout << b << " "; long long nu = b + 1; while (nu <= n) { cout << a << " " << nu << " "; nu++; } } else { long long nu = b; while (nu <= n) { cout << a << " " << nu << " "; nu++; } } for (long long j = a + 1; j < n; j++) { long long nu = j + 1; while (nu <= n) { cout << j << " " << nu << " "; nu++; } } cout << 1 << " "; } else if (a == c) { if (l % 2 == 0 && r % 2 == 0) { cout << b << " "; long long nu = b + 1; while (nu <= d) { cout << a << " " << nu << " "; nu++; } } else if (l % 2 == 0 && r % 2 != 0) { cout << b << " "; long long nu = b + 1; while (nu < d) { cout << a << " " << nu << " "; nu++; } cout << a << " "; } else if (l % 2 != 0 && r % 2 == 0) { long long nu = b; while (nu <= d) { cout << a << " " << nu << " "; nu++; } } else { long long nu = b; while (nu < d) { cout << a << " " << nu << " "; nu++; } cout << 1 << " "; } } else { if (l % 2 == 0) { cout << b << " "; long long nu = b + 1; while (nu <= n) { cout << a << " " << nu << " "; nu++; } } else { long long nu = b; while (nu <= n) { cout << a << " " << nu << " "; nu++; } } if (a + 1 < c) { for (long long j = a + 1; j < c; j++) { long long nu = j + 1; while (nu <= n) { cout << j << " " << nu << " "; nu++; } } } if (r % 2 == 0) { long long nu = c + 1; while (nu <= d) { cout << c << " " << nu << " "; nu++; } } else { long long nu = c + 1; while (nu < d) { cout << c << " " << nu << " "; nu++; } cout << c << " "; } } } cout << endl; } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.io.*; import java.util.*; import java.math.*; import java.awt.Point; public class Main { //static final long MOD = 998244353L; //static final long INF = 1000000000000000007L; static final long MOD = 1000000007L; static final int INF = 1000000007; //static long[] factorial; public static void main(String[] args) { FastScanner sc = new FastScanner(); PrintWriter pw = new PrintWriter(System.out); int Q = sc.ni(); for (int q = 0; q < Q; q++) { int N = sc.ni(); long L = sc.nl()-1; long R = sc.nl()-1; if (L == (N+0L)*(N-1)) { pw.println(1); } else { long index = 0; int first = 1; int second = -1; while (true) { if (L >= index + 2*(N-first)) { index += 2*(N-first); first++; } else { second = first+1; while (L >= index+2) { index += 2; second++; } break; } } long max = Math.min(R,(N+0L)*(N-1)-1); while (index <= max) { if (index == L-1) { pw.print(second + " "); index++; if (second == N) { first++; second = first+1; } else { second++; } continue; } if (index == max) { pw.print(first + " "); break; } else if (index+1 == max) { pw.print(first + " " + second + " "); break; } else { pw.print(first + " " + second + " "); if (second == N) { first++; second = first+1; } else { second++; } index += 2; } } if (R > max) { pw.println(1); } else { pw.println(); } } } pw.close(); } public static long dist(long[] p1, long[] p2) { return (Math.abs(p2[0]-p1[0])+Math.abs(p2[1]-p1[1])); } //Find the GCD of two numbers public static long gcd(long a, long b) { if (a < b) return gcd(b,a); if (b == 0) return a; else return gcd(b,a%b); } //Fast exponentiation (x^y mod m) public static long power(long x, long y, long m) { if (y < 0) return 0L; long ans = 1; x %= m; while (y > 0) { if(y % 2 == 1) ans = (ans * x) % m; y /= 2; x = (x * x) % m; } return ans; } public static int[] shuffle(int[] array) { Random rgen = new Random(); for (int i = 0; i < array.length; i++) { int randomPosition = rgen.nextInt(array.length); int temp = array[i]; array[i] = array[randomPosition]; array[randomPosition] = temp; } return array; } public static long[] shuffle(long[] array) { Random rgen = new Random(); for (int i = 0; i < array.length; i++) { int randomPosition = rgen.nextInt(array.length); long temp = array[i]; array[i] = array[randomPosition]; array[randomPosition] = temp; } return array; } public static int[][] shuffle(int[][] array) { Random rgen = new Random(); for (int i = 0; i < array.length; i++) { int randomPosition = rgen.nextInt(array.length); int[] temp = array[i]; array[i] = array[randomPosition]; array[randomPosition] = temp; } return array; } public static int[][] sort(int[][] array) { //Sort an array (immune to quicksort TLE) Arrays.sort(array, new Comparator<int[]>() { @Override public int compare(int[] a, int[] b) { return a[1]-b[1]; //ascending order } }); return array; } public static long[][] sort(long[][] array) { //Sort an array (immune to quicksort TLE) Random rgen = new Random(); for (int i = 0; i < array.length; i++) { int randomPosition = rgen.nextInt(array.length); long[] temp = array[i]; array[i] = array[randomPosition]; array[randomPosition] = temp; } Arrays.sort(array, new Comparator<long[]>() { @Override public int compare(long[] a, long[] b) { if (a[0] < b[0]) return -1; else if (a[0] > b[0]) return 1; else return 0; } }); return array; } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int ni() { return Integer.parseInt(next()); } long nl() { return Long.parseLong(next()); } double nd() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
python3
import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # ------------------------------ from math import factorial from collections import Counter, defaultdict from heapq import heapify, heappop, heappush def RL(): return map(int, sys.stdin.readline().rstrip().split()) def N(): return int(input()) def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0 def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0 def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2) mod = 1000000007 INF = float('inf') # ------------------------------ def main(): def c(sm, a1): sm = n*a1+(n-1)*n for _ in range(N()): n, l, r = RL() num = 2 while num**2-num<l: num+=1 s = l-(num-n-1)**2-(num-n-1) res = [] for i in range(1, num): res.append(i) res.append(num) for i in range(1, num): res.append(i) res.append(num+1) # print(res, l, r, num, l-s, ) # print(len(res), l-s, res[0]) print(" ".join([str(i) for i in res[l-s:l-s+(r-l)+1]])) if __name__ == "__main__": main()
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { long long n, l, r; cin >> n >> l >> r; long long cur = 1, odd = 1, num = 2, ye = 1, add = 2; while (cur < l) { cur += odd; cur++; if (cur > l) { cur--; cur -= odd; break; } odd += 2; num++; } while (cur < l) { cur++; if (ye == num) { ye = add; } else { ye = num; add++; } } for (long long i = l; i <= r; i++) { cout << ye << " "; if (ye == num) { if (add < num) { ye = add; } else { num++; add = 2; ye = 1; } } else { if (ye != 1) { add++; } ye = num; } } cout << endl; } return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int inf = 0x7FFFFFFF; const long long mod = (0 ? 1000000007 : 998244353); const double eps = 1e-7; void work() { long long n, l, r; cin >> n >> l >> r; vector<long long> ans; long long pos = l; if (l <= (n - 2) * 2) { long long f = l & 1; long long cnt = l / 2 + 1 + f; while (pos <= r && cnt < n) { if (f == 1) { ans.push_back(1); f = 0; } else { ans.push_back(cnt); cnt++; f = 1; } pos++; } } long long fl = 0; if (pos <= r) { ans.push_back(1); pos++; } long long now = n; while (pos <= r) { pos++; if (fl == 0) { ans.push_back(now); if (now == 2) { if (n == 2) { ans.push_back(1); break; } fl = 1; now++; } else now--; } else if (fl == 1) { ans.push_back(now); if (now == n) { fl = 2; } now++; } else { ans.push_back(1); break; } } for (long long i = 0; i < ans.size(); i++) { cout << ans[i] << ' '; } cout << endl; } signed main() { std::ios::sync_with_stdio(false); cin.tie(NULL); long long t = 1; cin >> t; while (t--) { work(); } return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
//package CodeforcesJava; import java.io.*; import java.util.*; public class Main { public void solve(InputProvider in, PrintWriter out) throws IOException { int testCount = in.nextInt(); for (int test = 0; test < testCount; test++) { long pointCount = in.nextLong(); long firstIndex = in.nextLong(); long lastIndex = in.nextLong(); long firstGroup = 2 * (pointCount - 1); boolean needLast = lastIndex == countElements(firstGroup, pointCount - 1) + 1; if (firstIndex < lastIndex) { if (needLast) { lastIndex--; } long minGuess = 0; long maxGuess = pointCount - 1; while (maxGuess > minGuess + 1) { long middleGuess = (maxGuess + minGuess) / 2; long middleGuessCount = countElements(firstGroup, middleGuess); if (firstIndex < middleGuessCount) { maxGuess = middleGuess; } else { minGuess = middleGuess; } } while (countElements(firstGroup, minGuess + 1) < firstIndex) { minGuess++; } long distance = firstIndex - countElements(firstGroup, minGuess); long levelPoint = minGuess + 1; long point; long pairPoint; if ((distance & 1) == 1) { point = levelPoint; pairPoint = (distance + 1) / 2 + levelPoint; } else { point = distance / 2 + levelPoint; out.print(point + " "); firstIndex++; if (point == pointCount) { point = levelPoint + 1; pairPoint = point + 1; } else { pairPoint = point + 1; point = levelPoint; } } boolean printMain = true; for (long i = firstIndex; i <= lastIndex; i++) { if (printMain) { out.print(point + " "); printMain = false; } else { out.print(pairPoint + " "); printMain = true; if (pairPoint < pointCount) { pairPoint++; } else { point++; pairPoint = point + 1; } } } } if (needLast) { out.print("1 "); } out.print("\n"); } } private long countElements(long first, long count) { return (2 * first - 2 * (count - 1)) * count / 2; } public static void main(String[] args) throws Exception { try (InputProvider input = new InputProvider(System.in); PrintWriter output = new PrintWriter(System.out)) { new Main().solve(input, output); } } public static class InputProvider implements AutoCloseable { private final BufferedReader reader; private StringTokenizer tokenizer; public InputProvider(Reader reader) { this.reader = new BufferedReader(reader); } public InputProvider(InputStream input) { reader = new BufferedReader(new InputStreamReader(input)); } public String next() throws IOException { if (Objects.isNull(tokenizer) || !tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(reader.readLine()); return tokenizer.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public String nextLine() throws IOException { return reader.readLine(); } @Override public void close() throws Exception { reader.close(); } } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s=new Scanner(System.in); int t=s.nextInt(); StringBuilder sb=new StringBuilder(); for(int i=0;i<t;i++) { int n=s.nextInt(); long l=s.nextLong(); long r=s.nextLong(); int left=0; int right=0; long ll=0; long rr=0; long count=0; int block=0; while(count<l&&block<n) { block++; count=count+2*(n-block); } left=block; ll=count-2*(n-block); count=0; block=0; while(count<r&&block<n) { block++; count=count+2*(n-block); } right=block; rr=count; ArrayList<Integer> list=new ArrayList<>(); for(int j=left;j<=right;j++) { fill(list,j,n); } long cc=0; for(long j=ll+1;j<=rr;j++) { int now=list.get((int)(j-(ll+1))); if(j>=l&&j<=rr) { cc++; sb.append(now+" "); } } if(cc==r-l+1) sb.append("\n"); else { sb.append(1+"\n"); } } System.out.println(sb); } public static void fill(ArrayList<Integer> list,int start,int n) { int c=start+1; for(int i=0;i<2*(n-start);i++) { if(i%2==0) { list.add(start); } else { list.add(c); c++; } } } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; vector<long long> ans; int main() { int tests = 1; int n; long long l, r; scanf("%d", &tests); while (tests--) { ans.clear(); scanf("%d%lld%lld", &n, &l, &r); long long s = sqrt(l - 1), t = sqrt(r - 1); while (s * (s - 1) <= l - 1) s++; s--; while (t * (t - 1) <= r - 1) t++; ans.push_back(1); for (long long i = s; i < t; ++i) { for (long long j = 2; j <= i; ++j) ans.push_back(i + 1), ans.push_back(j); ans.push_back(i + 1); ans.push_back(1); } r -= s * (s - 1) + 1, l -= s * (s - 1) + 1; for (int i = 0; i < (int)ans.size(); ++i) { if (i >= l && i <= r) printf("%lld ", ans[i]); } puts(""); } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.io.*; import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class cf1334d { public static void main(String[] args) throws IOException { int t = ri(); while(t --> 0) { int n = rni(); long l = nl() - 1, r = nl(); List<Long> ans = new ArrayList<>(); if(l == 0) { ans.add(1L); ++l; } long ind = 1, start = 1; while(ind + 2 * start <= l) { ind += 2 * start++; } long st = l - ind; ind = l; for(long i = st; i < 2 * start && ind < r; ++i, ++ind) { if(i % 2 == 0) { ans.add(start + 1); } else { ans.add((i + 1) / 2 == start ? 1 : (i + 3) / 2); } } while(ind < r) { ++start; for(long i = 0; i < 2 * start && ind < r; ++i, ++ind) { if(i % 2 == 0) { ans.add(start + 1); } else { ans.add((i + 1) / 2 == start ? 1 : (i + 3) / 2); } } } prln(ans); } close(); } static BufferedReader __in = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter __out = new PrintWriter(new OutputStreamWriter(System.out)); static StringTokenizer input; static Random rand = new Random(); // references // IBIG = 1e9 + 7 // IRAND ~= 3e8 // IMAX ~= 2e10 // LMAX ~= 9e18 // constants static final int IBIG = 1000000007; static final int IRAND = 327859546; static final int IMAX = 2147483647; static final int IMIN = -2147483648; static final long LMAX = 9223372036854775807L; static final long LMIN = -9223372036854775808L; // util static int minof(int a, int b, int c) {return min(a, min(b, c));} static int minof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); int min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;} static long minof(long a, long b, long c) {return min(a, min(b, c));} static long minof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); long min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;} static int maxof(int a, int b, int c) {return max(a, max(b, c));} static int maxof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); int max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;} static long maxof(long a, long b, long c) {return max(a, max(b, c));} static long maxof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); long max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;} static int powi(int a, int b) {if(a == 0) return 0; int ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;} static long powl(long a, int b) {if(a == 0) return 0; long ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;} static int floori(double d) {return (int)d;} static int ceili(double d) {return (int)ceil(d);} static long floorl(double d) {return (long)d;} static long ceill(double d) {return (long)ceil(d);} static void shuffle(int[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap;}} static void shuffle(long[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap;}} static void shuffle(double[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); double swap = a[i]; a[i] = a[ind]; a[ind] = swap;}} static <T> void shuffle(T[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); T swap = a[i]; a[i] = a[ind]; a[ind] = swap;}} static void rsort(int[] a) {shuffle(a); sort(a);} static void rsort(long[] a) {shuffle(a); sort(a);} static void rsort(double[] a) {shuffle(a); sort(a);} static int randInt(int min, int max) {return rand.nextInt(max - min + 1) + min;} // input static void r() throws IOException {input = new StringTokenizer(__in.readLine());} static int ri() throws IOException {return Integer.parseInt(__in.readLine());} static long rl() throws IOException {return Long.parseLong(__in.readLine());} static int[] ria(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()); return a;} static long[] rla(int n) throws IOException {long[] a = new long[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Long.parseLong(input.nextToken()); return a;} static char[] rcha() throws IOException {return __in.readLine().toCharArray();} static String rline() throws IOException {return __in.readLine();} static int rni() throws IOException {input = new StringTokenizer(__in.readLine()); return Integer.parseInt(input.nextToken());} static int ni() {return Integer.parseInt(input.nextToken());} static long rnl() throws IOException {input = new StringTokenizer(__in.readLine()); return Long.parseLong(input.nextToken());} static long nl() {return Long.parseLong(input.nextToken());} // output static void pr(int i) {__out.print(i);} static void prln(int i) {__out.println(i);} static void pr(long l) {__out.print(l);} static void prln(long l) {__out.println(l);} static void pr(double d) {__out.print(d);} static void prln(double d) {__out.println(d);} static void pr(char c) {__out.print(c);} static void prln(char c) {__out.println(c);} static void pr(char[] s) {__out.print(new String(s));} static void prln(char[] s) {__out.println(new String(s));} static void pr(String s) {__out.print(s);} static void prln(String s) {__out.println(s);} static void pr(Object o) {__out.print(o);} static void prln(Object o) {__out.println(o);} static void prln() {__out.println();} static void pryes() {__out.println("yes");} static void pry() {__out.println("Yes");} static void prY() {__out.println("YES");} static void prno() {__out.println("no");} static void prn() {__out.println("No");} static void prN() {__out.println("NO");} static void pryesno(boolean b) {__out.println(b ? "yes" : "no");}; static void pryn(boolean b) {__out.println(b ? "Yes" : "No");} static void prYN(boolean b) {__out.println(b ? "YES" : "NO");} static void prln(int... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);} static void prln(long... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);} static <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> iter = c.iterator(); for(int i = 0; i < n; __out.print(iter.next()), __out.print(' '), ++i); if(n >= 0) __out.println(iter.next());} static void h() {__out.println("hlfd");} static void flush() {__out.flush();} static void close() {__out.close();} }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { return a > b ? a : b; } void get_arr(int l, int* a) { int d = l / 4; if (l % 4 == 0) d--; a[0] = 1; a[1] = d + 3; a[2] = d + 2; a[3] = d + 3; } long long get_l(vector<int>& ans, long long l, long long s) { if (l == 2) { cout << "2 "; return 3; } if (l == 1) { if (s == 1) { cout << "1 "; return 2; } else { cout << "1 2 "; return 3; } } int a[4]; get_arr(l - 2, a); int ql = (l - 3) % 4; for (int j = 0, i = ql; j < s && i < 4; j++, i++) cout << a[i] << " "; return l + (4 - ql); } long long solve() { long long l, r, n; cin >> n >> l >> r; long long s = r - l + 1; vector<int> ans(s); l = get_l(ans, l, s); s = r - l + 1; for (int i = l; s > 0; i++) { int a[4]; get_arr(l, a); for (int i = 0; i < 4 && i < s; i++) cout << a[i] << " "; s = s - 4; } cout << endl; return 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { solve(); } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.io.BufferedInputStream; import java.util.Map; import java.util.Scanner; public class Main { private static Scanner sc = new Scanner(new BufferedInputStream(System.in)); public static void main(String[] args) { work(); } private static void work() { int t = sc.nextInt(); for (int i = 0; i < t; i++) { long n = sc.nextLong(); long l = sc.nextLong(), r = sc.nextLong(); printResult(n, l, r); } } private static void printResult(long n, long l, long r) { StringBuffer stringBuffer = new StringBuffer(); long k = ((2 * n - 1) - (long) Math.sqrt((2 * n - 1) * (2 * n - 1) - 4 * l)) / 2; int cnt = 0; long p = l, bias; while (cnt < r - l + 1) { if (p == n * (n - 1) + 1) { stringBuffer.append(1).append(' '); break; } bias = p - (2 * n - k - 1) * k; if (bias % 2 == 1) stringBuffer.append(k + 1).append(' '); else stringBuffer.append(bias / 2 + k + 1).append(' '); p++; cnt++; if (p > (2 * n - k - 2) * (k + 1)) k++; } System.out.println(stringBuffer); } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include<bits/stdc++.h> using namespace std; #define mod 1000000007 #define ll long long int #define pb push_back #define mp make_pair #define fi first #define se second #define boost ios_base::sync_with_stdio(false);cin.tie(NULL); #define inf 9223372036854775807 #define mini 9223372036854775807 #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}}; pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}}; ll power(ll a,ll b) { if(b==0) return 1; ll c=power(a,b/2); if(b%2==0) return ((c%mod)*(c%mod))%mod; else return ((((c%mod)*(c%mod))%mod)*a)%mod; } int main() { boost ll t,i; cin>>t; for(i=0; i<t; i++) { ll n,l,r; cin>>n>>l>>r; ll cnt=1; ll j=1; for(j=1; j<=n; j++) { ll nxt=cnt+(2*j); if(nxt>=l) break; cnt=nxt; } j++; // cout<<j<<endl; ll chance=0; ll cunt=1; while(cnt<=r) { ll val; if(chance==0) { if(cunt>=j) { cunt=1; j++; } val=cunt; cunt++; } else val=j; chance=1-chance; if(cnt>=l) cout<<val<<" "; cnt++; } cout<<endl; } return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.io.*; import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; // 21:35.396 + 2:22.250 + 2:29.637 public class cf1334d { public static void main(String[] args) throws IOException { int t = ri(); while(t --> 0) { int n = rni(); long l = nl() - 1, r = nl(); List<Long> ans = new ArrayList<>(); long start = 0; for(long i = max(start++, l); i < 1 && i < r; ++i) { ans.add(1L); } for(long i = max(start, l); i < start + 2 * (n - 2) && i < r; ++i) { if(i % 2 == 0) { ans.add(1L); } else { ans.add(2 + i / 2); } } start += 2 * (n - 2); for(long i = n; i >= 3; --i) { for(long j = max(start++, l); j < start && j < r; ++j) { ans.add(i); } for(long j = max(start, l), parity = (j - start) % 2; j < start + 2 * (i - 3) && j < r; ++j, parity = 1 - parity) { if(parity == 0) { ans.add(2 + (j - start) / 2); } else { ans.add(i); } } start += 2 * (i - 3); } for(long i = max(start, l); i < start + n - 1 && i < r; ++i) { ans.add(2 + i - start); } start += n - 1; for(long i = max(start++, l); i < start && i < r; ++i) { ans.add(1L); } /* // wrong pattern if(l == 0) { ans.add(1L); ++l; } long ind = 1, start = 1; while(ind + 2 * start <= l) { ind += 2 * start++; } long st = l - ind; ind = l; for(long i = st; i < 2 * start && ind < r; ++i, ++ind) { if(i % 2 == 0) { ans.add(start + 1); } else { ans.add((i + 1) / 2 == start ? 1 : (i + 3) / 2); } } while(ind < r) { ++start; for(long i = 0; i < 2 * start && ind < r; ++i, ++ind) { if(i % 2 == 0) { ans.add(start + 1); } else { ans.add((i + 1) / 2 == start ? 1 : (i + 3) / 2); } } } */ prln(ans); } close(); } static BufferedReader __in = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter __out = new PrintWriter(new OutputStreamWriter(System.out)); static StringTokenizer input; static Random rand = new Random(); // references // IBIG = 1e9 + 7 // IRAND ~= 3e8 // IMAX ~= 2e10 // LMAX ~= 9e18 // constants static final int IBIG = 1000000007; static final int IRAND = 327859546; static final int IMAX = 2147483647; static final int IMIN = -2147483648; static final long LMAX = 9223372036854775807L; static final long LMIN = -9223372036854775808L; // util static int minof(int a, int b, int c) {return min(a, min(b, c));} static int minof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); int min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;} static long minof(long a, long b, long c) {return min(a, min(b, c));} static long minof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); long min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;} static int maxof(int a, int b, int c) {return max(a, max(b, c));} static int maxof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); int max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;} static long maxof(long a, long b, long c) {return max(a, max(b, c));} static long maxof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); long max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;} static int powi(int a, int b) {if(a == 0) return 0; int ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;} static long powl(long a, int b) {if(a == 0) return 0; long ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;} static int floori(double d) {return (int)d;} static int ceili(double d) {return (int)ceil(d);} static long floorl(double d) {return (long)d;} static long ceill(double d) {return (long)ceil(d);} static void shuffle(int[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap;}} static void shuffle(long[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap;}} static void shuffle(double[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); double swap = a[i]; a[i] = a[ind]; a[ind] = swap;}} static <T> void shuffle(T[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); T swap = a[i]; a[i] = a[ind]; a[ind] = swap;}} static void rsort(int[] a) {shuffle(a); sort(a);} static void rsort(long[] a) {shuffle(a); sort(a);} static void rsort(double[] a) {shuffle(a); sort(a);} static int randInt(int min, int max) {return rand.nextInt(max - min + 1) + min;} // input static void r() throws IOException {input = new StringTokenizer(__in.readLine());} static int ri() throws IOException {return Integer.parseInt(__in.readLine());} static long rl() throws IOException {return Long.parseLong(__in.readLine());} static int[] ria(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()); return a;} static long[] rla(int n) throws IOException {long[] a = new long[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Long.parseLong(input.nextToken()); return a;} static char[] rcha() throws IOException {return __in.readLine().toCharArray();} static String rline() throws IOException {return __in.readLine();} static int rni() throws IOException {input = new StringTokenizer(__in.readLine()); return Integer.parseInt(input.nextToken());} static int ni() {return Integer.parseInt(input.nextToken());} static long rnl() throws IOException {input = new StringTokenizer(__in.readLine()); return Long.parseLong(input.nextToken());} static long nl() {return Long.parseLong(input.nextToken());} // output static void pr(int i) {__out.print(i);} static void prln(int i) {__out.println(i);} static void pr(long l) {__out.print(l);} static void prln(long l) {__out.println(l);} static void pr(double d) {__out.print(d);} static void prln(double d) {__out.println(d);} static void pr(char c) {__out.print(c);} static void prln(char c) {__out.println(c);} static void pr(char[] s) {__out.print(new String(s));} static void prln(char[] s) {__out.println(new String(s));} static void pr(String s) {__out.print(s);} static void prln(String s) {__out.println(s);} static void pr(Object o) {__out.print(o);} static void prln(Object o) {__out.println(o);} static void prln() {__out.println();} static void pryes() {__out.println("yes");} static void pry() {__out.println("Yes");} static void prY() {__out.println("YES");} static void prno() {__out.println("no");} static void prn() {__out.println("No");} static void prN() {__out.println("NO");} static void pryesno(boolean b) {__out.println(b ? "yes" : "no");}; static void pryn(boolean b) {__out.println(b ? "Yes" : "No");} static void prYN(boolean b) {__out.println(b ? "YES" : "NO");} static void prln(int... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);} static void prln(long... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);} static <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> iter = c.iterator(); for(int i = 0; i < n; __out.print(iter.next()), __out.print(' '), ++i); if(n >= 0) __out.println(iter.next());} static void h() {__out.println("hlfd");} static void flush() {__out.flush();} static void close() {__out.close();} }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
python3
def checklevel(a): currp = 0 currc = 0 for i in a: if currp > i[0]: return 'NO' if currc > i[1]: return 'NO' if i[1]-currc > i[0]-currp: return 'NO' currp = i[0] currc = i[1] return 'YES' def problem1(): l = int(input()) a = [] for _ in range(l): a.append(list(map(int,input().split()))) print(checklevel(a)) def makewealthy(a,x): total = a[0] if a[0] < x: return 0 i = 1 b = x while i < len(a): total += a[i] b += x if total < b: return i i += 1 return len(a) def problem2(): l,x = list(map(int,input().split())) a = list(map(int,input().split())) a.sort(reverse=True) print(makewealthy(a,x)) def minbullets(s): b = 0 l = len(s) for i in range(l): b += max (0, s[(i+1)%l][0] - s[i][1]) return min(i[0] for i in s) + b def problem3(): l = int(input()) a = [] for _ in range(l): a.append(list(map(int,input().split()))) print(minbullets(a)) def eulercycle(n,l,r): i = 0 k = n-1 if l == n*(n-1)+1: return [1] while i < l: i += 2*k k -= 1 s = [] a = n for j in range(i+1-l): if j%2 == 0: s.append(a) a -= 1 else: s.append(n-k-1) s = s[::-1] k = n-k a = k add = False if r == n*(n-1)+1: r -= 1 add = True for j in range(r-i): if j%2 == 0: if a == n: k += 1 a = k s.append(k) else: a += 1 s.append(a) if add: s.append(1) return(s) def problem4(): n,l,r = list(map(int,input().split())) x = eulercycle(n,l,r) print(*x) def divisors(n): s = [] for i in range(1,n+1): if n%i == 0: s.append(i) return s cases = int(input()) for _ in range(cases): problem4()
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
python3
import math # Ρ€Π΅ΡˆΠ΅Π½Π° def task_1343_c(): b = int(input()) array = [int(num) for num in input().split()] maxPositive = 0 minNegative = -10000000000 res = 0 for i in range(b): if array[i] < 0: if i != 0 and array[i - 1] >= 0: res += maxPositive maxPositive = 0 minNegative = max(minNegative, array[i]) else: if i != 0 and array[i - 1] < 0: res += minNegative minNegative = -10000000000 maxPositive = max(maxPositive, array[i]) if minNegative == -10000000000: res += maxPositive else: res += maxPositive + minNegative print(res) # Π½Π΅ Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ ΠΎΡ‚ слова совсСм def task_1341_b(): heightLen, doorSize = map(int, input().split()) heights = [int(num) for num in input().split()] perf = [0 for i in range(heightLen)] a = 0 for i in range(heightLen - 1): if i == 0: perf[i] = 0 else: if heights[i - 1] < heights[i] and heights[i] > heights[i + 1]: a += 1 perf[i] = a perf[heightLen - 1] = a max_global = 0 left_global = 0 for i in range(heightLen - doorSize): max_local = perf[i + doorSize - 1] - perf[i] if max_local > max_global: max_global = max_local left_global = i print(max_global + 1, left_global + 1) # Ρ€Π΅ΡˆΠΈΠ», Ρ‡Ρ‚ΠΎΠ± Π΅Ρ‘ def task_1340_a(): n = int(input()) array = [int(i) for i in input().split()] for i in range(n - 1): if array[i] < array[i + 1]: if array[i] + 1 != array[i + 1]: print("No") return print("Yes") #Ρ€Π΅ΡˆΠΈΠ» def task_1339_b(): n = int(input()) array = [int(num) for num in input().split()] array.sort() output = [0 for i in range(0, n)] i = 0 h = 0 j = n - 1 while i <= j: output[h] = array[i] h += 1 i += 1 if h < n: output[h] = array[j] h += 1 j -= 1 for val in reversed(output): print(val, end=' ') # Ρ€Π΅ΡˆΠ΅Π½Π° def task_1338_a(): n = int(input()) inputArr = [int(num) for num in input().split()] max_sec = 0 for i in range(1, n): local_sec = 0 a = inputArr[i - 1] - inputArr[i] if a <= 0: continue else: b = math.floor(math.log2(a)) local_sec = b + 1 for j in range(b, -1, -1): if a < pow(2, j): continue inputArr[i] += pow(2, j) a -= pow(2, j) if local_sec > max_sec: max_sec = local_sec print(max_sec) def task_1334_d(): n, l ,r = map(int, input().split()) if l == 9998900031: print(1) return res = [] res.append(1) for i in range(2, n + 1): if i == n: task_1334_d_helper(i, res) else: res.append(i) res.append(1) for i in range(l - 1, r): print(res[i], end=" ") def task_1334_d_helper(i, arr): arr.append(i) for j in range(2, i): if j == i - 1: task_1334_d_helper(i - 1, arr) else: arr.append(j) arr.append(i) a = int(input()) for i in range(a): task_1334_d()
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { int n, l, r; cin >> n >> l >> r; ll count = 0; int start; for (start = 1; start <= n && count < l; start++) { int edgesHere = 2 * (n - start); if (count + edgesHere >= l) { break; } count += edgesHere; } int next = start + 1; bool flag = false; while (count < l) { if (flag) { next++; } flag ^= 1; count++; } bool run = false; for (int i = l; i <= r; i++) { run = true; if (flag) cout << start << ' '; else { cout << next << ' '; if (++next > n) { ++start; if (start == n) { start = 1; } else { next = start + 1; } } } flag ^= 1; } if (!run) cout << 1; cout << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { solve(); } return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); int t = 1; cin >> t; while (t--) { long long n, l, r; cin >> n >> l >> r; bool f = 0; if (r == (n * (n - 1) + 1)) { r--; f = 1; } long long ans1 = (n - 1) * 2; long long sum = ans1, pos = 0; for (long long i = 1; i < n; i++) { if (l < ans1) { pos = i; break; } l -= ans1; r -= ans1; ans1 -= 2; } long long pos2 = (l + 1) / 2 + pos; while (l <= r) { if (l % 2 == 0) { cout << pos2 << " "; pos2++; } else cout << pos << " "; if (pos2 == n + 1) { pos++; pos2 = pos + 1; } l++; } if (f == 1) cout << 1 << " "; cout << endl; } return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
python3
import bisect dp = [None for i in range(10**5+2)] prev = 2 dp[0] = 1 dp[1] = 2 for i in range(2,10**5+1): curr = prev+2*(i-1) dp[i] = curr prev = curr def solve(curr, st, turn, n, l, r, res): while l<=r: if curr==n: res.append(1) l+=1 else: if turn: res.append(curr) l+=1 turn=False elif turn is False and st<n: res.append(st) l+=1 st+=1 turn=True else: res.append(st) l+=1 turn=True curr+=1 st=curr+1 return res t = int(input()) for _ in range(t): n, l, r = [int(x) for x in input().strip().split()] res= [] curr=1 i=n val=1 prev_curr=1 while l>=curr and i>1: prev_curr = curr curr+=2*(i-1) i-=1 val+=1 if l-curr<0: curr = val-1 curr_offset = l-prev_curr else: curr=val curr_offset = l-curr st_offset = curr_offset+1 # print(val,curr,curr_offset, st_offset) if curr_offset%2==0: turn = True else: turn = False st = curr+1+(st_offset)//2 # print(curr, st, turn) res = solve(curr, st, turn, n, l, r, res) print(*res[:r-l+1])
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.util.*; import java.io.*; public class Solution{ static PrintWriter out=new PrintWriter(System.out); public static void main (String[] args) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] input=br.readLine().trim().split(" "); int numTestCases=Integer.parseInt(input[0]); while(numTestCases-->0){ input=br.readLine().trim().split(" "); int n=Integer.parseInt(input[0]); long l=Long.parseLong(input[1]); long r=Long.parseLong(input[2]); printSequence(n,l,r); } out.flush(); out.close(); } public static void printSequence(int n,long l,long r) { long totalElements=0; int blockNumber=-1; for(int i=1;i<n;i++){ totalElements+=2L*(n-i); if(totalElements>l) { totalElements-=2L*(n-i); blockNumber=i; break; } } ArrayList<Integer> ans=new ArrayList<>(); long pos=totalElements+1; int count=0; for(int b=blockNumber;b<n && pos<=r && blockNumber!=-1;b++){ for(int i=b+1;i<=n;i++){ int currNumber=b; if(pos>=l && pos<=r){ ans.add(currNumber); count++; } pos++; currNumber=i; if(pos>=l && pos<=r){ ans.add(currNumber); count++; } pos++; } } if(count<(l-r+1)) { ans.add(1); } for(int i=0;i<ans.size();i++){ out.print(ans.get(i)+" "); } out.println(); } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } else return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } else return false; } ll S(ll n, ll k) { return 2 * (n - k); } void solve() { int T; cin >> T; for (ll(q) = (1); (q) <= (T); (q)++) { ll n, l, r; cin >> n >> l >> r; ll length = r - l + 1; ll lk; for (ll(k) = (1); (k) <= (n - 1); (k)++) { if (l - S(n, k) >= 0) l -= S(n, k), r -= S(n, k); else { lk = k; break; } } vector<ll> res; { res.push_back(0); ll i = 0; for (ll(k) = (lk); (k) <= (n - 1); (k)++) { for (ll(j) = (k + 1); (j) <= (n); (j)++) { res.push_back(k); i++; if (i == r) goto hoge; res.push_back(j); i++; if (i == r) goto hoge; } } if (i < r) res.push_back(1), i++; hoge: assert(i == r); } for (ll(i) = (l); (i) <= (r); (i)++) { cout << res[i] << (i < r ? " " : "\n"); } } return; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using namespace std; inline int qpow(int b, int e, int m = 998244353) { int a = 1; for (; e; e >>= 1, b = (long long)b * b % m) if (e & 1) a = (long long)a * b % m; return a; } int n, m, q, k; int a[300005], b[300005], c[300005]; const int pp[11] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31}; void solve() { long long n, l, r; cin >> n >> l >> r; vector<long long> v(n + 1); v[1] = 1; for (long long i = 2; i < n; i++) { v[i] = v[i - 1] + 2 * (n - (i - 1)); } v[n] = v[n - 1] + 2; auto itr1 = upper_bound(v.begin(), v.end(), l); auto itr2 = upper_bound(v.begin(), v.end(), r); if (itr1 == v.end()) { cout << 1 << endl; } else { int in1 = -1; int in2 = -1; auto k1 = itr1; auto k2 = itr2; int st1; st1 = (--k1) - v.begin(); int st2; st2 = k2 - v.begin(); long long i = v[st1]; while (i <= r && i < v[n]) { for (int j = 0; j < n - st1; j++) { if (i >= l && i <= r) cout << st1 << " " << st1 + j + 1 << " "; i += 2; } st1++; } if (r == v[n]) cout << 1 << endl; else cout << endl; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) solve(); return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include<iostream> #include<queue> #include<algorithm> #include<vector> #include<math.h> #include<cstring> #include<string> #include<stack> #include<map> #include<set> #include<cstdio> #include<deque> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9 * 2; const ll LNF = 1e18; const ll MOD = 998244353; const int MAXN = 200'005; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int T; cin >> T; while (T--) { ll n, l, r; cin >> n >> l >> r; ll cou = r - l; ll s = 1; ll f = 0; while (1) { if (s + f >= l) { break; } else s += f; f+=2; } //cout << "f " << f << '\n'; f /= 2; //cout << "s , f : " << s << ' ' << f << "\n"; ll a = f+1; ll b = (l - s+1)/2 ; //cout <<"a , b : "<< a << ' ' << b << "\n"; for (ll i = l; i <=r; i++) { if (i == 1) { cout << 1 << ' '; a = 2; b = 0; continue; } if (i % 2 == 0) { cout << a << ' '; if (i != l) b++; } else { if(a==n) cout << b % (a - 1) + 1 << ' '; else cout << b << ' '; if (b == a - 1) { a++; b = 0; } } } cout << '\n'; } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.util.*; import java.io.*; public class Main { static FastReader in=new FastReader(); static StringBuilder Sd=new StringBuilder(); static List<Integer>Gr[]; static long Mod=998244353; static Map<Integer,Integer>map=new HashMap<>(); public static void main(String [] args) { //Dir by MohammedElkady int t=in.nextInt(); while(t-->0) { long n=in.nextLong(),l=in.nextLong(),r=in.nextLong(); long ans=1,res=0; l-=1;r-=1; int lol=0; if(r>=n*(n-1)) {lol=1;r--;} for(long i=1;i<=n;i++) { if(res+((n-i)*2)<l) { ans=i; res+=(n-i)*2; }else break; } long vov=ans+1; if(!(lol>0&&l>r)) for(;l-1<=r;) { if(res>l) { Sout(vov-1+" "); l++; } if(res==l) { if(vov>n) { ans+=1;vov=ans+1; } Sout(ans+" "); if(r-l>=2) {Sout(vov+" ");} vov++; res+=2; l+=2; } else { vov++; res+=2; } } if(lol>0) {Soutln("1 ");} else Soutln(""); } Sclose(); } static long power(long x, long y, long p) { // Initialize result long res = 1; // Update x if it is more than or // equal to p x = x % p; while (y > 0) { // If y is odd, multiply x // with result if (y % 2 == 1) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } // Returns n^(-1) mod p static long modInverse(long n, long p) { return power(n, p-2, p); } // Returns nCr % p using Fermat's // little theorem. static long nCrModPFermat(int n, int r, long p) { // Base case if (r == 0) return 1; // Fill factorial array so that we // can find all factorial of r, n // and n-r long[] fac = new long[n+1]; fac[0] = 1; for (int i = 1 ;i <= n; i++) fac[i] = fac[i-1] * i % p; return (fac[n]* modInverse(fac[r], p) % p * modInverse(fac[n-r], p) % p) % p; } static long fac(int n , int m,int l) { long res=1; for(int i=l,u=1;i<=n||u<=m;i++,u++) { if(i<=n) {res*=i;} if(u<=m) {res/=u;} while(res>Mod) res-=Mod; } return res; } static long posation(int n) { long res=1; for(int i=0;i<n-3;i++) {res*=2L; while(res>Mod) res-=Mod; while(res<=0)res+=Mod;} return res; } static long gcd(long g,long x){ if(x<1)return g; else return gcd(x,g%x); } //array fill static long[]filllong(int n){long a[]=new long[n];for(int i=0;i<n;i++)a[i]=in.nextLong();return a;} static int[]fillint(int n){int a[]=new int[n];for(int i=0;i<n;i++)a[i]=in.nextInt();return a;} //OutPut Line static void Sout(String S) {Sd.append(S);} static void Soutln(String S) {Sd.append(S+"\n");} static void Soutf(String S) {Sd.insert(0, S);} static void Sclose() {System.out.println(Sd);} static void Sclean() {Sd=new StringBuilder();} } class node implements Comparable<node>{ int x,t; node(int x,int p){ this.x=x; this.t=p; } @Override public int compareTo(node o) { return (t-o.t); } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } class Sorting{ public static node[] bucketSort(node[] array, int bucketCount) { if (bucketCount <= 0) throw new IllegalArgumentException("Invalid bucket count"); if (array.length <= 1) return array; //trivially sorted int high = array[0].t; int low = array[0].t; for (int i = 1; i < array.length; i++) { //find the range of input elements if (array[i].t > high) high = array[i].t; if (array[i].t < low) low = array[i].t; } double interval = ((double)(high - low + 1))/bucketCount; //range of one bucket ArrayList<node> buckets[] = new ArrayList[bucketCount]; for (int i = 0; i < bucketCount; i++) { //initialize buckets buckets[i] = new ArrayList(); } for (int i = 0; i < array.length; i++) { //partition the input array buckets[(int)((array[i].t - low)/interval)].add(array[i]); } int pointer = 0; for (int i = 0; i < buckets.length; i++) { Collections.sort(buckets[i]); //mergeSort for (int j = 0; j < buckets[i].size(); j++) { //merge the buckets array[pointer] = buckets[i].get(j); pointer++; } } return array; } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.util.*; import java.io.*; import java.time.Period; public class codeforces { public static void main(String[] args) throws Exception { int t=sc.nextInt(); while(t-->0) { long n=sc.nextLong(); long l=sc.nextLong(); long r=sc.nextLong(); long number =2; long i=1; while(l-i*2>0) { l-=i*2; r-=i*2; i++; number++; } for(;l<=r;l++) { if(1l*l%2==0) { pw.print(1l*number+" "); }else { pw.print(1l*(l+1)/2+" "); } if(1l*l-i*2>=0) { l-=i*2; r-=i*2; i++; number++; } } pw.println(); } pw.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextLongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } static class pair implements Comparable<pair> { double x; double y; public pair(int x, int y) { this.x = x; this.y = y; } public String toString() { return x + " " + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair)o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Double(x).hashCode() * 31 + new Double(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return (int) (this.y - other.y); } else { return (int) (this.x - other.x); } } } static class tuble implements Comparable<tuble> { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + " " + y + " " + z; } public int compareTo(tuble other) { if (this.x == other.x) { return this.y - other.y; } else { return this.x - other.x; } } } public static long GCD(long a, long b) { if (b == 0) return a; if (a == 0) return b; return (a > b) ? GCD(a % b, b) : GCD(a, b % a); } public static long LCM(long a, long b) { return a * b / GCD(a, b); } static long Pow(long a, int e, int mod) // O(log e) { a %= mod; long res = 1; while (e > 0) { if ((e & 1) == 1) res = (res * a) % mod; a = (a * a) % mod; e >>= 1; } return res; } static long nc(int n, int r) { if (n < r) return 0; long v = fac[n]; v *= Pow(fac[r], mod - 2, mod); v %= mod; v *= Pow(fac[n - r], mod - 2, mod); v %= mod; return v; } public static boolean isprime(long a) { if (a == 0 || a == 1) { return false; } if (a == 2) { return true; } for (int i = 2; i < Math.sqrt(a) + 1; i++) { if (a % i == 0) { return false; } } return true; } public static boolean isPal(String s) { boolean t = true; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) != s.charAt(s.length() - 1 - i)) { t = false; break; } } return t; } public static long RandomPick(long[] a) { int n = a.length; int r = rn.nextInt(n); return a[r]; } public static int RandomPick(int[] a) { int n = a.length; int r = rn.nextInt(n); return a[r]; } public static void PH(String s, boolean reverse) { prelen = s.length(); HashsArray[HashsArrayInd] = new int[prelen + 1]; prepow = new int[prelen]; if (HashsArrayInd == 0) { int[] mods = { 1173017693, 1173038827, 1173069731, 1173086977, 1173089783, 1173092147, 1173107093, 1173114391, 1173132347, 1173144367, 1173150103, 1173152611, 1173163993, 1173174127, 1173204679, 1173237343, 1173252107, 1173253331, 1173255653, 1173260183, 1173262943, 1173265439, 1173279091, 1173285331, 1173286771, 1173288593, 1173298123, 1173302129, 1173308827, 1173310451, 1173312383, 1173313571, 1173324371, 1173361529, 1173385729, 1173387217, 1173387361, 1173420799, 1173421499, 1173423077, 1173428083, 1173442159, 1173445549, 1173451681, 1173453299, 1173454729, 1173458401, 1173459491, 1173464177, 1173468943, 1173470041, 1173477947, 1173500677, 1173507869, 1173522919, 1173537359, 1173605003, 1173610253, 1173632671, 1173653623, 1173665447, 1173675577, 1173675787, 1173684683, 1173691109, 1173696907, 1173705257, 1173705523, 1173725389, 1173727601, 1173741953, 1173747577, 1173751499, 1173759449, 1173760943, 1173761429, 1173762509, 1173769939, 1173771233, 1173778937, 1173784637, 1173793289, 1173799607, 1173802823, 1173808003, 1173810919, 1173818311, 1173819293, 1173828167, 1173846677, 1173848941, 1173853249, 1173858341, 1173891613, 1173894053, 1173908039, 1173909203, 1173961541, 1173968989, 1173999193}; mod = RandomPick(mods); int[] primes = { 59, 61, 67, 71, 73, 79, 83, 89, 97, 101 }; prime = RandomPick(primes); } prepow[0] = 1; if (!reverse) { for (int i = 1; i < prelen; i++) { prepow[i] = (int) ((1l * prepow[i - 1] * prime) % mod); } for (int i = 0; i < prelen; i++) { if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z') HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i] + ((1l * s.charAt(i) - 'a' + 1) * prepow[i]) % mod) % mod); else HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i] + ((1l * s.charAt(i) - 'A' + 27) * prepow[i]) % mod) % mod); } } else { for (int i = 1; i < prelen; i++) { prepow[i] = (int) ((1l * prepow[i - 1] * prime) % mod); } for (int i = 0; i < prelen; i++) { if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z') HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i] + ((1l * s.charAt(i) - 'a' + 1) * prepow[prelen - 1 - i]) % mod) % mod); else HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i] + ((1l * s.charAt(i) - 'A' + 27) * prepow[prelen - 1 - i]) % mod) % mod); } } HashsArrayInd++; } public static int PHV(int l, int r, int n, boolean reverse) { if (l > r) { return 0; } int val = (int) ((1l * HashsArray[n - 1][r] + mod - HashsArray[n - 1][l - 1]) % mod); if (!reverse) { val = (int) ((1l * val * prepow[prelen - l]) % mod); } else { val = (int) ((1l * val * prepow[r - 1]) % mod); } return val; } static int[][] HashsArray; static int HashsArrayInd = 0; static int[] prepow; static int prelen = 0; static int prime = 31; static long fac[]; static int mod = 998244353; static Random rn = new Random(); static Scanner sc = new Scanner(System.in); static PrintWriter pw = new PrintWriter(System.out); }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:36777216") #pragma pack(1) using namespace std; long long mod = 998244353; long long inf = 1e9; long double eps = 1e-6; double pi = acosl(-1); ifstream in("input.txt"); ofstream out("output.txt"); int main() { int t; scanf("%d", &t); while (t--) { long long n; scanf("%lld", &n); vector<int> a(n); for (int i = 1; i <= n; i++) { a[i - 1] = i; } sort(a.begin(), a.end(), [](const int& a, const int& b) { return to_string(a) < to_string(b); }); long long l, r; scanf("%lld%lld", &l, &r); int len = r - l + 1; int kk = 0; l--; r--; kk = (r == n * (n - 1)); r -= kk; int len1 = r - l; long long start = 0; for (; start < n; start++) { if (2 * (n - 1 - start) < l) { l -= 2 * (n - 1 - start); r -= 2 * (n - 1 - start); } else { break; } } vector<int> ans; int offset = l / 2 + 1; for (int i = 0; i <= len1; i++) { if ((l + i) % 2 == 1) { ans.push_back(a[start + offset]); offset++; if (offset + start == n) { start++; offset = 1; } } else ans.push_back(a[start]); } if (kk == 1) { ans.push_back(a[0]); } for (auto v : ans) { printf("%d ", v); } printf("\n"); } return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
python3
import math # Ρ€Π΅ΡˆΠ΅Π½Π° def task_1343_c(): b = int(input()) array = [int(num) for num in input().split()] maxPositive = 0 minNegative = -10000000000 res = 0 for i in range(b): if array[i] < 0: if i != 0 and array[i - 1] >= 0: res += maxPositive maxPositive = 0 minNegative = max(minNegative, array[i]) else: if i != 0 and array[i - 1] < 0: res += minNegative minNegative = -10000000000 maxPositive = max(maxPositive, array[i]) if minNegative == -10000000000: res += maxPositive else: res += maxPositive + minNegative print(res) # Π½Π΅ Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ ΠΎΡ‚ слова совсСм def task_1341_b(): heightLen, doorSize = map(int, input().split()) heights = [int(num) for num in input().split()] perf = [0 for i in range(heightLen)] a = 0 for i in range(heightLen - 1): if i == 0: perf[i] = 0 else: if heights[i - 1] < heights[i] and heights[i] > heights[i + 1]: a += 1 perf[i] = a perf[heightLen - 1] = a max_global = 0 left_global = 0 for i in range(heightLen - doorSize): max_local = perf[i + doorSize - 1] - perf[i] if max_local > max_global: max_global = max_local left_global = i print(max_global + 1, left_global + 1) # Ρ€Π΅ΡˆΠΈΠ», Ρ‡Ρ‚ΠΎΠ± Π΅Ρ‘ def task_1340_a(): n = int(input()) array = [int(i) for i in input().split()] for i in range(n - 1): if array[i] < array[i + 1]: if array[i] + 1 != array[i + 1]: print("No") return print("Yes") #Ρ€Π΅ΡˆΠΈΠ» def task_1339_b(): n = int(input()) array = [int(num) for num in input().split()] array.sort() output = [0 for i in range(0, n)] i = 0 h = 0 j = n - 1 while i <= j: output[h] = array[i] h += 1 i += 1 if h < n: output[h] = array[j] h += 1 j -= 1 for val in reversed(output): print(val, end=' ') # Ρ€Π΅ΡˆΠ΅Π½Π° def task_1338_a(): n = int(input()) inputArr = [int(num) for num in input().split()] max_sec = 0 for i in range(1, n): local_sec = 0 a = inputArr[i - 1] - inputArr[i] if a <= 0: continue else: b = math.floor(math.log2(a)) local_sec = b + 1 for j in range(b, -1, -1): if a < pow(2, j): continue inputArr[i] += pow(2, j) a -= pow(2, j) if local_sec > max_sec: max_sec = local_sec print(max_sec) def task_1334_d(): n, l ,r = map(int, input().split()) if l == 9998900031: print(1) return res = [] res.append(1) for i in range(2, n + 1): if i == n: task_1334_d_helper(i, res) else: res.append(i) res.append(1) for i in range(l - 1, r): print(res[i], end=" ") print() def task_1334_d_helper(i, arr): arr.append(i) for j in range(2, i): if j == i - 1: task_1334_d_helper(i - 1, arr) else: arr.append(j) arr.append(i) a = int(input()) for i in range(a): task_1334_d()
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const double PI = acos(-1.); const int N = 2e6 + 6; long long l, r, x; vector<long long> res; void gen(long long n) { if (x > r) return; if (x >= l && x <= r) res.push_back(1); x++; for (long long i = 2; i < n; i++) { if (x > r) return; if (x >= l && x <= r) res.push_back(n); x++; if (x >= l && x <= r) res.push_back(i); x++; } if (x >= l && x <= r) res.push_back(n); x++; } int main() { ios_base::sync_with_stdio(false); int T; cin >> T; while (T--) { res.clear(); long long n; cin >> n; cin >> l >> r; long long y = n; for (; y * (y - 1) >= l; y--) ; y = max(1LL, y - 1); x = y * (y - 1) + 1; for (long long i = y + 1; i <= n; i++) gen(i); if (x <= r) res.push_back(1); x++; for (auto x : res) cout << x << " "; cout << "\n"; } return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long f[10010]; map<long long, long long> vis; long long a[300005], b[300005], c[300005]; signed main() { std::ios::sync_with_stdio(false); long long t, n, i, j, m; cin >> t; while (t--) { cin >> n; for (i = 0; i < n; i++) { cin >> a[i] >> b[i]; } long long sum = 0; for (i = 0; i < n; i++) { if (i == 0) c[i] = max(0ll, a[0] - b[n - 1]); else c[i] = max(0ll, a[i] - b[i - 1]); sum += c[i]; } long long ans = 1e18; for (i = 0; i < n; i++) { ans = min(ans, sum - c[i] + a[i]); } cout << ans << endl; } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.io.*; import java.util.*; public class C { public static void main(String[] args) { FastScanner in = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); while(t-->0) { long n = in.nextInt(), l = in.nextLong(), r = in.nextLong(); int x = (int)Math.ceil(((2*n-1)-Math.sqrt((2*n-1)*(2*n-1)-4*l))/2); if(l>n*(n-1)) out.println(1); else{ long y = l-(n*(n-1)-((n-x)*(n-x+1))); long yy = y; y = x + (y-1)/2 + 1; int cnt = 0; long p = r-l+1; //out.println(x+" "+y); if(yy%2==0){ out.print(y+" "); p--; } if(r>n*(n-1)) p--; while(true){ if(cnt<p){ cnt++; out.print(x+" "); } else break; if(cnt<p){ cnt++; out.print(y+" "); y++; } else break; if(y==n+1){ x++; y = x+1; } } if(r>n*(n-1)) out.print(1); out.println(); } } out.flush(); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while(!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch(IOException e) {} return st.nextToken(); } String nextLine(){ try{ return br.readLine(); } catch(IOException e) { } return ""; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } int[] readArray(int n) { int a[] = new int[n]; for(int i=0;i<n;i++) a[i] = nextInt(); return a; } } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long tc, n, l, r; cin >> tc; for (long long i = 0; i < tc; i++) { cin >> n >> l >> r; if (l == (((n * (n - 1))) + 1)) { cout << "1"; continue; } long long ind = 0; long long add = (n - 1) * 2; long long sum = 1; while (1) { if ((add + ind) >= l) { break; } else { ind += add; add -= 2; sum++; } } ind++; add = sum; while (ind < l) { if (ind == l) { break; } else { if (ind % 2 == 0) { add++; } ind++; } } long long ind1 = l; if (l % 2 == 0) add++; while (ind1 <= r) { if (sum == n) { cout << "1"; break; } while (add <= n) { if (ind1 % 2 == 0) { cout << add << " "; ind1++; if (add == n) break; } else { cout << sum << " "; ind1++; add++; } if (ind1 > r) break; if (add > n) break; } if (ind1 > r) break; sum++; add = sum; } } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; void out(const vector<int>& arr) { for (auto i : arr) { cout << i << " "; } cout << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; for (int t1 = 0; t1 < t; t1++) { int n; long long l, r; cin >> n >> l >> r; long long pos = 0; long long delta = 0; int i = 1; while (pos < l) { if (n - i > 0) { delta = (long long)((long long)n - i) * 2; } else delta = 1; pos += delta; i++; } i--; long long realpos = pos - delta + 1; int j = i + 1; long long value = r - l + 1; while (realpos < l) { realpos += 2; j++; } bool flag = false; if (realpos != l) { realpos -= 2; j--; flag = true; } while (value > 0) { if (i == n) { cout << 1; break; } for (; j <= n; j++) { if (!flag) { cout << i << " "; value--; } flag = false; realpos++; if (value <= 0) break; cout << j << " "; value--; realpos++; } i++; j = i + 1; } cout << "\n"; } return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
python3
import os from io import BytesIO input = BytesIO(os.read(0, os.fstat(0).st_size)).readline t = int(input()) def visit(k): if k == 1: return [1] else: res = [k] for i in range(2, k): res.append(i) res.append(k) res.append(1) return res def visitlen(k): if k == 1: return 1 else: return 2 * (k-1) for _ in range(t): n, left, right = list(map(int, input().split())) interval = right-left+1 if left == 1: i = 1 res = [] while interval > 0: temp = visit(i) res.extend(visit(i)) i += 1 interval -= len(temp) for each in res[:right]: print(each, end = " ") print() else: i = 1 while visitlen(i) < left: left -= visitlen(i) i += 1 res = [] res.extend(visit(i)[left-1:]) intervalc = interval intervalc -= len(res) while intervalc > 0: i += 1 res.extend(visit(i)) intervalc -= visitlen(i) for each in res[:interval]: print(each, end = " ") print()
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { long long t; scanf("%lld", &t); while (t--) { long long n, l, r; scanf("%lld%lld%lld", &n, &l, &r); long long suml = 0, sumr = 0; long long headl = 1, headr = -1; long long flag1 = 0; for (long long i = 1; i < n; ++i) { if (!flag1) { suml += 2 * (n - i); } sumr += 2 * (n - i); if (suml > l && !flag1) { suml -= 2 * (n - i); flag1 = 1; headl = i; } else if (sumr >= r) { headr = i; break; } } long long vv = 0; if (headr == -1) { vv = 1; } long long flag = 1; long long now = headl + 1; for (long long i = suml + 1; i <= sumr; ++i) { if (flag == 1) { if (l <= i && i <= r) { printf("%lld ", headl); } flag = 2; } else if (flag == 2) { if (l <= i && i <= r) { printf("%lld ", now); } now++; if (now > n) { headl++; now = headl + 1; } flag = 1; } } if (vv == 1) { printf("1 "); } putchar('\n'); } return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.util.*; import java.io.*; import java.time.Period; public class codeforces { public static void main(String[] args) throws Exception { int t=sc.nextInt(); while(t-->0) { long n=sc.nextLong(); long l=sc.nextLong(); long r=sc.nextLong(); long number =2; long i=1; while(1l*1l-i*2>0) { l-=i*2; r-=i*2; i++; number++; } for(;l<=r;l++) { if(1l*l%2==0) { pw.print(1l*number+" "); }else { pw.print(1l*(l+1)/2+" "); } while(1l*l-i*2>=0) { l-=i*2; r-=i*2; i++; number++; } } pw.println(); } pw.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextLongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } static class pair implements Comparable<pair> { double x; double y; public pair(int x, int y) { this.x = x; this.y = y; } public String toString() { return x + " " + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair)o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Double(x).hashCode() * 31 + new Double(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return (int) (this.y - other.y); } else { return (int) (this.x - other.x); } } } static class tuble implements Comparable<tuble> { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + " " + y + " " + z; } public int compareTo(tuble other) { if (this.x == other.x) { return this.y - other.y; } else { return this.x - other.x; } } } public static long GCD(long a, long b) { if (b == 0) return a; if (a == 0) return b; return (a > b) ? GCD(a % b, b) : GCD(a, b % a); } public static long LCM(long a, long b) { return a * b / GCD(a, b); } static long Pow(long a, int e, int mod) // O(log e) { a %= mod; long res = 1; while (e > 0) { if ((e & 1) == 1) res = (res * a) % mod; a = (a * a) % mod; e >>= 1; } return res; } static long nc(int n, int r) { if (n < r) return 0; long v = fac[n]; v *= Pow(fac[r], mod - 2, mod); v %= mod; v *= Pow(fac[n - r], mod - 2, mod); v %= mod; return v; } public static boolean isprime(long a) { if (a == 0 || a == 1) { return false; } if (a == 2) { return true; } for (int i = 2; i < Math.sqrt(a) + 1; i++) { if (a % i == 0) { return false; } } return true; } public static boolean isPal(String s) { boolean t = true; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) != s.charAt(s.length() - 1 - i)) { t = false; break; } } return t; } public static long RandomPick(long[] a) { int n = a.length; int r = rn.nextInt(n); return a[r]; } public static int RandomPick(int[] a) { int n = a.length; int r = rn.nextInt(n); return a[r]; } public static void PH(String s, boolean reverse) { prelen = s.length(); HashsArray[HashsArrayInd] = new int[prelen + 1]; prepow = new int[prelen]; if (HashsArrayInd == 0) { int[] mods = { 1173017693, 1173038827, 1173069731, 1173086977, 1173089783, 1173092147, 1173107093, 1173114391, 1173132347, 1173144367, 1173150103, 1173152611, 1173163993, 1173174127, 1173204679, 1173237343, 1173252107, 1173253331, 1173255653, 1173260183, 1173262943, 1173265439, 1173279091, 1173285331, 1173286771, 1173288593, 1173298123, 1173302129, 1173308827, 1173310451, 1173312383, 1173313571, 1173324371, 1173361529, 1173385729, 1173387217, 1173387361, 1173420799, 1173421499, 1173423077, 1173428083, 1173442159, 1173445549, 1173451681, 1173453299, 1173454729, 1173458401, 1173459491, 1173464177, 1173468943, 1173470041, 1173477947, 1173500677, 1173507869, 1173522919, 1173537359, 1173605003, 1173610253, 1173632671, 1173653623, 1173665447, 1173675577, 1173675787, 1173684683, 1173691109, 1173696907, 1173705257, 1173705523, 1173725389, 1173727601, 1173741953, 1173747577, 1173751499, 1173759449, 1173760943, 1173761429, 1173762509, 1173769939, 1173771233, 1173778937, 1173784637, 1173793289, 1173799607, 1173802823, 1173808003, 1173810919, 1173818311, 1173819293, 1173828167, 1173846677, 1173848941, 1173853249, 1173858341, 1173891613, 1173894053, 1173908039, 1173909203, 1173961541, 1173968989, 1173999193}; mod = RandomPick(mods); int[] primes = { 59, 61, 67, 71, 73, 79, 83, 89, 97, 101 }; prime = RandomPick(primes); } prepow[0] = 1; if (!reverse) { for (int i = 1; i < prelen; i++) { prepow[i] = (int) ((1l * prepow[i - 1] * prime) % mod); } for (int i = 0; i < prelen; i++) { if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z') HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i] + ((1l * s.charAt(i) - 'a' + 1) * prepow[i]) % mod) % mod); else HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i] + ((1l * s.charAt(i) - 'A' + 27) * prepow[i]) % mod) % mod); } } else { for (int i = 1; i < prelen; i++) { prepow[i] = (int) ((1l * prepow[i - 1] * prime) % mod); } for (int i = 0; i < prelen; i++) { if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z') HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i] + ((1l * s.charAt(i) - 'a' + 1) * prepow[prelen - 1 - i]) % mod) % mod); else HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i] + ((1l * s.charAt(i) - 'A' + 27) * prepow[prelen - 1 - i]) % mod) % mod); } } HashsArrayInd++; } public static int PHV(int l, int r, int n, boolean reverse) { if (l > r) { return 0; } int val = (int) ((1l * HashsArray[n - 1][r] + mod - HashsArray[n - 1][l - 1]) % mod); if (!reverse) { val = (int) ((1l * val * prepow[prelen - l]) % mod); } else { val = (int) ((1l * val * prepow[r - 1]) % mod); } return val; } static int[][] HashsArray; static int HashsArrayInd = 0; static int[] prepow; static int prelen = 0; static int prime = 31; static long fac[]; static int mod = 998244353; static Random rn = new Random(); static Scanner sc = new Scanner(System.in); static PrintWriter pw = new PrintWriter(System.out); }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; signed main() { cin.tie(nullptr)->sync_with_stdio(false); long long t; cin >> t; while (t--) { long long n, l, r; cin >> n >> l >> r; long long mv = 0; bool b = false; for (long long i = 1; i <= n; i++) { long long nxt = i == 1 ? 1 : (i - 1) * 2; if (!(l > mv + nxt || r < mv + 1)) { b = true; for (long long j = max(1ll, l - mv); j <= min(r - mv, nxt); j++) { if (j == nxt) cout << "1 "; else if (j & 1) cout << i << " "; else cout << j / 2 + 1 << " "; } } mv += nxt; } if (b) cout << "\n"; } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long x, y, e; void solve(long long n, long long l) { long long i, sum = 0; for (i = 1; i < n; i++) { if (l <= sum + 2 * (n - i)) break; else sum += 2 * (n - i); } l -= sum; x = i; if (l % 2) { e = 1; y = i; return; } long long ans = i; for (i = 1; i <= l / 2; i++) ans++; y = ans; e = 2; return; } int main() { ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); long long t, n, l, r, i, k, a, b; cin >> t; while (t--) { cin >> n >> l >> r; e = 0; long long oh_bhai = n * (n - 1) + 1; if (oh_bhai == l) cout << "1\n"; else { solve(n, l); if (e == 1) { long long f = 0; for (i = l; i <= r; i++) { if (i == oh_bhai) cout << "1"; else if (f == 0) { f = 1; cout << x << " "; } else { f = 0; cout << y << " "; y++; if (y == n + 1) { x += 1; y = x + 1; } } } } else { long long f = 1; for (i = l; i <= r; i++) { if (i == oh_bhai) cout << "1"; else if (f == 0) { f = 1; cout << x << " "; } else { f = 0; cout << y << " "; y++; if (y == n + 1) { ++x; y = x + 1; } } } } } cout << "\n"; } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.util.*; import java.io.*; public class Solution{ static PrintWriter out=new PrintWriter(System.out); public static void main (String[] args) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] input=br.readLine().trim().split(" "); int numTestCases=Integer.parseInt(input[0]); while(numTestCases-->0){ input=br.readLine().trim().split(" "); int n=Integer.parseInt(input[0]); long l=Long.parseLong(input[1]); long r=Long.parseLong(input[2]); printSequence(n,l,r); } out.flush(); out.close(); } public static void printSequence(int n,long l,long r) { long totalElements=0; int blockNumber=-1; for(int i=1;i<n;i++){ totalElements+=2L*(n-i); if(totalElements>l) { totalElements-=2L*(n-i); blockNumber=i; break; } } ArrayList<Integer> ans=new ArrayList<>(); long pos=totalElements+1; for(int b=blockNumber;b<n && blockNumber!=-1;b++){ for(int i=b+1;i<=n;i++){ int currNumber=b; if(pos>=l && pos<=r){ ans.add(currNumber); } pos++; currNumber=i; if(pos>=l && pos<=r){ ans.add(currNumber); } pos++; } if(pos>r){ break; } } if(pos==r && r==1L*n*(n-1)+1) { ans.add(1); } for(int i=0;i<ans.size();i++){ out.print(ans.get(i)+" "); } out.println(); } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.util.*; import java.util.stream.*; import java.io.*; import java.math.*; public class Main { static boolean FROM_FILE = false; static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { if (FROM_FILE) { try { br = new BufferedReader(new FileReader("input.txt")); } catch (IOException error) { } } else { br = new BufferedReader(new InputStreamReader(System.in)); } } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static int max(int... nums) { int res = Integer.MIN_VALUE; for (int num: nums) res = Math.max(res, num); return res; } static int min(int... nums) { int res = Integer.MAX_VALUE; for (int num: nums) res = Math.min(res, num); return res; } static long max(long... nums) { long res = Long.MIN_VALUE; for (long num: nums) res = Math.max(res, num); return res; } static long min(long... nums) { long res = Long.MAX_VALUE; for (long num: nums) res = Math.min(res, num); return res; } static FastReader fr = new FastReader(); static PrintWriter out; public static void main(String[] args) { if (FROM_FILE) { try { out = new PrintWriter(new FileWriter("output.txt")); } catch (IOException error) { } } else { out = new PrintWriter(new OutputStreamWriter(System.out)); } new Main().run(); out.flush(); out.close(); } long getLevel(long n, long idx) { for (long i = 1; i <= n; i += 1) { if ((2 * n - 1 - i) * i >= idx) return i; } return -1; } void run() { int t = fr.nextInt(); while (t-- > 0) { long n = fr.nextLong(), l = fr.nextLong(), r = fr.nextLong(); if (l == n * (n - 1) + 1) { out.println(1); return; } int len = (int)(r - l) + 1; long[] res = new long[len]; int idx = 0; long k = getLevel(n, l), pre = (2 * n - 1 - (k - 1)) * (k - 1), col = k + (l - pre) / 2; if ((l - pre) % 2 == 0) res[idx++] = col; // out.println(col); for (long i = col + 1; i <= n && idx + 1 < len; i += 1) { res[idx++] = k; res[idx++] = i; } // out.println(Arrays.toString(res)); boolean finalOne = false; if (r == n * (n - 1) + 1) { r -= 1; finalOne = true; } long k2 = getLevel(n, r); // out.println(k + " " + k2); for (long level = k + 1; level < k2; level += 1) { for (long i = level + 1; i <= n; i += 1) { res[idx++] = level; res[idx++] = i; } } // out.println(Arrays.toString(res)); long last_x = k2, last_y = last_x + 1; while (idx + 1 < len) { res[idx++] = last_x; res[idx++] = last_y++; } if (idx < len) { res[idx] = finalOne ? 1 : last_x; } out.println(LongStream.of(res).mapToObj(e -> "" + e).collect(Collectors.joining(" "))); } } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; void f(const int offset, const int n, const int l, const int r) { if (l > r || n == 1) return; const int c = 2 * (n - 1); if (r >= 1 && l <= c) { for (int i = 1; i <= c; ++i) if (l <= i && i <= r) cout << (i & 1 ? offset : i / 2 + offset) << ' '; } f(offset + 1, n - 1, l - c, r - c); } void f() { int n, l, r; cin >> n >> l >> r; f(1, n, l, r); cout << "1\n"; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); int t; cin >> t; while (t--) f(); return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
// Magic. Do not touch. import java.io.*; import java.math.*; import java.util.*; public class Main { static class FastReader { private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public FastReader() { this(System.in); }public FastReader(InputStream is) { mIs = is;} public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];} public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;} public String next(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();} public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;} public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;} public double d() throws IOException {return Double.parseDouble(next()) ;} public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public void scanIntArr(int [] arr){ for(int li=0;li<arr.length;++li){ arr[li]=i();}} public void scanIntIndexArr(int [] arr){ for(int li=0;li<arr.length;++li){ arr[li]=i()-1;}} public void scanLongArr(long [] arr){for (int i=0;i<arr.length;++i){arr[i]=l();}} public void shuffle(int [] arr){ for(int i=arr.length;i>0;--i) { int r=(int)(Math.random()*i); int temp=arr[i-1]; arr[i-1]=arr[r]; arr[r]=temp; } } public int swapIntegers(int a,int b){return a;} //Call it like this: a=swapIntegers(b,b=a) } public static void main(String[] args) throws IOException { FastReader fr = new FastReader(); PrintWriter pw = new PrintWriter(System.out); /* inputCopy 3 2 1 3 3 3 6 99995 9998900031 9998900031 outputCopy 1 2 1 1 3 2 3 1 2 3 1 6 1 1 1 3 3 6 7 3 6 6 3 7 7 4 100000 9999899997 9999900001 100000 9999899998 9999900001 10 87 91 10 86 91 */ //Press Ctrl+Win+Alt+L for reformatting indentation int t = fr.i(); for (int ti = 0; ti < t; ++ti) { int n=fr.i(); long l=fr.l(); long r=fr.l(); long cur=n-1; long l2=l; while(l2-2L*cur>0 && cur!=0){ l2-=2L*cur; --cur; } long i=n-cur; long rem=(l2-1)/2; long i2=i+1+rem; long toPrint=r-l+1; if(l%2==0) { pw.print(i2+" "); ++i2; if(i2>n) { ++i; i2=i+1; --toPrint; } } //System.err.println("i="+i+" i2="+i2); for(;i<=n;++i) { for(;i2<=n && toPrint>0;++i2) { if(toPrint>=2) pw.print(i+" "+i2+" "); else pw.print(i+" "); toPrint-=2; } i2=i+2; } if(toPrint>0) { pw.print(1+" "); } pw.println(); } pw.flush(); pw.close(); } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { long long n, l, r; scanf("%lld%lld%lld", &n, &l, &r); int flag = 0; long long now = l >> 1; if (l % 2 == 0) { flag = 2; } else { flag = 1; } long long head = -1; for (int i = 1; i < n; ++i) { now -= n - i; if (now < 0) { head = i; now += n - i; now = head + 1 + now; break; } } if (head == -1) { printf("1\n"); continue; } int flag1 = 0; int sum = r - l + 1; while (sum--) { if (flag == 1) { if (head == n) { flag1 = 1; break; } printf("%lld ", head); flag = 2; } else if (flag == 2) { printf("%lld ", now); flag = 1; if (now == n) { head += 1; now = head + 1; } else { now++; } } } if (flag1) { printf("1\n"); continue; } printf("\n"); } return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
python3
test = int(input()) for _ in range(test): n , l , r = [int(x) for x in input().split()] start = 1 it = 1 if l == n*(n-1) + 1: print('1') continue while start < l: start += (n-it)*2 it += 1 if start != l: it -= 1 start -= (n - it)*2 a = it b = it+1 ok = True while start < l: if ok: ok = False else: ok = True b += 1 start += 1 # print(a , b , ok , '--------------------------') while start <= r: if r == n*(n-1) + 1: print('1' , end=' ') break if b == n+1: a += 1 b = a+1 if ok: print(a , end=' ') ok = False else: print(b , end=' ') b += 1 ok = True # ok != ok start += 1 print()
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { long long n, l, r; scanf("%lld%lld%lld", &n, &l, &r); int flag = 0; long long now = l >> 1; if (l % 2 == 0) { flag = 2; } else { flag = 1; } long long head = -1; for (int i = 1; i < n; ++i) { now -= n - i; if (now < 0) { head = i; now += n - i; now = head + 1 + now; break; } } if (head == -1) { printf("1\n"); continue; } int flag1 = 0; int sum = l - r + 1; while (sum--) { if (flag == 1) { if (head == n) { flag1 = 1; break; } printf("%lld ", head); flag = 2; } else if (flag == 2) { printf("%lld ", now); flag = 1; if (now == n) { head += 1; now = head + 1; } else { now++; } } } if (flag1) { printf("1\n"); continue; } printf("\n"); } return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.util.*; import java.io.*; import java.time.Period; public class codeforces { public static void main(String[] args) throws Exception { int t=sc.nextInt(); while(t-->0) { long n=sc.nextLong(); long l=sc.nextLong(); long r=sc.nextLong(); long number =2; long i=1; while(l-i*2>0) { number++; l-=i*2; r-=i*2; i++; } for(;l<=r;l++) { if(1l*l%2==0) { pw.print(number+" "); }else { pw.print((l+1)/2+" "); } if(1l*l-i*2>=0) { l-=i*2; r-=i*2; i++; number++; } } pw.println(); } pw.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextLongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } static class pair implements Comparable<pair> { double x; double y; public pair(int x, int y) { this.x = x; this.y = y; } public String toString() { return x + " " + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair)o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Double(x).hashCode() * 31 + new Double(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return (int) (this.y - other.y); } else { return (int) (this.x - other.x); } } } static class tuble implements Comparable<tuble> { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + " " + y + " " + z; } public int compareTo(tuble other) { if (this.x == other.x) { return this.y - other.y; } else { return this.x - other.x; } } } public static long GCD(long a, long b) { if (b == 0) return a; if (a == 0) return b; return (a > b) ? GCD(a % b, b) : GCD(a, b % a); } public static long LCM(long a, long b) { return a * b / GCD(a, b); } static long Pow(long a, int e, int mod) // O(log e) { a %= mod; long res = 1; while (e > 0) { if ((e & 1) == 1) res = (res * a) % mod; a = (a * a) % mod; e >>= 1; } return res; } static long nc(int n, int r) { if (n < r) return 0; long v = fac[n]; v *= Pow(fac[r], mod - 2, mod); v %= mod; v *= Pow(fac[n - r], mod - 2, mod); v %= mod; return v; } public static boolean isprime(long a) { if (a == 0 || a == 1) { return false; } if (a == 2) { return true; } for (int i = 2; i < Math.sqrt(a) + 1; i++) { if (a % i == 0) { return false; } } return true; } public static boolean isPal(String s) { boolean t = true; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) != s.charAt(s.length() - 1 - i)) { t = false; break; } } return t; } public static long RandomPick(long[] a) { int n = a.length; int r = rn.nextInt(n); return a[r]; } public static int RandomPick(int[] a) { int n = a.length; int r = rn.nextInt(n); return a[r]; } public static void PH(String s, boolean reverse) { prelen = s.length(); HashsArray[HashsArrayInd] = new int[prelen + 1]; prepow = new int[prelen]; if (HashsArrayInd == 0) { int[] mods = { 1173017693, 1173038827, 1173069731, 1173086977, 1173089783, 1173092147, 1173107093, 1173114391, 1173132347, 1173144367, 1173150103, 1173152611, 1173163993, 1173174127, 1173204679, 1173237343, 1173252107, 1173253331, 1173255653, 1173260183, 1173262943, 1173265439, 1173279091, 1173285331, 1173286771, 1173288593, 1173298123, 1173302129, 1173308827, 1173310451, 1173312383, 1173313571, 1173324371, 1173361529, 1173385729, 1173387217, 1173387361, 1173420799, 1173421499, 1173423077, 1173428083, 1173442159, 1173445549, 1173451681, 1173453299, 1173454729, 1173458401, 1173459491, 1173464177, 1173468943, 1173470041, 1173477947, 1173500677, 1173507869, 1173522919, 1173537359, 1173605003, 1173610253, 1173632671, 1173653623, 1173665447, 1173675577, 1173675787, 1173684683, 1173691109, 1173696907, 1173705257, 1173705523, 1173725389, 1173727601, 1173741953, 1173747577, 1173751499, 1173759449, 1173760943, 1173761429, 1173762509, 1173769939, 1173771233, 1173778937, 1173784637, 1173793289, 1173799607, 1173802823, 1173808003, 1173810919, 1173818311, 1173819293, 1173828167, 1173846677, 1173848941, 1173853249, 1173858341, 1173891613, 1173894053, 1173908039, 1173909203, 1173961541, 1173968989, 1173999193}; mod = RandomPick(mods); int[] primes = { 59, 61, 67, 71, 73, 79, 83, 89, 97, 101 }; prime = RandomPick(primes); } prepow[0] = 1; if (!reverse) { for (int i = 1; i < prelen; i++) { prepow[i] = (int) ((1l * prepow[i - 1] * prime) % mod); } for (int i = 0; i < prelen; i++) { if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z') HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i] + ((1l * s.charAt(i) - 'a' + 1) * prepow[i]) % mod) % mod); else HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i] + ((1l * s.charAt(i) - 'A' + 27) * prepow[i]) % mod) % mod); } } else { for (int i = 1; i < prelen; i++) { prepow[i] = (int) ((1l * prepow[i - 1] * prime) % mod); } for (int i = 0; i < prelen; i++) { if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z') HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i] + ((1l * s.charAt(i) - 'a' + 1) * prepow[prelen - 1 - i]) % mod) % mod); else HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i] + ((1l * s.charAt(i) - 'A' + 27) * prepow[prelen - 1 - i]) % mod) % mod); } } HashsArrayInd++; } public static int PHV(int l, int r, int n, boolean reverse) { if (l > r) { return 0; } int val = (int) ((1l * HashsArray[n - 1][r] + mod - HashsArray[n - 1][l - 1]) % mod); if (!reverse) { val = (int) ((1l * val * prepow[prelen - l]) % mod); } else { val = (int) ((1l * val * prepow[r - 1]) % mod); } return val; } static int[][] HashsArray; static int HashsArrayInd = 0; static int[] prepow; static int prelen = 0; static int prime = 31; static long fac[]; static int mod = 998244353; static Random rn = new Random(); static Scanner sc = new Scanner(System.in); static PrintWriter pw = new PrintWriter(System.out); }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class TaskD { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; PrintWriter pw = new PrintWriter(System.out); try { int t = Integer.parseInt(br.readLine()); while(t-->0) { st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); long l = Long.parseLong(st.nextToken()); long r = Long.parseLong(st.nextToken()); long ind = 0; ArrayList<Integer> al = new ArrayList<>(); for(int i=0 ; i<n ; i++) { if(i == n-1) { if(ind+1 == r) { al.add(1); } } else { long clen = (n-i-1)*2; long beg = ind+1; long end = ind+clen-1; if(beg <= l && end >= r) { int[] a = new int[(int)clen]; int x = i+1; int y = i+2; for(int j=0 ; j<clen ; j++) { if(j%2 == 0) a[j] = x; else { a[j] = y; y++; } } int starts = (int)(l-beg); int ends = (int)(r-beg+1); for(int j=starts ; j<=ends ; j++) { al.add(a[j]); } } else if(beg > l && end < r) { int[] a = new int[(int)clen]; int x = i+1; int y = i+2; for(int j=0 ; j<clen ; j++, y++) { if(j%2 == 0) a[j] = x; else { a[j] = y; y++; } } int starts = (int)(beg-beg); int ends = (int)(end-beg+1); for(int j=starts ; j<=ends ; j++) { al.add(a[j]); } } else if(beg <= l && end < r && end >= l) { int[] a = new int[(int)clen]; int x = i+1; int y = i+2; for(int j=0 ; j<clen ; j++, y++) { if(j%2 == 0) a[j] = x; else { a[j] = y; y++; } } int starts = (int)(l-beg); int ends = (int)(end-beg+1); for(int j=starts ; j<=ends ; j++) { al.add(a[j]); } } else if(beg > l && end >= r && r >= beg) { int[] a = new int[(int)clen]; int x = i+1; int y = i+2; for(int j=0 ; j<clen ; j++, y++) { if(j%2 == 0) a[j] = x; else { a[j] = y; y++; } } int starts = (int)(beg-beg); int ends = (int)(r-beg+1); for(int j=starts ; j<=ends ; j++) { al.add(a[j]); } } ind += clen; } } for(int i=0 ; i<al.size() ; i++) { pw.print(al.get(i) + " "); } pw.println(); } } finally { pw.flush(); pw.close(); } } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
python3
# ---------------------------iye ha aam zindegi--------------------------------------------- import math import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction import sys mod = 10 ** 9 + 7 mod1 = 998244353 # ------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # -------------------game starts now----------------------------------------------------import math class TreeNode: def __init__(self, k, v): self.key = k self.value = v self.left = None self.right = None self.parent = None self.height = 1 self.num_left = 1 self.num_total = 1 class AvlTree: def __init__(self): self._tree = None def add(self, k, v): if not self._tree: self._tree = TreeNode(k, v) return node = self._add(k, v) if node: self._rebalance(node) def _add(self, k, v): node = self._tree while node: if k < node.key: if node.left: node = node.left else: node.left = TreeNode(k, v) node.left.parent = node return node.left elif node.key < k: if node.right: node = node.right else: node.right = TreeNode(k, v) node.right.parent = node return node.right else: node.value = v return @staticmethod def get_height(x): return x.height if x else 0 @staticmethod def get_num_total(x): return x.num_total if x else 0 def _rebalance(self, node): n = node while n: lh = self.get_height(n.left) rh = self.get_height(n.right) n.height = max(lh, rh) + 1 balance_factor = lh - rh n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right) n.num_left = 1 + self.get_num_total(n.left) if balance_factor > 1: if self.get_height(n.left.left) < self.get_height(n.left.right): self._rotate_left(n.left) self._rotate_right(n) elif balance_factor < -1: if self.get_height(n.right.right) < self.get_height(n.right.left): self._rotate_right(n.right) self._rotate_left(n) else: n = n.parent def _remove_one(self, node): """ Side effect!!! Changes node. Node should have exactly one child """ replacement = node.left or node.right if node.parent: if AvlTree._is_left(node): node.parent.left = replacement else: node.parent.right = replacement replacement.parent = node.parent node.parent = None else: self._tree = replacement replacement.parent = None node.left = None node.right = None node.parent = None self._rebalance(replacement) def _remove_leaf(self, node): if node.parent: if AvlTree._is_left(node): node.parent.left = None else: node.parent.right = None self._rebalance(node.parent) else: self._tree = None node.parent = None node.left = None node.right = None def remove(self, k): node = self._get_node(k) if not node: return if AvlTree._is_leaf(node): self._remove_leaf(node) return if node.left and node.right: nxt = AvlTree._get_next(node) node.key = nxt.key node.value = nxt.value if self._is_leaf(nxt): self._remove_leaf(nxt) else: self._remove_one(nxt) self._rebalance(node) else: self._remove_one(node) def get(self, k): node = self._get_node(k) return node.value if node else -1 def _get_node(self, k): if not self._tree: return None node = self._tree while node: if k < node.key: node = node.left elif node.key < k: node = node.right else: return node return None def get_at(self, pos): x = pos + 1 node = self._tree while node: if x < node.num_left: node = node.left elif node.num_left < x: x -= node.num_left node = node.right else: return (node.key, node.value) raise IndexError("Out of ranges") @staticmethod def _is_left(node): return node.parent.left and node.parent.left == node @staticmethod def _is_leaf(node): return node.left is None and node.right is None def _rotate_right(self, node): if not node.parent: self._tree = node.left node.left.parent = None elif AvlTree._is_left(node): node.parent.left = node.left node.left.parent = node.parent else: node.parent.right = node.left node.left.parent = node.parent bk = node.left.right node.left.right = node node.parent = node.left node.left = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) def _rotate_left(self, node): if not node.parent: self._tree = node.right node.right.parent = None elif AvlTree._is_left(node): node.parent.left = node.right node.right.parent = node.parent else: node.parent.right = node.right node.right.parent = node.parent bk = node.right.left node.right.left = node node.parent = node.right node.right = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) @staticmethod def _get_next(node): if not node.right: return node.parent n = node.right while n.left: n = n.left return n # -----------------------------------------------binary seacrh tree--------------------------------------- class SegmentTree1: def __init__(self, data, default='z', func=lambda a, b: min(a, b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------game starts now----------------------------------------------------import math class SegmentTree: def __init__(self, data, default=0, func=lambda a, b: a + b): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------------------iye ha chutiya zindegi------------------------------------- class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD # --------------------------------------iye ha combinations ka zindegi--------------------------------- def powm(a, n, m): if a == 1 or n == 0: return 1 if n % 2 == 0: s = powm(a, n // 2, m) return s * s % m else: return a * powm(a, n - 1, m) % m # --------------------------------------iye ha power ka zindegi--------------------------------- def sort_list(list1, list2): zipped_pairs = zip(list2, list1) z = [x for _, x in sorted(zipped_pairs)] return z # --------------------------------------------------product---------------------------------------- def product(l): por = 1 for i in range(len(l)): por *= l[i] return por # --------------------------------------------------binary---------------------------------------- def binarySearchCount(arr, n, key): left = 0 right = n - 1 count = 0 while (left <= right): mid = int((right + left) / 2) # Check if middle element is # less than or equal to key if (arr[mid] < key): count = mid + 1 left = mid + 1 # If key is smaller, ignore right half else: right = mid - 1 return count # --------------------------------------------------binary---------------------------------------- def countdig(n): c = 0 while (n > 0): n //= 10 c += 1 return c def binary(x, length): y = bin(x)[2:] return y if len(y) >= length else "0" * (length - len(y)) + y def countGreater(arr, n, k): l = 0 r = n - 1 # Stores the index of the left most element # from the array which is greater than k leftGreater = n # Finds number of elements greater than k while (l <= r): m = int(l + (r - l) / 2) if (arr[m] >= k): leftGreater = m r = m - 1 # If mid element is less than # or equal to k update l else: l = m + 1 # Return the count of elements # greater than k return (n - leftGreater) # --------------------------------------------------binary------------------------------------ for ik in range(int(input())): n,l,rw=map(int,input().split()) k=[i for i in range(l,rw+1)] even=[] odd=[] for i in range(len(k)): if k[i]%2==0: even.append(k[i]//2) else: odd.append(k[i]//2+1) #print(odd,even) if odd!=[]: st=odd[0] n=0 r=0 n1=100000000 while(n<=n1): mid=(n+n1)//2 if (mid*(mid+1))//2==st: r=mid break elif (mid*(mid+1))//2<st: r=mid n=mid+1 else: n1=mid-1 tr=-(r*(r+1))//2+odd[0] cop=r if tr==0: tr=r r-=1 r+=1 #print(r,tr) for i in range(len(odd)): odd[i]=tr tr+=1 if tr>r: tr=1 r+=1 if even!=[]: st = even[0] n = 0 r = 0 n1 = 100000000 while (n <= n1): mid = (n + n1) // 2 if (mid * (mid + 1)) // 2 == st: r = mid break elif (mid * (mid + 1)) // 2 < st: r = mid n = mid + 1 else: n1 = mid - 1 cop=r if even[0]==(r*(r+1))//2: cop-=1 r+=1 else: r+=2 times=r-1-(even[0]-(cop*(cop+1))//2)+1 #print(r,times,cop) for i in range(len(even)): even[i]=r times-=1 if times==0: times=r r+=1 t=1 if l%2==1: t=0 ans=[] r=0 r1=0 #print(odd,even,l,r) for i in range(l,rw+1): if t%2==0: ans.append(odd[r]) r+=1 else: ans.append(even[r1]) r1+=1 t+=1 print(*ans)
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
python3
import collections, math, bisect local = False if local: file = open("input.txt", "r") import time def inp(): if local: return file.readline().rstrip() else: return input().rstrip() def ints(): return [int(_) for _ in inp().split()] if local: start=time.time() t = int(inp()) for _ in range(1,t+1): n, l, r = ints() if l==1: edge = 1 vert = 1 else: edge = 2 vert = 2 while edge<l: edge+=2*(vert-1) vert+=1 if edge>l: vert-=1 edge-=2*(vert-1) break ans = [] while edge<=r: if vert==1: if edge>=l: ans.append(1) vert=2 edge=2 continue for v in range(vert-1,0,-1): if edge>=l: ans.append(vert) edge+=1 if edge>r: break if edge>=l: ans.append(v) edge+=1 if edge>r: break vert+=1 print(" ".join([str(_) for _ in ans])) if local: fin = (time.time()-start)*1000 print("{:.2f}".format(fin) + "ms")
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.util.*; import java.io.*; public class Main { static FastReader in=new FastReader(); static StringBuilder Sd=new StringBuilder(); static List<Integer>Gr[]; static long Mod=998244353; static Map<Integer,Integer>map=new HashMap<>(); public static void main(String [] args) { //Dir by MohammedElkady int t=in.nextInt(); while(t-->0) { long n=in.nextLong(),l=in.nextLong(),r=in.nextLong(); long ans=1,res=0; l-=1;r-=1; int lol=0; if(r>=n*(n-1)) {lol=1;r--; } for(long i=1;i<=n;i++) { ans=i; if(res+((n-i)*2)<l) { res+=(n-i)*2; }else break; } long vov=ans+1; if(!(lol>0&&l>r)) for(;l<=r;) { if(res>l) { Sout(vov-1+" "); l++; } if(res==l) { if(vov>n) { ans+=1;vov=ans+1; } Sout(ans+" "); if(r-l>0) {Soutln(vov+" ");} vov++; res+=2; l+=2; } else { vov++; res+=2; } } if(lol>0) {Soutln("1 ");} else Soutln(""); } Sclose(); } static long power(long x, long y, long p) { // Initialize result long res = 1; // Update x if it is more than or // equal to p x = x % p; while (y > 0) { // If y is odd, multiply x // with result if (y % 2 == 1) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } // Returns n^(-1) mod p static long modInverse(long n, long p) { return power(n, p-2, p); } // Returns nCr % p using Fermat's // little theorem. static long nCrModPFermat(int n, int r, long p) { // Base case if (r == 0) return 1; // Fill factorial array so that we // can find all factorial of r, n // and n-r long[] fac = new long[n+1]; fac[0] = 1; for (int i = 1 ;i <= n; i++) fac[i] = fac[i-1] * i % p; return (fac[n]* modInverse(fac[r], p) % p * modInverse(fac[n-r], p) % p) % p; } static long fac(int n , int m,int l) { long res=1; for(int i=l,u=1;i<=n||u<=m;i++,u++) { if(i<=n) {res*=i;} if(u<=m) {res/=u;} while(res>Mod) res-=Mod; } return res; } static long posation(int n) { long res=1; for(int i=0;i<n-3;i++) {res*=2L; while(res>Mod) res-=Mod; while(res<=0)res+=Mod;} return res; } static long gcd(long g,long x){ if(x<1)return g; else return gcd(x,g%x); } //array fill static long[]filllong(int n){long a[]=new long[n];for(int i=0;i<n;i++)a[i]=in.nextLong();return a;} static int[]fillint(int n){int a[]=new int[n];for(int i=0;i<n;i++)a[i]=in.nextInt();return a;} //OutPut Line static void Sout(String S) {Sd.append(S);} static void Soutln(String S) {Sd.append(S+"\n");} static void Soutf(String S) {Sd.insert(0, S);} static void Sclose() {System.out.println(Sd);} static void Sclean() {Sd=new StringBuilder();} } class node implements Comparable<node>{ int x,t; node(int x,int p){ this.x=x; this.t=p; } @Override public int compareTo(node o) { return (t-o.t); } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } class Sorting{ public static node[] bucketSort(node[] array, int bucketCount) { if (bucketCount <= 0) throw new IllegalArgumentException("Invalid bucket count"); if (array.length <= 1) return array; //trivially sorted int high = array[0].t; int low = array[0].t; for (int i = 1; i < array.length; i++) { //find the range of input elements if (array[i].t > high) high = array[i].t; if (array[i].t < low) low = array[i].t; } double interval = ((double)(high - low + 1))/bucketCount; //range of one bucket ArrayList<node> buckets[] = new ArrayList[bucketCount]; for (int i = 0; i < bucketCount; i++) { //initialize buckets buckets[i] = new ArrayList(); } for (int i = 0; i < array.length; i++) { //partition the input array buckets[(int)((array[i].t - low)/interval)].add(array[i]); } int pointer = 0; for (int i = 0; i < buckets.length; i++) { Collections.sort(buckets[i]); //mergeSort for (int j = 0; j < buckets[i].size(); j++) { //merge the buckets array[pointer] = buckets[i].get(j); pointer++; } } return array; } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, l, r; cin >> n >> l >> r; int grupo = 0; int cont = 1; int nPassados = l; bool flag1 = false; if (r == (n) * (n - 1) + 1) { flag1 = true; r--; } while (l - (2 * (n - cont)) > 0 && cont != n) { l -= 2 * (n - cont); cont++; grupo++; } l--; while (nPassados <= r) { vector<int> numsGrupo; for (int I = 0; I < n - grupo - 1; I++) { numsGrupo.push_back(grupo + 1); numsGrupo.push_back(grupo + I + 2); } for (int I = 0; I < numsGrupo.size(); I++) { if (l != 0) { l--; } else { if (nPassados <= r) { cout << numsGrupo[I] << " "; nPassados++; } } } grupo++; } if (flag1) { cout << 1 << " "; } cout << endl; } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; void upgrade() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); } long long nums[100100]; long long func(long long a) { return a * (a - 1); } int main() { upgrade(); int t; cin >> t; for (int zzz = 0; zzz < t; zzz++) { long long n, l, r; cin >> n >> l >> r; nums[0] = 0; if (n == 2) { int a[4] = {0, 1, 2, 1}; for (int i = l; i < r + 1; i++) { cout << a[i] << ' '; } cout << '\n'; continue; } long long cnt = 2 * n - 3; long long st; long long ind, mod, head, f, cur; bool c = 1; for (int i = 1; i < n + 10; i++) { nums[i] = nums[i - 1] + cnt; cnt -= 2; if (nums[i] >= l) { st = nums[i - 1]; ind = (long long)i; break; } if (cnt < 0) { c = 0; f = l - nums[i - 1]; break; } } if (c) { mod = (l - st) % 2; head = (ind == 1) ? 1 : (n + 2 - ind); f = mod; cur = (l - st - 1) / 2 + 2; } for (int i = 0; i < r - l + 1; i++) { if (f == 1) { cout << head << ' '; if (head == 1 && cur == n) { head = n; cur = 2; } else if (head == 3) { f = 2; } else if (head != 1 && cur == head - 1) { head--; cur = 2; } else { f = 0; } } else if (f == 0) { cout << cur << ' '; cur++; f = 1; } else { if (f != n + 1) cout << f << ' '; else cout << 1 << ' '; f++; } } cout << '\n'; } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
python3
import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # ------------------------------ from math import factorial from collections import Counter, defaultdict from heapq import heapify, heappop, heappush def RL(): return map(int, sys.stdin.readline().rstrip().split()) def N(): return int(input()) def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0 def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0 def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2) mod = 1000000007 INF = float('inf') # ------------------------------ def main(): def c(sm, a1): sm = n*a1+(n-1)*n for _ in range(N()): n, l, r = RL() i = n-1 sm = 0 while sm<l: sm+=i*2 if i>0 else 1 if sm>=l: break i-=1 dif = l-(sm-i*2) res = [] for j in range(n-i, n+1): now = [] for k in range(j+1, n+1): now.append(j) now.append(k) res+=now if len(res)>(r-k+1)+dif: break res = res[dif-1:] if r==(n-1)*n+1: res.append(1) print(*res) if __name__ == "__main__": main()
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long n) { a %= 1000000007; if (n == 1) return a; if (n == 0) return 1; if (n % 2) return (a * (power((a * a) % 1000000007, n / 2) % 1000000007)) % 1000000007; return power((a * a) % 1000000007, n / 2) % 1000000007; } const long long inf = (long long)1e18; long long inverse(long long x) { return power(x, 1000000007 - 2) % 1000000007; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { long long n, l, r; cin >> n >> l >> r; long long tot = 0, c = 1; long long lo = 1, hi = n - 1; while (lo < hi) { long long mid = (lo + hi) / 2; if (2 * n * mid - mid * (mid - 1) >= l) hi = mid; else lo = mid + 1; } long long cp = c + (l - tot + 1) / 2; while (l <= r && l < n * (n - 1) + 1) { if (l % 2) cout << c << " "; else { cout << cp << " "; cp++; } l++; if (cp > n) c++, cp = c + 1; } if (r == n * (n - 1) + 1) cout << 1 << " "; cout << "\n"; } return 0; }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
python3
import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # ------------------------------ from math import factorial from collections import Counter, defaultdict from heapq import heapify, heappop, heappush def RL(): return map(int, sys.stdin.readline().rstrip().split()) def N(): return int(input()) def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0 def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0 def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2) mod = 1000000007 INF = float('inf') # ------------------------------ def main(): def c(sm, a1): sm = n*a1+(n-1)*n for _ in range(N()): n, l, r = RL() i = n-1 sm = 0 while sm+i*2+1<l: sm+=i*2 if i>0 else 1 i-=1 dif = l-sm res = [] for j in range(n-i, n): now = [] for k in range(j+1, n+1): now.append(j) now.append(k) res+=now if len(res)>(r-k+1)+dif: break res = res[dif-1:] if r==(n-1)*n+1: res.append(1) print(*res) if __name__ == "__main__": main()
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
python3
import sys t=int(sys.stdin.readline()) for _ in range(t): n,l,r=map(int,sys.stdin.readline().split()) prev=0 cur=0 start=1 if l==r and l==n*(n-1)+1: print(1) else: ans=[] while(True): cur+=(n-start)*2 if l<=cur: pos=l-prev total=r-l+1 if(pos%2==1): ans.append(start) total-=1 x=start+pos//2 +1 while(total>0): ans.append(x) if x==n: start+=1 if start==n: start=1 x=start total-=1 if total>0: ans.append(start) total-=1 x+=1 else: x=start+pos//2 +1 while(total>0): ans.append(x) if x==n: start+=1 if start==n: start=1 x=start total-=1 if total>0: ans.append(start) total-=1 x+=1 break prev=cur start+=1 print(*ans)
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.util.*; import java.io.*; public class Main { public static void main(String args[]) {new Main().run();} FastReader in = new FastReader(); PrintWriter out = new PrintWriter(System.out); void run(){ for(int q=ni();q>0;q--) { work(); out.println(); } out.flush(); } long mod=998244353L; long inf=Long.MAX_VALUE; long gcd(long a,long b) { return a==0?b:gcd(b%a,a); } void work() { long n=nl(),l=nl(),r=nl(); long c=1; long sum=0; while(sum+(n-c)*2<l&&c<n) { sum+=(n-c)*2; c++; } // System.out.println(c); long c2=(l+1-sum)/2+c; if((l-sum)%2==0) { out.print(c2+" "); l++; c2++; if(c2>n) { c++; c2=c+1; } } while(l<=Math.min(n*(n-1), r)) { out.print(c+" "); l++; if(l>r)break; out.print(c2+" "); if(c2>=n) { c++; c2=c+1; } l++; } if(l<=r) { out.print(1+" "); } } //input @SuppressWarnings("unused") private ArrayList<Integer>[] ng(int n, int m) { ArrayList<Integer>[] graph=(ArrayList<Integer>[])new ArrayList[n]; for(int i=0;i<n;i++) { graph[i]=new ArrayList<>(); } for(int i=1;i<=m;i++) { int s=in.nextInt()-1,e=in.nextInt()-1; graph[s].add(e); graph[e].add(s); } return graph; } private ArrayList<long[]>[] ngw(int n, int m) { ArrayList<long[]>[] graph=(ArrayList<long[]>[])new ArrayList[n]; for(int i=0;i<n;i++) { graph[i]=new ArrayList<>(); } for(int i=1;i<=m;i++) { long s=in.nextLong()-1,e=in.nextLong()-1,w=in.nextLong(); graph[(int)s].add(new long[] {e,w,i}); graph[(int)e].add(new long[] {s,w}); } return graph; } private int ni() { return in.nextInt(); } private long nl() { return in.nextLong(); } private String ns() { return in.next(); } private long[] na(int n) { long[] A=new long[n]; for(int i=0;i<n;i++) { A[i]=in.nextLong(); } return A; } private int[] nia(int n) { int[] A=new int[n]; for(int i=0;i<n;i++) { A[i]=in.nextInt(); } return A; } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br=new BufferedReader(new InputStreamReader(System.in)); } public String next() { while(st==null || !st.hasMoreElements())//ε›žθ½¦οΌŒη©Ίθ‘Œζƒ…ε†΅ { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } }
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
python2
from __future__ import division, print_function # import threading # threading.stack_size(2**27) # import sys # sys.setrecursionlimit(10**7) from sys import stdin, stdout import bisect #c++ upperbound import math import heapq def modinv(n,p): return pow(n,p-2,p) def cin(): return map(int,sin().split()) def ain(): #takes array as input return list(map(int,sin().split())) def sin(): return input() def inin(): return int(input()) import math def Divisors(n) : l = [] for i in range(1, int(math.sqrt(n) + 1)) : if (n % i == 0) : if (n // i == i) : l.append(i) else : l.append(i) l.append(n//i) return l q=[] def dfs(n,d,v,c): global q v[n]=1 x=d[n] q.append(n) j=c for i in x: if i not in v: f=dfs(i,d,v,c+1) j=max(j,f) # print(f) return j """*******************************************************""" def main(): t=inin() for _ in range(t): n,j,k=cin() k-=j k+=1 a=[] for i in range(n): if(i==0): a.append(1) else: a.append(n-i+1) # print(a) x=2*(n-1) ll=1 for i in range(n): if(j-x<=1 or x==0): j-=1 break else: j-=x if(x!=2): j+=ll x-=2 # print(j) # print(i,j) p=[] while(len(p)<k+j and i<n): f=2 xx=x if(xx>0 and len(p)>0): p.pop() while(xx>0): p.append(a[i]) p.append(f) if len(p)>=k+j: break f+=1 xx-=2 x-=2 i+=1 if(len(p)<j+k): for jj in range(3,n+1): p.append(jj) p.append(1) # print(p,j) print(*p[j:k+j]) ######## Python 2 and 3 footer by Pajenegod and c1729 # Note because cf runs old PyPy3 version which doesn't have the sped up # unicode strings, PyPy3 strings will many times be slower than pypy2. # There is a way to get around this by using binary strings in PyPy3 # but its syntax is different which makes it kind of a mess to use. # So on cf, use PyPy2 for best string performance. py2 = round(0.5) if py2: from future_builtins import ascii, filter, hex, map, oct, zip range = xrange import os, sys from io import IOBase, BytesIO BUFSIZE = 8192 class FastIO(BytesIO): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self.writable = "x" in file.mode or "w" in file.mode self.write = super(FastIO, self).write if self.writable else None def _fill(self): s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0]) return s def read(self): while self._fill(): pass return super(FastIO,self).read() def readline(self): while self.newlines == 0: s = self._fill(); self.newlines = s.count(b"\n") + (not s) self.newlines -= 1 return super(FastIO, self).readline() def flush(self): if self.writable: os.write(self._fd, self.getvalue()) self.truncate(0), self.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable if py2: self.write = self.buffer.write self.read = self.buffer.read self.readline = self.buffer.readline else: self.write = lambda s:self.buffer.write(s.encode('ascii')) self.read = lambda:self.buffer.read().decode('ascii') self.readline = lambda:self.buffer.readline().decode('ascii') sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip('\r\n') # Cout implemented in Python import sys class ostream: def __lshift__(self,a): sys.stdout.write(str(a)) return self cout = ostream() endl = '\n' # Read all remaining integers in stdin, type is given by optional argument, this is fast def readnumbers(zero = 0): conv = ord if py2 else lambda x:x A = []; numb = zero; sign = 1; i = 0; s = sys.stdin.buffer.read() try: while True: if s[i] >= b'R' [0]: numb = 10 * numb + conv(s[i]) - 48 elif s[i] == b'-' [0]: sign = -1 elif s[i] != b'\r' [0]: A.append(sign*numb) numb = zero; sign = 1 i += 1 except:pass if s and s[-1] >= b'R' [0]: A.append(sign*numb) return A # threading.Thread(target=main).start() if __name__== "__main__": main()
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
python3
t = int(input()) for _ in range(t): n, l, r = map(int, input().split()) ans = [] memo_l = -1 for x in range(1, n): if (x - 1) * x < l <= x * (x + 1): memo_l = x if memo_l == -1: print(1) else: tmp = (memo_l - 1) * memo_l for k in range(memo_l, n): for i in range(1, 2 * k + 1): if i % 2 == 0: ad = k + 1 else: ad = (i + 1) // 2 tmp += 1 if tmp > r: break elif l <= tmp: ans.append(ad) if r == n * (n - 1) + 1: ans.append(1) print(*ans)
1334_D. Minimum Euler Cycle
You are given a complete directed graph K_n with n vertices: each pair of vertices u β‰  v in K_n have both directed edges (u, v) and (v, u); there are no self-loops. You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β€” a visiting order, where each (v_i, v_{i + 1}) occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r. Input The first line contains the single integer T (1 ≀ T ≀ 100) β€” the number of test cases. Next T lines contain test cases β€” one per line. The first and only line of each test case contains three integers n, l and r (2 ≀ n ≀ 10^5, 1 ≀ l ≀ r ≀ n(n - 1) + 1, r - l + 1 ≀ 10^5) β€” the number of vertices in K_n, and segment of the cycle to print. It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5. Output For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once. Example Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 Note In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1. In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
{ "input": [ "3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n" ], "output": [ "1 2 1 \n1 3 2 3 \n1 \n" ] }
{ "input": [ "1\n2 2 3\n", "1\n4 13 13\n", "1\n3 1 1\n", "10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n", "1\n3 7 7\n", "1\n25 30 295\n", "1\n4 12 13\n", "5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n", "1\n5 4 4\n" ], "output": [ "2 1 \n", "1 \n", "1 \n", "1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n", "1 \n", "16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n", "4 1 \n", "1 \n1 \n1 \n1 \n7 1 \n", "3 \n" ] }
IN-CORRECT
java
import java.util.*; import java.io.*; public class Solution{ static PrintWriter out=new PrintWriter(System.out); public static void main (String[] args) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] input=br.readLine().trim().split(" "); int numTestCases=Integer.parseInt(input[0]); while(numTestCases-->0){ input=br.readLine().trim().split(" "); int n=Integer.parseInt(input[0]); long l=Long.parseLong(input[1]); long r=Long.parseLong(input[2]); printSequence(n,l,r); } out.flush(); out.close(); } public static void printSequence(int n,long l,long r) { long totalElements=0; int blockNumber=-1; for(int i=1;i<n;i++){ totalElements+=2L*(n-i); if(totalElements>l) { totalElements-=2L*(n-i); blockNumber=i; break; } } ArrayList<Integer> ans=new ArrayList<>(); long pos=totalElements+1; int count=0; for(int b=blockNumber;b<n && pos<=r && blockNumber!=-1;b++){ for(int i=b+1;i<=n;i++){ int currNumber=b; if(pos>=l && pos<=r){ ans.add(currNumber); count++; } pos++; currNumber=i; if(pos>=l && pos<=r){ ans.add(currNumber); count++; } pos++; } } if(count<(r-l+1)) { ans.add(1); } for(int i=0;i<ans.size();i++){ out.print(ans.get(i)+" "); } out.println(); } }