Submission #400693

# Submission time Handle Problem Language Result Execution time Memory
400693 2021-05-08T14:03:31 Z cpp219 Divide and conquer (IZhO14_divide) C++14
0 / 100
1 ms 332 KB
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 3e5 + 9;
const ll inf = 1e16 + 7;
const ll Log2 = 21;
struct mine{
    ll pos,g,e;
};
mine a[N];
ll n,gold[N],sum[N];
vector<ll> v;
bool lf(mine a,mine b){
    return a.pos < b.pos;
}

ll Find(ll x){
    return lower_bound(v.begin(),v.end(),x) - v.begin() + 1;
}

void compress(){
    sort(v.begin(),v.end()); v.resize(unique(v.begin(),v.end()) - v.begin());
}

ll st[4*N];

void upd(ll id,ll l,ll r,ll u,ll val){
    if (u < l||r < u) return;
    if (l == r){
        st[id] = val; return;
    }
    ll mid = (l + r)/2;
    upd(id*2,l,mid,u,val); upd(id*2 + 1,mid + 1,r,u,val);
    st[id] = max(st[id*2],st[id*2 + 1]);
}

ll Get(ll id,ll l,ll r,ll u,ll v){
    if (v < l||r < u) return 0;
    if (u <= l&&r <= v) return st[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(0); cout.tie(0);
    #define task "tst"
    if (fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        //freopen(task".out","w",stdout);
    }
    cin>>n;
    for (ll i = 1;i <= n;i++) cin>>a[i].pos>>a[i].g>>a[i].e;
    sort(a + 1,a + n + 1,lf);
    for (ll i = 1;i <= n;i++){
        gold[i] = gold[i - 1] + a[i].g; sum[i] = sum[i - 1] + a[i].e;
        v.push_back(sum[i] - a[i].pos); v.push_back(sum[i] - a[i].pos - a[i].e);
    }
    compress(); ll ans = 0;
    for (ll i = n;i > 0;i--){
        ll now = Find(sum[i] - a[i].pos - a[i].e); ans = max(ans,a[i].g);
        ll mx = Get(1,1,n,now,n); ans = max(ans,mx - gold[i - 1]);
        upd(1,1,n,Find(sum[i] - a[i].pos),gold[i]); //cout<<now<<"\n";
    }
    cout<<ans;
}

Compilation message

divide.cpp:1: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
divide.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
divide.cpp: In function 'int main()':
divide.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   56 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -