forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathI.cpp
More file actions
63 lines (54 loc) · 1.23 KB
/
I.cpp
File metadata and controls
63 lines (54 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <bits/stdc++.h>
using namespace std;
struct SegmentTree
{
int low, mid, high, value;
SegmentTree *l, *r;
SegmentTree(int low, int high): low(low), high(high)
{
mid = (low + high) / 2;
value = 0;
if (low == high) return;
l = new SegmentTree(low , mid);
r = new SegmentTree(mid + 1, high);
}
void update(int x, int v)
{
if (low == high) value = v;
else
{
if (x <= mid) l -> update(x, v);
else r -> update(x, v);
value = min(l -> value, r -> value);
}
}
int get(int x)
{
if (low == high) return low;
if (l -> value < x) return l -> get(x);
return r -> get(x);
}
};
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, id[300300], num;
cin >> n;
SegmentTree *tree = new SegmentTree(1, n);
vector <int> a(n + 1, 1), prev(n + 1, 0);
for (int i = 1; i <= n; i++)
{
if (prev[i])
a[i] = tree -> get(prev[i]);
tree -> update(a[i], i);
cin >> num;
for (int j = 0; j < num; j++)
cin >> id[j];
sort(id, id + num);
for (int j = 0; j < num; j++)
if (!prev[id[j]] && i + 1 < id[j])
prev[id[j]] = i + 1;
cout << a[i] << ' ';
}
}