QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#103852#5669. Traveling in Jade CityRobert_JYH#TL 7ms52044kbC++171.7kb2023-05-07 18:29:532023-05-07 18:29:53

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-07 18:29:53]
  • 评测
  • 测评结果:TL
  • 用时:7ms
  • 内存:52044kb
  • [2023-05-07 18:29:53]
  • 提交

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...

output:


result: