Codeforces Round 489
Posted corx
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round 489相关的知识,希望对你有一定的参考价值。
终于结束了紧张而刺激 的大三考试 ,开始打比赛了 ,手真的生了
A
#include<bits/stdc++.h> using namespace std; #define LOACL freopen("in","r",stdin); freopen("out","w",stdout); #define FASTIO ios::sync_with_stdio(false); #define CLOCK cout<<1.*clock()/CLOCKS_PER_SEC<<"ms"<<" "; const int inf = 987654321; const int sz = (int)1e6 + 5; const int mod = (int)1e9 + 7; const int sqrtn = 300; #define add(u,v,w) e[++tot]=(edge){v,head[u],w},head[u]=tot; #define CLR(arr,val) memset(arr,val,sizeof(arr)) #define DBG(x) cout<<(#x)<<"="<<x<<endl #define DBG2(x,y) cout<<(#x)<<"="<<x<<" "<<(#y)<<"="<<y<<endl #define DBG3(x,y,z) cout<<(#x)<<"="<<x<<" "<<(#y)<<"="<<y<<" "<<(#z)<<"="<<z<<endl #define FOR(i, a, b) for(int i=(a); i<(b); i++) #define REP(i, a, b) for(int i=(a); i<=(b); i++) #define DOWN(i, a, b) for(int i=(a); i>=(b); i--) #define Loop(i,u) for(int i =head[u];i;i=e[i].nxt) #define all(x) x.begin(),x.end() #define low(x) (x)&(-x) #define pb push_back typedef long long ll; typedef double dl; map<int,int> m; int main() { LOACL int n,a,b; cin>>n; while(n--) { cin>>a; m[a]++; } b = m.size(); if(m[0]!=0) b--; cout<<b<<endl; }
B
#include<bits/stdc++.h> using namespace std; #define LOACL freopen("in","r",stdin); freopen("out","w",stdout); #define FASTIO ios::sync_with_stdio(false); #define CLOCK cout<<1.*clock()/CLOCKS_PER_SEC<<"ms"<<" "; const int inf = 987654321; const int sz = (int)1e6 + 5; const int mod = (int)1e9 + 7; const int sqrtn = 300; #define add(u,v,w) e[++tot]=(edge){v,head[u],w},head[u]=tot; #define CLR(arr,val) memset(arr,val,sizeof(arr)) #define DBG(x) cout<<(#x)<<"="<<x<<endl #define DBG2(x,y) cout<<(#x)<<"="<<x<<" "<<(#y)<<"="<<y<<endl #define DBG3(x,y,z) cout<<(#x)<<"="<<x<<" "<<(#y)<<"="<<y<<" "<<(#z)<<"="<<z<<endl #define FOR(i, a, b) for(int i=(a); i<(b); i++) #define REP(i, a, b) for(int i=(a); i<=(b); i++) #define DOWN(i, a, b) for(int i=(a); i>=(b); i--) #define Loop(i,u) for(int i =head[u];i;i=e[i].nxt) #define all(x) x.begin(),x.end() #define low(x) (x)&(-x) #define pb push_back typedef long long ll; typedef double dl; ll l,r,x,y; bool ok(ll a) { return a>=l&&a<=r; } int main() { LOACL cin>>l>>r>>x>>y; if(y%x!=0) { cout<<0; return 0; } int t = y/x; int ans = 0; for(int i=1 ;i<=sqrt(t);i++) { if(t%i==0) { int xx=t/i; if(__gcd(i,xx)==1&&ok(x*i)&&ok(x*xx)) if(i==xx) ans++; else ans+=2; } } cout<<ans<<endl; }
C
#include<bits/stdc++.h> using namespace std; #define LOACL freopen("in","r",stdin); freopen("out","w",stdout); #define FASTIO ios::sync_with_stdio(false); #define CLOCK cout<<1.*clock()/CLOCKS_PER_SEC<<"ms"<<" "; const int inf = 987654321; const int sz = (int)2e5+100; const int mod = (int)1e9 + 7; const int sqrtn = 300; #define add(u,v,w) e[++tot]=(edge){v,head[u],w},head[u]=tot; #define CLR(arr,val) memset(arr,val,sizeof(arr)) #define DBG(x) cout<<(#x)<<"="<<x<<endl #define DBG2(x,y) cout<<(#x)<<"="<<x<<" "<<(#y)<<"="<<y<<endl #define DBG3(x,y,z) cout<<(#x)<<"="<<x<<" "<<(#y)<<"="<<y<<" "<<(#z)<<"="<<z<<endl #define FOR(i, a, b) for(int i=(a); i<(b); i++) #define REP(i, a, b) for(int i=(a); i<=(b); i++) #define DOWN(i, a, b) for(int i=(a); i>=(b); i--) #define Loop(i,u) for(int i =head[u];i;i=e[i].nxt) #define all(x) x.begin(),x.end() #define low(x) (x)&(-x) #define pb push_back typedef long long ll; typedef double dl; typedef unsigned long long ull; ull getpowwer(ull n,ull m ) { ull ans =1; while(m) { if(m&1) { ans *= n; ans%=mod; } n*=n; n%=mod; m/=2; } return ans; } int main() { LOACL ull x,y; cin>>x>>y; if(x>mod) x%=mod; if(x==0) { cout<<0<<endl; return 0; } ull s = getpowwer(2,y); cout<<(s*2*x-s+1)%mod<<endl; }
D
#include<bits/stdc++.h> using namespace std; #define LOACL freopen("in","r",stdin); freopen("out","w",stdout); #define FASTIO ios::sync_with_stdio(false); #define CLOCK cout<<1.*clock()/CLOCKS_PER_SEC<<"ms"<<" "; const int inf = 987654321; const int sz = (int)1e6 + 5; const int mod = (int)1e9 + 7; const int sqrtn = 300; #define add(u,v,w) e[++tot]=(edge){v,head[u],w},head[u]=tot; #define CLR(arr,val) memset(arr,val,sizeof(arr)) #define DBG(x) cout<<(#x)<<"="<<x<<endl #define DBG2(x,y) cout<<(#x)<<"="<<x<<" "<<(#y)<<"="<<y<<endl #define DBG3(x,y,z) cout<<(#x)<<"="<<x<<" "<<(#y)<<"="<<y<<" "<<(#z)<<"="<<z<<endl #define FOR(i, a, b) for(int i=(a); i<(b); i++) #define REP(i, a, b) for(int i=(a); i<=(b); i++) #define DOWN(i, a, b) for(int i=(a); i>=(b); i--) #define Loop(i,u) for(int i =head[u];i;i=e[i].nxt) #define all(x) x.begin(),x.end() #define low(x) (x)&(-x) #define pb push_back typedef long long ll; typedef double dl; const int MAXN = (int)2e5 + 5; const int INF = (int)1e18; int a[MAXN],nxt1[MAXN]; int main() { LOACL FASTIO int n,k,ans=0; cin>>n>>k; REP(i,1,n) cin>>a[i]; nxt1[n]=n+1; DOWN(i,n-1,1)nxt1[i]= (a[i+1]==1?nxt1[i+1]:i+1); REP(i,1,n) { ll now = i,p=1LL,s=0,pre =i-1; while(now!=n+1 &&(INF/a[now])>=p) { p*=a[now]; s+=a[now]+now-pre-1; if(p%k==0 && p/k-s <= nxt1[now]-now-1 && p/k - s >= 0) ans++; pre =now; now = nxt1[now]; } } cout<<ans<<endl; }
E
#include<bits/stdc++.h> using namespace std; #define LOACL freopen("in","r",stdin); freopen("out","w",stdout); typedef long long ll; class fenwickTree{ private: vector<ll> bit; int n; public: void init(int n ) { this->n = n ; bit.assign(n,0); } void add(int idx,ll d) { for(;idx<n;idx=idx|(idx+1)) bit[idx]+=d; } ll sum(int l) { ll r = 0; for(;l>=0;l=(l&(l+1))-1) r+=bit[l]; return r; } ll sum(int l,int r) { return sum(r)-sum(l-1); } }ft; int highBit(int n) { return (n==0?0:1+highBit(n/2)); } int main() { LOACL int n,q,num,p,s; cin>>n>>q; ft.init(n+2); vector<set<int> > group(31); for (int i=1;i<=n;i++) { cin>>num; ft.add(i,num); group[highBit(num)].insert(i); } for(int i =0;i<q;i++) { cin>>p>>s; num = ft.sum(p,p); group[highBit(num)].erase(p); group[highBit(s)].insert(p); ft.add(p,s-num); int ans =-1; for(int j =0;j<30;j++) { int cnt = 0; set<int>::iterator it = group[j].begin(); for(;it!=group[j].end();it++ ) { int pos = *it; num = ft.sum(pos,pos); if(num == ft.sum(pos-1)) { ans = pos; break; } cnt++; if(cnt>=2)break; } if(ans!=-1) break; } cout<<ans<<endl; } }
以上是关于Codeforces Round 489的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #489 (Div. 2)
伪暴力+智商剪枝Codeforces Round #489 (Div. 2) D
Codeforces Round #489 (Div. 2) E. Nastya and King-Shamans
[Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)][C. Playing Piano](代码片段