# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
701400 | Do_you_copy | Lightning Conductor (POI11_pio) | C++17 | 89 ms | 11172 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fi first
#define se second
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
using namespace std;
using ll = long long;
using pii = pair <int, int>;
const int maxN = 5e5 + 10;
const int inf = 0x3f3f3f3f;
//const int Mod =
int n;
int a[maxN];
int pre[maxN];
int suf[maxN];
void Init(){
cin >> n;
for (int i = 1; i <= n; ++i){
cin >> a[i];
}
int maxx = -1;
for (int i = 1; i <= n; ++i){
if (a[i] <= maxx) continue;
maxx = a[i];
for (int j = 1; i + (j - 1) * (j - 1) + 1 <= n; ++j){
pre[i + (j - 1) * (j - 1) + 1] = max(pre[i + (j - 1) * (j - 1) + 1], a[i] + j);
}
}
maxx = -1;
for (int i = n; i >= 1; --i){
if (a[i] <= maxx) continue;
maxx = a[i];
for (int j = 1; i - (j - 1) * (j - 1) - 1 > 0; ++j){
suf[i - (j - 1) * (j - 1) - 1] = max(suf[i - (j - 1) * (j - 1) - 1], a[i] + j);
}
}
for (int i = 1; i <= n; ++i){
pre[i] = max(pre[i], pre[i - 1]);
}
for (int i = n; i >= 1; --i){
suf[i] = max(suf[i], suf[i + 1]);
}
for (int i = 1; i <= n; ++i){
cout << max({suf[i], pre[i], a[i]}) - a[i] << "\n";
}
}
#define taskname "test"
signed main(){
faster
if (fopen(taskname ".inp", "r")){
freopen(taskname ".inp", "r", stdin);
freopen(taskname ".out", "w", stdout);
}
int tt = 1;
//cin >> tt;
while (tt--){
Init();
}
if (fopen("timeout.txt", "r")){
ofstream timeout("timeout.txt");
cerr << "Time elapsed: " << signed(double(clock()) / CLOCKS_PER_SEC * 1000) << "ms\n";
timeout << signed(double(clock()) / CLOCKS_PER_SEC * 1000);
timeout.close();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |