Codeforces Round #576 (Div. 2) | CF1199 Supplement

Keywords: PHP iOS

A. City Day Is it troublesome to use the st table//

Then O(1) queries the minimum number of X before this number and the minimum number of y after this number, noting that the boundary and x, y are zero.

 1 #include<bits/stdc++.h>
 2 #include<iostream>
 3 #include<stack>
 4 #include<algorithm>
 5 #include<cstdio>
 6 #include<cmath>
 7 #include<cstring>
 8 #define mem(a) memset(a,0,sizeof(a))
 9 #define memm(a) memset(a,inf,sizeof(a))
10 #define ll long long
11 #define ld long double
12 #define uL unsigned long long
13 #define pb push_back
14 #define inf 0x3f3f3f3f
15 using namespace std;
16 const int N=1e5+5;
17 const int M=100+5;
18 int n,m,k,a[N],b[N],x,y;
19 int cnt,sum,mx,st[N][25];
20 void findm()
21 {
22     for(int i=0;i<n;i++) {st[i][0]=a[i];}
23     for(int j=1;j<25;j++)
24         for(int i=0;i<n;i++)
25            if(i+(1<<(j-1))<n)
26              st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]);
27 }
28 int query(int l,int r)
29 {
30     if(l>r) return inf;
31     int len=log2(r-l+1);
32     return min(st[l][len],st[r-(1<<len)+1][len]);
33 }
34 int main()
35 {
36     cin>>n>>x>>y;
37     for(int i=0;i<n;i++)
38         cin>>a[i];
39     findm();
40     for(int i=0;i<n;i++)
41     {
42         if(query(max(0,i-x),max(0,i-1))>a[i] || i==0)
43         {
44             if((a[i]<query(min(n-1,i+1),min(n-1,i+y)))||i==n-1)
45             {
46                 cout<<i+1<<endl;
47                 return 0;
48             }
49         }
50     }
51     return 0;
52 }
CF1199 A

B. Water Lily

It's foolish to make several mistakes on double, and I didn't see the waist at first. It's even more foolish.

CF1199 B

C. MP3  

// I don't know if it's too much trouble to think about. It's more than 800 hours. Let's see later - "Okay, with fio, it's from 800 to 200 orz.

First judge whether it is satisfied or not, then find the critical point, move the logarithmic function (remember to subtract the number of species), and then enumerate l to get the minimum number of consumption d (sort a, the number before l + the number after r).

tips: 1. Save the subscripts of the first number of each number with v, in order of a before that. (2) Read the questions carefully and pick them up (whine)

 1 #include<bits/stdc++.h> 
 2 #define fio ios::sync_with_stdio(false);cin.tie(0) 
 3 #define ll long long 
 4 #define pb push_back
 5 #define inf 0x3f3f3f3f
 6 using namespace std;
 7 const int N=4e5+5; 
 8 int n,m,I,k,a[N],b[N],mx,x,y,ans;
 9 vector<int>v;
10 int f(int l,int r)
11 {
12      if(l>r) return inf;
13      if(r==v.size()-1) return v[l]-1;
14      return v[l]+n-v[r+1];
15 
16 }
17 int quickpow(int a,int n)
18 {
19     int ans=1;
20     while(n)
21     {
22         if(n&1) ans*=a;
23         n>>=1;
24         a*=a;
25     }
26     return ans;
27 }
28 int inter(int m)
29 {
30    return (log2(m)!=int(log2(m)))?log2(m)+1:log2(m);
31 }
32 int main()
33 {
34     fio;
35     cin>>n>>I;
36     I*=8;
37     for(int i=1;i<=n;i++)
38       cin>>a[i];
39     sort(a+1,a+n+1);
40     int now=-1,id=0;
41     for(int i=1;i<=n;i++)
42     {
43         if(a[i]!=now)
44         {
45            id=i;
46            now=a[i];
47            v.pb(id);
48         }
49     }
50     k=v.size();
51     ans=(inter(k)*n)-I;
52     if(ans<=0)
53     {
54         cout<<0<<endl;
55         return 0;
56     }
57     int need=inf;
58     ans=k-quickpow(2,I/n);
59     for(int i=0;i<=ans;i++)
60        need=min(f(i,k-ans+i-1),need);
61     cout<<need<<endl;
62     return 0;
63 }
CF1199 C

Posted by jcantrell on Tue, 30 Jul 2019 23:19:48 -0700