1010,1003,1012;
1,1010;
只有是两边都是全部牌都不一样,即第三条规则,那么yahaha是无法叫的,一定会被challenge;
会输,其余情况都是赢;
2,1003;
难点在于如何将两层的图建好;
一开始找了一个虚拟节点,将所有来到该节点路径的边权设为p,所有从该节点的路径设为0;
但是每两层要换一个;
按理说同层之间还是可以相互到达,且路径为p,但是没wa;
code:
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rep1(i,a,n) for(register int i=(a);i<(n);++i)
#define rep2(i,a,n) for(register int i=(a);i<=(n);++i)
#define per1(i,n,a) for( int i=(n);i>(a);i--)
#define per2(i,n,a) for( int i=(n);i>=(a);i--)
#define quick_cin() cin.tie(0),cout.tie(0),ios::sync_with_stdio(false)
#define memset(a,i,b) memset((a),(i),sizeof (b))
#define memcpy(a,i,b) memcpy((a),(i),sizeof (b))
#define pro_q priority_queue
#define eb emplace_back
#define endl "\n"
#define lowbit(m) ((-m)&(m))
#define dbug(y) cout<<(y)<<"\n"
#define dbug2(a,b) cout<<(a)<<" "<<(b)<<"\n"
#define dbug3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<"\n"
#define dbug4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<"\n"
#define yi first
#define er second
#define tulun int e[N],ne[N],h[N],w[N],idx;
#define add2(a,b) e[idx]=b,ne[idx]=h[a],h[a]=idx++;
#define add3(a,b,c) w[idx]=c,e[idx]=b,ne[idx]=h[a],h[a]=idx++;
#define T_solve() int T;cin>>T;while(T--)solve();
#define pi 3.14159265358979323846
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef double dob;
const int N=3e6+10;
int e[N],ne[N],h[N],idx;
LL w[N];
void add(int a,int b,int c)
{
w[idx]=c,e[idx]=b,ne[idx]=h[a],h[a]=idx++;
}
int k,p;
int s,t;
int d[N];
int q[N<<1];
int ceng_db[N];
vector<int>ceng[N];
int n,maxd;
void bfs()
{
int hh=0,tt=0;
q[0]=1;
d[1]=1;
ceng_db[1]=1;
while(hh<=tt)
{
int t=q[hh++];
bool f=0;
for(int i=h[t];~i;i=ne[i])
{
int j=e[i];
if(!d[j])
{
d[j]=d[t]+1;
maxd=max(maxd,d[j]);
if(!f)
{
f=1;
ceng_db[d[j]]=j;
}
q[++tt]=j;
}
}
}
rep2(i,1,n)
{
ceng[d[i]].emplace_back(i);
}
}
LL dist[N];
int st[N];
void dijkstra()
{
pro_q<PLL,vector<PLL>,greater<PLL>>heap;
heap.push({0,s});
dist[s]=0;
while(heap.size())
{
auto tt=heap.top();
heap.pop();
int t=tt.second;
if(st[t])continue;
st[t]=1;
for(int i=h[t];~i;i=ne[i])
{
int j=e[i];
// dbug4(j,dist[j],dist[t],w[i]);
if(dist[j]>dist[t]+w[i])
{
dist[j]=dist[t]+w[i];
// dbug3(t,j,dist[j]);
heap.push({dist[j],j});
}
}
}
}
void solve()
{
memset(h,-1,h);
maxd=0;
idx=0;
cin>>n;
memset(st,0,st);
memset(dist,0x3f,dist);
memset(d,0,d);
rep2(i,0,n+5)ceng[i].clear();
rep2(i,1,n-1)
{
int a,b,c;
cin>>a>>b>>c;
add(a,b,c);
add(b,a,c);
}
cin>>k>>p;
cin>>s>>t;
bfs();
int superv=n+1;
rep2(i,1,maxd-k)
{
int nn=i+k;
int siz1=ceng[i].size();
int siz2=ceng[nn].size();
rep1(j,0,siz1)
{
add(superv,ceng[i][j],0);
add(ceng[i][j],superv,p);
}
rep1(j,0,siz2)
{
add(ceng[nn][j],superv,p);
add(superv,ceng[nn][j],0);
}
superv++;
}
//rep2(i,1,n+1)dbug2(i,dist[i]);
dijkstra();
dbug(dist[t]);
}
signed main()
{
quick_cin();
T_solve();
return 0;
}
真正维护好同层之间关系的是每层用两个点,d1,d2;
上一层都指向d1,边权为p,然后d1指向下一层,边权为0;
下一层都指向d2,边权为p,然后d2指向上一层,边权为0;
这样同层之间达到路径就是2p;
code:唯一区别就是建图;
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rep1(i,a,n) for(register int i=(a);i<(n);++i)
#define rep2(i,a,n) for(register int i=(a);i<=(n);++i)
#define per1(i,n,a) for( int i=(n);i>(a);i--)
#define per2(i,n,a) for( int i=(n);i>=(a);i--)
#define quick_cin() cin.tie(0),cout.tie(0),ios::sync_with_stdio(false)
#define memset(a,i,b) memset((a),(i),sizeof (b))
#define memcpy(a,i,b) memcpy((a),(i),sizeof (b))
#define pro_q priority_queue
#define eb emplace_back
#define endl "\n"
#define lowbit(m) ((-m)&(m))
#define dbug(y) cout<<(y)<<"\n"
#define dbug2(a,b) cout<<(a)<<" "<<(b)<<"\n"
#define dbug3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<"\n"
#define dbug4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<"\n"
#define yi first
#define er second
#define tulun int e[N],ne[N],h[N],w[N],idx;
#define add2(a,b) e[idx]=b,ne[idx]=h[a],h[a]=idx++;
#define add3(a,b,c) w[idx]=c,e[idx]=b,ne[idx]=h[a],h[a]=idx++;
#define T_solve() int T;cin>>T;while(T--)solve();
#define pi 3.14159265358979323846
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef double dob;
const int N=3e6+10;
int e[N],ne[N],h[N],idx;
LL w[N];
void add(int a,int b,int c)
{
w[idx]=c,e[idx]=b,ne[idx]=h[a],h[a]=idx++;
}
int k,p;
int s,t;
int d[N];
int q[N<<1];
int ceng_db[N];
vector<int>ceng[N];
int n,maxd;
void bfs()
{
int hh=0,tt=0;
q[0]=1;
d[1]=1;
ceng_db[1]=1;
while(hh<=tt)
{
int t=q[hh++];
bool f=0;
for(int i=h[t];~i;i=ne[i])
{
int j=e[i];
if(!d[j])
{
d[j]=d[t]+1;
maxd=max(maxd,d[j]);
if(!f)
{
f=1;
ceng_db[d[j]]=j;
}
q[++tt]=j;
}
}
}
rep2(i,1,n)
{
ceng[d[i]].emplace_back(i);
}
}
LL dist[N];
int st[N];
void dijkstra()
{
pro_q<PLL,vector<PLL>,greater<PLL>>heap;
heap.push({0,s});
dist[s]=0;
while(heap.size())
{
auto tt=heap.top();
heap.pop();
int t=tt.second;
if(st[t])continue;
st[t]=1;
for(int i=h[t];~i;i=ne[i])
{
int j=e[i];
// dbug4(j,dist[j],dist[t],w[i]);
if(dist[j]>dist[t]+w[i])
{
dist[j]=dist[t]+w[i];
// dbug3(t,j,dist[j]);
heap.push({dist[j],j});
}
}
}
}
void solve()
{
memset(h,-1,h);
maxd=0;
idx=0;
cin>>n;
memset(st,0,st);
memset(dist,0x3f,dist);
memset(d,0,d);
rep2(i,0,n+5)ceng[i].clear();
rep2(i,1,n-1)
{
int a,b,c;
cin>>a>>b>>c;
add(a,b,c);
add(b,a,c);
}
cin>>k>>p;
cin>>s>>t;
bfs();
int superv=n+1;
rep2(i,1,maxd-k)
{
int nn=i+k;
int d1=superv;
superv++;
int d2=superv;
int siz1=ceng[i].size();
int siz2=ceng[nn].size();
rep1(j,0,siz1)
{
add(d2,ceng[i][j],0);
add(ceng[i][j],d1,p);
}
rep1(j,0,siz2)
{
add(ceng[nn][j],d2,p);
add(d1,ceng[nn][j],0);
}
}
//rep2(i,1,n+1)dbug2(i,dist[i]);
dijkstra();
dbug(dist[t]);
}
signed main()
{
quick_cin();
T_solve();
return 0;
}
3,1012;
开个线段树统计1~m窗口的人数和编号;
关键在于如何更新队伍人数;
开个小根堆记录离开时间和所在窗口,每次只要到了时间,都给他离开掉;
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rep1(i,a,n) for(register int i=(a);i<(n);++i)
#define rep2(i,a,n) for(register int i=(a);i<=(n);++i)
#define per1(i,n,a) for( int i=(n);i>(a);i--)
#define per2(i,n,a) for( int i=(n);i>=(a);i--)
#define quick_cin() cin.tie(0),cout.tie(0),ios::sync_with_stdio(false)
#define memset(a,i,b) memset((a),(i),sizeof (b))
#define memcpy(a,i,b) memcpy((a),(i),sizeof (b))
#define pro_q priority_queue
#define eb emplace_back
#define endl "\n"
#define lowbit(m) ((-m)&(m))
#define dbug(y) cout<<(y)<<"\n"
#define dbug2(a,b) cout<<(a)<<" "<<(b)<<"\n"
#define dbug3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<"\n"
#define dbug4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<"\n"
#define yi first
#define er second
#define tulun int e[N],ne[N],h[N],w[N],idx;
#define add2(a,b) e[idx]=b,ne[idx]=h[a],h[a]=idx++;
#define add3(a,b,c) w[idx]=c,e[idx]=b,ne[idx]=h[a],h[a]=idx++;
#define T_solve() int T;cin>>T;while(T--)solve();
#define pi 3.14159265358979323846
using namespace std;
typedef long long LL;
#define int LL
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef double dob;
const int N=2e6+10;
int n,m,a[N];
int leave[N];
struct node1
{
int start,len;
bool operator <(const node1 &B)const
{
return start<B.start;
}
}p[N];
struct node2
{
int l,r;
int id,minv;
}tr[N<<2];
void pushup(int u)
{
tr[u].minv=min(tr[u<<1].minv,tr[u<<1|1].minv);
if(tr[u<<1].minv==tr[u].minv)tr[u].id=tr[u<<1].id;
else tr[u].id=tr[u<<1|1].id;
}
void build(int u,int l,int r)
{
tr[u]={l,r,l,0};
if(l==r)return;
int mid=l+r>>1;
build(u<<1,l,mid),build(u<<1|1,mid+1,r);
pushup(u);
}
void modify(int u,int x,int v)
{
if(x==tr[u].l&&x==tr[u].r)
{
tr[u].minv+=v;
}
else
{
int mid=tr[u].l+tr[u].r>>1;
if(x<=mid)modify(u<<1,x,v);
if(x>mid)modify(u<<1|1,x,v);
pushup(u);
}
}
int query(int u,int l,int r)
{
return tr[u].id;
}
void solve()
{
cin>>n>>m;
rep2(i,1,n)
{
int a,b;
cin>>a>>b;
p[i]={a,b};
}
rep2(i,1,m)leave[i]=0;
build(1,1,m);
sort(p+1,p+n+1);
pro_q<PII,vector<PII>,greater<PII>>q;
int ans=0;
rep2(i,1,n)
{
while(q.size()&&q.top().first<=p[i].start)
{
modify(1,q.top().second,-1);
q.pop();
}
int pos=query(1,1,m);
modify(1,pos,1);
leave[pos]=max(p[i].start,leave[pos])+p[i].len;
q.push({leave[pos],pos});
ans=max(leave[pos],ans);
}
dbug(ans);
}
signed main()
{
quick_cin();
T_solve();
return 0;
}
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rep1(i,a,n) for(register int i=(a);i<(n);++i)
#define rep2(i,a,n) for(register int i=(a);i<=(n);++i)
#define per1(i,n,a) for( int i=(n);i>(a);i--)
#define per2(i,n,a) for( int i=(n);i>=(a);i--)
#define quick_cin() cin.tie(0),cout.tie(0),ios::sync_with_stdio(false)
#define memset(a,i,b) memset((a),(i),sizeof (b))
#define memcpy(a,i,b) memcpy((a),(i),sizeof (b))
#define pro_q priority_queue
#define eb emplace_back
#define endl "\n"
#define lowbit(m) ((-m)&(m))
#define dbug(y) cout<<(y)<<"\n"
#define dbug2(a,b) cout<<(a)<<" "<<(b)<<"\n"
#define dbug3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<"\n"
#define dbug4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<"\n"
#define yi first
#define er second
#define tulun int e[N],ne[N],h[N],w[N],idx;
#define add2(a,b) e[idx]=b,ne[idx]=h[a],h[a]=idx++;
#define add3(a,b,c) w[idx]=c,e[idx]=b,ne[idx]=h[a],h[a]=idx++;
#define T_solve() int T;cin>>T;while(T--)solve();
#define pi 3.14159265358979323846
using namespace std;
typedef long long LL;
#define int LL
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef double dob;
const int N=2e6+10;
int n,m,a[N];
int leave[N];
struct node1
{
int start,len;
bool operator <(const node1 &B)const
{
return start<B.start;
}
}p[N];
struct node2
{
int l,r;
int id,minv;
}tr[N<<2];
void pushup(int u)
{
tr[u].minv=min(tr[u<<1].minv,tr[u<<1|1].minv);
if(tr[u<<1].minv==tr[u].minv)tr[u].id=tr[u<<1].id;
else tr[u].id=tr[u<<1|1].id;
}
void build(int u,int l,int r)
{
tr[u]={l,r,l,0};
if(l==r)return;
int mid=l+r>>1;
build(u<<1,l,mid),build(u<<1|1,mid+1,r);
pushup(u);
}
void modify(int u,int x,int v)
{
if(x==tr[u].l&&x==tr[u].r)
{
tr[u].minv+=v;
}
else
{
int mid=tr[u].l+tr[u].r>>1;
if(x<=mid)modify(u<<1,x,v);
if(x>mid)modify(u<<1|1,x,v);
pushup(u);
}
}
int query(int u,int l,int r)
{
return tr[u].id;
}
void solve()
{
cin>>n>>m;
rep2(i,1,n)
{
int a,b;
cin>>a>>b;
p[i]={a,b};
}
rep2(i,1,m)leave[i]=0;
build(1,1,m);
sort(p+1,p+n+1);
pro_q<PII,vector<PII>,greater<PII>>q;
int ans=0;
rep2(i,1,n)
{
while(q.size()&&q.top().first<=p[i].start)
{
modify(1,q.top().second,-1);
q.pop();
}
int pos=query(1,1,m);
modify(1,pos,1);
leave[pos]=max(p[i].start,leave[pos])+p[i].len;
q.push({leave[pos],pos});
ans=max(leave[pos],ans);
}
dbug(ans);
}
signed main()
{
quick_cin();
T_solve();
return 0;
}