提出 #12619714


ソースコード 拡げる

#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("sse4.2")

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <sstream>
#include <deque>
#include <queue>
#include <complex>
#include <random>
#include <cassert>
#include <chrono>

using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIXED cout << fixed << setprecision(12)
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define graph vector<vector<int>>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define f first
#define s second
#define hashmap unordered_map
#define hashset unordered_set
#define eps 1e-9
#define mod 1000000007
#define inf 3000000000000000007ll
#define sz(a) signed(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#ifdef DEBUG
    mt19937 gen(857204);
#else
    mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

#ifdef DEBUG
    template<class T> T to_dbg(T x) { return x; }
    template<class T, class U> string to_dbg(pair<T, U> p) {
        stringstream ss;
        ss << '{' << p.f << ',' << p.s << '}';
        return ss.str();
    }
    string to_dbg(string s) { return "\"" + s + "\""; }
    template<class T> string to_dbg(vector<T> a) {
        stringstream ss;
        ss << '{';
        if (sz(a)) ss << to_dbg(a[0]);
        for (int i = 1; i < sz(a); ++i)
            ss << "," << to_dbg(a[i]);
        ss << '}';
        return ss.str();
    }
    template<class T>
    void dbgout(T x) { cout << to_dbg(x) << endl; }
    template<class T, class... U>
    void dbgout(T t, U... u) {
        cout << to_dbg(t) << ", ";
        dbgout(u...);
    }
    #define dbg(...) cout << "[" << #__VA_ARGS__ << "] = ", dbgout(__VA_ARGS__);
#else
    #define dbg(...) 0
#endif

template<class T, class U> inline void checkmin(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void checkmax(T &x, U y) { if (y > x) x = y; }
template<class T, class U> inline bool ifmax(T &x, U y) { if (y > x) return x = y, true; return false; }
template<class T, class U> inline bool ifmin(T &x, U y) { if (y < x) return x = y, true; return false; }
template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline void rsort(T &a) { sort(rall(a)); }
template<class T> inline void reverse(T &a) { reverse(all(a)); }
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.f >> p.s; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }
template<class T> inline T sorted(T a) { sort(a); return a; }

vector<int> a, asc, ans;
int ptr = 0;
graph G;

void recsolve(int v, int p = -1) {
    int ind = lower_bound(all(asc), a[v]) - asc.begin();
    int was = asc[ind];
    asc[ind] = a[v];
    while (asc[ptr] < mod) ++ptr;
    while (ptr > 0 && asc[ptr - 1] == mod) --ptr;
    ans[v] = ptr;
    for (auto i : G[v])
        if (i != p)
            recsolve(i, v);
    asc[ind] = was;
}

signed main() {
    FAST; FIXED;
    int n;
    cin >> n;
    a = vector<int>(n);
    cin >> a;
    G = graph(n);
    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        G[u].pb(v);
        G[v].pb(u);
    }
    ans = vector<int>(n);
    asc = vector<int>(n + 1, mod);
    recsolve(0);
    for (auto i : ans) cout << i << '\n';
    #ifdef DEBUG
        cerr << "Runtime is: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
    #endif
    return 0;
}

提出情報

提出日時
問題 F - LIS on Tree
ユーザ okwedook
言語 C++ (GCC 9.2.1)
得点 600
コード長 3890 Byte
結果 AC
実行時間 113 ms
メモリ 30836 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 1
AC × 17
セット名 テストケース
Sample Sample_01.txt
All Sample_01.txt, caterpillar_01.txt, ni_01.txt, ni_02.txt, ni_03.txt, path_02.txt, path_04.txt, path_07.txt, path_08.txt, rand_01.txt, rand_02.txt, rand_03.txt, rand_04.txt, rand_05.txt, rand_large_01.txt, same_01.txt, star_01.txt
ケース名 結果 実行時間 メモリ
Sample_01.txt AC 2 ms 3656 KiB
caterpillar_01.txt AC 104 ms 20280 KiB
ni_01.txt AC 5 ms 3596 KiB
ni_02.txt AC 2 ms 3552 KiB
ni_03.txt AC 2 ms 3552 KiB
path_02.txt AC 105 ms 26132 KiB
path_04.txt AC 111 ms 18764 KiB
path_07.txt AC 99 ms 21600 KiB
path_08.txt AC 103 ms 25312 KiB
rand_01.txt AC 3 ms 3556 KiB
rand_02.txt AC 2 ms 3668 KiB
rand_03.txt AC 2 ms 3556 KiB
rand_04.txt AC 2 ms 3596 KiB
rand_05.txt AC 2 ms 3656 KiB
rand_large_01.txt AC 113 ms 16652 KiB
same_01.txt AC 109 ms 30836 KiB
star_01.txt AC 89 ms 17088 KiB