Submission #1040139

# Submission time Handle Problem Language Result Execution time Memory
1040139 2024-07-31T17:05:18 Z modwwe Fuel Station (NOI20_fuelstation) C++17
49 / 100
277 ms 20804 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=-2e9;
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[300001];
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];
 ///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:173:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  173 |       int mid=l+r>>1;
      |               ~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2488 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2516 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 18636 KB Output is correct
2 Correct 79 ms 19860 KB Output is correct
3 Correct 81 ms 19144 KB Output is correct
4 Correct 75 ms 20432 KB Output is correct
5 Correct 77 ms 20804 KB Output is correct
6 Correct 77 ms 19912 KB Output is correct
7 Correct 77 ms 18792 KB Output is correct
8 Correct 74 ms 20168 KB Output is correct
9 Correct 84 ms 19216 KB Output is correct
10 Correct 74 ms 19844 KB Output is correct
11 Correct 81 ms 18800 KB Output is correct
12 Correct 74 ms 18628 KB Output is correct
13 Correct 81 ms 18972 KB Output is correct
14 Correct 79 ms 19652 KB Output is correct
15 Correct 77 ms 19104 KB Output is correct
16 Correct 84 ms 20224 KB Output is correct
17 Correct 81 ms 20556 KB Output is correct
18 Correct 80 ms 19908 KB Output is correct
19 Correct 74 ms 19144 KB Output is correct
20 Correct 101 ms 18884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 6 ms 2648 KB Output is correct
3 Correct 6 ms 2828 KB Output is correct
4 Correct 7 ms 2648 KB Output is correct
5 Correct 6 ms 2652 KB Output is correct
6 Correct 9 ms 5340 KB Output is correct
7 Correct 13 ms 5208 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 5 ms 2880 KB Output is correct
15 Correct 5 ms 2908 KB Output is correct
16 Correct 8 ms 2908 KB Output is correct
17 Correct 5 ms 2908 KB Output is correct
18 Correct 7 ms 2788 KB Output is correct
19 Correct 6 ms 2904 KB Output is correct
20 Correct 4 ms 2904 KB Output is correct
21 Correct 3 ms 2908 KB Output is correct
22 Correct 6 ms 2652 KB Output is correct
23 Correct 4 ms 2652 KB Output is correct
24 Correct 6 ms 2908 KB Output is correct
25 Correct 4 ms 2904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 6 ms 2648 KB Output is correct
3 Correct 6 ms 2828 KB Output is correct
4 Correct 7 ms 2648 KB Output is correct
5 Correct 6 ms 2652 KB Output is correct
6 Correct 9 ms 5340 KB Output is correct
7 Correct 13 ms 5208 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 5 ms 2880 KB Output is correct
15 Correct 5 ms 2908 KB Output is correct
16 Correct 8 ms 2908 KB Output is correct
17 Correct 5 ms 2908 KB Output is correct
18 Correct 7 ms 2788 KB Output is correct
19 Correct 6 ms 2904 KB Output is correct
20 Correct 4 ms 2904 KB Output is correct
21 Correct 3 ms 2908 KB Output is correct
22 Correct 6 ms 2652 KB Output is correct
23 Correct 4 ms 2652 KB Output is correct
24 Correct 6 ms 2908 KB Output is correct
25 Correct 4 ms 2904 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 180 ms 15948 KB Output is correct
28 Correct 185 ms 14796 KB Output is correct
29 Correct 174 ms 15988 KB Output is correct
30 Correct 166 ms 15792 KB Output is correct
31 Correct 277 ms 17852 KB Output is correct
32 Correct 243 ms 17216 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 0 ms 2396 KB Output is correct
36 Correct 0 ms 2396 KB Output is correct
37 Correct 0 ms 2520 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 175 ms 17272 KB Output is correct
40 Correct 149 ms 16576 KB Output is correct
41 Correct 152 ms 16576 KB Output is correct
42 Correct 160 ms 17340 KB Output is correct
43 Correct 149 ms 16336 KB Output is correct
44 Correct 270 ms 17848 KB Output is correct
45 Correct 256 ms 17088 KB Output is correct
46 Correct 246 ms 17220 KB Output is correct
47 Correct 66 ms 17608 KB Output is correct
48 Correct 68 ms 17100 KB Output is correct
49 Correct 144 ms 14280 KB Output is correct
50 Correct 148 ms 16588 KB Output is correct
51 Correct 144 ms 14796 KB Output is correct
52 Correct 141 ms 16332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2488 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2516 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 1 ms 2516 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Incorrect 1 ms 2396 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2488 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2516 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 6 ms 2648 KB Output is correct
18 Correct 6 ms 2828 KB Output is correct
19 Correct 7 ms 2648 KB Output is correct
20 Correct 6 ms 2652 KB Output is correct
21 Correct 9 ms 5340 KB Output is correct
22 Correct 13 ms 5208 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 5 ms 2880 KB Output is correct
30 Correct 5 ms 2908 KB Output is correct
31 Correct 8 ms 2908 KB Output is correct
32 Correct 5 ms 2908 KB Output is correct
33 Correct 7 ms 2788 KB Output is correct
34 Correct 6 ms 2904 KB Output is correct
35 Correct 4 ms 2904 KB Output is correct
36 Correct 3 ms 2908 KB Output is correct
37 Correct 6 ms 2652 KB Output is correct
38 Correct 4 ms 2652 KB Output is correct
39 Correct 6 ms 2908 KB Output is correct
40 Correct 4 ms 2904 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 5 ms 2908 KB Output is correct
43 Correct 9 ms 5212 KB Output is correct
44 Correct 9 ms 5496 KB Output is correct
45 Correct 9 ms 5464 KB Output is correct
46 Correct 8 ms 5372 KB Output is correct
47 Correct 9 ms 5404 KB Output is correct
48 Correct 0 ms 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 0 ms 2524 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 0 ms 2396 KB Output is correct
53 Correct 0 ms 2396 KB Output is correct
54 Correct 7 ms 5068 KB Output is correct
55 Correct 6 ms 5212 KB Output is correct
56 Correct 9 ms 5296 KB Output is correct
57 Correct 8 ms 5260 KB Output is correct
58 Correct 7 ms 5212 KB Output is correct
59 Incorrect 3 ms 2984 KB Output isn't correct
60 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2488 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2516 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 79 ms 18636 KB Output is correct
17 Correct 79 ms 19860 KB Output is correct
18 Correct 81 ms 19144 KB Output is correct
19 Correct 75 ms 20432 KB Output is correct
20 Correct 77 ms 20804 KB Output is correct
21 Correct 77 ms 19912 KB Output is correct
22 Correct 77 ms 18792 KB Output is correct
23 Correct 74 ms 20168 KB Output is correct
24 Correct 84 ms 19216 KB Output is correct
25 Correct 74 ms 19844 KB Output is correct
26 Correct 81 ms 18800 KB Output is correct
27 Correct 74 ms 18628 KB Output is correct
28 Correct 81 ms 18972 KB Output is correct
29 Correct 79 ms 19652 KB Output is correct
30 Correct 77 ms 19104 KB Output is correct
31 Correct 84 ms 20224 KB Output is correct
32 Correct 81 ms 20556 KB Output is correct
33 Correct 80 ms 19908 KB Output is correct
34 Correct 74 ms 19144 KB Output is correct
35 Correct 101 ms 18884 KB Output is correct
36 Correct 1 ms 2648 KB Output is correct
37 Correct 6 ms 2648 KB Output is correct
38 Correct 6 ms 2828 KB Output is correct
39 Correct 7 ms 2648 KB Output is correct
40 Correct 6 ms 2652 KB Output is correct
41 Correct 9 ms 5340 KB Output is correct
42 Correct 13 ms 5208 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 0 ms 2396 KB Output is correct
46 Correct 0 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 0 ms 2396 KB Output is correct
49 Correct 5 ms 2880 KB Output is correct
50 Correct 5 ms 2908 KB Output is correct
51 Correct 8 ms 2908 KB Output is correct
52 Correct 5 ms 2908 KB Output is correct
53 Correct 7 ms 2788 KB Output is correct
54 Correct 6 ms 2904 KB Output is correct
55 Correct 4 ms 2904 KB Output is correct
56 Correct 3 ms 2908 KB Output is correct
57 Correct 6 ms 2652 KB Output is correct
58 Correct 4 ms 2652 KB Output is correct
59 Correct 6 ms 2908 KB Output is correct
60 Correct 4 ms 2904 KB Output is correct
61 Correct 1 ms 2392 KB Output is correct
62 Correct 180 ms 15948 KB Output is correct
63 Correct 185 ms 14796 KB Output is correct
64 Correct 174 ms 15988 KB Output is correct
65 Correct 166 ms 15792 KB Output is correct
66 Correct 277 ms 17852 KB Output is correct
67 Correct 243 ms 17216 KB Output is correct
68 Correct 1 ms 2396 KB Output is correct
69 Correct 0 ms 2396 KB Output is correct
70 Correct 0 ms 2396 KB Output is correct
71 Correct 0 ms 2396 KB Output is correct
72 Correct 0 ms 2520 KB Output is correct
73 Correct 0 ms 2396 KB Output is correct
74 Correct 175 ms 17272 KB Output is correct
75 Correct 149 ms 16576 KB Output is correct
76 Correct 152 ms 16576 KB Output is correct
77 Correct 160 ms 17340 KB Output is correct
78 Correct 149 ms 16336 KB Output is correct
79 Correct 270 ms 17848 KB Output is correct
80 Correct 256 ms 17088 KB Output is correct
81 Correct 246 ms 17220 KB Output is correct
82 Correct 66 ms 17608 KB Output is correct
83 Correct 68 ms 17100 KB Output is correct
84 Correct 144 ms 14280 KB Output is correct
85 Correct 148 ms 16588 KB Output is correct
86 Correct 144 ms 14796 KB Output is correct
87 Correct 141 ms 16332 KB Output is correct
88 Correct 1 ms 2392 KB Output is correct
89 Correct 1 ms 2396 KB Output is correct
90 Correct 1 ms 2396 KB Output is correct
91 Correct 0 ms 2396 KB Output is correct
92 Correct 0 ms 2396 KB Output is correct
93 Correct 0 ms 2396 KB Output is correct
94 Correct 1 ms 2516 KB Output is correct
95 Correct 0 ms 2396 KB Output is correct
96 Incorrect 1 ms 2396 KB Output isn't correct
97 Halted 0 ms 0 KB -