2017-10-25模拟赛

T1 任务安排

容易发现 ans一定在0到min(s[i],t[i]) 的范围内,二分这个最早时间,按着完成工作、

 1 #include <algorithm>
 2 #include <cstdio>
 3 
 4 inline void read(int &x)
 5 {
 6     x=0; register char ch=getchar();
 7     for(; ch>'9'||ch<'0'; ) ch=getchar();
 8     for(; ch>='0'&&ch<='9'; ch=getchar()) x=x*10+ch-'0';
 9 }
10 const int N(100005);
11 struct Work {
12     int t,s;
13     bool operator < (const Work&x)const
14     {
15         if(s==x.s) return t<x.t;
16         return s<x.s;
17     }
18 }job[N];
19 
20 int ans=-1,L,R,Mid,n;
21 inline bool check(int x)
22 {
23     for(int i=1; i<=n; ++i)
24     {
25         if(x+job[i].t>job[i].s) return 0;
26         x+=job[i].t;
27     }
28     return 1;
29 }
30 
31 int Presist()
32 {
33     freopen("manage.in","r",stdin);
34     freopen("manage.out","w",stdout);
35     
36     read(n);
37     for(int t,i=1; i<=n; ++i)
38         read(job[i].t),read(job[i].s);
39     std::sort(job+1,job+n+1);
40     for(R=job[1].s-job[1].t+1; L<=R; )
41     {
42         Mid=L+R>>1;
43         if(check(Mid))
44         {
45             ans=Mid;
46             L=Mid+1;
47         }
48         else R=Mid-1;
49     }
50     printf("%d\n",ans);
51     return 0;
52 }
53 
54 int Aptal=Presist();
55 int main(int argc,char**argv){;}
AC

貌似可以直接贪心过。。

 

 

 

 T2 小 a 的强迫症

处理个数前缀和sum[i],对于第i个珠子对答案的贡献为C(sum[i]-1,num[i]-1),乘法原理统计ans

 1 #include <cstdio>
 2 
 3 #define LL long long
 4 
 5 inline void read(int &x)
 6 {
 7     x=0; register char ch=getchar();
 8     for(; ch>'9'||ch<'0'; ) ch=getchar();
 9     for(; ch>='0'&&ch<='9'; ch=getchar()) x=x*10+ch-'0';
10 }
11 const int mod(998244353);
12 const int MAX(500005);
13 const int N(100005);
14 int num[N],sum[N];
15 LL jc[MAX];
16 
17 inline LL Pow(LL a,LL b)
18 {
19     LL ret=1;
20     for(; b; b>>=1,a=(a%mod)*(a%mod)%mod)
21         if(b&1) ret=(ret%mod)*(a%mod)%mod;
22     return ret%mod;
23 }
24 
25 inline LL C(int a,int b)
26 {
27     return jc[a]%mod*Pow(jc[b],mod-2)%mod*Pow(jc[a-b],mod-2)%mod;
28 }
29 
30 int Presist()
31 {
32     freopen("qiang.in","r",stdin);
33     freopen("qiang.out","w",stdout);
34     
35     int n; read(n);    jc[0]=1;
36     for(int i=1; i<=n; ++i)
37         read(num[i]),sum[i]=sum[i-1]+num[i];
38     for(int i=1; i<=sum[n]; ++i)
39         jc[i]=jc[i-1]%mod*i%mod%mod;
40     LL ans=1;
41     for(int i=2; i<=n; ++i)
42         ans=ans%mod*C(sum[i]-1,num[i]-1)%mod;
43     printf("%I64d\n",ans);
44     return 0;
45 }
46 
47 int Aptal=Presist();
48 int main(int argc,char**argv){;}
AC

 

 

 

 

 

 T3 函数求和

 

 1 #include <cstdio>
 2 
 3 #define LL long long
 4 
 5 inline void read(int &x)
 6 {
 7     x=0; register char ch=getchar();
 8     for(; ch>'9'||ch<'0'; ) ch=getchar();
 9     for(; ch>='0'&&ch<='9'; ch=getchar()) x=x*10+ch-'0';
10 }
11 const int N(1e5+5);
12 int a[N],L[N],R[N],sum[N];
13 
14 struct Tree {
15     int l,r;
16     LL  sum;
17     bool flag;
18 }tr[2][N<<2];
19 
20 #define lc (now<<1)
21 #define rc (now<<1|1)
22 
23 void Tree_push(int now)
24 {
25     tr[0][lc].flag+=tr[0][now].flag;
26     tr[0][lc].sum+=tr[0][now].flag;
27     tr[0][rc].flag+=tr[0][now].flag;
28     tr[0][rc].sum+=tr[0][now].flag;
29     tr[0][now].flag=0;
30 }
31 
32 void Tree_change(int now,int to,int x)
33 {
34     if(tr[0][now].l==tr[0][now].r)
35     {
36         tr[0][now].sum=x;
37         tr[0][now].flag+=x;
38         return ;
39     }
40     if(tr[0][now].flag) Tree_push(now);
41     int mid=tr[0][now].l+tr[0][now].r>>1;
42     if(to<=mid) Tree_change(lc,to,x);
43     else if(to>mid) Tree_change(rc,to,x);
44     tr[0][now].sum=tr[0][lc].sum+tr[0][rc].sum;
45 }
46 
47 LL Tree_query(int now,int l,int r,int op)
48 {
49     if(tr[op][now].l==l&&tr[op][now].r==r) return tr[op][now].sum;
50     int mid=tr[op][now].l+tr[op][now].r>>1;
51     if(r<=mid) return Tree_query(lc,l,r,op);
52     else if(l>mid) return Tree_query(rc,l,r,op);
53     else return Tree_query(lc,l,mid,op)+Tree_query(rc,mid+1,r,op);
54 }
55 
56 void Tree_build(int now,int l,int r,int op)
57 {
58     tr[op][now].l=l,tr[op][now].r=r;
59     if(l==r)
60     {
61         if(!op) tr[op][now].sum=a[l];
62         else tr[op][now].sum=Tree_query(1,L[l],R[l],0);
63         tr[op][now].flag=0; return ;
64     }
65     int mid=tr[op][now].l+tr[op][now].r>>1;
66     Tree_build(lc,l,mid,op); Tree_build(rc,mid+1,r,op);
67     tr[op][now].sum=tr[op][lc].sum+tr[op][rc].sum;
68 }
69 
70 int Presist()
71 {
72     freopen("sum.in","r",stdin);
73     freopen("sum.out","w",stdout);
74     int n; read(n);
75     for(int i=1; i<=n; ++i) read(a[i]);
76     Tree_build(1,1,n,0);
77     for(int i=1; i<=n; ++i)
78         read(L[i]),read(R[i]);
79     Tree_build(1,1,n,1);
80     int q; read(q);
81     for(int op,l,r; q--; )
82     {
83         read(op),read(l),read(r);
84         if(op==1)
85         {
86             Tree_change(1,l,r);
87             Tree_build(1,1,n,1);
88         }
89         else printf("%I64d\n",Tree_query(1,l,r,1));
90     }
91     return 0;
92 }
93 
94 int Aptal=Presist();
95 int main(int argc,char**argv){;}
线段树20分暴力
  1 #include<cstdio>
  2 #include<cstring>
  3 #include<algorithm>
  4 #include<cmath>
  5 using namespace std;
  6 typedef unsigned long long LL;
  7 #define lowbit(x) ((x)&-(x))
  8 int n;
  9 int a[100005];
 10 LL c[100005];
 11 int L[100005],R[100005];
 12 int Q;
 13 int t[405][100005];
 14 int belong[100005];// (i-1)/B+1
 15 LL sum[405];
 16 int B,NUM;
 17 void add(int x,LL d){
 18     while(x<=n){
 19         c[x]+=d;
 20         x+=lowbit(x);
 21     }
 22 }
 23 LL ask(int x){
 24     LL ret=0;
 25     while(x){
 26         ret+=c[x];
 27         x-=lowbit(x);
 28     }
 29     return ret;
 30 }
 31 int main(){
 32     freopen("sum.in","r",stdin);
 33     freopen("sum.out","w",stdout);
 34     scanf("%d",&n);
 35     for(int i=1;i<=n;i++){
 36         scanf("%d",&a[i]);
 37     }
 38     for(int i=1;i<=n;i++){
 39         scanf("%d%d",&L[i],&R[i]);
 40     }
 41     B=sqrt(n)+1;
 42 //  printf("#%d\n",B);
 43     NUM=(n-1)/B+1;
 44     for(int i=1;i<=n;i++) belong[i]=(i-1)/B+1;
 45     for(int i=1;i<=n;i++) c[i]=a[i];
 46     for(int i=1;i<=n;i++){
 47         if(i+lowbit(i)<=n){
 48             c[i+lowbit(i)]+=c[i];
 49         }
 50     }
 51     for(int i=1;i<=n;i++){
 52         t[belong[i]][L[i]]++;
 53         t[belong[i]][R[i]+1]--;
 54     }
 55     for(int i=1;i<=NUM;i++){
 56         for(int j=1;j<=n;j++){
 57             t[i][j]+=t[i][j-1];
 58             sum[i]+=t[i][j]*1ULL*a[j];
 59         }
 60     }
 61     scanf("%d",&Q);
 62     while(Q--){
 63         int type,x,y;
 64         scanf("%d%d%d",&type,&x,&y);
 65         if(type==1){
 66             for(int i=1;i<=NUM;i++){
 67                 sum[i]-=t[i][x]*1ULL*a[x];
 68                 sum[i]+=t[i][x]*1ULL*y;
 69             }
 70             add(x,-a[x]);
 71             a[x]=y;
 72             add(x,a[x]);
 73         }else{
 74             int Ln,Rn;
 75             Ln=belong[x],Rn=belong[y];
 76             LL ans=0;
 77             if(Ln==Rn){
 78                 for(int i=x;i<=y;i++){
 79                     ans+=ask(R[i])-ask(L[i]-1);
 80                 }
 81             }else{
 82                 for(int i=Ln+1;i<Rn;i++) ans+=sum[i];
 83                 int lim;
 84                 lim=Ln*B;
 85                 lim=min(lim,y);
 86                 for(int i=x;i<=lim;i++){
 87                     ans+=ask(R[i])-ask(L[i]-1);
 88                 }
 89                 lim=(Rn-1)*B+1;
 90                 lim=max(lim,x);
 91                 for(int i=lim;i<=y;i++){
 92                     ans+=ask(R[i])-ask(L[i]-1);
 93                 }
 94             }
 95             printf("%I64d\n",ans);
 96         }
 97     }
 98     fclose(stdout);
 99     return 0;
100 }
std

 

posted @ 2017-10-25 14:30  Aptal丶  阅读(152)  评论(0编辑  收藏  举报