【Codeforces 356A】Knight Tournament
【链接】 我是链接,点我呀:)
【题意】
【代码】
import java.io.*;
import java.util.*;
public class Main {
static InputReader in;
static PrintWriter out;
public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
}
static int N = (int)3e5;
static class Task{
int n,m;
int nex[],f[],ans[];
int ff(int x) {
if (x==f[x]) return x;
else {
f[x] = ff(f[x]);
return f[x];
}
}
public void solve(InputReader in,PrintWriter out) {
nex = new int[N+10];f = new int[N+10];ans = new int[N+10];
for (int i = 1;i <= N;i++) {
nex[i] = i + 1;
f[i] = i;
}
n = in.nextInt();m = in.nextInt();
for (int i = 1;i <= m;i++) {
int li,ri,xi;
li = in.nextInt();ri = in.nextInt();xi = in.nextInt();
for (int j = li;j <= ri;) {
int fa = ff(j);
f[fa] = xi;
ans[fa] = xi;
int temp = nex[j];
nex[j] = ri+1;
j = temp;
}
}
for (int i = 1;i <= n;i++) {
if (ans[i]==i)
out.print(0);
else
out.print(ans[i]);
out.print(" ");
}
}
}
static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer;
public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
}
public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}