Discounted fares
Static interval maximum number of SB problem
#include <bits/stdc++.h>usingnamespace Std;#define for (i,n) for (int i=1;i<=n;i++)#define Fork (i,k,n) for (int i=k;i<=n;i++)#define REP (i,n) for (int i=0;i<n;i++)#define ForD (i,n) for (int i=n;i;i--)#define forkd (i,k,n) for (int i=n;i>=k;i--)#define REPD (i,n) for (int i=n;i>=0;i--)#Define Forp (x) for (int p=pre[x];p; p=next[p])#Define forpiter (x) for (int &p=iter[x];p; p=next[p])#define Lson (o<<1)#define Rson ((o<<1) +1)#Define MEM (a) memset (A,0,sizeof (a));#Define Memi (a) memset (A,127,sizeof (a));#Define Memi (a) memset (A,128,sizeof (a));#define INF (2139062143)#define F (100000007)#Define PB push_back#Define MP Make_pair#Define fi first#define se second#define VI vector<int>#define pi pair<int,int>#Define SI (a) ((a). Size ())#define EPS (1e-5)#define MAXN (1000000+10)#define maxlog (in)typedefLong LongLl;typedef unsignedLong LongUll;ll Mul (ll a,ll b) {return(a*b)%F;} ll Add (ll A,ll b) {return(a+b)%F;} ll Sub (ll A,ll b) {return(A-b+llabs (A-B)/f*f+f)%F;}voidUPD (ll &a,ll b) {a= (a%f+b%f)%F;}intRead () {intx=0, f=1;CharCh=getchar (); while(!isdigit (CH)) {if(ch=='-') f=-1; Ch=getchar ();} while(IsDigit (CH)) {x=x*Ten+ch-' 0 '; Ch=getchar ();}returnX*f;} Class rmq{ Public:intN,A[MAXN]; RMQ (int_n=0): N (_n) {} RMQ (int* _a,int_n=0): N (_n) {memcpy (a,_a,sizeof(int) *_n); }voidMemint* _a,int_n=0) {n=_n;memcpy (a,_a,sizeof(int) *_n); }intD[maxn][maxlog];voidRmq_init () {Rep (i,n) d[i][0]=a[i]; for(intj=1;(1<<J) <=n;j++) for(intI=0; i + (1<<J)-1< n; i++) {D[i][j]=max (d[i][j-1],d[i+ (1<< (J-1))][j-1]); } }intQueryintLintR) {if(l>r) swap (L,R);intK=floor (log (r-l+1)/log (2));returnMax (d[l][k],d[r-(1<<K) +1][k]); }}s;intN,m;intA[MAXN];intMain () {//Freopen ("A.in", "R", stdin);//Freopen (". Out", "w", stdout);N=read (); M=read (); MEM (a) for (I,n) {intT=read (), V=read (); A[t]=max (A[T],V); } S.mem (A,100010); S.rmq_init (); for (i,m) {intL=read (), R=read ();intP=s.query (L,R);if(p==0) puts ("None");Elseprintf"%d\n", p); }return 0;}
Tsukiji Land Market
Ask for a number 4 or 7 of K
Remember to use __int128.
#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <functional>#include <iostream>#include <cmath>#include <cctype>#include <ctime>usingnamespace Std;#define for (i,n) for (int i=1;i<=n;i++)#define Fork (i,k,n) for (int i=k;i<=n;i++)#define REP (i,n) for (int i=0;i<n;i++)#define ForD (i,n) for (int i=n;i;i--)#define forkd (i,k,n) for (int i=n;i>=k;i--)#define REPD (i,n) for (int i=n;i>=0;i--)#Define Forp (x) for (int p=pre[x];p; p=next[p])#Define forpiter (x) for (int &p=iter[x];p; p=next[p])#define Lson (o<<1)#define Rson ((o<<1) +1)#Define MEM (a) memset (A,0,sizeof (a));#Define Memi (a) memset (A,127,sizeof (a));#Define Memi (a) memset (A,128,sizeof (a));#define INF (2139062143)#define F (100000007)#Define PB push_back#Define MP Make_pair#Define fi first#define se second#define VI vector<int>#define pi pair<int,int>#Define SI (a) ((a). Size ())typedefLong LongLl;typedef __int128 Ull;ll Mul (ll a,ll b) {return(a*b)%F;} ll Add (ll A,ll b) {return(a+b)%F;} ll Sub (ll A,ll b) {return(A-b+llabs (A-B)/f*f+f)%F;}voidUPD (ll &a,ll b) {a= (a%f+b%f)%F;} Ull g[ -],p10[ -]; ll K;voidCalcintIBOOLflag=0) {if(!i)return; REP (P,Ten) {ull q= (p==4|| p==7|| Flag)? (p10[i-1]): g[i-1];if(k>q) k-=q;Else{cout<<p; Calc (i-1, flag| (p==4|| p==7)); Break; } }}intMain () {//Freopen ("C.in", "R", stdin);//Freopen (". Out", "w", stdout);p10[0]=1; for (I, -) p10[i]=p10[i-1]*TenLL; g[0]=0; for (I, -) g[i]=g[i-1]*8+2*p10[i-1];//For (i,20) cout<<g[i]<<endl; while(cin>>k) {intlen=1; while(g[len]< (ull) k) len++; Calc (len);p UTS (""); }return 0;}
Hihocoder Challenge 20