Submission #701454

# Submission time Handle Problem Language Result Execution time Memory
701454 2023-02-21T08:59:25 Z tamthegod Lightning Conductor (POI11_pio) C++17
45 / 100
1000 ms 46336 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];
int mark[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()
{
    mark[0] = 1;
    SparseTable();
    for(int i=1; i<=n; i++)
    {
        int res = 0;
        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);
            int val = get(l, r) + len - a[i];
            if(res < val)
            {
                res = val;
                mark[i] = len;
            }
            len--;
        }
        ans[i] = res;
    }
    mark[n + 1] = 1;
    for(int i=n; i>=1; i--)
    {
        int res = 0;
        int len = (int)sqrt(n - i - 1) + 1;
        while(len >= max(1, mark[i + 1] - 1))
        {
            int l = i + (len - 1) * (len - 1) + 1;
            int r = i + len * len;
            r = min(r, n);
            int val = get(l, r) + len - a[i];
            if(res < val)
            {
                res = val;
                mark[i] = len;
            }
            len--;
        }
        ans[i] = max(ans[i], res);
    }
    for(int i=1; i<=n; i++)
        cout << ans[i] << '\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 Correct 1 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 4812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 6620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 7480 KB Output is correct
2 Correct 54 ms 7380 KB Output is correct
3 Incorrect 72 ms 7732 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 112 ms 10584 KB Output is correct
2 Correct 130 ms 10460 KB Output is correct
3 Incorrect 107 ms 11016 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 349 ms 22368 KB Output is correct
2 Correct 354 ms 22196 KB Output is correct
3 Incorrect 347 ms 22704 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 673 ms 36072 KB Output is correct
2 Correct 664 ms 34036 KB Output is correct
3 Incorrect 690 ms 36136 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1049 ms 45072 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 46336 KB Time limit exceeded
2 Halted 0 ms 0 KB -