Submission #285014

# Submission time Handle Problem Language Result Execution time Memory
285014 2020-08-28T08:56:34 Z achibasadzishvili Discharging (NOI20_discharging) C++17
100 / 100
817 ms 174616 KB
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
int n,a[1000002];
ll dp[1000002];
int rm[1000002][21],po[2000002],pw[200],raod,mn,lo,pr[2000002];
int lef[1000002],rig[1000002];
vector<int>del[1000002];
int get(int x,int y){
    return pr[y];
    if(rm[y][po[y - x + 1]] > rm[x + pw[po[y - x + 1]] - 1][lo])return rm[y][po[y - x + 1]];
    return rm[x + pw[po[y - x + 1]] - 1][po[y - x + 1]];
}
int ind(int x,int 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] + (ll)get(x + 1 , mid) * (n - x) > dp[y] + (ll)get(y + 1 , mid) * (n - y)){
            r = mid - 1;
            ind = mid;
        }
        else
            l = mid + 1;
    }
    return ind;
}
void delet(int 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];
    int 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]);
        pr[i] = max(a[i] , pr[i - 1]);
    }
    //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<=19; j++){
            rm[i][j] = rm[i][j - 1];
            if(i - pw[j] + 1 >= 1 && rm[i - pw[j - 1]][j - 1]>rm[i][j])
                rm[i][j] = 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] + (ll)get(mn + 1 , i) * (ll)(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

Discharging.cpp:5: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    5 | #pragma GCC optimization ("O3")
      | 
Discharging.cpp:6: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    6 | #pragma GCC optimization ("unroll-loops")
      | 
Discharging.cpp: In function 'int main()':
Discharging.cpp:85:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |         for(int j=0; j<del[i].size(); j++){
      |                      ~^~~~~~~~~~~~~~
Discharging.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   55 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
Discharging.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   57 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 18 ms 27776 KB Output is correct
2 Correct 18 ms 27776 KB Output is correct
3 Correct 18 ms 27776 KB Output is correct
4 Correct 18 ms 27776 KB Output is correct
5 Correct 19 ms 27776 KB Output is correct
6 Correct 18 ms 27776 KB Output is correct
7 Correct 18 ms 27776 KB Output is correct
8 Correct 18 ms 27776 KB Output is correct
9 Correct 19 ms 27776 KB Output is correct
10 Correct 18 ms 27776 KB Output is correct
11 Correct 18 ms 27776 KB Output is correct
12 Correct 19 ms 27776 KB Output is correct
13 Correct 18 ms 27776 KB Output is correct
14 Correct 18 ms 27776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 28032 KB Output is correct
2 Correct 18 ms 28032 KB Output is correct
3 Correct 20 ms 28032 KB Output is correct
4 Correct 20 ms 27904 KB Output is correct
5 Correct 19 ms 28032 KB Output is correct
6 Correct 19 ms 27904 KB Output is correct
7 Correct 19 ms 28032 KB Output is correct
8 Correct 19 ms 27904 KB Output is correct
9 Correct 19 ms 28032 KB Output is correct
10 Correct 18 ms 27904 KB Output is correct
11 Correct 19 ms 27960 KB Output is correct
12 Correct 18 ms 28032 KB Output is correct
13 Correct 19 ms 28008 KB Output is correct
14 Correct 19 ms 28032 KB Output is correct
15 Correct 19 ms 27904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 28032 KB Output is correct
2 Correct 18 ms 28032 KB Output is correct
3 Correct 20 ms 28032 KB Output is correct
4 Correct 20 ms 27904 KB Output is correct
5 Correct 19 ms 28032 KB Output is correct
6 Correct 19 ms 27904 KB Output is correct
7 Correct 19 ms 28032 KB Output is correct
8 Correct 19 ms 27904 KB Output is correct
9 Correct 19 ms 28032 KB Output is correct
10 Correct 18 ms 27904 KB Output is correct
11 Correct 19 ms 27960 KB Output is correct
12 Correct 18 ms 28032 KB Output is correct
13 Correct 19 ms 28008 KB Output is correct
14 Correct 19 ms 28032 KB Output is correct
15 Correct 19 ms 27904 KB Output is correct
16 Correct 672 ms 163436 KB Output is correct
17 Correct 709 ms 163960 KB Output is correct
18 Correct 603 ms 166900 KB Output is correct
19 Correct 669 ms 162936 KB Output is correct
20 Correct 692 ms 162716 KB Output is correct
21 Correct 732 ms 163832 KB Output is correct
22 Correct 691 ms 164216 KB Output is correct
23 Correct 817 ms 160760 KB Output is correct
24 Correct 738 ms 161700 KB Output is correct
25 Correct 725 ms 161304 KB Output is correct
26 Correct 813 ms 159384 KB Output is correct
27 Correct 648 ms 165112 KB Output is correct
28 Correct 717 ms 163064 KB Output is correct
29 Correct 697 ms 160628 KB Output is correct
30 Correct 760 ms 159732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 457 ms 165368 KB Output is correct
2 Correct 476 ms 165076 KB Output is correct
3 Correct 479 ms 165112 KB Output is correct
4 Correct 471 ms 165240 KB Output is correct
5 Correct 468 ms 165064 KB Output is correct
6 Correct 468 ms 165280 KB Output is correct
7 Correct 459 ms 165240 KB Output is correct
8 Correct 457 ms 165112 KB Output is correct
9 Correct 471 ms 165172 KB Output is correct
10 Correct 464 ms 165216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 27776 KB Output is correct
2 Correct 18 ms 27776 KB Output is correct
3 Correct 18 ms 27776 KB Output is correct
4 Correct 18 ms 27776 KB Output is correct
5 Correct 19 ms 27776 KB Output is correct
6 Correct 18 ms 27776 KB Output is correct
7 Correct 18 ms 27776 KB Output is correct
8 Correct 18 ms 27776 KB Output is correct
9 Correct 19 ms 27776 KB Output is correct
10 Correct 18 ms 27776 KB Output is correct
11 Correct 18 ms 27776 KB Output is correct
12 Correct 19 ms 27776 KB Output is correct
13 Correct 18 ms 27776 KB Output is correct
14 Correct 18 ms 27776 KB Output is correct
15 Correct 18 ms 28032 KB Output is correct
16 Correct 18 ms 28032 KB Output is correct
17 Correct 20 ms 28032 KB Output is correct
18 Correct 20 ms 27904 KB Output is correct
19 Correct 19 ms 28032 KB Output is correct
20 Correct 19 ms 27904 KB Output is correct
21 Correct 19 ms 28032 KB Output is correct
22 Correct 19 ms 27904 KB Output is correct
23 Correct 19 ms 28032 KB Output is correct
24 Correct 18 ms 27904 KB Output is correct
25 Correct 19 ms 27960 KB Output is correct
26 Correct 18 ms 28032 KB Output is correct
27 Correct 19 ms 28008 KB Output is correct
28 Correct 19 ms 28032 KB Output is correct
29 Correct 19 ms 27904 KB Output is correct
30 Correct 18 ms 28032 KB Output is correct
31 Correct 17 ms 28032 KB Output is correct
32 Correct 18 ms 28032 KB Output is correct
33 Correct 19 ms 28032 KB Output is correct
34 Correct 19 ms 28032 KB Output is correct
35 Correct 18 ms 28032 KB Output is correct
36 Correct 19 ms 28024 KB Output is correct
37 Correct 19 ms 28032 KB Output is correct
38 Correct 18 ms 28032 KB Output is correct
39 Correct 20 ms 28032 KB Output is correct
40 Correct 19 ms 28032 KB Output is correct
41 Correct 19 ms 28032 KB Output is correct
42 Correct 19 ms 28032 KB Output is correct
43 Correct 19 ms 28032 KB Output is correct
44 Correct 18 ms 28032 KB Output is correct
45 Correct 18 ms 28032 KB Output is correct
46 Correct 18 ms 28032 KB Output is correct
47 Correct 18 ms 28032 KB Output is correct
48 Correct 18 ms 28032 KB Output is correct
49 Correct 19 ms 28032 KB Output is correct
50 Correct 18 ms 28032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 27776 KB Output is correct
2 Correct 18 ms 27776 KB Output is correct
3 Correct 18 ms 27776 KB Output is correct
4 Correct 18 ms 27776 KB Output is correct
5 Correct 19 ms 27776 KB Output is correct
6 Correct 18 ms 27776 KB Output is correct
7 Correct 18 ms 27776 KB Output is correct
8 Correct 18 ms 27776 KB Output is correct
9 Correct 19 ms 27776 KB Output is correct
10 Correct 18 ms 27776 KB Output is correct
11 Correct 18 ms 27776 KB Output is correct
12 Correct 19 ms 27776 KB Output is correct
13 Correct 18 ms 27776 KB Output is correct
14 Correct 18 ms 27776 KB Output is correct
15 Correct 18 ms 28032 KB Output is correct
16 Correct 18 ms 28032 KB Output is correct
17 Correct 20 ms 28032 KB Output is correct
18 Correct 20 ms 27904 KB Output is correct
19 Correct 19 ms 28032 KB Output is correct
20 Correct 19 ms 27904 KB Output is correct
21 Correct 19 ms 28032 KB Output is correct
22 Correct 19 ms 27904 KB Output is correct
23 Correct 19 ms 28032 KB Output is correct
24 Correct 18 ms 27904 KB Output is correct
25 Correct 19 ms 27960 KB Output is correct
26 Correct 18 ms 28032 KB Output is correct
27 Correct 19 ms 28008 KB Output is correct
28 Correct 19 ms 28032 KB Output is correct
29 Correct 19 ms 27904 KB Output is correct
30 Correct 672 ms 163436 KB Output is correct
31 Correct 709 ms 163960 KB Output is correct
32 Correct 603 ms 166900 KB Output is correct
33 Correct 669 ms 162936 KB Output is correct
34 Correct 692 ms 162716 KB Output is correct
35 Correct 732 ms 163832 KB Output is correct
36 Correct 691 ms 164216 KB Output is correct
37 Correct 817 ms 160760 KB Output is correct
38 Correct 738 ms 161700 KB Output is correct
39 Correct 725 ms 161304 KB Output is correct
40 Correct 813 ms 159384 KB Output is correct
41 Correct 648 ms 165112 KB Output is correct
42 Correct 717 ms 163064 KB Output is correct
43 Correct 697 ms 160628 KB Output is correct
44 Correct 760 ms 159732 KB Output is correct
45 Correct 457 ms 165368 KB Output is correct
46 Correct 476 ms 165076 KB Output is correct
47 Correct 479 ms 165112 KB Output is correct
48 Correct 471 ms 165240 KB Output is correct
49 Correct 468 ms 165064 KB Output is correct
50 Correct 468 ms 165280 KB Output is correct
51 Correct 459 ms 165240 KB Output is correct
52 Correct 457 ms 165112 KB Output is correct
53 Correct 471 ms 165172 KB Output is correct
54 Correct 464 ms 165216 KB Output is correct
55 Correct 18 ms 28032 KB Output is correct
56 Correct 17 ms 28032 KB Output is correct
57 Correct 18 ms 28032 KB Output is correct
58 Correct 19 ms 28032 KB Output is correct
59 Correct 19 ms 28032 KB Output is correct
60 Correct 18 ms 28032 KB Output is correct
61 Correct 19 ms 28024 KB Output is correct
62 Correct 19 ms 28032 KB Output is correct
63 Correct 18 ms 28032 KB Output is correct
64 Correct 20 ms 28032 KB Output is correct
65 Correct 19 ms 28032 KB Output is correct
66 Correct 19 ms 28032 KB Output is correct
67 Correct 19 ms 28032 KB Output is correct
68 Correct 19 ms 28032 KB Output is correct
69 Correct 18 ms 28032 KB Output is correct
70 Correct 18 ms 28032 KB Output is correct
71 Correct 18 ms 28032 KB Output is correct
72 Correct 18 ms 28032 KB Output is correct
73 Correct 18 ms 28032 KB Output is correct
74 Correct 19 ms 28032 KB Output is correct
75 Correct 18 ms 28032 KB Output is correct
76 Correct 537 ms 174324 KB Output is correct
77 Correct 553 ms 174320 KB Output is correct
78 Correct 551 ms 173888 KB Output is correct
79 Correct 555 ms 173808 KB Output is correct
80 Correct 623 ms 174616 KB Output is correct
81 Correct 558 ms 174064 KB Output is correct
82 Correct 550 ms 173936 KB Output is correct
83 Correct 561 ms 174048 KB Output is correct
84 Correct 548 ms 174104 KB Output is correct
85 Correct 580 ms 174352 KB Output is correct
86 Correct 561 ms 173744 KB Output is correct
87 Correct 538 ms 173708 KB Output is correct
88 Correct 556 ms 174000 KB Output is correct
89 Correct 551 ms 173932 KB Output is correct
90 Correct 571 ms 174168 KB Output is correct
91 Correct 636 ms 173424 KB Output is correct
92 Correct 758 ms 166648 KB Output is correct
93 Correct 792 ms 167416 KB Output is correct
94 Correct 596 ms 173552 KB Output is correct
95 Correct 554 ms 174244 KB Output is correct
96 Correct 536 ms 173416 KB Output is correct
97 Correct 551 ms 173936 KB Output is correct
98 Correct 534 ms 174176 KB Output is correct
99 Correct 543 ms 173804 KB Output is correct
100 Correct 550 ms 174128 KB Output is correct