답안 #400442

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
400442 2021-05-08T04:21:34 Z JerryLiu06 Tree Rotations (POI11_rot) C++17
0 / 100
52 ms 65540 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using ll = long long;
using db = long double;
using str = string;
 
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
 
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
 
#define mp make_pair
#define f first
#define s second

#define sz(x) (ll)(x).size()
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sor(x) sort(all(x))
#define ft front()
#define bk back()
#define pb push_back
#define pf push_front
 
#define lb lower_bound
#define ub upper_bound
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a)
#define EACH(a, x) for (auto& a : x)

const int MOD = 1e9 + 7;
const int MX = 2e5 + 10;
const ll INF = 1e18;

int N, timer = 1; ll ans; vi child[4 * MX]; Tree<int> T[4 * MX];

void DFS1(int X) {
    int Y; cin >> Y; 
    
    if (Y == 0) { 
        child[X].pb(++timer); DFS1(timer);
        child[X].pb(++timer); DFS1(timer);  
    }
    else T[X].insert(Y);
}
void DFS2(int X) {
    EACH(Y, child[X]) {
        DFS2(Y); if (sz(T[X]) < sz(T[Y])) T[X].swap(T[Y]);

        ll num = 0; EACH(C, T[Y]) num += T[X].order_of_key(C);

        ans += min(num, sz(T[X]) * sz(T[Y]) - num);

        EACH(C, T[Y]) T[X].insert(C); T[Y].clear();
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> N; DFS1(1); DFS2(1); cout << ans;
}

Compilation message

rot.cpp: In function 'void DFS2(int)':
rot.cpp:46:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   46 | #define EACH(a, x) for (auto& a : x)
      |                    ^~~
rot.cpp:71:9: note: in expansion of macro 'EACH'
   71 |         EACH(C, T[Y]) T[X].insert(C); T[Y].clear();
      |         ^~~~
rot.cpp:71:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   71 |         EACH(C, T[Y]) T[X].insert(C); T[Y].clear();
      |                                       ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 50 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 50 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 46 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 48 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 52 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 48 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 46 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 48 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 48 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 48 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 47 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -