首页 > 代码库 > cf754 754D - Fedor and coupons

cf754 754D - Fedor and coupons

2个多小时,弱智了。。(连A都做不对,就不要做D了(迷))

 1 #include<bits/stdc++.h>
 2 #define lowbit(x) x&(-x) 
 3 #define LL long long 
 4 #define N 100005
 5 #define M 1000005
 6 #define mod 2147483648LL
 7 #define inf 0x7ffffffff
 8 using namespace std;
 9 inline int ra()
10 {
11     int x=0,f=1; char ch=getchar();
12     while (ch<0 || ch>9){if (ch==-) f=-1; ch=getchar();}
13     while (ch>=0 && ch<=9){x=x*10+ch-0; ch=getchar();}
14     return x*f;
15 }
16 int n,k;
17 struct node{
18     int x,y,id;
19 }a[N<<2];
20 bool cmp(node a, node b)
21 {
22     if (a.x==b.x) return a.y<b.y;
23     return a.x<b.x; 
24 }
25 int ans,cnt;
26 int b[N<<2],L,R;
27 set<pair<int , int > > q;
28 set<pair<int , int > >:: iterator it;
29 int main()
30 {
31     n=ra(); k=ra();
32     for (int i=1; i<=n; i++)
33         a[i].x=ra(),a[i].y=ra(),a[i].id=i;
34     sort(a+1,a+n+1,cmp);
35     if (n==1)//zz
36     {
37         cout<<a[1].y-a[1].x+1<<endl;
38         cout<<"1";
39         return 0;
40     }
41 //    for (int i=1; i<=n; i++)
42 //        printf("%d %d %d\n",a[i].x,a[i].y,a[i].id);
43     q.insert(make_pair(a[1].y,a[1].id));
44     for (int i=2; i<=n; i++)
45     {
46         pair<int , int > tmp,qwq;
47         tmp=*q.begin();
48         while (a[i].x>tmp.first && !q.empty()) 
49         {
50             q.erase(tmp);
51             tmp=*q.begin();
52         }
53         q.insert(make_pair(a[i].y,a[i].id));
54         if (q.size()>=k)
55         {
56             tmp=*q.begin();
57             if (ans<tmp.first-a[i].x+1) 
58             {
59                 cnt=0;
60                 ans=tmp.first-a[i].x+1;
61                 L=a[i].x;
62                 R=tmp.first;
63             }
64             q.erase(tmp); //这里比较有意思,这是最小的,只要记录的最小的是没有用了的,再加着反而会让结果变小 
65         }
66     }
67     cout<<ans<<endl;
68     if (ans==0)
69     {
70         for (int i=1; i<=k; i++) cout<<i<<" ";
71     }
72     else 
73     {
74         //cout<<L<<" "<<R<<endl;
75         for (int i=1; i<=n; i++)
76             if (L>=a[i].x && R<=a[i].y && k)    //tmd还能这么输出,真是尴尬啊、、、 
77                 cout<<a[i].id<<" ",k--;
78     }
79     return 0;
80 }    
81 //%%%%%%%%%%%%%%%%cf有数据就是好,面相数据编程233 

 

cf754 754D - Fedor and coupons