# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
284979 | 2020-08-28T08:39:41 Z | achibasadzishvili | Discharging (NOI20_discharging) | C++17 | 985 ms | 265072 KB |
#include<bits/stdc++.h> #define ll long long #define f first #define s second #define pb push_back using namespace std; ll n,a[1000002]; ll dp[1000002],rm[1000002][21],po[2000002],pw[200],raod,mn,lo; ll lef[1000002],rig[1000002]; vector<ll>del[1000002]; ll get(ll x,ll y){ return a[y]; lo = po[y - x + 1]; if(rm[y][lo] > rm[x + pw[lo] - 1][lo])return rm[y][lo]; return rm[x + pw[lo] - 1][lo]; } ll ind(ll x,ll y){ if(y == n)return -1; ll l = y + 1,r = n,mid,ind = -1; while(r >= l){ mid = (l + r) / 2; if(dp[x] + get(x + 1 , mid) * (n - x) > dp[y] + get(y + 1 , mid) * (n - y)){ r = mid - 1; ind = mid; } else l = mid + 1; } return ind; } void delet(ll x){ if(lef[x] == rig[x] && lef[x] == -1)return; if(lef[x] == -1){ lef[rig[x]] = -1; mn = rig[x]; rig[x] = -1; return; } rig[lef[x]] = rig[x]; lef[rig[x]] = lef[x]; ll cur = ind(lef[x] , rig[x]); if(cur == -1){ lef[x] = rig[x] = -1; return; } del[cur].pb(lef[x]); lef[x] = rig[x] = -1; } int main(){ scanf("%d",&n); for(int i=1; i<=n; i++){ scanf("%d",&a[i]); } //int cl = clock(); //n = 1000000; //for(int i=1; i<=n; i++) // a[i] = n-i+1; pw[0] = 1; for(int i=1; i<=21; i++){ pw[i] = pw[i - 1] * 2; for(int j=pw[i - 1]; j<pw[i]; j++){ if(j <= 1000000) po[j] = i - 1; } } for(int i=0; i<=n; i++) lef[i] = rig[i] = -1; for(int i=1; i<=n; i++){ rm[i][0] = a[i]; for(int j=1; j<=20; j++){ if(i - pw[j] + 1 >= 1) rm[i][j] = max(rm[i][j - 1] , rm[i - pw[j - 1]][j - 1]); } } //cout << clock() - cl << '\n'; for(int i=1; i<=n; i++){ for(int j=0; j<del[i].size(); j++){ delet(del[i][j]); } dp[i] = dp[mn] + get(mn + 1 , i) * (n - mn); rig[i - 1] = i; lef[i] = i - 1; ll cur = ind(i - 1 , i); if(cur != -1) del[cur].pb(i - 1); } //cout << "time: " << clock() - cl << " " << raod << '\n'; cout << dp[n]; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 31744 KB | Output is correct |
2 | Correct | 22 ms | 31744 KB | Output is correct |
3 | Incorrect | 25 ms | 31616 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 32000 KB | Output is correct |
2 | Correct | 23 ms | 32000 KB | Output is correct |
3 | Correct | 24 ms | 32000 KB | Output is correct |
4 | Correct | 24 ms | 32000 KB | Output is correct |
5 | Correct | 24 ms | 32000 KB | Output is correct |
6 | Correct | 23 ms | 32000 KB | Output is correct |
7 | Correct | 24 ms | 31992 KB | Output is correct |
8 | Correct | 23 ms | 32000 KB | Output is correct |
9 | Correct | 23 ms | 32000 KB | Output is correct |
10 | Correct | 23 ms | 31992 KB | Output is correct |
11 | Correct | 24 ms | 32000 KB | Output is correct |
12 | Correct | 23 ms | 32000 KB | Output is correct |
13 | Correct | 23 ms | 32000 KB | Output is correct |
14 | Correct | 23 ms | 31992 KB | Output is correct |
15 | Correct | 23 ms | 32000 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 32000 KB | Output is correct |
2 | Correct | 23 ms | 32000 KB | Output is correct |
3 | Correct | 24 ms | 32000 KB | Output is correct |
4 | Correct | 24 ms | 32000 KB | Output is correct |
5 | Correct | 24 ms | 32000 KB | Output is correct |
6 | Correct | 23 ms | 32000 KB | Output is correct |
7 | Correct | 24 ms | 31992 KB | Output is correct |
8 | Correct | 23 ms | 32000 KB | Output is correct |
9 | Correct | 23 ms | 32000 KB | Output is correct |
10 | Correct | 23 ms | 31992 KB | Output is correct |
11 | Correct | 24 ms | 32000 KB | Output is correct |
12 | Correct | 23 ms | 32000 KB | Output is correct |
13 | Correct | 23 ms | 32000 KB | Output is correct |
14 | Correct | 23 ms | 31992 KB | Output is correct |
15 | Correct | 23 ms | 32000 KB | Output is correct |
16 | Correct | 816 ms | 263704 KB | Output is correct |
17 | Correct | 902 ms | 262776 KB | Output is correct |
18 | Correct | 774 ms | 265072 KB | Output is correct |
19 | Correct | 844 ms | 261484 KB | Output is correct |
20 | Correct | 893 ms | 261620 KB | Output is correct |
21 | Correct | 914 ms | 262556 KB | Output is correct |
22 | Correct | 883 ms | 262644 KB | Output is correct |
23 | Correct | 985 ms | 260592 KB | Output is correct |
24 | Correct | 923 ms | 261208 KB | Output is correct |
25 | Correct | 907 ms | 260480 KB | Output is correct |
26 | Correct | 959 ms | 258932 KB | Output is correct |
27 | Correct | 827 ms | 264052 KB | Output is correct |
28 | Correct | 885 ms | 262008 KB | Output is correct |
29 | Correct | 868 ms | 259828 KB | Output is correct |
30 | Correct | 968 ms | 259572 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 587 ms | 258680 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 31744 KB | Output is correct |
2 | Correct | 22 ms | 31744 KB | Output is correct |
3 | Incorrect | 25 ms | 31616 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 31744 KB | Output is correct |
2 | Correct | 22 ms | 31744 KB | Output is correct |
3 | Incorrect | 25 ms | 31616 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |