Submission #997983

# Submission time Handle Problem Language Result Execution time Memory
997983 2024-06-13T07:30:22 Z modwwe Treatment Project (JOI20_treatment) C++17
100 / 100
183 ms 32448 KB
#include<bits/stdc++.h>
#define int long long
//#define ll long long
#define down cout<<'\n';
#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".out","w",stdout)
#define pb push_back
#define checktime   cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
using namespace std;
const int inf=1e18;
void phongbeo();
const int mod2=1e9+7;
const int  mod1=998244353;
struct icd
{
    int a,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,f;

};
int n,m,s1,s2,s4,s3,sf,k,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l;
int  i,s10,s12;
int el=29;
main()
{
#ifndef ONLINE_JUDGE
    //fin(task),fou(task);
#endif
    NHP
    /// cin>>s1;
    // modwwe
    phongbeo(),down
    checktime
}
id a[100001];
vector<int> v;
struct cmp
{
    bool operator()(ib a,ib b)
    {
        return a.a>b.a;
    }
};
int b[100001];
bool cmp3(ib a,ib b)
{
    return a.a<b.a;
}
struct IT
{
    vector<ib> v2[100001];
    int c[100001];
    ib t[400001];
    ib mer(ib a,ib b)
    {
        if(a.a<=b.a) return a;
        else return b;
    }

    void setup(int node,int l,int r)
    {
        if(l==r)
        {
            sort(v2[l].begin(),v2[l].end(),cmp3);
            if(v2[l].size()!=0)
                t[node]=v2[l][0];
                else t[node].a=1e18,t[node].b=0;
            return;
        }
        int mid=l+r>>1;
        setup(node<<1,l,mid);
        setup(node<<1|1,mid+1,r);
        t[node]=mer(t[node<<1],t[node<<1|1]);
    }
    void upd2(int node,int l,int r,int l1,int r1)
    {
        if(l>r1||r<l1) return;
        if(l>=l1&&r<=r1)
        {
            c[l]++;
            if(c[l]<v2[l].size())
            {
                t[node]=v2[l][c[l]];
            }
            else t[node].a=1e18,t[node].b=0;
            return;
        }
        int mid=l+r>>1;
        upd2(node<<1,l,mid,l1,r1);
        upd2(node<<1|1,mid+1,r,l1,r1);
        t[node]=mer(t[node<<1],t[node<<1|1]);
    }
    void upd(int node,int l,int r,int l1,int r1,ib x)
    {
        if(l>r1||r<l1) return;
        if(l>=l1&&r<=r1)
        {
            v2[l].pb(x);
            return;
        }
        int mid=l+r>>1;
        upd(node<<1,l,mid,l1,r1,x);
        upd(node<<1|1,mid+1,r,l1,r1,x);
    }
    ib get(int node,int l,int r,int l1,int r1)
    {
        if(l>r1||r<l1) return{inf,0};
        if(l>=l1&&r<=r1) return t[node];
        int mid=l+r>>1;
        return mer(get(node<<1,l,mid,l1,r1),get(node<<1|1,mid+1,r,l1,r1)) ;
    }
} st1,st2;
void phongbeo()
{
    cin>>n>>m;
    for(int i=1; i<=m; i++)
        cin>>a[i].a>>a[i].b>>a[i].c>>a[i].d,a[i].b--,v.pb(a[i].a),b[i]=a[i].a;
/// cost i->j =a[j]
/// find min(cost(i))
    sort(v.begin(),v.end());
    for(int i=1; i<=m; i++)
    {
        a[i].a=lower_bound(v.begin(),v.end(),a[i].a)-v.begin()+1;
       if(a[i].b!=0)st1.upd(1,1,m,a[i].a,a[i].a, {a[i].b+b[i],i}),
        st2.upd(1,1,m,a[i].a,a[i].a, {a[i].b-b[i],i});
    }
    st1.setup(1,1,m);
    st2.setup(1,1,m);
    priority_queue<ib,vector<ib>,cmp>p;
    for(int i=1;i<=m;i++)
         if(a[i].b==0)
        p.push({a[i].d,i});
 while(!p.empty())
 {
      ib x=p.top();
      p.pop();
       if(a[x.b].c==n){
            cout<<x.a;
       exit(0);}
        s3=a[x.b].c+b[x.b];
  while(true)/// task 1
  {
      ib ss2=st1.get(1,1,m,a[x.b].a,m);
        if(ss2.a<=s3)
        {
            p.push({a[ss2.b].d+x.a,ss2.b});
            st1.upd2(1,1,m,a[ss2.b].a,a[ss2.b].a);
            st2.upd2(1,1,m,a[ss2.b].a,a[ss2.b].a);
        }
        else break;
  }
   s3=a[x.b].c-b[x.b];
  while(true)/// task 1
  {
       ib ss2=st2.get(1,1,m,1,a[x.b].a);
        if(ss2.a<=s3)
        {
            p.push({a[ss2.b].d+x.a,ss2.b});
            st1.upd2(1,1,m,a[ss2.b].a,a[ss2.b].a);
            st2.upd2(1,1,m,a[ss2.b].a,a[ss2.b].a);
        }
        else break;
  }
 }
 cout<<-1;
}

Compilation message

treatment.cpp:44:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   44 | main()
      | ^~~~
treatment.cpp: In member function 'void IT::setup(long long int, long long int, long long int)':
treatment.cpp:90:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   90 |         int mid=l+r>>1;
      |                 ~^~
treatment.cpp: In member function 'void IT::upd2(long long int, long long int, long long int, long long int, long long int)':
treatment.cpp:101:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<ib>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |             if(c[l]<v2[l].size())
      |                ~~~~^~~~~~~~~~~~~
treatment.cpp:108:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  108 |         int mid=l+r>>1;
      |                 ~^~
treatment.cpp: In member function 'void IT::upd(long long int, long long int, long long int, long long int, long long int, ib)':
treatment.cpp:121:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  121 |         int mid=l+r>>1;
      |                 ~^~
treatment.cpp: In member function 'ib IT::get(long long int, long long int, long long int, long long int, long long int)':
treatment.cpp:129:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  129 |         int mid=l+r>>1;
      |                 ~^~
# Verdict Execution time Memory Grader output
1 Correct 89 ms 27108 KB Output is correct
2 Correct 71 ms 27116 KB Output is correct
3 Correct 78 ms 28036 KB Output is correct
4 Correct 82 ms 27880 KB Output is correct
5 Correct 76 ms 29936 KB Output is correct
6 Correct 87 ms 27120 KB Output is correct
7 Correct 83 ms 27120 KB Output is correct
8 Correct 53 ms 27120 KB Output is correct
9 Correct 55 ms 27124 KB Output is correct
10 Correct 63 ms 27116 KB Output is correct
11 Correct 78 ms 29936 KB Output is correct
12 Correct 85 ms 29936 KB Output is correct
13 Correct 86 ms 29936 KB Output is correct
14 Correct 85 ms 29924 KB Output is correct
15 Correct 92 ms 27120 KB Output is correct
16 Correct 87 ms 27116 KB Output is correct
17 Correct 80 ms 27120 KB Output is correct
18 Correct 75 ms 29932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12888 KB Output is correct
2 Correct 1 ms 12892 KB Output is correct
3 Correct 1 ms 12892 KB Output is correct
4 Correct 2 ms 12892 KB Output is correct
5 Correct 2 ms 12892 KB Output is correct
6 Correct 1 ms 12892 KB Output is correct
7 Correct 2 ms 12892 KB Output is correct
8 Correct 2 ms 12892 KB Output is correct
9 Correct 1 ms 12892 KB Output is correct
10 Correct 2 ms 12888 KB Output is correct
11 Correct 1 ms 12892 KB Output is correct
12 Correct 2 ms 12892 KB Output is correct
13 Correct 2 ms 12888 KB Output is correct
14 Correct 1 ms 12892 KB Output is correct
15 Correct 2 ms 12888 KB Output is correct
16 Correct 1 ms 12892 KB Output is correct
17 Correct 2 ms 12892 KB Output is correct
18 Correct 2 ms 12892 KB Output is correct
19 Correct 2 ms 12892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12888 KB Output is correct
2 Correct 1 ms 12892 KB Output is correct
3 Correct 1 ms 12892 KB Output is correct
4 Correct 2 ms 12892 KB Output is correct
5 Correct 2 ms 12892 KB Output is correct
6 Correct 1 ms 12892 KB Output is correct
7 Correct 2 ms 12892 KB Output is correct
8 Correct 2 ms 12892 KB Output is correct
9 Correct 1 ms 12892 KB Output is correct
10 Correct 2 ms 12888 KB Output is correct
11 Correct 1 ms 12892 KB Output is correct
12 Correct 2 ms 12892 KB Output is correct
13 Correct 2 ms 12888 KB Output is correct
14 Correct 1 ms 12892 KB Output is correct
15 Correct 2 ms 12888 KB Output is correct
16 Correct 1 ms 12892 KB Output is correct
17 Correct 2 ms 12892 KB Output is correct
18 Correct 2 ms 12892 KB Output is correct
19 Correct 2 ms 12892 KB Output is correct
20 Correct 6 ms 13148 KB Output is correct
21 Correct 6 ms 13148 KB Output is correct
22 Correct 6 ms 13036 KB Output is correct
23 Correct 6 ms 13028 KB Output is correct
24 Correct 6 ms 13148 KB Output is correct
25 Correct 7 ms 13192 KB Output is correct
26 Correct 7 ms 13148 KB Output is correct
27 Correct 7 ms 13148 KB Output is correct
28 Correct 6 ms 13144 KB Output is correct
29 Correct 6 ms 13148 KB Output is correct
30 Correct 5 ms 13288 KB Output is correct
31 Correct 5 ms 13148 KB Output is correct
32 Correct 7 ms 13656 KB Output is correct
33 Correct 6 ms 13404 KB Output is correct
34 Correct 8 ms 13148 KB Output is correct
35 Correct 6 ms 13404 KB Output is correct
36 Correct 6 ms 13404 KB Output is correct
37 Correct 7 ms 13144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 27108 KB Output is correct
2 Correct 71 ms 27116 KB Output is correct
3 Correct 78 ms 28036 KB Output is correct
4 Correct 82 ms 27880 KB Output is correct
5 Correct 76 ms 29936 KB Output is correct
6 Correct 87 ms 27120 KB Output is correct
7 Correct 83 ms 27120 KB Output is correct
8 Correct 53 ms 27120 KB Output is correct
9 Correct 55 ms 27124 KB Output is correct
10 Correct 63 ms 27116 KB Output is correct
11 Correct 78 ms 29936 KB Output is correct
12 Correct 85 ms 29936 KB Output is correct
13 Correct 86 ms 29936 KB Output is correct
14 Correct 85 ms 29924 KB Output is correct
15 Correct 92 ms 27120 KB Output is correct
16 Correct 87 ms 27116 KB Output is correct
17 Correct 80 ms 27120 KB Output is correct
18 Correct 75 ms 29932 KB Output is correct
19 Correct 2 ms 12888 KB Output is correct
20 Correct 1 ms 12892 KB Output is correct
21 Correct 1 ms 12892 KB Output is correct
22 Correct 2 ms 12892 KB Output is correct
23 Correct 2 ms 12892 KB Output is correct
24 Correct 1 ms 12892 KB Output is correct
25 Correct 2 ms 12892 KB Output is correct
26 Correct 2 ms 12892 KB Output is correct
27 Correct 1 ms 12892 KB Output is correct
28 Correct 2 ms 12888 KB Output is correct
29 Correct 1 ms 12892 KB Output is correct
30 Correct 2 ms 12892 KB Output is correct
31 Correct 2 ms 12888 KB Output is correct
32 Correct 1 ms 12892 KB Output is correct
33 Correct 2 ms 12888 KB Output is correct
34 Correct 1 ms 12892 KB Output is correct
35 Correct 2 ms 12892 KB Output is correct
36 Correct 2 ms 12892 KB Output is correct
37 Correct 2 ms 12892 KB Output is correct
38 Correct 6 ms 13148 KB Output is correct
39 Correct 6 ms 13148 KB Output is correct
40 Correct 6 ms 13036 KB Output is correct
41 Correct 6 ms 13028 KB Output is correct
42 Correct 6 ms 13148 KB Output is correct
43 Correct 7 ms 13192 KB Output is correct
44 Correct 7 ms 13148 KB Output is correct
45 Correct 7 ms 13148 KB Output is correct
46 Correct 6 ms 13144 KB Output is correct
47 Correct 6 ms 13148 KB Output is correct
48 Correct 5 ms 13288 KB Output is correct
49 Correct 5 ms 13148 KB Output is correct
50 Correct 7 ms 13656 KB Output is correct
51 Correct 6 ms 13404 KB Output is correct
52 Correct 8 ms 13148 KB Output is correct
53 Correct 6 ms 13404 KB Output is correct
54 Correct 6 ms 13404 KB Output is correct
55 Correct 7 ms 13144 KB Output is correct
56 Correct 126 ms 29228 KB Output is correct
57 Correct 110 ms 29208 KB Output is correct
58 Correct 115 ms 28876 KB Output is correct
59 Correct 118 ms 29028 KB Output is correct
60 Correct 134 ms 29388 KB Output is correct
61 Correct 122 ms 28920 KB Output is correct
62 Correct 105 ms 29268 KB Output is correct
63 Correct 118 ms 30152 KB Output is correct
64 Correct 120 ms 30156 KB Output is correct
65 Correct 91 ms 27716 KB Output is correct
66 Correct 116 ms 29644 KB Output is correct
67 Correct 150 ms 30156 KB Output is correct
68 Correct 133 ms 30156 KB Output is correct
69 Correct 125 ms 29900 KB Output is correct
70 Correct 138 ms 30156 KB Output is correct
71 Correct 128 ms 30156 KB Output is correct
72 Correct 144 ms 30068 KB Output is correct
73 Correct 152 ms 30228 KB Output is correct
74 Correct 75 ms 30160 KB Output is correct
75 Correct 66 ms 30188 KB Output is correct
76 Correct 123 ms 31388 KB Output is correct
77 Correct 108 ms 31944 KB Output is correct
78 Correct 145 ms 31364 KB Output is correct
79 Correct 154 ms 30012 KB Output is correct
80 Correct 183 ms 29132 KB Output is correct
81 Correct 79 ms 30160 KB Output is correct
82 Correct 154 ms 29388 KB Output is correct
83 Correct 166 ms 30200 KB Output is correct
84 Correct 153 ms 29960 KB Output is correct
85 Correct 129 ms 30156 KB Output is correct
86 Correct 128 ms 30016 KB Output is correct
87 Correct 137 ms 30156 KB Output is correct
88 Correct 154 ms 30152 KB Output is correct
89 Correct 130 ms 30152 KB Output is correct
90 Correct 118 ms 32336 KB Output is correct
91 Correct 85 ms 30156 KB Output is correct
92 Correct 140 ms 30156 KB Output is correct
93 Correct 145 ms 30152 KB Output is correct
94 Correct 154 ms 30164 KB Output is correct
95 Correct 150 ms 30136 KB Output is correct
96 Correct 108 ms 31692 KB Output is correct
97 Correct 122 ms 32336 KB Output is correct
98 Correct 130 ms 32448 KB Output is correct
99 Correct 118 ms 32160 KB Output is correct
100 Correct 102 ms 31564 KB Output is correct
101 Correct 125 ms 32188 KB Output is correct
102 Correct 138 ms 32336 KB Output is correct
103 Correct 109 ms 30412 KB Output is correct