>>> import math >>> [ math.hypot(3,y+1)-math.hypot(3, y) for y in range(10) ] [0.16227766016837952, 0.4432736152956096, 0.6370894116552956, 0.7573593128807152, 0.8309518948453007, 0.8772520376540687, 0.9075691733645392, 0.9282306394536217, 0.9428292351876078, 0.9534735284054126]
ll ff(ll v) { ll ans=0; for(ll i=1;i<=v;i++) ans^=i; return ans; } ll f(ll v) { if(v<10) return ff(v); ll a=1; while(v>a) a=a<<1; a>>=1; return (((v-a)&1) ? 0 : a) ^ f(v^a); } class EllysXors { public: long long getXor(long long L, long long R) { //REP(i, 100) if(f(i+1)!=ff(i+1)) cout<<"ERRO"<<endl; return f(R)^f(L-1); } };
ll fff(ll A, ll B) { unsigned ans=0; unsigned AA = A; unsigned BB = B; for(unsigned i=AA;i<=BB;i++) ans^=i; return ans; }
↓あとで Accepted
int main() { int N, K; cin>>N>>K; VI w(N); REP(i, N) cin>>w[i]; int L=0, R=0; // [L, R) int maxi = -1; int maxv = 0; map<int, int> hi; ll ans = 0; while(1) { if(R==N) break; while(R<N && maxv<K) { R++; hi[w[R-1]]++; if(hi[w[R-1]] > maxv) { maxv = hi[w[R-1]]; maxi = w[R-1]; } } if(maxv<K) break; ans += N-R+1; //cout<<L<<" "<<R<<" + "<<N-R+1<<endl; while(L<N-1 && maxv == K) { L++; hi[w[L-1]]--; if(w[L-1]==maxi) {maxv--;break;} ans += N-R+1; } //cout<<L<<" "<<R<<endl; } cout<<ans<<endl; return 0; }
class BlurredDartboard { public: int minThrows(vector <int> p, int P) { int N=p.size(); VI vis(N, 0); int ma=-1; REP(i, N) { if(p[i]>0) { vis[p[i]-1]=1; ma=max(ma, p[i]); } } VI hid; REP(i, N) if(vis[i]==0) hid.PB(i+1); int hidsum = accumulate(ALL(hid), 0); sort(ALL(hid)); int ans=0; if(ma==-1 || hidsum > ma*hid.size()) { ans += P/hidsum*hid.size(); P -= P/hidsum*hidsum; } else { ans += P/ma; P -= P/ma*ma; } cout<<ans<<" "<<P<<endl; if(P==0) return ans; int lans=0; int PP=P; REP(i, hid.size()) { PP-=hid[i]; lans++; if(PP<=0) break; } if(PP>0) lans = 10000; cout<<lans<<endl; if(ma!=-1) lans = min(lans, (P+ma-1)/ma); cout<<lans<<" "<<ma<<endl; return ans+lans; } };
↓あとで通したやつ
vector <int> BB; VI w; map<PII, PII> memo; PII f(int bi, int wi) { PII key = MP(bi, wi); if(memo.count(key)) return memo[key]; if(wi==w.size()) return MP(0, 0); if(bi==BB.size()) return MP(-100000000, -100000000); PII rest = f(bi+1, wi+1); if(w[wi]==0) rest.first-=BB[bi]; else rest.first+=BB[bi]; rest.second+=BB[bi]; PII restB = f(bi+1, wi); //cout<<bi<<" "<<wi<<" "<<rest<<" "<<restB<<endl; return memo[key] = max(rest, restB); } class HeavyBooks { public: vector <int> findWeight(vector <int> B, vector <int> M) { memo = map<PII, PII>(); sort(ALL(B)); w = VI(M[0], 1); int to=0; REP(i, M.size()-1) { int mo = M[i+1]; for(int j=M[0]-1;j>=0;j--) { if(w[j]==1-to) { w[j]=to; mo--; if(mo==0) break; } } to=1-to; } cout<<w<<endl; BB=B; PII r = f(0, 0); cout<<r<<endl; vector<int> ans(2); ans[0]=-(r.first-r.second)/2; ans[1]=(r.first+r.second)/2; return ans; } };
#define MOD ((ll)1000000007) class PatrolRoute { public: int countRoutes(int X, int Y, int minT, int maxT) { ll ans = 0; for(int W=2;W<X;W++) { for(int H=2;H<Y;H++) { if( minT <= 2*(W+H) && 2*(W+H) <= maxT ) { ll a = (X-W) * (Y-H); ll b = (W-1)*(H-1)*6; ll lans = a*b; //cout<<W<<" "<<H<<" "<<a<<" "<<b+c<<endl; ans = (ans + lans) % MOD; } } } return ans; } };