Submission #997981

# Submission time Handle Problem Language Result Execution time Memory
997981 2024-06-13T07:27:26 Z modwwe Treatment Project (JOI20_treatment) C++17
100 / 100
168 ms 36360 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;
    }
};
bool color[100001];
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);}
       if(color[x.b]) continue;
        color[x.b]=1;
        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:91:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   91 |         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:102:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<ib>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |             if(c[l]<v2[l].size())
      |                ~~~~^~~~~~~~~~~~~
treatment.cpp:109:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  109 |         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:122:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  122 |         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:130:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  130 |         int mid=l+r>>1;
      |                 ~^~
# Verdict Execution time Memory Grader output
1 Correct 80 ms 27116 KB Output is correct
2 Correct 71 ms 27124 KB Output is correct
3 Correct 70 ms 30288 KB Output is correct
4 Correct 73 ms 30244 KB Output is correct
5 Correct 72 ms 33208 KB Output is correct
6 Correct 84 ms 30312 KB Output is correct
7 Correct 82 ms 30196 KB Output is correct
8 Correct 53 ms 30196 KB Output is correct
9 Correct 53 ms 30400 KB Output is correct
10 Correct 59 ms 30200 KB Output is correct
11 Correct 77 ms 33252 KB Output is correct
12 Correct 80 ms 33264 KB Output is correct
13 Correct 86 ms 33352 KB Output is correct
14 Correct 84 ms 33264 KB Output is correct
15 Correct 91 ms 30556 KB Output is correct
16 Correct 84 ms 30188 KB Output is correct
17 Correct 83 ms 29424 KB Output is correct
18 Correct 79 ms 32500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 2 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 2 ms 12884 KB Output is correct
7 Correct 2 ms 12892 KB Output is correct
8 Correct 2 ms 12924 KB Output is correct
9 Correct 2 ms 12892 KB Output is correct
10 Correct 2 ms 12892 KB Output is correct
11 Correct 2 ms 12892 KB Output is correct
12 Correct 2 ms 12892 KB Output is correct
13 Correct 1 ms 12892 KB Output is correct
14 Correct 2 ms 12892 KB Output is correct
15 Correct 2 ms 12892 KB Output is correct
16 Correct 2 ms 12892 KB Output is correct
17 Correct 2 ms 12892 KB Output is correct
18 Correct 2 ms 12924 KB Output is correct
19 Correct 2 ms 12892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 2 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 2 ms 12884 KB Output is correct
7 Correct 2 ms 12892 KB Output is correct
8 Correct 2 ms 12924 KB Output is correct
9 Correct 2 ms 12892 KB Output is correct
10 Correct 2 ms 12892 KB Output is correct
11 Correct 2 ms 12892 KB Output is correct
12 Correct 2 ms 12892 KB Output is correct
13 Correct 1 ms 12892 KB Output is correct
14 Correct 2 ms 12892 KB Output is correct
15 Correct 2 ms 12892 KB Output is correct
16 Correct 2 ms 12892 KB Output is correct
17 Correct 2 ms 12892 KB Output is correct
18 Correct 2 ms 12924 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 13240 KB Output is correct
22 Correct 8 ms 13404 KB Output is correct
23 Correct 6 ms 13452 KB Output is correct
24 Correct 6 ms 13400 KB Output is correct
25 Correct 7 ms 13404 KB Output is correct
26 Correct 7 ms 13400 KB Output is correct
27 Correct 9 ms 13404 KB Output is correct
28 Correct 7 ms 13404 KB Output is correct
29 Correct 7 ms 13412 KB Output is correct
30 Correct 5 ms 13404 KB Output is correct
31 Correct 5 ms 13436 KB Output is correct
32 Correct 7 ms 13404 KB Output is correct
33 Correct 7 ms 13404 KB Output is correct
34 Correct 8 ms 13232 KB Output is correct
35 Correct 7 ms 13404 KB Output is correct
36 Correct 8 ms 13404 KB Output is correct
37 Correct 8 ms 13148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 27116 KB Output is correct
2 Correct 71 ms 27124 KB Output is correct
3 Correct 70 ms 30288 KB Output is correct
4 Correct 73 ms 30244 KB Output is correct
5 Correct 72 ms 33208 KB Output is correct
6 Correct 84 ms 30312 KB Output is correct
7 Correct 82 ms 30196 KB Output is correct
8 Correct 53 ms 30196 KB Output is correct
9 Correct 53 ms 30400 KB Output is correct
10 Correct 59 ms 30200 KB Output is correct
11 Correct 77 ms 33252 KB Output is correct
12 Correct 80 ms 33264 KB Output is correct
13 Correct 86 ms 33352 KB Output is correct
14 Correct 84 ms 33264 KB Output is correct
15 Correct 91 ms 30556 KB Output is correct
16 Correct 84 ms 30188 KB Output is correct
17 Correct 83 ms 29424 KB Output is correct
18 Correct 79 ms 32500 KB Output is correct
19 Correct 2 ms 12892 KB Output is correct
20 Correct 2 ms 12892 KB Output is correct
21 Correct 2 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 2 ms 12884 KB Output is correct
25 Correct 2 ms 12892 KB Output is correct
26 Correct 2 ms 12924 KB Output is correct
27 Correct 2 ms 12892 KB Output is correct
28 Correct 2 ms 12892 KB Output is correct
29 Correct 2 ms 12892 KB Output is correct
30 Correct 2 ms 12892 KB Output is correct
31 Correct 1 ms 12892 KB Output is correct
32 Correct 2 ms 12892 KB Output is correct
33 Correct 2 ms 12892 KB Output is correct
34 Correct 2 ms 12892 KB Output is correct
35 Correct 2 ms 12892 KB Output is correct
36 Correct 2 ms 12924 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 13240 KB Output is correct
40 Correct 8 ms 13404 KB Output is correct
41 Correct 6 ms 13452 KB Output is correct
42 Correct 6 ms 13400 KB Output is correct
43 Correct 7 ms 13404 KB Output is correct
44 Correct 7 ms 13400 KB Output is correct
45 Correct 9 ms 13404 KB Output is correct
46 Correct 7 ms 13404 KB Output is correct
47 Correct 7 ms 13412 KB Output is correct
48 Correct 5 ms 13404 KB Output is correct
49 Correct 5 ms 13436 KB Output is correct
50 Correct 7 ms 13404 KB Output is correct
51 Correct 7 ms 13404 KB Output is correct
52 Correct 8 ms 13232 KB Output is correct
53 Correct 7 ms 13404 KB Output is correct
54 Correct 8 ms 13404 KB Output is correct
55 Correct 8 ms 13148 KB Output is correct
56 Correct 117 ms 32024 KB Output is correct
57 Correct 117 ms 32460 KB Output is correct
58 Correct 143 ms 31180 KB Output is correct
59 Correct 133 ms 31696 KB Output is correct
60 Correct 126 ms 32980 KB Output is correct
61 Correct 122 ms 31204 KB Output is correct
62 Correct 105 ms 31948 KB Output is correct
63 Correct 138 ms 33488 KB Output is correct
64 Correct 122 ms 33380 KB Output is correct
65 Correct 92 ms 31144 KB Output is correct
66 Correct 117 ms 32972 KB Output is correct
67 Correct 140 ms 33996 KB Output is correct
68 Correct 165 ms 33996 KB Output is correct
69 Correct 140 ms 33740 KB Output is correct
70 Correct 147 ms 34164 KB Output is correct
71 Correct 139 ms 34132 KB Output is correct
72 Correct 133 ms 34044 KB Output is correct
73 Correct 140 ms 34244 KB Output is correct
74 Correct 70 ms 33920 KB Output is correct
75 Correct 69 ms 34000 KB Output is correct
76 Correct 130 ms 34924 KB Output is correct
77 Correct 115 ms 35536 KB Output is correct
78 Correct 155 ms 35040 KB Output is correct
79 Correct 149 ms 33996 KB Output is correct
80 Correct 157 ms 32716 KB Output is correct
81 Correct 91 ms 34020 KB Output is correct
82 Correct 168 ms 32208 KB Output is correct
83 Correct 149 ms 33228 KB Output is correct
84 Correct 147 ms 33228 KB Output is correct
85 Correct 141 ms 34164 KB Output is correct
86 Correct 129 ms 34308 KB Output is correct
87 Correct 149 ms 34152 KB Output is correct
88 Correct 149 ms 34000 KB Output is correct
89 Correct 141 ms 34000 KB Output is correct
90 Correct 119 ms 36172 KB Output is correct
91 Correct 85 ms 34000 KB Output is correct
92 Correct 130 ms 33996 KB Output is correct
93 Correct 149 ms 33956 KB Output is correct
94 Correct 151 ms 34252 KB Output is correct
95 Correct 139 ms 34056 KB Output is correct
96 Correct 105 ms 35548 KB Output is correct
97 Correct 119 ms 36172 KB Output is correct
98 Correct 124 ms 36172 KB Output is correct
99 Correct 124 ms 36360 KB Output is correct
100 Correct 102 ms 35664 KB Output is correct
101 Correct 137 ms 36176 KB Output is correct
102 Correct 133 ms 36172 KB Output is correct
103 Correct 108 ms 34380 KB Output is correct