제출 #1120312

#제출 시각아이디문제언어결과실행 시간메모리
1120312hihihihawUntitled (POI11_rot)C++17
100 / 100
404 ms36700 KiB
#pragma GCC optimize("O3,unroll-loops,fast-math")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define int long long
#define pb push_back
#define pii pair<int, int>
#define sz(v) (int)v.size()
#define fi first
#define se second
#define INF 999999992000000023
#define MOD 1000000007
#define cint(x) int x;cin >> x;
#define cinarr(a, n)  int a[n]; for (int i = 0; i < n; i++) cin >> a[i];
#define coutarr(a) for (auto d : a){cout << d << " ";} cout << endl;
#define coutarrD(a) for (auto d : a) {cout << d.fi << "," << d.se << " "; }cout << endl;
#define BERKAY_TUP  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define ld long double
#define mid (start + end) / 2
#define vvi vector<vector<int>>

int t=1;
int interactive=0;
int usaco=0;
int testCase=0;
//ordered_set v[100023];
int ans;
ordered_set calc(int x){
    ordered_set zz;
    int a;
    cin>>a;
    if (a!=0){
        zz.insert(a);
        return zz;
    }
    ordered_set z1=calc(2*x);
    ordered_set z2=calc(2*x+1);
    if (sz(z1)>sz(z2)) z1.swap(z2);
    int ans1=0,ans2=0;
    for (auto d:z1){
        int g=z2.order_of_key(d);
        ans1+=g;
        ans2+=sz(z2)-g;
    }
    ans+=min(ans1,ans2);
    zz.swap(z2);
    for (auto d:z1){
        zz.insert(d);
    }
    return zz;
}
void solve(){
    int n;
    cin>>n;
    calc(1);
    cout<<ans<<endl;
    

    

    



   
    

}

int32_t main(){
    BERKAY_TUP;
    if (usaco)
    {
        freopen("help.in", "r", stdin);
        freopen("help.out", "w", stdout);
    }
    if (!interactive)
    {
#ifdef Local
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        // freopen("wormsort.out", "w", stdout);
#endif
    }
    if (t == 1)
        solve();
    else
    {
        cin >> t;
        while (t--)
        {
            testCase++;
            solve();
        }
    }

    return 0;
}

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

rot.cpp: In function 'int32_t main()':
rot.cpp:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         freopen("help.in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
rot.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |         freopen("help.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...