[CSP-S妯℃嫙娴嬭瘯96]棰樿В
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[CSP-S妯℃嫙娴嬭瘯96]棰樿В相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/printf' title='printf'>printf
鎯呭喌 璐績 tor 娴嬭瘯 ret size wap har浠ュ悗涓嶈兘鍐嶅€熸病鏀瑰畬棰樼殑鐞嗙敱涓嶅啓棰樿В浜?hellip;…
A.姹傚拰
姹?sum sum i+j-1$
鏌垮瓙灏变笉鍖栦簡鍚?hellip;…杩欏勾澶磒j閮戒笉鑰冭繖涔堝急鏅虹殑鍏紡鍖栫畝浜?hellip;…
鍧戠偣1锛氭ā鏁颁笉瀹氾紝鍙兘娌℃湁2鐨勯€嗗厓锛岄偅涔堝彧瑕佸厛鎶婁箻鏁伴噷鐨?鍘绘帀灏卞ソ浜嗐€?/span>
鍧戠偣2锛?e18鐐竘ong long $ ightarrow$ 鎱㈤€熶箻鍗冲彲
#include<cstdio> #include<iostream> #include<cstring> #include<vector> using namespace std; typedef long long ll; ll x,y,xx,yy,mod; ll mul(ll a,ll b) { ll res=0; while(b) { if(b&1)res+=a,res%=mod; a=(a+a)%mod; b>>=1; } return res; } vector<ll> fac; #define F int main() { #ifdef F freopen("sum.in","r",stdin); freopen("sum.out","w",stdout); #endif /*mod=1e9+7; cout<<mul(100000,3)<<endl;*/ scanf("%lld%lld%lld%lld%lld",&x,&y,&xx,&yy,&mod); int cnt=1; fac.push_back(x+xx); fac.push_back(xx-x+1); fac.push_back(yy-y+1); for(int i=0;i<3;i++) if(cnt&&fac[i]%2==0)fac[i]/=2,cnt--; ll ans=1; for(int i=0;i<3;i++) ans=mul(ans,fac[i]); fac.clear();cnt=1; fac.push_back(y+yy); fac.push_back(xx-x+1); fac.push_back(yy-y+1); for(int i=0;i<3;i++) if(cnt&&fac[i]%2==0)fac[i]/=2,cnt--; ll res=1; for(int i=0;i<3;i++) res=mul(res,fac[i]); (ans+=res)%=mod; ans-=mul(xx-x+1,yy-y+1)%mod; (ans+=mod)%=mod; printf("%lld ",ans); /*ans=(x+xx)*(xx-x+1)%mod*(yy-y+1)%mod*inv%mod; ans+=(xx-x+1)*(y+yy)%mod*(yy-y+1)%mod*inv%mod;ans%=mod; ans-=(xx-x+1)*(yy-y+1)%mod;ans=(ans+mod)%mod; printf("%lld ",ans);*/ return 0; }
B.鍒嗙粍閰嶅
鏄剧劧锛屾渶澶?$ imes$ 鏈€澶?+$ 绗簩澶?$ imes$ 绗簩澶?$+...$鐨勬柟寮忚兘浣垮皬缁勬€诲€兼渶澶с€?/span>
杩欓噷绠€鍗曞啓涓€涓嬭瘉鏄庯紝鑰冭檻鍙湁涓ゅ鐨勬儏鍐点€?/span>
璁惧畠浠负$a,b,a-x,b-y$锛屽洜涓哄疄鍔涘€间负姝f暣鏁版墍浠ュ繀鏈?a>x,b>y$
閭d箞鎸夋帓鍚嶉厤瀵圭殑鎬诲€间负$ab imes 2 -ay-bx+xy$
浜ゅ弶閰嶅鐨勪负$ab imes 2 -ay-bx$
寰堟樉鐒跺墠鑰呭ぇ浜庡悗鑰呫€?/span>
鎵€浠ュ彧瑕佽椽蹇冨湴寰€鍙虫壂锛屽埌涓嶈兘鍔犲叆缁勯噷鏃跺紑鏂扮粍灏卞ソ浜嗐€?/span>
鏆村姏鐨勮瘽姣忔閮絪ort鎴栦簩鍒嗘煡鎵捐偗瀹氭槸涓嶈鐨?/span>
鐢变簬寰€鍙虫墿灞曡繖涓繃绋嬪叿鏈夊崟璋冩€э紝鍙互鑰冭檻浜屽垎
浣哻heck涓€娆$殑浠d环涔熷緢澶э紝闇€瑕佽娉曞噺灏忎簩鍒嗚寖鍥?/span>
閭d箞鍙互鍏堝€嶅鍒颁竴涓笉鍚堟硶鐨勪綅缃紝鍐嶄互$1<<(p-1)$涓哄乏杈圭晫锛?1<<p$涓哄彸杈圭晫杩涜浜屽垎
鏃堕棿澶嶆潅搴︽渶鍔d负$O(n log^2 n)$銆?/span>
#include<cstdio> #include<iostream> #include<cstring> #include<vector> #include<algorithm> using namespace std; typedef long long ll; ll read() { ll x=0,f=1;char ch=getchar(); while(!isdigit(ch)){if(ch==鈥?鈥?f=-1;ch=getchar();} while(isdigit(ch))x=x*10+ch-鈥?鈥?ch=getchar(); return x*f; } const int N=5e5+5; int n; ll m; ll a[N],b[N]; vector<ll> nowa,nowb; bool check(int l,int r) { vector<ll> tmpa,tmpb; swap(nowa,tmpa);swap(nowb,tmpb); for(int i=l;i<=r;i++) nowa.push_back(a[i]),nowb.push_back(b[i]); sort(nowa.begin(),nowa.end());sort(nowb.begin(),nowb.end()); int sz=nowa.size();ll res=0; for(int i=sz-1;i>=0;i--) { res+=nowa[i]*nowb[i]; if(res>m)return 0; } return 1; } int find(int x) { int p=0; for(int i=0; ;i++) { p=i; if(!check(x,min(x+(1<<i)-1,n)))break; if(x+(1<<i)-1>=n)break; } int l=x+(1<<p-1)-1,r=min(x+(1<<p)-1,n),res=l; while(l<=r) { int mid=l+r>>1; if(check(x,mid))res=mid,l=mid+1; else r=mid-1; } return res; } #define F int main() { #ifdef F freopen("pair.in","r",stdin); freopen("pair.out","w",stdout); #endif n=read();m=read(); for(int i=1;i<=n;i++) a[i]=read(); for(int i=1;i<=n;i++) b[i]=read(); int ans=0; int i=1; while(i<=n)i=find(i)+1,ans++; printf("%d ",ans); return 0; } /* 3 50 6 7 6 6 3 5 */
C.鍩庡競娓告垙
鍜?/span>
以上是关于[CSP-S妯℃嫙娴嬭瘯96]棰樿В的主要内容,如果未能解决你的问题,请参考以下文章
鎬ц兘娴嬭瘯涔嬫柊涓€浠f湇鍔″櫒鎬ц兘娴嬭瘯宸ュ叿Gatling
NLP-BERT 璋锋瓕鑷劧璇█澶勭悊妯″瀷锛欱ERT-鍩轰簬pytorch