# Educational Codeforces Round 92 (Rated for Div. 2) 选讲

https://codeforces.ml/contest/1389/problem/F

 1 #include<bits/stdc++.h>
2 using namespace std;
3 #define LL long long
4
5 int n;
6 const int maxn=400011;
7
8 struct SEG
9 {
10     int l,r,t;
11     bool operator < (const SEG &b) const
12     {
13         return r<b.r;
14     }
15 }seg[maxn];
16 int lisa[maxn<<1],li=0;
17
18 int dp[maxn],contain[maxn];
20 struct SMT
21 {
22     SmtNode a[maxn<<2];
23     int n;
24     SMT() {n=0;}
25     void clear(int N) {n=N;}
26 //    int ls(int x) {return x<<1;}
27 //    int rs(int x) {return (x<<1)|1;}
28     #define ls(x) (x<<1)
29     #define rs(x) ((x<<1)|1)
30     void up(int x) {a[x].Max=max(a[ls(x)].Max,a[rs(x)].Max);}
33     void Insert(int x,int L,int R,int p,int v)
34     {
35         if (L==R) {a[x].Max=max(a[x].Max,v); return;}
36         down(x);
37         int mid=(L+R)>>1;
38         if (p<=mid) Insert(ls(x),L,mid,p,v);
39         else Insert(rs(x),mid+1,R,p,v);
40         up(x);
41     }
42     void insert(int p,int v) {Insert(1,0,n,p,v);}
43     int QPreMax(int x,int L,int R,int p)
44     {
45         if (R<=p) return a[x].Max;
46         down(x);
47         int mid=(L+R)>>1;
48         if (p<=mid) return QPreMax(ls(x),L,mid,p);
49         return max(QPreMax(ls(x),L,mid,p),QPreMax(rs(x),mid+1,R,p));
50     }
51     int qPreMax(int p) {return QPreMax(1,0,n,p);}
52     void Add(int x,int L,int R,int ql,int qr,int v)
53     {
54         if (ql<=L && R<=qr) {addsingle(x,v); return;}
55         down(x);
56         int mid=(L+R)>>1;
59         up(x);
60     }
62 }s[2];
63
64 int main()
65 {
66     scanf("%d",&n);
67     for (int i=1;i<=n;i++)
68     {
69         scanf("%d%d%d",&seg[i].l,&seg[i].r,&seg[i].t);
70         seg[i].t--;
71         lisa[++li]=seg[i].l;
72         lisa[++li]=seg[i].r;
73     }
74     sort(lisa+1,lisa+1+li); li=unique(lisa+1,lisa+1+li)-lisa-1;
75     for (int i=1;i<=n;i++)
76     {
77         seg[i].l=lower_bound(lisa+1,lisa+1+li,seg[i].l)-lisa;
78         seg[i].r=lower_bound(lisa+1,lisa+1+li,seg[i].r)-lisa;
79     }
80     sort(seg+1,seg+1+n);
81 //    for (int i=1;i<=n;i++) cout<<"NO"<<i<<' '<<seg[i].l<<' '<<seg[i].r<<' '<<seg[i].t<<endl;
82
83     s[0].clear(li); s[1].clear(li);
84     dp[0]=0;
85     for (int i=1;i<=n;i++)
86     {
87         bool ty=seg[i].t;
88         dp[i]=s[ty^1].qPreMax(seg[i].l-1)+1;
89         s[ty].insert(seg[i].r,dp[i]);
91 //        cout<<i<<' '<<dp[i]<<endl;
92     }
93
94     int ans=0;
95     for (int i=1;i<=n;i++) ans=max(ans,dp[i]);
96     printf("%d\n",ans);
97     return 0;
98 }
View Code

 1 #include<bits/stdc++.h>
2 using namespace std;
3 #define LL long long
4
5 int n;
6 struct SEG{int l,r;};
7 vector<SEG> seg[2];
8 multiset<int> s;
9
10 int main()
11 {
12     scanf("%d",&n);
13     for (int i=1,l,r,t;i<=n;i++)
14     {
15         scanf("%d%d%d",&l,&r,&t);
16         seg[t-1].push_back((SEG){l,r});
17     }
18     sort(seg[0].begin(),seg[0].end(),[](SEG a,SEG b) {return a.r<b.r;});
19     sort(seg[1].begin(),seg[1].end(),[](SEG a,SEG b) {return a.l<b.l;});
20
21 //    cout<<endl;
22     unsigned int j=0,ans=n;
23     for (SEG x:seg[0])
24     {
25         while (j<seg[1].size() && seg[1][j].l<=x.r) s.insert(seg[1][j].r),j++;
26         auto it=s.lower_bound(x.l);
27         if (it==s.end()) continue;
28 //        cout<<x.l<<' '<<x.r<<' '<<*it<<endl;
29         s.erase(it);
30         ans--;
31     }
32     printf("%d\n",ans);
33     return 0;
34 }
View Code

posted @ 2020-08-04 00:25  Blue233333  阅读(158)  评论(0编辑  收藏  举报