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
|
java
|
import java.io.*;
import java.util.*;
public class eulercycc {
/*
* @return Index of leftmost number >=key. Inclusive
*/
/*
private static int bsLowerBound(int[] a, int key) {
// Modified Arrays.binarySearch
int low = 0;
int high = a.length - 1;
while (low <= high) {
int mid = (low + high) >>> 1;
int midVal = a[mid];
int cmp = midVal - key;
if (cmp < 0)
low = mid + 1;
else if (cmp > 0)
high = mid - 1;
else if (mid != 0 && a[mid-1]==midVal) { // not lower bound
high = mid-1;
}
else
return mid; // key found
}
return high+1; // key not found, returns number before
}*/
/**
* @return Index of rightmost number <=key. Inclusive
*/
private static long bsLowerBound(int high, long key) {
// Modified Arrays.binarySearch
int low = 0;
while (low <= high) {
int mid = (low + high) >>> 1;
long cmp = mid * (mid + 1L) - key;
if (cmp < 0) {
low = mid + 1;
}
else if (cmp > 0) {
high = mid - 1;
}
else {
return mid; // key found
}
}
return high + 1; // key not found, returns number after
}
public static void main(String[] args) throws Exception {
R in = new R();
int TESTCASES = in.nextInt();
StringBuilder out = new StringBuilder();
for (int TC = 0; TC < TESTCASES; TC++) {
int n = in.nextInt();
long l = in.nextLong();
long r = in.nextLong();
long p = bsLowerBound(n+69, l);
p=Math.max(1, p-3);
for (long i = l; i <= r; i++) {
// n-1 inside the partition
while (i > p*(p+1)) {
p++;
}
if ((i&1)==0) {
// even
out.append(p+1).append(' ');
} else {
out.append( (i+1-p*(p-1)) >> 1 ).append(' ');
}
}
out.setCharAt(out.length()-1, '\n');
}
System.out.print(out);
System.out.flush();
}
//<editor-fold desc="R">
/**
* This class is for fast input. Please ignore.
*/
public static class R {
private BufferedReader br;
/**
* Should be set to null at end of line
*/
private StringTokenizer st;
public R() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public R(String filename) throws IOException {
br = new BufferedReader(new FileReader(filename + ".in"));
}
public R(BufferedReader reader) {
br = reader;
}
public BufferedReader getReader() {
return br;
}
public StringTokenizer getStringTokenizer() {
return st;
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
String s = br.readLine();
if (s == null) return null;
st = new StringTokenizer(s);
}
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
/**
* Note:
* CAN MODIFY the BufferedReader's location and the string tokenizer!!!
* Recommended to only use with next().
*/
public boolean lineHasNext() throws IOException {
if (st == null) {
String s = br.readLine();
if (s == null) return false;
st = new StringTokenizer(s);
}
return st.hasMoreTokens();
}
/**
* Note:
* CAN MODIFY the BufferedReader's location and the string tokenizer!!!
* Recommended to only use with next().
*/
public boolean hasNext() throws IOException {
while (st == null || !st.hasMoreTokens()) {
String s = br.readLine();
if (s == null) return false;
st = new StringTokenizer(s);
}
return true;
}
/**
* Skips a line. Sets st to null if has tokens left, and otherwise
* reads a line.
*/
public void skipLine() throws IOException {
if (st == null || !st.hasMoreTokens()) {
br.readLine(); // Otherwise, would do nothing.
}
st = null;
}
/**
* This will set st to null, and this ignores current line
*/
public String[] nextLine() throws IOException {
String s = br.readLine();
if (s == null) return null;
st = new StringTokenizer(s);
ArrayList<String> result = new ArrayList<>();
while (st.hasMoreTokens()) {
result.add(st.nextToken());
}
st = null;
return result.toArray(new String[0]);
}
/**
* sets st to null!
*/
public String[] nextTower(int lines) throws IOException {
String[] tower = new String[lines];
st = null;
for (int i = 0; i < lines; i++) {
tower[i] = br.readLine();
}
return tower;
}
public int[] nextIntLine() throws IOException {
return intArr(nextLine());
}
public long[] nextLongLine() throws IOException {
return longArr(nextLine());
}
public int[] nextIntTower(int lines) throws IOException {
return intArr(nextTower(lines));
}
public long[] nextLongTower(int lines) throws IOException {
return longArr(nextTower(lines));
}
public int[] intArr(String[] strings) throws IOException {
int[] ints = new int[strings.length];
int i = 0;
for (String s : strings) {
ints[i] = Integer.parseInt(s);
i++;
}
return ints;
}
public long[] longArr(String[] strings) throws IOException {
long[] longs = new long[strings.length];
int i = 0;
for (String s : strings) {
longs[i] = Long.parseLong(s);
i++;
}
return longs;
}
public double[] doubleArr(String[] strings) {
double[] doubles = new double[strings.length];
int i = 0;
for (String s : strings) {
doubles[i] = Double.parseDouble(s);
i++;
}
return doubles;
}
/**
* This will set st to null
*/
public char[] nextCharArray() throws IOException {
st = null;
String s = br.readLine();
return s == null ? null : s.toCharArray();
}
/**
* This will set st to null
* Boolean at pos i true if char at pos i == c
*/
public boolean[] nextBoolArray(char c) throws IOException {
char[] chars = nextCharArray();
if (chars == null) return null;
boolean[] booleans = new boolean[chars.length];
for (int i = 0; i < chars.length; i++) {
booleans[i] = chars[i] == c;
}
return booleans;
}
public int[][] next2Dint(int lines) throws IOException {
int[][] result = new int[lines][];
for (int i = 0; i < lines; i++) {
result[i] = nextIntLine();
}
return result;
}
public long[][] next2Dlong(int lines) throws IOException {
long[][] result = new long[lines][];
for (int i = 0; i < lines; i++) {
result[i] = nextLongLine();
}
return result;
}
public char[][] next2Dchar(int lines) throws IOException {
char[][] result = new char[lines][];
for (int i = 0; i < lines; i++) {
result[i] = nextCharArray();
}
return result;
}
public boolean[][] next2Dbool(int lines, char c) throws IOException {
boolean[][] result = new boolean[lines][];
for (int i = 0; i < lines; i++) {
result[i] = nextBoolArray(c);
}
return result;
}
}
//</editor-fold>
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
java
|
import java.util.*;
import java.io.*;
public class Main {
static FastReader in=new FastReader();
static StringBuilder Sd=new StringBuilder();
static List<Integer>Gr[];
static long Mod=998244353;
static Map<Integer,Integer>map=new HashMap<>();
public static void main(String [] args) {
//Dir by MohammedElkady
int t=in.nextInt();
while(t-->0) {
long n=in.nextLong(),l=in.nextLong(),r=in.nextLong();
long ans=1,res=0;
l-=1;r-=1;
int lol=0;
if(r>=n*(n-1)) {lol=1;r--;
}
for(long i=1;i<=n;i++) {
ans=i;
if(res+((n-i)*2)<l)
{
res+=(n-i)*2;
}else break;
}
long vov=ans+1;
if(!(lol>0&&l>r))
for(;l<=r;) {
if(res>l) {
Sout(vov-1+" ");
l++;
}
if(res==l) {
if(vov>n) {
ans+=1;vov=ans+1;
}
Sout(ans+" ");
if(r+1-l>0) {Sout(vov+" ");}
vov++;
res+=2;
l+=2;
}
else {
vov++;
res+=2;
}
}
if(lol>0) {Soutln("1 ");}
else Soutln("");
}
Sclose();
}
static long power(long x, long y, long p)
{
// Initialize result
long res = 1;
// Update x if it is more than or
// equal to p
x = x % p;
while (y > 0)
{
// If y is odd, multiply x
// with result
if (y % 2 == 1)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
// Returns n^(-1) mod p
static long modInverse(long n, long p)
{
return power(n, p-2, p);
}
// Returns nCr % p using Fermat's
// little theorem.
static long nCrModPFermat(int n, int r,
long p)
{
// Base case
if (r == 0)
return 1;
// Fill factorial array so that we
// can find all factorial of r, n
// and n-r
long[] fac = new long[n+1];
fac[0] = 1;
for (int i = 1 ;i <= n; i++)
fac[i] = fac[i-1] * i % p;
return (fac[n]* modInverse(fac[r], p)
% p * modInverse(fac[n-r], p)
% p) % p;
}
static long fac(int n , int m,int l) {
long res=1;
for(int i=l,u=1;i<=n||u<=m;i++,u++) {
if(i<=n) {res*=i;}
if(u<=m) {res/=u;}
while(res>Mod)
res-=Mod;
}
return res;
}
static long posation(int n) {
long res=1;
for(int i=0;i<n-3;i++) {res*=2L;
while(res>Mod)
res-=Mod;
while(res<=0)res+=Mod;}
return res;
}
static long gcd(long g,long x){
if(x<1)return g;
else return gcd(x,g%x);
}
//array fill
static long[]filllong(int n){long a[]=new long[n];for(int i=0;i<n;i++)a[i]=in.nextLong();return a;}
static int[]fillint(int n){int a[]=new int[n];for(int i=0;i<n;i++)a[i]=in.nextInt();return a;}
//OutPut Line
static void Sout(String S) {Sd.append(S);}
static void Soutln(String S) {Sd.append(S+"\n");}
static void Soutf(String S) {Sd.insert(0, S);}
static void Sclose() {System.out.println(Sd);}
static void Sclean() {Sd=new StringBuilder();}
}
class node implements Comparable<node>{
int x,t;
node(int x,int p){
this.x=x;
this.t=p;
}
@Override
public int compareTo(node o) {
return (t-o.t);
}
}
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
class Sorting{
public static node[] bucketSort(node[] array, int bucketCount) {
if (bucketCount <= 0) throw new IllegalArgumentException("Invalid bucket count");
if (array.length <= 1) return array; //trivially sorted
int high = array[0].t;
int low = array[0].t;
for (int i = 1; i < array.length; i++) { //find the range of input elements
if (array[i].t > high) high = array[i].t;
if (array[i].t < low) low = array[i].t;
}
double interval = ((double)(high - low + 1))/bucketCount; //range of one bucket
ArrayList<node> buckets[] = new ArrayList[bucketCount];
for (int i = 0; i < bucketCount; i++) { //initialize buckets
buckets[i] = new ArrayList();
}
for (int i = 0; i < array.length; i++) { //partition the input array
buckets[(int)((array[i].t - low)/interval)].add(array[i]);
}
int pointer = 0;
for (int i = 0; i < buckets.length; i++) {
Collections.sort(buckets[i]); //mergeSort
for (int j = 0; j < buckets[i].size(); j++) { //merge the buckets
array[pointer] = buckets[i].get(j);
pointer++;
}
}
return array;
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
python3
|
# problem 2
def calc(N, index):
# find the number when given (N,index)
if index == 1:
return 1
cnt = 1
while 1+cnt*(cnt-1) < index:
cnt += 1
# maximum value := cnt
Left = index-(cnt-1)*(cnt-2)
if Left % 2 == 0:
return cnt
else:
if cnt != Left//2+1:
return Left//2+1
else:
return 1
def solve():
n, l, r = map(int, input().split())
A = []
for i in range(l, r+1):
A.append(calc(n, i))
print(*A)
def main():
T = int(input())
for i in range(T):
solve()
if __name__ == "__main__":
main()
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long i, j, k, n, t, m, l, r;
cin >> t;
while (t--) {
cin >> n >> l >> r;
r = r - l + 1;
if ((l - 1) == n * (n - 1)) {
cout << 1 << endl;
} else {
for (i = 1; i <= n - 1; i++) {
if ((n - i) * 2 < l)
l = l - (n - i) * 2;
else {
long long x = (l - 1) / 2;
long long p = i + x;
x = x * 2;
if (l - x == 1) {
while (r--) {
cout << i << " ";
p++;
if (r > 0) {
cout << p << " ";
r--;
}
if (p == n) {
i++;
p = i;
}
if (i >= n && r > 0) {
cout << 1;
break;
}
}
} else {
while (r--) {
p++;
cout << p << " ";
if (r > 0) {
cout << i << " ";
r--;
}
if (p == n) {
i++;
p = i;
}
if (i >= n && r > 0) {
cout << 1 << " ";
break;
}
}
}
cout << endl;
break;
}
}
}
}
}
|
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 Ana {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
// Thread.sleep(2000);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();long l=sc.nextLong(); long r=sc.nextLong();
long i=1, count=2;
while(i<=l) {
i+=count;
count+=2;
}
i-=count-2;
count/=2;
// System.out.println(i+" "+ count);
StringBuilder sb= new StringBuilder();
boolean first=true;
while(i<=r) {
long j;
if(first) {
j=((l-i)/2);
i+=2*j;
j++;
first=false;
}
else
j=1;
for(;j<count;j++) {
if(i>=l && i<=r) {
sb.append(j+" "); i++;
}
if(i>=l && i<=r) {
sb.append(count+" "); i++;
}
else
i++;
}
count++;
}
out.println(sb);
}
out.close();
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
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 boolean ready() throws IOException {
return br.ready();
}
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
python3
|
import bisect
dp = [None for i in range(10**5+2)]
prev = 2
dp[0] = 1
dp[1] = 2
for i in range(2,10**5+1):
curr = prev+2*(i-1)
dp[i] = curr
prev = curr
def solve(curr, st, turn, l, r, res):
# print("in solve", curr, st, turn, res)
if curr==1 and l<=r:
res.append(1)
res.append(2)
res.append(1)
l+=3
curr=3
while l<=r:
# print(l,r,res)
if turn:
res.append(curr)
l+=1
turn=False
elif turn is False and st<curr:
res.append(st)
l+=1
st+=1
turn=True
else:
res.append(1)
l+=1
turn=True
curr+=1
st=2
return res
t = int(input())
for _ in range(t):
n, l, r = [int(x) for x in input().strip().split()]
res= []
ind = bisect.bisect_right(dp,l)
if dp[ind-1]==l:
# print("in 1")
curr = ind
st = 2
turn=True
res = solve(curr,st,turn,l,r,res)
else:
# print("in 2")
curr = ind
offset = l-dp[ind-1]
if offset%2==0:
turn = True
else:
turn = False
st = 2+offset//2
res = solve(curr, st, turn, l, r, res)
# res_string = "".join(str(r) for r in res)
print(*res[:r-l+1])
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
void comp() {
long long i, j, k, l, m, n, r;
cin >> n >> l >> r;
vector<long long> v1(n + 1);
v1[0] = 0;
v1[1] = 2 * (n - 1);
for (i = 2; i < n; i++) {
v1[i] = v1[i - 1] + 2 * (n - i);
}
long long low = 0;
long long high = n - 1;
long long mid, temp;
vector<long long> ans;
for (i = l; i < r + 1; i++) {
low = 1;
high = n - 1;
temp = 1;
while (low <= high) {
mid = (low + high) / 2;
if (v1[mid] >= i) {
temp = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
if (i % 2)
ans.push_back(temp);
else {
j = i;
j -= v1[mid - 1];
j /= 2;
ans.push_back(temp + j);
}
}
for (i = 0; i < ans.size(); i++) cout << ans[i] << " ";
cout << endl;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
long long i = 0, t;
cin >> t;
while (t--) {
comp();
}
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
|
# HEY STALKER
sm = [i*2 for i in range(1, 200005)]
for _ in range(int(input())):
m, l, r = map(int, input().split())
z = 0
n = 0
sd = 0
while z < l:
n += 1
sd += 2
z += sd
tot = (r-l+1)
nn = n-1
sx = 0
for t in range(nn):
sx += sm[t]
sx += 1
nikal = l-sx
ans = []
for t in range(1, n+1):
ans.append(t)
ans.append(n+1)
n += 1
ans.reverse()
while nikal:
nikal -= 1
ans.pop()
ans.reverse()
while len(ans) < tot:
for t in range(1, n+1):
ans.append(t)
ans.append(n+1)
n += 1
print(*ans[:tot])
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int q;
cin >> q;
while (q--) {
__int64 n, l, r;
cin >> n >> l >> r;
__int64 b = 0, f = 1, s = 0;
for (__int64 k = 2 * (n - 1); b + k < l && k >= 0; k -= 2) {
b += k; ++f;
}
s = f + (l - b) / 2 + 1;
b += l - b;
if (l % 2 == 0) {
cout << s << ' ';
++b;
}
for ( ; b <= r && f < n; b += 2) {
cout << f << ' ' << s << ' ';
++s;
if (s > n) {
++f;
s = f + 1;
}
}
if (r == n * (n - 1) + 1) {
cout << 1;
}
cout << '\n';
}
return 0;
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
python3
|
#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*k:
mul+=1
ch=0
k-=1
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;
void solve(long long cur, long long sum) {
if (cur == n) {
if (sum < r) printf("1 ");
return;
}
bool b = 0;
for (long long i = cur + 1; i <= n; i++) {
if (sum > r) {
b = 1;
break;
}
sum++;
if (sum >= l && sum <= r) {
printf("%lld ", cur);
}
sum++;
if (sum >= l && sum <= r) {
printf("%lld ", i);
}
}
if (b) return;
solve(cur + 1, sum);
return;
}
int main() {
int t;
cin >> t;
long long sum, cur;
while (t--) {
sum = 0;
cur = 1;
scanf("%lld%lld%lld", &n, &l, &r);
if (r == (n) * (n - 1) + 1 && l == r) {
cout << 1 << endl;
continue;
}
if (r == (n) * (n - 1) + 1 && l == r - 1) {
cout << n << ' ' << 1 << endl;
continue;
}
for (long long i = 1; i <= n + 1; i++) {
if (sum > l) {
sum -= (n - i + 1) * 2;
break;
}
sum += (n - i) * 2;
cur = i;
}
solve(cur, sum);
cout << endl;
}
return 0;
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
void upgrade() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
}
int main() {
upgrade();
int tc;
cin >> tc;
while (tc--) {
int n, l, r;
cin >> n >> l >> r;
int add = 2 * n - 2, cnt = 0, h = 1;
while (add != 0 && cnt + add <= l) {
cnt += add;
add -= 2;
h++;
}
if (add == 0) {
cout << 1 << '\n';
continue;
}
int diff = l - cnt;
bool f = (diff % 2) == 1;
int st = (diff - 1) / 2 + h + 1;
for (int i = 0; i < r - l + 1; i++) {
if (f) {
cout << h << ' ';
} else {
cout << st << ' ';
st++;
if (st == n + 1) {
h++;
st = h + 1;
if (h == n && i != r - l) {
cout << 1;
break;
}
}
}
f = !f;
}
cout << '\n';
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
python3
|
from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def lsi():
x=list(stdin.readline())
x.pop()
return x
def si(): return stdin.readline()
res=['YES', 'NO']
############# CODE STARTS HERE #############
for _ in range(ii()):
n, l, r=mi()
x, p=1, 0
while x<=l:
p+=2
x+=p
x-=p
p//=2
p+=1
#print(x, p)
dl=l-x
a=[]
z=dl//2+1
if not dl:
a.append(1)
l+=1
elif not dl%2:
a.append(z)
l+=1
while l<=r:
a.append(p)
l+=1
if l<=r:
z+=1
if z==p:
z=1
p+=1
a.append(z)
l+=1
print(*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
|
java
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
public class Main
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args)
{
FastReader sc=new FastReader();
StringBuilder sb1=new StringBuilder();
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
long l=sc.nextLong();
long r=sc.nextLong();
l--;
r--;
//StringBuilder sb1=new StringBuilder();
l-=2;
r-=2;
long a[]={1,0,1};
while(l<=r)
{
if(l<0)
{
if(l==-2)
sb1.append(1);
else if(l==-1)
sb1.append(2);
}
else if(l%4==0)
{
sb1.append(1);
}
else
{
sb1.append(((l/4)+2+a[(int)(l%4)-1]));
}
sb1.append(" ");
l++;
}
sb1.append("\n");
}
System.out.print(sb1.toString());
}
}
|
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 pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
void printChar(long long x, long long l, long long r, long long& curpos) {
if (l <= curpos && curpos <= r) std::cout << x << " ";
++curpos;
}
long long print(long long s, long long e, long long l, long long r,
long long curpos) {
if (curpos > r) return curpos;
if (s == e) {
printChar(s, l, r, curpos);
return curpos;
}
if (s == e - 1) {
printChar(s, l, r, curpos);
printChar(e, l, r, curpos);
printChar(s, l, r, curpos);
return curpos;
}
long long ns = s + 1;
long long ne = e - 1;
long long totalNextCycle = (e - (s + 1) + 1) * 2;
if (curpos + totalNextCycle <= l) {
curpos += totalNextCycle;
} else {
for (long long i = s + 1; i <= e; i++) {
printChar(s, l, r, curpos);
printChar(i, l, r, curpos);
}
}
curpos = print(ns, ne, l, r, curpos);
totalNextCycle = (ne - (ns + 1) + 1) * 2;
if (curpos > r || curpos + totalNextCycle <= l) {
curpos += totalNextCycle;
} else {
for (long long i = ns + 1; i <= ne; i++) {
printChar(e, l, r, curpos);
printChar(i, l, r, curpos);
}
}
printChar(e, l, r, curpos);
printChar(s, l, r, curpos);
return curpos;
}
int main() {
std::ios::sync_with_stdio(false);
int t;
std::cin >> t;
while (t--) {
long long n, l, r;
std::cin >> n >> l >> r;
print(1, n, l, r, 1);
std::cout << std::endl;
}
return 0;
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
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 && i <= 4 * n - 5) {
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
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
vector<int> ans;
int main() {
int T;
scanf("%d", &T);
while (T--) {
int n;
long long l, r;
ans.clear();
scanf("%d%I64d%I64d", &n, &l, &r);
bool flag = 0;
long long last = 0, now = 0;
for (int i = 1; i <= n - 1; i++) {
int pos = 0;
now = last + 2 * (n - i - 1) + 2;
if (flag == 0) {
if (l > last && r <= now) {
int del1 = l - last, del2 = r - last;
for (int j = 1; j <= 2 * (n - i - 1) + 2; j++) {
if (j % 2 == 1)
pos = i;
else
pos = j / 2 + i;
if (j >= del1 && j <= del2) ans.push_back(pos);
}
} else if (l <= now && l > last) {
flag = 1;
int del = l - last;
for (int j = 1; j <= 2 * (n - i - 1) + 2; j++) {
if (j % 2 == 1) {
pos = i;
} else {
pos = j / 2 + 1;
}
if (j >= del) ans.push_back(pos);
}
}
} else if (flag == 1) {
if (r > last && r <= now) {
flag = 0;
int del = r - last;
for (int j = 1; j <= 2 * (n - i - 1) + 2; j++) {
if (j % 2 == 1) {
pos = i;
} else {
pos = j / 2 + i;
}
if (j <= del) ans.push_back(pos);
}
} else {
for (int j = 1; j <= 2 * (n - i - 1) + 2; j++) {
if (j % 2 == 1) {
pos = i;
} else {
pos = j / 2 + i;
}
ans.push_back(pos);
}
}
}
last = now;
}
for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]);
if (r == 1ll * n * (n - 1) + 1) printf("%d ", 1);
puts("");
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
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;
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;
}
if (l > r) {
cout << "\n";
continue;
}
if (l == r) {
cout << start << "\n";
continue;
}
if (l + 1 == r) {
cout << start << " " << star << "\n";
continue;
}
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
|
java
|
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Itwazonce
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
scan in = new scan(inputStream);
PrintWriter out = new PrintWriter(outputStream);
minimumeulercycle solver = new minimumeulercycle();
solver.solve(1, in, out);
out.close();
}
static class minimumeulercycle {
public void solve(int testNumber, scan in, PrintWriter out) {
int t = in.scanInt();
while (t-- > 0) {
long n = in.scanLong();
long l = in.scanLong();
long r = in.scanLong();
int len = (int) (r - l + 1);
long ans[] = new long[len];
int k = 0;
long total = 0;
boolean check = true;
for (long i = 1; k < len && i <= n; i++) {
if (check) total += 2 * (i * n - (i * (i + 1)) / 2);
if (total < l) {
continue;
} else if (check) {
total -= 2 * (i * n - (i * (i + 1)) / 2);
check = false;
}
for (long j = i + 1; k < ans.length && j <= n; j++) {
// out.println(i+" "+total+" "+i+" "+j);
total++;
if (l <= total && total <= r) {
ans[k++] = i;
}
total++;
if (l <= total && total <= r) {
ans[k++] = j;
}
}
}
for (int i = 0; i < ans.length; i++) {
if (ans[i] == 0)
ans[i] = 1;
out.print(ans[i] + " ");
}
out.println();
}
}
}
static class scan {
private byte[] buf = new byte[4 * 1024];
private int index;
private BufferedInputStream in;
private int total;
public scan(InputStream inputStream) {
in = new BufferedInputStream(inputStream);
}
private int scan() {
if (index >= total) {
index = 0;
try {
total = in.read(buf);
} catch (Exception e) {
e.printStackTrace();
}
if (total <= 0)
return -1;
}
return buf[index++];
}
public int scanInt() {
int integer = 0;
int n = scan();
while (isWhiteSpace(n))
n = scan();
int neg = 1;
if (n == '-') {
neg = -1;
n = scan();
}
while (!isWhiteSpace(n)) {
if (n >= '0' && n <= '9') {
integer *= 10;
integer += n - '0';
n = scan();
}
// else throw new InputMismatchException();
}
return neg * integer;
}
public long scanLong() {
long lon = 0;
int n = scan();
while (isWhiteSpace(n))
n = scan();
int neg = 1;
if (n == '-') {
neg = -1;
n = scan();
}
while (!isWhiteSpace(n) && n != '.') {
if (n >= '0' && n <= '9') {
lon *= 10;
lon += n - '0';
n = scan();
}
// else throw new InputMismatchException();
}
return lon * neg;
}
private boolean isWhiteSpace(int n) {
if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
return true;
return false;
}
}
}
|
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 implements Runnable{
FastScanner sc;
PrintWriter pw;
final class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
e.printStackTrace();
}
}
public long nlo() {
return Long.parseLong(next());
}
public String next() {
if (st.hasMoreTokens()) return st.nextToken();
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
e.printStackTrace();
}
return st.nextToken();
}
public int ni() {
return Integer.parseInt(next());
}
public String nli() {
String line = "";
if (st.hasMoreTokens()) line = st.nextToken();
else try {
return br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
while (st.hasMoreTokens()) line += " " + st.nextToken();
return line;
}
public double nd() {
return Double.parseDouble(next());
}
}
public static void main(String[] args)
{
new Thread(null,new Solution(),"codeforces",1<<25).start();
}
public void run()
{
sc=new FastScanner();
pw=new PrintWriter(System.out);
solve();
pw.flush();
pw.close();
}
public long gcd(long a,long b)
{
return b==0L?a:gcd(b,a%b);
}
public long ppow(long a,long b,long mod)
{
if(b==0L)
return 1L;
long tmp=1;
while(b>1L)
{
if((b&1L)==1)
tmp*=a;
a*=a;
a%=mod;
tmp%=mod;
b>>=1;
}
return (tmp*a)%mod;
}
public int gcd(int x,int y)
{
return y==0?x:gcd(y,x%y);
}
//////////////////////////////////
///////////// LOGIC ///////////
////////////////////////////////
public void solve(){
int t=sc.ni();
while(t-->0)
{
long n=sc.nlo();
long l=sc.nlo();
long r=sc.nlo();
long tt=r-l+1L;
StringBuilder str=new StringBuilder();
for(long i=1;i<n;i++)
{
l-=(n-i)*2L;
if(l>0)
continue;
l+=(n-i)*2L;
if(l%2==0){
long j=l/2+i;
str.append(j+" ");
tt--;}
tt=dop(i,l/2+1,n,tt,str);
break;
}
if(tt>0)
str.append(1);
pw.println(str);
}
}
public long dop(long i,long p,long n,long t,StringBuilder str)
{
//pw.println(i+" "+p+" "+t);
for(;i<n;i++)
{
for(long j=i+p;j<=n;j++)
{
if(t>=2)
{str.append(i+" "+j+" ");t-=2L;}
else
{
str.append(i+" ");
t-=1;
}
if(t==0)
break;
}
p=1;
if(t==0)
break;
}
if(t==1)
{t--; str.append(1);}
return t;
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
cpp
|
#include<iostream>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<cstring>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<cstdio>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9 * 2;
const ll LNF = 1e18;
const ll MOD = 998244353;
const int MAXN = 200'005;
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T;
cin >> T;
while (T--) {
ll n, l, r;
cin >> n >> l >> r;
ll cou = r - l;
ll s = 1;
ll f = 0;
while (1) {
if (s + f > l) {
break;
}
else
s += f;
f+=2;
}
//cout << "f " << f << '\n';
f /= 2;
//cout << "s , f : " << s << ' ' << f << "\n";
ll a = f+1;
ll b = (l - s+1)/2 ;
//cout <<"a , b : "<< a << ' ' << b << "\n";
for (ll i = l; i <=r; i++) {
if (i == 1) {
cout << 1 << ' ';
a = 2;
b = 0;
continue;
}
if (i % 2 == 0) {
cout << a << ' ';
if (i != l)
b++;
}
else {
cout << b % (a - 1) + 1 << ' ';
if (b == a - 1) {
b = 0;
a++;
}
}
}
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) / 2 + ptr;
for (long long i = l; i <= r; i++) {
if (i > n * (n - 1)) {
vec.push_back(1);
break;
}
if ((i - l) % 2 == 0) vec.push_back(ptr);
if ((i - l) % 2) vec.push_back(gir++);
if (gir > n) ptr++, gir = ptr + 1;
}
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.util.*;
import java.io.*;
public class D
{
static IO io = new IO();
public static void main(String[] args)
{
int T = io.getInt();
while(T-->0){
long n = io.getInt();
long l = io.getLong()-1;
long r = io.getLong()-1;
long pos = 0, posi = 0;
long[] len = new long[(int)n];
for(long i=0; i<n; i++){ //len is the length os seq up to init with i
len[(int)i] = 2*n*i - i*(i+1);
if(len[(int)i] < l){
pos = len[(int)i];
posi = i;
}
}
System.out.println(pos+" "+posi);
long fi = posi+1, se = posi+2, par = 0;
long out = 0;
while(pos <= r){
if(par%2 == 0){
out = fi;
}
else{
out = se;
se++;
if(se == n+1){
fi++;
se = fi+1;
}
if(fi == n){
fi = 1;
}
}
if(pos >= l){
io.print(out+" ");
}
par = (par+1)%2;
pos++;
}
io.println();
}
io.close();
}
}
class IO extends PrintWriter {
public IO() {
super(new BufferedOutputStream(System.out));
r = new BufferedReader(new InputStreamReader(System.in));
}
public IO(String fileName) {
super(new BufferedOutputStream(System.out));
try{
r = new BufferedReader(new FileReader(fileName));
} catch (FileNotFoundException e) {
this.println("File Not Found");
}
}
public boolean hasMoreTokens() {
return peekToken() != null;
}
public int getInt() {
return Integer.parseInt(nextToken());
}
public double getDouble() {
return Double.parseDouble(nextToken());
}
public long getLong() {
return Long.parseLong(nextToken());
}
public String getWord() {
return nextToken();
}
public String getLine(){
try{
st = null;
return r.readLine();
}
catch(IOException ex){}
return null;
}
private BufferedReader r;
private String line;
private StringTokenizer st;
private String token;
private String peekToken() {
if (token == null)
try {
while (st == null || !st.hasMoreTokens()) {
line = r.readLine();
if (line == null) return null;
st = new StringTokenizer(line);
}
token = st.nextToken();
} catch (IOException e) { }
return token;
}
private String nextToken() {
String ans = peekToken();
token = null;
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
|
python3
|
from sys import stdin, gettrace
from math import sqrt
if not gettrace():
def input():
return next(stdin)[:-1]
# def input():
# return stdin.buffer.readline()
def main():
def solve():
n,l,r = map(int, input().split())
lv = int((2*n+1 - sqrt((2*n-1)**2 -4*(l-1)))/2)
lvs = -2*n+2*n*lv-lv*lv+lv
lrd = l - lvs - 1
res = []
i = lv
j = lv+lrd//2 + 1
for _ in range(l-1, r, 2):
res += [i,j]
if j < n:
j += 1
else:
i +=1
j = i+1
if r == n*(n-1)+1:
res[r-l] = 1
print(' '.join(map(str, res[:r-l+1])))
q = int(input())
for _ in range(q):
solve()
if __name__ == "__main__":
main()
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
python3
|
t = int(input())
for i in range(t):
n, l, r = map(int, input().split())
if l == n * (n - 1) + 1:
print(1)
else:
x = 1
summa = x * 2 * n
rasn = x * (x + 1)
while summa - rasn < l:
summa += 2 * n
rasn = (rasn // x) * (x + 2)
x += 1
x -= 1
first = x + 1
second = (l - x + 1) // 2 + first
ind = l
while ind + 1 <= r:
print(first, second, end=" ")
if second == n:
first += 1
second = first + 1
else:
second += 1
ind += 2
if ind == r:
if r == n * (n - 1) + 1:
print(1)
elif second == n:
print(first + 1)
else:
print(first)
else:
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;
const double PI = acos(-1.0);
const int M = 1e5 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while (T--) {
long long n, l, r, f = 0;
cin >> n >> l >> r;
l--;
if (r == n * (n - 1) + 1) r--, f = 1;
long long nl = (n - 1) * 2, nr = (n - 1) * 2;
while (l >= nl && nl) l -= nl, nl -= 2;
while (r >= nr && nr) r -= nr, nr -= 2;
while (nl >= nr && nl) {
long long tp = n - (nl / 2);
long long nm = 0;
for (int i = tp + 1; i <= n; i++) {
if (nl == nr && nm >= r) break;
if (l >= 2)
l -= 2, nm += 2;
else if (l) {
l--;
cout << i << " ";
nm++;
} else {
if (nl == nr && r - nm < 2)
cout << tp << " ", nm++;
else
cout << tp << " " << i << " ", nm += 2;
}
}
nl -= 2;
}
if (f) 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
|
java
|
import java.io.BufferedInputStream;
import java.util.Map;
import java.util.Scanner;
public class Main {
private static Scanner sc = new Scanner(new BufferedInputStream(System.in));
public static void main(String[] args) {
work();
}
private static void work() {
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
long n = sc.nextLong();
long l = sc.nextLong(), r = sc.nextLong();
printResult(n, l, r);
}
}
private static void printResult(long n, long l, long r) {
StringBuffer stringBuffer = new StringBuffer();
long k = (long) ((double) (2 * n - 1) - Math.sqrt((2 * n - 1) * (2 * n - 1) - 4 * l)) / 2;
int cnt = 0;
long p = l, bias;
while (cnt < r - l + 1) {
if (p == n * (n - 1) + 1) {
stringBuffer.append(1).append(' ');
break;
}
bias = p - (2 * n - k - 1) * k;
if (bias % 2 == 1)
stringBuffer.append(k + 1).append(' ');
else
stringBuffer.append(bias / 2 + k + 1).append(' ');
p++;
cnt++;
if (p > (2 * n - k - 2) * (k + 1))
k++;
}
System.out.println(stringBuffer);
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
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;
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
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7FFFFFFF;
const long long mod = (0 ? 1000000007 : 998244353);
const double eps = 1e-7;
void work() {
long long n, l, r;
cin >> n >> l >> r;
long long sum = 1;
long long nw = 2;
long long cnt = 1;
while (sum + nw <= l) {
cnt++;
sum += nw;
nw += 2;
}
vector<long long> ans;
long long fl = 0;
long long res = l - sum;
long long pos = l - 1;
if (res == 0) {
ans.push_back(1);
pos++;
cnt++;
fl = 0;
} else if (res & 1)
fl = 1;
long long now = 2 + res / 2;
while (pos < r) {
pos++;
if (fl == 0) {
ans.push_back(cnt);
fl = 1;
continue;
}
if (now == cnt) {
cnt++;
ans.push_back(1);
now = 2;
fl = 0;
continue;
}
fl = 0;
ans.push_back(now);
now++;
continue;
}
for (long long i = 0; i < ans.size(); i++) {
cout << ans[i] << ' ';
}
cout << endl;
}
signed main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
long long t = 1;
cin >> t;
while (t--) {
work();
}
return 0;
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
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
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
|
java
|
import java.io.BufferedInputStream;
import java.util.Scanner;
public class Main {
private static Scanner sc = new Scanner(new BufferedInputStream(System.in));
public static void main(String[] args) {
work();
}
private static void work() {
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int n = sc.nextInt();
long l = sc.nextLong(), r = sc.nextLong();
printResult(l, r);
}
}
private static void printResult(long l, long r) {
StringBuffer stringBuffer = new StringBuffer();
long n = (long) Math.sqrt(l);
int cnt = 0;
long p = l, bias;
while (cnt < r - l + 1) {
bias = p - n * (n - 1) - 1;
if (bias % 2 == 1)
stringBuffer.append(n + 1).append(' ');
else {
if (bias / 2 == n)
stringBuffer.append(1).append(' ');
else
stringBuffer.append(bias / 2 + 1).append(' ');
}
p++;
cnt++;
if (p > n * (n + 1) + 1)
n++;
}
System.out.println(stringBuffer);
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
python3
|
import sys
import math
import bisect
readLine = lambda : sys.stdin.readline()
readInt = lambda : int(sys.stdin.readline())
readInts = lambda : [int(x) for x in sys.stdin.readline().split(" ")]
def main():
t = readInt()
solns = []
MAX_N = 2 * 10 ** 5
segStarts = [i * (i - 1) + 1 for i in range(1, MAX_N)]
segStarts.insert(0, 0)
for _ in range(t):
s = []
n, l, r = readInts()
# find start of segment containing l
x_start = bisect.bisect_left(segStarts, l-1)
offset_x = (l - 1) - segStarts[x_start] # number of terms from seg start to x
# left offset in node y segment
maxVal = x_start + 1
i = maxVal - (offset_x + 1) // 2
if offset_x == -1:
i = 1
maxVal -= 1
for j in range(l - 1, r):
if i == 0:
maxVal += 1
i = maxVal - 1
if j % 2 == 1:
s.append(maxVal)
else:
s.append(i)
i -= 1
solns.append(" ".join(str(x) for x in s))
print("\n".join(solns))
main()
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
python3
|
# |
# _` | __ \ _` | __| _ \ __ \ _` | _` |
# ( | | | ( | ( ( | | | ( | ( |
# \__,_| _| _| \__,_| \___| \___/ _| _| \__,_| \__,_|
import sys
import collections
def read_line():
return sys.stdin.readline()[:-1]
def read_int():
return int(sys.stdin.readline())
def read_int_line():
return [int(v) for v in sys.stdin.readline().split()]
t = read_int()
for i in range(t):
n,l,r = read_int_line()
u = r-l+1
lt = l
k = 0
while lt>0:
k+=1
lt -= 2*(k)
lt += 2*(k)
k-=1
j= max(k,1)
s = 0
for i in range(1,j):
s += 2*(n-i)
lt = l
lt -= s
lt +=1
i = j + lt//2
ans = []
while j<=n and len(ans)<=u:
if j!=k:
i = j+1
while i<=n and len(ans)<=u:
ans.append(j)
ans.append(i)
i+=1
j+=1
ans.append(1)
print(*ans[:u])
|
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 v_count(int begin) {
if (begin == 0) {
return 0;
}
return (long long)begin * (begin - 1) + 1;
}
int find_begin(long long n, long long x) {
if (x == 1) {
return 1;
}
long long begin = max(1, (int)sqrt(x) - 5);
while (v_count(begin) < x) {
begin++;
}
return begin;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
long long n, l, r;
cin >> n >> l >> r;
int begin_l = find_begin(n, l);
long long i = v_count(begin_l - 1) + 1;
int cur = begin_l;
int other = 2;
while (i < l) {
i++;
if (cur == begin_l) {
if (other == begin_l) {
cur = 1;
} else {
cur = other;
other++;
}
} else {
cur = begin_l;
}
}
cout << cur << ' ';
while (i < r) {
i++;
if (cur == 1) {
begin_l++;
cur = begin_l;
other = 2;
} else if (cur == begin_l) {
if (other == begin_l) {
cur = 1;
other = 2;
} else {
cur = other;
other++;
}
} else {
cur = begin_l;
}
cout << cur << ' ';
}
cout << '\n';
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
java
|
import java.util.*;
import java.io.*;
public class EulerPath{
public static void main(String args[]){
Scanner kb=new Scanner(System.in);
long cases=kb.nextLong();
for(int i=0; i<cases; i++) {
long n=kb.nextLong();
long start=kb.nextLong();
long end=kb.nextLong();
long n_i=(long) Math.floor((Math.sqrt(1+4*(start-1))-1)/2)+1;
while(start<=end) {
if(start==end-1) {
System.out.print(1 + " ");
}
else {
for(int j=0; j<2*n_i; j++) {
if(n_i*(n_i-1)+1+j>=start&&n_i*(n_i-1)+1+j<=end) {
if(j%2==1) {
System.out.print(n_i+1 + " ");
}
else {
System.out.print(j/2+1 + " ");
}
}
}
}
start=(n_i+1)*n_i;
n_i++;
}
System.out.println();
}
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
java
|
import java.util.*;
import java.io.*;
import java.time.Period;
public class codeforces {
public static void main(String[] args) throws Exception {
int t=sc.nextInt();
while(t-->0) {
long n=sc.nextLong();
long l=sc.nextLong();
long r=sc.nextLong();
long number =2;
long i=1;
while(l-i*2>0) {
l-=i*2;
r-=i*2;
i++;
number++;
}
for(;l<=r;l++) {
if(l%2==0) {
pw.print(number+" ");
}else {
pw.print(((long)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
|
java
|
import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeSet;
/**
* Created by Katushka on 11.03.2020.
*/
public class C {
static int[] readArray(int size, InputReader in) {
int[] a = new int[size];
for (int i = 0; i < size; i++) {
a[i] = in.nextInt();
}
return a;
}
static long[] readLongArray(int size, InputReader in) {
long[] a = new long[size];
for (int i = 0; i < size; i++) {
a[i] = in.nextLong();
}
return a;
}
public static void main(String[] args) throws FileNotFoundException {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
int t = in.nextInt();
for (int k = 0; k < t; k++) {
int n = in.nextInt();
long l = in.nextLong();
long r = in.nextLong();
long i = 0;
long s = 0;
while (s < l) {
i += 2;
s += i;
}
long s0 = s - i;
long j = s0 + 1;
long a = 1;
int j1 = 0;
StringBuilder ans = new StringBuilder();
while (j <= r) {
if (j >= l) {
ans.append(a).append(' ');
}
j++;
j1++;
if (j1 >= i) {
i += 2;
j1 = 0;
a = 1;
} else {
if (j1 % 2 == 1) {
a = i / 2 + 1;
} else {
a = j1 / 2 + 1;
}
}
}
out.println(ans.toString());
}
out.close();
}
private 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 String nextString() {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public char nextChar() {
return next().charAt(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.readline
T = int(input())
for _ in range(T):
n, l, r = map(int, input().split())
lb, ub = 0, n
while ub - lb > 1:
m = (lb + ub) // 2
if m * (2*n-m-1) < l:
lb = m
else:
ub = m
i = ub
s = lb * (2*n-lb-1) + 1
j = (l - s + 1) // 2 + i
ans = []
for k in range(l, r+1):
if i == n:
i = 1
if (k - s) % 2 == 0:
ans.append(i)
else:
j += 1
ans.append(j)
if j == n:
s = k + 1
i += 1
j = i
print(*ans)
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
python3
|
from sys import stdin
def allWays(start, verts, done, stack, n):
global valid
if not valid:
return
stack.append(start)
if len(done) == len(verts):
print(stack)
stack.pop()
valid = False
return
for x in range(1,n+1):
if start != x and not (start,x) in done:
done.add((start,x))
allWays(x,verts,done,stack,n)
done.remove((start,x))
stack.pop()
'''
for y in range(1,10):
verts = set([((x//y) + 1, (x%y)+1) for x in range(y**2)])
for x in range(1,y+1):
verts.remove((x,x))
valid = True
print(y, end=' ')
allWays(1, verts, set(), [], y)
'''
def order(n,x):
out = []
for y in range(x+1,n+1):
out.append(x)
out.append(y)
return out
for case in range(int(stdin.readline())):
n,l,r = [int(x) for x in stdin.readline().split()]
end1 = False
if r == n*(n-1) + 1:
end1 = True
r -= 1
if l == n*(n-1) + 1:
print(1)
else:
x = 1
while l > 2*(n-x):
l -= 2*(n-x)
r -= 2*(n-x)
x += 1
out = order(n,x)
r -= 2*(n-x)
x += 1
while r > 0:
out += order(n,x)
r -= 2*(n-x)
if end1:
out += [1]
if r != 0:
realOut = out[l-1:r]
else:
realOut = out[l-1:]
print(' '.join([str(b) for b in realOut]))
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
python3
|
import math
# ΡΠ΅ΡΠ΅Π½Π°
def task_1343_c():
b = int(input())
array = [int(num) for num in input().split()]
maxPositive = 0
minNegative = -10000000000
res = 0
for i in range(b):
if array[i] < 0:
if i != 0 and array[i - 1] >= 0:
res += maxPositive
maxPositive = 0
minNegative = max(minNegative, array[i])
else:
if i != 0 and array[i - 1] < 0:
res += minNegative
minNegative = -10000000000
maxPositive = max(maxPositive, array[i])
if minNegative == -10000000000:
res += maxPositive
else:
res += maxPositive + minNegative
print(res)
# Π½Π΅ ΡΠ°Π±ΠΎΡΠ°Π΅Ρ ΠΎΡ ΡΠ»ΠΎΠ²Π° ΡΠΎΠ²ΡΠ΅ΠΌ
def task_1341_b():
heightLen, doorSize = map(int, input().split())
heights = [int(num) for num in input().split()]
perf = [0 for i in range(heightLen)]
a = 0
for i in range(heightLen - 1):
if i == 0:
perf[i] = 0
else:
if heights[i - 1] < heights[i] and heights[i] > heights[i + 1]:
a += 1
perf[i] = a
perf[heightLen - 1] = a
max_global = 0
left_global = 0
for i in range(heightLen - doorSize):
max_local = perf[i + doorSize - 1] - perf[i]
if max_local > max_global:
max_global = max_local
left_global = i
print(max_global + 1, left_global + 1)
# ΡΠ΅ΡΠΈΠ», ΡΡΠΎΠ± Π΅Ρ
def task_1340_a():
n = int(input())
array = [int(i) for i in input().split()]
for i in range(n - 1):
if array[i] < array[i + 1]:
if array[i] + 1 != array[i + 1]:
print("No")
return
print("Yes")
#ΡΠ΅ΡΠΈΠ»
def task_1339_b():
n = int(input())
array = [int(num) for num in input().split()]
array.sort()
output = [0 for i in range(0, n)]
i = 0
h = 0
j = n - 1
while i <= j:
output[h] = array[i]
h += 1
i += 1
if h < n:
output[h] = array[j]
h += 1
j -= 1
for val in reversed(output):
print(val, end=' ')
# ΡΠ΅ΡΠ΅Π½Π°
def task_1338_a():
n = int(input())
inputArr = [int(num) for num in input().split()]
max_sec = 0
for i in range(1, n):
local_sec = 0
a = inputArr[i - 1] - inputArr[i]
if a <= 0:
continue
else:
b = math.floor(math.log2(a))
local_sec = b + 1
for j in range(b, -1, -1):
if a < pow(2, j):
continue
inputArr[i] += pow(2, j)
a -= pow(2, j)
if local_sec > max_sec:
max_sec = local_sec
print(max_sec)
def task_1334_d():
n, l ,r = map(int, input().split())
if l == 9998900031:
print(1)
return
res = []
count = 0
start_pos = l
for i in range(1, n + 1):
count += (n + 1 - i) * 2
if count >= l:
for j in range(n - i):
res.append(i)
res.append(j + i + 1)
if count > r:
break
else:
start_pos -= (n + 1 - i) * 2
res.append(1)
for i in range(start_pos - 1, start_pos + (r - l)):
print(res[i], end=" ")
print()
a = int(input())
for i in range(a):
task_1334_d()
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
java
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.StringTokenizer;
public class d {
public static void main(String[] args) {
FS in = new FS(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
while(t-->0) {
long n = in.nextInt();
long l = in.nextLong()-1;
long orig = l;
long r = in.nextLong();
for(; l < 2*n-3; l++) {
if(l%2 == 0) out.print("1 ");
else out.print((l+3)/2 + " ");
}
long curr = 2*n-3;
for(int i = 2; i < n; i++) {
long tmp = curr+2*(n-i);
for(long j = l-curr; l < Math.min(tmp, r); j++, l++) {
if(j == 0) out.print(n + " ");
else if(j%2 == 1) out.print(i + " ");
else out.print(i+j/2 + " ");
}
curr = tmp;
}
if(orig < n*(n-1) && r >= n*(n-1)) out.print(n + " ");
if(r == n*(n-1)+1) out.print("1 ");
out.println();
}
out.close();
}
static class FS {
BufferedReader in;
StringTokenizer token;
public FS(InputStream str) {
in = new BufferedReader(new InputStreamReader(str));
}
public String next() {
if(token == null || !token.hasMoreElements()) {
try {
token = new StringTokenizer(in.readLine());
} catch (IOException ex) {
}
return next();
}
return token.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
python3
|
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 - 2) + li[i - 1])
start = n
for i in range(n, 0, -1):
if(l >= li[i]):
start = i
break
st = ''
base = l - li[start]
temp = l
if( i != 1 ):
pairs = i - 2
pairs -= base//2
flag = base%2
num = 2
temp = l
if (flag == 0):
st += str(i) + " "
temp += 1
while(temp <= r and num <= i - 1 - base//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 = 2
while(num <= a - 1 and temp <= r):
st += str(num) + " "
temp += 1
if(temp <= r):
st += str(a) + " "
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 = 2
while(num <= a - 1 and temp <= r):
st += str(num) + " "
temp += 1
if(temp <= r):
st += str(a) + " "
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
|
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;
long long cnt = 0;
while (i <= r) {
if (i >= 4 * n - 5) ans.push_back(1LL), cnt++;
if (cnt > 1) {
ans.pop_back();
break;
} else 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
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const long long inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T;
cin >> T;
while (T--) {
long long n, l, r;
cin >> n >> l >> r;
long long num = 0;
long long cnt = r - l + 1;
for (int i = 1; i <= n && cnt; ++i) {
if (num + 2 * n - 2 * i < l) {
num += 2 * n - 2 * i;
} else {
if ((l - num) % 2 == 0) {
cnt--;
cout << (l - num) / 2 + i << ' ';
}
int temp = i;
if (l - num - 2 * n + 2 * i == 0) {
++temp;
}
for (int j = temp; j < n && cnt; ++j) {
for (int k = (j == i ? (l - num + 1) / 2 + i : j + 1); k <= n && cnt;
++k) {
cout << j << ' ';
cnt--;
if (cnt == 0) break;
cout << k << ' ';
cnt--;
if (cnt == 0) break;
}
}
break;
}
}
if (cnt) cout << "1";
cout << endl;
}
return 0;
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
cpp
|
/*
"With age, comes wisdom. With travel, comes understanding.
Remember that happiness is a way of travel β not a destination"
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define F first
#define S second
#define pb push_back
#define si set <int>
#define vi vector <int>
#define pii pair <int, int>
#define vpi vector <pii>
#define vpp vector <pair<int, pii>>
#define mii map <int, int>
#define mpi map <pii, int>
#define spi set <pii>
#define endl "\n"
#define sz(x) ((int) x.size())
#define all(p) p.begin(), p.end()
#define double long double
#define que_max priority_queue <int>
#define que_min priority_queue <int, vi, greater<int>>
#define bug(...) __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a) for(auto x : a) cout << x << " "; cout << endl
#define print1(a) for(auto x : a) cout << x.F << " " << x.S << endl
#define print2(a,x,y) for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl
inline int power(int a, int b)
{
int x = 1;
while (b)
{
if (b & 1) x *= a;
a *= a;
b >>= 1;
}
return x;
}
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> Set;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
const char* comma = strchr (names + 1, ',');
cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}
const int N = 100005;
int n, m, l, r;
void work(int pos, int x, int tot)
{
int req = r - tot + 1, tt = r - l + 1;
// bug(tot, l);
vi v;
for (int i = pos; i <= n; i++)
{
if (i == n)
v.pb(1);
else
{
int y = i;
for (int j = 0; j < x; j++)
{
if (j & 1)
{
y++;
v.pb(y);
req--;
}
else
{
v.pb(i);
req--;
}
if (!req)
break;
}
}
if (!req)
break;
}
// print(v);
for (int i = l - tot - 1; i < sz(v); i++)
{
cout << v[i] << " ";
tt--;
if (!tt)
break;
}
cout << endl;
}
void solve()
{
cin >> n >> l >> r;
int tot = 0, x = 2 * (n - 1);
for (int i = 1; i <= n; i++)
{
if (tot + x >= l)
{
work(i, x, tot);
break;
}
tot += x;
x -= 2;
if (!x)
x = 1;
}
}
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cout << setprecision(9) << fixed;
clock_t z = clock();
int t; cin >> t;
while (t--) solve();
cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);
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(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
long long int n, l, r;
cin >> n >> l >> r;
long long int l1 = 0, r1 = n - 1, mid, pos = -1;
while (l1 <= r1) {
mid = l1 + (r1 - l1) / 2;
if (2 * mid * n - mid * (mid + 1) < l) {
l1 = mid + 1;
pos = mid;
} else
r1 = mid - 1;
}
long long int t = r - l + 1;
l = l - (2 * pos * n - pos * (pos + 1));
pos++;
if (l % 2 == 0) {
cout << pos + l / 2 << " ";
t--;
l++;
}
long long int count = 2 * (n - pos) - (l - 1);
l++;
int b = -1;
while (count > 0) {
b = 1;
if (t <= 0) break;
cout << pos << " ";
t--;
if (t <= 0) break;
cout << pos + l / 2 << " ";
t--;
l += 2;
count -= 2;
}
if (b == 1) {
pos++;
}
while (t > 0) {
if (pos == n && t > 0) {
cout << 1 << " ";
break;
}
long long int count = 2 * (n - pos);
long long int c = 2;
while (count > 0 && t > 0) {
if (t <= 0) break;
cout << pos << " ";
t--;
if (t <= 0) break;
cout << pos + c / 2 << " ";
t--;
c += 2;
count -= 2;
}
pos++;
if (t <= 0) break;
}
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
|
#n = int(input())
#used = [[False for _ in range(n)] for __ in range(n)]
#
#for i in range(n):
# used[i][i] = True
#
#start = n - 1
#cur = 0
#
#res = []
#while True:
# if cur == 0:
# start -= 1
# res += [cur + 1]
# print(cur + 1)
# for i in range(n):
# if not used[cur][i] and not (start == 0 and i == 0):
# used[cur][i] = True
# cur = i
# break
# else:
# print('error or done')
# break
#res += [1]
#
#assert len(res) == n * (n-1) + 1
#
#s = ' '.join(map(str, res))
#for i in range(1,n+1):
# for j in range(1,n+1):
# if i == j: continue
# assert f'{i} {j}' in s
def oracle(n, start, end):
nod = 0
t = n - 1
ii = 0
while start - ii >= t*2:
if t == 0:
nod += 1
break
nod += 1
ii += t*2
t -= 1
if t < -10:
import sys
sys.exit()
R = []
for cur in range(nod, n):
for v in range(cur+1, n):
ii += 1
if start <= ii <= end:
R.append(cur + 1)
ii += 1
if start <= ii <= end:
R.append(v + 1)
if ii > end:
return R
ii += 1
if start <= ii <= end:
R.append(1)
return R
t = int(input())
for _ in range(t):
a,b,c = map(int,input().split())
print(*oracle(a, b, c))
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
python3
|
from sys import stdin, gettrace
from math import sqrt
if not gettrace():
def input():
return next(stdin)[:-1]
# def input():
# return stdin.buffer.readline()
def main():
def solve():
n,l,r = map(int, input().split())
lv = int((2*n+1 - sqrt((2*n-1)**2 -4*(l-1)))/2)
lvs = -2*n+2*n*lv-lv*lv+lv
lrd = l - lvs - 1
res = []
i = lvs+1
j = lvs+(lrd+2)//2 + 1
for _ in range(l-1, r, 2):
res += [i,j]
if j < n:
j += 1
else:
i +=1
j = i+1
if r == n*(n-1)+1:
res[l-r] = 1
print(' '.join(map(str, res[:r-l+1])))
q = int(input())
for _ in range(q):
solve()
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.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.StringTokenizer;
public class d {
public static void main(String[] args) {
FS in = new FS(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
while(t-->0) {
long n = in.nextInt();
long l = in.nextLong()-1;
long orig = l;
long r = in.nextLong();
for(; l < 2*n-3; l++) {
if(l%2 == 0) out.print("1 ");
else out.print((l+3)/2 + " ");
}
long curr = 2*n-3;
for(int i = 2; i < n; i++) {
out.flush();
long tmp = curr+2*(n-i);
for(long j = l-curr; l < Math.min(tmp, r); j++, l++) {
if(j == 0) out.print(n + " ");
else if(j%2 == 1) out.print(i + " ");
else out.print(i+j/2 + " ");
}
}
if(orig < n*(n-1) && r >= n*(n-1)) out.print(n + " ");
if(r == n*(n-1)+1) out.print("1 ");
out.println();
}
out.close();
}
static class FS {
BufferedReader in;
StringTokenizer token;
public FS(InputStream str) {
in = new BufferedReader(new InputStreamReader(str));
}
public String next() {
if(token == null || !token.hasMoreElements()) {
try {
token = new StringTokenizer(in.readLine());
} catch (IOException ex) {
}
return next();
}
return token.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
cpp
|
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define yn(x) cout<<(x == 0 ? "NO" : "YES")<<"\n"
using namespace std;
const ll mod = 1e9+7;
ll powmod(ll a, ll b){
assert(b>=0);
if(b==0){return 1;}
a = a%mod;
ll h = powmod(a, b/2);
h = (h*h)%mod;
if(b%2 == 1){ h = (h*a)%mod; }
return h;
}
ll gcd(ll a, ll b) {return __gcd(a, b);}
void solve(){
//solve here//
ll n, l, r; cin >> n >> l >> r;
ll a=0, b=1;
for(int i=1;i<n;i++){
a += 2*(n-i)-1;
for(ll j=max(b, l);j<=min(a, r);j++){
ll rel = j-b+1;
if(rel%2 == 1){
cout << (n-i+1)%n + 1 << " ";
} else {
cout << 1+rel/2 << " ";
}
}
b = a+1;
}
a += n;
for(ll i=max(b, l);i<=min(a, r);i++){
ll rel = i-b+1;
cout << rel%n+1 << " ";
}
cout << "\n"; return;
}
int main(){
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1; cin >> t;
while(t--){
solve();
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
java
|
import java.util.*;
import java.io.*;
import java.time.Period;
public class codeforces {
public static void main(String[] args) throws Exception {
int t=sc.nextInt();
while(t-->0) {
long n=sc.nextLong();
long l=sc.nextLong();
long r=sc.nextLong();
long number =2;
long i=1;
while(l-i*2>0) {
l-=i*2;
r-=i*2;
i++;
number++;
}
for(;l<=r;l++) {
if(l%2==0) {
pw.print(number+" ");
}else {
pw.print((l+1l)/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
|
# from sys import stdin,stdout
# input = stdin.readline
# print = stdout.write
from math import *
ar=[0,1]
for i in range(2,100010):
ar.append(i*(i-1)+1)
def jg(ar,n):
l=0
r=len(ar)-1
ans=-1
while(l<=r):
m=(l+r)//2
if(ar[m]>=n):
ans=m
r=m-1
else:
l=m+1
return ans
print(ar[:10])
for __ in range(int(input())):
n,l,r=map(int,input().split())
for i in range(l,r+1):
if(i==1):
print(1,end=" ")
elif(i==2):
print(2,end=" ")
elif(i==3):
print(1,end=" ")
else:
a=jg(ar,i)
if(i%2==0):
print(a,end=" ")
else:
temp=i-ar[a-1]
if(temp//2 + 1==a):
print(1,end=" ")
else:
print(temp//2+1,end=" ")
print()
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
python3
|
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
from functools import lru_cache #use @lru_cache(None)
if os.path.exists('in.txt'): sys.stdin=open('in.txt','r')
if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w')
#
def input(): return sys.stdin.readline()
def mapi(arg=0): return map(int if arg==0 else str,input().split())
#------------------------------------------------------------------
for _ in range(int(input())):
n,l,r = mapi()
tmp = n*(n-1)+1
if l==tmp:
print(1)
else:
total = 2*(n-1)
cnt = 1
while l>total:
cnt+=1
total+=2*(n-cnt)
total -=2*(n-cnt)
res = []
pst = 0
nxt = 0
if (l-total)%2==0:
tmp = cnt+(l-total)//2
res.append(tmp)
if tmp!=n:
pst = cnt
nxt = tmp+1
else:
pst,nxt = cnt+1,cnt+2
else:
pst = cnt
nxt = cnt+(l-total)//2+1
while len(res)-1<r-l:
res.append(pst)
res.append(nxt)
if nxt==n:
if pst==n-1: pst=1
else:
pst +=1
nxt = pst+1
else:
nxt+=1
print(*res[:r-l+1])
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7FFFFFFF;
const long long mod = (0 ? 1000000007 : 998244353);
const double eps = 1e-7;
void work() {
long long n, l, r;
cin >> n >> l >> r;
long long sum = 1;
long long nw = 2;
long long cnt = 1;
while (sum + nw <= l) {
cnt++;
sum += nw;
nw += 2;
}
vector<long long> ans;
long long fl = 1;
long long res = l - sum;
long long pos = l - 1;
cnt++;
if (res == 0) {
ans.push_back(1);
pos++;
fl = 0;
res = 2;
} else if (res & 1)
fl = 0;
long long now = 1 + res / 2;
while (pos < r) {
pos++;
if (fl == 0) {
ans.push_back(cnt);
fl = 1;
continue;
}
if (now == cnt) {
cnt++;
ans.push_back(1);
now = 2;
fl = 0;
continue;
}
fl = 0;
ans.push_back(now);
now++;
continue;
}
for (long long i = 0; i < ans.size(); i++) {
cout << ans[i] << ' ';
}
cout << endl;
}
signed main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
long long t = 1;
cin >> t;
while (t--) {
work();
}
return 0;
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
python3
|
t = int(input())
if t == 3:
print(1, 2, 1)
print(1,3,2,3)
print(1)
exit()
if t < 20:
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
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
void upgrade() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
long long func(long long a) { return a * (a - 1); }
int main() {
upgrade();
int t;
cin >> t;
for (int zzz = 0; zzz < t; zzz++) {
long long n, l, r;
cin >> n >> l >> r;
long long h = 2;
while (l > func(h) + 1) {
h++;
}
long long a = l - func(h - 1) - 1;
long long h2;
if (a == 2 * h - 2) {
h2 = 1;
} else {
h2 = a / 2 + 1;
}
long long f = a % 2;
if (l == 1) {
h = 1, h2 = 1;
f = 0;
}
for (int i = 0; i < r - l + 1; i++) {
if (f) {
cout << h << ' ';
if (h == 2) h2 = 1;
} else {
cout << h2 << ' ';
if (h2 == 1) {
h++;
h2 = 2;
} else if (h2 == h - 1) {
h2 = 1;
} else {
h2++;
}
}
f = ~f;
}
cout << '\n';
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int i, j, n, m, k;
long long int l, r;
cin >> n >> l >> r;
bool var1 = 0;
long long int var2 = 0, var = 0;
if (r == (n * (n - 1LL)) + 1LL) {
var1 = 1;
r--;
} else {
long long int o = 0;
while (o < 2) o++;
}
long long int o = 0;
for (i = 1; i <= n; i++) {
var2 += (n - i) * 2LL;
if (o == 1) {
o = 0;
} else if (var2 >= l) {
var2 -= (n - i) * 2LL;
var = i;
break;
} else {
o = 0;
}
}
var2 = l - var2;
long long int p = var2;
long long int var3 = 1;
var2 = (var + var2 / 2 + var2 % 2);
if (l <= r && (p % 2LL == 0)) {
cout << var2 << " ";
l++;
var2++;
} else {
o = 0;
}
o = 0;
while (l <= r && o == 0) {
if (var2 > n) {
var++;
var2++;
}
if (o == 1)
o = 0;
else
o = 0;
if ((var3 % 2) == 1)
cout << var << " ";
else {
cout << var2 << " ";
var2++;
}
l++;
var3 = 1 - var3;
}
o = 1;
if (var1) cout << o << " ";
cout << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int i, j, n, m, k;
long long 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 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+1])
# 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
|
java
|
import java.util.*;
import java.lang.*;
import java.io.*;
public class GFG{
public static void main (String[] args) throws Exception
{
FastScanner sc = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int t= sc.nextInt();
while(t-->0){
int n=sc.nextInt();
long l,r;
l=sc.nextLong();
r=sc.nextLong();
l--;
long s=0;
for(int v=1;l<r && v<n;v++){
long len=n-v;
if(s+2*len<=l){
s+=2*len;
continue;
}
for(int u=v+1;u<=n;u++){
if(s==l && l<r){
out.print(v+" ");
l++;
}
s++;
if(s==l && l<r){
out.print(u+" ");
l++;
}
s++;
}
}
out.print("1");
out.println();
}
out.close();
}
}
class FastScanner
{
final private int BUFFER_SIZE = 1 << 17;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public FastScanner(InputStream in)
{
din = new DataInputStream(in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String nextLine() throws Exception
{
StringBuffer sb = new StringBuffer("");
byte c = read();
while (c <= ' ') c = read();
do
{
sb.append((char)c);
c = read();
}
while(c > ' ');
return sb.toString();
}
public char nextChar() throws Exception
{
byte c = read();
while(c <= ' ') c = read();
return (char)c;
}
public int nextInt() throws Exception
{
int ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = c == '-';
if (neg) c = read();
do
{
ret = ret * 10 + c - '0';
c = read();
}
while (c > ' ');
if (neg) return -ret;
return ret;
}
public long nextLong() throws Exception
{
long ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = c == '-';
if (neg) c = read();
do
{
ret = ret * 10 + c - '0';
c = read();
}
while (c > ' ');
if (neg) return -ret;
return ret;
}
private void fillBuffer() throws Exception
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1) buffer[0] = -1;
}
private byte read() throws Exception
{
if (bufferPointer == bytesRead) fillBuffer();
return buffer[bufferPointer++];
}
public double nextDouble() throws Exception
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
java
|
import java.util.*;
import java.io.*;
public class Main {
static FastReader in=new FastReader();
static StringBuilder Sd=new StringBuilder();
static List<Integer>Gr[];
static long Mod=998244353;
static Map<Integer,Integer>map=new HashMap<>();
public static void main(String [] args) {
//Dir by MohammedElkady
int t=in.nextInt();
while(t-->0) {
long n=in.nextLong(),l=in.nextLong(),r=in.nextLong();
long ans=1,res=0;
l-=1;r-=1;
int lol=0;
if(r>=n*(n-1)) {lol=1;r--;
}
for(long i=1;i<=n;i++) {
ans=i;
if(res+((n-i)*2)<l)
{
res+=(n-i)*2;
}else break;
}
long vov=ans+1;
if(!(lol>0&&l>r))
for(;l-1<=r;) {
if(res>l) {
Sout(vov-1+" ");
l++;
}
if(res==l) {
if(vov>n) {
ans+=1;vov=ans+1;
}
Sout(ans+" ");
if(r-l>=2) {Sout(vov+" ");}
vov++;
res+=2;
l+=2;
}
else {
vov++;
res+=2;
}
}
if(lol>0) {Soutln("1 ");}
else Soutln("");
}
Sclose();
}
static long power(long x, long y, long p)
{
// Initialize result
long res = 1;
// Update x if it is more than or
// equal to p
x = x % p;
while (y > 0)
{
// If y is odd, multiply x
// with result
if (y % 2 == 1)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
// Returns n^(-1) mod p
static long modInverse(long n, long p)
{
return power(n, p-2, p);
}
// Returns nCr % p using Fermat's
// little theorem.
static long nCrModPFermat(int n, int r,
long p)
{
// Base case
if (r == 0)
return 1;
// Fill factorial array so that we
// can find all factorial of r, n
// and n-r
long[] fac = new long[n+1];
fac[0] = 1;
for (int i = 1 ;i <= n; i++)
fac[i] = fac[i-1] * i % p;
return (fac[n]* modInverse(fac[r], p)
% p * modInverse(fac[n-r], p)
% p) % p;
}
static long fac(int n , int m,int l) {
long res=1;
for(int i=l,u=1;i<=n||u<=m;i++,u++) {
if(i<=n) {res*=i;}
if(u<=m) {res/=u;}
while(res>Mod)
res-=Mod;
}
return res;
}
static long posation(int n) {
long res=1;
for(int i=0;i<n-3;i++) {res*=2L;
while(res>Mod)
res-=Mod;
while(res<=0)res+=Mod;}
return res;
}
static long gcd(long g,long x){
if(x<1)return g;
else return gcd(x,g%x);
}
//array fill
static long[]filllong(int n){long a[]=new long[n];for(int i=0;i<n;i++)a[i]=in.nextLong();return a;}
static int[]fillint(int n){int a[]=new int[n];for(int i=0;i<n;i++)a[i]=in.nextInt();return a;}
//OutPut Line
static void Sout(String S) {Sd.append(S);}
static void Soutln(String S) {Sd.append(S+"\n");}
static void Soutf(String S) {Sd.insert(0, S);}
static void Sclose() {System.out.println(Sd);}
static void Sclean() {Sd=new StringBuilder();}
}
class node implements Comparable<node>{
int x,t;
node(int x,int p){
this.x=x;
this.t=p;
}
@Override
public int compareTo(node o) {
return (t-o.t);
}
}
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
class Sorting{
public static node[] bucketSort(node[] array, int bucketCount) {
if (bucketCount <= 0) throw new IllegalArgumentException("Invalid bucket count");
if (array.length <= 1) return array; //trivially sorted
int high = array[0].t;
int low = array[0].t;
for (int i = 1; i < array.length; i++) { //find the range of input elements
if (array[i].t > high) high = array[i].t;
if (array[i].t < low) low = array[i].t;
}
double interval = ((double)(high - low + 1))/bucketCount; //range of one bucket
ArrayList<node> buckets[] = new ArrayList[bucketCount];
for (int i = 0; i < bucketCount; i++) { //initialize buckets
buckets[i] = new ArrayList();
}
for (int i = 0; i < array.length; i++) { //partition the input array
buckets[(int)((array[i].t - low)/interval)].add(array[i]);
}
int pointer = 0;
for (int i = 0; i < buckets.length; i++) {
Collections.sort(buckets[i]); //mergeSort
for (int j = 0; j < buckets[i].size(); j++) { //merge the buckets
array[pointer] = buckets[i].get(j);
pointer++;
}
}
return array;
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
python2
|
def search(X, l=0, r=100010) :
if r <= l : return l
n = (r+l) // 2
v = 1+n*(n-1)
if X < v : return search(X, l, n)
elif X > v : return search(X, n+1, r)
else : return n
T = input()
for t in range(T) :
N, L, R = map(int,raw_input().split())
lSec = search(L)
rSec = search(R)
lBase = 1+(lSec-1)*(lSec-2) if lSec > 1 else 0
rBase = 1+(rSec-1)*(rSec-2) if rSec > 1 else 0
extraL = L-lBase
extraR = R-rBase
# extra on the left
res = [] if lSec > 1 or rSec == 1 else [1]
for i in range(extraL, (lSec-1)*2+1 if lSec < rSec else extraR+1) :
if i%2 == 0 : res.append(i//2+1 if i//2+1 != lSec else 1)
else : res.append(lSec)
# middle chunks
for i in range(lSec+1, rSec) :
for j in range(1,(i-1)*2+1) :
if j%2 == 0 : res.append(j//2+1 if j//2+1 != i else 1)
else : res.append(i)
if (lSec < rSec) :
# right chunks
for i in range(1,extraR+1) :
if i%2 == 0 : res.append(i//2+1 if i//2+1 != rSec else 1)
else : res.append(rSec)
print ' '.join(str(x) for x in 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
|
cpp
|
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef long long int ll;
int main()
{ ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;cin>>t;while (t--){
ll n;ll l,r;cin>>n>>l>>r;
ll pre[n]={0};pre[0]=2*(n-1);
for (int i=1;i<n-1;i++){
pre[i]=pre[i-1]+2*(n-i-1);
}
pre[n-1]=pre[n-2]+1;
int in=lower_bound(pre,pre+n,l)-pre,in2=lower_bound(pre,pre+n,r)-pre;
if (in==n-1){
cout<<1<<"\n";
}
else{
ll temp=l;
if (in){
temp-=pre[in-1];
}
ll st=(temp+1)/2+in+1,st1,st2;
if (temp%2){st1=in+1,st2=st;}else {st1=st;st2=in+1;}
if (in==in2){
for (ll k=l;k<r;k+=2){
cout<<st1<<" "<<st2<<" ";
if (st1==in+1)st2++;
else st1++;
}
if ((r-l)%2==0){
cout<<st1;
}
cout<<"\n";
}
else{
for (ll k=l;k<pre[in];k+=2){
cout<<st1<<" "<<st2<<" ";
if (st1==in+1)st2++;
else st1++;
}
if ((pre[in]-l)%2==0)
cout<<st1<<" ";
for (int k=in+1;k<in2;k++){
for (int j=k+2;j<=n;j++){
cout<<k+1<<" "<<j<<" ";
}
}
if (in2==n-1)cout<<1<<"\n"; else{
ll t2=r-pre[in2-1];
for (ll i=1;i<t2;i+=2){
cout<<in2+1<<" "<<in2+1+i<<" ";
}
if (t2%2)cout<<in2+1;cout<<"\n";}
}
}
}
return 0;
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
python3
|
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush
def RL(): return map(int, sys.stdin.readline().rstrip().split())
def N(): return int(input())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
mod = 1000000007
INF = float('inf')
# ------------------------------
def main():
def c(sm, a1):
sm = n*a1+(n-1)*n
for _ in range(N()):
n, l, r = RL()
i = n-1
sm = 0
while sm<l:
sm+=i*2 if i>0 else 1
if sm>=l: break
i-=1
dif = l-(sm-i*2)
res = []
for j in range(n-i, n+1):
now = []
for k in range(j+1, n+1):
now.append(j)
now.append(k)
res+=now
if len(res)>(r-k+1)+dif: break
res = res[dif-1:]
if len(res)<r-l+1: res.append(1)
print(*res)
if __name__ == "__main__":
main()
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
cpp
|
#include<bits/stdc++.h>
using namespace std;
#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 ans;
/*if(n==2)
{
ans.pb(1);
ans.pb(2);
return ans;
}
else if(n>2)
{
v.pb(1);
v.pb(n);
loop(i,2,n-1)
v.pb(i);
ans=v;
ans.pb(n-1);
//print(ans);
reverse(beg(v),last(v));
//copy(beg(v),last(v),last(ans));
for(ll u:v)
ans.pb(u);
//print(ans);
ans.ppb();
}*/
loop(i,1,n)
{
ans.pb(i);
ans.pb(n);
}
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
|
python3
|
CASES = int(input())
answers = []
while (CASES):
CASES -= 1
num, begin, end = [int(x) for x in input().split(" ")]
sequence = []
index = 0
tempB = begin
tempE = end
while (tempB > 0):
tempB -= 2*index
tempE -= 2*index
index += 1
if (tempB < 0):
index -= 1
tempB += 2*index
tempE += 2*index
i = 0
while (i <= tempE):
for x in range(1, index + 1):
sequence.append(x)
sequence.append(index + 1)
i += 2
index += 1
answers.append(" ".join([str(x) for x in sequence[tempB-1:tempE]]))
for ans in answers:
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 MinimumEulerCycle {
// https://codeforces.com/contest/1334/problem/D
public static void main(String[] args) throws IOException, FileNotFoundException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader in = new BufferedReader(new FileReader("MinimumEulerCycle"));
int t = Integer.parseInt(in.readLine());
while (t --> 0) {
StringTokenizer st = new StringTokenizer(in.readLine());
long n = Integer.parseInt(st.nextToken());
long l = Long.parseLong(st.nextToken());
long r = Long.parseLong(st.nextToken());
long curnum = 2;
long cursum=0;
while (cursum + (curnum-1)*2 < l) {
cursum += (curnum-1)*2;
curnum++;
}
long[] cur = new long[(int)(2*(curnum-1)+1)];
cur[0] = 1;
cur[1] = curnum;
int pointer=2;
for (long i=2; i< curnum; i++) {
cur[pointer] = i;
pointer++;
cur[pointer] = curnum;
pointer++;
}
cur[pointer] = 1;
StringBuilder sb = new StringBuilder();
for (int i=0; i<cur.length; i++) {
cursum++;
if (cursum >= l && cursum <= r) {
sb.append(cur[i] + " ");
}
}
System.out.println(sb);
}
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n, lgrp = 0, rgrp = 0;
long long int l, r;
cin >> n >> l >> r;
for (int k = 1; k <= n - 1; ++k) {
if (l <= 2 * (n - k) * 1LL) {
lgrp = k;
break;
} else {
l -= 2 * (n - k) * 1LL;
}
}
for (int k = 1; k <= n - 1; ++k) {
if (r <= 2 * (n - k) * 1LL) {
rgrp = k;
break;
} else {
r -= 2 * (n - k) * 1LL;
}
}
int start = 0;
if (lgrp == 0) lgrp = n;
if (rgrp == 0) rgrp = n;
if (lgrp == n && rgrp == n) {
cout << 1;
} else if (lgrp != rgrp) {
if (l % 2 == 1) {
++l;
cout << lgrp << " ";
}
start = l / 2;
cout << lgrp + start << " ";
++l;
for (int i = l; i <= 2 * (n - lgrp); ++i) {
if (i % 2 == 0) {
++start;
cout << lgrp + start << " ";
} else {
cout << lgrp << " ";
}
}
for (int i = lgrp + 1; i < rgrp; ++i) {
start = 0;
for (int j = 1; j <= 2 * (n - i); ++j) {
if (j % 2 == 0) {
++start;
cout << i + start << " ";
} else {
cout << i << " ";
}
}
}
if (rgrp == n) {
cout << 1 << " ";
} else {
start = 0;
for (int i = 1; i <= r; ++i) {
if (i % 2 == 0) {
++start;
cout << rgrp + start << " ";
} else {
cout << rgrp << " ";
}
}
}
} else {
if (l % 2 == 1) {
++l;
cout << lgrp << " ";
}
start = l / 2;
cout << lgrp + start << " ";
++l;
for (int i = l; i <= r; ++i) {
if (i % 2 == 0) {
++start;
cout << lgrp + start << " ";
} else {
cout << lgrp << " ";
}
}
}
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;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
long long n, l, r;
cin >> n >> l >> r;
list<int> ans;
long long k = 1, cur = 0;
while (cur + 2 * (n - k) <= l && k < n - 1) {
cur += 2 * (n - k);
k++;
}
int m = k;
for (long long i = cur + 1; i <= r; ++i) {
if (i % 2) {
if (m == n) {
k++;
m = k;
}
if (k == n) k = 1;
ans.push_back(k);
} else {
m++;
ans.push_back(m);
}
}
for (long long i = 0; i < l - cur - 1; ++i) ans.pop_front();
for (auto i : ans) cout << i << " ";
cout << endl;
}
return 0;
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
java
|
import java.io.*;
import java.util.*;
public class eulercycc {
/*
* @return Index of leftmost number >=key. Inclusive
*/
/*
private static int bsLowerBound(int[] a, int key) {
// Modified Arrays.binarySearch
int low = 0;
int high = a.length - 1;
while (low <= high) {
int mid = (low + high) >>> 1;
int midVal = a[mid];
int cmp = midVal - key;
if (cmp < 0)
low = mid + 1;
else if (cmp > 0)
high = mid - 1;
else if (mid != 0 && a[mid-1]==midVal) { // not lower bound
high = mid-1;
}
else
return mid; // key found
}
return high+1; // key not found, returns number before
}*/
/**
* @return Index of rightmost number <=key. Inclusive
*/
private static long bsLowerBound(long high, long key) {
// Modified Arrays.binarySearch
long low = 0;
while (low <= high) {
long mid = (low + high) >>> 1;
long cmp = mid * (mid + 1L) - key;
if (cmp < 0) {
low = mid + 1;
}
else if (cmp > 0) {
high = mid - 1;
}
else {
return mid; // key found
}
}
return low - 1; // key not found, returns number after
}
public static void main(String[] args) throws Exception {
R in = new R();
int TESTCASES = in.nextInt();
StringBuilder out = new StringBuilder();
for (int TC = 0; TC < TESTCASES; TC++) {
long n = in.nextInt();
long l = in.nextLong();
long r = in.nextLong();
long p = bsLowerBound(n+69, l);
p=Math.max(1, p-3);
for (long i = l; i <= r; i++) {
// n-1 inside the partition
while (i > p*(p+1)) {
p++;
}
if ((i&1)==0) {
// even
out.append(p+1).append(' ');
} else {
out.append( (i+1-p*(p-1)) >> 1 ).append(' ');
}
}
out.setCharAt(out.length()-1, '\n');
}
System.out.print(out);
System.out.flush();
}
//<editor-fold desc="R">
/**
* This class is for fast input. Please ignore.
*/
public static class R {
private BufferedReader br;
/**
* Should be set to null at end of line
*/
private StringTokenizer st;
public R() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public R(String filename) throws IOException {
br = new BufferedReader(new FileReader(filename + ".in"));
}
public R(BufferedReader reader) {
br = reader;
}
public BufferedReader getReader() {
return br;
}
public StringTokenizer getStringTokenizer() {
return st;
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
String s = br.readLine();
if (s == null) return null;
st = new StringTokenizer(s);
}
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
/**
* Note:
* CAN MODIFY the BufferedReader's location and the string tokenizer!!!
* Recommended to only use with next().
*/
public boolean lineHasNext() throws IOException {
if (st == null) {
String s = br.readLine();
if (s == null) return false;
st = new StringTokenizer(s);
}
return st.hasMoreTokens();
}
/**
* Note:
* CAN MODIFY the BufferedReader's location and the string tokenizer!!!
* Recommended to only use with next().
*/
public boolean hasNext() throws IOException {
while (st == null || !st.hasMoreTokens()) {
String s = br.readLine();
if (s == null) return false;
st = new StringTokenizer(s);
}
return true;
}
/**
* Skips a line. Sets st to null if has tokens left, and otherwise
* reads a line.
*/
public void skipLine() throws IOException {
if (st == null || !st.hasMoreTokens()) {
br.readLine(); // Otherwise, would do nothing.
}
st = null;
}
/**
* This will set st to null, and this ignores current line
*/
public String[] nextLine() throws IOException {
String s = br.readLine();
if (s == null) return null;
st = new StringTokenizer(s);
ArrayList<String> result = new ArrayList<>();
while (st.hasMoreTokens()) {
result.add(st.nextToken());
}
st = null;
return result.toArray(new String[0]);
}
/**
* sets st to null!
*/
public String[] nextTower(int lines) throws IOException {
String[] tower = new String[lines];
st = null;
for (int i = 0; i < lines; i++) {
tower[i] = br.readLine();
}
return tower;
}
public int[] nextIntLine() throws IOException {
return intArr(nextLine());
}
public long[] nextLongLine() throws IOException {
return longArr(nextLine());
}
public int[] nextIntTower(int lines) throws IOException {
return intArr(nextTower(lines));
}
public long[] nextLongTower(int lines) throws IOException {
return longArr(nextTower(lines));
}
public int[] intArr(String[] strings) throws IOException {
int[] ints = new int[strings.length];
int i = 0;
for (String s : strings) {
ints[i] = Integer.parseInt(s);
i++;
}
return ints;
}
public long[] longArr(String[] strings) throws IOException {
long[] longs = new long[strings.length];
int i = 0;
for (String s : strings) {
longs[i] = Long.parseLong(s);
i++;
}
return longs;
}
public double[] doubleArr(String[] strings) {
double[] doubles = new double[strings.length];
int i = 0;
for (String s : strings) {
doubles[i] = Double.parseDouble(s);
i++;
}
return doubles;
}
/**
* This will set st to null
*/
public char[] nextCharArray() throws IOException {
st = null;
String s = br.readLine();
return s == null ? null : s.toCharArray();
}
/**
* This will set st to null
* Boolean at pos i true if char at pos i == c
*/
public boolean[] nextBoolArray(char c) throws IOException {
char[] chars = nextCharArray();
if (chars == null) return null;
boolean[] booleans = new boolean[chars.length];
for (int i = 0; i < chars.length; i++) {
booleans[i] = chars[i] == c;
}
return booleans;
}
public int[][] next2Dint(int lines) throws IOException {
int[][] result = new int[lines][];
for (int i = 0; i < lines; i++) {
result[i] = nextIntLine();
}
return result;
}
public long[][] next2Dlong(int lines) throws IOException {
long[][] result = new long[lines][];
for (int i = 0; i < lines; i++) {
result[i] = nextLongLine();
}
return result;
}
public char[][] next2Dchar(int lines) throws IOException {
char[][] result = new char[lines][];
for (int i = 0; i < lines; i++) {
result[i] = nextCharArray();
}
return result;
}
public boolean[][] next2Dbool(int lines, char c) throws IOException {
boolean[][] result = new boolean[lines][];
for (int i = 0; i < lines; i++) {
result[i] = nextBoolArray(c);
}
return result;
}
}
//</editor-fold>
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
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 (val == n && !left) {
sector++;
val = sector + 1;
}
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
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
int n;
long long l, r;
int main() {
ios_base::sync_with_stdio(0);
cin.tie();
int t;
cin >> t;
while (t--) {
cin >> n >> l >> r;
--l;
--r;
long long a = 1LL, b = 1LL, c = -l;
long long idx = floor((-b + sqrt(b * b - 4LL * a * c)) / (2LL * a));
long long num = idx + 2LL;
l -= (idx) * (idx + 1LL);
r -= (idx) * (idx + 1LL);
long long curr = (l / 2LL) + 1LL;
for (long long i = l; i <= r; ++i) {
if (num == curr) {
++num;
curr = 1LL;
}
if (i % 2LL == 0LL) {
cout << curr << " ";
} else {
cout << num << " ";
curr++;
}
}
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;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_pair_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statisticur_node_update>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define fi first
#define se second
#define endl '\n'
#define int int64_t
#define double long double
mt19937 rnd(time(0));
// const double TIME_LIMIT = 1.8;
// Heuristic TL: clock() < TIME_LIMIT * CLOCKS_PER_SEC
const int MAXN = 101;
const int MOD = (int)1e9 + 7;
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("FDT.txt","r",stdin);
int test;
cin >> test;
while(test --){
int n, l, r;
cin >> n >> l >> r;
int cur = 0;
int st = 0;
for(int brac = 1; brac < n; brac ++){
int range = 2*(n - brac);
if(l >= cur + 1 && l <= cur + range){
st = brac;
break;
}
cur += range;
}
if(st == 0){
cout << 1 << endl;
continue;
}
// cout << st << " " << cur << endl;
vector<int> res;
int c = cur + 1;
int inb = 0;
int mt = st + 1;
while(c <= n*(n - 1) && c <= r){
int current;
if(!inb){
if(c >= l && c <= r) res.push_back(st);
}
else{
if(c >= l && c <= r) res.push_back(mt);
mt ++;
}
c ++;
if(c == cur + (n - st)*2 + 1){
// new brac
st ++;
mt = st + 1;
}
inb ^= 1;
}
if(r == (n*(n - 1) + 1))
res.push_back(1);
for(auto u: res)
cout << u << " ";
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 int MAXN = 100257;
int T, N;
long long l, r;
long long level[MAXN];
long long prefix[MAXN];
int findNode(long long &l, int &nextMin) {
long long ind = l - level[nextMin - 1];
if (l == N * (N - 1) + 1) {
return 1;
}
if (ind == 1) {
return nextMin;
} else if (ind == prefix[nextMin]) {
++nextMin;
return N;
}
--ind;
return ind % 2 == 0 ? nextMin : ind / 2 + nextMin + 1;
}
void solve() {
cin >> N >> l >> r;
level[0] = 0;
int start = -1;
for (int i = 1; i < N; i++) {
prefix[i] = 1 + 2 * (N - i - 1) + 1;
level[i] = level[i - 1] + prefix[i];
if (level[i - 1] <= l && l < level[i]) {
start = i;
}
}
if (start == -1) {
start = N;
}
while (l <= r) {
int node = findNode(l, start);
cout << node << " ";
++l;
}
cout << endl;
}
int main() {
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;
long long int oo = numeric_limits<long long int>::max();
long long int MOD = 1e9 + 7;
long long int comp(long long int n) { return 1LL + (n * (n + 1LL)); }
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(i) < l) i++;
long long int idx = i == 1 ? 1 : comp(i - 1);
if (l == 1) {
cout << 1 << " ";
}
for (; i <= n; i++) {
long long int ii = i + 1;
for (long long int j = 0; j < 2 * 1LL * i; j++) {
long long int nm;
if (j % 2 == 0) {
nm = ii;
} else if (j + 1LL == 2 * 1LL * i) {
nm = 1;
} else {
nm = j / 2 + 2;
}
idx++;
if (idx >= l && idx <= r) {
cout << nm << " ";
} else if (idx > r) {
goto end;
}
}
}
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
|
cpp
|
//Author Sumit Raj.
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back//_____standard_template____
#define bsdk ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); //___________program booster_________
#define pop pop_back
#define str string
#define endl "\n"
#define vec vector
#define m_p make_pair
#define mod 1000000007
#define modi 998244353
int i,j;
main()
{
bsdk
int t;
cin>>t;
while(t--)
{
int n,l,r,c1=0,c;
cin>>n>>l>>r;
int p=0,sm=0;
vector<int>ans;
if(r==(n*(n-1))+1)
c1=1;
for(i=n-1;i>=0;i--)
{
sm+=(2*i);
p++;
if(sm>l)
{
p--;
sm-=(2*i);
break;
}
}
p++;
int k=l-sm,cnt=0;
int s=p+(k/2)+1;
if(k%2==0)
{
if(k==0)
ans.pb(n);
else
ans.pb(p+(k/2));
cnt++;
s=p+(k/2)+1;
}
c=0;
for(i=p;i<n;i++)
{
for(j=s;j<=n;j++)
{
ans.pb(i);
cnt++;
if(cnt==r-l+1)
{
c=1;
break;
}
ans.pb(j);
cnt++;
if(cnt==r-l+1)
{
c=1;
break;
}
}
s=i+2;
if(c==1)
break;
}
if(c1==1)
{
ans.pb(1);
cnt++;
}
//cout<<cnt<<endl;
for(i=0;i<ans.size();i++)
cout<<ans[i]<<" ";
cout<<endl;
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
cpp
|
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#define fastio cin.tie(0); ios::sync_with_stdio(0);
#define multitc int _t; cin>>_t; while(_t--)
#define arrin(arr, n, type) arr.assign(n,type()); for(auto& i : arr) cin>>i;
#define all(x) (x).begin(), (x).end()
const int dir[9][2] = {{-1,0},{0,1},{1,0},{0,-1},{1,1},{-1,-1},{1,-1},{-1,1},{0,0}};
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll INF = 1e9+7;
const ll MOD = 998244353;
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
int nextInt(){int x; cin>>x; return x;}
ll nextLong(){ll x; cin>>x; return x;}
template<typename T>
void arrin2d(vector<vector<T>>& arr, int y, int x)
{
arr.assign(y,vector<T>(x));
for(int i=0;i<y;++i)
{
for(int j=0;j<x;++j)
{
cin>>arr[i][j];
}
}
}
//using template
//code goes here
ll n, l, r;
void print_segment(int num, int start, int end)
{
int len = (num-1)*2;
for(int i=start;i<=end;++i)
{
if(i % 2 == 1)
{
cout<<num<<' ';
}
else
{
cout<<i/2+1<<' ';
}
}
}
int main()
{
fastio;
multitc
{
cin>>n>>l>>r;
int nroot = 2;
pair<int,int> left = {-1,-1}, right;
for(int i=1;i<=n+1;++i)
{
if(i * 2 >= l && left.first == -1)
{
left = {nroot,(l-1) % (i*2)};
}
if(i * 2 >= r)
{
right = {nroot,(r-1)%(i*2)};
break;
}
l-=i*2;
r-=i*2;
++nroot;
}
if(left.first == right.first)
{
print_segment(left.first,left.second,right.second);
}
else
{
print_segment(left.first,left.second,(left.first-1)*2-1);
for(int i=left.first+1;i<right.first;++i)
{
print_segment(i,0,(i-1)*2-1);
}
print_segment(right.first,0,right.second);
}
cout<<'\n';
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
java
|
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
int t=s.nextInt();
StringBuilder sb=new StringBuilder();
for(int i=0;i<t;i++)
{
int n=s.nextInt();
long l=s.nextLong();
long r=s.nextLong();
int start=0;
long left1=0;
int end=0;
long left2=0;
int count=0;
int block=0;
while(count<l&&block<n)
{
block++;
count=count+2*(n-block);
}
start=block;
left1=count-2*(n-block);
count=0;
block=0;
while(count<r&&block<n)
{
block++;
count=count+2*(n-block);
}
end=block;
left2=count;
ArrayList<Integer> list=new ArrayList<>();
for(int j=start;j<=end;j++)
{
fill(list,j,n);
}
int cc=0;
for(long j=left1+1;j<=left2;j++)
{
if(j>=l&&j<=r)
{
sb.append(list.get((int)(j-(left1+1)))+" ");
cc++;
}
}
if(cc==r-l+1)
{
sb.append("\n");
}
else
{
sb.append(1+"\n");
}
}
System.out.println(sb);
}
public static void fill(ArrayList<Integer> list,int start,int n)
{
int c=start+1;
for(int i=0;i<2*(n-start);i++)
{
if(i%2==0)
{
list.add(start);
}
else
{
list.add(c);
c++;
}
}
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
java
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.StringTokenizer;
public class d {
public static void main(String[] args) {
FS in = new FS(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
while(t-->0) {
long n = in.nextInt();
long l = in.nextLong()-1;
long r = in.nextLong();
for(; l < 2*n-3; l++) {
if(l%2 == 0) out.print("1 ");
else out.print((l+3)/2 + " ");
}
long curr = 2*n-3;
for(int i = 2; i < n; i++) {
out.flush();
long tmp = curr+2*(n-i);
for(long j = l-curr; l < Math.min(tmp, r+1); j++, l++) {
if(j == 0) out.print(n + " ");
else if(j%2 == 1) out.print(i + " ");
else out.print(i+j/2 + " ");
}
}
if(l <= n*(n-1) && r >= n*(n-1)) out.print(n + " ");
if(r == n*(n-1)+1) out.print("1 ");
out.println();
}
out.close();
}
static class FS {
BufferedReader in;
StringTokenizer token;
public FS(InputStream str) {
in = new BufferedReader(new InputStreamReader(str));
}
public String next() {
if(token == null || !token.hasMoreElements()) {
try {
token = new StringTokenizer(in.readLine());
} catch (IOException ex) {
}
return next();
}
return token.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
const long long inf = 2e18;
const long long mod1 = 998244353;
const long long mod = 1e9 + 7;
void solve() {
long long n, l, r;
cin >> n >> l >> r;
long long lo = 0, hi = n;
while (lo <= hi) {
long long mid = (lo + hi) / 2;
long long now = mid * (2 * n - mid - 1);
if (now <= l)
lo = mid + 1;
else
hi = mid - 1;
}
long long layer = lo - 1;
long long sum = layer * (2 * n - layer - 1);
long long curr = l - sum;
long long thislayer = 2 * (n - layer - 1);
while (l <= r) {
if (l == n * (n - 1) + 1)
cout << 1 << " ";
else if (curr % 2)
cout << layer + 1 << " ";
else
cout << layer + 1 + curr / 2 << " ";
curr++;
l++;
if (curr > thislayer) {
curr = 1;
layer++;
thislayer = 2 * (n - layer - 1);
}
}
cout << '\n';
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) solve();
return 0;
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
java
|
import java.util.*;
import java.io.*;
public class Solution{
public static class pair{
int x;
int y;
}
public static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
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());
}
public int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) {
a[i]=nextInt();
}
return a;
}public double nextDouble() {
return Double.parseDouble(next());
}
}
public static void main(String[] args) throws IOException{
FastScanner fs=new FastScanner();
int t=fs.nextInt();
PrintWriter out=new PrintWriter(System.out);
while(t-->0){
int n=fs.nextInt();
long l=fs.nextLong();
long r=fs.nextLong();
long sum=0;
long use=1;
int ln=-1,rn=-1;
boolean lb=false,rb=false;
long lsum=0;
long rsum=0,plsum=0,prsum=0;
for(int i=1;i<=n;i++){
sum+=use;
if(!lb&&l<=sum){
ln=i;
lsum=use;
plsum=sum-use;
lb=true;
}
if(!rb&&r<=sum){
rn=i;
rsum=use;
rb=true;
prsum=sum-use;
break;
}
if(use==1){
use=2;
}else{
use+=2;
}
}
// System.out.println(ln+" "+rn);
if(ln==rn){
ArrayList<Long> list=new ArrayList<>();
l=l-plsum;
long lu=0;
long inc=2;
r=r-prsum;
for(int i=1;i<=lsum;i++){
if(i%2!=0){
lu=ln;
}else{
if(inc==ln){
inc=1;
}
lu=inc;
inc++;
}
if(l<=i&&r>=i){
list.add(lu);
}
}
for(int i=0;i<list.size();i++){
System.out.print(list.get(i)+" ");
}
System.out.println();
}else{
ArrayList<Long> list=new ArrayList<>();
l=l-plsum;
long lu=0;
long inc=2;
for(int i=1;i<=lsum;i++){
if(i%2!=0){
lu=ln;
}else{
if(inc==ln){
inc=1;
}
lu=inc;
inc++;
}
if(l<=i){
list.add(lu);
}
}
// System.out.println(list);
for(int j=ln+1;j<rn;j++){
if(lsum==1){
lsum=2;
}else{
lsum+=2;
}
lu=0;
inc=2;
for(int i=1;i<=lsum;i++){
if(i%2!=0){
lu=j;
}else{
if(inc==j){
inc=1;
}
lu=inc;
inc++;
}
list.add(lu);
}
}
r=r-prsum;
lu=0;
inc=2;
for(int i=1;i<=rsum;i++){
if(i%2!=0){
lu=rn;
}else{
if(inc==rn){
inc=1;
}
lu=inc;
inc++;
}
if(r>=i){
list.add(lu);
}else{
break;
}
}
for(int i=0;i<list.size();i++){
System.out.print(list.get(i)+" ");
}
System.out.println();
}
}
out.close();
}
public static void dfs(HashMap<Integer,ArrayList<Integer>> map,int r,ArrayList<Integer> end,int c){
if(map.get(r).size()==0){
end.add(c);
return;
}
ArrayList<Integer> l=map.get(r);
for(int i=0;i<l.size();i++){
dfs(map,l.get(i),end,c+1);
}
}
public static String com(String s1,String s2){
if(s1.compareTo(s2)>0){
return s1;
}else{
return s2;
}
}
public static void fost(HashMap<Integer,ArrayList<Integer>> map,int n,int n1){
ArrayList<Integer> s=map.get(n);
// System.out.println(s);
for(int i=0;i<s.size();i++){
if(s.get(i)==n1){
s.remove(i);
break;
}
}
// System.out.println(s);
for(int i=0;i<s.size();i++){
fost(map,s.get(i),n);
}
}
public static long calc(long n,long b){
if(b==1){
return Long.MAX_VALUE;
}
long val=(long)Math.ceil(n/b);
long p=2;
long ans=val;
while(val!=0){
val=(long)Math.ceil((long)n/(long)Math.pow(b,p));
p++;
ans+=val;
}
return ans;
}
public static long quala(long b){
long val=(long)Math.ceil(Math.pow(1+(8*b),0.5));
if(val%2==0){
long va=(long)(2+val)/(long)2;
return va;
}else{
long va=(long)(1+val)/(long)2;
return va;
}
}
public static String find(int a,int b){
if(a==3){
if(b==1){
return "abb";
}else if(b==2){
return "bab";
}else{
return "bba";
}
}
int v=((a-1)*(a-2))/2;
if(b<=v){
String s=find(a-1,b);
StringBuffer sb=new StringBuffer(s);
int diff=a-s.length();
while(diff-->0){
sb.insert(0,"a");
}
return sb.toString();
}else{
int diff=b-v;
StringBuffer sb=new StringBuffer();
sb.append("b");
for(int i=0;i<a-diff-1;i++){
sb.append("a");
}
sb.append("b");
for(int i=0;i<diff-1;i++){
sb.append("a");
}
return sb.toString();
}
// return new String("a"+s);
}
public static long z(long val){
long p=1;
while(val!=0){
long rem=val%10;
p*=rem;
val=val/10;
}
return p;
}
public static int[] soe(int n){
int[] arr=new int[n];
arr[0]=0;
for(int i=1;i<n;i++){
if(arr[i]==0){
for(int j=(2*(i+1))-1;j<n;j=j+i+1){
arr[j]=1;
}
}
}
return arr;
}
public static int[][] floydWarshall(int graph[][],int V){
int dist[][] = new int[V][V];
int i, j, k;
for (i = 0; i < V; i++){
for (j = 0; j < V; j++){
dist[i][j] = graph[i][j];
}
}
for (k = 0; k < V; k++) {
for (i = 0; i < V; i++){
for (j = 0; j < V; j++){
if (dist[i][k] + dist[k][j] < dist[i][j]){
dist[i][j] = dist[i][k] + dist[k][j];
}
}
}
}
return dist;
}
public static class Comp implements Comparator<pair>{
public int compare(pair a,pair b){
if(a.x!=b.x){
return b.x-a.x;
}else{
return a.y-b.y;
}
}
}
public static long gcd(long a,long b){
if (b == 0)
return a;
return gcd(b, a % b);
}
public static int lcm(int a,int b){
int x=Math.max(a,b);
int y=Math.min(a,b);
long ans=x;
while(ans%y!=0){
ans+=x;
}
if(ans>Integer.MAX_VALUE){
return -1;
}
return (int)ans;
}
public static long fact(int n){
long ans=1;
for(int i=1;i<=n;i++){
ans*=i;
}
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
|
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()
if l == n*(n-1)+1:
print(1)
return
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 and i < n*(n-1):
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>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
long long pows(long long a, long long b) {
long long res = 1;
while (b > 0) {
if (b & 1) res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
long long powm(long long x, long long y, long long m = 1000000007) {
x = x % m;
long long res = 1;
while (y) {
if (y & 1) res = res * x;
res %= m;
y = y >> 1;
x = x * x;
x %= m;
}
return res;
}
long long modInverse(long long a, long long m = 1000000007) {
if (m == 1) return 0;
long long m0 = m, y = 0, x = 1;
while (a > 1) {
long long q = a / m, t = m;
m = a % m, a = t;
t = y;
y = x - q * y;
x = t;
}
if (x < 0) x += m0;
return x;
}
vector<long long> par(5005), sizes(5005);
long long find_par(long long x) {
if (x == par[x]) {
return x;
}
return (par[x] = find_par(par[x]));
}
void union_sets(long long a, long long b) {
a = find_par(a);
b = find_par(b);
if (a != b) {
if (sizes[a] < sizes[b]) {
swap(a, b);
}
sizes[a] += sizes[b];
par[b] = a;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long T;
cin >> T;
while (T--) {
long long n, m, i, j, k, x, y, z, t, e, f, p, q, g, l, r, w, h,
count1 = 0, prod = 1, a, b, c, d, index, x1, x2, y1, y2, diff, ans = 0,
sum = 0, sum1 = 0, sum2 = 0, flag = 0, flag1 = 0, flag2 = 0;
string s, s1, s2;
cin >> n >> l >> r;
sum = 0;
k = 1;
if (l == r && l == (n * (n - 1) + 1)) {
cout << "1\n";
continue;
}
while (sum + 2 * (n - k) < l) {
sum += 2 * (n - k);
k++;
}
long long start, cur;
if (l % 2 == 1) {
start = k;
x = k + (l - sum + 1) / 2;
cur = l;
} else {
cout << k + (l - sum + 1) / 2 << " ";
if (k + (l - sum + 1) / 2 == n) {
start = k + 1;
x = start + 1;
} else {
start = k;
x = k + (l - sum + 1) / 2 + 1;
}
cur = l + 1;
}
a = 0;
while (cur <= r) {
if (a % 2 == 0) {
cout << start << " ";
} else {
cout << x << " ";
x++;
}
if (x == n + 1) {
start++;
x = start + 1;
}
if (start == n) {
start = 1;
}
cur++;
a++;
}
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
|
python2
|
rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
def solve(N, L, R):
L -= 1; R -= 1
left = 0
nxt = 1
k = 1
while left + nxt <= L:
left += nxt
k += 1
if nxt == 1:
nxt = 2
else:
nxt += 2
# start writing from k
def write(k):
if k == 1:
bns.append(1)
return
if k == 2:
bns.append(2)
bns.append(1)
return
for j in range(2, k):
bns.append(k)
bns.append(j)
bns.append(k)
bns.append(1)
return
bns = []
while len(bns) < (R - left + 1):
write(k)
k += 1
return bns[L - left: R - left + 1]
for tc in xrange(rri()):
ans = solve(*rrm())
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
|
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;
}
}
long pos=totalElements+1;
for(int b=blockNumber;b<n;b++){
for(int i=b+1;i<=n;i++){
int currNumber=b;
if(pos==r && r==1L*n*(n-1)+1)
{
out.print("1 ");
pos++;
break;
}
if(pos>=l && pos<=r){
out.print(currNumber+" ");
}
pos++;
currNumber=i;
if(pos==r && r==1L*n*(n-1)+1)
{
out.print("1 ");
pos++;
break;
}
if(pos>=l && pos<=r){
out.print(currNumber+" ");
}
pos++;
}
if(pos>r){
break;
}
}
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;
int t;
long long n, l, r, c, o = 1, two = 2, cc;
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
cin >> t;
while (t--) {
cin >> n >> l >> r;
c = (n - o) * two;
long long d = r - l + o;
cc = 1;
l--;
while (l >= c) {
l -= c;
c -= two;
cc++;
if (c == 0 && l == 0) break;
}
for (cc; cc < n && d > 0; cc++) {
for (int j = 0, id = cc; j < c && d > 0; j++) {
if (j % 2) {
id++;
}
if (j < l) continue;
if (j % 2)
cout << id << " ";
else
cout << cc << " ";
d--;
}
l = 0;
}
if (d) 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
|
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
N, l, r = map(int, input().split())
tt = 0
y = 0
x = 0
for i in range(N):
tt += (N - i - 1) * 2
if tt < l:
x = i
y = tt
table = []
ttt = r - y
ttt -= (tt < ttt)
if l > tt:
print(1)
continue
while len(table) < ttt:
for i in range(x + 1, N):
table.append(x + 1)
table.append(i + 1)
x += 1
table.append(1)
#print(table, x, y)
print(*table[l - y - 1: r - y])
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
java
|
import java.util.*;
import java.io.*;
import java.time.Period;
public class Main {
public static void main(String[] args) throws Exception {
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
long l=sc.nextLong();
long r=sc.nextLong();
int number =2;
int i=1;
while(l-i*2>0) {
number++;
l-=i*2;
r-=i*2;
i++;
}
for(;l<=r;l++) {
if(l%2==0) {
pw.print(number);
}else {
pw.print((l+1)/2);
}
if(l!=r) {
pw.print(" ");
}
if(l-i*2>=0) {
l-=i*2;
r-=i*2;
i++;
number++;
}
}
pw.println();
}
pw.close();
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public long[] nextLongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public int[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public Integer[] nextIntegerArray(int n) throws IOException {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public boolean ready() throws IOException {
return br.ready();
}
}
static class pair implements Comparable<pair> {
double x;
double y;
public pair(int x, int y) {
this.x = x;
this.y = y;
}
public String toString() {
return x + " " + y;
}
public boolean equals(Object o) {
if (o instanceof pair) {
pair p = (pair)o;
return p.x == x && p.y == y;
}
return false;
}
public int hashCode() {
return new Double(x).hashCode() * 31 + new Double(y).hashCode();
}
public int compareTo(pair other) {
if (this.x == other.x) {
return (int) (this.y - other.y);
} else {
return (int) (this.x - other.x);
}
}
}
static class tuble implements Comparable<tuble> {
int x;
int y;
int z;
public tuble(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public String toString() {
return x + " " + y + " " + z;
}
public int compareTo(tuble other) {
if (this.x == other.x) {
return this.y - other.y;
} else {
return this.x - other.x;
}
}
}
public static long GCD(long a, long b) {
if (b == 0)
return a;
if (a == 0)
return b;
return (a > b) ? GCD(a % b, b) : GCD(a, b % a);
}
public static long LCM(long a, long b) {
return a * b / GCD(a, b);
}
static long Pow(long a, int e, int mod) // O(log e)
{
a %= mod;
long res = 1;
while (e > 0) {
if ((e & 1) == 1)
res = (res * a) % mod;
a = (a * a) % mod;
e >>= 1;
}
return res;
}
static long nc(int n, int r) {
if (n < r)
return 0;
long v = fac[n];
v *= Pow(fac[r], mod - 2, mod);
v %= mod;
v *= Pow(fac[n - r], mod - 2, mod);
v %= mod;
return v;
}
public static boolean isprime(long a) {
if (a == 0 || a == 1) {
return false;
}
if (a == 2) {
return true;
}
for (int i = 2; i < Math.sqrt(a) + 1; i++) {
if (a % i == 0) {
return false;
}
}
return true;
}
public static boolean isPal(String s) {
boolean t = true;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) != s.charAt(s.length() - 1 - i)) {
t = false;
break;
}
}
return t;
}
public static long RandomPick(long[] a) {
int n = a.length;
int r = rn.nextInt(n);
return a[r];
}
public static int RandomPick(int[] a) {
int n = a.length;
int r = rn.nextInt(n);
return a[r];
}
public static void PH(String s, boolean reverse) {
prelen = s.length();
HashsArray[HashsArrayInd] = new int[prelen + 1];
prepow = new int[prelen];
if (HashsArrayInd == 0) {
int[] mods = { 1173017693, 1173038827, 1173069731, 1173086977, 1173089783, 1173092147, 1173107093,
1173114391, 1173132347, 1173144367, 1173150103, 1173152611, 1173163993, 1173174127, 1173204679,
1173237343, 1173252107, 1173253331, 1173255653, 1173260183, 1173262943, 1173265439, 1173279091,
1173285331, 1173286771, 1173288593, 1173298123, 1173302129, 1173308827, 1173310451, 1173312383,
1173313571, 1173324371, 1173361529, 1173385729, 1173387217, 1173387361, 1173420799, 1173421499,
1173423077, 1173428083, 1173442159, 1173445549, 1173451681, 1173453299, 1173454729, 1173458401,
1173459491, 1173464177, 1173468943, 1173470041, 1173477947, 1173500677, 1173507869, 1173522919,
1173537359, 1173605003, 1173610253, 1173632671, 1173653623, 1173665447, 1173675577, 1173675787,
1173684683, 1173691109, 1173696907, 1173705257, 1173705523, 1173725389, 1173727601, 1173741953,
1173747577, 1173751499, 1173759449, 1173760943, 1173761429, 1173762509, 1173769939, 1173771233,
1173778937, 1173784637, 1173793289, 1173799607, 1173802823, 1173808003, 1173810919, 1173818311,
1173819293, 1173828167, 1173846677, 1173848941, 1173853249, 1173858341, 1173891613, 1173894053,
1173908039, 1173909203, 1173961541, 1173968989, 1173999193};
mod = RandomPick(mods);
int[] primes = { 59, 61, 67, 71, 73, 79, 83, 89, 97, 101 };
prime = RandomPick(primes);
}
prepow[0] = 1;
if (!reverse) {
for (int i = 1; i < prelen; i++) {
prepow[i] = (int) ((1l * prepow[i - 1] * prime) % mod);
}
for (int i = 0; i < prelen; i++) {
if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z')
HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i]
+ ((1l * s.charAt(i) - 'a' + 1) * prepow[i]) % mod) % mod);
else
HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i]
+ ((1l * s.charAt(i) - 'A' + 27) * prepow[i]) % mod) % mod);
}
} else {
for (int i = 1; i < prelen; i++) {
prepow[i] = (int) ((1l * prepow[i - 1] * prime) % mod);
}
for (int i = 0; i < prelen; i++) {
if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z')
HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i]
+ ((1l * s.charAt(i) - 'a' + 1) * prepow[prelen - 1 - i]) % mod) % mod);
else
HashsArray[HashsArrayInd][i + 1] = (int) ((1l * HashsArray[HashsArrayInd][i]
+ ((1l * s.charAt(i) - 'A' + 27) * prepow[prelen - 1 - i]) % mod) % mod);
}
}
HashsArrayInd++;
}
public static int PHV(int l, int r, int n, boolean reverse) {
if (l > r) {
return 0;
}
int val = (int) ((1l * HashsArray[n - 1][r] + mod - HashsArray[n - 1][l - 1]) % mod);
if (!reverse) {
val = (int) ((1l * val * prepow[prelen - l]) % mod);
} else {
val = (int) ((1l * val * prepow[r - 1]) % mod);
}
return val;
}
static int[][] HashsArray;
static int HashsArrayInd = 0;
static int[] prepow;
static int prelen = 0;
static int prime = 31;
static long fac[];
static int mod = 998244353;
static Random rn = new Random();
static Scanner sc = new Scanner(System.in);
static PrintWriter pw = new PrintWriter(System.out);
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
python3
|
import sys
input=sys.stdin.readline
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
def main():
t=int(input())
for _ in range(t):
n,l,r=map(int,input().split())
Ans=query(n,l,r)
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
|
java
|
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.List;
import java.util.*;
public class realfast implements Runnable
{
private static final int INF = (int) 1e9;
long in= (long)Math.pow(10,9)+7;
long fac[]= new long[3000];
public void solve() throws IOException
{
int t = readInt();
for(int f =0;f<t;f++)
{
int n = readInt();
long l = readLong();
Long r = readLong();
long start =1;
if(l==1)
out.print(1+" ");
for(int i=2;i<=n;i++)
{
if(r<=start)
break;
long len = 2*(i-1);
start++;
long end = len-1+ start;
if(l>end)
{
start=end;
}
else
{
long tl = l-start;
long tr = r - start;
tl =Math.max(tl,0);
tr = Math.min(tr,len-1);
for(long j=tl;j<=Math.min(tr,len-3);j++)
{
if(j%2==0)
out.print(i+" ");
else
{
long count =j/2;
out.print((2+count)+" ");
}
}
if(len-2>=tl&&len-2<=tr)
out.print(i+" ");
if(len-1>=tl&&len-1<=tr)
out.print(1+" ");
start=end;
}
}
out.println();
}
}
public long pow(long n , long p,long m)
{
if(p==0)
return 1;
long val = pow(n,p/2,m);;
val= (val*val)%m;
if(p%2==0)
return val;
else
return (val*n)%m;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
new Thread(null, new realfast(), "", 128 * (1L << 20)).start();
}
private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
private BufferedReader reader;
private StringTokenizer tokenizer;
private PrintWriter out;
@Override
public void run() {
try {
if (ONLINE_JUDGE || !new File("input.txt").exists()) {
reader = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
} else {
reader = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
}
solve();
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
try {
reader.close();
} catch (IOException e) {
// nothing
}
out.close();
}
}
private String readString() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
@SuppressWarnings("unused")
private int readInt() throws IOException {
return Integer.parseInt(readString());
}
@SuppressWarnings("unused")
private long readLong() throws IOException {
return Long.parseLong(readString());
}
@SuppressWarnings("unused")
private double readDouble() throws IOException {
return Double.parseDouble(readString());
}
}
class edge implements Comparable<edge>{
int u ;
int v ;
int val;
edge(int u1, int v1 , int val1)
{
this.u=u1;
this.v=v1;
this.val=val1;
}
public int compareTo(edge e)
{
return this.val-e.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
|
python3
|
res = [1]
s = 1
for i in range(10**5+2):
s+=2*(i+1)
res.append(s)
def binaryS(x,n):
lo = 0
hi = n+1
while lo<hi:
mid = (lo+hi)//2
midval = res[mid]
if midval<x:
lo = mid+1
elif midval>x:
hi = mid
else:
return mid
return lo
#print(binaryS(10,4),binaryS(13,4),binaryS(15,4))
for lo in range(int(input())):
n,l,r = map(int,input().split())
key = binaryS(l,n)
st = key
ans = []
if (res[key]==l):
st = key+1
ans.append(1)
l=l+1
m = l - res[st-1]
st+=1
t = (m+1)//2+1
if t==st:
nxt = 1
else:
nxt = t
for i in range(l,r+1):
#print(nxt,st)
if(i%2==0):
ans.append(st)
else:
ans.append(nxt)
if(nxt==1):
st = st+1
nxt = 2
elif(nxt==st-1):
nxt=1
else:
nxt+=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
|
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;
public class x1334D
{
public static void main(String omkar[]) throws Exception
{
BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(infile.readLine());
int T = Integer.parseInt(st.nextToken());
StringBuilder sb = new StringBuilder();
outer:while(T-->0)
{
st = new StringTokenizer(infile.readLine());
int N = Integer.parseInt(st.nextToken());
long L = Long.parseLong(st.nextToken());
long R = Long.parseLong(st.nextToken());
long val = 0L;
for(int i=1; i < N; i++)
{
if(val+2*(N-i) >= L)
{
long startdex = val+1;
R -= startdex;
L -= startdex;
ArrayList<Integer> ls = new ArrayList<Integer>();
ls.add(i);
int next = i+1;
for(int a=1; a < 2*(N-i); a++)
{
if(a%2 == 1)
ls.add(next++);
else
ls.add(i);
}
int boof = i;
while(boof+1 < N && ls.size() <= R)
{
ls.add(boof+1);
next = boof+2;
for(int a=1; a < 2*(N-boof-1); a++)
{
if(a%2 == 1)
ls.add(next++);
else
ls.add(boof+1);
}
}
if(boof+1 >= N)
ls.add(1);
//print
for(int a = (int)L; a <= R; a++)
sb.append(ls.get(a)+" ");
sb.append("\n");
continue outer;
}
else
val += 2*(N-i);
}
sb.append("1\n");
}
System.out.print(sb);
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
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 < r - l + 1; 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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author sumit
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
DMinimumEulerCycle solver = new DMinimumEulerCycle();
solver.solve(1, in, out);
out.close();
}
static class DMinimumEulerCycle {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int t = in.nextInt();
while (t-- > 0) {
int n = in.nextInt();
long l = in.nextLong();
long r = in.nextLong();
StringBuilder str = new StringBuilder();
long[] sum = new long[n];
sum[0] = 2 * (n - 1);
int mm = 1;
for (int i = 1; i < n; i++) {
int xx = n - mm;
sum[i] = sum[i - 1] + 2 * xx;
mm++;
}
while (l <= r) {
if (l == (1L * n * (n - 1) + 1)) {
str.append("1 ");
} else {
int start = 0;
int end = n - 1;
int ans = -1;
while (start <= end) {
int mid = (start + end) / 2;
if (sum[mid] < l) {
start = mid + 1;
} else if (sum[mid] >= l) {
ans = mid;
end = mid - 1;
}
}
long l1 = l;
if (ans > 0)
l = l - sum[ans - 1];
String ss = "";
if (l % 2 == 1) {
ss = (1 + ans) + " ";
} else {
ss = (1 + ans + l / 2) + " ";
}
str.append(ss);
l = l1;
}
l++;
}
out.printLine(str.toString());
}
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void printLine(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
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 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 & 15;
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sign = 1;
if (c == '-') {
sign = -1;
c = read();
}
long result = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
result *= 10;
result += c & 15;
c = read();
} while (!isSpaceChar(c));
return result * sign;
}
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -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 get_even(long long mid) {
long long cnt = 2 * mid;
long long odd = (cnt / 2) * (cnt / 2);
long long even = cnt * (cnt + 1) / 2 - odd;
return even;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
long long n, l, r;
cin >> n >> l >> r;
long long low = 1, high = 2e9;
while (low < high) {
long long mid = (low + high) / 2;
long long even = get_even(mid);
if (even + 1 >= l)
high = mid;
else
low = mid + 1;
}
long long need = r - l + 1;
long long cur = get_even(low - 1);
if (l > 1) {
cur++;
} else {
cout << 1 << ' ';
need--;
}
l -= cur;
r -= cur;
long long elem = low + 1;
long long blocks = (l - 1) / 2;
if ((l - 1) % 2) {
if (blocks + 2 == elem)
cout << 1 << ' ';
else
cout << 2 + blocks << ' ';
need--;
blocks++;
}
while (need > 0) {
for (long long j = 2 + blocks; j <= elem; j++) {
cout << elem << ' ';
need--;
if (need == 0) break;
if (j == elem)
cout << 1 << ' ';
else
cout << j << ' ';
need--;
if (need == 0) break;
}
elem++;
blocks = 0;
}
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>
struct fst {
int f, s, n;
bool t;
fst(int f, int s, int n, bool t) : f(f), s(s), t(t), n(n){};
void increment() {
if (t == 0) {
t = 1;
} else {
s++;
t = 0;
}
if (s > n) {
f++;
if (f >= n) {
f = 1;
};
s = f + 1;
}
}
void out() { std::cout << (t ? s : f) << " "; }
};
int main() {
int t;
std::cin >> t;
for (int i = 0; i < t; i++) {
long long int n, l, r, ind, f, s;
bool t;
std::cin >> n;
std::cin >> l;
std::cin >> r;
if (l != (n * (n - 1) + 1)) {
t = (l + 1) % 2;
f = ((2 * n - 1) - sqrt((2 * n - 1) * (2 * n - 1) - 4 * l)) / 2 + 1;
ind = l - (f - 1) * n - f * (f - 1) / 2;
s = (ind + 1) / 2 + f;
fst frst(f, s, n, t);
while (l <= r) {
frst.out();
frst.increment();
l++;
}
std::cout << std::endl;
} else {
std::cout << 1 << std::endl;
}
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
java
|
// package CodeForces;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;
public class EducationalRound85D {
public static void solve() {
int t = s.nextInt();
while(t-- > 0) {
int n = s.nextInt();
long l = s.nextLong();
long r = s.nextLong();
ArrayList<Integer> ranges = new ArrayList<Integer>();
int temp = n - 1;
while(temp > 0) {
ranges.add(2 * temp - 1);
ranges.add(1);
temp--;
}
long sum = 0;
int idx = 0;
for(int i = 0; i < ranges.size(); i++) {
if(sum + ranges.get(i) < l) {
sum += ranges.get(i);
idx++;
}else {
break;
}
}
int times = (int)(r - l + 1);
ArrayList<Integer> ans = new ArrayList<Integer>();
if(idx == ranges.size()) {
out.println(1);
continue;
}
int offset = 0;
if(idx%2 == 1) {
ans.add(n);
times--;
idx++;
}else {
offset = (int)(l - sum);
}
while(idx < ranges.size() && times > 0) {
if(idx%2 == 1) {
ans.add(n);
times--;
idx++;
offset = 1;
continue;
}
int start = offset;
int curr_mid = idx/2 + 1;
while(start <= ranges.get(idx) && times > 0) {
if(start%2 == 1) {
ans.add(curr_mid);
}else {
ans.add(curr_mid + start/2);
}
times--;
start++;
}
idx++;
}
if(times == 1) {
ans.add(1);
}
for(Integer x : ans) {
out.print(x + " ");
}
out.println();
}
}
public static void main(String[] args) {
new Thread(null, null, "Thread", 1 << 27) {
public void run() {
try {
out = new PrintWriter(new BufferedOutputStream(System.out));
s = new FastReader(System.in);
solve();
out.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}.start();
}
public static PrintWriter out;
public static FastReader s;
public static class FastReader {
private InputStream stream;
private byte[] buf = new byte[4096];
private int curChar, snumChars;
public FastReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (snumChars == -1) {
throw new InputMismatchException();
}
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException E) {
throw new InputMismatchException();
}
}
if (snumChars <= 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 number = 0;
do {
number *= 10;
number += c - '0';
c = read();
} while (!isSpaceChar(c));
return number * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
long sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long number = 0;
do {
number *= 10L;
number += (long) (c - '0');
c = read();
} while (!isSpaceChar(c));
return number * sgn;
}
public int[] nextIntArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = this.nextInt();
}
return arr;
}
public long[] nextLongArray(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = this.nextLong();
}
return arr;
}
public String next() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndofLine(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public boolean isEndofLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
}
|
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, n);
int xr = getSeq(r, n);
long next = l - (2 * n - 1) * (xl - 1) + (xl - 1) * (xl - 1) - 1;
for (int i = xl; i <= xr; i++)
{
long max = Math.min(r - (2 * n - 1) * (i - 1) + (i - 1) * (i - 1), 2 * (n - i));
for (long j = next; j < max; j++)
{
if (j % 2 == 0) System.out.print(i + " ");
else System.out.print(i + j / 2 + 1 + " ");
}
next = 0;
}
if (r == (long) (n - 1) * n + 1) System.out.print(1);
System.out.println();
}
}
public static int getSeq(long l, int n)
{
return (int) Math.floor(0.5d * (2 * n - 1 - Math.sqrt((2 * n - 1) * (2 * n - 1) - 4 * l))) + 1;
}
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
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
const int mods = 998244353;
const int maxn = 1e5 + 10;
const int N = 1e5 + 10;
const int E = 2e5 + 10;
long long n, l, r;
long long k[maxn];
vector<int> ans;
int main() {
int T;
cin >> T;
while (T--) {
cin >> n >> l >> r;
for (int i = 1; i <= (n - 1); ++i) {
k[i] = k[i - 1] + 2 * (n - i);
}
k[n] = k[n - 1] + 1;
long long bo = lower_bound(k + 1, k + n + 1, l + 1) - k;
if (bo > n) {
printf("1\n");
continue;
}
long long pc = k[bo - 1] + 1;
long long tot = 1;
long long tmp;
ans.clear();
while (pc <= r) {
if (bo == n) {
ans.push_back(1);
break;
}
if (pc % 2 == 1)
tmp = bo;
else {
tmp = bo + tot;
tot++;
}
if (pc >= l) ans.push_back(tmp);
pc++;
if (tmp == n) {
bo++;
tot = 1;
}
}
for (int i = 0; i <= (ans.size() - 1); ++i) {
cout << ans[i] << " ";
}
cout << endl;
}
}
|
1334_D. Minimum Euler Cycle
|
You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1.
|
{
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
}
|
{
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
}
|
IN-CORRECT
|
cpp
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
map<pii, ll> memo;
set<ll> st;
map<ll, ll> cnts;
ll dp(ll a, ll b) {
if (st.find(a + b) == st.end() || cnts[a + b] == 0) return 2;
if (a == 0 && b == 0) return cnts[0];
cnts[a + b]--;
return 1 + dp(b, a + b);
cnts[a + b]++;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin >> n;
ll a[n];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n; i++) {
ll x = a[i];
st.insert(x);
if (cnts.find(x) == cnts.end()) cnts[x] = 0;
cnts[x]++;
}
ll out = 0;
for (int diff = 1; diff < n; diff++) {
for (int i = 0; i < n; i++) {
cnts[a[i]]--;
cnts[a[(i + diff) % n]]--;
out = max(out, dp(a[i], a[(i + diff) % n]));
cnts[a[i]]++;
cnts[a[(i + diff) % n]]++;
}
}
cout << out << 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>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long i, j, k, n, l, r, t;
cin >> t;
while (t--) {
cin >> n >> l >> r;
i = 2;
while ((i * (i - 1)) < l) i++;
while (l <= r) {
j = l - ((i - 1) * (i - 2));
if ((j) % 2 == 0) {
cout << i << " ";
l++;
j = l - ((i - 1) * (i - 2));
if (((j + 1) / 2) == i) i++;
} else {
cout << ((j + 1) / 2) << " ";
l++;
}
}
cout << "\n";
}
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.