Submission #971719

# Submission time Handle Problem Language Result Execution time Memory
971719 2024-04-29T08:12:35 Z Aiperiii Divide and conquer (IZhO14_divide) C++14
100 / 100
159 ms 25540 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*4];
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++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 432 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 600 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 2 ms 856 KB Output is correct
22 Correct 2 ms 860 KB Output is correct
23 Correct 6 ms 3572 KB Output is correct
24 Correct 7 ms 3572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 432 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 600 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 2 ms 856 KB Output is correct
22 Correct 2 ms 860 KB Output is correct
23 Correct 6 ms 3572 KB Output is correct
24 Correct 7 ms 3572 KB Output is correct
25 Correct 6 ms 3420 KB Output is correct
26 Correct 11 ms 4312 KB Output is correct
27 Correct 13 ms 4312 KB Output is correct
28 Correct 64 ms 11472 KB Output is correct
29 Correct 84 ms 12744 KB Output is correct
30 Correct 159 ms 25540 KB Output is correct
31 Correct 137 ms 24256 KB Output is correct
32 Correct 142 ms 24512 KB Output is correct
33 Correct 131 ms 24296 KB Output is correct
34 Correct 128 ms 23748 KB Output is correct
35 Correct 145 ms 24768 KB Output is correct
36 Correct 146 ms 24804 KB Output is correct