제출 #1227527

#제출 시각아이디문제언어결과실행 시간메모리
1227527omarrrrConstruction of Highway (JOI18_construction)C++20
7 / 100
2093 ms532 KiB
#include<bits/stdc++.h> #define ll long long #define F first #define S second #define pb push_back using namespace std; const ll N=1e6,mod=1e9 +7; ll a,b,d,n,m,l,k,q; ll t[N]; ll p[N]; ll x,y; ll c; ll cal(ll y){ vector<ll>in; in.pb(t[y]); ll res=0; if(y==3){ x++; } t[y]=c; while(y!=p[y]){ y=p[y]; res+=(lower_bound(in.begin(),in.end(),t[y])-in.begin()); in.pb(t[y]); t[y]=c; sort(in.begin(),in.end()); } return res; } int main(){ ios_base::sync_with_stdio(0),cin.tie(0); ll T=1; // cin>>T; while(T--){ cin>>n; for(ll i=0;i<n;i++){ cin>>t[i]; p[i]=-1; } p[0]=0; for(ll i=0;i<n-1;i++){ // ll res=0; cin>>x>>y; x--;y--; p[y]=x; c=t[y]; cout<<cal(x)<<"\n"; } } return 0; } /* 4 10 3 6 2 9 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...