Submission #1040148

# Submission time Handle Problem Language Result Execution time Memory
1040148 2024-07-31T17:11:08 Z modwwe Fuel Station (NOI20_fuelstation) C++17
49 / 100
261 ms 15344 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 inf;
        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 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 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 1 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 1 ms 4564 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4564 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 13764 KB Output is correct
2 Correct 80 ms 13504 KB Output is correct
3 Correct 78 ms 12308 KB Output is correct
4 Correct 75 ms 11964 KB Output is correct
5 Correct 82 ms 11972 KB Output is correct
6 Correct 86 ms 12044 KB Output is correct
7 Correct 75 ms 12960 KB Output is correct
8 Correct 71 ms 12488 KB Output is correct
9 Correct 81 ms 13504 KB Output is correct
10 Correct 71 ms 13332 KB Output is correct
11 Correct 78 ms 11968 KB Output is correct
12 Correct 73 ms 13244 KB Output is correct
13 Correct 74 ms 11976 KB Output is correct
14 Correct 76 ms 11976 KB Output is correct
15 Correct 73 ms 13252 KB Output is correct
16 Correct 81 ms 12588 KB Output is correct
17 Correct 77 ms 12220 KB Output is correct
18 Correct 80 ms 12100 KB Output is correct
19 Correct 71 ms 13760 KB Output is correct
20 Correct 79 ms 13288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 6 ms 4792 KB Output is correct
3 Correct 6 ms 4700 KB Output is correct
4 Correct 7 ms 4700 KB Output is correct
5 Correct 6 ms 4776 KB Output is correct
6 Correct 9 ms 6820 KB Output is correct
7 Correct 9 ms 6748 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 0 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 5 ms 4772 KB Output is correct
15 Correct 5 ms 4700 KB Output is correct
16 Correct 5 ms 4780 KB Output is correct
17 Correct 5 ms 4908 KB Output is correct
18 Correct 6 ms 4636 KB Output is correct
19 Correct 6 ms 4700 KB Output is correct
20 Correct 3 ms 4700 KB Output is correct
21 Correct 3 ms 4700 KB Output is correct
22 Correct 4 ms 4700 KB Output is correct
23 Correct 4 ms 4700 KB Output is correct
24 Correct 7 ms 4800 KB Output is correct
25 Correct 5 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 6 ms 4792 KB Output is correct
3 Correct 6 ms 4700 KB Output is correct
4 Correct 7 ms 4700 KB Output is correct
5 Correct 6 ms 4776 KB Output is correct
6 Correct 9 ms 6820 KB Output is correct
7 Correct 9 ms 6748 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 0 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 5 ms 4772 KB Output is correct
15 Correct 5 ms 4700 KB Output is correct
16 Correct 5 ms 4780 KB Output is correct
17 Correct 5 ms 4908 KB Output is correct
18 Correct 6 ms 4636 KB Output is correct
19 Correct 6 ms 4700 KB Output is correct
20 Correct 3 ms 4700 KB Output is correct
21 Correct 3 ms 4700 KB Output is correct
22 Correct 4 ms 4700 KB Output is correct
23 Correct 4 ms 4700 KB Output is correct
24 Correct 7 ms 4800 KB Output is correct
25 Correct 5 ms 4700 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 146 ms 12768 KB Output is correct
28 Correct 166 ms 13736 KB Output is correct
29 Correct 160 ms 11968 KB Output is correct
30 Correct 160 ms 12480 KB Output is correct
31 Correct 240 ms 15220 KB Output is correct
32 Correct 240 ms 14584 KB Output is correct
33 Correct 0 ms 4444 KB Output is correct
34 Correct 0 ms 4444 KB Output is correct
35 Correct 0 ms 4444 KB Output is correct
36 Correct 1 ms 4440 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 0 ms 4444 KB Output is correct
39 Correct 173 ms 15296 KB Output is correct
40 Correct 140 ms 14272 KB Output is correct
41 Correct 150 ms 14784 KB Output is correct
42 Correct 174 ms 15344 KB Output is correct
43 Correct 153 ms 12224 KB Output is correct
44 Correct 257 ms 14496 KB Output is correct
45 Correct 261 ms 14392 KB Output is correct
46 Correct 237 ms 14800 KB Output is correct
47 Correct 62 ms 12552 KB Output is correct
48 Correct 64 ms 13176 KB Output is correct
49 Correct 141 ms 13304 KB Output is correct
50 Correct 142 ms 13248 KB Output is correct
51 Correct 143 ms 13504 KB Output is correct
52 Correct 138 ms 12988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 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 1 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 1 ms 4564 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4564 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 0 ms 4512 KB Output is correct
18 Correct 0 ms 4444 KB Output is correct
19 Correct 0 ms 4444 KB Output is correct
20 Correct 1 ms 4564 KB Output is correct
21 Correct 0 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 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 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 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 1 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 1 ms 4564 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4564 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 6 ms 4792 KB Output is correct
18 Correct 6 ms 4700 KB Output is correct
19 Correct 7 ms 4700 KB Output is correct
20 Correct 6 ms 4776 KB Output is correct
21 Correct 9 ms 6820 KB Output is correct
22 Correct 9 ms 6748 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 0 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 0 ms 4444 KB Output is correct
29 Correct 5 ms 4772 KB Output is correct
30 Correct 5 ms 4700 KB Output is correct
31 Correct 5 ms 4780 KB Output is correct
32 Correct 5 ms 4908 KB Output is correct
33 Correct 6 ms 4636 KB Output is correct
34 Correct 6 ms 4700 KB Output is correct
35 Correct 3 ms 4700 KB Output is correct
36 Correct 3 ms 4700 KB Output is correct
37 Correct 4 ms 4700 KB Output is correct
38 Correct 4 ms 4700 KB Output is correct
39 Correct 7 ms 4800 KB Output is correct
40 Correct 5 ms 4700 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 4 ms 4700 KB Output is correct
43 Correct 8 ms 6748 KB Output is correct
44 Correct 10 ms 6992 KB Output is correct
45 Correct 9 ms 6748 KB Output is correct
46 Correct 8 ms 6748 KB Output is correct
47 Correct 8 ms 6748 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 0 ms 4444 KB Output is correct
50 Correct 0 ms 4444 KB Output is correct
51 Correct 0 ms 4444 KB Output is correct
52 Correct 0 ms 4444 KB Output is correct
53 Correct 0 ms 4472 KB Output is correct
54 Correct 7 ms 6828 KB Output is correct
55 Correct 6 ms 6912 KB Output is correct
56 Correct 7 ms 6748 KB Output is correct
57 Correct 7 ms 6932 KB Output is correct
58 Correct 6 ms 6748 KB Output is correct
59 Incorrect 3 ms 4700 KB Output isn't correct
60 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 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 1 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 1 ms 4564 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4564 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 0 ms 4444 KB Output is correct
16 Correct 79 ms 13764 KB Output is correct
17 Correct 80 ms 13504 KB Output is correct
18 Correct 78 ms 12308 KB Output is correct
19 Correct 75 ms 11964 KB Output is correct
20 Correct 82 ms 11972 KB Output is correct
21 Correct 86 ms 12044 KB Output is correct
22 Correct 75 ms 12960 KB Output is correct
23 Correct 71 ms 12488 KB Output is correct
24 Correct 81 ms 13504 KB Output is correct
25 Correct 71 ms 13332 KB Output is correct
26 Correct 78 ms 11968 KB Output is correct
27 Correct 73 ms 13244 KB Output is correct
28 Correct 74 ms 11976 KB Output is correct
29 Correct 76 ms 11976 KB Output is correct
30 Correct 73 ms 13252 KB Output is correct
31 Correct 81 ms 12588 KB Output is correct
32 Correct 77 ms 12220 KB Output is correct
33 Correct 80 ms 12100 KB Output is correct
34 Correct 71 ms 13760 KB Output is correct
35 Correct 79 ms 13288 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 6 ms 4792 KB Output is correct
38 Correct 6 ms 4700 KB Output is correct
39 Correct 7 ms 4700 KB Output is correct
40 Correct 6 ms 4776 KB Output is correct
41 Correct 9 ms 6820 KB Output is correct
42 Correct 9 ms 6748 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 0 ms 4444 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 0 ms 4444 KB Output is correct
49 Correct 5 ms 4772 KB Output is correct
50 Correct 5 ms 4700 KB Output is correct
51 Correct 5 ms 4780 KB Output is correct
52 Correct 5 ms 4908 KB Output is correct
53 Correct 6 ms 4636 KB Output is correct
54 Correct 6 ms 4700 KB Output is correct
55 Correct 3 ms 4700 KB Output is correct
56 Correct 3 ms 4700 KB Output is correct
57 Correct 4 ms 4700 KB Output is correct
58 Correct 4 ms 4700 KB Output is correct
59 Correct 7 ms 4800 KB Output is correct
60 Correct 5 ms 4700 KB Output is correct
61 Correct 1 ms 4444 KB Output is correct
62 Correct 146 ms 12768 KB Output is correct
63 Correct 166 ms 13736 KB Output is correct
64 Correct 160 ms 11968 KB Output is correct
65 Correct 160 ms 12480 KB Output is correct
66 Correct 240 ms 15220 KB Output is correct
67 Correct 240 ms 14584 KB Output is correct
68 Correct 0 ms 4444 KB Output is correct
69 Correct 0 ms 4444 KB Output is correct
70 Correct 0 ms 4444 KB Output is correct
71 Correct 1 ms 4440 KB Output is correct
72 Correct 1 ms 4444 KB Output is correct
73 Correct 0 ms 4444 KB Output is correct
74 Correct 173 ms 15296 KB Output is correct
75 Correct 140 ms 14272 KB Output is correct
76 Correct 150 ms 14784 KB Output is correct
77 Correct 174 ms 15344 KB Output is correct
78 Correct 153 ms 12224 KB Output is correct
79 Correct 257 ms 14496 KB Output is correct
80 Correct 261 ms 14392 KB Output is correct
81 Correct 237 ms 14800 KB Output is correct
82 Correct 62 ms 12552 KB Output is correct
83 Correct 64 ms 13176 KB Output is correct
84 Correct 141 ms 13304 KB Output is correct
85 Correct 142 ms 13248 KB Output is correct
86 Correct 143 ms 13504 KB Output is correct
87 Correct 138 ms 12988 KB Output is correct
88 Correct 1 ms 4444 KB Output is correct
89 Correct 0 ms 4512 KB Output is correct
90 Correct 0 ms 4444 KB Output is correct
91 Correct 0 ms 4444 KB Output is correct
92 Correct 1 ms 4564 KB Output is correct
93 Correct 0 ms 4444 KB Output is correct
94 Correct 1 ms 4444 KB Output is correct
95 Correct 1 ms 4444 KB Output is correct
96 Incorrect 0 ms 4444 KB Output isn't correct
97 Halted 0 ms 0 KB -