답안 #417994

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
417994 2021-06-04T19:36:28 Z Runtime_error_ 금 캐기 (IZhO14_divide) C++14
100 / 100
164 ms 22064 KB
#include <bits/stdc++.h>
#define ll long long
#define le node+node
#define ri node+node+1
#define mid (l+r)/2
using namespace std;
const ll inf = 2e5+9,MX = 1e18+9;
ll n,ans,x[inf],g[inf],e[inf];

ll cnt;
map<ll,ll> compress;

ll tree[inf<<2];

void build(ll node,ll l,ll r){
    if(l == r)
        return void(tree[node] = MX);
    build(le,l,mid);
    build(ri,mid+1,r);
    tree[node] = min(tree[le],tree[ri]);
}

void update(ll node,ll l,ll r,ll idx,ll val){
    if(l == r)
        return void(tree[node] = min(tree[node],val));
    if(idx <= mid)
        update(le,l,mid,idx,val);
    else
        update(ri,mid+1,r,idx,val);
    tree[node] = min(tree[le],tree[ri]);
}

ll query(ll node,ll l,ll r,ll x,ll y){
    if(l>r || r<x || l>y || x>y)
        return MX;
    if(l>=x && r<=y)
        return tree[node];
    return min(query(le,l,mid,x,y),query(ri,mid+1,r,x,y));
}

signed main(){
    scanf("%lld",&n);
    for(ll i=1;i<=n;i++)
        scanf("%lld%lld%lld",x+i,g+i,e+i),g[i] += g[i-1],
        e[i] += e[i-1],compress[e[i]-x[i]],compress[e[i-1]-x[i]];
    for(auto &o:compress)
        o.second = ++cnt;
    build(1,1,cnt);
    for(ll i=1;i<=n;i++){
        update(1,1,cnt,compress[ e[i-1]-x[i] ],g[i-1]);
        ans = max(ans,g[i]-query(1,1,cnt,1,compress[ e[i]-x[i] ]));
    }
    printf("%lld\n",ans);
}

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     scanf("%lld",&n);
      |     ~~~~~^~~~~~~~~~~
divide.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         scanf("%lld%lld%lld",x+i,g+i,e+i),g[i] += g[i-1],
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 3 ms 584 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 2 ms 532 KB Output is correct
22 Correct 2 ms 716 KB Output is correct
23 Correct 7 ms 1356 KB Output is correct
24 Correct 8 ms 1388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 3 ms 584 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 2 ms 532 KB Output is correct
22 Correct 2 ms 716 KB Output is correct
23 Correct 7 ms 1356 KB Output is correct
24 Correct 8 ms 1388 KB Output is correct
25 Correct 5 ms 1308 KB Output is correct
26 Correct 11 ms 2360 KB Output is correct
27 Correct 13 ms 2508 KB Output is correct
28 Correct 59 ms 10800 KB Output is correct
29 Correct 71 ms 11056 KB Output is correct
30 Correct 164 ms 22064 KB Output is correct
31 Correct 136 ms 20972 KB Output is correct
32 Correct 142 ms 21104 KB Output is correct
33 Correct 117 ms 20804 KB Output is correct
34 Correct 125 ms 20476 KB Output is correct
35 Correct 138 ms 21316 KB Output is correct
36 Correct 129 ms 21548 KB Output is correct