답안 #674650

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674650 2022-12-25T15:18:54 Z tamthegod Teams (CEOI11_tea) C++17
80 / 100
996 ms 44536 KB
// Make the best become better
// No room for laziness
#include<bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e9;
int n, a[maxN], id[maxN];
int f[maxN], trace[maxN];
int dp[maxN];
pair<int, int> st[4 * maxN];
void ReadInput()
{
    cin >> n;
    for(int i=1; i<=n; i++)
        cin >> a[i];
}
void update(int id, int l, int r, int pos, pair<int, int> val)
{
    if(l == r)
    {
        st[id] = val;
        return;
    }
    int mid = (l + r) / 2;
    if(pos <= mid) update(id * 2, l, mid, pos, val);
    else update(id * 2 + 1, mid + 1, r, pos, val);
    st[id] = max(st[id * 2], st[id * 2 + 1]);
}
pair<int, int> get(int id, int l, int r, int u, int v)
{
    if(l > v || r < u) return {-oo, -oo};
    if(l >= u && r <= v) return st[id];
    int mid = (l + r) / 2;
    return max(get(id * 2, l, mid, u, v), get(id * 2 + 1, mid + 1, r, u, v));
}
bool chk(int val)
{
    memset(dp, -3, sizeof dp);
    dp[0] = 0;
    vector<int> vc;
    vc.pb(0);
    for(int i=1; i<=n; i++)
    {
        int t = id[i];
        int l = max(0, i - val), r = i - a[t];
        int j = upper_bound(vc.begin(), vc.end(), r) - vc.begin() - 1;
        if(j < 0) continue;
        j = vc[j];
        if(j < l) continue;
        dp[i] = dp[j] + 1;
        vc.pb(i);
    }
    return dp[n] == f[n];
}
void Print(int val)
{
    memset(f, -3, sizeof f);
    f[0] = 0;
    vector<int> vc;
    vc.pb(0);
    for(int i=1; i<=n; i++)
    {
        int t = id[i];
        int l = max(0, i - val), r = i - a[t];
        int j = upper_bound(vc.begin(), vc.end(), r) - vc.begin() - 1;
        if(j < 0) continue;
        j = vc[j];
        if(j < l) continue;
        f[i] = f[j] + 1;
        trace[i] = j + 1;
        vc.pb(i);
    }
    cout << f[n] << '\n';
    int i = n;
    while(i)
    {
        cout << i - trace[i] + 1 << " ";
        for(int j=i; j>=trace[i]; j--)
            cout << id[j] << " ";
        i = trace[i] - 1;
        cout << '\n';
    }
}
void Solve()
{
    iota(id + 1, id + n + 1, 1);
    sort(id + 1, id + n + 1, [](int i, int j)
    {
        return a[i] < a[j];
    });
    memset(f, -3, sizeof f);
    f[0] = 0;
    vector<int> vc;
    vc.pb(0);
    for(int i=1; i<=n; i++)
    {
        int t = id[i];
        int l = 0, r = i - a[t];
        int j = upper_bound(vc.begin(), vc.end(), r) - vc.begin() - 1;
        if(j < 0) continue;
        j = vc[j];
        if(j < l) continue;
        f[i] = f[j] + 1;
        vc.pb(i);
    }
    int low = a[id[n]], high = n, mid;
    while(low <= high)
    {
        mid = (low + high) / 2;
        if(chk(mid)) high = mid - 1;
        else low = mid + 1;
    }
  //  cout << low;return;
    Print(low);
}
int32_t main()
{
    //freopen("x.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 4 ms 8148 KB Output is correct
3 Correct 4 ms 8148 KB Output is correct
4 Correct 4 ms 8148 KB Output is correct
5 Correct 4 ms 8148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8180 KB Output is correct
2 Correct 4 ms 8148 KB Output is correct
3 Correct 4 ms 8148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 8148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 8280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8276 KB Output is correct
2 Correct 8 ms 8276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 9852 KB Output is correct
2 Correct 51 ms 10624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 10396 KB Output is correct
2 Correct 48 ms 10528 KB Output is correct
3 Correct 72 ms 10740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 600 ms 31964 KB Output is correct
2 Correct 543 ms 32196 KB Output is correct
3 Correct 716 ms 30556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 928 ms 36864 KB Output is correct
2 Correct 794 ms 43796 KB Output is correct
3 Correct 772 ms 41988 KB Output is correct
4 Correct 800 ms 40340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 556 ms 27856 KB Output is correct
2 Correct 189 ms 30668 KB Output is correct
3 Correct 780 ms 42704 KB Output is correct
4 Correct 996 ms 44536 KB Output is correct