제출 #411072

#제출 시각아이디문제언어결과실행 시간메모리
411072jamezzzConstruction of Highway (JOI18_construction)C++14
16 / 100
2048 ms4872 KiB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#include <ext/rope>
using namespace __gnu_cxx;

typedef tree<long long, null_type, less<long long>,
rb_tree_tag, tree_order_statistics_node_update> pbds;
//less_equal for identical elements

#define DEBUG

#ifdef DEBUG
#define debug(...) printf(__VA_ARGS__);
#else
#define debug(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;

int n,c[100005],a,b,p[100005],ft[100005];
vii v;

void up(int x,int v){
	while(x<=n)ft[x]+=v,x+=x&-x;
}
int qry(int x){
	int res=0;
	while(x)res+=ft[x],x-=x&-x;
	return res;
}

int main(){
	sf("%d",&n);
	for(int i=1;i<=n;++i){
		sf("%d",&c[i]);
		v.pb(c[i],i);
	}
	sort(all(v));
	int cnt=0,pv=-1;
	for(int i=0;i<n;++i){
		if(v[i].fi!=pv)++cnt,pv=v[i].fi;
		c[v[i].se]=cnt;
	}
	p[1]=-1;
	for(int i=1;i<n;++i){
		sf("%d%d",&a,&b);
		memset(ft,0,sizeof ft);
		p[b]=a;
		ll ans=0;
		while(a!=-1){
			ans+=qry(c[a]);
			up(c[a]+1,1);
			c[a]=c[b];
			a=p[a];
		}
		pf("%lld\n",ans);
	}
}

컴파일 시 표준 에러 (stderr) 메시지

construction.cpp: In function 'int main()':
construction.cpp:54:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |  sf("%d",&n);
      |    ^
construction.cpp:56:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |   sf("%d",&c[i]);
      |     ^
construction.cpp:67:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |   sf("%d%d",&a,&b);
      |     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...