Submission #1040146

# Submission time Handle Problem Language Result Execution time Memory
1040146 2024-07-31T17:09:55 Z modwwe Fuel Station (NOI20_fuelstation) C++17
49 / 100
284 ms 15972 KB
//https://www.instagram.com/_modwwe/
#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2")
#include<bits/stdc++.h>
#define int long long
//#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP     ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe  int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".ans","w",stdout)
#define pb push_back
#define checktime   cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
using namespace std;
void phongbeo();
const int inf=-1e18;
const int mod2=998244353;
const int  mod1=998244353;
struct icd
{
    long double a;
    int b;
};
struct ib
{
    int a;
    int b;
};
struct ic
{
    int a,b,c;
};
struct id
{
    int a,b,c,d;
};
struct ie
{
    int a,b,c,d,e;

};

int n,m,s1,s2,s4,s3,sf,k,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,s33,dem3,l,r,mid;
int  i,s10,s12;
int kk;
int el=29;
main()
{
#ifndef ONLINE_JUDGE
    //fin(task),fou(task);
#endif
    NHP
    /// cin>>s1;
    //  modwwe
    phongbeo();
}
ic a[300002];
bool cmp(ic a,ic b)
{
    return a.a<b.a;
}
vector<int> v;
struct IT
{
    int t[1200001];
    int lazy[1200001];
    void ff(int x)
    {
        for(int i=x*2; i<=x*2+1; i++){
                if(t[i]<0) continue;
            t[i]+=lazy[x],
                  lazy[i]+=lazy[x];}
        lazy[x]=0;
    }
    void build(int node,int l,int r)
    {
        if(l==r)
        {
            t[node]=v[l-1];
            return;
        }
        int mid=l+r>>1;
        build(node<<1,l,mid);
        build(node<<1|1,mid+1,r);
        t[node]=max(t[node<<1],t[node<<1|1]);
    }

    void upd(int node,int l,int r,int l1,int r1,int x)
    {
    if(t[node]<0) return;
        if(l>r1||r<l1) return;
        if(l>=l1&&r<=r1)
        {
             if(x==inf) {t[node]=inf; lazy[node]=inf;
             }
             if(t[node]>=0){
             t[node]+=x;
             lazy[node]+=x;}
            return;
        }
        int mid=l+r>>1;
        ff(node);
        upd(node<<1,l,mid,l1,r1,x);
       upd(node<<1|1,mid+1,r,l1,r1,x);
        t[node]=max(t[node<<1],t[node<<1|1]);
    }
    int get(int node,int l,int r,int l1,int r1)
    { if(t[node]<0) return -1e9;
        if(l>r1||r<l1) return inf;
        if(l>=l1&&r<=r1) return t[node];
        ff(node);
        int mid=l+r>>1;
        return max(get(node<<1,l,mid,l1,r1),get(node<<1|1,mid+1,r,l1,r1));
    }
    void setup(int node,int l,int r)
    {
        if(l==r)
        {
            if(l==1)s2=1,s3=v[l-1];
            else s2=v[l-2],s3=v[l-1];
            return;
        }
    }
} st;
bool check(int x)
{int x2=x;
    for(int i=0; i<=n; i++)
    {
        if(x2<=v[a[i].c-1]) x+=a[i].b;
        x=x+a[i].a-a[i+1].a;
        if(x<0) return 0;
    }
    return 1;
}
void phongbeo()
{
    cin>>n>>m;
    for(int i=1; i<=n; i++)
        cin>>a[i].a>>a[i].b>>a[i].c,v.pb({a[i].c});
    sort(v.begin(),v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
    for(int i=1; i<=n; i++) a[i].c=lower_bound(v.begin(),v.end(),a[i].c)-v.begin()+1;
    sort(a+1,a+1+n,cmp);
    a[n+1].a=m;
    s4=1;
    st.build(1,1,v.size());
   for(int i=0;i<=n; i++)
    {
        if(a[i].c!=0)
            st.upd(1,1,v.size(),1,a[i].c,a[i].b);
        st.upd(1,1,v.size(),1,v.size(),a[i].a-a[i+1].a);
        l=1;
        r=n;
        while(l<=r)
        {
            int mid=l+r>>1;
            if(st.get(1,1,v.size(),1,mid)<0)l=mid+1;
            else r=mid-1;
        }
      if(l-1!=0) st.upd(1,1,v.size(),1,l-1,inf);
     s4=max(s4,l);
    }
    if(s4==v.size()+1) {cout<<m; exit(0);}
 if(s4==1) l=1,r=v[s4-1];
 else l=v[s4-2]+1,r=v[s4-1];
 r=min(r,m-1);
 ///cout<<l<<" "<<r<<"\n";
  while(l<=r)
  {
      int mid=l+r>>1;
       if(check(mid))r=mid-1;
   else l=mid+1;
  }
  cout<<r+1;

}

Compilation message

FuelStation.cpp:51:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   51 | main()
      | ^~~~
FuelStation.cpp: In member function 'void IT::build(long long int, long long int, long long int)':
FuelStation.cpp:86:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   86 |         int mid=l+r>>1;
      |                 ~^~
FuelStation.cpp: In member function 'void IT::upd(long long int, long long int, long long int, long long int, long long int, long long int)':
FuelStation.cpp:105:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  105 |         int mid=l+r>>1;
      |                 ~^~
FuelStation.cpp: In member function 'long long int IT::get(long long int, long long int, long long int, long long int, long long int)':
FuelStation.cpp:116:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  116 |         int mid=l+r>>1;
      |                 ~^~
FuelStation.cpp: In function 'void phongbeo()':
FuelStation.cpp:160:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  160 |             int mid=l+r>>1;
      |                     ~^~
FuelStation.cpp:167:10: 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]
  167 |     if(s4==v.size()+1) {cout<<m; exit(0);}
      |        ~~^~~~~~~~~~~~
FuelStation.cpp:174:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  174 |       int mid=l+r>>1;
      |               ~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 4576 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 12192 KB Output is correct
2 Correct 79 ms 11972 KB Output is correct
3 Correct 81 ms 12480 KB Output is correct
4 Correct 75 ms 13656 KB Output is correct
5 Correct 77 ms 11972 KB Output is correct
6 Correct 82 ms 11964 KB Output is correct
7 Correct 86 ms 12176 KB Output is correct
8 Correct 86 ms 12800 KB Output is correct
9 Correct 82 ms 13756 KB Output is correct
10 Correct 70 ms 13500 KB Output is correct
11 Correct 76 ms 13764 KB Output is correct
12 Correct 75 ms 12740 KB Output is correct
13 Correct 93 ms 13872 KB Output is correct
14 Correct 79 ms 12736 KB Output is correct
15 Correct 77 ms 12004 KB Output is correct
16 Correct 94 ms 13344 KB Output is correct
17 Correct 79 ms 11972 KB Output is correct
18 Correct 78 ms 12744 KB Output is correct
19 Correct 82 ms 12988 KB Output is correct
20 Correct 79 ms 13292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 6 ms 4700 KB Output is correct
3 Correct 6 ms 4700 KB Output is correct
4 Correct 6 ms 4700 KB Output is correct
5 Correct 6 ms 4784 KB Output is correct
6 Correct 9 ms 6748 KB Output is correct
7 Correct 9 ms 6996 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 7 ms 4700 KB Output is correct
15 Correct 5 ms 4700 KB Output is correct
16 Correct 5 ms 4700 KB Output is correct
17 Correct 5 ms 4700 KB Output is correct
18 Correct 6 ms 4700 KB Output is correct
19 Correct 6 ms 4696 KB Output is correct
20 Correct 3 ms 4696 KB Output is correct
21 Correct 3 ms 4696 KB Output is correct
22 Correct 4 ms 4784 KB Output is correct
23 Correct 4 ms 4696 KB Output is correct
24 Correct 6 ms 4696 KB Output is correct
25 Correct 4 ms 4780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 6 ms 4700 KB Output is correct
3 Correct 6 ms 4700 KB Output is correct
4 Correct 6 ms 4700 KB Output is correct
5 Correct 6 ms 4784 KB Output is correct
6 Correct 9 ms 6748 KB Output is correct
7 Correct 9 ms 6996 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 7 ms 4700 KB Output is correct
15 Correct 5 ms 4700 KB Output is correct
16 Correct 5 ms 4700 KB Output is correct
17 Correct 5 ms 4700 KB Output is correct
18 Correct 6 ms 4700 KB Output is correct
19 Correct 6 ms 4696 KB Output is correct
20 Correct 3 ms 4696 KB Output is correct
21 Correct 3 ms 4696 KB Output is correct
22 Correct 4 ms 4784 KB Output is correct
23 Correct 4 ms 4696 KB Output is correct
24 Correct 6 ms 4696 KB Output is correct
25 Correct 4 ms 4780 KB Output is correct
26 Correct 0 ms 4444 KB Output is correct
27 Correct 145 ms 12944 KB Output is correct
28 Correct 165 ms 12220 KB Output is correct
29 Correct 165 ms 13744 KB Output is correct
30 Correct 161 ms 11972 KB Output is correct
31 Correct 246 ms 15240 KB Output is correct
32 Correct 247 ms 14416 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 0 ms 4444 KB Output is correct
36 Correct 0 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 181 ms 14560 KB Output is correct
40 Correct 140 ms 14784 KB Output is correct
41 Correct 151 ms 14412 KB Output is correct
42 Correct 161 ms 15972 KB Output is correct
43 Correct 139 ms 12544 KB Output is correct
44 Correct 281 ms 15292 KB Output is correct
45 Correct 271 ms 15512 KB Output is correct
46 Correct 284 ms 14528 KB Output is correct
47 Correct 70 ms 13504 KB Output is correct
48 Correct 76 ms 12852 KB Output is correct
49 Correct 142 ms 12980 KB Output is correct
50 Correct 177 ms 12056 KB Output is correct
51 Correct 143 ms 11964 KB Output is correct
52 Correct 141 ms 12224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 4576 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 0 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 0 ms 4444 KB Output is correct
21 Correct 0 ms 4444 KB Output is correct
22 Correct 0 ms 4444 KB Output is correct
23 Correct 0 ms 4444 KB Output is correct
24 Incorrect 0 ms 4444 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 4576 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 6 ms 4700 KB Output is correct
18 Correct 6 ms 4700 KB Output is correct
19 Correct 6 ms 4700 KB Output is correct
20 Correct 6 ms 4784 KB Output is correct
21 Correct 9 ms 6748 KB Output is correct
22 Correct 9 ms 6996 KB Output is correct
23 Correct 0 ms 4444 KB Output is correct
24 Correct 0 ms 4444 KB Output is correct
25 Correct 0 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 0 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 7 ms 4700 KB Output is correct
30 Correct 5 ms 4700 KB Output is correct
31 Correct 5 ms 4700 KB Output is correct
32 Correct 5 ms 4700 KB Output is correct
33 Correct 6 ms 4700 KB Output is correct
34 Correct 6 ms 4696 KB Output is correct
35 Correct 3 ms 4696 KB Output is correct
36 Correct 3 ms 4696 KB Output is correct
37 Correct 4 ms 4784 KB Output is correct
38 Correct 4 ms 4696 KB Output is correct
39 Correct 6 ms 4696 KB Output is correct
40 Correct 4 ms 4780 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 4 ms 4700 KB Output is correct
43 Correct 9 ms 6748 KB Output is correct
44 Correct 9 ms 6840 KB Output is correct
45 Correct 9 ms 6828 KB Output is correct
46 Correct 12 ms 6996 KB Output is correct
47 Correct 9 ms 6748 KB Output is correct
48 Correct 0 ms 4444 KB Output is correct
49 Correct 0 ms 4444 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 1 ms 4444 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 1 ms 4540 KB Output is correct
54 Correct 7 ms 6988 KB Output is correct
55 Correct 6 ms 6748 KB Output is correct
56 Correct 7 ms 6748 KB Output is correct
57 Correct 7 ms 6748 KB Output is correct
58 Correct 6 ms 6748 KB Output is correct
59 Incorrect 3 ms 4696 KB Output isn't correct
60 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 4576 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 77 ms 12192 KB Output is correct
17 Correct 79 ms 11972 KB Output is correct
18 Correct 81 ms 12480 KB Output is correct
19 Correct 75 ms 13656 KB Output is correct
20 Correct 77 ms 11972 KB Output is correct
21 Correct 82 ms 11964 KB Output is correct
22 Correct 86 ms 12176 KB Output is correct
23 Correct 86 ms 12800 KB Output is correct
24 Correct 82 ms 13756 KB Output is correct
25 Correct 70 ms 13500 KB Output is correct
26 Correct 76 ms 13764 KB Output is correct
27 Correct 75 ms 12740 KB Output is correct
28 Correct 93 ms 13872 KB Output is correct
29 Correct 79 ms 12736 KB Output is correct
30 Correct 77 ms 12004 KB Output is correct
31 Correct 94 ms 13344 KB Output is correct
32 Correct 79 ms 11972 KB Output is correct
33 Correct 78 ms 12744 KB Output is correct
34 Correct 82 ms 12988 KB Output is correct
35 Correct 79 ms 13292 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 6 ms 4700 KB Output is correct
38 Correct 6 ms 4700 KB Output is correct
39 Correct 6 ms 4700 KB Output is correct
40 Correct 6 ms 4784 KB Output is correct
41 Correct 9 ms 6748 KB Output is correct
42 Correct 9 ms 6996 KB Output is correct
43 Correct 0 ms 4444 KB Output is correct
44 Correct 0 ms 4444 KB Output is correct
45 Correct 0 ms 4444 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 0 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 7 ms 4700 KB Output is correct
50 Correct 5 ms 4700 KB Output is correct
51 Correct 5 ms 4700 KB Output is correct
52 Correct 5 ms 4700 KB Output is correct
53 Correct 6 ms 4700 KB Output is correct
54 Correct 6 ms 4696 KB Output is correct
55 Correct 3 ms 4696 KB Output is correct
56 Correct 3 ms 4696 KB Output is correct
57 Correct 4 ms 4784 KB Output is correct
58 Correct 4 ms 4696 KB Output is correct
59 Correct 6 ms 4696 KB Output is correct
60 Correct 4 ms 4780 KB Output is correct
61 Correct 0 ms 4444 KB Output is correct
62 Correct 145 ms 12944 KB Output is correct
63 Correct 165 ms 12220 KB Output is correct
64 Correct 165 ms 13744 KB Output is correct
65 Correct 161 ms 11972 KB Output is correct
66 Correct 246 ms 15240 KB Output is correct
67 Correct 247 ms 14416 KB Output is correct
68 Correct 1 ms 4444 KB Output is correct
69 Correct 1 ms 4444 KB Output is correct
70 Correct 0 ms 4444 KB Output is correct
71 Correct 0 ms 4444 KB Output is correct
72 Correct 1 ms 4444 KB Output is correct
73 Correct 1 ms 4444 KB Output is correct
74 Correct 181 ms 14560 KB Output is correct
75 Correct 140 ms 14784 KB Output is correct
76 Correct 151 ms 14412 KB Output is correct
77 Correct 161 ms 15972 KB Output is correct
78 Correct 139 ms 12544 KB Output is correct
79 Correct 281 ms 15292 KB Output is correct
80 Correct 271 ms 15512 KB Output is correct
81 Correct 284 ms 14528 KB Output is correct
82 Correct 70 ms 13504 KB Output is correct
83 Correct 76 ms 12852 KB Output is correct
84 Correct 142 ms 12980 KB Output is correct
85 Correct 177 ms 12056 KB Output is correct
86 Correct 143 ms 11964 KB Output is correct
87 Correct 141 ms 12224 KB Output is correct
88 Correct 1 ms 4444 KB Output is correct
89 Correct 0 ms 4444 KB Output is correct
90 Correct 1 ms 4444 KB Output is correct
91 Correct 1 ms 4444 KB Output is correct
92 Correct 0 ms 4444 KB Output is correct
93 Correct 0 ms 4444 KB Output is correct
94 Correct 0 ms 4444 KB Output is correct
95 Correct 0 ms 4444 KB Output is correct
96 Incorrect 0 ms 4444 KB Output isn't correct
97 Halted 0 ms 0 KB -