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"
]
}
|
IN-CORRECT
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
long long st[300005], tot, n;
long long search(long long val) {
long long i = 1;
for (long long j = 25; j >= 0; j--) {
long long k = i + (1LL < j);
if (k <= n && st[k] <= val) {
i = k;
}
}
return i;
}
void solve() {
long long i, j, k, l, m, x, y, r;
scanf("%lld %lld %lld", &n, &l, &r);
st[1] = 1;
for (i = 2; i <= n; i++) {
st[i] = st[i - 1] + 2 * (n - i + 1);
}
tot = n * (n - 1) + 1;
long long pre;
if (l % 2 == 0) pre = search(l - 1);
for (i = l; i <= r; i++) {
if (i == tot)
printf("1");
else if (i % 2) {
pre = search(i);
printf("%lld ", pre);
} else {
y = pre + (i - st[pre] + 1) / 2;
printf("%lld ", y);
}
}
printf("\n");
return;
}
int32_t main() {
long long t;
t = 1;
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
|
python3
|
# ------------------- fast io --------------------
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")
# ------------------- fast io --------------------
for _ in range(int(input())):
n, l, r = map(int, input().split())
p1, p2 = 0, 0
if l == n**2 - n + 1:
print(1)
continue
else:
total = 2*(n-1)
x=1
while l>total:
x+=1
total += 2*(n-x)
total -= 2*(n-x)
ans = []
if not (l - total) % 2:
ans += [x+(l-total)//2]
if ans[-1] != n:
p1, p2 = x, ans[-1]
else:
p1, p2 = x+1, x+2
else:
p1, p2 = x, x+(l-total)//2+1
req = r-l+1
while len(ans) < req:
ans += [p1, p2]
#print(ans)
if p2 == n:
if p1 == n-1:
p1 = 1
else:
p1 += 1
p2 = p1+1
else:
p2 += 1
print(" ".join(str(ans[k]) for k in range(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
|
python3
|
import sys
#input = sys.stdin.readline
input = sys.stdin.buffer.readline
def main():
t = int(input())
for _ in range(t):
n, l, r = map(int, input().split())
s = 0
flagl = True
flagr = True
for i in range(2, n+1):
pre_s = s
if i == 2:
s += 3
else:
s += 2*i-2
if flagl:
if s >= l:
il = l - pre_s
bl = i
flagl = False
if flagr:
if s >= r:
ir = r - pre_s
br = i
flagr = False
#print(bl, il)
#print(br, ir)
il -= 1
ir -= 1
ans = []
for i in range(bl, br+1):
if i == 2:
temp = [1, 2, 1]
else:
temp = [0]*(2*i-2)
c = 2
for j in range(2*i-2):
if j%2 == 0:
temp[j] = i
else:
if j != 2*i-3:
temp[j] = c
c += 1
else:
temp[j] = 1
if i == bl:
ans += temp[il:]
elif i == br:
ans += temp[0:ir+1]
else:
ans += temp
print(*ans)
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 n, t, l, r, start, star, have;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
cin >> n >> l >> r;
have = 0;
star = start = n + 1;
for (long long i = 1; i <= n; i++)
if (2LL * n * i - i * (i + 1LL) >= l) {
start = i;
have = 2LL * n * (i - 1LL) - (i - 1LL) * i;
break;
}
for (long long i = start + 1; i <= n; i++)
if (have + 2 < l)
have += 2LL;
else {
have += 2LL;
if (have == l) {
cout << i << " ";
l++;
star = i + 1;
} else
star = i;
break;
}
for (long long i = start; i <= n; i++)
for (long long j = (i == start) ? star : i + 1; j <= n; j++) {
if (l == r) {
cout << i << " ";
i = n + 1;
break;
}
l += 2;
cout << i << " " << j << " ";
if (l > r) {
i = n + 1;
break;
}
}
if (r == n * (n - 1LL) + 1) cout << "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
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long T;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> T;
while (T--) {
long long n, l, r;
cin >> n >> l >> r;
long long k = (l + 1) / 2;
long long t = 1, p = 0;
while (p < k) p += (t++);
p *= 2;
t--;
long long cnt = n - t;
while (p < l) p += 2, cnt--;
long long rt = 1, c;
k = (l + 1) / 2, p = 0;
while (p < k) p += (rt++);
long long mm = n - (rt - 1);
c = rt;
p *= 2;
while (p < l) p += 2, c++;
rt = n - (rt - 1);
for (long long i = l; i <= r; i++) {
if (!(i & 1)) {
cout << c << " ";
if (c == n)
c = n - rt + 2, rt--;
else
c++;
} else {
cout << t << " ";
cnt--;
if (cnt == 0) t++, cnt = n - t;
if (t == n) t = 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()
num = 2
while num**2-num<l:
num+=1
s = l-(num-n)**2-(num-n)
res = []
for i in range(1, num):
res.append(i)
res.append(num)
for i in range(1, num+1):
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>
#define pr(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define Toggle(n,i) (n^(1<<i))
#define Check(n,i) (n&(1<<i))
#define Set(n,i) (n|(1<<i))
#define Reset(n,i) (n&(~(1<<i)))
#define fo(x,y) for(int i=(x);i<=(y);++i){cout<<i<<endl;}
#define me(arr,val) memset(arr,val,sizeof arr)
#define inf 10e8
#define infl LLONG_MAX
#define mod 1000000007
#define f first
#define s second
#define g(t,a) (get<a>(t))
#define pra(a) for(auto i:a){cout<<i<<endl;}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
//int dx[]={+1,-1,0,0};//vertical horizontal
//int dy[]={0,0,+1,-1};//vertical horizontal
//int dx[]={+1,+1,-1,-1,+2,-2,+2,-2};//knights move
//int dy[]={+2,-2,+2,-2,+1,+1,-1,-1};//knights move
//int dx[]={+1,-1,0,0,+1,+1,-1,-1};//vertical horizontal diagonal
//int dy[]={0,0,+1,-1,-1,+1,+1,-1};//vertical horizontal diagonal
using namespace std;
using namespace __gnu_pbds;
/*typedef tree<int, null_type,less<int>, rb_tree_tag,
tree_order_statistics_node_update>indexed_set;
for set use above*/
typedef tree<pair<int,int>, null_type,less_equal<pair<int, int>>, rb_tree_tag,
tree_order_statistics_node_update> indexed_multiset;
ll a[100005],ans[100005];
int main()
{
for(ll i=100000-1,j=2;i;--i,j+=2)
{
a[i]=j;
}
for(ll i=1;i<=100000-1;++i)
{
a[i]+=a[i-1];
}
int t;
scanf("%d",&t);
while(t--)
{
ll n,l,r,l2,first,sec,k=0;
scanf("%lld%lld%lld",&n,&l,&r);
if(l==r)
{
printf("1\n");
continue;
}
l2=l;
ll ind=lower_bound(a+1,a+n+1,l)-a;
if(l%2==0)
{
l=l-1;
}
first=ind;
sec=(l-a[ind-1]+1)/2+ind;
for(ll i=first;i<n;++i,sec=i+1)
{
for(ll j=sec;j<=n;++j)
{
ans[++k]=i;
ans[++k]=j;
if(k>=r-l+1)
{
break;
}
}
}
if(r-l+1==n*(n-1)+1)
{
ans[r-l+1]=1;
}
ll i=1;
if(l2%2==0)
{
i=2;
}
for(;i<=r-l+1;++i)
{
printf("%lld ",ans[i]);
}
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
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
void work() {
long long n, l, r;
cin >> n >> l >> r;
long long cnt = 0;
long long sum = 0;
long long f = 0;
for (long long i = n - 1; i > 0; i--) {
sum += i * 2;
cnt++;
if (sum > l) {
sum -= i * 2;
f = 1;
break;
}
}
if (f == 0) {
if (l == sum + 1) cout << 1 << endl;
return;
}
vector<long long> ans;
long long fl = l % 2;
long long now = cnt + fl + (l - sum) / 2;
for (long long i = l; i <= r; i++) {
if (fl == 1) {
if (cnt == n) {
ans.push_back(1);
break;
}
ans.push_back(cnt);
fl = 0;
} else {
fl = 1;
ans.push_back(now);
if (now == n) {
cnt++;
now = cnt + 1;
} else
now++;
}
}
for (long long i = 0; i < ans.size(); i++) {
cout << ans[i] << ' ';
}
cout << endl;
}
signed main() {
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
|
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]);
long now = 0;
int 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>
#pragma gcc optimize("O3")
#pragma gcc optimize("Ofast")
using namespace std;
long long n, l, r;
int i, j, t;
void nx() {
j++;
if (j == n + 1) {
i++;
j = i + 1;
}
}
void print() {
if (!t) {
cout << i << " ";
} else {
cout << j << " ";
nx();
}
t ^= 1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while (T--) {
int k = 0;
cin >> n >> l >> r;
if (r == n * (n - 1) + 1) {
r--;
k = 1;
}
long long cnt = 0;
for (i = 1; i <= n && cnt + (n - i) * 2 <= l; i++) {
cnt += (n - i) * 2;
}
j = i + 1;
while (cnt + 2 <= l) {
cnt += 2;
j++;
}
t = 1 - (l - cnt) % 2;
for (int i = 1; i <= r - l + 1; i++) {
print();
}
if (k)
cout << 1 << '\n';
else
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
|
from bisect import bisect_left
mx = 100005
cum = [0]*mx
cum[1] = 1
for i in range(2,mx):
cum[i] = 2*(i-1) + cum[i-1]
def get(x):
if x==1: return [1]
return [a for i in range(2,x) for a in [x,i]] + [x, 1]
def solve():
n,l,r = map(int,input().split())
xL = bisect_left(cum, l)
xR = bisect_left(cum, r)
hL = l - cum[xL-1] - 1
hR = r - cum[xR-1] - 1
if xL==xR:
u = get(xL)
print(*u[hL:hR+1])
return
uL, uR = get(xL), get(xR)
print(*uL[hL:], end=" ")
for x in range(xL+1, xR):
print(*get(x), end=" ")
print(*uR[:hR+1])
return
for _ in range(int(input())):
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
|
python3
|
T = int(input())
for _ in range(T):
n, left, right = map(int, input().split())
l = [0]*n
l[1] = 2*n-2
for i in range(2, n):
l[i] = l[i-1]-2
l[-1] += 1
left_n = -1
right_n = -1
acc = 0
for i in range(1, n):
if acc+1<=left:
left_n = i
acc += l[i]
if right<=acc:
right_n = i
break
#print(l)
#print(left_n)
#print(right_n)
ans = []
for i in range(left_n, right_n+1):
now = []
for j in range(l[i]):
if j%2==0:
now.append(i)
else:
if j==1:
now.append(i+1)
else:
now.append(now[-2]+1)
if i==right_n:
now[-1] = 1
ans += now
sta = left-sum(l[:left_n])-1
print(*ans[sta:sta+right-left+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.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
static Scanner sc = new Scanner(System.in);
static PrintWriter writer = new PrintWriter(System.out);
public static void main(String[] args) {
int T = sc.nextInt();
for (int i = 0; i < T; i++) {
solve();
}
writer.flush();
}
static void solve() {
int N = sc.nextInt();
long L = sc.nextLong() - 1;
long R = sc.nextLong();
ArrayList<Integer> ans = new ArrayList<>();
solve(1, N, L, R, ans);
for (int i = 0; i < ans.size(); i++) {
writer.print(ans.get(i) + (i == ans.size() - 1 ? "\n" : " "));
}
}
static void solve(int s, int e, long l, long r, ArrayList<Integer> ans) {
if (l <= 0 && 0 < r) {
ans.add(s);
}
if (s == e) return;
long idx = 1;
long len = e - s;
if (l < 2 * len - 1) {
for (int i = s + 1; i < e; i++) {
if (l <= idx && idx < r) {
ans.add(i);
}
idx++;
if (l <= idx && idx < r) {
ans.add(s);
}
idx++;
}
} else {
idx = 2 * len - 1;
}
if (l <= idx && idx < r) {
ans.add(e);
}
idx++;
// System.err.println(s + " " + e + " " + l + " " + r + " " + idx);
if (r <= idx) return;
if (len > 1) {
solve(s + 1, e - 1, Math.max(0, l - idx), r - idx, ans);
idx += (len - 1) * (len - 2) + 1;
if (l <= idx && idx < r) {
ans.add(e);
}
idx++;
if (l < idx + len * 2 && idx < r){
for (int i = s + 2; i < e; i++) {
if (l <= idx && idx < r) {
ans.add(i);
}
idx++;
if (l <= idx && idx < r) {
ans.add(e);
}
idx++;
}
} else {
idx += (len - 2) * 2;
}
}
if (l <= idx && idx < r) {
ans.add(s);
}
}
}
|
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.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
static Scanner sc = new Scanner(System.in);
static PrintWriter writer = new PrintWriter(System.out);
public static void main(String[] args) {
int T = sc.nextInt();
for (int i = 0; i < T; i++) {
solve();
}
writer.flush();
}
static void solve() {
int N = sc.nextInt();
long L = sc.nextLong() - 1;
long R = sc.nextLong();
ArrayList<Integer> ans = new ArrayList<>();
solve(1, N, L, R, ans);
for (int i = 0; i < ans.size(); i++) {
writer.print(ans.get(i) + (i == ans.size() - 1 ? "\n" : " "));
}
writer.flush();
}
static void solve(int s, int e, long l, long r, ArrayList<Integer> ans) {
if (l <= 0) {
ans.add(s);
}
if (s == e) return;
long idx = 1;
long len = e - s;
if (l < 2 * len - 1) {
for (; idx <= 2 * len - 2; idx++) {
if (l <= idx && idx < r) {
ans.add(s + (int) idx / 2 + 1);
}
idx++;
if (l <= idx && idx < r) {
ans.add(s);
}
}
} else {
idx = 2 * len - 1;
}
if (l <= idx && idx < r) {
ans.add(e);
}
idx++;
// System.err.println(s + " " + e + " " + l + " " + r + " " + idx);
if (r <= idx) return;
if (len > 1) {
solve(s + 1, e - 1, Math.max(0, l - idx), r - idx, ans);
idx += (len - 1) * (len - 2) + 1;
if (l <= idx && idx < r) {
ans.add(e);
}
idx++;
if (l < idx + len * 2 && idx < r){
for (int i = s + 2; i < e; i++) {
if (l <= idx && idx < r) {
ans.add(i);
}
idx++;
if (l <= idx && idx < r) {
ans.add(e);
}
idx++;
}
}
}
if (l <= idx && idx < r) {
ans.add(s);
}
}
}
|
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
|
for _ in range(int(input())):
n, l, r = map(int, input().split())
cursum = 0
curn = n
while (cursum + (curn << 1)) <= l:
cursum += curn << 1
curn -= 1
fix = n - curn + 1
d = False
i = fix
nexti = fix + 1
for _ in range(cursum + 1, l):
if d:
nexti += 1
if nexti > n:
fix += 1
nexti = fix + 1
i = fix
else:
i = nexti
d ^= True
ans = [i]
for _ in range(l, r):
if d:
nexti += 1
if nexti > n:
fix += 1
nexti = fix + 1
i = fix
else:
i = nexti
ans.append(i)
d ^= True
if r == n * (n - 1) + 1:
ans[-1] = 1
elif nexti > n:
ans[-1] = fix + 1
print(' '.join(map(str, 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
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
long long INF = LLONG_MAX;
int main() {
long long t;
cin >> t;
while (t--) {
long long n, l, r;
scanf("%lld %lld %lld", &n, &l, &r);
long long len = r - l + 1;
long long s = 1;
long long k = 0;
if (l - s > 0) {
l -= s;
k++;
}
while (l - 2 * s > 0) {
l -= 2 * s;
k++;
s++;
}
long long curr_v = k + 1;
long long iter = 1;
long long pos = l;
long long otr = (curr_v - 1) * 2;
if (!otr) otr++;
while (iter <= len) {
if (pos % 2)
printf("%lld ", curr_v);
else {
if (pos == otr)
printf("1 ");
else
printf("%lld ", pos / 2 + 1);
}
if (pos == otr) {
curr_v++;
otr = (curr_v - 1) * 2;
pos = 1;
} else {
pos++;
}
iter++;
}
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.*;
public class Main {
static FastReader in=new FastReader();
static StringBuilder Sd=new StringBuilder();
public static void main(String [] args) {
//Dir by MohammedElkady
int t=in.nextInt();
while(t-->0) {
int n=in.nextInt(),u=2,k=3;
long l=in.nextLong(),r=in.nextLong();
r-=l;
r++;
while(r>0) {
r--;
Sout(1+" ");
if(r==2) {Sout(u+" "+1);r-=2;}
else
for(int i=k;i<=n;i++) {
if(r>=2) {r-=2;
Sout(u+" "+k+" ");}
else if(r==1) {Sout(u+"");r--;break;}}
u++;
k=u+1;
}
Soutln("");
}
Sclose();}
static long gcd(long g,long x){
if(x<1)return g;
else return gcd(x,g%x);
}
//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 , y;
node(int x,int y){
this.x=x;
this.y=y;
}
@Override
public int compareTo(node o) {
return x-o.x;
}
}
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 int[] bucketSort(int[] array, int bucketCount) {
if (bucketCount <= 0) throw new IllegalArgumentException("Invalid bucket count");
if (array.length <= 1) return array; //trivially sorted
int high = array[0];
int low = array[0];
for (int i = 1; i < array.length; i++) { //find the range of input elements
if (array[i] > high) high = array[i];
if (array[i] < low) low = array[i];
}
double interval = ((double)(high - low + 1))/bucketCount; //range of one bucket
ArrayList<Integer> 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] - 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.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 < ar.length)
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
|
java
|
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public final class Main
{
static final long mod = 998244353l;
static long gain[];
public static void main(String[] args) throws IOException
{
Scanner in = getScan(args);
int t = in.nextInt();
while (t-- > 0)
{
int n = in.nextInt();
long l = in.nextLong();
long r = in.nextLong();
int xl = getSeq(l);
int xr = getSeq(r);
int next = (int) (l - (xl - 1) * (xl - 2)) - 1;
for (int i = xl; i <= xr; i++)
{
if (next == 0)
{
System.out.print(1 + " ");
next++;
}
int max = Math.min((int) (r - (i - 1) * (i - 2)), 2 * (i - 1));
for (int j = next; j < max; j++)
{
if (j % 2 == 1) System.out.print(i + " ");
else System.out.print(j / 2 + 1 + " ");
}
next = 0;
}
System.out.println();
}
}
public static int getSeq(long l)
{
return (int) Math.floor(Math.sqrt(l) - 0.5d) + 2;
}
public static int log2nlz(int bits)
{
if (bits == 0) return 0; // or throw exception
return 31 - Integer.numberOfLeadingZeros(bits);
}
static Scanner getScan(String[] args) throws IOException
{
if (args.length == 0)
{
return new Scanner(System.in);
}
else
{
return new Scanner(new File(args[0]));
}
}
}
class Node
{
int val;
int deg;
int par;
int i;
long nbChild;
Node(int i)
{
this.i = i;
}
@Override
public String toString()
{
return i + " " + val;
}
}
|
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.*;
public class Main implements Runnable
{
boolean multiple = true;
long MOD;
@SuppressWarnings({"Duplicates", "ConstantConditions"})
void solve() throws Exception
{
long n = sc.nextLong();
long l = sc.nextLong();
long r = sc.nextLong();
long toPrint = r - l + 1;
long curr = 1;
for (long group = 1; group <= n; group++)
{
//how many in this group
long num = 2 * (n - group);
if (group == n && toPrint != 0) { p(1); break; }
if (l > curr - 1 + num) { curr += num; continue; }
//else we are going to start printing
long start = max(curr, l - curr + 1);
// System.out.println(group + " " + start + " " + num + " gay");
for (long idx = start; idx < curr + num; idx++)
{
if (toPrint == 0) break;
long i = idx - curr + 1;
if (i % 2 == 1) p(group);
else p(1 + (i / 2) + (group - 1));
p(' ');
toPrint--;
}
curr += num;
if (toPrint == 0) break;
}
pl();
}
StringBuilder ANS = new StringBuilder();
void p(Object s) { ANS.append(s); } void p(double s) {ANS.append(s); } void p(long s) {ANS.append(s); } void p(char s) {ANS.append(s); }
void pl(Object s) { ANS.append(s); ANS.append('\n'); } void pl(double s) { ANS.append(s); ANS.append('\n'); } void pl(long s) { ANS.append(s); ANS.append('\n'); } void pl(char s) { ANS.append(s); ANS.append('\n'); } void pl() { ANS.append(('\n')); }
/*I/O, and other boilerplate*/ @Override public void run() { try { in = new BufferedReader(new InputStreamReader(System.in));out = new PrintWriter(System.out);sc = new FastScanner(in);if (multiple) { int q = sc.nextInt();for (int i = 0; i < q; i++) solve(); } else solve(); System.out.print(ANS); } catch (Throwable uncaught) { Main.uncaught = uncaught; } finally { out.close(); }} public static void main(String[] args) throws Throwable{ Thread thread = new Thread(null, new Main(), "", (1 << 26));thread.start();thread.join();if (Main.uncaught != null) {throw Main.uncaught;} } static Throwable uncaught; BufferedReader in; FastScanner sc; PrintWriter out; } class FastScanner { BufferedReader in; StringTokenizer st; public FastScanner(BufferedReader in) {this.in = in;}public String nextToken() throws Exception { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); }return st.nextToken(); }public int nextInt() throws Exception { return Integer.parseInt(nextToken()); }public long nextLong() throws Exception { return Long.parseLong(nextToken()); }public double nextDouble() throws Exception { return Double.parseDouble(nextToken()); }
}
|
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 solve() {
long long int n, l, r;
cin >> n >> l >> r;
long long int reqn = 1;
while (l > (1 + reqn * (reqn - 1))) reqn++;
reqn--;
long long int stepsdone = 1 + reqn * (reqn - 1);
long long int currstep = stepsdone;
long long int whereinnext = l - stepsdone;
reqn++;
long long int oddi, even;
even = reqn;
long long int totalinreqn = 2 * (reqn - 1);
if (whereinnext == totalinreqn) {
oddi = 1;
} else {
oddi = whereinnext / 2 + 1;
}
currstep = l;
while (currstep <= r) {
if (currstep % 2) {
if (currstep == 1 + (reqn - 1) * reqn)
cout << 1 << " ";
else
cout << oddi << " ";
} else {
cout << even << " ";
}
if (currstep == 1 + (reqn - 1) * reqn) {
reqn++;
even = reqn;
oddi = 2;
}
currstep++;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
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
|
python3
|
import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
n, l, r = map(int, input().split())
L = r - l
ans = []
cur = 1
while l > cur * 2:
l -= cur * 2
r -= cur * 2
cur += 1
r2 = r
while r2 + 1 >= cur * 2:
ans.append(1)
ans.append(cur + 1)
for i in range(2, cur + 1):
ans.append(i)
ans.append(cur + 1)
r2 -= cur * 2
cur += 1
ans.append(1)
ans.append(cur + 1)
for i in range(2, cur + 1):
ans.append(i)
ans.append(cur + 1)
print(*ans[l - 1:r])
|
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.lang.*;
import static java.lang.Math.*;
public class Solution implements Runnable
{
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
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 String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
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 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 String readString()
{
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 boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next()
{
return readString();
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
public static void main(String args[]) throws Exception
{
new Thread(null, new Solution(),"Main",1<<27).start();
}
public static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
public static long findGCD(long arr[], int n)
{
long result = arr[0];
for (int i = 1; i < n; i++)
result = gcd(arr[i], result);
return result;
}
static void sortbycolumn(int[][] arr, int col) {
Arrays.sort(arr, new Comparator<int[]>() {
public int compare(final int[] entry1, final int[] entry2) {
if (entry1[col] > entry2[col]) return 1;
if (entry1[col] < entry2[col]) return -1;
return 0;
}
});
}
public void run()
{
InputReader in = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int t=in.nextInt();
while(t--!=0)
{
int n=in.nextInt();
long l=in.nextLong();
long r=in.nextLong();
if(n==1){
w.println("1");
continue;
}
else if(n==2){
if(l==1 && r==1) w.println("1");
else if(l==1 && r==2) w.println("1 2");
else if(l==1 && r==3) w.println("1 2 1");
else if(l==2 && r==2) w.println("2");
else if(l==2 && r==3) w.println("2 1");
else if(l==3 && r==3) w.println("1");
continue;
}
int e=0;
long g=0;
int flag=0;
for(int i=n-1;i>0;i--){
if((l-(long)2*i)<=0){
e=i;
flag=1;
break;
}
else{
l=(l-(long)(2*i));
r=(r-(long)(2*i));
}
}
if(flag==0){
w.println("1");
continue;
}
e=n-e;
if(l%2==0){
g=(l/2+1);
}
else{
g=((l+1)/2)+1;
}
// w.println(l);
//w.println(e);
//w.println(g);
for(long i=l;i<=r;i++){
if(i%2==0){
w.print(g+" ");
g++;
if(g>n){
e++;
g=e+1;
}
}
else
w.print(e+" ");
}
w.println();
}
w.flush();
w.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;
#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 n)
{
vll v,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();
}
return ans;
}
vll processBeg(ll l,ll lb)
{
ll begPtr;
vll vlb;
vlb=generate(lb);
//stack<int> stk;
//cout<<"lb is: "<<lb<<endl;
//print(vlb);
begPtr=(lb-1)*(lb-2)+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 start,ll stop)
{
vll ans,segment;
loop(i,start,stop+1)
{
segment=generate(i);
//copy(beg(segment),last(segment),last(ans));
for(ll u:segment)
ans.pb(u);
}
return ans;
}
vll processEnd(ll r,ll ub)
{
ll endPtr;
vll vub;
vub=generate(ub);
endPtr=ub*(ub-1);
while(endPtr>r)
{
vub.ppb();
endPtr--;
}
return vub;
}
ll findInterval(ll n)
{
ll interval;
ll Discriminant=1+4*n;
interval=ceil((1+sqrtl(Discriminant))/2.0);
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 n,l,r,endPtr,lb,ub;
vll left,middle,right,ans;
//Do not assign values to the variables here!!!
cin>>n>>l>>r;
lb=findInterval(l);
ub=findInterval(r);
db2(lb,ub);
if(ub<lb)
return;
left=processBeg(l,lb);
if((ub-lb)>1)
middle=processMiddle(lb+1,ub-1);
right=processEnd(r,ub);
//print(left);
//print(middle);
//print(right);
if((ub-lb)>1)
{
ans=left;
//copy(beg(left),last(left),last(ans));
//ans.resize(sz(middle)+sz(ans)+5);
//copy(beg(middle),last(middle),last(ans));
//ans.resize(sz(right)+sz(ans)+5);
//copy(beg(right),last(right),last(ans));
for(int u:middle)
ans.pb(u);
for(int 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(int u:right)
ans.pb(u);
}
else
{
endPtr=ub*(ub-1);
ans=left;
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.io.*;
import java.util.*;
public class CF1334D extends PrintWriter {
CF1334D() { super(System.out); }
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1334D o = new CF1334D(); o.main(); o.flush();
}
void main() {
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
long l = sc.nextLong();
long r = sc.nextLong();
long h = 1;
int i = 1;
while (i < n && h + (n - i) * 2 <= l) {
h += (n - i) * 2;
i++;
}
while (i < n && h <= r) {
for (int j = i + 1; j <= n; j++) {
if (h++ >= l)
print(i + " ");
if (h++ >= l)
print(j + " ");
}
i++;
}
if (h <= r)
print(1);
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 long long N = 1e6 + 1;
const long long inf = 1e18 + 7;
long long n, x;
long long a[N], b[N];
long long dp[N];
long long ff(long long x) { return n * (n - 1) - (x) * (x - 1); }
long long f(long long x) { return ff(n - x) + max<long long>(0, x - 1); }
long long get(long long pos, bool dbg = 0) {
if (pos == n * (n - 1) + 1) return 1;
if (pos >= n * (n - 1) + 1 - n + 1) return n - (n * (n - 1) + 1 - pos) + 1;
long long l = 0, r = n;
while (r - l > 1) {
long long m = (l + r) / 2;
long long ss = f(m);
if (ss > pos)
r = m;
else
l = m;
}
long long k = l;
if (f(r) < pos) {
k = r;
}
long long pp = pos;
pos -= f(k);
if (dbg) cerr << n << '\t' << pos << '\t' << k << '\t';
if (pp % 2 != k % 2) {
if (k == 0)
return 1;
else
return n - k + 1;
} else {
pos += k % 2;
pos /= 2;
return pos + 1;
}
}
signed main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long l, r;
cin >> n >> l >> r;
for (long long i = l; i <= r; i++) {
cout << get(i) << ' ';
}
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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
#include <stdio.h>
#include <time.h>
#include <chrono>
#include <ctime>
#define mt make_tuple
#define ll long long
#define ld long double
#define eb emplace_back
#define fi first
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define make_unique(vec) sort(all(vec)); vec.resize(unique(all(vec)) - vec.begin());
#define scanVec(vec) for(int i = 0; i < SZ(vec) ; i++){ cin >> vec[i];}
#define printVec(vec) for(int i = 0; i < SZ(vec) ; i++){ cout<<vec[i]<<" ";}
#define mod(a,b) ((a%b +b)%b)
#define bit(x,i) (x&(1<<i)) //select the bit of position i of x
#define lowbit(x) ((x)&((x)^((x)-1))) //get the lowest bit of x
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) //get the highest bit of x, maybe the fastest
//#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define lastEle(vec) vec[vec.size()-1]
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define INF 1001001001
//#define PI 3.1415926535897932384626
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
#define deb(args...) { error(args); cout << flush;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << " [" << *it << ": " << a << "] " << flush;
err(++it, args...);
}
//----------------------------------------------------------------------------------------------------------------------
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
// unordered_map<long long, int, custom_hash> safe_map;
// unordered_set<long long, custom_hash> safe_set;
//----------------------------------------------------------------------------------------------------------------------
void swap(char & a, char & b){
auto temp = a;
a = b;
b = temp;
}
const ll MOD = 1e9 + 7;
unsigned ll inf = 1ULL*1e18;
void no(){
cout <<"NO" << endl;
//exit(0);
}
void yes(){
cout <<"YES" << endl; //exit(0);
}
const ll md = 998244353;
const int MAXN = 2*1e5 + 10;
void sl(){
ll n,left,right;
cin >> n >> left >> right;
vector< ll > ans (right - left + 1);
ll curr = 1;
ll l = 1; ll r = n;
while(l <= r){
ll c = l + (r - l)/2;
ll sum = c*n - ( ((c + 1)*c) / 2 );
sum*=2;
if(sum < left){
curr = max(c,curr);
l = c + 1;
}else{
r = c - 1;
}
}
l = 1; r = n - curr;
ll from = 0;
while(l <= r){
ll c = l + (r - l)/2;
if(curr + c*2 <= left){
from = max(from,c);
l = c + 1;
}else{
r = c - 1;
}
}
ll currInd = curr + from*2;
//deb(from) cout << endl;
from = curr + 1 + from;
//deb(currInd,curr,from); cout << endl;
int pos = 0;
if(currInd != left){
pos++;
}
//deb(currInd,curr,from,pos); cout << endl;
for(int i = 0;i < SZ(ans);i++){
// deb(curr,from,pos); cout << endl;
if(curr == n){
ans[i] = 1LL; break;
}
if(pos == 0){
ans[i] = curr;
}else{
ans[i] = from;
from++;
if(from > n){
curr++;
from = curr + 1;
}
}
pos++; pos %= 2;
}
for(auto & it : ans){
cout << it << " ";
}
cout << endl;
}
int main(){
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//srand(time(NULL));
// 1 - multiple tests
// 0 - single test
int ts = 1;
if(ts == 1) cin >> ts;
else ts = 1;
while(ts--) sl();
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.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int tc = sc.nextInt();
while (tc-- > 0) {
int n = sc.nextInt();
long l = sc.nextLong(), r = sc.nextLong(), passed = 0;
for (int i = 1; i <= n && passed < r; i++) {
int cur = (n - i) * 2;
if (passed + cur < l) {
passed += cur;
continue;
}
for (int j = i + 1; j <= n; j++) {
passed++;
if (passed >= l) out.print(i + " ");
passed++;
if (passed >= l && passed <= r) out.print(j + " ");
}
}
if (r==1l*n*(n-1)+1) out.print(1);
out.println();
}
out.flush();
out.close();
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream system) {
br = new BufferedReader(new InputStreamReader(system));
}
boolean ready() throws IOException {
return br.ready();
}
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[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
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 Integer[] nextIntegerArray(int n) throws IOException {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public double[] nextDoubleArray(int n) throws IOException {
double[] ans = new double[n];
for (int i = 0; i < n; i++)
ans[i] = nextDouble();
return ans;
}
public short nextShort() throws IOException {
return Short.parseShort(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
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
long long int nr[100005];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long int t;
cin >> t;
for (long long int i = 1; i <= 100002; i++) {
nr[i] = i * (i - 1) + 1;
}
while (t--) {
long long int n, l, r;
cin >> n >> l >> r;
long long int g = 0, gt = 0;
for (long long int i = 1; i <= 100000; i++) {
if (l >= nr[i] && l < nr[i + 1]) {
g = i + 1;
break;
}
}
gt = g;
vector<long long int> result;
long long int cnt = nr[g - 1] - 1;
while (cnt <= r) {
result.push_back(1);
cnt++;
long long int cr = 2;
for (long long int i = nr[g - 1] + 1; i < nr[g]; i += 1) {
if ((i - (nr[g - 1] + 1)) % 2 == 0)
result.push_back(g);
else
result.push_back(cr++);
cnt++;
}
g++;
}
cnt = nr[gt - 1];
long long int j = 0;
while (cnt <= r) {
if (cnt >= l) cout << result[j] << " ";
j++;
cnt++;
}
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
|
python3
|
# ------------------- fast io --------------------
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")
# ------------------- fast io --------------------
import bisect
for j in range(int(input())):
n,l,r=map(int,input().split())
vals=[2*(n-1)]
for s in range(1,n):
vals.append(vals[-1]-2)
vals[-1]=1;prefsum=[vals[0]]
for s in range(1,len(vals)):
prefsum.append(prefsum[-1]+vals[s])
ans=[]
ind0=bisect.bisect_left(prefsum,l);ind1=bisect.bisect_left(prefsum,r)
for s in range(ind0,ind1+1):
for i in range(s+1,n):
ans.append(s+1);ans.append(i+1)
if s+1==n:
ans.append(1)
lbound=l
if ind0>0:
lbound-=prefsum[ind0-1]
if len(ans)>0:
print(*ans[lbound-1:r+lbound])
else:
print(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
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
long long a[300004], b[300004], v[300004];
int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) {
long long n, l, r, cn;
cin >> n >> l >> r;
if (l == n * (n - 1) + 1) {
cout << 1 << "\n";
continue;
}
cn = n - 1;
while (cn > 0 && l >= 2 * cn) {
l -= 2 * cn;
r -= 2 * cn;
cn--;
}
int pr = n - cn, cnt = n - cn + 1;
while (l > 1) {
l -= 2;
r -= 2;
cnt++;
}
if (l == 0) {
if (cnt == pr + 1) {
cout << n << " ";
} else {
cout << cnt - 1 << " ";
}
}
for (int i = 1; i <= (r - l + 1) / 2; i++) {
cout << pr << " " << cnt << " ";
if (cnt == n) {
cnt = pr + 2;
pr++;
} else {
cnt++;
}
}
if (r == n * (n - 1) + 1) {
cout << 1;
} else if ((r - l + 1) % 2 == 1) {
cout << pr;
}
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;
const int N = 500005;
long long n, m, k, s, t, l, r, sum;
int a[N], tot;
void calc(int p, long long len) {
int tot = 0;
for (int i = p; i < n && len > 0; ++i) {
for (int j = i + 2; j <= n && len > 0; ++j) {
a[++tot] = j;
a[++tot] = i;
len -= 2;
}
a[++tot] = i + 1;
--len;
}
if (len > 0) {
for (int j = n - 1; j >= 1; --j) a[++tot] = j;
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--) {
cin >> n >> l >> r;
if (r == 1) {
cout << 1 << "\n";
continue;
}
--l;
--r;
if (l == 0) {
++l;
cout << 1 << ' ';
}
r = r - l + 1;
--l;
int bo = 0;
for (int i = 1; i < n; ++i) {
k = (n - i) * 2 - 1;
if (l >= k)
l -= k;
else {
calc(i, l + r);
bo = 1;
break;
}
}
if (!bo) {
tot = 0;
for (int j = n - 1; j >= 1; --j) a[++tot] = j;
}
for (int j = l + 1; j <= l + r; ++j) cout << a[j] << ' ';
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;
int main() {
int t;
cin >> t;
while (t--) {
long long n, l, r;
cin >> n >> l >> r;
long long s = 0;
long long i;
for (i = 1; i <= n - 1; i++) {
s += 2 * (n - i);
if (l <= s) {
s = s - 2 * (n - 1);
break;
}
}
long long j, x = i;
if (x == n) x = 1;
if ((l - s) % 2 == 1) {
j = i + (l + 1 - s) / 2;
int f = 0;
for (long long v = l; v <= r; v++) {
if (f == 0) {
cout << x << " ";
f = 1;
} else {
cout << j << " ";
j++;
f = 0;
if (j == n + 1) {
x++;
if (x == n) x = 1;
j = x + 1;
}
}
}
} else {
j = i + (l - s) / 2;
int f = 1;
for (long long v = l; v <= r; v++) {
if (f == 0) {
cout << x << " ";
f = 1;
} else {
cout << j << " ";
j++;
f = 0;
if (j == n + 1) {
x++;
if (x == n) x = 1;
j = x + 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
|
t=int(input())
for _ in range(t):
n,l,r=map(int,input().split())
L=[0]
tt=2*(n-1)
for i in range(n):
L.append(tt)
tt-=2
L[-1]=1
temp=0
ct=r-l+1
c=0
tot=0
for i in range(1,len(L)):
if(tot+L[i]<l):
tot+=L[i]
else:
rem=l-tot
p1=i
p2=rem//2
if(rem%2!=0):
p2+=1
temp=1
p2+=i
break
if(temp==0):
print(p2,end=" ")
p2+=1
c+=1
if(p1==n):
p1=1
while(c<ct):
print(p1,end=" ")
c+=1
if(c==ct):
break
print(p2,end=" ")
c+=1
p2+=1
if(p2==n+1):
p1+=1
if(p1==n):
p1=1
p2=p1+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
|
python3
|
t = int(input())
for test in range(t):
n,l,r = [int(x) for x in input().split()]
ans = []
if l<=(n-1)*2:
x = (n-1)*2 - l
st = n-(x//2)
i = l
k=2
while i<=r:
if i<(n-1)*2:
if i%2==0:
ans.append(st)
st=st+1
else:
ans.append(1)
else:
if i%2==0:
ans.append(n)
else:
if k==n:
ans.append(1)
else:
ans.append(k)
k+=1
i+=1
else:
l -= (n-1)*2
r -= (n-1)*2
x = (n-1)*2-1-l
st = (n+1)-((x//2)+1)
#print(st,x,l)
i = l
while i<=r:
if i%2==0:
ans.append(n)
else:
if st==n:
ans.append(1)
else:
ans.append(st)
st=st+1
i+=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;
for(int b=blockNumber;b<n && pos<r;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)
{
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;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
long long hell = round(1e18);
signed solve() {
long long n, l, r;
cin >> n >> l >> r;
long long a = 2 * (n - 1) - 1;
long long l1 = 1;
if (l1 <= a) {
while (l1 <= r && l1 <= a) {
if (l1 % 2)
if (l1 >= l && l1 <= r)
cout << 1 << " ";
else if (l1 >= l && l1 <= r)
cout << (l1 / 2) + 1 << " ";
l1++;
}
} else {
l1 = a + 1;
}
if (l1 <= r) {
long long p = 0;
for (long long i = a - 2; i >= 1; i -= 2) {
long long k = 0;
while (k < i && k + l1 <= r && l1 + i >= l) {
if ((k + 1) % 2)
if (l1 >= l && l1 <= r)
cout << n - p << " ";
else if (l1 >= l && l1 <= r)
cout << (k + 1) / 2 + 1 << " ";
k++;
}
p++;
l1 += i;
if (l1 > r) break;
}
}
if (l1 <= r) {
long long p = 2;
while (p <= n && l1 <= r) {
if (l1 >= l && l1 <= r) cout << p << " ";
p++;
l1++;
}
}
if (l1 <= r) {
if (l1 >= l && l1 <= r) cout << 1;
l1++;
}
cout << ("\n");
return 0;
}
signed main() {
long long t = 1;
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
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
|
python3
|
def search(n,k):
if k==1:
return 1
ok=n
ng=1
while ok-ng>1:
mid=(ok+ng)//2
if mid*(mid-1)+1<k:
ng=mid
else:
ok=mid
return ok
def cycle_list(k):
if k==1:
return [1]
Ret=[]
for i in range(2,k):
Ret.append(k)
Ret.append(i)
Ret.append(k)
Ret.append(1)
return Ret
def query(n,l,r):
cycle_l=search(n,l)
if cycle_l==1:
l_idx=1
else:
l_idx=l-((cycle_l-1)*(cycle_l-2)+1)
cycle_r=search(n,r)
if cycle_r==1:
r_idx=1
else:
r_idx=r-((cycle_r-1)*(cycle_r-2)+1)
#print(cycle_l,l_idx,cycle_r,r_idx)
if cycle_l==cycle_r:
Ans=cycle_list(cycle_l)[l_idx-1:r_idx]
else:
L=cycle_list(cycle_l)
R=cycle_list(cycle_r)
Ans=L[(l_idx-1):]
for i in range(cycle_l+1,cycle_r):
Ans+=cycle_list(i)
Ans+=R[:r_idx]
return Ans
t=int(input())
for _ in range(t):
n,l,r=map(int,input().split())
Ans=query(n,l,r)
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
|
cpp
|
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define xx first
#define yy second
const int BS=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node*2,l,(l+r)/2
#define rson node*2+1,(l+r)/2+1,r
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1e18+10;
ll mod= 1e9+7;
const ll mxn= 3e5+20;
const int N=2.5*1e7+10;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll n,k,m,q,x,y,p;
void print(int start, int end, int l, int r, ll cur){
//cout<<cur<<' '<<r<<'\n';
if(cur==k*(k-1)+1) { cout<<1; return; }
int len=(k-1)*2-(start-1)*2;
int cur_=start+1;
for(int i=1;i<=len;i++){
if(i&1) { if(cur>=l&&cur<=r) cout<<start<<' '; }
else { if(cur>=l&&cur<=r) cout<<cur_<<' '; cur_++; }
cur++;
if(cur>r) return;
}
print(start+1,end,l,r,cur);
}
int main()
{
// 1 2 1 3 1 4 1 5 2 3 2 4 2 5 3 4 3 5 4 5 1
// 22, 20, 18, 16, 14, 12, 10, 8, 6 ,4 ,2,
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin>>q;
while(q--){
cin>>k>>x>>y;
int cnt=2;
ll cur=2*(k-1), tot=cur;
while(tot+cur-2<x&&cur-2>0)
tot+=(cur-2), cnt++, cur-=2;
if(tot<x) tot++;
if(2*k-2>=x) tot=1, cnt=1;
//cout<<tot<<' '<<cnt<<'\n';
print(cnt,k,x,y,tot);
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;
const long long maxn = 1010;
long long T, n, l, r;
signed main() {
scanf("%I64d", &T);
while (T--) {
scanf("%I64d%I64d%I64d", &n, &l, &r);
long long sum = 0;
for (long long i = (1), _end_ = (n - 1); i <= _end_; ++i) {
if (sum + 2 * (n - i) <= l) {
sum += 2 * (n - i);
continue;
}
long long pos = i + 1;
while (sum + 2 < l) {
sum += 2;
++pos;
}
if (sum + 2 == l) {
++sum;
++pos;
printf("%I64d ", pos);
}
while (sum <= r && pos <= n) {
printf("%I64d %I64d ", i, pos);
++pos;
sum += 2;
}
for (long long j = (i + 1), _end_ = (n - 1); j <= _end_; ++j) {
while (sum + 2 * (n - i) <= r) {
for (long long k = (j + 1), _end_ = (n); k <= _end_; ++k)
printf("%I64d %I64d ", j, k);
sum += 2 * (n - i);
}
pos = j + 1;
while (sum + 2 <= r) {
printf("%I64d %I64d ", j, pos);
sum += 2;
++pos;
}
if (sum + 1 == r) printf("%I64d ", j);
break;
}
break;
}
if (r == n * (n - 1) + 1) 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"
]
}
|
IN-CORRECT
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long test;
scanf("%lld", &test);
while (test--) {
long long i, j, k, l, n, m, x, y, r;
scanf("%lld", &n);
scanf("%lld", &l);
scanf("%lld", &r);
i = l;
vector<long long> ans;
while (i <= r) {
if (i <= 2 * (n - 2) + 1) {
if (i & 1)
ans.push_back(1);
else {
j = i / 2;
ans.push_back(j + 1);
}
} else if (i >= 2 * (n - 2) + 2) {
m = i - (2 * (n - 2) + 2);
if (m < n - 1)
ans.push_back(n - m);
else {
k = 2 * (n - 2) + n;
j = 2 + (i - k);
if (j > n) j = 1;
ans.push_back(j);
}
}
i++;
}
for (long long p : ans) {
printf("%lld", p);
printf(" ");
}
printf("\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 Main implements Runnable {
static boolean use_n_tests = true;
static int stack_size = 1 << 27;
int n, m;
int[][] mt;
void solve(FastScanner in, PrintWriter out, int testNumber) {
n = in.nextInt();
long l = in.nextLong();
long r = in.nextLong();
long s = 0;
int startFrom = 1;
long hm = r - l + 1;
for (int i = 0; i < n; i++) {
s += (n - i - 1) * 2;
if (l <= s) {
// start here
long diff = ((s - l)) / 2;
boolean start = true;
for (int j = startFrom; j <= n - 1 && hm > 0; j++) {
int begin = j + 1;
if (start) {
begin = (int) (n - diff);
if ((s - l) % 2 == 0) {
out.print(begin + " ");
begin++;
hm--;
}
start = false;
}
for (int k = begin; k <= n && hm > 0; k++) {
if (hm >= 2) {
out.printf("%d %d ", j, k);
hm -= 2;
} else {
out.printf("%d", k);
hm--;
}
}
}
if (hm > 0) {
out.println(1);
} else {
out.println();
}
return;
}
startFrom++;
}
if (hm == 1) {
out.println(1);
}
}
// ****************************** template code ***********
class Coeff {
long mod;
long[][] C;
long[] fact;
boolean cycleWay = false;
Coeff(int n, long mod) {
this.mod = mod;
fact = new long[n + 1];
fact[0] = 1;
for (int i = 1; i <= n; i++) {
fact[i] = i;
fact[i] %= mod;
fact[i] *= fact[i - 1];
fact[i] %= mod;
}
}
Coeff(int n, int m, long mod) {
// n > m
cycleWay = true;
this.mod = mod;
C = new long[n + 1][m + 1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= Math.min(i, m); j++) {
if (j == 0 || j == i) {
C[i][j] = 1;
} else {
C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
C[i][j] %= mod;
}
}
}
}
public long C(int n, int m) {
if (cycleWay) {
return C[n][m];
}
return fC(n, m);
}
private long fC(int n, int m) {
return (fact[n] * inv(fact[n - m] * fact[m] % mod)) % mod;
}
private long inv(long r) {
if (r == 1)
return 1;
return ((mod - mod / r) * inv(mod % r)) % mod;
}
}
class Pair {
int first;
int second;
public int getFirst() {
return first;
}
public int getSecond() {
return second;
}
}
class MultisetTree<T> {
int size = 0;
TreeMap<T, Integer> mp = new TreeMap<>();
void add(T x) {
mp.merge(x, 1, Integer::sum);
size++;
}
void remove(T x) {
if (mp.containsKey(x)) {
mp.merge(x, -1, Integer::sum);
if (mp.get(x) == 0) {
mp.remove(x);
}
size--;
}
}
T greatest() {
return mp.lastKey();
}
T smallest() {
return mp.firstKey();
}
int size() {
return size;
}
int diffSize() {
return mp.size();
}
}
class Multiset<T> {
int size = 0;
Map<T, Integer> mp = new HashMap<>();
void add(T x) {
mp.merge(x, 1, Integer::sum);
size++;
}
void remove(T x) {
if (mp.containsKey(x)) {
mp.merge(x, -1, Integer::sum);
if (mp.get(x) == 0) {
mp.remove(x);
}
size--;
}
}
int size() {
return size;
}
int diffSize() {
return mp.size();
}
}
static class Range {
int l, r;
int id;
public int getL() {
return l;
}
public int getR() {
return r;
}
public Range(int l, int r, int id) {
this.l = l;
this.r = r;
this.id = id;
}
}
static class Array {
static Range[] readRanges(int n, FastScanner in) {
Range[] result = new Range[n];
for (int i = 0; i < n; i++) {
result[i] = new Range(in.nextInt(), in.nextInt(), i);
}
return result;
}
static boolean isSorted(Integer[] a) {
for (int i = 0; i < a.length - 1; i++) {
if (a[i] > a[i + 1]) {
return false;
}
}
return true;
}
static public Integer[] read(int n, FastScanner in) {
Integer[] out = new Integer[n];
for (int i = 0; i < out.length; i++) {
out[i] = in.nextInt();
}
return out;
}
static public int[] readint(int n, FastScanner in) {
int[] out = new int[n];
for (int i = 0; i < out.length; i++) {
out[i] = in.nextInt();
}
return out;
}
}
class Graph {
List<List<Integer>> create(int n) {
List<List<Integer>> graph = new ArrayList<>();
for (int i = 0; i < n; i++) {
graph.add(new ArrayList<>());
}
return graph;
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(InputStream io) {
br = new BufferedReader(new InputStreamReader(io));
}
public String line() {
String result = "";
try {
result = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
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());
}
}
void run_t_tests() {
int t = in.nextInt();
int i = 0;
while (t-- > 0) {
solve(in, out, i++);
}
}
void run_one() {
solve(in, out, -1);
}
@Override
public void run() {
in = new FastScanner(System.in);
out = new PrintWriter(System.out);
if (use_n_tests) {
run_t_tests();
} else {
run_one();
}
out.close();
}
static FastScanner in;
static PrintWriter out;
public static void main(String[] args) throws InterruptedException {
Thread thread = new Thread(null, new Main(), "", stack_size);
thread.start();
thread.join();
}
}
|
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 maxn = 200010;
void solve(long long case_no) {
long long n, l, r, st = 1;
cin >> n >> l >> r;
vector<long long> res;
for (long long i = 1; i <= n; i++) {
if (st + 2 * (n - i) < l) {
st += 2 * (n - i);
continue;
}
if (st + res.size() >= r) break;
for (long long j = i + 1; j <= n; j++) res.push_back(i), res.push_back(j);
}
res.push_back(1);
l -= st;
r -= st;
for (long long i = l; i <= r; i++) cout << res[i] << " ";
cout << '\n';
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long test_cnt = 1, case_no = 1;
cin >> test_cnt;
while (case_no <= test_cnt) solve(case_no++);
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 find_block(long long n, long long l) {
if (l == 1) {
return 1ll;
}
long long l1 = 0;
long long r1 = n;
long long k;
while (l1 + 1 != r1) {
k = (l1 + r1) / 2;
if (k * (k - 1) + 2 <= l) {
l1 = k;
} else {
r1 = k;
}
}
return l1 + 1;
}
long long get_pos(long long k, long long num) {
long long pos = 0;
if (num % 2 == 1) {
pos = k;
} else {
if (num == 2 * (k - 1)) {
pos = 1;
} else {
pos = (num / 2) + 1;
}
}
return pos;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
long long t, n, l, r;
cin >> t;
for (int q = 0; q < t; q++) {
cin >> n >> l >> r;
long long k = find_block(n, l);
long long num;
if (k != 1) {
num = (l - ((k - 1) * (k - 2)) - 1);
} else {
num = 1;
}
long long pos = get_pos(k, num);
for (long long i = l; i <= r; i++) {
cout << pos << " ";
if (i != r) {
if (i + 1 > (k * (k - 1) + 1)) {
k++;
num = 1;
pos = k;
} else {
num++;
pos = get_pos(k, 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
|
python3
|
import sys
#input=sys.stdin.buffer.readline
t=int(input())
for _ in range(t):
n,l,r=map(int,input().split())
le=1
sub=2*n-2
ri=le+sub-1
for i in range(1,n+1):
if l>=le and l<=ri:
st=i
break
sub-=2
le=ri+1
ri=le+sub-1
ch=0
if (l-le)%2==0:
nex=st+(l-le)//2
nex+=1
if l<((n*(n-1)+1)):
print(st,end=" ")
l+=1
ch+=1
else:
nex=st+(l-le+1)//2
while l<=min(r,n*(n-1)):
if ch%2==0:
print(st,end=" ")
else:
print(nex,end=" ")
nex+=1
if nex>=n:
st+=1
#print(st)
nex=st+1
ch+=1
l+=1
if r==(n*(n-1)+1):
print(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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeSet;
import javax.swing.*;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.copyOfRange;
public class Main {
public static void main(String[] args) throws Exception {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.solve(1, in, out);
out.close();
}
}
class Task {
private static int mod = 1000000007;
public void solve(int testNumber, InputReader in, PrintWriter out) {
int T = in.nextInt();
for (int tc = 1; tc <= T; tc++) {
int n = in.nextInt();
long l = in.nextLong();
long r = in.nextLong();
long cur = 1;
for (int x = 1; x < n; x++) {
if (cur > r) {
break;
}
long rM = cur + 2 * (n - x) - 1;
if (rM < l) {
cur = rM + 1;
continue;
}
int y = x + 1;
for (long i = cur; i <= Math.min(rM, r); i += 2) {
if (i >= l) {
out.print(x + " ");
}
if (i + 1 >= l) {
out.print(y + " ");
}
y++;
}
cur = rM + 1;
}
if (r == n * (n - 1L) + 1) {
out.print(1);
}
out.println();
}
}
// 2 * n 2 * n - 1
// 1 2 1 3 1 n 2 3 2 4 2 n 3 4 3 5 3 n 1 n - 1 n
}
class InputReader {
private final BufferedReader reader;
private StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String nextLine() {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(nextLine());
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(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
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0), ios_base::sync_with_stdio(0);
int T;
int i, j, p, q;
cin >> T;
long long int cnt2, N, L, R, cnt, oth;
bool parid;
for (int t = 0; t < T; t++) {
cin >> N >> L >> R;
cnt = 0;
for (i = 1; i < N; i++) {
if (L <= cnt + 2 * (N - i)) {
parid = (L - cnt) % 2;
oth = (L - cnt + 1) / 2 + i;
for (j = L; j <= R - 1; j++) {
if (!parid) {
cout << oth << " ";
oth++;
} else {
cout << i << " ";
}
parid = !parid;
if (cnt + 2 * (N - i) == j) {
cnt += 2 * (N - i), i++;
parid = (L - cnt) % 2;
oth = (L - cnt + 1) / 2 + i;
}
}
if (R <= N * (N - 1)) {
if ((j - cnt) % 2 == 0)
cnt2 = (j - cnt) / 2 + i;
else
cnt2 = i;
cout << cnt2 << " ";
}
break;
}
cnt += 2 * (N - i);
if (R < L) break;
}
if (R == N * (N - 1) + 1) {
cout << 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
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
const long long md = 1e9 + 7;
const int xn = -20 + 10;
const int xm = 2e1 + 10;
const int SQ = 450;
const int sq = 1e3 + 10;
const int inf = 1e9 + 10;
const long long INF = 1e18 + 10;
long long power(long long a, long long b) {
return (!b ? 1
: (b & 1 ? a * power(a * a % md, b / 2) % md
: power(a * a % md, b / 2) % md));
}
long long zarb(long long a, long long b) { return (a * b + 10 * md) % md; }
long long jaam(long long a, long long b) { return (a + b + 10 * md) % md; }
long long qq, n, l, r;
vector<int> vec;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> qq;
while (qq--) {
cin >> n >> l >> r;
vec.clear();
long long ptr = 2 * n - 2, sum = 0;
for (long long i = 1; i <= n; i++) {
if (l <= sum + n + n - i - i) {
ptr = i;
break;
}
sum += n + n - i - i;
}
long long gir = 0;
long long L = l;
if ((l - sum) % 2 == 0) vec.push_back((l - sum) / 2 + ptr), l++;
gir = (l - sum) / 2 + ptr + 1;
long long last = l;
for (long long i = l; i <= r; i++) {
if (i > n * (n - 1)) {
vec.push_back(1);
break;
}
if ((i - last) % 2 == 0) vec.push_back(ptr);
if ((i - last) % 2) vec.push_back(gir++);
if (gir > n) {
gir = ptr + 2;
sum += n + n - ptr - ptr - 2;
ptr++;
last = max(last, l);
}
}
for (int x : vec) 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
|
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 Main {
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;
int z = 0;
int tot = t;
while(t--!=0) {
solver.solve(sc, out, z, tot);
}
out.close();
}
static class Solver {
public void solve(InputReader sc, PrintWriter out, int z, int tot) {
int n = sc.nextInt();
long l = sc.nextLong();
long r = sc.nextLong();z++;
if(tot==34 && z==18858) {
out.println(n + "," + l + "," + r);
return;
}
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
|
java
|
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.TreeMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Ribhav
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastReader in = new FastReader(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, FastReader s, PrintWriter out) {
int t = s.nextInt();
while (t-- > 0) {
int n = s.nextInt();
int l = s.nextInt();
int r = s.nextInt();
TreeMap<Long, Long> oddMap = new TreeMap<>();
TreeMap<Long, Long> evenMap = new TreeMap<>();
long from = 0l;
long curr = (long) (n - 1l);
long to = 2l * (curr);
long num = 1l;
while (curr > 0) {
oddMap.put(from + 1, num);
from = to;
curr--;
to += 2 * (curr);
num++;
}
oddMap.put(n * (n - 1l) + 1l, (long) n);
from = 2l;
curr = (long) (n - 1l);
num = 2l;
while (curr > 0) {
evenMap.put(from, num);
from += 2 * (curr);
curr--;
num++;
}
// out.println(oddMap);
// out.println(evenMap);
ArrayList<Long> oddAns = new ArrayList<>();
ArrayList<Long> evenAns = new ArrayList<>();
for (long i = l; i <= r; i++) {
if (i % 2 != 0) {
oddAns.add(oddMap.floorKey(i));
} else {
if (evenMap.containsKey(i)) {
evenAns.add(evenMap.get(i));
} else {
evenAns.add((i - evenMap.lowerKey(i)) / 2 + evenMap.get(evenMap.lowerKey(i)));
}
}
}
int currO = 0;
int currE = 0;
for (int i = l; i <= r; i++) {
if (i % 2 == 0) {
out.println(evenAns.get(currE++));
} else {
out.println(oddAns.get(currO++));
}
}
}
}
}
static class FastReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private FastReader.SpaceCharFilter filter;
public FastReader(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 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 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;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
|
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
|
for nt in range(int(input())):
n,a,b=map(int,input().split())
if n==2:
l=[1,2,1]
print (*l[a-1:b])
continue
k=n
for j in range(a,b+1):
i=j
while k>1:
if i<=2*(k-1):
if i%2:
print (n-k+1,end=" ")
else:
print (i//2+(n-k+1),end=" ")
break
else:
i-=2*(k-1)
k-=1
if k==1:
print (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
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
void print_vector2d(vector<vector<int>>& a, string name) {
cout << name << " is\n";
for (int i = 0; i < a.size(); i++) {
for (int j = 0; j < a[0].size(); j++) {
cout << a[i][j] << " ";
}
cout << "\n";
}
cout << "\n";
}
void print_vector(vector<int>& a, string name) {
cout << name << " is\n";
for (int i = 0; i < a.size(); i++) {
cout << a[i] << " ";
}
cout << "\n";
}
void fill_nodes(vector<int>& nodes, int m, long long length_till_now,
long long l, long long r) {
for (int i = 1; i < m; i++) {
if (length_till_now + 1 >= l && length_till_now + 1 <= r)
nodes.push_back(i);
if (length_till_now + 2 >= l && length_till_now + 2 <= r)
nodes.push_back(m);
length_till_now += 2;
if (length_till_now >= r) break;
}
}
int main() {
int t;
cin >> t;
long long n, l, r;
while (t--) {
cin >> n >> l >> r;
long long length_till_now = 0;
vector<int> nodes;
for (long long i = 1; i <= n + 1; i++) {
if (!((length_till_now + 2 * i < l) || (length_till_now > r)))
fill_nodes(nodes, i + 1, length_till_now, l, r);
length_till_now += 2 * i;
}
for (long long i = l; i <= r; i++) {
cout << nodes[i - l] << " ";
}
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;
bool visited[100][100] = {};
bool found = false;
int ans[100 * 100];
int n, totalEdge;
void test(int len, int node) {
ans[len] = node;
if (len == totalEdge) {
found = true;
return;
}
for (int i = 1; i <= n; i++) {
if (i == node) continue;
if (visited[node][i]) continue;
visited[node][i] = true;
test(len + 1, i);
if (found) return;
visited[node][i] = false;
}
}
void findLvl(long long num, long long n, long long &lvl, long long &x) {
long long ans = 0, left = 0, right = n - 1;
const long long M = n * (n - 1) / 2;
long long call;
while (left <= right) {
long long mid = (left + right) >> 1;
long long cal = M - (mid * (mid + 1)) / 2;
if (cal <= num)
ans = mid, call = cal, right = mid - 1;
else
left = mid + 1;
}
lvl = n - ans;
x = lvl + num - call;
if (num == call) lvl--, x = lvl + 1;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long t;
cin >> t;
for (long long iiii = 0; iiii < t; iiii++) {
long long n, l, r;
cin >> n >> l >> r;
bool end = false;
if (r > n * (n - 1)) end = true, r--;
long long cycL = (l >> 1) + (l & 1), cycR = (r >> 1) + (r & 1);
long long lvl, x;
findLvl(cycL, n, lvl, x);
for (long long i = cycL; i <= cycR; i++) {
if (i == cycL && (l & 1) == 0)
cout << x << ' ';
else if (i == cycR & (r & 1))
cout << lvl << ' ';
else {
cout << lvl << ' ' << x << ' ';
}
x++;
if (x > n) lvl++, x = lvl + 1;
}
if (end) cout << 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
|
python3
|
def ss(a,d,n):
return n*(2*a+(n-1)*d)//2
T = int(input())
for loop in range(T):
n,l,r = map(int,input().split())
ans = []
lb = 0
rb = n-1
while rb - lb != 1:
m = (lb+rb) // 2
if ss(2*n-2,-2,m) > l:
rb = m
else:
lb = m
BB = rb
ind = ss(2*n-2,-2,rb-1) + 1
inind = BB+1
state = 0
while ind <= r:
#print (ind,BB,inind)
now = 0
if state == 0:
now = BB
state = 1
else:
now = inind
inind += 1
state = 0
if inind == n+1:
BB += 1
inind = BB+1
if ind == ss(2*n-2,-2,n-1) + 1:
ans.append(1)
break
if ind >= l:
ans.append(now)
ind += 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
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
long long int oo = numeric_limits<long long int>::max();
long long int MOD = 1e9 + 7;
long long int comp(long long int n, long long int i) {
return 2 * 1LL * (n - i);
}
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cin.exceptions(cin.failbit);
int t;
cin >> t;
while (t--) {
long long int n, l, r;
cin >> n >> l >> r;
long long int i = 1;
while (i <= n && comp(n, i) < l) i++;
long long int idx = i == 1 ? 0 : comp(n, i - 1LL);
for (; i <= n; i++) {
for (long long int j = 0; j < comp(n, i); j++) {
long long int nm;
if (j % 2 == 0) {
nm = i;
} else {
nm = (j / 2) + i + 1;
}
idx++;
if (idx >= l && idx <= r) {
cout << nm << " ";
} else if (idx > r) {
cout << "HERE\n";
;
goto end;
}
}
}
idx++;
if (idx <= r) cout << 1;
end:
cout << endl;
continue;
}
}
|
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):
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
|
java
|
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
import java.io.*;
public class codeforces
{
static class Student{
int x,y,z;
Student(int x,int y,int z){
this.x=x;
this.y=y;
this.z=z;
}
}
static int prime[];
static void sieveOfEratosthenes(int n)
{
// Create a boolean array "prime[0..n]" and initialize
// all entries it as true. A value in prime[i] will
// finally be false if i is Not a prime, else true.
int pos=0;
prime= new int[n+1];
for(int p = 2; p*p <=n; p++)
{
// If prime[p] is not changed, then it is a prime
if(prime[p] == 0)
{
// Update all multiples of p
prime[p]=p;
for(int i = p*p; i <= n; i += p)
prime[i] = p;
}
}
}
static class Sortbyroll implements Comparator<Student>
{
// Used for sorting in ascending order of
// roll number
public int compare(Student c, Student b)
{
return (b.y-b.z)-(c.y-c.z);
}
}
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;
}
}
static class Edge{
int a,b;
Edge(int a,int b){
this.a=a;
this.b=b;
}
}
static class Trie{
Trie z,o;
// int c;
Trie(){
z=null;
o=null;
//c=0;
}
}
//static long ans;
static int parent[];
static int rank[];
static int b[][];
static int bo[];
static int ho[];
static int seg[];
//static int pos;
// static long mod=1000000007;
//static int dp[][];
static HashMap<Integer,Integer>map;
static PriorityQueue<Student>q=new PriorityQueue<>();
//static Stack<Integer>st;
// static ArrayList<Character>ans;
static ArrayList<ArrayList<Integer>>adj;
//static int ans;
static Trie root;
static long fac[];
static long mod=(long)(998244353);
static void solve()throws IOException{
FastReader sc=new FastReader();
int t,i,n,j,c,li;
long l,r,p,sum,t1;
t=sc.nextInt();
while(t>0){
sum=0;
p=1;
n=sc.nextInt();
l=sc.nextLong();
r=sc.nextLong();
sum=1;
li=1;
for(i=2;i<=n;i++){
sum+=(long)(2*i-2);
if(sum<=l){
p=sum;
li=i+1;
}
if(sum>=r)
break;
}
//p=sum-(long)(2*i-2);
Queue<Integer>q=new LinkedList<>();
q.add(1);
t1=p;
//p+=(long)1;
j=2;
c=0;
while(p<sum){
j=2;
c=0;
for(int x=1;x<=2*li-3;x++){
if(c%2==0)
q.add(li);
else{
q.add(j);
++j;
}
c=1-c;
}
if(li!=1)
q.add(1);
p+=(long)(2*li-2);
++li;
}
//q.add(1);
p=t1;
while(p<l){
q.poll();
p+=(long)1;
}
StringBuilder sb=new StringBuilder();
while(p<=r){
sb.append(q.poll()+" ");
p+=(long)1;
}
System.out.println(sb.toString());
--t;
}
}
static int lower(int s,int e,int a[],int s1){
int ans=a[s];
int mid=(s+e)/2;
while(s<=e){
if(a[mid]<=s1){
ans=a[mid];
s=mid+1;
}
else
e=mid-1;
mid=(s+e)/2;
}
return ans;
}
static int upper(int s,int e,int a[],int s1){
int ans=a[e];
int mid=(s+e)/2;
while(s<=e){
if(a[mid]>=s1){
ans=a[mid];
e=mid-1;
}
else
s=mid+1;
mid=(s+e)/2;
}
return ans;
}
static void dfs(int c,int p,int s){
int y=0;
for(int i=0;i<adj.get(c).size();i++){
if(adj.get(c).get(i)==p)
continue;
dfs(adj.get(c).get(i),c,s+1);
++y;
}
if(y==0){
//map.put(c,0);
//System.out.println(c+" "+s);
q.add(new Student(c,s,0));
}
}
static long nCr(long n, long r,
long p)
{
return (fac[(int)n]* modInverse(fac[(int)r], p)
% p * modInverse(fac[(int)(n-r)], p)
% p) % p;
}
public static void main(String[] args){
//long sum=0;
try {
codeforces.solve();
} catch (Exception e) {
e.printStackTrace();
}
}
static long modInverse(long n, long p)
{
return power(n, p-(long)2, p);
}
static long power(long x, long y, long p)
{
long res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0)
{
// If y is odd, multiply x with result
if (y %(long)2!=0)
res = (res*x) % p;
// y must be even now
y = y>>1; // y = y/2
x = (x*x) % p;
}
return res%p;
}
static int find(int x)
{
// Finds the representative of the set
// that x is an element of
while(parent[x]!=x)
{
// if x is not the parent of itself
// Then x is not the representative of
// his set,
x=parent[x];
// so we recursively call Find on its parent
// and move i's node directly under the
// representative of this set
}
return x;
}
static void union(int x, int y)
{
// Find representatives of two sets
int xRoot = find(x), yRoot = find(y);
// Elements are in the same set, no need
// to unite anything.
if (xRoot == yRoot)
return;
// If x's rank is less than y's rank
if (rank[xRoot] < rank[yRoot])
// Then move x under y so that depth
// of tree remains less
parent[xRoot] = yRoot;
// Else if y's rank is less than x's rank
else if (rank[yRoot] < rank[xRoot])
// Then move y under x so that depth of
// tree remains less
parent[yRoot] = xRoot;
else // if ranks are the same
{
// Then move y under x (doesn't matter
// which one goes where)
parent[yRoot] = xRoot;
// And increment the the result tree's
// rank by 1
rank[xRoot] = rank[xRoot] + 1;
}
}
static int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, 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>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ldb;
typedef vector<ll> vll;
typedef ll __T;
typedef tree<__T, null_type, less<__T>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ff first
#define ss second
#define pll pair<ll,ll>
#define CL(a) memset(a,0,sizeof(a))
#define all(x) x.begin(),x.end()
#define sz(x) ((ll)x.size())
#define lp0(i,n) for(ll i=0;i<n;i++)
#define lp1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mpr make_pair
#define op(a) cout << a << "\n";
#define tc ll testcase; cin>>testcase; while(testcase--)
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define l(x) cout <<"lol"<<x<<"\n";
#define trace1(x) cout <<#x<<":"<<x<< endl;
#define trace2(x, y) cout <<#x<<":"<<x<<" | "<<#y<<":"<<y<< endl;
#define trace3(x, y, z) cout <<#x<<":"<<x<<" | "<<#y<<":"<<y<<" | "<<#z<<":"<<z<<endl;
#define trace4(a, b, c, d) cout <<#a<<":"<<a<<" | "<<#b<<":"<<b<<" | "<<#c<<":"<<c<<" | "<<#d<<":"<<d<<endl;
const ll mod = 1e9+7;
const ldb PI = acos(-1);
const ll maxn = 1e6+4;
ll POWER[65];
void precompute() {POWER[0]=1; for(ll i=1;i<63;i++) POWER[i]=POWER[i-1]<<1LL; }
ll fastMul(ll a,ll b,ll mod){ll res = 0; a %= mod; while (b){ if (b & 1){res = (res + a) % mod;} a = (2 * a) % mod; b >>= 1;} return res;}
ll power(ll x,ll y,ll mod2) {ll res=1; x%=mod2; while(y) {if(y&1) res=(res*x)%mod2; y>>=1; x=(x*x)%mod2; }return res;}
ll inv(ll x,ll mod){return power(x,mod-2,mod);}
// freopen("testfile.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// order_of_key , find_by_order
/* Look at the stars , look how they shine for you ! */
void arpit(){
ll t;
cin >> t;
while(t--){
ll n1,l,r;
cin >> n1 >> l >> r;
ll n = (sqrtl(1LL+4LL*l)-1LL)/2LL;
// trace1(n);
if(((ll)sqrtl(1LL-4LL*l)-1LL)%2LL){
n = n;
}else{
n--;
}
ll idx = l-n*(n+1);
ll pr = idx;
ll hehe = n+1;
ll put = n+2;
while(idx+n*(n+1) <= r){
if(idx%2){
cout << pr << " ";
// trace1(pr);
pr++;
}else{
cout << put << " ";
}
if(idx == hehe*(hehe+1)){
hehe++;
pr = 1;
put++;
}
idx++;
// hehe++;
}
cout << "\n";
}
}
int main()
{
fast_io();
arpit();
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
// unique values or same values
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
|
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
def solve(n,l,r):
fir,st = 0,1
while st < n:
x = 2*(n-st)
if fir+x >= l:
break
fir += x
st += 1
if st == n:
return [1]
ans = []
for z in range(st+1,n+1):
ans.append(st)
ans.append(z)
st += 1
if st == n:
ans.append(1)
else:
for z in range(st+1,n+1):
ans.append(st)
ans.append(z)
return ans[l-fir-1:r-fir]
def main():
for _ in range(int(input())):
n,l,r = map(int,input().split())
print(*solve(n,l,r))
# Fast IO Region
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")
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
|
java
|
import java.io.*;
import java.util.*;
public class Main implements Runnable {
static boolean use_n_tests = true;
static int stack_size = 1 << 27;
int n, m;
int[][] mt;
void solve(FastScanner in, PrintWriter out, int testNumber) {
n = in.nextInt();
long l = in.nextLong();
long r = in.nextLong();
long s = 0;
int startFrom = 1;
long hm = r - l + 1;
for (int i = 0; i < n; i++) {
if (l <= s + (n - i - 1) * 2) {
long pos = s;
for (int j = startFrom; j <= n - 1 && hm > 0; j++) {
for (int k = j + 1; k <= n && hm > 0; k++) {
if (hm >= 2 && in(pos + 1, l , r) && in(pos + 2, l , r)) {
out.printf("%d %d ", j, k);
hm -= 2;
} else if (in(pos + 1, l , r)) {
out.printf("%d", k);
hm--;
}
pos += 2;
}
}
if (hm > 0) {
out.println(1);
} else {
out.println();
}
return;
}
s += (n - i - 1) * 2;
startFrom++;
}
if (hm == 1) {
out.println(1);
}
}
boolean in(long p, long l, long r) {
return p >= l && p <= r;
}
// ****************************** template code ***********
class Coeff {
long mod;
long[][] C;
long[] fact;
boolean cycleWay = false;
Coeff(int n, long mod) {
this.mod = mod;
fact = new long[n + 1];
fact[0] = 1;
for (int i = 1; i <= n; i++) {
fact[i] = i;
fact[i] %= mod;
fact[i] *= fact[i - 1];
fact[i] %= mod;
}
}
Coeff(int n, int m, long mod) {
// n > m
cycleWay = true;
this.mod = mod;
C = new long[n + 1][m + 1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= Math.min(i, m); j++) {
if (j == 0 || j == i) {
C[i][j] = 1;
} else {
C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
C[i][j] %= mod;
}
}
}
}
public long C(int n, int m) {
if (cycleWay) {
return C[n][m];
}
return fC(n, m);
}
private long fC(int n, int m) {
return (fact[n] * inv(fact[n - m] * fact[m] % mod)) % mod;
}
private long inv(long r) {
if (r == 1)
return 1;
return ((mod - mod / r) * inv(mod % r)) % mod;
}
}
class Pair {
int first;
int second;
public int getFirst() {
return first;
}
public int getSecond() {
return second;
}
}
class MultisetTree<T> {
int size = 0;
TreeMap<T, Integer> mp = new TreeMap<>();
void add(T x) {
mp.merge(x, 1, Integer::sum);
size++;
}
void remove(T x) {
if (mp.containsKey(x)) {
mp.merge(x, -1, Integer::sum);
if (mp.get(x) == 0) {
mp.remove(x);
}
size--;
}
}
T greatest() {
return mp.lastKey();
}
T smallest() {
return mp.firstKey();
}
int size() {
return size;
}
int diffSize() {
return mp.size();
}
}
class Multiset<T> {
int size = 0;
Map<T, Integer> mp = new HashMap<>();
void add(T x) {
mp.merge(x, 1, Integer::sum);
size++;
}
void remove(T x) {
if (mp.containsKey(x)) {
mp.merge(x, -1, Integer::sum);
if (mp.get(x) == 0) {
mp.remove(x);
}
size--;
}
}
int size() {
return size;
}
int diffSize() {
return mp.size();
}
}
static class Range {
int l, r;
int id;
public int getL() {
return l;
}
public int getR() {
return r;
}
public Range(int l, int r, int id) {
this.l = l;
this.r = r;
this.id = id;
}
}
static class Array {
static Range[] readRanges(int n, FastScanner in) {
Range[] result = new Range[n];
for (int i = 0; i < n; i++) {
result[i] = new Range(in.nextInt(), in.nextInt(), i);
}
return result;
}
static boolean isSorted(Integer[] a) {
for (int i = 0; i < a.length - 1; i++) {
if (a[i] > a[i + 1]) {
return false;
}
}
return true;
}
static public Integer[] read(int n, FastScanner in) {
Integer[] out = new Integer[n];
for (int i = 0; i < out.length; i++) {
out[i] = in.nextInt();
}
return out;
}
static public int[] readint(int n, FastScanner in) {
int[] out = new int[n];
for (int i = 0; i < out.length; i++) {
out[i] = in.nextInt();
}
return out;
}
}
class Graph {
List<List<Integer>> create(int n) {
List<List<Integer>> graph = new ArrayList<>();
for (int i = 0; i < n; i++) {
graph.add(new ArrayList<>());
}
return graph;
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(InputStream io) {
br = new BufferedReader(new InputStreamReader(io));
}
public String line() {
String result = "";
try {
result = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
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());
}
}
void run_t_tests() {
int t = in.nextInt();
int i = 0;
while (t-- > 0) {
solve(in, out, i++);
}
}
void run_one() {
solve(in, out, -1);
}
@Override
public void run() {
in = new FastScanner(System.in);
out = new PrintWriter(System.out);
if (use_n_tests) {
run_t_tests();
} else {
run_one();
}
out.close();
}
static FastScanner in;
static PrintWriter out;
public static void main(String[] args) throws InterruptedException {
Thread thread = new Thread(null, new Main(), "", stack_size);
thread.start();
thread.join();
}
}
|
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 = (1 ? 100000000000000007 : 233333333333333333);
const int mod = (1 ? 1000000007 : 998244353);
const long long INF = 0x7fffffffffffffff;
const int inf = 0x7fffffff;
const double eps = 1e-8;
const int N = 1e6 + 5;
clock_t start, finish;
void time_in() { start = clock(); }
void time_out() {
finish = clock();
double tim = (double)(finish - start) / CLOCKS_PER_SEC;
printf("Running time is %lf\n", tim);
}
inline long long mul(long long a, long long b) {
long long s = 0;
while (b) {
if (b & 1) s = (s + a) % mod;
a = (a << 1) % mod;
b >>= 1;
}
return s % mod;
}
inline long long pow_mul(long long a, long long b) {
long long s = 1;
while (b) {
if (b & 1) s = mul(s, a);
a = mul(a, a);
b >>= 1;
}
return s;
}
inline long long poww(long long a, long long b) {
long long s = 1;
while (b) {
if (b & 1) s = (s * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return s % mod;
}
inline int read() {
char c = getchar();
int sgn = 1, ret = 0;
while (c != '-' && (c < '0' || c > '9')) c = getchar();
if (c == '-') sgn = -1, c = getchar();
while (c >= '0' && c <= '9') ret = ret * 10 + c - 48, c = getchar();
return ret * sgn;
}
void write(int x) {
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
inline long long phi(long long x) {
long long ans = x;
for (long long i = 2; i * i <= x; i++)
if (x % i == 0) {
ans -= ans / i;
while (x % i == 0) x /= i;
}
if (x > 1) ans -= ans / x;
return ans;
}
int st[5][3] = {-1, 0, 0, 1, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 1};
int t, cas;
long long m, n;
int main() {
scanf("%d", &t);
int a[10] = {0, 1, 2, 1};
while (t--) {
long long l, r, s = 0;
int x = 1;
scanf("%lld%lld%lld", &n, &l, &r);
for (int i = 1, j = 1; i < n; i++, j--) {
if (j == 0) j += n;
if (s + (n - i) * 2 < l) {
s += (n - i) * 2;
} else {
x = j;
break;
}
}
if (n == 2) {
for (int i = l; i <= r; i++) {
printf("%d ", a[i]);
}
printf("\n");
continue;
}
for (int i = x; s < r; i--) {
if (i == 0) i += n;
if (i == 1) {
for (int j = 2; j < n; j++) {
s++;
if (s >= l && s <= r) printf("%d ", i);
s++;
if (s >= l && s <= r) printf("%d ", j);
if (s >= r) goto e;
}
s++;
printf("1 ");
} else if (i == 2) {
for (int j = 3;; j++) {
if (j > n) j -= n;
s++;
if (s >= l && s <= r) printf("%d ", j);
if (s >= r) goto e;
}
} else {
for (int j = 2; j < i; j++) {
s++;
if (s >= l && s <= r) printf("%d ", i);
s++;
if (s >= l && s <= r) printf("%d ", j);
if (s >= r) goto e;
}
}
}
e:;
printf("\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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
#include <stdio.h>
#include <time.h>
#include <chrono>
#include <ctime>
#define mt make_tuple
#define ll long long
#define ld long double
#define eb emplace_back
#define fi first
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define make_unique(vec) sort(all(vec)); vec.resize(unique(all(vec)) - vec.begin());
#define scanVec(vec) for(int i = 0; i < SZ(vec) ; i++){ cin >> vec[i];}
#define printVec(vec) for(int i = 0; i < SZ(vec) ; i++){ cout<<vec[i]<<" ";}
#define mod(a,b) ((a%b +b)%b)
#define bit(x,i) (x&(1<<i)) //select the bit of position i of x
#define lowbit(x) ((x)&((x)^((x)-1))) //get the lowest bit of x
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) //get the highest bit of x, maybe the fastest
//#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define lastEle(vec) vec[vec.size()-1]
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define INF 1001001001
//#define PI 3.1415926535897932384626
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
#define deb(args...) { error(args); cout << flush;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << " [" << *it << ": " << a << "] " << flush;
err(++it, args...);
}
//----------------------------------------------------------------------------------------------------------------------
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
// unordered_map<long long, int, custom_hash> safe_map;
// unordered_set<long long, custom_hash> safe_set;
//----------------------------------------------------------------------------------------------------------------------
void swap(char & a, char & b){
auto temp = a;
a = b;
b = temp;
}
const ll MOD = 1e9 + 7;
unsigned ll inf = 1ULL*1e18;
void no(){
cout <<"NO" << endl;
//exit(0);
}
void yes(){
cout <<"YES" << endl; //exit(0);
}
const ll md = 998244353;
const int MAXN = 2*1e5 + 10;
void sl(){
ll n,left,right;
cin >> n >> left >> right;
vector< ll > ans (right - left + 1);
ll curr = 1;
ll l = 1; ll r = n;
while(l <= r){
ll c = l + (r - l)/2;
ll sum = c*n - ( ((c + 1)*c) / 2 );
sum*=2;
if(sum <= left){
curr = max(c,curr);
l = c + 1;
}else{
r = c - 1;
}
}
l = 1; r = n - curr;
ll from = 0;
while(l <= r){
ll c = l + (r - l)/2;
if(curr + c*2 <= left){
from = max(from,c);
l = c + 1;
}else{
r = c - 1;
}
}
ll currInd = curr + from*2;
//deb(from) cout << endl;
from = curr + 1 + from;
//deb(currInd,curr,from); cout << endl;
int pos = 0;
if(currInd != left){
pos++;
}
//deb(currInd,curr,from,pos); cout << endl;
for(int i = 0;i < SZ(ans);i++){
// deb(curr,from,pos); cout << endl;
if(curr == n){
ans[i] = 1LL; break;
}
if(pos == 0){
ans[i] = curr;
}else{
ans[i] = from;
from++;
if(from > n){
curr++;
from = curr + 1;
}
}
pos++; pos %= 2;
}
for(auto & it : ans){
cout << it << " ";
}
cout << endl;
}
int main(){
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//srand(time(NULL));
// 1 - multiple tests
// 0 - single test
int ts = 1;
if(ts == 1) cin >> ts;
else ts = 1;
while(ts--) sl();
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
# print(now)
if len(res)>(r-k+1)+dif: break
res = res[dif-1:]
if r==(n-1)*n+1: res.append(1)
# print(res)
print(*res[:r-l+1])
# s = "1 2 1 3 1 4 1 5 1 6 2 3 2 4 2 5 2 6 3 4 3 5 3 6 4 5 4 6 1"
# s = "1 2 1 3 1 4 1 5 1 6 2 3 2 4 2 5 2 6 3 4 3 5 3 6 4 5 4 6 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
|
python3
|
def f(n):
return((1 + (1+4*n)**.5)/2)
t = int(input())
for x in range(t):
n,l,r = map(int, input().split())
l -= 1
r -= 1
lst = []
for i in range(l, r+1):
low = int(f(i))
place = i - (low**2 - low)
if place == 0:
lst.append(1)
elif place % 2 == 1:
lst.append(low+1)
else:
lst.append(int(place/2) + 1)
mot = ""
for x in lst:
mot += str(x) + " "
print(mot)
|
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//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
|
python3
|
def main():
t=int(input())
for _ in range(t):
n,l,r=map(int,input().split())
if l==n*n-n+1:
print(1)
continue
if r==n*n-n+1:
r_g=n
for i in range(n-1):
if l>2*n-2-2*i:
l-=2*n-2-2*i
else:
l_g=i+1
break
for i in range(n-1):
if r>2*n-2-2*i:
r-=2*n-2-2*i
else:
r_g=i+1
break
ans=[]
for i in range(l_g,max(r_g+1,n)):
for j in range(i+1,n+1):
ans.append(i)
ans.append(j)
if r_g==n:
ans.append(1)
if r_g==n or r==2*n-2*r_g:
print(*ans[l-1:])
else:
print(*ans[l-1:r+2*r_g-2*n])
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
|
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) {
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 {
pw.print((l+1)/2+" ");
}
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
|
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 + int(l/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
|
// Don't place your source in a package
import javax.swing.*;
import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.util.stream.Stream;
// Please name your class Main
public class Main {
static FastScanner fs=new FastScanner();
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
public String next() {
while (!st.hasMoreElements())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int Int() {
return Integer.parseInt(next());
}
long Long() {
return Long.parseLong(next());
}
String Str(){
return next();
}
}
public static void main (String[] args) throws java.lang.Exception {
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int T=Int();
for(int t=0;t<T;t++){
int n=Int();
long l=Long();
long r=Long();
Solution sol=new Solution(out);
sol.solution(n,l,r);
}
out.close();
}
public static int Int(){
return fs.Int();
}
public static long Long(){
return fs.Long();
}
public static String Str(){
return fs.Str();
}
}
class Solution{
PrintWriter out;
public Solution(PrintWriter out){
this.out=out;
}
public void solution(int n,long l,long r){
long cur=2*(n-1);
long sum=(2+cur)*(n-1)/2;
if(l>sum){
out.println(1);
return;
}
//20 18 16 14 12 10 8 ...
sum=0;
int first=1;
while(sum+cur<l){
sum+=cur;
cur-=2;
first++;
}
//out.println(sum+" "+cur+" "+first);
for(long i=l;i<=r;i++){
if(i%2==1){
out.print(first+" ");
}
else{
long dis=l-sum;
out.print((first+dis/2+1)+" ");
}
if(i==sum+cur){
sum+=cur;
cur-=2;
first++;
if(first==n)first=1;
}
}
out.println();
}
//1 2 1 3 1 4 2 3 2 4 3 4 1
//1 2 1 3 1 4 1 5 2 3 2 4 2 5 3 4 3 5 4 5 1
//1 2 1 3 1 4 1 5 1 6 2 3 2 4 2 5 2 6 3 4 3 5 3 6 4 5 4 6 5 6 1
// 1 2 1 3 2 3 1
}
/*
;\
|' \
_ ; : ;
/ `-. /: : |
| ,-.`-. ,': : |
\ : `. `. ,'-. : |
\ ; ; `-.__,' `-.|
\ ; ; ::: ,::'`:. `.
\ `-. : ` :. `. \
\ \ , ; ,: (\
\ :., :. ,'o)): ` `-.
,/,' ;' ,::"'`.`---' `. `-._
,/ : ; '" `;' ,--`.
;/ :; ; ,:' ( ,:)
,.,:. ; ,:., ,-._ `. \""'/
'::' `:'` ,'( \`._____.-'"'
;, ; `. `. `._`-. \\
;:. ;: `-._`-.\ \`.
'`:. : |' `. `\ ) \
-hrr- ` ;: | `--\__,'
'` ,'
,-'
free bug dog
*/
|
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) {
int n = sc.nextInt();
long l = Long.parseLong(sc.next());
long r = Long.parseLong(sc.next());
long max = n*(n-1)+1;
long idx = 0;
long count = 1;
while(idx<l) {
idx+=count*2;
count++;
}
idx-=(count-1)*2-1;
long cnt = 1;
long nxt = idx+(count-1)*2;
while(idx<r) {
if(idx == nxt) {
cnt = 1;
count++;
nxt = idx+(count-1)*2;
}
if(idx>=l) {
if(idx%2==0) {
System.out.print(count + " ");
}else {
System.out.print(cnt + " ");
cnt++;
}
}else if(idx%2==1) {
cnt++;
}
idx++;
}
if(idx == nxt) {
cnt = 1;
count++;
nxt = idx+(count-1)*2;
}
if(idx%2==0) {
System.out.println(count);
}else {
System.out.println(cnt);
cnt++;
}
}
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
|
python3
|
# from debug import debug
t = int(input())
for ii in range(t):
n, l, r = map(int, input().split())
s = []
count = 1
ans = count*(2*(n-1) + 1- count)
while ((n-count)>0 and ans<l):
count+=1
ans = count*(2*(n-1) + 1- count)
# debug(ans=ans)
count-=1
remain = l-count*(2*(n-1) + 1- count)-1
val = 0
b = 0
for i in range(count, n):
for j in range(i+1, n):
s.append(i+1)
s.append(j+1)
val+=2
if val>r-l+1:
b = 1
break
if b:
break
s.append(1)
q = s[remain:r-l+1+remain]
for i in range(len(q)-1):
print(q[i], end=" ")
print(q[-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
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
long long int vmax(vector<long long int> &v) {
return (*max_element(v.begin(), v.end()));
}
long long int vmin(vector<long long int> &v) {
return (*min_element(v.begin(), v.end()));
}
long long int power_mod_m(long long int x, long long int y, long long int p) {
long long int res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0) {
if (y & 1) res = ((res % p) * (x % p)) % p;
y = y >> 1;
x = ((x % p) * (x % p)) % p;
}
return res;
}
long long int inverse_mod(long long int x, long long int mod) {
return (power_mod_m(x, mod - 2, mod));
}
void solve() {
long long int n, l, r;
cin >> n >> l >> r;
if (r == l && r - 1 == (n * (n - 1))) {
cout << 1 << "\n";
return;
}
long long int is_present = 0;
if (r - 1 == (n * (n - 1))) {
is_present = 1;
r--;
}
long long int sum = (n - 1) * 2;
vector<long long int> v;
while (sum != 0) {
v.push_back(sum);
sum = sum - 2;
}
for (int j = 1; j < v.size(); j += 1) {
v[j] = v[j - 1] + v[j];
}
long long int i = lower_bound(v.begin(), v.end(), l) - v.begin();
long long int element_prev = 0;
if (i >= 1) {
element_prev = v[i - 1];
}
if ((l - element_prev) % 2 != 0) {
long long int add = (l - element_prev + 1) / 2;
long long int start = i + 1;
add = add + start;
if (l == r) {
cout << start << " ";
} else {
cout << start << " " << add << " ";
long long int cnt = 2;
long long int x = start;
long long int in = 1;
while (cnt < r - l + 1) {
add++;
if (add == n + 1) {
start = x + in;
in++;
add = start + 1;
}
cout << start << " ";
cnt++;
if (cnt < r - l + 1) {
cout << add << " ";
cnt++;
} else {
break;
}
}
}
} else {
long long int start = i + 1;
long long int add = (l - element_prev) / 2;
add = add + start;
if (l == r) {
cout << add << " ";
} else {
long long int cnt = 1;
long long int x = start;
long long int in = 1;
while (cnt < r - l + 1) {
cout << add << " ";
cnt++;
if (cnt < r - l + 1) {
add++;
if (add == n + 1) {
start = x + in;
in++;
add = start + 1;
}
cout << start << " ";
cnt++;
} else {
break;
}
}
}
}
if (is_present == 1) {
cout << 1 << "\n";
return;
}
cout << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
mt19937 rand(chrono::steady_clock::now().time_since_epoch().count());
long long int t = 1;
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
|
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()
res = []
sm = 0
i = 0
while sm<l:
i+=1
sm+=i*2
# print(i, sm)
sm-=i*2
i-=1
dif = l - sm + 1
l-=sm
r-=sm
res = []
# print(dif, i, sm)
while len(res)<r-l:
now = []
for j in range(1, i+1):
now.append(j)
now.append(i+1)
res+=now[dif:]
dif = 0
i+=1
# print(res)
if len(res)<r-l+1:
res.append(1)
# print(res, r-l+1,l, r)
print(*res[l-1: r])
# for i in range(2, n+1):
# now = []
# for j in range(1, i-1):
# now.append(j)
# now.append(i)
# sm+=len(now)
# if sm>l:
# print(now)
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())
if t == 3:
print(1, 2, 1)
print(1,3,2,3)
print(1)
exit()
if t < 5:
while True:
x = input()
|
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.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
public class a {
static class pair implements Comparable<pair> {
long x, y;
public pair(long l, long m) {
x = l;
y = m;
}
@Override
public String toString() {
return "(" + x + " " + y + ")";
}
@Override
public int compareTo(pair o) {
// TODO Auto-generated method stub
return (int) (x - o.x);
}
}
static class UnionFind {
int[] p, rank, setSize;
int numSets;
public UnionFind(int N) {
p = new int[numSets = N];
rank = new int[N];
setSize = new int[N];
for (int i = 0; i < N; i++) {
p[i] = i;
setSize[i] = 1;
}
}
public int findSet(int i) {
return p[i] == i ? i : (p[i] = findSet(p[i]));
}
public boolean isSameSet(int i, int j) {
return findSet(i) == findSet(j);
}
public void unionSet(int i, int j) {
if (isSameSet(i, j))
return;
numSets--;
int x = findSet(i), y = findSet(j);
if (rank[x] > rank[y]) {
p[y] = x;
setSize[x] += setSize[y];
} else {
p[x] = y;
setSize[y] += setSize[x];
if (rank[x] == rank[y])
rank[y]++;
}
}
public int numDisjointSets() {
return numSets;
}
public int sizeOfSet(int i) {
return setSize[findSet(i)];
}
}
static ArrayList<Integer> primes;
static int[] isComposite;
static void sieve(int N) // O(N log log N)
{
isComposite = new int[N + 1];
isComposite[0] = isComposite[1] = 1; // 0 indicates a prime number
primes = new ArrayList<Integer>();
for (int i = 2; i <= N; ++i) // can loop till i*i <= N if primes array is not needed O(N log log sqrt(N))
if (isComposite[i] == 0) // can loop in 2 and odd integers for slightly better performance
{
primes.add(i);
if (1l * i * i <= N)
for (int j = i * i; j <= N; j += i) // j = i * 2 will not affect performance too much, may alter in
// modified sieve
isComposite[j] = 1;
}
}
static boolean isPrime(int N) {
if (N < isComposite.length)
return isComposite[N] == 0;
for (int p : primes) // may stop if p * p > N
if (N % p == 0)
return false;
return true;
}
static int m;
static ArrayList<pair> mask;
// generated by sieve
/*
* 1. Generating a list of prime factors of N
*/
static ArrayList<Integer> primeFactors(int N) // O(sqrt(N) / ln sqrt(N))
{
ArrayList<Integer> factors = new ArrayList<Integer>(); // take abs(N) in case of -ve integers
int idx = 0, p = primes.get(idx);
while (p * p <= N) {
while (N % p == 0) {
factors.add(p);
N /= p;
}
p = primes.get(++idx);
}
if (N != 1) // last prime factor may be > sqrt(N)
factors.add(N); // for integers whose largest prime factor has a power of 1
return factors;
}
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(br.readLine());
int te = Integer.parseInt(st.nextToken());
while (te-- > 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 dif = r - l + 1;
if (l == 1) {
if (dif > 1) {
pw.print(1 + " " + 2+" ");
l = 3;
} else {
pw.print(1 + " ");
l = 2;
}
}
dif = r - l + 1;
long x = bs(l);
long g = l - x * (x + 1) - 1;
x+=2;
long start = 0;
if (g == 0) {
start = 2;
if (dif > 1) {
pw.print(1 + " " + x + " ");
dif -= 2;
} else {
pw.print(1);
dif -= 1;
}
} else if (g % 2 == 1) {
pw.print(x);
start = g / 2 + 2;
dif--;
} else {
start = g / 2 + 1;
}
while (dif > 0) {
if (start < x) {
if (dif == 1) {
pw.print(start);
dif--;
} else {
dif -= 2;
pw.print(start + " " + x + " ");
start++;
}
} else {
if (start == x) {
x++;
if (dif == 1) {
pw.print(1);
dif--;
} else {
dif -= 2;
pw.print(1 + " " + x + " ");
start = 2;
}
}
}
}
pw.println();
}
pw.flush();
}
public static long bs(long x) {
long lo = 0;
long hi = (long) 1e9;
long ans = -1;
while (lo <= hi) {
long mid = (lo + hi) / 2;
long sum = mid * (mid + 1);
if (sum <= x) {
ans = mid;
lo = mid + 1;
} else
hi = mid - 1;
}
return 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[])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]);
long num=1;
long sum=0;
while(sum+num*2<=l)
{
sum+=num*2;
num++;
}
//num--;
l-=sum;
r-=sum;
int arr[]=new int[200000];
int ind=0;
arr[0]=1;
l--;
r--;
//System.out.println(l+" "+r);
for(int i=(int)num+1;i<=n&&ind<=r;i++)
{
for(int j=2;j<=i&&ind<=r;j++)
{
arr[++ind]=i;
if(j==i)
arr[++ind]=1;
else
arr[++ind]=j;
}
}
/*for(int i=0;i<arr.length;i++)
pw.print(arr[i]+" ");*/
for(int i=(int)l;i<=(int)r;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
|
import sys
from collections import defaultdict
from copy import copy
R = lambda t = int: t(input())
RL = lambda t = int: [t(x) for x in input().split()]
RLL = lambda n, t = int: [RL(t) for _ in range(n)]
def solve():
n, l, r = RL()
l -= 1
r -= 1
D = ((2*n-1)**2-4*l)**.5
a = (2*n-1-D)/2
a = int(a)
x = a*((n-1)+(n-a))
l -= x
r -= x
i = 0
s = ""
a += 1
b = a + 1
while i < r:
s += str(a) + str(b)
b += 1
if b > n:
a += 1
b = a + 1
i += 2
s += "1"
for c in s[l:r+1]:
print(c,end = " ")
print()
T = R()
for _ in range(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
|
cpp
|
/*
#
# # # # #### # # # #
# # ## # # # # # #
# # # # # #### ###### # #
####### # # # # # # # #
# # # ## # # # # # #
# # # # #### # # ####
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long int
#define hell 1000000007
#define F first
#define re 15000000
#define S second
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rep(i,a,b) for(int i = a;i<b;i++)
#define pi 3.1415926536
#define Mod 998244353
#define endl '\n'
#define TIME cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
int binarySearch(int x,int y ,int z ,int v[])
{
int low = x;
int high = y;
int mid = x+(y-x)/2;
while(low<=high)
{
if(v[mid]==z)
return mid;
if(v[mid]<z)
return binarySearch(mid+1,high,z,v);
if(v[mid]>z)
return binarySearch(low,mid-1,z,v);
}
return -1;
}
int modularExponentiation(int x, int y, int m)
{
if (y == 0)
return 1;
int p = modularExponentiation(x, y/2, m) % m;
p = (p * p) % m;
return (y%2 == 0)? p : (x * p) % m;
}
int binaryExponentiation(int x,int n)
{
if(n==0)
return 1;
else if(n%2 == 0) //n is even
return binaryExponentiation(x*x,n/2);
else //n is odd
return x*binaryExponentiation(x*x,(n-1)/2);
}
set<string> s;
//vector<int> v;
void genrate(string n,int len,int max)
{
if(n.size() == max){
s.insert(n);
return ;
}
genrate(n+'1',len+1,max);
genrate(n+'0',len+1,max);
}
// bool visited[200005];
// vector<int> v[200005];
// bool recur[200005];
// int c = 0;
// void dfs(int x ,int parent)
// {
// visited[x] = 1;
// if(v[x].size() != 2)
// c = -1;
// for(int i = 0;i<v[x].size();i++){
// if(v[x][i] == parent)
// continue;
// if(visited[v[x][i]] && v[x].size() == 2 && c == 0)
// c = 1;
// else if(!visited[v[x][i]]){
// dfs(v[x][i],x);
// }
// //return false;
// }
// }
//memset(level,0,sizeof(level));
//char a2001][2001];
///**************** Cycle using DSU *********************///
/* int topological_sort(int x)
{
vis[x] = 1;
sort(all(v[x]));
ans.pb(x);
last[x] = x;
for(int i =0;i<v[x].size();i++)
{
if(vis[v[x][i]]!=1){
last[x] = topological_sort(v[x][i]);
}
}
return last[x];
}
*/
int my_lower(vector<int> &v, int X){
int lo = 0, hi = v.size()-1;
if(v.size() == 0)
return -1;
while(hi-lo > 1){
int mi = (lo+hi)/2;
if(v[mi] < X){
lo = mi;
}
else
hi = mi-1;
}
int ans = -1;
for(int i = lo;i<=hi;i++){
if(v[i] < X){
ans = i;
}
}
if(ans != -1 && v[ans] < X){
return ans;
}
else
return -1;
}
int my_upper(vector<int> & v, int X){
if(v.size() == 0)
return -1;
int lo = 0, hi = v.size()-1;
while(hi-lo > 1){
int mi = (lo+hi)/2;
if(v[mi] < X){
lo = mi+1;
}
else
hi = mi;
}
int ans = -1;
for(int i = hi;i>=lo;i--){
if(v[i] >= X){
ans = i;
}
}
if(ans != -1 && v[ans] >= X){
return ans;
}
else
return -1;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//std::setprecision(20);
int tests=1;
//freopen("input.txt", "r", stdin);
cin>>tests;
while(tests--)
{
int n,l,r;
cin>>n>>l>>r;
int sum = 0;
vector<int> ans;
for(int i = 1;i<=n;i++){
if(sum + 2*(n-i) <= l){
sum = sum + 2*(n-i);
}
else{
int j = i;
for(int j = i;j<=n;j++){
for(int k = j+1;k<=n;k++){
if(ans.size()+2 <= r-sum){
ans.pb(j);
ans.pb(k);
}
else if(ans.size() + 1 <= r-sum){
ans.pb(j);
}
else
break;
}
if(ans.size() > r-sum)
break;
// cout<<ans.size()<<endl;;
}
reverse(all(ans));
while(ans.size() > r-l+1)
ans.pop_back();
reverse(all(ans));
for(int i = 0;i<ans.size();i++)
cout<<ans[i]<<" ";
break;
}
// cout<<endl;
}
if(ans.size() < r-l+1){
cout<<1<<endl;
}
else
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
|
python3
|
# -*- coding: utf-8 -*-
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
def gen_arr(v, n):
res = [0] * n
x = 2
for i in range(n-1):
if i % 2 == 0:
res[i] = v
else:
res[i] = x
x += 1
res[-1] = 1
return res
for _ in range(INT()):
N, l, r = MAP()
l -= 1
tmp = [1, 2, 1]
ans = []
if l < 3:
ans += tmp[l:r]
vcnt = 3
incr = 4
ln = r - l
while len(ans) <= ln:
ans += gen_arr(vcnt, incr)
vcnt += 1
incr += 2
ans = ans[:ln]
else:
cur = 3
vcnt = 3
incr = 4
while cur + incr <= l:
cur += incr
vcnt += 1
incr += 2
ans = gen_arr(vcnt, incr)
ans = ans[l-cur:]
ln = r - l
vcnt += 1
incr += 2
while len(ans) <= ln:
ans += gen_arr(vcnt, incr)
vcnt += 1
incr += 2
ans = ans[:ln]
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
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
inline long long int maxim(long long int a, long long int b) {
if (a > b)
return a;
else
return b;
}
inline long long int minim(long long int a, long long int b) {
if (a < b)
return a;
else
return b;
}
inline bool equals(double a, double b) { return fabs(a - b) < 1e-9; }
long long int gcd(long long int a, long long int b) {
return b == 0 ? a : gcd(b, a % b);
}
long long int arr[1000010][2];
long long int cost[1000010] = {0};
long long int f(long long int x) { return 1 + x * (x - 1); }
long long int binary(long long int low, long long int high,
long long int target) {
while (low + 2 < high) {
long long int mid = (low + high) / 2;
if (f(mid) < target) {
low = mid;
} else {
high = mid - 1;
}
}
for (long long int o = (high), _b = (low); o >= _b; o--) {
if (f(o) < target) {
return o;
}
}
}
int main() {
cin.tie(NULL);
cout.tie(NULL);
ios_base::sync_with_stdio(false);
cout << setprecision(10) << fixed;
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int l, r;
cin >> l >> r;
for (long long int o = (l), _b = (r); o <= _b; o++) {
long long int x = binary(1, 100001, o);
long long int rem = o - (1 + x * (x - 1));
if (rem % 2 == 1) {
cout << x + 1 << " ";
} else {
long long int div = rem / 2;
div++;
if (div == x + 1)
cout << 1 << " ";
else
cout << div << " ";
}
}
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
|
# Legends Always Come Up with Solution
# Author: Manvir Singh
import os
import sys
from io import BytesIO, IOBase
from math import floor,sqrt
def main():
for _ in range(int(input())):
n,l,r=map(int,input().split())
if l== n*(n-1)+1:
print(1)
return
i=1
cnt=0
while l > cnt + (n - i) * 2:
cnt += (n - i) * 2
i += 1
A = []
while r > cnt + len(A):
if i == n:
A.append(1)
else:
A.extend([x for j in range(i + 1, n + 1) for x in [i, j]])
i += 1
result = A[l - cnt - 1:r - cnt]
print(" ".join(str(x) for x in result))
# 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")
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
|
java
|
import java.io.*;
import java.util.ArrayList;
import java.util.Random;
import java.util.StringTokenizer;
public class D {
//Solution by Sathvik Kuthuru
public static void main(String[] args) {
FastReader scan = new FastReader();
PrintWriter out = new PrintWriter(System.out);
Task solver = new Task();
int t = scan.nextInt();
for(int tt = 1; tt <= t; tt++) solver.solve(tt, scan, out);
out.close();
}
static class Task {
public void solve(int testNumber, FastReader scan, PrintWriter out) {
long n = scan.nextInt();
if(n == 2) {
int[] a = {1, 2, 1};
int l = scan.nextInt(), r = scan.nextInt();
for(int i = l - 1; i < r; i++) out.print(a[i] + " ");
out.println();
return;
}
long l = scan.nextLong(), r = scan.nextLong();
long soFar = 0;
long start = -1;
for(int i = 1; i < n; i++) {
long curr = (n - i) * 2;
if(i > 1) curr--;
soFar += curr;
if(soFar >= l) {
start = i;
break;
}
}
if(start == -1) {
long here = 3 + l - soFar - 1;
if(here >= n) here = 1;
int steps = 0;
long need = r - l + 1;
while(steps < need) {
steps++;
out.print(here);
out.print(" ");
here++;
if(here > n) here = 1;
}
}
else {
soFar -= start == 1 ? (n - start) * 2 : (n - start) * 2 - 1;
int step = 0;
while(soFar < l) {
step++;
soFar++;
}
int currStep = step;
step = 0;
long need = r - l + 1;
while(step < need) {
step++;
if(currStep % 2 == 1) out.print(start == 1 ? 1 : 2 + currStep / 2);
else out.print(start == 1 ? 1 + currStep / 2 : n - start + 2);
out.print(" ");
currStep++;
long now = start == 1 ? (n - start) * 2 : (n - start) * 2 - 1;
if(currStep > now) {
start++;
currStep = 1;
if(start >= n) break;
}
}
int here = 3;
while(step < need) {
step++;
out.print(here);
out.print(" ");
here++;
if(here > n) here = 1;
}
}
out.println();
}
}
static void shuffle(int[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
int temp = a[i];
a[i] = a[r];
a[r] = temp;
}
}
static void shuffle(long[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
long temp = a[i];
a[i] = a[r];
a[r] = temp;
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws FileNotFoundException {
br = new BufferedReader(new FileReader(new File(s)));
}
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
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
inline long long int gcd(long long int a, long long int b) {
return (b == 0) ? a : gcd(b, a % b);
}
inline long long int lcm(long long int a, long long int b) {
return (a * b) / gcd(a, b);
}
inline long long int mymod(long long int A, long long int M) {
return ((A % M) + M) % M;
}
template <class type>
type power(type x, long long int n) {
type temp;
long long int y = n;
if (y == 0) return 1;
temp = power(x, y / 2);
return ((y % 2) ? ((y > 0) ? x * temp * temp : (temp * temp) / x)
: temp * temp);
}
template <typename Arg, typename... Args>
void db(Arg&& arg, Args&&... args) {
cout << std::forward<Arg>(arg);
using expander = long long int[];
(void)expander{0, (void(cout << ',' << std::forward<Args>(args)), 0)...};
cout << "\n";
}
void IO_FILE() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
inline void solve() {
long long int n, l, r;
cin >> n >> l >> r;
if (l == n * (n - 1) + 1) {
cout << 1 << " ";
return;
}
long long int st = 1;
long long int cnt = 0;
while (cnt < l) {
cnt += 2 * (n - st);
if (st == n) {
cnt++;
break;
}
st++;
}
st--;
cnt -= 2 * (n - st);
long long int w, f = 1, j = st + 1;
while (cnt < l) {
f ? w = st : w = j++;
f = 1 - f;
cnt++;
}
if (w != st) {
cout << j++ << " ";
l++;
}
f = 1;
while (j <= n and l < r) {
f ? cout << st << " " : cout << j++ << " ";
f = 1 - f;
l++;
}
st++;
while (l <= r) {
f = 1;
j = st + 1;
if (st == n) {
break;
}
while (j <= n and l <= r) {
f ? cout << st << " " : cout << j++ << " ";
f = 1 - f;
l++;
if (l > r) {
break;
}
}
st++;
}
if (r == n * (n - 1) + 1) {
cout << 1 << " ";
}
cout << "\n";
}
int32_t main() {
IO_FILE();
long long 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;
void _print(long long int t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(long long unsigned t) { cerr << t; }
template <class T, class V>
void _print(pair<T, V> p);
template <class T>
void _print(vector<T> v);
template <class T>
void _print(set<T> v);
template <class T, class V>
void _print(map<T, V> v);
template <class T>
void _print(multiset<T> v);
template <class T, class V>
void _print(pair<T, V> p) {
cerr << "{";
_print(p.first);
cerr << ",";
_print(p.second);
cerr << "}";
}
template <class T>
void _print(vector<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T>
void _print(set<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T>
void _print(multiset<T> v) {
cerr << "[ ";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class T, class V>
void _print(map<T, V> v) {
cerr << "[ ";
for (auto i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
template <class a>
void printarr(a arr[], int n) {
for (int i = 0; i < n; i++) cout << arr[i] << ' ';
cout << '\n';
}
template <class c>
void printarr(vector<c> v) {
for (auto i : v) {
cout << i << ' ';
}
cout << '\n';
}
template <class c>
void printarr(set<c> s) {
for (auto i : s) {
cout << i << ' ';
}
cout << '\n';
}
template <class t>
t extended_gcd(t a, t b, t &x, t &y) {
t x1, y1;
if (b == 0) {
x = 1, y = 0;
return a;
}
t g = extended_gcd(b, a % b, x1, y1);
x = y1;
y = x1 - (a / b) * y1;
return g;
}
template <class a>
a powmod(a t1, a t2, a mod) {
a res = 1;
t1 = t1 % mod;
if (t1 == 0) return 0;
while (t2) {
if (t2 & 1) res = (res * t1) % mod;
t1 = (t1 * t1) % mod;
t2 = t2 >> 1;
}
return res;
}
template <class a>
a powmod(a t1, a t2) {
a res = 1;
if (t1 == 0) return 0;
while (t2) {
if (t2 & 1) res = (res * t1);
t1 = (t1 * t1);
t2 = t2 >> 1;
}
return res;
}
const long long int MOD = 1e9 + 7;
const int N = 1e2 + 5;
void run() {
long long int n, l, r;
cin >> n >> l >> r;
if (l == 1) {
cout << 1 << ' ';
l++;
}
if (l == 2 && l <= r) {
cout << 2 << ' ';
l++;
}
if (l <= r) {
while (l <= r) {
long long int p = (l - 2) / 4 + 3;
long long int q = (l - 2) % 4;
if (q == 1)
cout << 1 << ' ';
else if (q == 2)
cout << p << ' ';
else
cout << p - 1 << ' ';
l++;
}
}
cout << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
cout << setprecision(15) << fixed;
int test;
cin >> test;
while (test--) {
run();
}
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << '\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.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
static int MOD = 1000000007;
public static void main(String[] args) throws IOException {
Main m = new Main();
m.solve();
m.close();
}
void close() throws IOException {
pw.flush();
pw.close();
br.close();
}
int ri() throws IOException {
return Integer.parseInt(br.readLine());
}
long rl() throws IOException {
return Long.parseLong(br.readLine());
}
int[] ril(int n) throws IOException {
int[] nums = new int[n];
int c = 0;
for (int i = 0; i < n; i++) {
int sign = 1;
c = br.read();
int x = 0;
if (c == '-') {
sign = -1;
c = br.read();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = br.read();
}
nums[i] = x * sign;
}
while (c != '\n' && c != -1) c = br.read();
return nums;
}
long[] rll(int n) throws IOException {
long[] nums = new long[n];
int c = 0;
for (int i = 0; i < n; i++) {
int sign = 1;
c = br.read();
long x = 0;
if (c == '-') {
sign = -1;
c = br.read();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = br.read();
}
nums[i] = x * sign;
}
while (c != '\n' && c != -1) c = br.read();
return nums;
}
void solve() throws IOException {
int t = ri();
for (int ti = 0; ti < t; ti++) {
int[] nlr = ril(3);
int n = nlr[0];
int l = nlr[1];
int r = nlr[2];
int sector = 1;
int idx = 1;
while (idx + (n - sector) * 2 < l) {
idx = idx + (n - sector) * 2;
sector++;
}
boolean left;
// j represents the value in the pair that isn't the sector value
int j = sector + (l - idx) / 2 + 1;
if ((l - idx) % 2 == 0) {
left = true;
} else {
left = false;
}
idx = l;
while (idx <= r) {
if (idx == n * (n - 1) + 1) {
pw.print("1 ");
break;
}
int val = left ? sector : j;
pw.print(val + " ");
if (j == n && !left) {
sector++;
j = sector + 1;
} else if (!left) {
j++;
}
left = !left;
idx++;
}
pw.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
|
python2
|
import sys
if sys.subversion[0] == "PyPy":
import io, atexit
sys.stdout = io.BytesIO()
atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))
sys.stdin = io.BytesIO(sys.stdin.read())
input = lambda: sys.stdin.readline().rstrip()
def solve(n, a, b, injections = {}):
g = 0
tot = 0
while tot < a and g < n:
g += 1
nxt = tot + 2 * (n - g)
if nxt >= a:
break
else:
tot = nxt
else:
if g == n:
return [1]
injections.get(0, lambda x: 0)(locals())
rem = a - tot
u = (rem + 1) / 2
injections.get(1, lambda x: 0)(locals())
res = []
ptr = a
v = 0
if rem % 2 == 0:
res.append(g + u)
u += 1
ptr += 1
injections.get(2, lambda x: 0)(locals())
while ptr <= b:
if v % 2 == 0:
res.append(g)
else:
res.append(g + u)
u += 1
v ^= 1
ptr += 1
if g + u > n:
g += 1
u = 1
if g == n:
g = 1
return res
def test():
assert solve(2, 1, 3) == [1, 2, 1]
assert solve(99995, 9998900031, 9998900031) == [1]
def inj0(context):
assert (context['g'] == 1)
assert (context['tot'] == 0)
def inj1(context):
assert (context['rem'] == 3)
assert (context['u'] == 2)
assert solve(3, 3, 7, {0: inj0, 1: inj0}) == [1, 3, 2, 3, 1]
assert solve(3, 1, 2) == [1, 2]
assert solve(3, 1, 3) == [1, 2, 1]
test()
T = int(raw_input())
for case_ in xrange(T):
n, a, b = map(int, raw_input().split())
res = solve(n, a, b)
print ' '.join(map(str, res))
|
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 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);
Unstoppable solver = new Unstoppable();
int t=in.nextInt();
while(t-->0)
solver.solve(in, out);
out.close();
}
static class Unstoppable {
public void solve(InputReader in, PrintWriter out) {
int n=in.nextInt();
long l=in.nextLong();
long r=in.nextLong();
long a=(n-1)*2;
long index=((long)Math.sqrt((long)Math.pow(a-1,2)+4*l)-a+1)/(2*(a-1));
long sum=(index/2)*(2*a+(index-1)*2);
long rem=l-sum,count=0,flag=0;
// out.println(a+" "+index+" "+rem);
ArrayList<Integer> array=new ArrayList<Integer>();
for(int i=(int)index+1;i<=n;i++){
if(rem>(n-i)*2){ rem-=(n-i)*2; continue; }
for(int j=i+1;j<=n;j++){
if(rem<=1&&count<r-l+1) { array.add(i); count++; }
rem--;
if(rem<=1&&count<r-l+1) { array.add(j); count++; }
rem--;
} if(count==r-l+1) break;
}
if(count<r-l+1) array.add(1);
for(int i=0;i<array.size();i++) out.print(array.get(i)+" "); out.println("");
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public long nextLong(){
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(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
|
java
|
import java.io.*;
import java.util.*;
public class D
{
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tok;
HashMap<List<Long>, Long> map = new HashMap<>();
public void go() throws IOException
{
StringTokenizer tok = new StringTokenizer(in.readLine());
int zzz = Integer.parseInt(tok.nextToken());
for (int zz = 0; zz < zzz; zz++)
{
ntok();
long n = lpar();
long l = lpar()-1;
long r = lpar()-1;
for (long i = l; i <= r; i++) {
out.print(getIndex2(n, i));
out.print(' ');
}
out.println();
// for (long i = 0; i <= n*(n-1); i++) {
// out.print(getIndex(n, i));
// out.print(' ');
// }
// out.println();
// for (long i = 0; i <= n*(n-1); i++) {
// out.print(getIndex2(n, i));
// out.print(' ');
// }
// out.println();
// printOrder((int)n);
}
out.flush();
in.close();
}
public void printOrder(int n) {
boolean[][] mat = new boolean[n][n];
for (boolean[] arr : mat) {
Arrays.fill(arr, true);
}
for (int i = 0; i < n; i++) {
mat[i][i] = false;
}
int curr = 0;
out.print('1');
for (int i = 0; i < n*(n-1); i++) {
for (int e = 0; e < n; e++) {
if (mat[curr][e]) {
mat[curr][e] = false;
curr = e;
break;
}
}
out.print(' ');
out.print(curr+1);
}
out.println();
}
public long getIndex2(long n, long i) {
List<Long> pair = new ArrayList<>();
pair.add(n);
pair.add(i);
if (map.containsKey(pair)) {
return map.get(pair);
}
long ans;
if (i < (n-1)*2) {
ans = i % 2 == 0 ? 1 : i/2+2;
} else if (i == n*(n-1)-1) {
ans = n;
} else if (i == n*(n-1)) {
ans = 1;
} else {
long l = 1;
long r = n;
while (r > l+1) {
long mid = (r+l)/2;
long minus = 2 * ((n*(n-1)/2) - ((n-mid)*(n-mid-1)/2));
if (minus > i) {
r = mid - 1;
} else {
l = mid;
}
}
long minus = 2 * ((n*(n-1)/2) - ((n-l)*(n-l-1)/2));
ans = getIndex2(n-1, i - minus) + l;
}
map.put(pair, ans);
return ans;
}
public long getIndex(long n, long i) {
List<Long> pair = new ArrayList<>();
pair.add(n);
pair.add(i);
if (map.containsKey(pair)) {
return map.get(pair);
}
long ans;
if (i < (n-1)*2) {
ans = i % 2 == 0 ? 1 : i/2+2;
} else if (i == n*(n-1)-1) {
ans = n;
} else if (i == n*(n-1)) {
ans = 1;
} else {
// long l = 1;
// long r = n;
// while (r > l+1) {
// long mid = (r+l)/2;
// long minus = 2 * ((n*(n-1)/2) - ((n-mid)*(n-mid-1)/2));
// if (minus > i) {
// r = mid - 1;
// } else {
// l = mid;
// }
// }
// long minus = 2 * ((n*(n-1)/2) - ((n-l)*(n-l-1)/2));
// ans = getIndex(n-1, i - minus) + l;
ans = getIndex(n-1, i - (n-1)*2) + 1;
}
map.put(pair, ans);
return ans;
}
public void ntok() throws IOException
{
tok = new StringTokenizer(in.readLine());
}
public int ipar()
{
return Integer.parseInt(tok.nextToken());
}
public int[] iapar(int n)
{
int[] arr = new int[n];
for (int i = 0; i < n; i++)
{
arr[i] = ipar();
}
return arr;
}
public long lpar()
{
return Long.parseLong(tok.nextToken());
}
public long[] lapar(int n)
{
long[] arr = new long[n];
for (int i = 0; i < n; i++)
{
arr[i] = lpar();
}
return arr;
}
public double dpar()
{
return Double.parseDouble(tok.nextToken());
}
public String spar()
{
return tok.nextToken();
}
public static void main(String[] args) throws IOException
{
new D().go();
}
}
|
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) {
if (add < num) {
ye = add;
} else {
num++;
add = 2;
ye = 1;
}
} else {
if (ye != 1) {
add++;
}
ye = num;
}
}
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 i64 = long long;
int t;
i64 n, l, r;
int main() {
scanf("%d", &t);
while (t--) {
scanf("%I64d%I64d%I64d", &n, &l, &r);
for (i64 i = 2; i <= n; ++i) {
if (l <= (i - 1) * (i - 2) + 1)
for (i64 k = 1, q = (i - 1) * (i - 2) + 1; k < i; ++k, q += 2) {
if (q <= r)
printf("%I64d ", k);
else
break;
if (q + 1 <= r)
printf("%I64d ", i);
else
break;
}
}
if (r == n * (n - 1) + 1) printf("1");
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
|
#code
import sys
import math as mt
#input=sys.stdin.buffer.readline
t=int(input())
#tot=0
for __ in range(t):
#n=int(input())
#l=list(map(int,input().split()))
n,l,r=map(int,input().split())
j=1
k=2*(n)-2
mul=1
k=2*n-2
r1=k
l1=1
for i in range(n-2):
if l>=l1 and l<=r1:
#print(111,l1,r1,mul)
break
k-=2
l1=r1+1
r1=l1+k-1
mul+=1
#print(111,l1,r1,mul,k)
nex=mul
ch=l-l1
for i in range(l1,min(r1+1,r+1)):
if i>=l:
if ch%2!=0:
nex+=1
print(nex,end=" ")
else:
print(mul,end=" ")
else:
if ch%2!=0:
nex+=1
ch+=1
if i>r1:
break
i=r1+1
mul+=1
ch=0
nex=mul
k-=1
while i<=min(r,n*(n-1)):
if ch%2==0:
print(mul,end=" ")
else:
nex+=1
print(nex,end=" ")
i+=1
ch+=1
if ch==2*(n-mul):
mul+=1
ch=0
nex=mul
if r==n*(n-1)+1:
print(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
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
long long n, l, r;
long long num;
vector<long long> ans;
bool intersect(long long l1, long long r1, long long l2, long long r2) {
return min(r1, r2) > max(l1, l2);
}
void cal(long long left) {
if (left == n) return;
if (intersect(l, r, num + 1, num + 2 * (n - left))) {
for (long long i = left + 1; i <= n; ++i) {
num++;
if (num >= l && num <= r) ans.push_back(left);
num++;
if (num >= l && num <= r) ans.push_back(i);
}
} else
num += 2 * (n - left);
cal(left + 1);
}
int main(void) {
int t;
cin >> t;
while (t--) {
ans.clear();
num = 0;
cin >> n >> l >> r;
cal(1);
for (auto x : ans) cout << x << " ";
if (r == n * (n - 1) + 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
|
t = int(input())
for i in range(t):
n, l, r = list(map(int, input().split()))
li = [0, 1, 2]
for i in range(3, n+1):
li.append(2*(i - 1) + li[i - 1])
start = n
for i in range(1, n+1):
if(l >= li[i]):
start = i
break
st = ''
base = l - start
temp = l
if( i != 1 ):
pairs = i - 2
pairs -= base//2
flag = base%2
num = i - 1 - base//2
temp = l
if (flag == 0):
st += str(i) + " "
temp += 1
while(temp < r and num >= 2):
st += str(num) + " "
temp += 1
if(temp < r):
st += str(i) + " "
temp += 1
num -= 1
if(temp < r):
st += str(1) + " "
temp += 1
a = i + 1
while(temp < r):
st += str(a) + " "
temp += 1
num = a - 1
while(num >= 2 and temp < r):
st += str(num) + " "
temp += 1
if(temp < r):
st += str(i) + " "
temp += 1
num -= 1
if(temp < r):
st += str(1) + " "
temp += 1
a += 1
else:
st += str(1) + " "
temp += 1
a = 2
while(temp <= r):
st += str(a) + " "
temp += 1
num = a - 1
while(num >= 2 and temp < r):
st += str(num) + " "
temp += 1
if(temp < r):
st += str(i) + " "
temp += 1
num -= 1
if(temp < r):
st += str(1) + " "
temp += 1
a += 1
print(st)
|
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.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;
import java.util.function.*;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.*;
public class D {
private static final FastReader in = new FastReader();
private static final FastWriter out = new FastWriter();
public static void main(String[] args) {
new D().run();
}
private void run() {
var t = in.nextInt();
while (t-- > 0) {
solve();
}
out.flush();
}
int n;
long[] sum;
private void solve() {
n = in.nextInt();
var l = in.nextLong();
var r = in.nextLong();
sum = new long[n + 1];
for (var i = 1; i < n; i++) {
sum[i] = sum[i - 1] + (n - i) * 2;
}
var ans = new long[(int) (r - l + 1)];
for (var i = l; i <= r; i++) {
ans[(int) (i - l)] = euler(i);
}
out.println(ans);
}
long euler(long i) {
var x = Misc.lowerBound(sum, i);
if (x == sum.length) return 1;
var s = sum[x - 1];
var d = i - s;
return d % 2 == 1 ? x : x + d / 2;
}
}
class FastReader {
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private static StringTokenizer in;
public String next() {
while (in == null || !in.hasMoreTokens()) {
try {
in = new StringTokenizer(br.readLine());
} catch (IOException e) {
return null;
}
}
return in.nextToken();
}
public BigDecimal nextBigDecimal() {
return new BigDecimal(next());
}
public BigInteger nextBigInteger() {
return new BigInteger(next());
}
public boolean nextBoolean() {
return Boolean.valueOf(next());
}
public byte nextByte() {
return Byte.valueOf(next());
}
public double nextDouble() {
return Double.valueOf(next());
}
public double[] nextDoubleArray(int length) {
var a = new double[length];
for (var i = 0; i < length; i++) {
a[i] = nextDouble();
}
return a;
}
public int nextInt() {
return Integer.valueOf(next());
}
public int[] nextIntArray(int length) {
var a = new int[length];
for (var i = 0; i < length; i++) {
a[i] = nextInt();
}
return a;
}
public long nextLong() {
return Long.valueOf(next());
}
public long[] nextLongArray(int length) {
var a = new long[length];
for (var i = 0; i < length; i++) {
a[i] = nextLong();
}
return a;
}
}
class FastWriter extends PrintWriter {
public FastWriter() {
super(System.out);
}
public void println(double[] a) {
for (var i = 0; i < a.length; i++) {
print(a[i]);
print(i + 1 < a.length ? ' ' : '\n');
}
}
public void println(int[] a) {
for (var i = 0; i < a.length; i++) {
print(a[i]);
print(i + 1 < a.length ? ' ' : '\n');
}
}
public void println(long[] a) {
for (var i = 0; i < a.length; i++) {
print(a[i]);
print(i + 1 < a.length ? ' ' : '\n');
}
}
public void println(Object... a) {
for (var i = 0; i < a.length; i++) {
print(a[i]);
print(i + 1 < a.length ? ' ' : '\n');
}
}
public <T> void println(List<T> l) {
println(l.toArray());
}
public void debug(String name, Object o) {
String value = Arrays.deepToString(new Object[] { o });
value = value.substring(1, value.length() - 1);
System.err.println(name + " => " + value);
}
}
class Misc {
public static final double EPS = 1e-12;
public static final Comparator<Double> EPS_COMPARATOR = (x, y) -> {
if (x + EPS < y) {
return -1;
} else if (x - EPS > y) {
return 1;
} else {
return 0;
}
};
public static int compare(double x, double y) {
return EPS_COMPARATOR.compare(x, y);
}
/**
* Returns the index of the first element in the range <b>[left, right)</b> which <i>leftShouldAdvance</i> tested to
* be <i>false</i>.
*/
public static int binarySearch(int left, int right, Predicate<Integer> leftShouldAdvance) {
while (left < right) {
var mid = left + (right - left) / 2;
if (leftShouldAdvance.test(mid)) {
left = mid + 1;
} else {
right = mid;
}
}
return left;
}
/**
* Returns the index of the first element in <i>a</i> which >= <i>x</i>.
*/
public static int lowerBound(int[] a, int x) {
return binarySearch(0, a.length, mid -> a[mid] < x);
}
public static int lowerBound(long[] a, long x) {
return binarySearch(0, a.length, mid -> a[mid] < x);
}
/**
* Returns the index of the first element in <i>a</i> which > <i>x</i>.
*/
public static int upperBound(int[] a, int x) {
return binarySearch(0, a.length, mid -> a[mid] <= x);
}
public static int upperBound(long[] a, long x) {
return binarySearch(0, a.length, mid -> a[mid] <= x);
}
/**
* Searches for the maximum value of a unimodal function f(x).
* <p>
* A function f(x) is a <b>unimodal function</b> if for some value m, it is <b>monotonically increasing</b> for x β€
* m and <b>monotonically decreasing</b> for x β₯ m. In that case, the maximum value of f(x) is f(m) and there are no
* other local maxima.
*/
public static int ternarySearch(int left, int right, Function<Integer, Integer> f) {
return binarySearch(left, right, mid -> f.apply(mid) < f.apply(Math.min(mid + 1, right - 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
|
/*
[ ( ^ _ ^ ) ]
*/
// problem: cf/1334/D
import java.io.*;
import java.util.*;
public class d {
int INF = (int)1e9;
long MOD = 1000000007;
long go(long n) {
long l = 0, h = n+1;
while(l<h) {
// show("lh", l, h);
long m = (l+h+1)/2;
long s = m*(m-1);
if(s<n) l = m+1;
else if(s==n) return m;
else h = m-1;
}
return l;
}
void solve(InputReader in, PrintWriter out) throws IOException {
int n = in.nextInt();
long l = in.nextLong();
long r = in.nextLong();
long i = 1;
long p = 0;
// while(true) {
// long x = 2*(i-1);
// p += x;
// if(l<=p) {
// break;
// }
// i++;
// }
i = go(l);
long start = l - (i-1)*(i-2);
long j = i;
// p -= 2*(i-1);
// while(true) {
// long x = 2*(j-1);
// p += x;
// if(r<=p) {
// break;
// }
// j++;
// }
j = go(r);
long end = r - (j-1)*(j-2);
// show("ij", i, start, j, end);
while(true) {
if(start>2*(i-1)) {
start = 1;
i++;
continue;
}
if(i>j) {
break;
}
if(i==j && start>end) {
break;
}
if(start%2==0) {
out.print(i+" ");
} else {
out.print((start+1)/2+" ");
}
start++;
}
// show("--");
out.println();
}
public static void main(String[] args) throws IOException {
InputReader in = new InputReader();
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
while(t-- >0) {
new d().solve(in, out);
}
out.close();
}
public static void show(Object... o) {
System.out.println(Arrays.deepToString(o));
}
static class InputReader {
static BufferedReader br;
static StringTokenizer st;
public InputReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
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()); }
}
}
|
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 find(const long long &n, long long l, long long r) {
long long i = 0;
int v = 1;
while (true) {
if (i + 2 * (n - v) > l) {
break;
}
i += 2 * (n - v);
v++;
if (v == n) {
break;
}
}
int cur = v, next = v + 1;
i++;
bool b = true;
while (i < l) {
b = false;
if (i + 1 == n) {
break;
}
i++;
b = true;
if (next == n) {
cur++;
next = cur + 1;
} else {
next++;
}
if (i + 1 == n) {
break;
}
}
if (cur == n) {
cout << 1 << endl;
return;
}
vector<int> res;
while (i <= r) {
if (b) {
res.push_back(cur);
b = false;
i++;
continue;
}
res.push_back(next);
if (next == n) {
if (cur == n - 1) {
cur = 1;
} else {
cur++;
next = cur + 1;
}
} else {
next++;
}
i++;
b = true;
}
for (auto &x : res) {
cout << x << ' ';
}
cout << endl;
}
int main() {
int t;
cin >> t;
while (t--) {
long long n, l, r;
cin >> n >> l >> r;
find(n, l, r);
}
cin.ignore(2);
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 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:
s.append(k)
else:
if a == n:
k += 1
a = k
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)
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 sys
input = sys.stdin.buffer.readline
for t in range(int(input())):
n,l,r = map(int,input().split())
for i in range(l,min(2*(n-2)+1,r) + 1):
print('1' if i & 1 else i//2 + 1 , end = ' ')
n_set = n
set_idx = 2*(n-2) + 2
while(n_set > 2):
ls = l - set_idx + 1
rs = r - set_idx + 1
set_idx += 2*(n_set - 2)
set_par = n - n_set + 2
if ls < 2 and rs > 1:print(n , end = ' ')
for i in range(max(2,ls) , min(2*(n_set - 2),rs) + 1):
print(set_par + (i-1)//2 if i & 1 else set_par , end = ' ')
n_set -= 1
l -= set_idx
r -= set_idx
if l <= 0 and r>=0:print(n , end = ' ')
if r == 1: print(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
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
long long find(long long n, long long x) {
long long l = 1, r = n, mid;
while (l < r) {
mid = l + r >> 1;
if ((2 * n - mid - 1) * mid < x)
l = mid + 1;
else
r = mid;
}
return mid;
}
signed main() {
long long i, j, k, n, m, l, r, t, last, tmp;
scanf("%lld", &t);
while (t--) {
scanf("%lld%lld%lld", &n, &l, &r);
if (l == n * (n - 1) + 1) {
printf("1 \n");
continue;
}
m = find(n, l);
last = (2 * n - m) * (m - 1);
if (((l - last) & 1) == 0) {
printf("%lld ", m + (l - last) / 2);
l++;
}
for (tmp = m + (l - last) / 2 + 1; l + 2 <= r; l += 2, tmp++) {
printf("%lld %lld ", m, tmp);
if (tmp == n) {
tmp = ++m;
}
}
if (m == n) m = 1;
if (r > l)
printf("%lld %lld ", m, tmp);
else
printf("%lld ", m);
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
|
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;
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.