답안 #871145

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
871145 2023-11-10T04:15:16 Z winter0101 Two Dishes (JOI19_dishes) C++14
100 / 100
3948 ms 251592 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>
#define 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+1]<0)return findlow(id*2+1,mid+1,r);
else return findlow(id*2,l,mid);
}
}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);
    if (pos==0)break;
    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);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 236 ms 80272 KB Output is correct
2 Correct 290 ms 72020 KB Output is correct
3 Correct 153 ms 67836 KB Output is correct
4 Correct 203 ms 77936 KB Output is correct
5 Correct 8 ms 39260 KB Output is correct
6 Correct 282 ms 68740 KB Output is correct
7 Correct 79 ms 57936 KB Output is correct
8 Correct 62 ms 50300 KB Output is correct
9 Correct 155 ms 68868 KB Output is correct
10 Correct 298 ms 68940 KB Output is correct
11 Correct 124 ms 63488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 39260 KB Output is correct
2 Correct 7 ms 39428 KB Output is correct
3 Correct 7 ms 39256 KB Output is correct
4 Correct 7 ms 39512 KB Output is correct
5 Correct 7 ms 39260 KB Output is correct
6 Correct 7 ms 39444 KB Output is correct
7 Correct 8 ms 39260 KB Output is correct
8 Correct 7 ms 39260 KB Output is correct
9 Correct 8 ms 39260 KB Output is correct
10 Correct 7 ms 39384 KB Output is correct
11 Correct 7 ms 39260 KB Output is correct
12 Correct 7 ms 39260 KB Output is correct
13 Correct 8 ms 39516 KB Output is correct
14 Correct 7 ms 39260 KB Output is correct
15 Correct 7 ms 39452 KB Output is correct
16 Correct 7 ms 39260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 39260 KB Output is correct
2 Correct 7 ms 39428 KB Output is correct
3 Correct 7 ms 39256 KB Output is correct
4 Correct 7 ms 39512 KB Output is correct
5 Correct 7 ms 39260 KB Output is correct
6 Correct 7 ms 39444 KB Output is correct
7 Correct 8 ms 39260 KB Output is correct
8 Correct 7 ms 39260 KB Output is correct
9 Correct 8 ms 39260 KB Output is correct
10 Correct 7 ms 39384 KB Output is correct
11 Correct 7 ms 39260 KB Output is correct
12 Correct 7 ms 39260 KB Output is correct
13 Correct 8 ms 39516 KB Output is correct
14 Correct 7 ms 39260 KB Output is correct
15 Correct 7 ms 39452 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 41564 KB Output is correct
19 Correct 11 ms 41560 KB Output is correct
20 Correct 10 ms 41560 KB Output is correct
21 Correct 10 ms 41564 KB Output is correct
22 Correct 11 ms 41532 KB Output is correct
23 Correct 11 ms 41564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 39260 KB Output is correct
2 Correct 7 ms 39428 KB Output is correct
3 Correct 7 ms 39256 KB Output is correct
4 Correct 7 ms 39512 KB Output is correct
5 Correct 7 ms 39260 KB Output is correct
6 Correct 7 ms 39444 KB Output is correct
7 Correct 8 ms 39260 KB Output is correct
8 Correct 7 ms 39260 KB Output is correct
9 Correct 8 ms 39260 KB Output is correct
10 Correct 7 ms 39384 KB Output is correct
11 Correct 7 ms 39260 KB Output is correct
12 Correct 7 ms 39260 KB Output is correct
13 Correct 8 ms 39516 KB Output is correct
14 Correct 7 ms 39260 KB Output is correct
15 Correct 7 ms 39452 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 41564 KB Output is correct
19 Correct 11 ms 41560 KB Output is correct
20 Correct 10 ms 41560 KB Output is correct
21 Correct 10 ms 41564 KB Output is correct
22 Correct 11 ms 41532 KB Output is correct
23 Correct 11 ms 41564 KB Output is correct
24 Correct 182 ms 65520 KB Output is correct
25 Correct 188 ms 76504 KB Output is correct
26 Correct 202 ms 65672 KB Output is correct
27 Correct 219 ms 81488 KB Output is correct
28 Correct 263 ms 66900 KB Output is correct
29 Correct 138 ms 66400 KB Output is correct
30 Correct 599 ms 69972 KB Output is correct
31 Correct 104 ms 62196 KB Output is correct
32 Correct 58 ms 48468 KB Output is correct
33 Correct 366 ms 67968 KB Output is correct
34 Correct 416 ms 70356 KB Output is correct
35 Correct 599 ms 64080 KB Output is correct
36 Correct 557 ms 64204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 39260 KB Output is correct
2 Correct 7 ms 39428 KB Output is correct
3 Correct 7 ms 39256 KB Output is correct
4 Correct 7 ms 39512 KB Output is correct
5 Correct 7 ms 39260 KB Output is correct
6 Correct 7 ms 39444 KB Output is correct
7 Correct 8 ms 39260 KB Output is correct
8 Correct 7 ms 39260 KB Output is correct
9 Correct 8 ms 39260 KB Output is correct
10 Correct 7 ms 39384 KB Output is correct
11 Correct 7 ms 39260 KB Output is correct
12 Correct 7 ms 39260 KB Output is correct
13 Correct 8 ms 39516 KB Output is correct
14 Correct 7 ms 39260 KB Output is correct
15 Correct 7 ms 39452 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 41564 KB Output is correct
19 Correct 11 ms 41560 KB Output is correct
20 Correct 10 ms 41560 KB Output is correct
21 Correct 10 ms 41564 KB Output is correct
22 Correct 11 ms 41532 KB Output is correct
23 Correct 11 ms 41564 KB Output is correct
24 Correct 182 ms 65520 KB Output is correct
25 Correct 188 ms 76504 KB Output is correct
26 Correct 202 ms 65672 KB Output is correct
27 Correct 219 ms 81488 KB Output is correct
28 Correct 263 ms 66900 KB Output is correct
29 Correct 138 ms 66400 KB Output is correct
30 Correct 599 ms 69972 KB Output is correct
31 Correct 104 ms 62196 KB Output is correct
32 Correct 58 ms 48468 KB Output is correct
33 Correct 366 ms 67968 KB Output is correct
34 Correct 416 ms 70356 KB Output is correct
35 Correct 599 ms 64080 KB Output is correct
36 Correct 557 ms 64204 KB Output is correct
37 Correct 212 ms 68208 KB Output is correct
38 Correct 222 ms 84740 KB Output is correct
39 Correct 367 ms 82216 KB Output is correct
40 Correct 274 ms 72960 KB Output is correct
41 Correct 7 ms 39256 KB Output is correct
42 Correct 602 ms 73324 KB Output is correct
43 Correct 393 ms 71776 KB Output is correct
44 Correct 458 ms 73380 KB Output is correct
45 Correct 576 ms 67572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 39260 KB Output is correct
2 Correct 7 ms 39428 KB Output is correct
3 Correct 7 ms 39256 KB Output is correct
4 Correct 7 ms 39512 KB Output is correct
5 Correct 7 ms 39260 KB Output is correct
6 Correct 7 ms 39444 KB Output is correct
7 Correct 8 ms 39260 KB Output is correct
8 Correct 7 ms 39260 KB Output is correct
9 Correct 8 ms 39260 KB Output is correct
10 Correct 7 ms 39384 KB Output is correct
11 Correct 7 ms 39260 KB Output is correct
12 Correct 7 ms 39260 KB Output is correct
13 Correct 8 ms 39516 KB Output is correct
14 Correct 7 ms 39260 KB Output is correct
15 Correct 7 ms 39452 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 41564 KB Output is correct
19 Correct 11 ms 41560 KB Output is correct
20 Correct 10 ms 41560 KB Output is correct
21 Correct 10 ms 41564 KB Output is correct
22 Correct 11 ms 41532 KB Output is correct
23 Correct 11 ms 41564 KB Output is correct
24 Correct 182 ms 65520 KB Output is correct
25 Correct 188 ms 76504 KB Output is correct
26 Correct 202 ms 65672 KB Output is correct
27 Correct 219 ms 81488 KB Output is correct
28 Correct 263 ms 66900 KB Output is correct
29 Correct 138 ms 66400 KB Output is correct
30 Correct 599 ms 69972 KB Output is correct
31 Correct 104 ms 62196 KB Output is correct
32 Correct 58 ms 48468 KB Output is correct
33 Correct 366 ms 67968 KB Output is correct
34 Correct 416 ms 70356 KB Output is correct
35 Correct 599 ms 64080 KB Output is correct
36 Correct 557 ms 64204 KB Output is correct
37 Correct 212 ms 68208 KB Output is correct
38 Correct 222 ms 84740 KB Output is correct
39 Correct 367 ms 82216 KB Output is correct
40 Correct 274 ms 72960 KB Output is correct
41 Correct 7 ms 39256 KB Output is correct
42 Correct 602 ms 73324 KB Output is correct
43 Correct 393 ms 71776 KB Output is correct
44 Correct 458 ms 73380 KB Output is correct
45 Correct 576 ms 67572 KB Output is correct
46 Correct 1080 ms 174380 KB Output is correct
47 Correct 1192 ms 251592 KB Output is correct
48 Correct 1976 ms 239696 KB Output is correct
49 Correct 1431 ms 196364 KB Output is correct
50 Correct 3948 ms 199264 KB Output is correct
51 Correct 2176 ms 183656 KB Output is correct
52 Correct 2610 ms 199712 KB Output is correct
53 Correct 3744 ms 166856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 236 ms 80272 KB Output is correct
2 Correct 290 ms 72020 KB Output is correct
3 Correct 153 ms 67836 KB Output is correct
4 Correct 203 ms 77936 KB Output is correct
5 Correct 8 ms 39260 KB Output is correct
6 Correct 282 ms 68740 KB Output is correct
7 Correct 79 ms 57936 KB Output is correct
8 Correct 62 ms 50300 KB Output is correct
9 Correct 155 ms 68868 KB Output is correct
10 Correct 298 ms 68940 KB Output is correct
11 Correct 124 ms 63488 KB Output is correct
12 Correct 7 ms 39260 KB Output is correct
13 Correct 7 ms 39428 KB Output is correct
14 Correct 7 ms 39256 KB Output is correct
15 Correct 7 ms 39512 KB Output is correct
16 Correct 7 ms 39260 KB Output is correct
17 Correct 7 ms 39444 KB Output is correct
18 Correct 8 ms 39260 KB Output is correct
19 Correct 7 ms 39260 KB Output is correct
20 Correct 8 ms 39260 KB Output is correct
21 Correct 7 ms 39384 KB Output is correct
22 Correct 7 ms 39260 KB Output is correct
23 Correct 7 ms 39260 KB Output is correct
24 Correct 8 ms 39516 KB Output is correct
25 Correct 7 ms 39260 KB Output is correct
26 Correct 7 ms 39452 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 41564 KB Output is correct
30 Correct 11 ms 41560 KB Output is correct
31 Correct 10 ms 41560 KB Output is correct
32 Correct 10 ms 41564 KB Output is correct
33 Correct 11 ms 41532 KB Output is correct
34 Correct 11 ms 41564 KB Output is correct
35 Correct 182 ms 65520 KB Output is correct
36 Correct 188 ms 76504 KB Output is correct
37 Correct 202 ms 65672 KB Output is correct
38 Correct 219 ms 81488 KB Output is correct
39 Correct 263 ms 66900 KB Output is correct
40 Correct 138 ms 66400 KB Output is correct
41 Correct 599 ms 69972 KB Output is correct
42 Correct 104 ms 62196 KB Output is correct
43 Correct 58 ms 48468 KB Output is correct
44 Correct 366 ms 67968 KB Output is correct
45 Correct 416 ms 70356 KB Output is correct
46 Correct 599 ms 64080 KB Output is correct
47 Correct 557 ms 64204 KB Output is correct
48 Correct 212 ms 68208 KB Output is correct
49 Correct 222 ms 84740 KB Output is correct
50 Correct 367 ms 82216 KB Output is correct
51 Correct 274 ms 72960 KB Output is correct
52 Correct 7 ms 39256 KB Output is correct
53 Correct 602 ms 73324 KB Output is correct
54 Correct 393 ms 71776 KB Output is correct
55 Correct 458 ms 73380 KB Output is correct
56 Correct 576 ms 67572 KB Output is correct
57 Correct 217 ms 78928 KB Output is correct
58 Correct 246 ms 75708 KB Output is correct
59 Correct 288 ms 74068 KB Output is correct
60 Correct 370 ms 83592 KB Output is correct
61 Correct 482 ms 80208 KB Output is correct
62 Correct 7 ms 39260 KB Output is correct
63 Correct 623 ms 74372 KB Output is correct
64 Correct 373 ms 69856 KB Output is correct
65 Correct 491 ms 73280 KB Output is correct
66 Correct 568 ms 67664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 236 ms 80272 KB Output is correct
2 Correct 290 ms 72020 KB Output is correct
3 Correct 153 ms 67836 KB Output is correct
4 Correct 203 ms 77936 KB Output is correct
5 Correct 8 ms 39260 KB Output is correct
6 Correct 282 ms 68740 KB Output is correct
7 Correct 79 ms 57936 KB Output is correct
8 Correct 62 ms 50300 KB Output is correct
9 Correct 155 ms 68868 KB Output is correct
10 Correct 298 ms 68940 KB Output is correct
11 Correct 124 ms 63488 KB Output is correct
12 Correct 7 ms 39260 KB Output is correct
13 Correct 7 ms 39428 KB Output is correct
14 Correct 7 ms 39256 KB Output is correct
15 Correct 7 ms 39512 KB Output is correct
16 Correct 7 ms 39260 KB Output is correct
17 Correct 7 ms 39444 KB Output is correct
18 Correct 8 ms 39260 KB Output is correct
19 Correct 7 ms 39260 KB Output is correct
20 Correct 8 ms 39260 KB Output is correct
21 Correct 7 ms 39384 KB Output is correct
22 Correct 7 ms 39260 KB Output is correct
23 Correct 7 ms 39260 KB Output is correct
24 Correct 8 ms 39516 KB Output is correct
25 Correct 7 ms 39260 KB Output is correct
26 Correct 7 ms 39452 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 41564 KB Output is correct
30 Correct 11 ms 41560 KB Output is correct
31 Correct 10 ms 41560 KB Output is correct
32 Correct 10 ms 41564 KB Output is correct
33 Correct 11 ms 41532 KB Output is correct
34 Correct 11 ms 41564 KB Output is correct
35 Correct 182 ms 65520 KB Output is correct
36 Correct 188 ms 76504 KB Output is correct
37 Correct 202 ms 65672 KB Output is correct
38 Correct 219 ms 81488 KB Output is correct
39 Correct 263 ms 66900 KB Output is correct
40 Correct 138 ms 66400 KB Output is correct
41 Correct 599 ms 69972 KB Output is correct
42 Correct 104 ms 62196 KB Output is correct
43 Correct 58 ms 48468 KB Output is correct
44 Correct 366 ms 67968 KB Output is correct
45 Correct 416 ms 70356 KB Output is correct
46 Correct 599 ms 64080 KB Output is correct
47 Correct 557 ms 64204 KB Output is correct
48 Correct 212 ms 68208 KB Output is correct
49 Correct 222 ms 84740 KB Output is correct
50 Correct 367 ms 82216 KB Output is correct
51 Correct 274 ms 72960 KB Output is correct
52 Correct 7 ms 39256 KB Output is correct
53 Correct 602 ms 73324 KB Output is correct
54 Correct 393 ms 71776 KB Output is correct
55 Correct 458 ms 73380 KB Output is correct
56 Correct 576 ms 67572 KB Output is correct
57 Correct 1080 ms 174380 KB Output is correct
58 Correct 1192 ms 251592 KB Output is correct
59 Correct 1976 ms 239696 KB Output is correct
60 Correct 1431 ms 196364 KB Output is correct
61 Correct 3948 ms 199264 KB Output is correct
62 Correct 2176 ms 183656 KB Output is correct
63 Correct 2610 ms 199712 KB Output is correct
64 Correct 3744 ms 166856 KB Output is correct
65 Correct 217 ms 78928 KB Output is correct
66 Correct 246 ms 75708 KB Output is correct
67 Correct 288 ms 74068 KB Output is correct
68 Correct 370 ms 83592 KB Output is correct
69 Correct 482 ms 80208 KB Output is correct
70 Correct 7 ms 39260 KB Output is correct
71 Correct 623 ms 74372 KB Output is correct
72 Correct 373 ms 69856 KB Output is correct
73 Correct 491 ms 73280 KB Output is correct
74 Correct 568 ms 67664 KB Output is correct
75 Correct 1157 ms 230304 KB Output is correct
76 Correct 1215 ms 214616 KB Output is correct
77 Correct 1466 ms 201552 KB Output is correct
78 Correct 2085 ms 248888 KB Output is correct
79 Correct 3902 ms 203312 KB Output is correct
80 Correct 2233 ms 188888 KB Output is correct
81 Correct 2768 ms 194916 KB Output is correct
82 Correct 3766 ms 170968 KB Output is correct
83 Correct 3672 ms 190816 KB Output is correct