class EllysNumberGuessing { public: int getNumber(vector <int> G, vector <int> A) { ll limit=1000000000; VI w(2); w[0]=G[0]-A[0]; w[1]=G[0]+A[0]; VI ans; REP(j, 2) { bool has=true; REP(i, G.size()) { ll a=G[i]-A[i]; ll b=G[i]+A[i]; if(!(w[j]==a || w[j]==b)) has=false; } if(has) { if(1<=w[j] && w[j]<=limit) { ans.PB(w[j]); } } } if(ans.size()==0) return -2; if(ans.size()==1) return ans[0]; if(ans.size()==2) return -1; return -1; } };
Div1-Mediumはこれですよ http://t.co/2fixl1Bo55
— *IRUN (@ir5) 2014, 1月 30
class EllysPairing { public: int getMax(int M, vector <int> count, vector <int> first, vector <int> mult, vector <int> add) { int N=count.size(); int co=0; ll maj=-1; REP(i, N) { uint32_t v = first[i]; REP(loop, count[i]) { if(v==maj) co++; else if(co==0) maj=v,co=1; else co--; v = (v * mult[i] + add[i]) & (M-1); } } co=0; REP(i, N) { uint32_t v = first[i]; REP(loop, count[i]) { if(maj==v) co++; v = (v * mult[i] + add[i]) & (M-1); } } int total=accumulate(ALL(count), 0); int th = total/2; if(co>th) { int rest = (co-th) - (total-th*2); th-=rest; } return th; } };
int h[(1<<16)+1]; class EllysPairing { public: int getMax(int M, vector <int> count, vector <int> first, vector <int> mult, vector <int> add) { int N=count.size(); CLEAR(h, 0); REP(i, N) { VI w; uint32_t v = first[i]; REP(loop, count[i]) { h[v&((1<<16)-1)]++; v = (v * mult[i] + add[i]) & (M-1); } } ll lo=-1, loi=-1; REP(i, 1<<16) if(lo<h[i]){lo=h[i];loi=i;} CLEAR(h, 0); REP(i, N) { VI w; uint32_t v = first[i]; REP(loop, count[i]) { h[v>>16]++; v = (v * mult[i] + add[i]) & (M-1); } } ll hi=-1, hii=-1; REP(i, 1<<16) if(hi<h[i]){hi=h[i];hii=i;} int maj = (hii<<16)+loi, mx=0; REP(i, N) { VI w; uint32_t v = first[i]; REP(loop, count[i]) { if(v==maj) mx++; v = (v * mult[i] + add[i]) & (M-1); } } int total=accumulate(ALL(count), 0); int th = total/2; if(mx>th) { int rest = (mx-th) - (total-th*2); th-=rest; // cout<<"--- "<<rest<<endl; } return th; } };
ll p[100010][3]; ll w[100010]; ll len[100010]; int main() { ios::sync_with_stdio(false); ll N,M; while(cin>>M) { len[0]=0; REP(i, M) { cin>>p[i][0]; if(p[i][0]==1) { cin>>p[i][1]; len[i+1] = len[i]+1; if(len[i]<100000) w[len[i]] = p[i][1]; } if(p[i][0]==2) { cin>>p[i][1]>>p[i][2]; len[i+1] = len[i]+p[i][1]*p[i][2]; for(int j=0;j<p[i][1]*p[i][2] && len[i]+j<100000;j++) { w[len[i]+j]=w[j%p[i][1]]; } } } cin>>N; VI ans(N); REP(i, N) { ll idx; cin>>idx; int d = distance(&len[0], lower_bound(&len[0], &len[M+1], idx)); if(p[d-1][0]==1) { assert(idx==len[d]); ans[i] = p[d-1][1]; } else { int j = (idx-1-len[d-1]) % p[d-1][1]; ans[i] = w[j]; } } REP(i, N) { if(i) cout<<" "; cout<<ans[i]; } cout<<endl; } return 0; }
int chL[110000]; // L child, 1base int chR[110000]; // R child, 1base int rL[7007]; int rR[7007]; int T[7007]; int L[7007]; int R[7007]; int X[7007]; // 109332 int main() { ios::sync_with_stdio(false); ll N,M; ll type,t,v; while(cin>>N>>M) { int cs=1; REP(i, 110000) { int ch = (POPCOUNT(i+1)==1) ? 2:1; chL[i+1]=ch==2?cs++:-1; chR[i+1]=cs++; } int hints=0; REP(i, M) { cin>>type; if(type==1) { cin>>T[hints]>>L[hints]>>R[hints]>>X[hints]; hints++; } else { cin>>t>>v; REP(j, t) rL[j]=rR[j]=-1; rL[t]=rR[t]=v; RANGE(j, t, N) { rL[j+1]=chL[rL[j]]==-1 ? chR[rL[j]] : chL[rL[j]]; rR[j+1]=chR[rR[j]]; } map<int, int> ma; REP(hi, hints) { if(rL[T[hi]]==-1) continue; bool in = !(R[hi]<rL[T[hi]] || rR[T[hi]]<L[hi]); if(in) ma[X[hi]]=1; } cout<<ma.size()<<endl; } } } return 0; }
class PowerOfThree { public: bool f(ll X, ll Y, ll step) { if(X==0 && Y==0 && step==0) return true; if(step==0) return false; return f(X+(X>0?-1:1)*step, Y, step/3) || f(X, Y+(Y>0?-1:1)*step, step/3); } string ableToGet(int x, int y) { bool ans=false; if(x==0 && y==0) return "Possible"; REP(k, 22) { ll step=1; REP(i, k) step*=3; ans = ans || f(x, y, step); if(ans) break; } return ans ? "Possible" : "Impossible"; } };
int dp[51][2210]; class TypoCoderDiv1 { public: int getmax(vector <int> D, int X) { int minf=-(1<<29); int N=D.size(); REP(i, N+1) REP(v, 2201) dp[i][v]=minf; dp[0][X]=0; REP(i, N) { REP(v, 2200) { if(dp[i][v]==minf) continue; for(int k=-1;k<=1;k+=2) { int nv = max(v+k*D[i], 0); if(nv>=2200) { if(i+1<N) { int nnv = max(nv-D[i+1], 0); if(nnv < 2200) { // 2200未満に戻ってこれるなら更新 dp[i+2][nnv] = max(dp[i+2][nnv], dp[i][v]+2); } } } else { dp[i+1][nv] = max(dp[i+1][nv], dp[i][v]); } } } } int ans = 0; REP(v, 2200) ans=max(ans, dp[N][v]); // 最後で 2200 を超える場合 REP(v, 2200) if(dp[N-1][v]!=minf && v+D[N-1]>=2200) { ans=max(ans, dp[N-1][v]+1); } return ans; } };
class TypoCoderDiv1 { public: int getmax(vector <int> D, int X) { int N=D.size(); map<int, int> dp[52]; dp[0][X]=0; REP(i, N+1) FOR(e, dp[i]) for(int d=-1;d<=1;d+=2) { int v=e->first; int nv = max(0, e->first + d*D[i]); int change = v<2200&&nv>=2200 || v>=2200&&nv<2200; if(e->first>=2200 && nv<2200 || e->first<2200) dp[i+1][nv] = max(dp[i+1][nv], change + e->second); } int ans=0; FOR(e, dp[N]) ans=max(ans, e->second); return ans; } };