제출 #1283706

#제출 시각아이디문제언어결과실행 시간메모리
1283706thaibeo123Construction of Highway (JOI18_construction)C++20
16 / 100
2095 ms2728 KiB
#include <bits/stdc++.h> using namespace std; #define NAME "A" #define ll long long #define fi first #define se second #define pb push_back #define all(x) x.begin(), x.end() #define MASK(x) (1ll << (x)) #define BIT(x, i) (((x) >> (i)) & 1) const int N = 2e5 + 5; struct FenwickTree { int n; vector<int> fen; FenwickTree() {} FenwickTree(int n): n(n), fen(n + 1) {} void update(int x, int v) { for (int i = x; i <= n; i += i & -i) { fen[i] += v; } } int get(int x) { int res = 0; for (int i = x; i > 0; i -= i & -i) { res += fen[i]; } return res; } }; FenwickTree fen; int n; int c[N], a[N], p[N]; vector<int> vals; int getans(int u) { int ans = 0; while (u != 0) { ans += fen.get(a[u] - 1); //cout << u << " " << a[u] << " " << fen.get(a[u]) << "\n"; fen.update(a[u], 1); u = p[u]; } return ans; } void input() { cin >> n; for (int i = 1; i <= n; i++) { cin >> c[i]; vals.pb(c[i]); } sort(all(vals)); vals.erase(unique(all(vals)), vals.end()); for (int i = 1; i <= n; i++) { c[i] = upper_bound(all(vals), c[i]) - vals.begin(); a[i] = c[i]; } } void solve() { fen = FenwickTree(vals.size()); for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; p[v] = u; int ans = getans(u); while (u != 0) { fen.update(a[u], -1); u = p[u]; } int cost = c[v]; while (v != 0) { a[v] = cost; v = p[v]; } cout << ans << "\n"; } } signed main() { if (fopen(NAME".INP", "r")) { freopen(NAME".INP", "r", stdin); freopen(NAME".OUT", "w", stdout); } cin.tie(0)->sync_with_stdio(0); int t = 1; //cin >> t; while (t--) { input(); solve(); } return 0; }

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

construction.cpp: In function 'int main()':
construction.cpp:89:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |         freopen(NAME".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
construction.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         freopen(NAME".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...