Submission #996661

# Submission time Handle Problem Language Result Execution time Memory
996661 2024-06-11T04:01:48 Z berWoW Tree Rotations (POI11_rot) C++14
72 / 100
265 ms 65536 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // namespace __gnu_pbds
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

typedef long long ll;

typedef __gnu_pbds::tree<
int,
__gnu_pbds::null_type,
less<int>,
__gnu_pbds::rb_tree_tag,
__gnu_pbds::tree_order_statistics_node_update>
ordered_set;

const int MAX_N = 2e5 + 10;

int n, cnt;
ll inv[MAX_N];
ordered_set trunks[MAX_N];

int count_inv() {
    int p;
    scanf("%d", &p);
    if (p != 0) { trunks[p].insert(p); return p; }

    int l = count_inv(), r = count_inv();

    if (trunks[l].size() < trunks[r].size()) swap(l, r);

    ll inv_l_r = 0, inv_r_l = 0, i = 0;

    for (auto it = trunks[r].begin(); it != trunks[r].end(); it++) {
        trunks[l].insert(*it);
        int pos = trunks[l].order_of_key(*it);
        inv_l_r += trunks[l].size() - pos - 1;
        inv_r_l += pos - i++;
    }

    inv[l] = inv[l] + inv[r] + min(inv_l_r, inv_r_l);

    return l;
}

int main() {
    scanf("%d", &n);
    printf("%lld\n", inv[count_inv()]);
}

Compilation message

rot.cpp: In function 'int count_inv()':
rot.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     scanf("%d", &p);
      |     ~~~~~^~~~~~~~~~
rot.cpp: In function 'int main()':
rot.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 15964 KB Output is correct
2 Correct 9 ms 16092 KB Output is correct
3 Correct 12 ms 16172 KB Output is correct
4 Correct 8 ms 15960 KB Output is correct
5 Correct 9 ms 15964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 15960 KB Output is correct
2 Correct 8 ms 15964 KB Output is correct
3 Correct 8 ms 16068 KB Output is correct
4 Correct 9 ms 15964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16216 KB Output is correct
2 Correct 10 ms 16196 KB Output is correct
3 Correct 9 ms 16168 KB Output is correct
4 Correct 12 ms 16216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 16988 KB Output is correct
2 Correct 13 ms 17088 KB Output is correct
3 Correct 10 ms 16824 KB Output is correct
4 Correct 11 ms 16988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 18520 KB Output is correct
2 Correct 23 ms 19288 KB Output is correct
3 Correct 61 ms 27208 KB Output is correct
4 Correct 20 ms 19292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 31772 KB Output is correct
2 Correct 50 ms 28248 KB Output is correct
3 Correct 64 ms 29780 KB Output is correct
4 Correct 53 ms 29776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 33620 KB Output is correct
2 Correct 80 ms 34128 KB Output is correct
3 Correct 108 ms 36192 KB Output is correct
4 Correct 79 ms 30800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 142 ms 35024 KB Output is correct
2 Correct 122 ms 36436 KB Output is correct
3 Correct 100 ms 41556 KB Output is correct
4 Correct 111 ms 41368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 179 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 219 ms 51024 KB Output is correct
2 Correct 218 ms 62548 KB Output is correct
3 Correct 251 ms 63316 KB Output is correct
4 Correct 178 ms 57972 KB Output is correct
5 Runtime error 223 ms 65536 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 265 ms 57036 KB Output is correct
2 Correct 263 ms 50232 KB Output is correct
3 Runtime error 239 ms 65536 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -