답안 #871142

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
871142 2023-11-10T04:01:23 Z winter0101 Two Dishes (JOI19_dishes) C++14
74 / 100
4116 ms 259624 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]){
    st.cong(1,0,m,v,q[v]);
    opt.insert(v);
    //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<<i<<" "<<prefixsum<<" "<<st.get(1,0,m,i,i)<<" "<<mx+prefixsum<<'\n';
    }
    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);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 260 ms 81616 KB Output is correct
2 Correct 297 ms 73220 KB Output is correct
3 Correct 154 ms 69272 KB Output is correct
4 Correct 210 ms 79456 KB Output is correct
5 Correct 7 ms 39256 KB Output is correct
6 Correct 294 ms 69984 KB Output is correct
7 Correct 90 ms 58896 KB Output is correct
8 Correct 59 ms 50308 KB Output is correct
9 Correct 154 ms 70228 KB Output is correct
10 Correct 303 ms 69656 KB Output is correct
11 Correct 128 ms 63512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 39256 KB Output is correct
2 Correct 7 ms 39256 KB Output is correct
3 Correct 8 ms 39260 KB Output is correct
4 Correct 7 ms 39404 KB Output is correct
5 Correct 7 ms 39512 KB Output is correct
6 Correct 7 ms 39260 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 39384 KB Output is correct
10 Correct 7 ms 39448 KB Output is correct
11 Correct 7 ms 39464 KB Output is correct
12 Correct 7 ms 39264 KB Output is correct
13 Correct 7 ms 39264 KB Output is correct
14 Correct 7 ms 39264 KB Output is correct
15 Correct 7 ms 39264 KB Output is correct
16 Correct 7 ms 39264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 39256 KB Output is correct
2 Correct 7 ms 39256 KB Output is correct
3 Correct 8 ms 39260 KB Output is correct
4 Correct 7 ms 39404 KB Output is correct
5 Correct 7 ms 39512 KB Output is correct
6 Correct 7 ms 39260 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 39384 KB Output is correct
10 Correct 7 ms 39448 KB Output is correct
11 Correct 7 ms 39464 KB Output is correct
12 Correct 7 ms 39264 KB Output is correct
13 Correct 7 ms 39264 KB Output is correct
14 Correct 7 ms 39264 KB Output is correct
15 Correct 7 ms 39264 KB Output is correct
16 Correct 7 ms 39264 KB Output is correct
17 Correct 9 ms 41568 KB Output is correct
18 Correct 9 ms 41568 KB Output is correct
19 Correct 11 ms 41604 KB Output is correct
20 Correct 10 ms 41700 KB Output is correct
21 Correct 10 ms 41564 KB Output is correct
22 Correct 13 ms 41564 KB Output is correct
23 Correct 13 ms 41564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 39256 KB Output is correct
2 Correct 7 ms 39256 KB Output is correct
3 Correct 8 ms 39260 KB Output is correct
4 Correct 7 ms 39404 KB Output is correct
5 Correct 7 ms 39512 KB Output is correct
6 Correct 7 ms 39260 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 39384 KB Output is correct
10 Correct 7 ms 39448 KB Output is correct
11 Correct 7 ms 39464 KB Output is correct
12 Correct 7 ms 39264 KB Output is correct
13 Correct 7 ms 39264 KB Output is correct
14 Correct 7 ms 39264 KB Output is correct
15 Correct 7 ms 39264 KB Output is correct
16 Correct 7 ms 39264 KB Output is correct
17 Correct 9 ms 41568 KB Output is correct
18 Correct 9 ms 41568 KB Output is correct
19 Correct 11 ms 41604 KB Output is correct
20 Correct 10 ms 41700 KB Output is correct
21 Correct 10 ms 41564 KB Output is correct
22 Correct 13 ms 41564 KB Output is correct
23 Correct 13 ms 41564 KB Output is correct
24 Correct 180 ms 66384 KB Output is correct
25 Correct 202 ms 76496 KB Output is correct
26 Correct 214 ms 66580 KB Output is correct
27 Correct 214 ms 82168 KB Output is correct
28 Correct 266 ms 68004 KB Output is correct
29 Correct 153 ms 67144 KB Output is correct
30 Correct 605 ms 70680 KB Output is correct
31 Correct 96 ms 62164 KB Output is correct
32 Correct 59 ms 48760 KB Output is correct
33 Correct 362 ms 68688 KB Output is correct
34 Correct 418 ms 70508 KB Output is correct
35 Correct 591 ms 64560 KB Output is correct
36 Correct 582 ms 64728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 39256 KB Output is correct
2 Correct 7 ms 39256 KB Output is correct
3 Correct 8 ms 39260 KB Output is correct
4 Correct 7 ms 39404 KB Output is correct
5 Correct 7 ms 39512 KB Output is correct
6 Correct 7 ms 39260 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 39384 KB Output is correct
10 Correct 7 ms 39448 KB Output is correct
11 Correct 7 ms 39464 KB Output is correct
12 Correct 7 ms 39264 KB Output is correct
13 Correct 7 ms 39264 KB Output is correct
14 Correct 7 ms 39264 KB Output is correct
15 Correct 7 ms 39264 KB Output is correct
16 Correct 7 ms 39264 KB Output is correct
17 Correct 9 ms 41568 KB Output is correct
18 Correct 9 ms 41568 KB Output is correct
19 Correct 11 ms 41604 KB Output is correct
20 Correct 10 ms 41700 KB Output is correct
21 Correct 10 ms 41564 KB Output is correct
22 Correct 13 ms 41564 KB Output is correct
23 Correct 13 ms 41564 KB Output is correct
24 Correct 180 ms 66384 KB Output is correct
25 Correct 202 ms 76496 KB Output is correct
26 Correct 214 ms 66580 KB Output is correct
27 Correct 214 ms 82168 KB Output is correct
28 Correct 266 ms 68004 KB Output is correct
29 Correct 153 ms 67144 KB Output is correct
30 Correct 605 ms 70680 KB Output is correct
31 Correct 96 ms 62164 KB Output is correct
32 Correct 59 ms 48760 KB Output is correct
33 Correct 362 ms 68688 KB Output is correct
34 Correct 418 ms 70508 KB Output is correct
35 Correct 591 ms 64560 KB Output is correct
36 Correct 582 ms 64728 KB Output is correct
37 Correct 214 ms 69488 KB Output is correct
38 Correct 219 ms 85072 KB Output is correct
39 Correct 388 ms 82512 KB Output is correct
40 Correct 281 ms 73044 KB Output is correct
41 Correct 8 ms 39260 KB Output is correct
42 Correct 610 ms 73604 KB Output is correct
43 Correct 388 ms 71584 KB Output is correct
44 Correct 428 ms 73560 KB Output is correct
45 Correct 600 ms 64084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 39256 KB Output is correct
2 Correct 7 ms 39256 KB Output is correct
3 Correct 8 ms 39260 KB Output is correct
4 Correct 7 ms 39404 KB Output is correct
5 Correct 7 ms 39512 KB Output is correct
6 Correct 7 ms 39260 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 39384 KB Output is correct
10 Correct 7 ms 39448 KB Output is correct
11 Correct 7 ms 39464 KB Output is correct
12 Correct 7 ms 39264 KB Output is correct
13 Correct 7 ms 39264 KB Output is correct
14 Correct 7 ms 39264 KB Output is correct
15 Correct 7 ms 39264 KB Output is correct
16 Correct 7 ms 39264 KB Output is correct
17 Correct 9 ms 41568 KB Output is correct
18 Correct 9 ms 41568 KB Output is correct
19 Correct 11 ms 41604 KB Output is correct
20 Correct 10 ms 41700 KB Output is correct
21 Correct 10 ms 41564 KB Output is correct
22 Correct 13 ms 41564 KB Output is correct
23 Correct 13 ms 41564 KB Output is correct
24 Correct 180 ms 66384 KB Output is correct
25 Correct 202 ms 76496 KB Output is correct
26 Correct 214 ms 66580 KB Output is correct
27 Correct 214 ms 82168 KB Output is correct
28 Correct 266 ms 68004 KB Output is correct
29 Correct 153 ms 67144 KB Output is correct
30 Correct 605 ms 70680 KB Output is correct
31 Correct 96 ms 62164 KB Output is correct
32 Correct 59 ms 48760 KB Output is correct
33 Correct 362 ms 68688 KB Output is correct
34 Correct 418 ms 70508 KB Output is correct
35 Correct 591 ms 64560 KB Output is correct
36 Correct 582 ms 64728 KB Output is correct
37 Correct 214 ms 69488 KB Output is correct
38 Correct 219 ms 85072 KB Output is correct
39 Correct 388 ms 82512 KB Output is correct
40 Correct 281 ms 73044 KB Output is correct
41 Correct 8 ms 39260 KB Output is correct
42 Correct 610 ms 73604 KB Output is correct
43 Correct 388 ms 71584 KB Output is correct
44 Correct 428 ms 73560 KB Output is correct
45 Correct 600 ms 64084 KB Output is correct
46 Correct 1128 ms 181212 KB Output is correct
47 Correct 1250 ms 259624 KB Output is correct
48 Correct 2069 ms 246200 KB Output is correct
49 Correct 1466 ms 198992 KB Output is correct
50 Correct 4116 ms 201452 KB Output is correct
51 Correct 2299 ms 189640 KB Output is correct
52 Correct 2720 ms 205660 KB Output is correct
53 Correct 3808 ms 169952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 260 ms 81616 KB Output is correct
2 Correct 297 ms 73220 KB Output is correct
3 Correct 154 ms 69272 KB Output is correct
4 Correct 210 ms 79456 KB Output is correct
5 Correct 7 ms 39256 KB Output is correct
6 Correct 294 ms 69984 KB Output is correct
7 Correct 90 ms 58896 KB Output is correct
8 Correct 59 ms 50308 KB Output is correct
9 Correct 154 ms 70228 KB Output is correct
10 Correct 303 ms 69656 KB Output is correct
11 Correct 128 ms 63512 KB Output is correct
12 Correct 8 ms 39256 KB Output is correct
13 Correct 7 ms 39256 KB Output is correct
14 Correct 8 ms 39260 KB Output is correct
15 Correct 7 ms 39404 KB Output is correct
16 Correct 7 ms 39512 KB Output is correct
17 Correct 7 ms 39260 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 39384 KB Output is correct
21 Correct 7 ms 39448 KB Output is correct
22 Correct 7 ms 39464 KB Output is correct
23 Correct 7 ms 39264 KB Output is correct
24 Correct 7 ms 39264 KB Output is correct
25 Correct 7 ms 39264 KB Output is correct
26 Correct 7 ms 39264 KB Output is correct
27 Correct 7 ms 39264 KB Output is correct
28 Correct 9 ms 41568 KB Output is correct
29 Correct 9 ms 41568 KB Output is correct
30 Correct 11 ms 41604 KB Output is correct
31 Correct 10 ms 41700 KB Output is correct
32 Correct 10 ms 41564 KB Output is correct
33 Correct 13 ms 41564 KB Output is correct
34 Correct 13 ms 41564 KB Output is correct
35 Correct 180 ms 66384 KB Output is correct
36 Correct 202 ms 76496 KB Output is correct
37 Correct 214 ms 66580 KB Output is correct
38 Correct 214 ms 82168 KB Output is correct
39 Correct 266 ms 68004 KB Output is correct
40 Correct 153 ms 67144 KB Output is correct
41 Correct 605 ms 70680 KB Output is correct
42 Correct 96 ms 62164 KB Output is correct
43 Correct 59 ms 48760 KB Output is correct
44 Correct 362 ms 68688 KB Output is correct
45 Correct 418 ms 70508 KB Output is correct
46 Correct 591 ms 64560 KB Output is correct
47 Correct 582 ms 64728 KB Output is correct
48 Correct 214 ms 69488 KB Output is correct
49 Correct 219 ms 85072 KB Output is correct
50 Correct 388 ms 82512 KB Output is correct
51 Correct 281 ms 73044 KB Output is correct
52 Correct 8 ms 39260 KB Output is correct
53 Correct 610 ms 73604 KB Output is correct
54 Correct 388 ms 71584 KB Output is correct
55 Correct 428 ms 73560 KB Output is correct
56 Correct 600 ms 64084 KB Output is correct
57 Correct 343 ms 69916 KB Output is correct
58 Incorrect 274 ms 76368 KB Output isn't correct
59 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 260 ms 81616 KB Output is correct
2 Correct 297 ms 73220 KB Output is correct
3 Correct 154 ms 69272 KB Output is correct
4 Correct 210 ms 79456 KB Output is correct
5 Correct 7 ms 39256 KB Output is correct
6 Correct 294 ms 69984 KB Output is correct
7 Correct 90 ms 58896 KB Output is correct
8 Correct 59 ms 50308 KB Output is correct
9 Correct 154 ms 70228 KB Output is correct
10 Correct 303 ms 69656 KB Output is correct
11 Correct 128 ms 63512 KB Output is correct
12 Correct 8 ms 39256 KB Output is correct
13 Correct 7 ms 39256 KB Output is correct
14 Correct 8 ms 39260 KB Output is correct
15 Correct 7 ms 39404 KB Output is correct
16 Correct 7 ms 39512 KB Output is correct
17 Correct 7 ms 39260 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 39384 KB Output is correct
21 Correct 7 ms 39448 KB Output is correct
22 Correct 7 ms 39464 KB Output is correct
23 Correct 7 ms 39264 KB Output is correct
24 Correct 7 ms 39264 KB Output is correct
25 Correct 7 ms 39264 KB Output is correct
26 Correct 7 ms 39264 KB Output is correct
27 Correct 7 ms 39264 KB Output is correct
28 Correct 9 ms 41568 KB Output is correct
29 Correct 9 ms 41568 KB Output is correct
30 Correct 11 ms 41604 KB Output is correct
31 Correct 10 ms 41700 KB Output is correct
32 Correct 10 ms 41564 KB Output is correct
33 Correct 13 ms 41564 KB Output is correct
34 Correct 13 ms 41564 KB Output is correct
35 Correct 180 ms 66384 KB Output is correct
36 Correct 202 ms 76496 KB Output is correct
37 Correct 214 ms 66580 KB Output is correct
38 Correct 214 ms 82168 KB Output is correct
39 Correct 266 ms 68004 KB Output is correct
40 Correct 153 ms 67144 KB Output is correct
41 Correct 605 ms 70680 KB Output is correct
42 Correct 96 ms 62164 KB Output is correct
43 Correct 59 ms 48760 KB Output is correct
44 Correct 362 ms 68688 KB Output is correct
45 Correct 418 ms 70508 KB Output is correct
46 Correct 591 ms 64560 KB Output is correct
47 Correct 582 ms 64728 KB Output is correct
48 Correct 214 ms 69488 KB Output is correct
49 Correct 219 ms 85072 KB Output is correct
50 Correct 388 ms 82512 KB Output is correct
51 Correct 281 ms 73044 KB Output is correct
52 Correct 8 ms 39260 KB Output is correct
53 Correct 610 ms 73604 KB Output is correct
54 Correct 388 ms 71584 KB Output is correct
55 Correct 428 ms 73560 KB Output is correct
56 Correct 600 ms 64084 KB Output is correct
57 Correct 1128 ms 181212 KB Output is correct
58 Correct 1250 ms 259624 KB Output is correct
59 Correct 2069 ms 246200 KB Output is correct
60 Correct 1466 ms 198992 KB Output is correct
61 Correct 4116 ms 201452 KB Output is correct
62 Correct 2299 ms 189640 KB Output is correct
63 Correct 2720 ms 205660 KB Output is correct
64 Correct 3808 ms 169952 KB Output is correct
65 Correct 343 ms 69916 KB Output is correct
66 Incorrect 274 ms 76368 KB Output isn't correct
67 Halted 0 ms 0 KB -