Submission #598379

# Submission time Handle Problem Language Result Execution time Memory
598379 2022-07-18T08:14:23 Z AGE Transport (COCI19_transport) C++14
0 / 130
391 ms 22220 KB
#include<bits/stdc++.h>
#define F first
#define S second
#define int long long
#define pb push_back

using namespace std;
const int N=2e5+10,M=2e3,mod=1e9+7;
int cost[N],seg[N*4],ans[N];
map<pair<int,int>,int>mp;

void build(int v,int tl,int tr){

    if(tl==tr){
        seg[v]=ans[tl];
        return ;
    }

    int tm=(tl+tr)/2;

    build(v*2,tl,tm);
    build(v*2+1,tm+1,tr);

    seg[v]=min(seg[v*2],seg[v*2+1]);

}

int get(int v,int tl,int tr,int l,int r){

    if(tl>r||tr<l){
        return 1e18;
    }

    if(tl>=l&&tr<=r)
        return seg[v];

    int tm=(tl+tr)/2;

    return min(get(v*2,tl,tm,l,r),get(v*2+1,tm+1,tr,l,r));

}

int n;
bool ok(int mid,int val,int start){

    if(start+mid-1>n)
        return 0;

    int ans1=get(1,1,n,start,start+mid-1);
    return ans1>=val;

}

main()
{

    cin>>n;

    for(int i=1;i<=n;i++)
        cin>>cost[i];

    for(int i=0;i<n-1;i++){
        int x,y,z;
        cin>>x>>y>>z;
        mp[{x,y}]=z;
        mp[{y,x}]=z;
    }

    ans[0]=0;

    for(int i=1;i<=n;i++){
        ans[i+1]=ans[i]+cost[i]-mp[{i,i+1}];
    }

    build(1,1,n);
    int anss=0;

    for(int i=1;i<=n;i++){

        int val=ans[i];
        int l=0,r=n+1;

        while(l<r){

            int mid=(l+r+1)/2;
            if(ok(mid,val,i))
                l=mid;
            else
                r=mid-1;

        }

        anss+=l-1;

    }

    cout<<anss*2<<endl;


    return 0;
}

Compilation message

transport.cpp:54:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   54 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 167 ms 7384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 256 ms 9676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 323 ms 13748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 91 ms 6300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 161 ms 10448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 232 ms 13680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 321 ms 18180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 391 ms 22220 KB Output isn't correct
2 Halted 0 ms 0 KB -