Submission #701444

# Submission time Handle Problem Language Result Execution time Memory
701444 2023-02-21T08:46:57 Z tamthegod Lightning Conductor (POI11_pio) C++17
0 / 100
536 ms 48284 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 = 5e5 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n;
int a[maxN];
int f[21][maxN];
int lg[maxN];
int ans[maxN];
void SparseTable()
{
    for(int i=1; i<=n; i++)
        f[0][i] = a[i];
    for(int k=1; k<=lg[n]; k++)
        for(int i=1; i<=n; i++)
        {
            int j = i + (1 << (k - 1));
            if(j > n) f[k][i] = f[k - 1][i];
            else f[k][i] = max(f[k - 1][i], f[k - 1][j]);
        }
}
inline int get(int l, int r)
{
    int k = lg[r - l + 1];
    return max(f[k][l], f[k][r - (1 << k) + 1]);
}
void ReadInput()
{
    cin >> n;
    for(int i=1; i<=n; i++)
        cin >> a[i];
    for(int i=2; i<maxN; i++)
        lg[i] = lg[i / 2] + 1;
}
void Solve()
{
    SparseTable();
    for(int i=1; i<=n; i++)
    {
        int res = ans[i - 1] + a[i - 1] - a[i] - 1;
        int len = (int)sqrt(i - 2) + 1;
        while(len >= 1)
        {
            int r = i - (len - 1) * (len - 1) - 1;
            int l = i - len * len;
            l = max(1, l);
            if(a[i] + res - len >= get(l, i - 1)) break;
            res = max(res, get(l, r) + len - a[i]);
            len--;
        }
        if(a[i] > a[i - 1])
        {
            len = (int)sqrt(n - i - 1) + 1;
            while(len >= 1)
            {
                int l = i + (len - 1) * (len - 1) + 1;
                int r = i + len * len;
                r = min(r, n);
                if(a[i] + res - len >= get(i + 1, r)) break;
                res = max(res, get(l, r) + len - a[i]);
                len--;
            }
        }
        cout << (ans[i] = res) << '\n';
    }
}
int32_t main()
{
  //  freopen("sol.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 4632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 6388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 10060 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 60 ms 21300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 97 ms 34656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 536 ms 48284 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 121 ms 45896 KB Output isn't correct
2 Halted 0 ms 0 KB -