牛牛与比赛颁奖 ###K

题目链接:https://ac.nowcoder.com/acm/contest/9982/G

思路: 扫描线思想, 左端点排序  维护sum来统计 当前通过 sum题的有多少人     [l,r]都为贡献1  r+1 才消去贡献 (记右端点要r+1才能合理消去 类似差分)

用cnt 数组存 过cnt[i] 题的人 最后将cnt数组 后缀和 变为 cnt[i] 至少通过i题的人 然后模拟即可  

把排名转换成过题的人数即可

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int maxn=1e5+10;
 4 const int mod=1e9+7;
 5 #define ll long long
 6 #define pi pair<int,int>
 7 #define fi first
 8 #define sc second
 9 #define pb push_back
10 pi a[maxn*2];
11 int cnt[maxn];
12 
13 
14 int main()
15 {
16     ios::sync_with_stdio(0);
17     cin.tie(0);
18     int n,m;
19     cin>>n>>m;
20     int tot=0;
21     for(int i=0;i<m;i++)
22     {
23         int l,r;
24         cin>>l>>r;
25         a[++tot]={l,1};
26         a[++tot]={r+1,-1};
27     }
28     sort(a+1,a+1+tot);
29     int sum=1;
30     for(int i=2;i<=tot;i++)
31     {
32         int len=a[i].fi-a[i-1].fi;
33         cnt[sum]+=len;
34         sum+=a[i].sc;
35     }
36 
37     int au=(n+10-1)/10,ag=(n+4-1)/4,cu=(n+2-1)/2;
38     int x=-1,y=-1,z=-1;
39     for(int i=m;i>=0;i--)
40     {
41         cnt[i]+=cnt[i+1];
42         if(x==-1&&cnt[i]>=au) x=i;
43         if(y==-1&&cnt[i]>=ag) y=i;
44         if(z==-1&&cnt[i]>=cu) z=i;
45     }
46     x=max(x,1);
47     y=max(y,1);
48     z=max(z,1);
49 
50     cout<<cnt[x]<<" "<<cnt[y]-cnt[x]<<" "<<cnt[z]-cnt[y]<<'\n';
51 
52 
53 
54 
55 
56 
57 
58 
59 }
View Code

 

posted @ 2021-02-11 14:38  canwinfor  阅读(94)  评论(0)    收藏  举报