답안 #971718

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971718 2024-04-29T08:11:48 Z Aiperiii 금 캐기 (IZhO14_divide) C++14
48 / 100
58 ms 21976 KB
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=2e5+5;
int t[N];
void build(int v,int tl,int tr){
    t[v]=1e9;
    if(tl!=tr){
        int tm=(tl+tr)/2;
        build(v*2,tl,tm);
        build(v*2+1,tm+1,tr);
    }
}
void update(int v,int tl,int tr,int pos,int x){
    if(tl==tr)t[v]=min(t[v],x);
    else{
        int tm=(tl+tr)/2;
        if(pos<=tm)update(v*2,tl,tm,pos,x);
        else update(v*2+1,tm+1,tr,pos,x);
        t[v]=min(t[v*2],t[v*2+1]);
    }
}
int get(int v,int tl,int tr,int l,int r){
    if(tl>r or tr<l)return 1e9;
    if(l<=tl && tr<=r)return t[v];
    int tm=(tl+tr)/2;
    return min(get(v*2,tl,tm,l,r),get(v*2+1,tm+1,tr,l,r));
}
signed main(){
    ios_base::sync_with_stdio();
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vector <int> x(n+1),g(n+1),e(n+1),pre(n+1),prg(n+1);
    for(int i=1;i<=n;i++){
        cin>>x[i]>>g[i]>>e[i];
    }
    vector <int> v;
    for(int i=1;i<=n;i++){
        pre[i]=pre[i-1]+e[i];
        v.pb(pre[i]-x[i]);
        v.pb(pre[i-1]-x[i]);
        prg[i]=prg[i-1]+g[i];
    }
    sort(all(v));
    map <int,int> val_ind;
    int ind=1;
    for(int i=0;i<v.size();i++){
        if(i==0 or v[i]!=v[i-1]){
            val_ind[v[i]]=ind;
            ind++;
        }
    }
    ind--;
    int mx=0;
    build(1,1,ind);
    for(int i=1;i<=n;i++){
        update(1,1,ind,val_ind[pre[i-1]-x[i]],i);
        int pos=get(1,1,ind,1,val_ind[pre[i]-x[i]]);
        mx=max(mx,prg[i]-prg[pos-1]);
    }
    cout<<mx<<"\n";
}
/*
4
0 5 1
1 7 2
4 4 1
7 15 1
*/

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:52:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 356 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 356 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
19 Correct 2 ms 608 KB Output is correct
20 Correct 2 ms 616 KB Output is correct
21 Correct 3 ms 608 KB Output is correct
22 Correct 3 ms 860 KB Output is correct
23 Correct 7 ms 1632 KB Output is correct
24 Correct 8 ms 1640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 356 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 356 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
19 Correct 2 ms 608 KB Output is correct
20 Correct 2 ms 616 KB Output is correct
21 Correct 3 ms 608 KB Output is correct
22 Correct 3 ms 860 KB Output is correct
23 Correct 7 ms 1632 KB Output is correct
24 Correct 8 ms 1640 KB Output is correct
25 Correct 6 ms 1636 KB Output is correct
26 Correct 11 ms 2864 KB Output is correct
27 Correct 13 ms 2776 KB Output is correct
28 Runtime error 58 ms 21976 KB Execution killed with signal 11
29 Halted 0 ms 0 KB -