답안 #862087

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
862087 2023-10-17T14:00:26 Z guagua0407 Two Dishes (JOI19_dishes) C++17
100 / 100
1815 ms 286420 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

const int mxn=1e6+5;
ll a[mxn],S[mxn],Q[mxn];
ll b[mxn],T[mxn],P[mxn];
int pa[mxn],pb[mxn];
ll g[mxn],V[mxn];
vector<int> qa[mxn],qb[mxn];
int n,m;

int main() {_
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>S[i]>>P[i];
        a[i]+=a[i-1];
    }
    for(int i=1;i<=m;i++){
        cin>>b[i]>>T[i]>>Q[i];
        b[i]+=b[i-1];
    }
    for(int i=1;i<=n;i++){
        int pos=upper_bound(b,b+m+1,S[i]-a[i])-b-1;
        pa[i]=pos;
        if(pos>=0) qa[pos].push_back(i);
    }
    for(int i=1;i<=m;i++){
        int pos=upper_bound(a,a+n+1,T[i]-b[i])-a-1;
        pb[i]=pos;
        if(pos>=0) qb[pos].push_back(i);
    }
    for(int i=1;i<=m;i++){
        if(pb[i]>=0) g[i]=V[i]=Q[i];
    }
    /*for(int i=1;i<=n;i++){
        cout<<pa[i]<<' ';
    }cout<<'\n';
    for(int i=1;i<=m;i++){
        cout<<pb[i]<<' ';
    }cout<<'\n';*/
    set<int> S;
    S.insert(m+1);
    V[m+1]=-1e18;
    for(int i=1;i<=n;i++){
        vector<int> vec;
        if(pa[i]>=0){
            g[0]+=P[i];
            g[pa[i]+1]-=P[i];
            if(g[pa[i]+1]>V[pa[i]+1] or g[pa[i]+1]<V[pa[i]+1]){
                if(pa[i]+1<=m) S.insert(pa[i]+1);
            }
            if(g[pa[i]+1]<V[pa[i]+1]){
                if(pa[i]+1<=m) vec.push_back(pa[i]+1);
            }
        }
        for(auto v:qb[i-1]){
            if(g[v]>0 or g[v]<0){
                S.insert(v);
            }
            if(g[v]<0){
                vec.push_back(v);
            }
            V[v]=0;
        }
        sort(all(vec));
        /*for(auto v:vec){
            cout<<v<<' ';
        }cout<<'\n';
        for(auto v:S){
            cout<<v<<' ';
        }cout<<'\n';*/
        for(auto v:vec){
            auto it=S.lower_bound(v);
            if((*it)!=v) continue;
            if(g[*it]==V[*it]) S.erase(it);
            if(g[*it]>=V[*it]) continue;
            while(true){
                int cur=*it;
                ll dif=V[cur]-g[cur];
                int nxt=*next(it);
                g[cur]=V[cur];
                g[nxt]-=dif;
                if(g[nxt]>=V[nxt]){
                    S.erase(it);
                    if(g[nxt]==V[nxt]) S.erase(S.find(nxt));
                    break;
                }
                else{
                    it=S.erase(it);
                }
            }
        }
        /*for(auto v:S){
            cout<<v<<' ';
        }cout<<'\n';
        ll sum=0;
        for(int i=0;i<=m;i++){
            if(i!=0) cout<<g[i]+sum<<' ';
            sum+=g[i];
        }cout<<'\n';*/
    }
    for(int i=1;i<=m;i++){
        g[i]+=g[i-1];
    }
    cout<<g[m]<<'\n';
    return 0;
}
//maybe its multiset not set

Compilation message

dishes.cpp: In function 'void setIO(std::string)':
dishes.cpp:12:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 109884 KB Output is correct
2 Correct 165 ms 99772 KB Output is correct
3 Correct 127 ms 95724 KB Output is correct
4 Correct 176 ms 105296 KB Output is correct
5 Correct 12 ms 66136 KB Output is correct
6 Correct 159 ms 98364 KB Output is correct
7 Correct 69 ms 82384 KB Output is correct
8 Correct 72 ms 80336 KB Output is correct
9 Correct 130 ms 96584 KB Output is correct
10 Correct 151 ms 100584 KB Output is correct
11 Correct 93 ms 90092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 66292 KB Output is correct
2 Correct 12 ms 64092 KB Output is correct
3 Correct 12 ms 66140 KB Output is correct
4 Correct 12 ms 66208 KB Output is correct
5 Correct 12 ms 66192 KB Output is correct
6 Correct 12 ms 66140 KB Output is correct
7 Correct 12 ms 66392 KB Output is correct
8 Correct 12 ms 66140 KB Output is correct
9 Correct 12 ms 66296 KB Output is correct
10 Correct 12 ms 66136 KB Output is correct
11 Correct 12 ms 66140 KB Output is correct
12 Correct 12 ms 66140 KB Output is correct
13 Correct 12 ms 66140 KB Output is correct
14 Correct 14 ms 66300 KB Output is correct
15 Correct 12 ms 66140 KB Output is correct
16 Correct 13 ms 66284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 66292 KB Output is correct
2 Correct 12 ms 64092 KB Output is correct
3 Correct 12 ms 66140 KB Output is correct
4 Correct 12 ms 66208 KB Output is correct
5 Correct 12 ms 66192 KB Output is correct
6 Correct 12 ms 66140 KB Output is correct
7 Correct 12 ms 66392 KB Output is correct
8 Correct 12 ms 66140 KB Output is correct
9 Correct 12 ms 66296 KB Output is correct
10 Correct 12 ms 66136 KB Output is correct
11 Correct 12 ms 66140 KB Output is correct
12 Correct 12 ms 66140 KB Output is correct
13 Correct 12 ms 66140 KB Output is correct
14 Correct 14 ms 66300 KB Output is correct
15 Correct 12 ms 66140 KB Output is correct
16 Correct 13 ms 66284 KB Output is correct
17 Correct 13 ms 66372 KB Output is correct
18 Correct 13 ms 66276 KB Output is correct
19 Correct 13 ms 66272 KB Output is correct
20 Correct 14 ms 66396 KB Output is correct
21 Correct 14 ms 66392 KB Output is correct
22 Correct 13 ms 66392 KB Output is correct
23 Correct 14 ms 66308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 66292 KB Output is correct
2 Correct 12 ms 64092 KB Output is correct
3 Correct 12 ms 66140 KB Output is correct
4 Correct 12 ms 66208 KB Output is correct
5 Correct 12 ms 66192 KB Output is correct
6 Correct 12 ms 66140 KB Output is correct
7 Correct 12 ms 66392 KB Output is correct
8 Correct 12 ms 66140 KB Output is correct
9 Correct 12 ms 66296 KB Output is correct
10 Correct 12 ms 66136 KB Output is correct
11 Correct 12 ms 66140 KB Output is correct
12 Correct 12 ms 66140 KB Output is correct
13 Correct 12 ms 66140 KB Output is correct
14 Correct 14 ms 66300 KB Output is correct
15 Correct 12 ms 66140 KB Output is correct
16 Correct 13 ms 66284 KB Output is correct
17 Correct 13 ms 66372 KB Output is correct
18 Correct 13 ms 66276 KB Output is correct
19 Correct 13 ms 66272 KB Output is correct
20 Correct 14 ms 66396 KB Output is correct
21 Correct 14 ms 66392 KB Output is correct
22 Correct 13 ms 66392 KB Output is correct
23 Correct 14 ms 66308 KB Output is correct
24 Correct 122 ms 92880 KB Output is correct
25 Correct 141 ms 101604 KB Output is correct
26 Correct 135 ms 97916 KB Output is correct
27 Correct 156 ms 107244 KB Output is correct
28 Correct 149 ms 94920 KB Output is correct
29 Correct 109 ms 93520 KB Output is correct
30 Correct 251 ms 99408 KB Output is correct
31 Correct 72 ms 85012 KB Output is correct
32 Correct 64 ms 78524 KB Output is correct
33 Correct 180 ms 93776 KB Output is correct
34 Correct 216 ms 100280 KB Output is correct
35 Correct 210 ms 92796 KB Output is correct
36 Correct 221 ms 93108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 66292 KB Output is correct
2 Correct 12 ms 64092 KB Output is correct
3 Correct 12 ms 66140 KB Output is correct
4 Correct 12 ms 66208 KB Output is correct
5 Correct 12 ms 66192 KB Output is correct
6 Correct 12 ms 66140 KB Output is correct
7 Correct 12 ms 66392 KB Output is correct
8 Correct 12 ms 66140 KB Output is correct
9 Correct 12 ms 66296 KB Output is correct
10 Correct 12 ms 66136 KB Output is correct
11 Correct 12 ms 66140 KB Output is correct
12 Correct 12 ms 66140 KB Output is correct
13 Correct 12 ms 66140 KB Output is correct
14 Correct 14 ms 66300 KB Output is correct
15 Correct 12 ms 66140 KB Output is correct
16 Correct 13 ms 66284 KB Output is correct
17 Correct 13 ms 66372 KB Output is correct
18 Correct 13 ms 66276 KB Output is correct
19 Correct 13 ms 66272 KB Output is correct
20 Correct 14 ms 66396 KB Output is correct
21 Correct 14 ms 66392 KB Output is correct
22 Correct 13 ms 66392 KB Output is correct
23 Correct 14 ms 66308 KB Output is correct
24 Correct 122 ms 92880 KB Output is correct
25 Correct 141 ms 101604 KB Output is correct
26 Correct 135 ms 97916 KB Output is correct
27 Correct 156 ms 107244 KB Output is correct
28 Correct 149 ms 94920 KB Output is correct
29 Correct 109 ms 93520 KB Output is correct
30 Correct 251 ms 99408 KB Output is correct
31 Correct 72 ms 85012 KB Output is correct
32 Correct 64 ms 78524 KB Output is correct
33 Correct 180 ms 93776 KB Output is correct
34 Correct 216 ms 100280 KB Output is correct
35 Correct 210 ms 92796 KB Output is correct
36 Correct 221 ms 93108 KB Output is correct
37 Correct 178 ms 101080 KB Output is correct
38 Correct 167 ms 110320 KB Output is correct
39 Correct 211 ms 113636 KB Output is correct
40 Correct 179 ms 104016 KB Output is correct
41 Correct 12 ms 66140 KB Output is correct
42 Correct 256 ms 102316 KB Output is correct
43 Correct 195 ms 96852 KB Output is correct
44 Correct 229 ms 103220 KB Output is correct
45 Correct 249 ms 96336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 66292 KB Output is correct
2 Correct 12 ms 64092 KB Output is correct
3 Correct 12 ms 66140 KB Output is correct
4 Correct 12 ms 66208 KB Output is correct
5 Correct 12 ms 66192 KB Output is correct
6 Correct 12 ms 66140 KB Output is correct
7 Correct 12 ms 66392 KB Output is correct
8 Correct 12 ms 66140 KB Output is correct
9 Correct 12 ms 66296 KB Output is correct
10 Correct 12 ms 66136 KB Output is correct
11 Correct 12 ms 66140 KB Output is correct
12 Correct 12 ms 66140 KB Output is correct
13 Correct 12 ms 66140 KB Output is correct
14 Correct 14 ms 66300 KB Output is correct
15 Correct 12 ms 66140 KB Output is correct
16 Correct 13 ms 66284 KB Output is correct
17 Correct 13 ms 66372 KB Output is correct
18 Correct 13 ms 66276 KB Output is correct
19 Correct 13 ms 66272 KB Output is correct
20 Correct 14 ms 66396 KB Output is correct
21 Correct 14 ms 66392 KB Output is correct
22 Correct 13 ms 66392 KB Output is correct
23 Correct 14 ms 66308 KB Output is correct
24 Correct 122 ms 92880 KB Output is correct
25 Correct 141 ms 101604 KB Output is correct
26 Correct 135 ms 97916 KB Output is correct
27 Correct 156 ms 107244 KB Output is correct
28 Correct 149 ms 94920 KB Output is correct
29 Correct 109 ms 93520 KB Output is correct
30 Correct 251 ms 99408 KB Output is correct
31 Correct 72 ms 85012 KB Output is correct
32 Correct 64 ms 78524 KB Output is correct
33 Correct 180 ms 93776 KB Output is correct
34 Correct 216 ms 100280 KB Output is correct
35 Correct 210 ms 92796 KB Output is correct
36 Correct 221 ms 93108 KB Output is correct
37 Correct 178 ms 101080 KB Output is correct
38 Correct 167 ms 110320 KB Output is correct
39 Correct 211 ms 113636 KB Output is correct
40 Correct 179 ms 104016 KB Output is correct
41 Correct 12 ms 66140 KB Output is correct
42 Correct 256 ms 102316 KB Output is correct
43 Correct 195 ms 96852 KB Output is correct
44 Correct 229 ms 103220 KB Output is correct
45 Correct 249 ms 96336 KB Output is correct
46 Correct 714 ms 221148 KB Output is correct
47 Correct 950 ms 268232 KB Output is correct
48 Correct 1183 ms 283788 KB Output is correct
49 Correct 743 ms 237052 KB Output is correct
50 Correct 1815 ms 227652 KB Output is correct
51 Correct 1160 ms 207976 KB Output is correct
52 Correct 1470 ms 227656 KB Output is correct
53 Correct 1604 ms 195420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 109884 KB Output is correct
2 Correct 165 ms 99772 KB Output is correct
3 Correct 127 ms 95724 KB Output is correct
4 Correct 176 ms 105296 KB Output is correct
5 Correct 12 ms 66136 KB Output is correct
6 Correct 159 ms 98364 KB Output is correct
7 Correct 69 ms 82384 KB Output is correct
8 Correct 72 ms 80336 KB Output is correct
9 Correct 130 ms 96584 KB Output is correct
10 Correct 151 ms 100584 KB Output is correct
11 Correct 93 ms 90092 KB Output is correct
12 Correct 12 ms 66292 KB Output is correct
13 Correct 12 ms 64092 KB Output is correct
14 Correct 12 ms 66140 KB Output is correct
15 Correct 12 ms 66208 KB Output is correct
16 Correct 12 ms 66192 KB Output is correct
17 Correct 12 ms 66140 KB Output is correct
18 Correct 12 ms 66392 KB Output is correct
19 Correct 12 ms 66140 KB Output is correct
20 Correct 12 ms 66296 KB Output is correct
21 Correct 12 ms 66136 KB Output is correct
22 Correct 12 ms 66140 KB Output is correct
23 Correct 12 ms 66140 KB Output is correct
24 Correct 12 ms 66140 KB Output is correct
25 Correct 14 ms 66300 KB Output is correct
26 Correct 12 ms 66140 KB Output is correct
27 Correct 13 ms 66284 KB Output is correct
28 Correct 13 ms 66372 KB Output is correct
29 Correct 13 ms 66276 KB Output is correct
30 Correct 13 ms 66272 KB Output is correct
31 Correct 14 ms 66396 KB Output is correct
32 Correct 14 ms 66392 KB Output is correct
33 Correct 13 ms 66392 KB Output is correct
34 Correct 14 ms 66308 KB Output is correct
35 Correct 122 ms 92880 KB Output is correct
36 Correct 141 ms 101604 KB Output is correct
37 Correct 135 ms 97916 KB Output is correct
38 Correct 156 ms 107244 KB Output is correct
39 Correct 149 ms 94920 KB Output is correct
40 Correct 109 ms 93520 KB Output is correct
41 Correct 251 ms 99408 KB Output is correct
42 Correct 72 ms 85012 KB Output is correct
43 Correct 64 ms 78524 KB Output is correct
44 Correct 180 ms 93776 KB Output is correct
45 Correct 216 ms 100280 KB Output is correct
46 Correct 210 ms 92796 KB Output is correct
47 Correct 221 ms 93108 KB Output is correct
48 Correct 178 ms 101080 KB Output is correct
49 Correct 167 ms 110320 KB Output is correct
50 Correct 211 ms 113636 KB Output is correct
51 Correct 179 ms 104016 KB Output is correct
52 Correct 12 ms 66140 KB Output is correct
53 Correct 256 ms 102316 KB Output is correct
54 Correct 195 ms 96852 KB Output is correct
55 Correct 229 ms 103220 KB Output is correct
56 Correct 249 ms 96336 KB Output is correct
57 Correct 170 ms 110652 KB Output is correct
58 Correct 158 ms 101312 KB Output is correct
59 Correct 158 ms 104932 KB Output is correct
60 Correct 194 ms 114360 KB Output is correct
61 Correct 183 ms 99160 KB Output is correct
62 Correct 12 ms 66136 KB Output is correct
63 Correct 263 ms 102364 KB Output is correct
64 Correct 198 ms 99128 KB Output is correct
65 Correct 227 ms 97996 KB Output is correct
66 Correct 227 ms 95832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 109884 KB Output is correct
2 Correct 165 ms 99772 KB Output is correct
3 Correct 127 ms 95724 KB Output is correct
4 Correct 176 ms 105296 KB Output is correct
5 Correct 12 ms 66136 KB Output is correct
6 Correct 159 ms 98364 KB Output is correct
7 Correct 69 ms 82384 KB Output is correct
8 Correct 72 ms 80336 KB Output is correct
9 Correct 130 ms 96584 KB Output is correct
10 Correct 151 ms 100584 KB Output is correct
11 Correct 93 ms 90092 KB Output is correct
12 Correct 12 ms 66292 KB Output is correct
13 Correct 12 ms 64092 KB Output is correct
14 Correct 12 ms 66140 KB Output is correct
15 Correct 12 ms 66208 KB Output is correct
16 Correct 12 ms 66192 KB Output is correct
17 Correct 12 ms 66140 KB Output is correct
18 Correct 12 ms 66392 KB Output is correct
19 Correct 12 ms 66140 KB Output is correct
20 Correct 12 ms 66296 KB Output is correct
21 Correct 12 ms 66136 KB Output is correct
22 Correct 12 ms 66140 KB Output is correct
23 Correct 12 ms 66140 KB Output is correct
24 Correct 12 ms 66140 KB Output is correct
25 Correct 14 ms 66300 KB Output is correct
26 Correct 12 ms 66140 KB Output is correct
27 Correct 13 ms 66284 KB Output is correct
28 Correct 13 ms 66372 KB Output is correct
29 Correct 13 ms 66276 KB Output is correct
30 Correct 13 ms 66272 KB Output is correct
31 Correct 14 ms 66396 KB Output is correct
32 Correct 14 ms 66392 KB Output is correct
33 Correct 13 ms 66392 KB Output is correct
34 Correct 14 ms 66308 KB Output is correct
35 Correct 122 ms 92880 KB Output is correct
36 Correct 141 ms 101604 KB Output is correct
37 Correct 135 ms 97916 KB Output is correct
38 Correct 156 ms 107244 KB Output is correct
39 Correct 149 ms 94920 KB Output is correct
40 Correct 109 ms 93520 KB Output is correct
41 Correct 251 ms 99408 KB Output is correct
42 Correct 72 ms 85012 KB Output is correct
43 Correct 64 ms 78524 KB Output is correct
44 Correct 180 ms 93776 KB Output is correct
45 Correct 216 ms 100280 KB Output is correct
46 Correct 210 ms 92796 KB Output is correct
47 Correct 221 ms 93108 KB Output is correct
48 Correct 178 ms 101080 KB Output is correct
49 Correct 167 ms 110320 KB Output is correct
50 Correct 211 ms 113636 KB Output is correct
51 Correct 179 ms 104016 KB Output is correct
52 Correct 12 ms 66140 KB Output is correct
53 Correct 256 ms 102316 KB Output is correct
54 Correct 195 ms 96852 KB Output is correct
55 Correct 229 ms 103220 KB Output is correct
56 Correct 249 ms 96336 KB Output is correct
57 Correct 714 ms 221148 KB Output is correct
58 Correct 950 ms 268232 KB Output is correct
59 Correct 1183 ms 283788 KB Output is correct
60 Correct 743 ms 237052 KB Output is correct
61 Correct 1815 ms 227652 KB Output is correct
62 Correct 1160 ms 207976 KB Output is correct
63 Correct 1470 ms 227656 KB Output is correct
64 Correct 1604 ms 195420 KB Output is correct
65 Correct 170 ms 110652 KB Output is correct
66 Correct 158 ms 101312 KB Output is correct
67 Correct 158 ms 104932 KB Output is correct
68 Correct 194 ms 114360 KB Output is correct
69 Correct 183 ms 99160 KB Output is correct
70 Correct 12 ms 66136 KB Output is correct
71 Correct 263 ms 102364 KB Output is correct
72 Correct 198 ms 99128 KB Output is correct
73 Correct 227 ms 97996 KB Output is correct
74 Correct 227 ms 95832 KB Output is correct
75 Correct 895 ms 269876 KB Output is correct
76 Correct 710 ms 222608 KB Output is correct
77 Correct 787 ms 239364 KB Output is correct
78 Correct 1037 ms 286420 KB Output is correct
79 Correct 1771 ms 227828 KB Output is correct
80 Correct 1123 ms 208720 KB Output is correct
81 Correct 1293 ms 213908 KB Output is correct
82 Correct 1589 ms 195592 KB Output is correct
83 Correct 1658 ms 214604 KB Output is correct