QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#710710#5458. Shortest Path Query123456zmyWA 48ms10056kbC++172.6kb2024-11-04 21:08:372024-11-04 21:08:43

Judging History

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

  • [2024-11-04 21:08:43]
  • 评测
  • 测评结果:WA
  • 用时:48ms
  • 内存:10056kb
  • [2024-11-04 21:08:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
long long ans[50011];
int main()
{
    memset(ans,0x3f,sizeof(ans));
    int n,m;
    scanf("%d%d",&n,&m);
    // n=50000,m=100000;
    vector<vector<pair<int,int>>>to(n+1);
    for(int i=1,u,v,w;i<=m;i++)
    {
        scanf("%d%d%d",&u,&v,&w);
        // u=(i+1)/2,v=(i+1)/2+1,w=i&1;
        to[v].emplace_back(u,w);
    }
    int q;
    scanf("%d",&q);
    // q=50000;
    // vector<long long>ans(q+1,0x3f3f3f3f);
    vector<vector<pair<pair<int,int>,int>>>query(n+1);
    for(int i=1,a,b,x;i<=q;i++)
    {
        scanf("%d%d%d",&a,&b,&x);
        // a=rand()%10000+1,b=rand()%10000+1,x=rand()%n+1;
        query[x].push_back({{a,b},i});
    }
    vector<vector<pair<int,int>>>dp(n+1);
    dp[1].push_back({0,0});
    for(int i=2;i<=n;i++)
    {
        dp[i&1023].clear();
        for(auto tmp_:to[i])
        {
            int u=tmp_.first,w=tmp_.second;
            int i_=i&1023,u_=u&1023;
            auto cmp=[&](pair<int,int>i,pair<int,int>j,pair<int,int>k)
            {
                j.first-=i.first,j.second-=i.second;
                k.first-=i.first,k.second-=i.second;
                return k.second*j.first<=j.second*k.first;
            };
            auto ins=[&](vector<pair<int,int>>&v,pair<int,int>p)
            {
                if(v.size()&&v.back().second<=p.second)return;
                if(v.size()&&v.back()==p)v.pop_back();
                while(v.size()>1&&cmp(v[v.size()-2],v[v.size()-1],p))v.pop_back();
                v.push_back(p);
            };
            int l=0;
            vector<pair<int,int>>dp1;
            for(auto&tmp:dp[u_])
            {
                while(l<dp[i_].size()&&dp[i_][l]<tmp)
                    ins(dp1,dp[i_][l++]);
                ins(dp1,{tmp.first+(w^1),tmp.second+w});
            }
            while(l<dp[i_].size())ins(dp1,dp[i_][l++]);
            dp[i_].swap(dp1);
        }
        for(auto tmp:query[i])
        {
            long long a=tmp.first.first,b=tmp.first.second,l=tmp.second;
            int i_=i&1023;
            for(auto&p:dp[i_])ans[l]=min(ans[l],p.first*a+p.second*b);
        }
        //  for(auto&p:dp[i&1023])printf("%d %d\n",p.first,p.second);
    }
    for(auto tmp:query[1])ans[tmp.second]=0;
    long long anss=0;
    for(int i=1;i<=q;i++)//anss^=ans[i];//
        printf("%lld\n",ans[i]);
    // printf("%d %d\n",anss,clock());
    return 0;
}
/*
4 4
1 2 0
1 3 1
2 4 0
3 4 1
3
3 5 2
3 2 4
2 3 4

4 10
1 2 0
1 2 1
2 3 0
2 3 1
3 4 0
3 4 1
1 3 0
1 3 1
2 4 0
2 4 1
2 
1 1 4
1 2 4
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4156kb

input:

4 4
1 2 0
1 3 1
2 4 0
3 4 1
3
3 5 2
3 2 4
2 3 4

output:

3
4
4

result:

ok 3 number(s): "3 4 4"

Test #2:

score: -100
Wrong Answer
time: 48ms
memory: 10056kb

input:

50000 100000
1 2 1
2 3 0
3 4 1
4 5 0
5 6 1
6 7 0
7 8 1
8 9 1
9 10 0
10 11 1
11 12 1
12 13 1
13 14 0
14 15 0
15 16 0
16 17 0
17 18 1
18 19 1
19 20 0
20 21 1
21 22 0
22 23 0
23 24 1
24 25 1
25 26 0
26 27 1
27 28 0
28 29 0
29 30 0
30 31 0
31 32 1
32 33 0
33 34 1
34 35 1
35 36 1
36 37 1
37 38 0
38 39 0
...

output:

170908240
211628934
231474449
255818720
88795740
22774091
47305654
95107307
70249201
256525330
140353585
88500764
273743646
170244509
233942882
193952628
148158145
108426225
187045475
78330668
86995245
206339661
201644556
226201680
294112170
188516895
176346952
107099680
127727215
272590888
19706169...

result:

wrong answer 1st numbers differ - expected: '164602050', found: '170908240'