Submission #47384

#TimeUsernameProblemLanguageResultExecution timeMemory
47384Just_Solve_The_ProblemConstruction of Highway (JOI18_construction)C++11
16 / 100
444 ms4288 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define ll long long #define pii pair < int, int > #define fr first #define sc second #define mk make_pair #define sz(s) (int)s.size() #define all(s) s.begin(), s.end() #define ok puts("ok"); #define whatis(x) cerr << #x << " = " << x << endl; #define pause system("pause"); #define random rand() ^ (rand() << 5) const int N = (int)1e5 + 7; const int inf = (int)1e9 + 7; struct fenwick { int tree[N]; fenwick() { memset(tree, 0, sizeof tree); } void upd(int pos, int val) { for (; pos < N; pos += pos & -pos) { tree[pos] += val; } } int get(int r) { int res = 0; for (; r > 0; r -= r & -r) { res += tree[r]; } return res; } }tr; int n; int c[N], b[N]; pii ar[N]; int pr[N]; vector < int > gr[N]; void dfs(int v) { for (int to : gr[v]) { pr[to] = v; dfs(to); } } main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &c[i]); b[i] = c[i]; } if (n > 4000) return 0; sort(b + 1, b + n + 1); int m = unique(b + 1, b + n + 1) - b - 1; for (int i = 1; i <= n; i++) { c[i] = lower_bound(b + 1, b + m + 1, c[i]) - b; } for (int i = 1; i < n; i++) { int u, v; scanf("%d %d", &u, &v); gr[u].pb(v); ar[i] = mk(u, v); } dfs(1); for (int i = 1; i < n; i++) { int ans = 0; tr = fenwick(); int v = ar[i].fr; while (v != 0) { ans += tr.get(c[v] - 1); tr.upd(c[v], 1); c[v] = c[ar[i].sc]; v = pr[v]; } printf("%d\n", ans); } }

Compilation message (stderr)

construction.cpp:54:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
construction.cpp: In function 'int main()':
construction.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
construction.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &c[i]);
     ~~~~~^~~~~~~~~~~~~
construction.cpp:69:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &u, &v);
     ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...