A. 百度无人车
签到
#include<bits/stdc++.h>
using namespace 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 ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;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,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#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 Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long 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)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
#define MAXN (20000+10)
int n;
ll a[MAXN];
ll check(ll m) {
ll t=0;
For(i,n) if(a[i]>m) t+=a[i]-m;
return t;
}
int main()
{
// freopen("A.in","r",stdin);
// freopen(".out","w",stdout);
cin>>n;
For(i,n){
a[i]=read();
}
ll p=read();
ll s;cin>>s;
s/=p;
ll l=1,r=20000,ans=20000;
while(l<=r){
ll m=(l+r)/2;
if(check(m)<=s) {ans=m; r=m-1;
}else l=m+1;
}
cout<<ans<<endl;
return 0;
}
百度科学家(困难)
主席树建图,SCC缩点
卡内存真好玩
#include<bits/stdc++.h>
using namespace 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 ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;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,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#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 Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long 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)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
#define MAXN (100000+10)
int n;
int a[MAXN];
int id[MAXN]={};
int idd[MAXN]={};
#undef MAXN
#define MAXN (2000000+10)
ll sccans[MAXN]={};
vi G[MAXN],G2[MAXN];
vi S;
int vis[MAXN],sccno[MAXN],scc_cnt;
void dfs1(int u) {
if (vis[u]) return ;
vis[u] = 1;
int sz=SI(G[u]);
Rep(i,sz) dfs1(G[u][i]);
S.pb(u);
}
void dfs2(int u) {
if (sccno[u]) return;
sccno[u] = scc_cnt;
int sz=SI(G2[u]);
Rep(i,sz) dfs2(G2[u][i]);
}
void find_scc(int n) {
scc_cnt=0;
S.clear();
MEM(sccno) MEM(vis)
Rep(i,n) dfs1(i);
RepD(i,n-1)
if (!sccno[S[i]]) {
scc_cnt++; dfs2(S[i]);
}
}
int pp;
int tot=1;
int rot=1,lson[MAXN],rson[MAXN];
void build(int x,int l,int r) {
if(l==r){
id[l]=x ;return;
}
int m=(l+r)/2;
lson[x]=++tot;rson[x]=++tot;
G[x].pb(lson[x]);
G2[lson[x]].pb(x);
build(lson[x],l,m);
G[x].pb(rson[x]);
G2[rson[x]].pb(x);
build(rson[x],m+1,r);
}
void init(int &rot,int rot2,int l,int r, int p ,int newid) {
if(!rot) {
rot= ++tot;
}
if(l==r) {
id[newid]=rot;
return;
}
int m=(l+r)/2;
if(p<=m) {
lson[rot]=0;
rson[rot]=rson[rot2];
G[rot].pb(rson[rot]);
G2[rson[rot]].pb(rot);
init(lson[rot],lson[rot2],l,m,p,newid);
G[rot].pb(lson[rot]);
G2[lson[rot]].pb(rot);
}
else {
rson[rot]=0;
lson[rot]=lson[rot2];
G[rot].pb(lson[rot]);
G2[lson[rot]].pb(rot);
init(rson[rot],rson[rot2],m+1,r,p,newid);
G[rot].pb(rson[rot]);
G2[rson[rot]].pb(rot);
}
}
void get(int x,int l,int r,int L,int R) {
int m=(l+r)/2;
if(L<=l&&r<=R) {
G[id[idd[pp]]].pb(x);
G2[x].pb(id[idd[pp]]);
return;
}
if(L<=m) get(lson[x],l,m,L,R);
if(m<R) get(rson[x],m+1,r,L,R);
}
bool fl[MAXN]={};
int iid[MAXN];
int main()
{
// freopen("B.in","r",stdin);
// freopen(".out","w",stdout);
cin>>n;
For(i,n) {
a[i]=read();
}
build(1,1,n);
int m=read();
int rot=1;
int newid=n;
For(i,n) idd[i]=i;
For(i,m) {
int op=read();
if(op==1) {
int x=read(),l=read(),r=read();
pp=x;
get(rot,1,n,l,r );
}else {
int x=read(),p=read();
int ro=0;
init(ro,rot,1,n,x,++newid);
rot=ro;
a[newid]=p;
idd[x]=newid;
}
}
tot++;
find_scc(tot);
For(i,tot) {
for(int v: G[i]){
if(sccno[i]!=sccno[v]) {
fl[sccno[i]]=1;
}
}
}
For(i,newid){
iid[i]=sccno[id[i]];
}
For(i,newid){
sccans[sccno[id[i]]]+=a[i];
}
ll p=1e18;
For(i,newid) if(!fl[iid[i]]){
gmin(p,sccans[iid[i]]);
}
cout<<p<<endl;
return 0;
}