Submission #540388

# Submission time Handle Problem Language Result Execution time Memory
540388 2022-03-20T09:10:15 Z andrei_boaca Art Exhibition (JOI18_art) C++17
100 / 100
899 ms 37336 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
struct date
{
    ll a,b;
} v[500005];
ll ans=0;
int n;
bool comp(date a, date b)
{
    return a.a<b.a;
}
ll arb[2000005],toprop[2000005];
void prop(int nod)
{
    ll val=toprop[nod];
    for(int i=nod*2;i<=nod*2+1;i++)
    {
        arb[i]+=val;
        toprop[i]+=val;
    }
}
void update(int nod,int st,int dr,int a,int b,ll val)
{
    if(st!=dr)
        prop(nod);
    toprop[nod]=0;
    if(st>=a&&dr<=b)
    {
        arb[nod]+=val;
        toprop[nod]+=val;
        return;
    }
    int mij=(st+dr)/2;
    if(a<=mij)
        update(nod*2,st,mij,a,b,val);
    if(b>mij)
        update(nod*2+1,mij+1,dr,a,b,val);
    arb[nod]=max(arb[nod*2],arb[nod*2+1]);
}
ll query(int nod,int st,int dr,int a,int b)
{
    if(st!=dr)
        prop(nod);
    toprop[nod]=0;
    if(st>=a&&dr<=b)
        return arb[nod];
    int mij=(st+dr)/2;
    ll rez=0;
    if(a<=mij)
        rez=max(rez,query(nod*2,st,mij,a,b));
    if(b>mij)
        rez=max(rez,query(nod*2+1,mij+1,dr,a,b));
    return rez;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>v[i].a>>v[i].b;
    sort(v+1,v+n+1,comp);
    for(int i=1;i<=n;i++)
    {
        update(1,1,n,i,n,v[i].b);
        update(1,1,n,i,i,-v[i].a);
    }
    for(int i=1;i<=n;i++)
    {
        update(1,1,n,i,n,+v[i].a);
        ll val=query(1,1,n,i,n);
        ans=max(ans,val);
        update(1,1,n,i,n,-v[i].a);
        update(1,1,n,i,n,-v[i].b);
        update(1,1,n,i,i,+v[i].a);
    }
    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 7 ms 724 KB Output is correct
28 Correct 7 ms 728 KB Output is correct
29 Correct 9 ms 716 KB Output is correct
30 Correct 7 ms 716 KB Output is correct
31 Correct 7 ms 724 KB Output is correct
32 Correct 7 ms 720 KB Output is correct
33 Correct 7 ms 724 KB Output is correct
34 Correct 7 ms 724 KB Output is correct
35 Correct 7 ms 780 KB Output is correct
36 Correct 7 ms 728 KB Output is correct
37 Correct 7 ms 724 KB Output is correct
38 Correct 7 ms 724 KB Output is correct
39 Correct 7 ms 812 KB Output is correct
40 Correct 9 ms 784 KB Output is correct
41 Correct 7 ms 724 KB Output is correct
42 Correct 7 ms 724 KB Output is correct
43 Correct 7 ms 720 KB Output is correct
44 Correct 7 ms 804 KB Output is correct
45 Correct 7 ms 724 KB Output is correct
46 Correct 6 ms 712 KB Output is correct
47 Correct 6 ms 724 KB Output is correct
48 Correct 7 ms 724 KB Output is correct
49 Correct 8 ms 724 KB Output is correct
50 Correct 7 ms 724 KB Output is correct
51 Correct 8 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 7 ms 724 KB Output is correct
28 Correct 7 ms 728 KB Output is correct
29 Correct 9 ms 716 KB Output is correct
30 Correct 7 ms 716 KB Output is correct
31 Correct 7 ms 724 KB Output is correct
32 Correct 7 ms 720 KB Output is correct
33 Correct 7 ms 724 KB Output is correct
34 Correct 7 ms 724 KB Output is correct
35 Correct 7 ms 780 KB Output is correct
36 Correct 7 ms 728 KB Output is correct
37 Correct 7 ms 724 KB Output is correct
38 Correct 7 ms 724 KB Output is correct
39 Correct 7 ms 812 KB Output is correct
40 Correct 9 ms 784 KB Output is correct
41 Correct 7 ms 724 KB Output is correct
42 Correct 7 ms 724 KB Output is correct
43 Correct 7 ms 720 KB Output is correct
44 Correct 7 ms 804 KB Output is correct
45 Correct 7 ms 724 KB Output is correct
46 Correct 6 ms 712 KB Output is correct
47 Correct 6 ms 724 KB Output is correct
48 Correct 7 ms 724 KB Output is correct
49 Correct 8 ms 724 KB Output is correct
50 Correct 7 ms 724 KB Output is correct
51 Correct 8 ms 724 KB Output is correct
52 Correct 884 ms 37192 KB Output is correct
53 Correct 893 ms 37236 KB Output is correct
54 Correct 893 ms 37244 KB Output is correct
55 Correct 897 ms 37248 KB Output is correct
56 Correct 882 ms 37316 KB Output is correct
57 Correct 899 ms 37272 KB Output is correct
58 Correct 870 ms 37324 KB Output is correct
59 Correct 889 ms 37232 KB Output is correct
60 Correct 870 ms 37232 KB Output is correct
61 Correct 867 ms 37336 KB Output is correct
62 Correct 871 ms 37236 KB Output is correct
63 Correct 865 ms 37176 KB Output is correct
64 Correct 852 ms 37308 KB Output is correct
65 Correct 871 ms 37252 KB Output is correct
66 Correct 869 ms 37264 KB Output is correct
67 Correct 869 ms 37232 KB Output is correct
68 Correct 863 ms 37324 KB Output is correct