HZOJ 20190818 NOIP 24 analog solution to a problem

T1 string:

Bare Cartland number of questions, koala seniors talked about the original title, is bzoj3907 grid that question, and this question is simpler, do not even high-precision

Conclusion $ C_ {n + m} ^ {n} -C_ {n + m} ^ {n + 1} $ examination on cut 10min

 

 1 #include<bits/stdc++.h>
 2 #define int long long
 3 const int mod=20100403;
 4 const int N=2000006;
 5 using namespace std;
 6 int inv[N],fac[N];
 7 int qpow(int a,int b){
 8     int ans=1;
 9     while(b){
10         if(b&1) ans=ans*a%mod;
11         b>>=1;
12         a=a*a%mod;
13     }
14     return ans%mod;
15 }
16 int C(int n,int m){
17     return fac[n]%mod*inv[n-m]%mod*inv[m]%mod;
18 }
19 signed main(){
20     int n,m;
21     scanf("%lld%lld",&n,&m);
22     fac[0]=1;
23     for(int i=1;i<=n+m;++i) fac[i]=fac[i-1]*i%mod;
24     inv[m+n]=qpow(fac[m+n],mod-2);
25     for(int i=m+n;i>=1;--i) inv[i-1]=inv[i]*i%mod;
26     //inv[0]=1;
27     //for(int i=1;i<=m+n;++i) cout<<i<<" "<<inv[i]<<endl;
28     int ans=(C(n+m,n)%mod-C(m+n,n+1)%mod+mod)%mod;
29     printf("%lld",ans%mod);
30 }
T1

 

T2 Crow drink water:

Looks like this is a problem most difficult test of the bar, on the test due to the busy tone T3 no time to think, resulting in only called $ O (mn ^ 2) $ in Sibo violence, only took 25pts, even $ O (nm) $ violence did not think the results of the examination 3min shot a 50pts violence, a little mistake ah QAQ.

See the range of data we can guess this question should be positive solutions complexity level in $ O (nlog_2n) $ of

First, be sure to enumerate n, which means we have to get rid of enumeration m, we consider the contribution calculated separately for each bucket, you can calculate the number of times each bucket can be up to drink, then drink according to each point what sort of times that we deal with sequential scanning is front to back each bucket is drunk, we recorded a res represents the contribution of each bucket, when calculating the contribution of each point with the first point to be able to drink up subtracting the current number in the answer ans also divided by the current number of barrels and the rest, as it is to drink a bucket, all buckets must be a corresponding decline in the water level, and quite often able to drink the rest, all the rest to be shared equally buckets, but we noticed that he also may have remaining, so we put the remainder of the original sequence in front and did not compare now to sweep the barrels, if the remainder is large, then prove that this bucket of water to drink once again have a chance, otherwise It will not produce answers contribution, as to how to find the number in front of it you can use a number of maintenance Fenwick tree, then this problem is still more details, see the details or on behalf of It.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N=1e5+10;
 4 int a[N],w[N];
 5 struct node{
 6     int maxn,id;
 7 }wat[N];int n,m,x;
 8 int tr[N];
 9 bool cmp(node a,node b){
10     return (a.maxn==b.maxn)?a.id<b.id:a.maxn<b.maxn;
11 }
12 inline int lowbit(int x){return x&(-x);}
13 void add(int x,int val){
14     for(;x<=n;x+=lowbit(x)) tr[x]+=val;
15 }
16 int query(int x){
17     int ans=0;
18     for(;x;x-=lowbit(x)) ans+=tr[x];
19     return ans;
20 }
21 int main(){
22     scanf("%d%d%d",&n,&m,&x);
23     for(int i=1;i<=n;++i) scanf("%d",&w[i]);
24     for(int i=1;i<=n;++i) scanf("%d",&a[i]);
25     for(int i=1;i<=n;++i){
26         wat[i].maxn=(x-w[i])/a[i]+1;
27         wat[i].id=i;
28         add(i,1);
29     }
30     sort(wat+1,wat+n+1,cmp);
31     int ans=0;
32     int cnt=n;
33     for(int i=1;i<=n;++i){
34         add(wat[i].id,-1);
35         if(wat[i].maxn<=0) continue;
36         cnt=(wat[i].maxn-ans)/(n-i+1);
37         if(cnt>=m){ans+=m;continue;}
38         if(query(wat[i].id)<(wat[i].maxn-ans)%(n-i+1)) cnt++;
39         if(cnt>0) ans+=cnt;
40     }
41     printf("%d",ans);
42 }
T2

The camel door T3 King's Treasure:

Emergent's a question, and NOIP simulation 15 T2 bombing campaign that questions like, but this question is difficult to engage map building, a large data range $ O (n ^ 2) $ violence is certainly built drawing card, and then I how in the examination room like a long time to build map

, However SoftBrands topic people do not card, really open (f ×× k) heart (you) last out of time forced jb called blind violence build map, then transferred for a year, after just a sample then there is no time to think of the T2 and T3 happy to mention 10 points, good results again Sibo's mother expressed condolences to the topic .

Very simple, direct tarjan shrink point, DAG topology run on the way to update the answer.

Positive Solutions Built FIG door is to the same line cross-day direct compression point, the same column longitudinal atlas door direct the point, since you build door violence

 

  1 #include<bits/stdc++.h>
  2 using namespace std;
  3 const int N=100005;
  4 struct node{
  5     int x,y,opt;
  6 }t[N];
  7 int n,r,c;
  8 int du[N];
  9 int dx[10]={-1,-1,-1,0,0,1,1,1},dy[10]={-1,0,1,-1,1,-1,0,1};
 10 int first[5000005],nex[5000005],to[5000005],tot;
 11 vector<int> vx[N*10],vy[N*10];
 12 map<pair<int ,int> ,int> mp;
 13 void add(int a,int b){
 14     to[++tot]=b,nex[tot]=first[a],first[a]=tot;
 15 }
 16 int firstc[5000005],nexc[5000005],toc[5000005],totc;
 17 void add_c(int a,int b){
 18     toc[++totc]=b,nexc[totc]=firstc[a],firstc[a]=totc;
 19 }
 20 void init(){
 21     for(int i=1;i<=n;++i){
 22         if(t[i].opt==1){
 23             for(int j=0;j<(int)vx[t[i].x].size();++j){
 24                 if(i==vx[t[i].x][j]) continue;
 25                 add(i,vx[t[i].x][j]);
 26             }
 27         }
 28         else if(t[i].opt==2){
 29             for(int j=0;j<(int)vy[t[i].y].size();++j){
 30                 if(i==vy[t[i].y][j]) continue;
 31                 add(i,vy[t[i].y][j]);
 32             }
 33         }
 34         else{
 35             for(int j=0;j<8;++j){
 36                 int nx=t[i].x+dx[j],ny=t[i].y+dy[j];
 37                 if(nx<=0||ny<=0||nx>r||ny>c) continue;
 38                 if(!mp[make_pair(nx,ny)]) continue;
 39                 add(i,mp[make_pair(nx,ny)]);
 40             }
 41         }
 42     }
 43 }
 44 int dfn[5000005],low[5000005],ins[5000005],top,sta[5000005],res,big[5000005],num,bl[5000005];
 45 void tarjan(int x){
 46     dfn[x]=low[x]=++num;
 47     ins[x]=1,sta[++top]=x;
 48     for(int i=first[x];i;i=nex[i]){
 49         int y=to[i];
 50         if(!dfn[y]){
 51             tarjan(y);
 52             low[x]=min(low[x],low[y]);
 53         }
 54         else if(ins[y]) low[x]=min(low[x],dfn[y]);
 55     }
 56     if(dfn[x]==low[x]){
 57         int y;
 58         res++;
 59         do{
 60             y=sta[top--];
 61             ins[y]=0;
 62             big[res]++;
 63             bl[y]=res;
 64         }while(x!=y);
 65     }
 66 }
 67 queue<int> q;
 68 int ans[5000005];
 69 void topo(){
 70     for(int i=1;i<=res;++i){
 71         ans[i]=big[i];
 72         if(!du[i]){
 73             q.push(i);
 74         }
 75     }
 76     while(q.size()){
 77         int x=q.front();q.pop();
 78         for(int i=firstc[x];i;i=nexc[i]){
 79             int y=toc[i];
 80             ans[y]=max(ans[y],ans[x]+big[y]);
 81             du[y]--;
 82             if(!du[y]) q.push(y);
 83         }
 84     }
 85 }
 86 signed main(){
 87     scanf("%d%d%d",&n,&r,&c);
 88     for(int i=1;i<=n;++i){
 89         scanf("%d%d%d",&t[i].x,&t[i].y,&t[i].opt);
 90         mp[make_pair(t[i].x,t[i].y)]=i;
 91         vx[t[i].x].push_back(i);
 92         vy[t[i].y].push_back(i);
 93     }
 94     init();
 95     for(int i=1;i<=n;++i) if(!dfn[i]) tarjan(i);
 96     for(int i=1;i<=n;++i){
 97         for(int j=first[i];j;j=nex[j]){
 98             int y=to[j];
 99             if(bl[y]==bl[i]) continue;
100             add_c(bl[i],bl[y]);
101             du[bl[y]]++;
102         }
103     }
104     topo();
105     int ansss=0;
106     for(int i=1;i<=res;++i) ansss=max(ansss,ans[i]);
107     printf("%d",ansss);
108 }
T3

 

Guess you like

Origin www.cnblogs.com/leom10/p/11373865.html
Recommended