2019杭电多校第三场

比赛总结

@辣鸡lfw,一开始算三角形那题没想到正解使用莫队乱搞,然后要选出50个最大的时候还用莫队。。。主席树区间第k大什么的完全忘记了

题解

1001 Another Chess Problem

unsolved

1002 Beauty Of Unimodal Sequence

unsolved

1003 Coefficient

unsolved

1004 Double Tree

unsolved

1005 Everything Is Generated In Equal Probability

 1 #include
 2 using namespace std;
 3 typedef long long ll;
 4 #define mod 998244353
 5 const int maxn=3000;
 6 const int maxm=3010;
 7 int n;
 8 ll sum,f[maxm],rav[maxm],b[maxm];
 9 ll Pow(ll x,int n)
10 {
11     ll ans=1;
12     while(n)
13     {
14         if(n&1)ans=ans*x%mod;
15         n>>=1;
16         x=x*x%mod;
17     }
18     return ans;
19 }
20 ll C(int a,int b){return (f[a]*rav[b]%mod)*rav[a-b]%mod;}
21 void Init()
22 {
23     sum=0; f[0]=rav[0]=1;
24     for(ll i=1;i<=maxn;i++)f[i]=f[i-1]*i%mod;
25     rav[maxn]=Pow(f[maxn],mod-2);
26     for(ll i=maxn-1;i;i--) rav[i]=rav[i+1]*(i+1)%mod;
27 }
28 /////////// 求组合数和逆元 
29 
30 int main()
31 { 
32     while(~scanf("%d",&n)) 
33     {
34         Init();
35         
36         ll r=Pow(4,mod-2),k,x,y;
37         for(ll i=2;i<=n;++i)
38         {
39             x=Pow(2,i);
40             y=Pow(Pow(2,i)-1,mod-2);
41             k=x*y%mod;
42             b[i]=k*((i*(i-1)%mod)*r%mod)%mod;
43             for(int j=0;jmod;
44             sum=(sum+b[i])%mod;
45         }
46         sum=sum*Pow(n,mod-2)%mod;
47         
48         printf("%lld\n",sum);
49     }
50     return 0;
51 }
View Code

1006 Fantastic Magic Cube

unsolved

1007 Game

unsolved

1008 Harmonious Army

题解:https://blog.csdn.net/baiyifeifei/article/details/97231963

 1 #include
 2 #define maxl 200010
 3 using namespace std;
 4  
 5 int n,q,cnt,tot;
 6 int a[maxl],num[maxl],rt[maxl];
 7 long long b[110];
 8 struct node
 9 {
10     int ls,rs,sum;
11 }tree[maxl*40];
12  
13 inline void insert(int num,int &x,int l,int r)
14 {
15     tree[++tot]=tree[x];x=tot;
16     ++tree[x].sum;
17     if(l==r) return;
18     int mid=(l+r)>>1;
19     if(num<=mid)
20         insert(num,tree[x].ls,l,mid);
21     else
22         insert(num,tree[x].rs,mid+1,r);
23 }
24  
25 inline int query(int i,int j,int k,int l,int r)
26 {
27     if(l==r)
28         return l;
29     int tp=tree[tree[j].ls].sum-tree[tree[i].ls].sum;
30     int mid=(l+r)>>1;
31     if(k<=tp) 
32         return query(tree[i].ls,tree[j].ls,k,l,mid);
33     else
34         return query(tree[i].rs,tree[j].rs,k-tp,mid+1,r);
35 }
36  
37 inline void prework()
38 {
39     for(int i=1;i<=n;i++)
40         scanf("%d",&a[i]),num[i]=a[i];
41     sort(num+1,num+1+n);
42     cnt=unique(num+1,num+1+n)-num-1;
43     for(int i=1;i<=n;i++)
44         a[i]=lower_bound(num+1,num+1+cnt,a[i])-num;
45     for(int i=0;i<=tot;i++)
46         tree[i].ls=tree[i].rs=tree[i].sum=0;
47     tot=0;
48     for(int i=1;i<=n;i++)
49         rt[i]=0;
50     for(int i=1;i<=n;i++)
51     {
52         rt[i]=rt[i-1];
53         insert(a[i],rt[i],1,cnt);
54     }
55 }
56  
57 inline void mainwork()
58 {
59     int l,r,up;
60     long long ans=0;
61     for(int i=1;i<=q;i++)
62     {
63         scanf("%d%d",&l,&r);
64         up=min(50,r-l+1);
65         for(int j=1;j<=up;j++)
66             b[j]=num[query(rt[l-1],rt[r],r-l+1-j+1,1,cnt)];
67         ans=-1;
68         for(int j=1;j<=up-2;j++)
69         if(b[j]1]+b[j+2])
70         {
71             ans=b[j]+b[j+1]+b[j+2];
72             break;
73         }
74         printf("%lld\n",ans);
75     }
76 }
77  
78 int main()
79 {
80     while(~scanf("%d%d",&n,&q))
81     {
82         prework();
83         mainwork();
84         //print();
85     }
86     return 0;
87 }
View Code

1009 I Love Palindrome String

 1 #include
 2 #define maxl 200010
 3 using namespace std;
 4  
 5 int n,q,cnt,tot;
 6 int a[maxl],num[maxl],rt[maxl];
 7 long long b[110];
 8 struct node
 9 {
10     int ls,rs,sum;
11 }tree[maxl*40];
12  
13 inline void insert(int num,int &x,int l,int r)
14 {
15     tree[++tot]=tree[x];x=tot;
16     ++tree[x].sum;
17     if(l==r) return;
18     int mid=(l+r)>>1;
19     if(num<=mid)
20         insert(num,tree[x].ls,l,mid);
21     else
22         insert(num,tree[x].rs,mid+1,r);
23 }
24  
25 inline int query(int i,int j,int k,int l,int r)
26 {
27     if(l==r)
28         return l;
29     int tp=tree[tree[j].ls].sum-tree[tree[i].ls].sum;
30     int mid=(l+r)>>1;
31     if(k<=tp) 
32         return query(tree[i].ls,tree[j].ls,k,l,mid);
33     else
34         return query(tree[i].rs,tree[j].rs,k-tp,mid+1,r);
35 }
36  
37 inline void prework()
38 {
39     for(int i=1;i<=n;i++)
40         scanf("%d",&a[i]),num[i]=a[i];
41     sort(num+1,num+1+n);
42     cnt=unique(num+1,num+1+n)-num-1;
43     for(int i=1;i<=n;i++)
44         a[i]=lower_bound(num+1,num+1+cnt,a[i])-num;
45     for(int i=0;i<=tot;i++)
46         tree[i].ls=tree[i].rs=tree[i].sum=0;
47     tot=0;
48     for(int i=1;i<=n;i++)
49         rt[i]=0;
50     for(int i=1;i<=n;i++)
51     {
52         rt[i]=rt[i-1];
53         insert(a[i],rt[i],1,cnt);
54     }
55 }
56  
57 inline void mainwork()
58 {
59     int l,r,up;
60     long long ans=0;
61     for(int i=1;i<=q;i++)
62     {
63         scanf("%d%d",&l,&r);
64         up=min(50,r-l+1);
65         for(int j=1;j<=up;j++)
66             b[j]=num[query(rt[l-1],rt[r],r-l+1-j+1,1,cnt)];
67         ans=-1;
68         for(int j=1;j<=up-2;j++)
69         if(b[j]1]+b[j+2])
70         {
71             ans=b[j]+b[j+1]+b[j+2];
72             break;
73         }
74         printf("%lld\n",ans);
75     }
76 }
77  
78 int main()
79 {
80     while(~scanf("%d%d",&n,&q))
81     {
82         prework();
83         mainwork();
84         //print();
85     }
86     return 0;
87 }
View Code

1010 Just Skip The Problem

就直接问n个2进制位上的数,由于有顺序,那么就是n!,对1e6+3取模,那就在外面预处理到1e6+3,之后都是0

 1 #include
 2 #define maxl 1000010
 3 using namespace std;
 4 
 5 const int mod=1e6+3;
 6 
 7 long long f[maxl]; 
 8 
 9 int main()
10 {
11     f[1]=1;
12     for(int i=2;i)
13         f[i]=(f[i-1]*i)%mod;
14     int n;
15     while(~scanf("%d",&n))
16     {
17         if(n>=mod)
18             puts("0");
19         else
20             printf("%lld\n",f[n]);
21     }
22     return 0;
23 }
View Code

1011 Keen On Everything But Triangle

题解:https://blog.csdn.net/liufengwei1/article/details/97324278

 1 #include
 2 #define maxl 200010
 3 using namespace std;
 4  
 5 int n,q,cnt,tot;
 6 int a[maxl],num[maxl],rt[maxl];
 7 long long b[110];
 8 struct node
 9 {
10     int ls,rs,sum;
11 }tree[maxl*40];
12  
13 inline void insert(int num,int &x,int l,int r)
14 {
15     tree[++tot]=tree[x];x=tot;
16     ++tree[x].sum;
17     if(l==r) return;
18     int mid=(l+r)>>1;
19     if(num<=mid)
20         insert(num,tree[x].ls,l,mid);
21     else
22         insert(num,tree[x].rs,mid+1,r);
23 }
24  
25 inline int query(int i,int j,int k,int l,int r)
26 {
27     if(l==r)
28         return l;
29     int tp=tree[tree[j].ls].sum-tree[tree[i].ls].sum;
30     int mid=(l+r)>>1;
31     if(k<=tp) 
32         return query(tree[i].ls,tree[j].ls,k,l,mid);
33     else
34         return query(tree[i].rs,tree[j].rs,k-tp,mid+1,r);
35 }
36  
37 inline void prework()
38 {
39     for(int i=1;i<=n;i++)
40         scanf("%d",&a[i]),num[i]=a[i];
41     sort(num+1,num+1+n);
42     cnt=unique(num+1,num+1+n)-num-1;
43     for(int i=1;i<=n;i++)
44         a[i]=lower_bound(num+1,num+1+cnt,a[i])-num;
45     for(int i=0;i<=tot;i++)
46         tree[i].ls=tree[i].rs=tree[i].sum=0;
47     tot=0;
48     for(int i=1;i<=n;i++)
49         rt[i]=0;
50     for(int i=1;i<=n;i++)
51     {
52         rt[i]=rt[i-1];
53         insert(a[i],rt[i],1,cnt);
54     }
55 }
56  
57 inline void mainwork()
58 {
59     int l,r,up;
60     long long ans=0;
61     for(int i=1;i<=q;i++)
62     {
63         scanf("%d%d",&l,&r);
64         up=min(50,r-l+1);
65         for(int j=1;j<=up;j++)
66             b[j]=num[query(rt[l-1],rt[r],r-l+1-j+1,1,cnt)];
67         ans=-1;
68         for(int j=1;j<=up-2;j++)
69         if(b[j]1]+b[j+2])
70         {
71             ans=b[j]+b[j+1]+b[j+2];
72             break;
73         }
74         printf("%lld\n",ans);
75     }
76 }
77  
78 int main()
79 {
80     while(~scanf("%d%d",&n,&q))
81     {
82         prework();
83         mainwork();
84         //print();
85     }
86     return 0;
87 }
View Code

 

1012 Longest Subarray

题解:https://blog.csdn.net/liufengwei1/article/details/97324937

 1 #include
 2 #define maxl 200010
 3 using namespace std;
 4  
 5 int n,q,cnt,tot;
 6 int a[maxl],num[maxl],rt[maxl];
 7 long long b[110];
 8 struct node
 9 {
10     int ls,rs,sum;
11 }tree[maxl*40];
12  
13 inline void insert(int num,int &x,int l,int r)
14 {
15     tree[++tot]=tree[x];x=tot;
16     ++tree[x].sum;
17     if(l==r) return;
18     int mid=(l+r)>>1;
19     if(num<=mid)
20         insert(num,tree[x].ls,l,mid);
21     else
22         insert(num,tree[x].rs,mid+1,r);
23 }
24  
25 inline int query(int i,int j,int k,int l,int r)
26 {
27     if(l==r)
28         return l;
29     int tp=tree[tree[j].ls].sum-tree[tree[i].ls].sum;
30     int mid=(l+r)>>1;
31     if(k<=tp) 
32         return query(tree[i].ls,tree[j].ls,k,l,mid);
33     else
34         return query(tree[i].rs,tree[j].rs,k-tp,mid+1,r);
35 }
36  
37 inline void prework()
38 {
39     for(int i=1;i<=n;i++)
40         scanf("%d",&a[i]),num[i]=a[i];
41     sort(num+1,num+1+n);
42     cnt=unique(num+1,num+1+n)-num-1;
43     for(int i=1;i<=n;i++)
44         a[i]=lower_bound(num+1,num+1+cnt,a[i])-num;
45     for(int i=0;i<=tot;i++)
46         tree[i].ls=tree[i].rs=tree[i].sum=0;
47     tot=0;
48     for(int i=1;i<=n;i++)
49         rt[i]=0;
50     for(int i=1;i<=n;i++)
51     {
52         rt[i]=rt[i-1];
53         insert(a[i],rt[i],1,cnt);
54     }
55 }
56  
57 inline void mainwork()
58 {
59     int l,r,up;
60     long long ans=0;
61     for(int i=1;i<=q;i++)
62     {
63         scanf("%d%d",&l,&r);
64         up=min(50,r-l+1);
65         for(int j=1;j<=up;j++)
66             b[j]=num[query(rt[l-1],rt[r],r-l+1-j+1,1,cnt)];
67         ans=-1;
68         for(int j=1;j<=up-2;j++)
69         if(b[j]1]+b[j+2])
70         {
71             ans=b[j]+b[j+1]+b[j+2];
72             break;
73         }
74         printf("%lld\n",ans);
75     }
76 }
77  
78 int main()
79 {
80     while(~scanf("%d%d",&n,&q))
81     {
82         prework();
83         mainwork();
84         //print();
85     }
86     return 0;
87 }
View Code

 

你可能感兴趣的:(2019杭电多校第三场)