Submission #701422

# Submission time Handle Problem Language Result Execution time Memory
701422 2023-02-21T08:22:03 Z tamthegod Lightning Conductor (POI11_pio) C++17
72 / 100
1000 ms 45512 KB
// Make the best become better
// No room for laziness
#include<bits/stdc++.h>

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#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 = 1e18;
int n;
int a[maxN];
int f[21][maxN];
int lg[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 = 0;
        int len = 1;
        while(true)
        {
            int r = i - (len - 1) * (len - 1) - 1;
            int l = i - len * len;
            l = max(1, l);
            if(l > r) break;
            res = max(res, get(l, r) + len - a[i]);
            len++;
        }
        len = 1;
        while(true)
        {
            int l = i + (len - 1) * (len - 1) + 1;
            int r = i + len * len;
            r = min(r, n);
            if(l > r) break;
            res = max(res, get(l, r) + len - a[i]);
            len++;
        }
        cout << 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 Correct 2 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 6484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 8080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 8876 KB Output is correct
2 Correct 118 ms 8832 KB Output is correct
3 Correct 118 ms 9160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 217 ms 11716 KB Output is correct
2 Correct 225 ms 11732 KB Output is correct
3 Correct 217 ms 12184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 751 ms 22388 KB Output is correct
2 Correct 742 ms 22604 KB Output is correct
3 Correct 741 ms 23276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1063 ms 34396 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1069 ms 45512 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1074 ms 44532 KB Time limit exceeded
2 Halted 0 ms 0 KB -