QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#96280 | #125. Wild Boar | eyiigjkn | 12 | 49ms | 284716kb | C++14 | 3.6kb | 2023-04-13 18:39:52 | 2023-04-13 18:39:54 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll INF=1e18;
int a[100010],W[8010],pre[4010],nxt[4010];
ll f[4010][4010],dis[8010];
vector<int> G[2010],rG[2010],H[8010];
struct Node
{
int v;ll w;
Node(int v,ll w):v(v),w(w){}
bool operator<(const Node &t)const{return w>t.w;}
};
struct Path
{
int s,t;ll d;
Path(){}
Path(int s,int t,ll d):s(s),t(t),d(d){}
bool operator<(const Path &t)const{return d<t.d;}
Path operator+(const Path &t)const{return Path(s,t.t,d+t.d);}
};
struct Info
{
Path a[4];
Info(){fill(a,a+4,Path(0,0,INF));}
Info(vector<Path> &vec)
{
fill(a,a+4,Path(0,0,INF));
if(vec.empty()) return;
int sz=vec.size();
static bool vis[20];
sort(vec.begin(),vec.end());
vis[0]=1;a[0]=vec[0];
for(int i=1;i<sz;i++)
if(!vis[i] && vec[i].s!=a[0].s && vec[i].t!=a[0].t)
{
vis[i]=1;a[1]=vec[i];
break;
}
for(int i=1;i<sz;i++)
if(!vis[i] && vec[i].s!=a[0].s && vec[i].t!=a[1].t)
{
vis[i]=1;a[2]=vec[i];
break;
}
for(int i=1;i<sz;i++)
if(!vis[i] && vec[i].s!=a[1].s && vec[i].t!=a[0].t)
{
vis[i]=1;a[3]=vec[i];
break;
}
memset(vis,0,sizeof(bool)*sz);
}
Info operator+(const Info &t)const
{
vector<Path> vec;
for(int i:{0,1,2,3})
if(a[i].d<INF)
for(int j:{0,1,2,3})
if(t.a[j].d<INF && (a[i].t-1)/2!=(t.a[j].s-1)/2)
vec.push_back(a[i]+t.a[j]);
return Info(vec);
}
}g[2010][2010],val[100010],sum[300010];
void Dijk(int n,int s)
{
static bool vis[8010];
static priority_queue<Node,vector<Node>> pq;
fill(dis+1,dis+n+1,INF);
memset(vis+1,0,sizeof(bool)*n);
pq.emplace(s,dis[s]=W[s]);
while(!pq.empty())
{
int u=pq.top().v;pq.pop();
if(vis[u]) continue;
vis[u]=1;
for(int v:H[u])
if(dis[u]+W[v]<dis[v])
pq.emplace(v,dis[v]=dis[u]+W[v]);
}
}
inline void pushup(int rt){sum[rt]=sum[rt*2]+sum[rt*2+1];}
void build(int rt,int l,int r)
{
if(l==r) return sum[rt]=val[l],void();
int mid=(l+r)/2;
build(rt*2,l,mid);
build(rt*2+1,mid+1,r);
pushup(rt);
}
void update(int rt,int l,int r,int x,const Info &y)
{
if(l==r) return sum[rt]=val[l]=y,void();
int mid=(l+r)/2;
if(x<=mid) update(rt*2,l,mid,x,y);
else update(rt*2+1,mid+1,r,x,y);
pushup(rt);
}
int main()
{
int n,m,q,L,u,v,w,tot=0;
cin>>n>>m>>q>>L;
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&u,&v,&w);
W[++tot]=w;
G[u].push_back(tot);
rG[v].push_back(tot);
W[++tot]=w;
G[v].push_back(tot);
rG[u].push_back(tot);
}
for(int i=1;i<=n;i++)
{
int sz=G[i].size();
for(int j=0;j<sz;j++) H[tot+j+1].push_back(G[i][j]);
for(int j=1;j<sz;j++) H[tot+j+1].push_back(tot+j),pre[G[i][j]]=tot+j;
tot+=sz;
for(int j=0;j<sz;j++) H[tot+j+1].push_back(G[i][j]);
for(int j=1;j<sz;j++) H[tot+j].push_back(tot+j+1),nxt[G[i][j-1]]=tot+j+1;
tot+=sz;
}
for(int i=1;i<=2*m;i++)
{
int j=(i-1^1)+1;
if(pre[j]) H[i].push_back(pre[j]);
if(nxt[j]) H[i].push_back(nxt[j]);
}
for(int i=1;i<=2*m;i++)
{
Dijk(tot,i);
memcpy(f[i]+1,dis+1,sizeof(ll)*2*m);
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
if(i==j) continue;
vector<Path> vec;
for(int p:G[i])
for(int q:rG[j])
vec.emplace_back(p,q,f[p][q]);
g[i][j]=Info(vec);
}
for(int i=1;i<=L;i++) scanf("%d",&a[i]);
for(int i=1;i<L;i++) val[i]=g[a[i]][a[i+1]];
build(1,1,L-1);
while(q--)
{
scanf("%d%d",&u,&v);a[u]=v;
if(u>1) update(1,1,L-1,u-1,g[a[u-1]][v]);
if(u<L) update(1,1,L-1,u,g[v][a[u+1]]);
if(sum[1].a[0].d<INF) printf("%lld\n",sum[1].a[0].d);
else puts("-1");
}
return 0;
}
详细
Subtask #1:
score: 12
Accepted
Test #1:
score: 12
Accepted
time: 11ms
memory: 283088kb
input:
5 5 1 10 1 4 10 2 4 2 2 5 4 3 5 4 4 5 7 2 4 5 3 5 3 5 4 2 1 10 1
output:
-1
result:
ok single line: '-1'
Test #2:
score: 0
Accepted
time: 12ms
memory: 283144kb
input:
5 10 1 10 1 2 8 1 3 5 1 4 2 1 5 1 2 3 7 2 4 9 2 5 6 3 4 10 3 5 10 4 5 6 4 2 4 3 5 3 1 4 3 5 3 5
output:
64
result:
ok single line: '64'
Test #3:
score: 0
Accepted
time: 24ms
memory: 284052kb
input:
5 10 1 10 1 2 8 1 3 4 1 4 2 1 5 10 2 3 10 2 4 10 2 5 6 3 4 10 3 5 2 4 5 10 5 1 2 1 4 5 1 5 3 1 8 4
output:
60
result:
ok single line: '60'
Test #4:
score: 0
Accepted
time: 21ms
memory: 283316kb
input:
6 10 1 10 1 3 3 1 4 5 1 5 9 1 6 10 2 3 4 2 5 5 2 6 1 3 6 4 4 6 6 5 6 8 4 3 6 4 1 3 6 4 3 5 1 1
output:
48
result:
ok single line: '48'
Test #5:
score: 0
Accepted
time: 12ms
memory: 284400kb
input:
6 10 1 10 1 2 10 1 3 9 1 5 6 1 6 9 2 4 3 2 5 4 2 6 9 3 5 2 4 5 6 4 6 8 4 6 2 3 2 3 1 3 5 4 9 1
output:
86
result:
ok single line: '86'
Test #6:
score: 0
Accepted
time: 20ms
memory: 283952kb
input:
6 10 1 10 1 2 7 1 4 10 1 5 9 1 6 9 2 3 7 2 4 3 3 4 1 3 5 4 4 6 2 5 6 3 6 3 1 3 6 4 6 4 3 1 5 2
output:
61
result:
ok single line: '61'
Test #7:
score: 0
Accepted
time: 20ms
memory: 282928kb
input:
7 10 1 10 1 2 4 1 3 8 1 5 10 1 7 5 2 5 5 2 7 4 3 4 8 3 6 9 4 7 6 5 6 9 2 1 2 1 2 1 2 1 2 1 9 2
output:
56
result:
ok single line: '56'
Test #8:
score: 0
Accepted
time: 28ms
memory: 283760kb
input:
7 10 1 10 1 4 8 1 5 9 1 6 5 1 7 5 2 4 1 2 6 9 2 7 6 3 5 5 3 7 2 5 6 7 6 5 3 4 6 3 6 4 7 4 4 4
output:
88
result:
ok single line: '88'
Test #9:
score: 0
Accepted
time: 20ms
memory: 283520kb
input:
7 10 1 10 1 3 1 1 4 5 1 5 8 2 3 4 2 7 9 3 4 8 3 7 5 4 5 1 5 6 8 6 7 2 6 5 2 5 6 5 6 5 7 6 4 3
output:
84
result:
ok single line: '84'
Test #10:
score: 0
Accepted
time: 4ms
memory: 283824kb
input:
7 10 1 10 1 3 4 1 4 3 1 5 7 1 6 5 1 7 2 2 3 8 2 4 6 4 7 7 5 6 10 6 7 4 3 2 3 1 3 1 3 1 3 2 9 3
output:
90
result:
ok single line: '90'
Test #11:
score: 0
Accepted
time: 41ms
memory: 282680kb
input:
8 10 1 10 1 2 4 1 7 4 1 8 7 2 3 7 2 4 2 3 7 5 3 8 8 4 5 5 5 6 5 6 8 3 3 5 7 5 6 3 5 3 6 4 9 2
output:
105
result:
ok single line: '105'
Test #12:
score: 0
Accepted
time: 28ms
memory: 283932kb
input:
8 10 1 10 1 3 6 1 7 3 1 8 1 2 3 10 2 4 6 2 8 9 3 5 3 4 6 5 5 7 7 6 8 7 5 2 6 8 4 5 2 5 3 6 10 7
output:
114
result:
ok single line: '114'
Test #13:
score: 0
Accepted
time: 27ms
memory: 283644kb
input:
8 10 1 10 1 2 6 1 3 9 1 6 7 2 8 6 3 5 10 4 6 4 4 7 1 4 8 8 5 7 7 6 8 9 2 8 5 6 2 3 5 6 4 8 3 5
output:
125
result:
ok single line: '125'
Test #14:
score: 0
Accepted
time: 40ms
memory: 283664kb
input:
8 10 1 10 1 2 5 1 5 8 1 8 3 2 6 5 2 7 8 3 4 5 3 8 4 4 6 4 5 6 1 5 7 5 7 4 5 1 6 4 7 4 8 6 10 1
output:
99
result:
ok single line: '99'
Test #15:
score: 0
Accepted
time: 31ms
memory: 283076kb
input:
9 10 1 10 1 3 1 1 6 6 1 9 6 2 4 5 2 9 3 3 5 4 4 5 10 6 7 6 7 8 8 8 9 6 3 5 2 6 2 8 5 1 3 7 2 8
output:
189
result:
ok single line: '189'
Test #16:
score: 0
Accepted
time: 11ms
memory: 284516kb
input:
9 10 1 10 1 8 9 1 9 5 2 6 8 2 7 10 3 5 8 3 7 5 4 5 3 4 8 4 5 9 7 6 9 9 4 7 5 2 7 5 8 4 6 1 7 2
output:
217
result:
ok single line: '217'
Test #17:
score: 0
Accepted
time: 20ms
memory: 283376kb
input:
9 10 1 10 1 4 8 1 9 10 2 3 3 2 5 10 3 9 1 4 8 5 5 7 6 6 7 2 6 8 7 8 9 10 2 9 6 4 5 8 6 3 9 3 4 7
output:
116
result:
ok single line: '116'
Test #18:
score: 0
Accepted
time: 12ms
memory: 282844kb
input:
9 10 1 10 1 3 6 1 4 1 2 4 1 2 6 7 3 4 6 3 9 1 5 6 2 5 8 6 7 8 8 7 9 9 1 6 7 6 9 7 1 5 9 3 7 6
output:
155
result:
ok single line: '155'
Test #19:
score: 0
Accepted
time: 11ms
memory: 284716kb
input:
10 10 1 10 1 3 6 1 9 5 2 4 4 2 6 2 3 4 10 5 8 1 5 10 7 6 7 8 7 10 2 8 9 8 10 3 10 9 1 2 8 4 7 4 2 3
output:
196
result:
ok single line: '196'
Test #20:
score: 0
Accepted
time: 2ms
memory: 282940kb
input:
10 10 1 10 1 4 5 1 8 6 2 8 9 2 9 7 3 9 4 3 10 3 4 7 5 5 6 10 5 10 10 6 7 8 9 5 4 6 5 8 2 8 9 8 3 9
output:
284
result:
ok single line: '284'
Test #21:
score: 0
Accepted
time: 49ms
memory: 283008kb
input:
5 10 1 10 1 2 1 1 3 7 1 4 6 1 5 10 2 3 2 2 4 4 2 5 5 3 4 1 3 5 10 4 5 3 2 1 5 1 4 2 5 4 1 5 7 5
output:
45
result:
ok single line: '45'
Test #22:
score: 0
Accepted
time: 7ms
memory: 283096kb
input:
5 10 1 10 1 2 4 1 3 10 1 4 5 1 5 6 2 3 2 2 4 1 2 5 1 3 4 9 3 5 10 4 5 10 4 2 3 1 4 3 1 3 2 3 10 1
output:
49
result:
ok single line: '49'
Test #23:
score: 0
Accepted
time: 41ms
memory: 282764kb
input:
5 10 1 10 1 2 10 1 3 8 1 4 2 1 5 10 2 3 7 2 4 2 2 5 4 3 4 3 3 5 7 4 5 1 3 1 2 4 5 4 3 2 5 2 10 2
output:
41
result:
ok single line: '41'
Test #24:
score: 0
Accepted
time: 16ms
memory: 283948kb
input:
5 10 1 10 1 2 7 1 3 7 1 4 4 1 5 8 2 3 6 2 4 10 2 5 1 3 4 9 3 5 4 4 5 6 1 4 3 1 2 4 2 1 2 4 1 2
output:
70
result:
ok single line: '70'
Test #25:
score: 0
Accepted
time: 29ms
memory: 283136kb
input:
5 10 1 10 1 2 10 1 3 8 1 4 9 1 5 3 2 3 3 2 4 3 2 5 10 3 4 1 3 5 1 4 5 7 4 3 1 3 4 2 4 5 2 3 9 2
output:
36
result:
ok single line: '36'
Test #26:
score: 0
Accepted
time: 36ms
memory: 283332kb
input:
5 10 1 10 1 2 5 1 3 7 1 4 2 1 5 6 2 3 5 2 4 2 2 5 8 3 4 8 3 5 3 4 5 1 3 2 5 4 1 2 4 3 1 2 2 2
output:
38
result:
ok single line: '38'
Subtask #2:
score: 0
Dangerous Syscalls
Dependency #1:
100%
Accepted
Test #27:
score: 0
Dangerous Syscalls
input:
20 40 1 100 1 9 61 1 17 2 1 20 2 2 8 35 2 16 11 2 17 4 3 5 19 3 18 52 4 5 4 4 6 89 4 11 52 5 6 59 5 10 77 5 12 24 5 13 82 5 16 55 5 18 25 6 7 98 6 9 59 6 15 37 7 10 42 7 17 71 8 10 37 8 19 31 9 10 74 9 14 25 9 15 70 9 18 39 10 14 1 11 20 46 12 17 48 12 20 36 13 17 32 13 20 77 14 18 73 15 16 50 15 17...
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%