2018-10-17多校连测2

T1

题意:

与[Usaco2017 Feb]Why Did the Cow Cross the Road相同,只是数据范围加大了,

将原来的n=2e4加到了2e5,很显然n^2的暴力会TLE,用set在longn时间内做完即可。

典型的贪心,以r为第一关键字,l为第二关键字从小到大排序。

 

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<iostream>
 5 #include<set>
 6 using namespace std;
 7 inline int read()
 8 {
 9     int x=0,w=1; char ch=getchar();
10     while (!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}
11     while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
12     return x*w;
13 }
14 const int N=200005;
15 int n,m;
16 multiset<int> s;
17 multiset<int>::iterator it;
18 struct note
19 {
20     int l,r;
21 }cow[N];
22 bool cmp (note a,note b){return a.r==b.r?a.l<b.l:a.r<b.r;}
23 int main()
24 {
25     freopen("dream.in","r",stdin);
26     freopen("dream.out","w",stdout);
27     n=read(),m=read();
28     for (int u=1;u<=m;u++)  cow[u].l=read(),cow[u].r=read();
29     for (int u=1;u<=n;u++)
30     {
31         int x=read();
32         s.insert(x);
33     }
34     sort(cow+1,cow+1+m,cmp);
35     int ans=0;
36     for (int u=1;u<=m;u++)
37     {
38         it=s.lower_bound(cow[u].l);
39         if (it!=s.end()&&*it<=cow[u].r)
40         {
41             ans++;
42             s.erase(it);
43         }
44     }
45     printf("%d\n",ans);
46     return 0;
47 }
View Code

 

posted @ 2018-10-17 19:56  Dingwenh  阅读(92)  评论(0编辑  收藏  举报