Submission #871143

# Submission time Handle Problem Language Result Execution time Memory
871143 2023-11-10T04:09:23 Z winter0101 Two Dishes (JOI19_dishes) C++17
74 / 100
3960 ms 251228 KB
#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define pil pair<int,long long>
const int maxn=1e6+9;
long long a[maxn],b[maxn],s[maxn],t[maxn],p[maxn],q[maxn];
long long f[maxn];
struct IT{
vector<long long>st;
void resz(int n){
st.resize(4*n+9);
}
void update(int id,int l,int r,int u,long long val){
if (l>u||r<u)return;
if (l==r){
    st[id]=val;
    return;
}
int mid=(l+r)/2;
update(id*2,l,mid,u,val);
update(id*2+1,mid+1,r,u,val);
st[id]=min(st[id*2],st[id*2+1]);
}
void cong(int id,int l,int r,int u,long long val){
if (l>u||r<u)return;
if (l==r){
    st[id]+=val;
    return;
}
int mid=(l+r)/2;
cong(id*2,l,mid,u,val);
cong(id*2+1,mid+1,r,u,val);
st[id]=min(st[id*2],st[id*2+1]);
}
long long get(int id,int l,int r,int u,int v){
if (l>v||r<u||u>v)return 2e15;
if (u<=l&&r<=v)return st[id];
int mid=(l+r)/2;
return min(get(id*2,l,mid,u,v),get(id*2+1,mid+1,r,u,v));
}
int findlow(int id,int l,int r){
if (st[id]>=0)return -1;
if (l==r)return l;
int mid=(l+r)/2;
if (st[id*2]<0)return findlow(id*2,l,mid);
else return findlow(id*2+1,mid+1,r);
}
}st;
vector<int>del[maxn];
long long g[maxn];
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("temp.INP","r",stdin);
    //freopen("temp.OUT","w",stdout);
    int n,m;
    cin>>n>>m;
    for1(i,1,n)cin>>a[i]>>s[i]>>p[i];
    for1(i,1,m)cin>>b[i]>>t[i]>>q[i];
    for1(i,1,n)a[i]+=a[i-1];
    for1(i,1,m)b[i]+=b[i-1];
    f[0]=0;
    long long prefixsum=0,mx=0;
    set<int>opt;
    opt.insert(0);
    st.resz(m+1);
    st.update(1,0,m,0,f[0]);
    for1(i,1,m){
    f[i]=f[i-1];
    if (b[i]<=t[i]){
    f[i]+=q[i];
    prefixsum+=q[i];
    }
    if (f[i]-prefixsum>mx){
    st.update(1,0,m,i,f[i]-prefixsum-mx);
    opt.insert(i);
    g[i]=f[i]-prefixsum-mx;
    mx=f[i]-prefixsum;
    }
    }
    for1(i,1,m){
    if (b[i]>t[i])continue;
    int l=1,r=n,ans=-1;
    while (l<=r){
    int mid=(l+r)/2;
    if (a[mid]+b[i]>t[i]){
    ans=mid;
    r=mid-1;
    }
    else l=mid+1;
    }
    if (ans!=-1)del[ans].pb(i);
    }
    for1(i,1,n){
    int l=0,r=m,ans=-1;
    while (l<=r){
    int mid=(l+r)/2;
    if (a[i]+b[mid]<=s[i]){
    ans=mid;
    l=mid+1;
    }
    else r=mid-1;
    }
    if (ans!=-1){
    st.cong(1,0,m,0,p[i]);
    st.cong(1,0,m,ans+1,-p[i]);
    opt.insert(ans+1);
    }
    for (auto v:del[i]){
    if (q[v]>=0){
    st.cong(1,0,m,v,q[v]);
    opt.insert(v);
    }
    else {
    st.cong(1,0,m,v,q[v]);
    opt.insert(v-1);
    }
    //cout<<i<<" "<<v<<'\n';
    }
    while (st.st[1]<0){
    int pos=st.findlow(1,0,m);
    auto it=opt.upper_bound(pos);
    if (it==opt.end()){
    st.update(1,0,m,pos,0);
    }
    else {
    long long val=st.get(1,0,m,(*it),(*it))+st.get(1,0,m,pos,pos);
    st.update(1,0,m,pos,0);
    st.update(1,0,m,(*it),val);
    }
    opt.erase(pos);
    }
    }
    prefixsum=0,mx=0;
    for1(i,0,m){
    mx+=st.get(1,0,m,i,i);
    if (a[n]+b[i]<=t[i])prefixsum+=q[i];
    }
    cout<<prefixsum+mx;
    //for1(i,0,m)cout<<st.get(1,0,m,i,i)<<'\n';
    //cout<<st.get(1,0,m,0,0)+st.get(1,0,m,1,1)+st.get(1,0,m,2,2);
}
# Verdict Execution time Memory Grader output
1 Correct 245 ms 80240 KB Output is correct
2 Correct 288 ms 71928 KB Output is correct
3 Correct 152 ms 68180 KB Output is correct
4 Correct 204 ms 77880 KB Output is correct
5 Correct 7 ms 39260 KB Output is correct
6 Correct 290 ms 68636 KB Output is correct
7 Correct 79 ms 58192 KB Output is correct
8 Correct 63 ms 49952 KB Output is correct
9 Correct 155 ms 69076 KB Output is correct
10 Correct 298 ms 68944 KB Output is correct
11 Correct 126 ms 62956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 39380 KB Output is correct
2 Correct 8 ms 39260 KB Output is correct
3 Correct 7 ms 39260 KB Output is correct
4 Correct 7 ms 39460 KB Output is correct
5 Correct 7 ms 39260 KB Output is correct
6 Correct 8 ms 39384 KB Output is correct
7 Correct 7 ms 39260 KB Output is correct
8 Correct 7 ms 39260 KB Output is correct
9 Correct 7 ms 39260 KB Output is correct
10 Correct 7 ms 39260 KB Output is correct
11 Correct 7 ms 39784 KB Output is correct
12 Correct 7 ms 39460 KB Output is correct
13 Correct 7 ms 39260 KB Output is correct
14 Correct 7 ms 39452 KB Output is correct
15 Correct 7 ms 39388 KB Output is correct
16 Correct 7 ms 39260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 39380 KB Output is correct
2 Correct 8 ms 39260 KB Output is correct
3 Correct 7 ms 39260 KB Output is correct
4 Correct 7 ms 39460 KB Output is correct
5 Correct 7 ms 39260 KB Output is correct
6 Correct 8 ms 39384 KB Output is correct
7 Correct 7 ms 39260 KB Output is correct
8 Correct 7 ms 39260 KB Output is correct
9 Correct 7 ms 39260 KB Output is correct
10 Correct 7 ms 39260 KB Output is correct
11 Correct 7 ms 39784 KB Output is correct
12 Correct 7 ms 39460 KB Output is correct
13 Correct 7 ms 39260 KB Output is correct
14 Correct 7 ms 39452 KB Output is correct
15 Correct 7 ms 39388 KB Output is correct
16 Correct 7 ms 39260 KB Output is correct
17 Correct 9 ms 41564 KB Output is correct
18 Correct 9 ms 41744 KB Output is correct
19 Correct 11 ms 41608 KB Output is correct
20 Correct 10 ms 41592 KB Output is correct
21 Correct 10 ms 41564 KB Output is correct
22 Correct 11 ms 41620 KB Output is correct
23 Correct 11 ms 41564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 39380 KB Output is correct
2 Correct 8 ms 39260 KB Output is correct
3 Correct 7 ms 39260 KB Output is correct
4 Correct 7 ms 39460 KB Output is correct
5 Correct 7 ms 39260 KB Output is correct
6 Correct 8 ms 39384 KB Output is correct
7 Correct 7 ms 39260 KB Output is correct
8 Correct 7 ms 39260 KB Output is correct
9 Correct 7 ms 39260 KB Output is correct
10 Correct 7 ms 39260 KB Output is correct
11 Correct 7 ms 39784 KB Output is correct
12 Correct 7 ms 39460 KB Output is correct
13 Correct 7 ms 39260 KB Output is correct
14 Correct 7 ms 39452 KB Output is correct
15 Correct 7 ms 39388 KB Output is correct
16 Correct 7 ms 39260 KB Output is correct
17 Correct 9 ms 41564 KB Output is correct
18 Correct 9 ms 41744 KB Output is correct
19 Correct 11 ms 41608 KB Output is correct
20 Correct 10 ms 41592 KB Output is correct
21 Correct 10 ms 41564 KB Output is correct
22 Correct 11 ms 41620 KB Output is correct
23 Correct 11 ms 41564 KB Output is correct
24 Correct 186 ms 65568 KB Output is correct
25 Correct 191 ms 75728 KB Output is correct
26 Correct 200 ms 65480 KB Output is correct
27 Correct 211 ms 81176 KB Output is correct
28 Correct 252 ms 67180 KB Output is correct
29 Correct 142 ms 66296 KB Output is correct
30 Correct 588 ms 69872 KB Output is correct
31 Correct 105 ms 62056 KB Output is correct
32 Correct 58 ms 48556 KB Output is correct
33 Correct 369 ms 67952 KB Output is correct
34 Correct 431 ms 69816 KB Output is correct
35 Correct 581 ms 63980 KB Output is correct
36 Correct 562 ms 63852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 39380 KB Output is correct
2 Correct 8 ms 39260 KB Output is correct
3 Correct 7 ms 39260 KB Output is correct
4 Correct 7 ms 39460 KB Output is correct
5 Correct 7 ms 39260 KB Output is correct
6 Correct 8 ms 39384 KB Output is correct
7 Correct 7 ms 39260 KB Output is correct
8 Correct 7 ms 39260 KB Output is correct
9 Correct 7 ms 39260 KB Output is correct
10 Correct 7 ms 39260 KB Output is correct
11 Correct 7 ms 39784 KB Output is correct
12 Correct 7 ms 39460 KB Output is correct
13 Correct 7 ms 39260 KB Output is correct
14 Correct 7 ms 39452 KB Output is correct
15 Correct 7 ms 39388 KB Output is correct
16 Correct 7 ms 39260 KB Output is correct
17 Correct 9 ms 41564 KB Output is correct
18 Correct 9 ms 41744 KB Output is correct
19 Correct 11 ms 41608 KB Output is correct
20 Correct 10 ms 41592 KB Output is correct
21 Correct 10 ms 41564 KB Output is correct
22 Correct 11 ms 41620 KB Output is correct
23 Correct 11 ms 41564 KB Output is correct
24 Correct 186 ms 65568 KB Output is correct
25 Correct 191 ms 75728 KB Output is correct
26 Correct 200 ms 65480 KB Output is correct
27 Correct 211 ms 81176 KB Output is correct
28 Correct 252 ms 67180 KB Output is correct
29 Correct 142 ms 66296 KB Output is correct
30 Correct 588 ms 69872 KB Output is correct
31 Correct 105 ms 62056 KB Output is correct
32 Correct 58 ms 48556 KB Output is correct
33 Correct 369 ms 67952 KB Output is correct
34 Correct 431 ms 69816 KB Output is correct
35 Correct 581 ms 63980 KB Output is correct
36 Correct 562 ms 63852 KB Output is correct
37 Correct 221 ms 68440 KB Output is correct
38 Correct 241 ms 84028 KB Output is correct
39 Correct 371 ms 81672 KB Output is correct
40 Correct 289 ms 72428 KB Output is correct
41 Correct 7 ms 39256 KB Output is correct
42 Correct 600 ms 72584 KB Output is correct
43 Correct 413 ms 70484 KB Output is correct
44 Correct 432 ms 72240 KB Output is correct
45 Correct 581 ms 66916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 39380 KB Output is correct
2 Correct 8 ms 39260 KB Output is correct
3 Correct 7 ms 39260 KB Output is correct
4 Correct 7 ms 39460 KB Output is correct
5 Correct 7 ms 39260 KB Output is correct
6 Correct 8 ms 39384 KB Output is correct
7 Correct 7 ms 39260 KB Output is correct
8 Correct 7 ms 39260 KB Output is correct
9 Correct 7 ms 39260 KB Output is correct
10 Correct 7 ms 39260 KB Output is correct
11 Correct 7 ms 39784 KB Output is correct
12 Correct 7 ms 39460 KB Output is correct
13 Correct 7 ms 39260 KB Output is correct
14 Correct 7 ms 39452 KB Output is correct
15 Correct 7 ms 39388 KB Output is correct
16 Correct 7 ms 39260 KB Output is correct
17 Correct 9 ms 41564 KB Output is correct
18 Correct 9 ms 41744 KB Output is correct
19 Correct 11 ms 41608 KB Output is correct
20 Correct 10 ms 41592 KB Output is correct
21 Correct 10 ms 41564 KB Output is correct
22 Correct 11 ms 41620 KB Output is correct
23 Correct 11 ms 41564 KB Output is correct
24 Correct 186 ms 65568 KB Output is correct
25 Correct 191 ms 75728 KB Output is correct
26 Correct 200 ms 65480 KB Output is correct
27 Correct 211 ms 81176 KB Output is correct
28 Correct 252 ms 67180 KB Output is correct
29 Correct 142 ms 66296 KB Output is correct
30 Correct 588 ms 69872 KB Output is correct
31 Correct 105 ms 62056 KB Output is correct
32 Correct 58 ms 48556 KB Output is correct
33 Correct 369 ms 67952 KB Output is correct
34 Correct 431 ms 69816 KB Output is correct
35 Correct 581 ms 63980 KB Output is correct
36 Correct 562 ms 63852 KB Output is correct
37 Correct 221 ms 68440 KB Output is correct
38 Correct 241 ms 84028 KB Output is correct
39 Correct 371 ms 81672 KB Output is correct
40 Correct 289 ms 72428 KB Output is correct
41 Correct 7 ms 39256 KB Output is correct
42 Correct 600 ms 72584 KB Output is correct
43 Correct 413 ms 70484 KB Output is correct
44 Correct 432 ms 72240 KB Output is correct
45 Correct 581 ms 66916 KB Output is correct
46 Correct 1129 ms 164288 KB Output is correct
47 Correct 1187 ms 251228 KB Output is correct
48 Correct 1989 ms 239412 KB Output is correct
49 Correct 1466 ms 192452 KB Output is correct
50 Correct 3960 ms 184612 KB Output is correct
51 Correct 2255 ms 173128 KB Output is correct
52 Correct 2613 ms 197640 KB Output is correct
53 Correct 3727 ms 165204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 245 ms 80240 KB Output is correct
2 Correct 288 ms 71928 KB Output is correct
3 Correct 152 ms 68180 KB Output is correct
4 Correct 204 ms 77880 KB Output is correct
5 Correct 7 ms 39260 KB Output is correct
6 Correct 290 ms 68636 KB Output is correct
7 Correct 79 ms 58192 KB Output is correct
8 Correct 63 ms 49952 KB Output is correct
9 Correct 155 ms 69076 KB Output is correct
10 Correct 298 ms 68944 KB Output is correct
11 Correct 126 ms 62956 KB Output is correct
12 Correct 7 ms 39380 KB Output is correct
13 Correct 8 ms 39260 KB Output is correct
14 Correct 7 ms 39260 KB Output is correct
15 Correct 7 ms 39460 KB Output is correct
16 Correct 7 ms 39260 KB Output is correct
17 Correct 8 ms 39384 KB Output is correct
18 Correct 7 ms 39260 KB Output is correct
19 Correct 7 ms 39260 KB Output is correct
20 Correct 7 ms 39260 KB Output is correct
21 Correct 7 ms 39260 KB Output is correct
22 Correct 7 ms 39784 KB Output is correct
23 Correct 7 ms 39460 KB Output is correct
24 Correct 7 ms 39260 KB Output is correct
25 Correct 7 ms 39452 KB Output is correct
26 Correct 7 ms 39388 KB Output is correct
27 Correct 7 ms 39260 KB Output is correct
28 Correct 9 ms 41564 KB Output is correct
29 Correct 9 ms 41744 KB Output is correct
30 Correct 11 ms 41608 KB Output is correct
31 Correct 10 ms 41592 KB Output is correct
32 Correct 10 ms 41564 KB Output is correct
33 Correct 11 ms 41620 KB Output is correct
34 Correct 11 ms 41564 KB Output is correct
35 Correct 186 ms 65568 KB Output is correct
36 Correct 191 ms 75728 KB Output is correct
37 Correct 200 ms 65480 KB Output is correct
38 Correct 211 ms 81176 KB Output is correct
39 Correct 252 ms 67180 KB Output is correct
40 Correct 142 ms 66296 KB Output is correct
41 Correct 588 ms 69872 KB Output is correct
42 Correct 105 ms 62056 KB Output is correct
43 Correct 58 ms 48556 KB Output is correct
44 Correct 369 ms 67952 KB Output is correct
45 Correct 431 ms 69816 KB Output is correct
46 Correct 581 ms 63980 KB Output is correct
47 Correct 562 ms 63852 KB Output is correct
48 Correct 221 ms 68440 KB Output is correct
49 Correct 241 ms 84028 KB Output is correct
50 Correct 371 ms 81672 KB Output is correct
51 Correct 289 ms 72428 KB Output is correct
52 Correct 7 ms 39256 KB Output is correct
53 Correct 600 ms 72584 KB Output is correct
54 Correct 413 ms 70484 KB Output is correct
55 Correct 432 ms 72240 KB Output is correct
56 Correct 581 ms 66916 KB Output is correct
57 Correct 346 ms 68692 KB Output is correct
58 Incorrect 353 ms 75216 KB Output isn't correct
59 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 245 ms 80240 KB Output is correct
2 Correct 288 ms 71928 KB Output is correct
3 Correct 152 ms 68180 KB Output is correct
4 Correct 204 ms 77880 KB Output is correct
5 Correct 7 ms 39260 KB Output is correct
6 Correct 290 ms 68636 KB Output is correct
7 Correct 79 ms 58192 KB Output is correct
8 Correct 63 ms 49952 KB Output is correct
9 Correct 155 ms 69076 KB Output is correct
10 Correct 298 ms 68944 KB Output is correct
11 Correct 126 ms 62956 KB Output is correct
12 Correct 7 ms 39380 KB Output is correct
13 Correct 8 ms 39260 KB Output is correct
14 Correct 7 ms 39260 KB Output is correct
15 Correct 7 ms 39460 KB Output is correct
16 Correct 7 ms 39260 KB Output is correct
17 Correct 8 ms 39384 KB Output is correct
18 Correct 7 ms 39260 KB Output is correct
19 Correct 7 ms 39260 KB Output is correct
20 Correct 7 ms 39260 KB Output is correct
21 Correct 7 ms 39260 KB Output is correct
22 Correct 7 ms 39784 KB Output is correct
23 Correct 7 ms 39460 KB Output is correct
24 Correct 7 ms 39260 KB Output is correct
25 Correct 7 ms 39452 KB Output is correct
26 Correct 7 ms 39388 KB Output is correct
27 Correct 7 ms 39260 KB Output is correct
28 Correct 9 ms 41564 KB Output is correct
29 Correct 9 ms 41744 KB Output is correct
30 Correct 11 ms 41608 KB Output is correct
31 Correct 10 ms 41592 KB Output is correct
32 Correct 10 ms 41564 KB Output is correct
33 Correct 11 ms 41620 KB Output is correct
34 Correct 11 ms 41564 KB Output is correct
35 Correct 186 ms 65568 KB Output is correct
36 Correct 191 ms 75728 KB Output is correct
37 Correct 200 ms 65480 KB Output is correct
38 Correct 211 ms 81176 KB Output is correct
39 Correct 252 ms 67180 KB Output is correct
40 Correct 142 ms 66296 KB Output is correct
41 Correct 588 ms 69872 KB Output is correct
42 Correct 105 ms 62056 KB Output is correct
43 Correct 58 ms 48556 KB Output is correct
44 Correct 369 ms 67952 KB Output is correct
45 Correct 431 ms 69816 KB Output is correct
46 Correct 581 ms 63980 KB Output is correct
47 Correct 562 ms 63852 KB Output is correct
48 Correct 221 ms 68440 KB Output is correct
49 Correct 241 ms 84028 KB Output is correct
50 Correct 371 ms 81672 KB Output is correct
51 Correct 289 ms 72428 KB Output is correct
52 Correct 7 ms 39256 KB Output is correct
53 Correct 600 ms 72584 KB Output is correct
54 Correct 413 ms 70484 KB Output is correct
55 Correct 432 ms 72240 KB Output is correct
56 Correct 581 ms 66916 KB Output is correct
57 Correct 1129 ms 164288 KB Output is correct
58 Correct 1187 ms 251228 KB Output is correct
59 Correct 1989 ms 239412 KB Output is correct
60 Correct 1466 ms 192452 KB Output is correct
61 Correct 3960 ms 184612 KB Output is correct
62 Correct 2255 ms 173128 KB Output is correct
63 Correct 2613 ms 197640 KB Output is correct
64 Correct 3727 ms 165204 KB Output is correct
65 Correct 346 ms 68692 KB Output is correct
66 Incorrect 353 ms 75216 KB Output isn't correct
67 Halted 0 ms 0 KB -