답안 #1040144

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1040144 2024-07-31T17:08:04 Z modwwe Fuel Station (NOI20_fuelstation) C++17
49 / 100
257 ms 14012 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[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];
 ///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;
      |               ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 2396 KB Output is correct
6 Correct 0 ms 2396 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 10708 KB Output is correct
2 Correct 77 ms 10808 KB Output is correct
3 Correct 77 ms 10692 KB Output is correct
4 Correct 77 ms 11464 KB Output is correct
5 Correct 79 ms 11212 KB Output is correct
6 Correct 106 ms 12744 KB Output is correct
7 Correct 75 ms 11212 KB Output is correct
8 Correct 72 ms 12484 KB Output is correct
9 Correct 79 ms 10952 KB Output is correct
10 Correct 79 ms 11976 KB Output is correct
11 Correct 75 ms 11976 KB Output is correct
12 Correct 75 ms 11724 KB Output is correct
13 Correct 74 ms 12488 KB Output is correct
14 Correct 75 ms 11720 KB Output is correct
15 Correct 72 ms 12568 KB Output is correct
16 Correct 79 ms 11560 KB Output is correct
17 Correct 73 ms 11400 KB Output is correct
18 Correct 74 ms 10956 KB Output is correct
19 Correct 72 ms 12748 KB Output is correct
20 Correct 84 ms 13004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 6 ms 2652 KB Output is correct
3 Correct 6 ms 2652 KB Output is correct
4 Correct 6 ms 2768 KB Output is correct
5 Correct 6 ms 2652 KB Output is correct
6 Correct 9 ms 5196 KB Output is correct
7 Correct 10 ms 5200 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 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 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 5 ms 2652 KB Output is correct
15 Correct 5 ms 2892 KB Output is correct
16 Correct 5 ms 2896 KB Output is correct
17 Correct 5 ms 2652 KB Output is correct
18 Correct 6 ms 2648 KB Output is correct
19 Correct 6 ms 2652 KB Output is correct
20 Correct 3 ms 2652 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 4 ms 2652 KB Output is correct
23 Correct 5 ms 2652 KB Output is correct
24 Correct 6 ms 2776 KB Output is correct
25 Correct 4 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 6 ms 2652 KB Output is correct
3 Correct 6 ms 2652 KB Output is correct
4 Correct 6 ms 2768 KB Output is correct
5 Correct 6 ms 2652 KB Output is correct
6 Correct 9 ms 5196 KB Output is correct
7 Correct 10 ms 5200 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 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 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 5 ms 2652 KB Output is correct
15 Correct 5 ms 2892 KB Output is correct
16 Correct 5 ms 2896 KB Output is correct
17 Correct 5 ms 2652 KB Output is correct
18 Correct 6 ms 2648 KB Output is correct
19 Correct 6 ms 2652 KB Output is correct
20 Correct 3 ms 2652 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 4 ms 2652 KB Output is correct
23 Correct 5 ms 2652 KB Output is correct
24 Correct 6 ms 2776 KB Output is correct
25 Correct 4 ms 2652 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 148 ms 11860 KB Output is correct
28 Correct 170 ms 12484 KB Output is correct
29 Correct 167 ms 11976 KB Output is correct
30 Correct 162 ms 11208 KB Output is correct
31 Correct 246 ms 13244 KB Output is correct
32 Correct 244 ms 12924 KB Output is correct
33 Correct 1 ms 2392 KB Output is correct
34 Correct 1 ms 2392 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 2396 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 172 ms 13240 KB Output is correct
40 Correct 143 ms 13340 KB Output is correct
41 Correct 149 ms 13756 KB Output is correct
42 Correct 188 ms 14012 KB Output is correct
43 Correct 167 ms 11988 KB Output is correct
44 Correct 257 ms 13756 KB Output is correct
45 Correct 250 ms 12988 KB Output is correct
46 Correct 235 ms 12732 KB Output is correct
47 Correct 67 ms 12560 KB Output is correct
48 Correct 64 ms 11212 KB Output is correct
49 Correct 139 ms 11472 KB Output is correct
50 Correct 140 ms 12744 KB Output is correct
51 Correct 140 ms 11720 KB Output is correct
52 Correct 138 ms 11972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 2396 KB Output is correct
6 Correct 0 ms 2396 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Incorrect 0 ms 2396 KB Output isn't correct
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 2396 KB Output is correct
6 Correct 0 ms 2396 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 6 ms 2652 KB Output is correct
18 Correct 6 ms 2652 KB Output is correct
19 Correct 6 ms 2768 KB Output is correct
20 Correct 6 ms 2652 KB Output is correct
21 Correct 9 ms 5196 KB Output is correct
22 Correct 10 ms 5200 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 0 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 0 ms 2396 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 5 ms 2652 KB Output is correct
30 Correct 5 ms 2892 KB Output is correct
31 Correct 5 ms 2896 KB Output is correct
32 Correct 5 ms 2652 KB Output is correct
33 Correct 6 ms 2648 KB Output is correct
34 Correct 6 ms 2652 KB Output is correct
35 Correct 3 ms 2652 KB Output is correct
36 Correct 2 ms 2652 KB Output is correct
37 Correct 4 ms 2652 KB Output is correct
38 Correct 5 ms 2652 KB Output is correct
39 Correct 6 ms 2776 KB Output is correct
40 Correct 4 ms 2652 KB Output is correct
41 Correct 1 ms 2392 KB Output is correct
42 Correct 5 ms 2652 KB Output is correct
43 Correct 8 ms 4956 KB Output is correct
44 Correct 9 ms 4956 KB Output is correct
45 Correct 8 ms 4956 KB Output is correct
46 Correct 8 ms 4956 KB Output is correct
47 Correct 9 ms 4952 KB Output is correct
48 Correct 0 ms 2392 KB Output is correct
49 Correct 0 ms 2396 KB Output is correct
50 Correct 0 ms 2396 KB Output is correct
51 Correct 0 ms 2396 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 0 ms 2396 KB Output is correct
54 Correct 6 ms 4772 KB Output is correct
55 Correct 6 ms 4956 KB Output is correct
56 Correct 7 ms 4956 KB Output is correct
57 Correct 7 ms 4956 KB Output is correct
58 Correct 6 ms 4828 KB Output is correct
59 Incorrect 3 ms 2648 KB Output isn't correct
60 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 2396 KB Output is correct
6 Correct 0 ms 2396 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 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 77 ms 10708 KB Output is correct
17 Correct 77 ms 10808 KB Output is correct
18 Correct 77 ms 10692 KB Output is correct
19 Correct 77 ms 11464 KB Output is correct
20 Correct 79 ms 11212 KB Output is correct
21 Correct 106 ms 12744 KB Output is correct
22 Correct 75 ms 11212 KB Output is correct
23 Correct 72 ms 12484 KB Output is correct
24 Correct 79 ms 10952 KB Output is correct
25 Correct 79 ms 11976 KB Output is correct
26 Correct 75 ms 11976 KB Output is correct
27 Correct 75 ms 11724 KB Output is correct
28 Correct 74 ms 12488 KB Output is correct
29 Correct 75 ms 11720 KB Output is correct
30 Correct 72 ms 12568 KB Output is correct
31 Correct 79 ms 11560 KB Output is correct
32 Correct 73 ms 11400 KB Output is correct
33 Correct 74 ms 10956 KB Output is correct
34 Correct 72 ms 12748 KB Output is correct
35 Correct 84 ms 13004 KB Output is correct
36 Correct 1 ms 2392 KB Output is correct
37 Correct 6 ms 2652 KB Output is correct
38 Correct 6 ms 2652 KB Output is correct
39 Correct 6 ms 2768 KB Output is correct
40 Correct 6 ms 2652 KB Output is correct
41 Correct 9 ms 5196 KB Output is correct
42 Correct 10 ms 5200 KB Output is correct
43 Correct 0 ms 2396 KB Output is correct
44 Correct 0 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 0 ms 2396 KB Output is correct
48 Correct 0 ms 2396 KB Output is correct
49 Correct 5 ms 2652 KB Output is correct
50 Correct 5 ms 2892 KB Output is correct
51 Correct 5 ms 2896 KB Output is correct
52 Correct 5 ms 2652 KB Output is correct
53 Correct 6 ms 2648 KB Output is correct
54 Correct 6 ms 2652 KB Output is correct
55 Correct 3 ms 2652 KB Output is correct
56 Correct 2 ms 2652 KB Output is correct
57 Correct 4 ms 2652 KB Output is correct
58 Correct 5 ms 2652 KB Output is correct
59 Correct 6 ms 2776 KB Output is correct
60 Correct 4 ms 2652 KB Output is correct
61 Correct 0 ms 2396 KB Output is correct
62 Correct 148 ms 11860 KB Output is correct
63 Correct 170 ms 12484 KB Output is correct
64 Correct 167 ms 11976 KB Output is correct
65 Correct 162 ms 11208 KB Output is correct
66 Correct 246 ms 13244 KB Output is correct
67 Correct 244 ms 12924 KB Output is correct
68 Correct 1 ms 2392 KB Output is correct
69 Correct 1 ms 2392 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 2396 KB Output is correct
73 Correct 0 ms 2396 KB Output is correct
74 Correct 172 ms 13240 KB Output is correct
75 Correct 143 ms 13340 KB Output is correct
76 Correct 149 ms 13756 KB Output is correct
77 Correct 188 ms 14012 KB Output is correct
78 Correct 167 ms 11988 KB Output is correct
79 Correct 257 ms 13756 KB Output is correct
80 Correct 250 ms 12988 KB Output is correct
81 Correct 235 ms 12732 KB Output is correct
82 Correct 67 ms 12560 KB Output is correct
83 Correct 64 ms 11212 KB Output is correct
84 Correct 139 ms 11472 KB Output is correct
85 Correct 140 ms 12744 KB Output is correct
86 Correct 140 ms 11720 KB Output is correct
87 Correct 138 ms 11972 KB Output is correct
88 Correct 1 ms 2396 KB Output is correct
89 Correct 1 ms 2396 KB Output is correct
90 Correct 0 ms 2396 KB Output is correct
91 Correct 0 ms 2396 KB Output is correct
92 Correct 1 ms 2396 KB Output is correct
93 Correct 1 ms 2392 KB Output is correct
94 Correct 1 ms 2392 KB Output is correct
95 Correct 0 ms 2396 KB Output is correct
96 Incorrect 0 ms 2396 KB Output isn't correct
97 Halted 0 ms 0 KB -