C. Vasya And Array
Vasya has an array
a
1
,
a
2
,
…
,
a
n
a_1,a_2,…,a_n
a1,a2,…,an.
You don’t know this array, but he told you
m
m
m facts about this array. The
i
−
t
h
i-th
i−th fact is a triple of numbers
t
i
t_i
ti,
l
i
l_i
li and
r
i
r_i
ri
(
0
≤
t
i
≤
1
,
1
≤
l
i
<
r
i
≤
n
)
(0\leq t_i\leq1,1\leq l_i<r_i\leq n)
(0≤ti≤1,1≤li<ri≤n) and it means:
if
t
i
=
1
t_i=1
ti=1 then subbarray
a
l
i
,
a
l
i
+
1
,
…
,
a
r
i
a_{l_i},a_{l_{i+1}},…,a_{r_i}
ali,ali+1,…,ari is sorted in non-decreasing order;
if
t
i
=
0
t_i=0
ti=0 then subbarray
a
l
i
,
a
l
i
+
1
,
…
,
a
r
i
a_{l_i},a_{l_{i+1}},…,a_{r_i}
ali,ali+1,…,ari is not sorted in non-decreasing order. A subarray is not sorted if there is at least one pair of consecutive elements in this subarray such that the former is greater than the latter.
For example if
a
=
[
2
,
1
,
1
,
3
,
2
]
a=[2,1,1,3,2]
a=[2,1,1,3,2] then he could give you three facts:
t
1
=
1
,
l
1
=
2
,
r
1
=
4
t_1=1,l_1=2,r_1=4
t1=1,l1=2,r1=4 (the subarray
[
a
2
,
a
3
,
a
4
]
=
[
1
,
1
,
3
]
[a_2,a_3,a_4]=[1,1,3]
[a2,a3,a4]=[1,1,3] is sorted),
t
2
=
0
,
l
2
=
4
,
r
2
=
5
t_2=0,l_2=4,r_2=5
t2=0,l2=4,r2=5 (the subarray
[
a
4
,
a
5
]
=
[
3
,
2
]
[a_4,a_5]=[3,2]
[a4,a5]=[3,2] is not sorted), and
t
3
=
0
,
l
3
=
3
,
r
3
=
5
t_3=0,l_3=3,r_3=5
t3=0,l3=3,r3=5 (the subarray
[
a
3
,
a
5
]
=
[
1
,
3
,
2
]
[a_3,a_5]=[1,3,2]
[a3,a5]=[1,3,2] is not sorted).
You don’t know the array ?. Find any array which satisfies all the given facts.
Input
The first line contains two integers
n
n
n and
m
m
m
(
2
≤
n
≤
1000
,
1
≤
m
≤
1000
)
(2\leq n\leq1000,1\leq m \leq1000)
(2≤n≤1000,1≤m≤1000).
Each of the next ? lines contains three integers
t
i
,
l
i
a
n
d
r
i
(
0
≤
t
i
≤
1
,
1
≤
l
i
<
r
i
≤
n
)
t_i, l_i\ and\ r_i (0\leq t_i\leq1,1\leq l_i<r_i\leq n)
ti,li and ri(0≤ti≤1,1≤li<ri≤n).
If
t
i
=
1
t_i=1
ti=1 then subbarray
a
l
i
,
a
l
i
+
1
,
…
,
a
r
i
a_{l_i},a_{l_{i+1}},…,a_{r_i}
ali,ali+1,…,ari is sorted. Otherwise (if
t
i
=
0
t_i=0
ti=0) subbarray
a
l
i
,
a
l
i
+
1
,
…
,
a
r
i
a_{l_i},a_{l_{i+1}},…,a_{r_i}
ali,ali+1,…,ari is not sorted.
Output
If there is no array that satisfies these facts in only line print N O NO NO (in any letter case).
If there is a solution, print Y E S YES YES (in any letter case). In second line print n n n integers a 1 , a 2 , … , a n ( 1 ≤ a i ≤ 1 0 9 ) a_1,a_2,…,a_n (1\leq a_i\leq10^9) a1,a2,…,an(1≤ai≤109) — the array a a a, satisfying all the given facts. If there are multiple satisfying arrays you can print any of them.
Examples
input
7 4
1 1 3
1 2 5
0 5 6
1 6 7
output
YES
1 2 2 3 5 4 4
input
4 2
1 1 4
0 2 3
output
NO
题意
- 就是构造一个长度为 n n n的数组,然后给出 m m m条描述条件,分为两种描述,一种是描述区间 [ l , r ] [l,r] [l,r]内的数单调不减,另一种描述 [ l , r ] [l,r] [l,r]内的数不是单调不减
题解
- 计需要构造的数组为 a a a,用 m a r k [ i ] mark[i] mark[i]表示 a [ i + 1 ] a[i+1] a[i+1]是否需要大于等于 a [ i ] a[i] a[i],当给出第一种描述时,位置 [ l , r − 1 ] [l,r-1] [l,r−1]内的位置的 m a r k mark mark值都要标记为 1 1 1,存下第二种描述,处理完第一种后,对于每一个第二种描述,检查 [ l , r − 1 ] [l,r-1] [l,r−1]内的 m a r k mark mark是否有 0 0 0的情况,显然,如果没有,这种描述是无解的, c h e c k check check所有第二种描述都没问题之后,另 a [ 1 ] = n a[1]=n a[1]=n,然后对于 1 ≤ i < n 1\leq i<n 1≤i<n,如果 m a r k [ i ] = 1 mark[i]=1 mark[i]=1,不妨令 a [ i + 1 ] = a [ i ] a[i+1]=a[i] a[i+1]=a[i],否则令 a [ i + 1 ] = a [ i ] − 1 a[i+1]=a[i]-1 a[i+1]=a[i]−1;
- 感觉典型
C
F
CF
CF题特点啊,想清楚代码很短,不想好直接写
F
S
T
FST
FST,
H
a
c
k
e
d
Hacked
Hacked,还贼长贼长,
这题列表全挂了
#include<bits/stdc++.h>
using namespace std;
const int maxn=1005;
int a[maxn][3],mark[maxn];
int main()
{
int n,m;scanf("%d %d",&n,&m);
for(int i=1,t,l,r;i<=m;i++){
scanf("%d %d %d",&a[i][0],&a[i][1],&a[i][2]);
if(a[i][0]) for(int j=a[i][1];j<a[i][2];j++) mark[j]=1;
}
for(int i=1;i<=m;i++){
bool ok=false;
if(!a[i][0]){
for(int j=a[i][1];j<a[i][2];j++){
if(!mark[j]) {ok=true;break;}
}
if(!ok) return printf("NO\n"),0;
}
}
int ans=n+1;
printf("YES\n");
for(int i=1;i<=n;i++) printf("%d%c",mark[i-1]?ans:--ans,i==n?'\n':' ');
}