답안 #287835

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
287835 2020-09-01T03:54:20 Z zecookiez Tree Rotations (POI11_rot) PyPy
0 / 100
26 ms 4992 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
template<class C>constexpr int len(const C&c){return int(c.size());}
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int MAXN = 200005;
int N; long long ans, bit[MAXN];

void update(int pos, int val){
    for(int i = pos; i <= N; i += i & -i) bit[i] += val;
}
long long query(int pos){
    long long tot = 0;
    for(int i = pos; i > 0; i -= i & -i) tot += bit[i];
    return tot;
}
vector<int> solve(){
    int A; cin >> A;
    if(A != 0){
        update(A, 1);
        return {A};
    }
    vector<int> left = solve(), right = solve();
    if(len(left) > len(right)) swap(left, right);
    memset(bit, 0, sizeof(bit));
    long long cur, case1 = 0, case2 = 0;
    for(auto i : right) update(i, 1);
    for(auto i : left){
        cur = query(i - 1);
        case1 += cur;
        case2 += len(right) - cur;
    }
    ans += min(case1, case2);
    for(auto i : left) update(i, 1), right.push_back(i);
    return right;
}

int main(){
    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> N; vector<int> arr = solve();
    cout << ans << '\n';
    return 0;
}

Compilation message

File "rot.py", line 5
    using namespace std;
         ^
SyntaxError: invalid syntax
# 결과 실행 시간 메모리 Grader output
1 Runtime error 23 ms 4832 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 23 ms 4832 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 25 ms 4832 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 25 ms 4992 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 24 ms 4832 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 24 ms 4832 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 24 ms 4832 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 26 ms 4884 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 24 ms 4864 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 23 ms 4832 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 24 ms 4832 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -