QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#103852 | #5669. Traveling in Jade City | Robert_JYH# | TL | 7ms | 52044kb | C++17 | 1.7kb | 2023-05-07 18:29:53 | 2023-05-07 18:29:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
string no="impossible";
int n,k,m,q;
const int maxn=2e6+10;
vector<tuple<int,int,int>> ve[maxn];
bool ok[maxn];
struct kkk{
int x,len;
bool operator<(kkk k1)const{
return len>k1.len;
}
};
signed main()
{
ios::sync_with_stdio(false);cin.tie(0);
cin>>n>>k>>m>>q;
for(int i=1;i<=n;i++){
int x=i,y=i%n+1;
int w;cin>>w;
ve[x].emplace_back(y,w,i);
ve[y].emplace_back(x,w,i);
}
for(int i=0;i<=m;i++){
int x,y;
int w;cin>>w;
if(i==0){
x=1,y=n+1;
}
else if(i==m){
x=n+m,y=k;
}
else x=n+i,y=n+i+1;
ve[x].emplace_back(y,w,i+n+1);
ve[y].emplace_back(x,w,i+n+1);
}
while(q--){
char c;cin>>c;
if(c=='q'){
int beg,ed;
cin>>beg>>ed;
int inf =1e18;
vector<int> dis(n+m+1,inf);
priority_queue<kkk,vector<kkk>> qu;
qu.push(kkk{beg,0});
while(!qu.empty()){
kkk k1=qu.top();qu.pop();
if(dis[k1.x]>k1.len){
dis[k1.x]=k1.len;
}
else continue;
for(auto [to,l,id]:ve[k1.x])if(!ok[id]){
qu.push(kkk{to,k1.len+l});
}
}
if(dis[ed]==inf)cout<<no<<"\n";
else cout<<dis[ed]<<"\n";
}
if(c=='x'){
int id;cin>>id;id+=n+1;
ok[id]=!ok[id];
}
if(c=='c'){
int id;cin>>id;
ok[id]=!ok[id];
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 51180kb
input:
4 3 1 9 2 3 8 4 1 1 q 3 4 x 0 q 3 4 c 3 q 3 4 c 1 q 3 4 x 0 q 3 4
output:
6 8 9 impossible 6
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 7ms
memory: 52044kb
input:
4 3 1 9 2 3 8 4 1 1 q 3 4 x 0 q 3 4 c 3 q 3 4 c 1 q 3 4 x 0 q 3 4
output:
6 8 9 impossible 6
result:
ok 5 lines
Test #3:
score: -100
Time Limit Exceeded
input:
1000000 999999 1000000 1000000 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 2...