제출 #699821

#제출 시각아이디문제언어결과실행 시간메모리
699821vjudge1Construction of Highway (JOI18_construction)C++17
16 / 100
2094 ms117096 KiB
#include "bits/stdc++.h"
using namespace std;

// #define ORD_SET
// #define ROPE
#ifdef ORD_SET
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    template<typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#endif
#ifdef ROPE
    #include <ext/rope>
    using namespace __gnu_cxx;
#endif        

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

using ll = long long;
using ld = long double;
#define pb push_back
#define ff first
#define ss second
#define sz(x) (ll)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// #define ll int
void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
void NotInteractive() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
void pre(ll a) { cout<<fixed<<setprecision(a); }
ll bit(ll a) { return __builtin_popcountll(a); }
ll binmul(ll a, ll b, ll c) { ll res = 0; while(b) { if(b&1) (res += a) %= c; (a += a) %= c; b >>= 1; } return res; }
ll binpow(ll a, ll b, ll c) { ll res = 1; while(b) { if(b&1) (res *= a) %= c; (a *= a) %= c; b >>= 1; } return res; }
template<typename T> T gcd(T a, T b) { if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b) { return a/gcd(a, b)*b; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ld rnd() { return rng()%INT_MAX*1.0/INT_MAX; }

struct sn { ll l, r, x; };
ll B = 316;
const ll mod = 1e9+7;
const ll inf = 1e18+7;
const ll MX = LLONG_MAX;
const ll MN = LLONG_MIN;
const ld P = acos(-1.0);
const ll N = 3e5+5;
ll c[N], t[N*4];
vector<ll> g[N];

void update(ll v, ll tl, ll tr, ll pos) {
    if(tl==tr) {
        t[v]++;
        return;
    }
    ll tm = (tl+tr)/2;
    if(pos<=tm) update(v*2, tl, tm, pos);
    else update(v*2+1, tm+1, tr, pos);
    t[v] = t[v*2]+t[v*2+1];
}

ll get(ll v, ll tl, ll tr, ll l, ll r) {
    if(r<tl || tr<l) return 0;
    if(l<=tl && tr<=r) return t[v];
    ll tm = (tl+tr)/2;
    return get(v*2, tl, tm, l, r)+get(v*2+1, tm+1, tr, l, r);
}

void kigash() {
    ll n;
    cin>>n;
    map<ll, ll> m; set<ll> st; ll ks = 0;
    for(ll i=1; i<=n; i++) cin>>c[i], st.insert(c[i]);
    for(auto to:st) m[to] = ++ks;
    for(ll i=1; i<=n; i++) c[i] = m[c[i]];
    g[1].pb(1);
    for(ll k=1; k<n; k++) {
        ll u, v, cnt = 0;
        cin>>u>>v;
        for(ll i=0; i<=(n+1)*4; i++) t[i] = 0;
        for(ll i=0; i<sz(g[u]); i++) {
            cnt += get(1, 1, n+1, c[g[u][i]]+1, n+1);
            update(1, 1, n+1, c[g[u][i]]);
        }
        cout<<cnt<<"\n";
        for(ll i=0; i<sz(g[u]); i++) c[g[u][i]] = c[v];
        g[v] = g[u];
        g[v].pb(v);
    }
    return;
}

signed main(/*Kigash Amir*/) {
    // freopen("");
    NotInteractive();
    // precalc();
    
    ll tt = 1;
    // cin>>tt;
    for(ll i=1; i<=tt; i++) kigash();
    
    exit(0);
}

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

construction.cpp: In function 'void freopen(std::string)':
construction.cpp:31:33: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
      |                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
construction.cpp:31:73: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
      |                                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...