답안 #1108592

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1108592 2024-11-04T14:19:09 Z vjudge1 Art Exhibition (JOI18_art) C++17
100 / 100
396 ms 25236 KB
#include <bits/stdc++.h>
#define ll long long

using namespace std;
long long ans,c,n;
pair<long long,long long>a[500005];
struct tutao{long long val,lazy;}st[2000020];
void Down(ll id)
{
    long long t=st[id].lazy;
    st[id*2].val+=t;
    st[id*2].lazy+=t;

    st[id*2+1].val+=t;
    st[id*2+1].lazy+=t;
    st[id].lazy=0;
}
void Update(ll id,ll l,ll r,ll u,ll v,ll val)
{
    if(r<u||v<l)return;
    if(u<=l&&r<=v)
    {
        st[id].val+=val;
        st[id].lazy+=val;
        return;
    }
    Down(id);
    ll mid=(l+r)/2;
    Update(id*2,l,mid,u,v,val);
    Update(id*2+1,mid+1,r,u,v,val);
    st[id].val=max(st[id*2].val,st[id*2+1].val);
}
long long Get(ll id,ll l,ll r,ll u,ll v)
{
    if(r<u||v<l)return -1e18;
    if(u<=l&&r<=v)return st[id].val;
    Down(id);
    ll mid=(l+r)/2;
    return max(Get(id*2,l,mid,u,v),Get(id*2+1,mid+1,r,u,v));
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i].first>>a[i].second;
    sort(a+1,a+n+1);
    ans=a[1].second;
    Update(1,1,n,1,1,a[1].first+a[1].second);
    for(int i=2;i<=n;i++)
    {
        ans=max(ans,a[i].second);
        c=Get(1,1,n,1,i-1);
        ans=max(ans,c+a[i].second-a[i].first);
        Update(1,1,n,i,i,a[i].first+a[i].second);
        Update(1,1,n,1,i-1,a[i].second);
    }
    cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2552 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2552 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2556 KB Output is correct
22 Correct 1 ms 2384 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2384 KB Output is correct
25 Correct 1 ms 2384 KB Output is correct
26 Correct 1 ms 2384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2552 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2556 KB Output is correct
22 Correct 1 ms 2384 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2384 KB Output is correct
25 Correct 1 ms 2384 KB Output is correct
26 Correct 1 ms 2384 KB Output is correct
27 Correct 4 ms 4688 KB Output is correct
28 Correct 4 ms 4736 KB Output is correct
29 Correct 4 ms 4860 KB Output is correct
30 Correct 4 ms 4688 KB Output is correct
31 Correct 4 ms 4688 KB Output is correct
32 Correct 4 ms 4688 KB Output is correct
33 Correct 5 ms 4688 KB Output is correct
34 Correct 4 ms 4604 KB Output is correct
35 Correct 5 ms 4688 KB Output is correct
36 Correct 5 ms 4688 KB Output is correct
37 Correct 4 ms 4688 KB Output is correct
38 Correct 4 ms 4688 KB Output is correct
39 Correct 4 ms 4688 KB Output is correct
40 Correct 5 ms 4688 KB Output is correct
41 Correct 5 ms 4688 KB Output is correct
42 Correct 4 ms 4688 KB Output is correct
43 Correct 4 ms 4688 KB Output is correct
44 Correct 4 ms 4688 KB Output is correct
45 Correct 4 ms 4688 KB Output is correct
46 Correct 4 ms 4688 KB Output is correct
47 Correct 4 ms 4688 KB Output is correct
48 Correct 4 ms 4688 KB Output is correct
49 Correct 4 ms 4688 KB Output is correct
50 Correct 4 ms 4568 KB Output is correct
51 Correct 4 ms 4688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2552 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2556 KB Output is correct
22 Correct 1 ms 2384 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2384 KB Output is correct
25 Correct 1 ms 2384 KB Output is correct
26 Correct 1 ms 2384 KB Output is correct
27 Correct 4 ms 4688 KB Output is correct
28 Correct 4 ms 4736 KB Output is correct
29 Correct 4 ms 4860 KB Output is correct
30 Correct 4 ms 4688 KB Output is correct
31 Correct 4 ms 4688 KB Output is correct
32 Correct 4 ms 4688 KB Output is correct
33 Correct 5 ms 4688 KB Output is correct
34 Correct 4 ms 4604 KB Output is correct
35 Correct 5 ms 4688 KB Output is correct
36 Correct 5 ms 4688 KB Output is correct
37 Correct 4 ms 4688 KB Output is correct
38 Correct 4 ms 4688 KB Output is correct
39 Correct 4 ms 4688 KB Output is correct
40 Correct 5 ms 4688 KB Output is correct
41 Correct 5 ms 4688 KB Output is correct
42 Correct 4 ms 4688 KB Output is correct
43 Correct 4 ms 4688 KB Output is correct
44 Correct 4 ms 4688 KB Output is correct
45 Correct 4 ms 4688 KB Output is correct
46 Correct 4 ms 4688 KB Output is correct
47 Correct 4 ms 4688 KB Output is correct
48 Correct 4 ms 4688 KB Output is correct
49 Correct 4 ms 4688 KB Output is correct
50 Correct 4 ms 4568 KB Output is correct
51 Correct 4 ms 4688 KB Output is correct
52 Correct 360 ms 25192 KB Output is correct
53 Correct 396 ms 25160 KB Output is correct
54 Correct 350 ms 25160 KB Output is correct
55 Correct 354 ms 25164 KB Output is correct
56 Correct 349 ms 25168 KB Output is correct
57 Correct 348 ms 25056 KB Output is correct
58 Correct 352 ms 25236 KB Output is correct
59 Correct 345 ms 25040 KB Output is correct
60 Correct 391 ms 25168 KB Output is correct
61 Correct 376 ms 25044 KB Output is correct
62 Correct 360 ms 25100 KB Output is correct
63 Correct 380 ms 25080 KB Output is correct
64 Correct 368 ms 25160 KB Output is correct
65 Correct 356 ms 25160 KB Output is correct
66 Correct 362 ms 25168 KB Output is correct
67 Correct 368 ms 25044 KB Output is correct
68 Correct 366 ms 25156 KB Output is correct