Submission #239483

# Submission time Handle Problem Language Result Execution time Memory
239483 2020-06-15T21:23:50 Z aggu_01000101 Divide and conquer (IZhO14_divide) C++14
100 / 100
129 ms 18408 KB
#include <bits/stdc++.h>
#define int long long
#define INF 1000000000000000
#define lchild(i) (i*2 + 1)
#define rchild(i) (i*2 + 2)
#define mid(l, u) ((l+u)/2)
#define x(p) p.first
#define y(p) p.second
#define MOD 998244353
using namespace std;
const int N = 1e5 + 5;
int seg[4*N];
int lazy[4*N];
struct site{
    int x, g, e;
};
int build(int l, int u, int i){
    lazy[i] = 0;
    if(l==u) return seg[i] = -INF;
    return seg[i] = max(build(l, mid(l, u), lchild(i)), build(mid(l, u)+1, u, rchild(i)));

}
int query(int l, int u, int i, int ll, int uu){
    if(lazy[i]){
        seg[i]+=lazy[i];
        if(l!=u){
            lazy[lchild(i)] += lazy[i];
            lazy[rchild(i)] += lazy[i];
        }
        lazy[i] = 0;
    }
    if(l>=ll && u<=uu) return seg[i];
    if(l>uu || u<ll) return -INF;
    return max(query(l, mid(l, u), lchild(i), ll, uu), query(mid(l, u)+1, u, rchild(i), ll, uu));
}
int update(int l, int u, int i, int ll, int uu, int upval){
    if(lazy[i]){
        seg[i]+=lazy[i];
        if(l!=u){
            lazy[lchild(i)] += lazy[i];
            lazy[rchild(i)] += lazy[i];
        }
        lazy[i] = 0;
    }
    if(l>=ll && u<=uu){
        lazy[i] = upval;
        seg[i]+=lazy[i];
        if(l!=u){
            lazy[lchild(i)] += lazy[i];
            lazy[rchild(i)] += lazy[i];
        }
        lazy[i] = 0;
        return seg[i];
    }
    if(l>uu || u<ll) return seg[i];
    return seg[i] = max(update(l, mid(l, u), lchild(i), ll, uu, upval), update(mid(l, u)+1, u, rchild(i), ll, uu, upval));
}
int update1(int l, int u, int i, int ll, int upval){
    if(lazy[i]){
        seg[i]+=lazy[i];
        if(l!=u){
            lazy[lchild(i)] += lazy[i];
            lazy[rchild(i)] += lazy[i];
        }
        lazy[i] = 0;
    }
    if(l>=ll && u<=ll){
        return seg[i] = upval;
    }
    if(l>ll || u<ll) return seg[i];
    return seg[i] = max(update1(l, mid(l, u), lchild(i), ll, upval), update1(mid(l, u)+1, u, rchild(i), ll, upval));
}
signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
    int n;
    cin>>n;
    site arr[n];
    for(int i = 0;i<n;i++){
        cin>>arr[i].x>>arr[i].g>>arr[i].e;
    }
    build(0, n-1, 0);
    priority_queue<pair<int, int>> ss;
    int tosub = 0;
    int prev = arr[n-1].x;
    for(int i = n-1;i>=0;i--){
        int toadd = arr[i].e - (prev - arr[i].x);
        prev = arr[i].x;
        tosub+=toadd;
        ss.push({arr[i].e - tosub, i});
    }
    int mp[n];
    for(int i = n-1;i>=0;i--) {
        mp[ss.top().second] = i;
        //cout<<(ss.top().second)<<" "<<i<<endl;
        ss.pop();
    }
    set<pair<int, int>> s;
    tosub = 0;
    prev = arr[n-1].x;
    int ans = 0;
    for(int i = n-1;i>=0;i--){
        int toadd = arr[i].e - (prev - arr[i].x);
        prev = arr[i].x;
        tosub+=toadd;
        s.insert({arr[i].e - tosub, i}); //then >= -tosub
        update1(0, n-1, 0, mp[i], 0);
        update(0, n-1, 0, 0, n-1, arr[i].g);
        //cout<<"ADDING "<<arr[i].g<<endl;
        auto it = s.lower_bound({-tosub, 0});
        int lower = mp[(*it).second];
        ans = max(ans, query(0, n-1, 0, lower, n-1));
        //cout<<"PROCESSING INDEX "<<i<<"\n";
        /*for(int j = 0;j<n;j++){
            query(0, n-1, 0, j, j);
            //cout<<"INDEX "<<j<<" "<<query(0, n-1, 0, j, j)<<"\n";
        }*/
    }
    cout<<ans<<"\n";
}
/*
 1 a
 1 b
 3 1
 1 d
 2 2
 2 1
 3 2
 1 e
 2 1
 2 5
 1 c
 3 2
 2 2
 3 2
 */
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 6 ms 640 KB Output is correct
19 Correct 6 ms 512 KB Output is correct
20 Correct 6 ms 512 KB Output is correct
21 Correct 6 ms 640 KB Output is correct
22 Correct 6 ms 640 KB Output is correct
23 Correct 10 ms 1280 KB Output is correct
24 Correct 9 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 6 ms 640 KB Output is correct
19 Correct 6 ms 512 KB Output is correct
20 Correct 6 ms 512 KB Output is correct
21 Correct 6 ms 640 KB Output is correct
22 Correct 6 ms 640 KB Output is correct
23 Correct 10 ms 1280 KB Output is correct
24 Correct 9 ms 1280 KB Output is correct
25 Correct 9 ms 1152 KB Output is correct
26 Correct 14 ms 2048 KB Output is correct
27 Correct 14 ms 2176 KB Output is correct
28 Correct 57 ms 8944 KB Output is correct
29 Correct 70 ms 9224 KB Output is correct
30 Correct 129 ms 18408 KB Output is correct
31 Correct 120 ms 17132 KB Output is correct
32 Correct 123 ms 17256 KB Output is correct
33 Correct 104 ms 17128 KB Output is correct
34 Correct 109 ms 17000 KB Output is correct
35 Correct 124 ms 17512 KB Output is correct
36 Correct 117 ms 17768 KB Output is correct