답안 #878058

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878058 2023-11-24T04:02:14 Z vjudge1 Ants and Sugar (JOI22_sugar) C++17
100 / 100
1206 ms 210976 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF=1e18;
struct T{
    int mx[2][2];
    T(){memset(mx,0,sizeof(mx));}
}st[4000001];
int lazy[4000001],lazy2[4000001],cnt[4000001];
int q,l,t[500001],x[500001],a[500001],s;
vector <int> ve;
T f(T a, T b, int cnt){
    T c;
    for (int i=0;i<2;i++)
        for (int j=0;j<2;j++)
            c.mx[i][j]=max(a.mx[i][0]+b.mx[0][j],a.mx[i][1]+b.mx[1][j]-cnt);
    for (int i=0;i<2;i++){
        c.mx[i][0]=max(c.mx[i][0],a.mx[i][0]);
        c.mx[0][i]=max(c.mx[0][i],b.mx[0][i]);
    }
    return c;
}
void down(int node, int l, int r){
    if (l==r)
        return;
    for (int i=0;i<2;i++)
        for (int j=0;j<2;j++){
            st[node<<1].mx[i][j]+=lazy[node];
            st[node<<1|1].mx[i][j]+=lazy[node];
        }
    lazy[node<<1]+=lazy[node];
    lazy[node<<1|1]+=lazy[node];
    lazy[node]=0;
    cnt[node<<1]+=lazy2[node];
    cnt[node<<1|1]+=lazy2[node];
    lazy2[node<<1]+=lazy2[node];
    lazy2[node<<1|1]+=lazy2[node];
    lazy2[node]=0;
}
void update(int node, int l, int r, int u, int v, int val){
    if (l>v||r<u||l>r)
        return;
    if (l>=u&&r<=v){
        for (int i=0;i<2;i++)
            for (int j=0;j<2;j++)
                st[node].mx[i][j]+=val;
        lazy[node]+=val;
        cnt[node]+=val;
        lazy2[node]+=val;
        return;
    }
    down(node,l,r);
    int mid=(l+r)>>1;
    if (mid>=u&&mid<v)
        cnt[node]+=val;
    update(node<<1,l,mid,u,v,val);
    update(node<<1|1,mid+1,r,u,v,val);
    st[node]=f(st[node<<1],st[node<<1|1],cnt[node]);
}
int32_t main(){
    ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
    cin >> q >> l;
    for (int i=0;i<q;i++){
        cin >> t[i] >> x[i] >> a[i];
        if (t[i]==1)
            ve.push_back(x[i]);
        else{
            ve.push_back(x[i]-l);
            ve.push_back(x[i]+l);
        }
    }
    sort(ve.begin(),ve.end());
    ve.resize(unique(ve.begin(),ve.end())-ve.begin());
    for (int i=0;i<q;i++){
        if (t[i]==1){
            s+=a[i];
            int pos=lower_bound(ve.begin(),ve.end(),x[i])-ve.begin();
            update(1,0,ve.size()-1,pos,pos,a[i]);
        }
        else{
            int u=lower_bound(ve.begin(),ve.end(),x[i]-l)-ve.begin();
            int v=lower_bound(ve.begin(),ve.end(),x[i]+l)-ve.begin();
            update(1,0,ve.size()-1,u,v,-a[i]);
        }
        cout << s-max(st[1].mx[0][0],0LL) << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 132700 KB Output is correct
2 Correct 17 ms 132700 KB Output is correct
3 Correct 16 ms 132708 KB Output is correct
4 Correct 18 ms 132508 KB Output is correct
5 Correct 17 ms 136796 KB Output is correct
6 Correct 18 ms 132716 KB Output is correct
7 Correct 18 ms 132696 KB Output is correct
8 Correct 18 ms 132784 KB Output is correct
9 Correct 17 ms 132696 KB Output is correct
10 Correct 19 ms 133168 KB Output is correct
11 Correct 19 ms 133212 KB Output is correct
12 Correct 20 ms 132956 KB Output is correct
13 Correct 22 ms 133212 KB Output is correct
14 Correct 22 ms 132948 KB Output is correct
15 Correct 20 ms 133208 KB Output is correct
16 Correct 19 ms 132956 KB Output is correct
17 Correct 19 ms 132800 KB Output is correct
18 Correct 19 ms 132948 KB Output is correct
19 Correct 20 ms 133212 KB Output is correct
20 Correct 19 ms 132956 KB Output is correct
21 Correct 20 ms 133212 KB Output is correct
22 Correct 19 ms 132956 KB Output is correct
23 Correct 20 ms 133052 KB Output is correct
24 Correct 18 ms 132948 KB Output is correct
25 Correct 19 ms 133212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 132696 KB Output is correct
2 Correct 18 ms 132784 KB Output is correct
3 Correct 16 ms 136792 KB Output is correct
4 Correct 484 ms 170172 KB Output is correct
5 Correct 224 ms 157348 KB Output is correct
6 Correct 569 ms 171956 KB Output is correct
7 Correct 222 ms 157988 KB Output is correct
8 Correct 712 ms 175028 KB Output is correct
9 Correct 474 ms 175796 KB Output is correct
10 Correct 737 ms 175212 KB Output is correct
11 Correct 458 ms 174268 KB Output is correct
12 Correct 228 ms 156356 KB Output is correct
13 Correct 286 ms 164576 KB Output is correct
14 Correct 451 ms 170940 KB Output is correct
15 Correct 451 ms 169140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 132696 KB Output is correct
2 Correct 217 ms 154772 KB Output is correct
3 Correct 285 ms 162760 KB Output is correct
4 Correct 484 ms 170300 KB Output is correct
5 Correct 452 ms 169748 KB Output is correct
6 Correct 668 ms 178848 KB Output is correct
7 Correct 49 ms 141308 KB Output is correct
8 Correct 297 ms 160964 KB Output is correct
9 Correct 483 ms 175308 KB Output is correct
10 Correct 948 ms 207104 KB Output is correct
11 Correct 949 ms 207716 KB Output is correct
12 Correct 958 ms 208016 KB Output is correct
13 Correct 927 ms 207080 KB Output is correct
14 Correct 987 ms 208008 KB Output is correct
15 Correct 1020 ms 207484 KB Output is correct
16 Correct 988 ms 206368 KB Output is correct
17 Correct 1012 ms 208052 KB Output is correct
18 Correct 1093 ms 206400 KB Output is correct
19 Correct 1098 ms 207116 KB Output is correct
20 Correct 1077 ms 206940 KB Output is correct
21 Correct 1154 ms 208172 KB Output is correct
22 Correct 1206 ms 207224 KB Output is correct
23 Correct 1133 ms 206180 KB Output is correct
24 Correct 1054 ms 206756 KB Output is correct
25 Correct 1091 ms 206456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 132700 KB Output is correct
2 Correct 17 ms 132700 KB Output is correct
3 Correct 16 ms 132708 KB Output is correct
4 Correct 18 ms 132508 KB Output is correct
5 Correct 17 ms 136796 KB Output is correct
6 Correct 18 ms 132716 KB Output is correct
7 Correct 18 ms 132696 KB Output is correct
8 Correct 18 ms 132784 KB Output is correct
9 Correct 17 ms 132696 KB Output is correct
10 Correct 19 ms 133168 KB Output is correct
11 Correct 19 ms 133212 KB Output is correct
12 Correct 20 ms 132956 KB Output is correct
13 Correct 22 ms 133212 KB Output is correct
14 Correct 22 ms 132948 KB Output is correct
15 Correct 20 ms 133208 KB Output is correct
16 Correct 19 ms 132956 KB Output is correct
17 Correct 19 ms 132800 KB Output is correct
18 Correct 19 ms 132948 KB Output is correct
19 Correct 20 ms 133212 KB Output is correct
20 Correct 19 ms 132956 KB Output is correct
21 Correct 20 ms 133212 KB Output is correct
22 Correct 19 ms 132956 KB Output is correct
23 Correct 20 ms 133052 KB Output is correct
24 Correct 18 ms 132948 KB Output is correct
25 Correct 19 ms 133212 KB Output is correct
26 Correct 17 ms 132696 KB Output is correct
27 Correct 18 ms 132784 KB Output is correct
28 Correct 16 ms 136792 KB Output is correct
29 Correct 484 ms 170172 KB Output is correct
30 Correct 224 ms 157348 KB Output is correct
31 Correct 569 ms 171956 KB Output is correct
32 Correct 222 ms 157988 KB Output is correct
33 Correct 712 ms 175028 KB Output is correct
34 Correct 474 ms 175796 KB Output is correct
35 Correct 737 ms 175212 KB Output is correct
36 Correct 458 ms 174268 KB Output is correct
37 Correct 228 ms 156356 KB Output is correct
38 Correct 286 ms 164576 KB Output is correct
39 Correct 451 ms 170940 KB Output is correct
40 Correct 451 ms 169140 KB Output is correct
41 Correct 16 ms 132696 KB Output is correct
42 Correct 217 ms 154772 KB Output is correct
43 Correct 285 ms 162760 KB Output is correct
44 Correct 484 ms 170300 KB Output is correct
45 Correct 452 ms 169748 KB Output is correct
46 Correct 668 ms 178848 KB Output is correct
47 Correct 49 ms 141308 KB Output is correct
48 Correct 297 ms 160964 KB Output is correct
49 Correct 483 ms 175308 KB Output is correct
50 Correct 948 ms 207104 KB Output is correct
51 Correct 949 ms 207716 KB Output is correct
52 Correct 958 ms 208016 KB Output is correct
53 Correct 927 ms 207080 KB Output is correct
54 Correct 987 ms 208008 KB Output is correct
55 Correct 1020 ms 207484 KB Output is correct
56 Correct 988 ms 206368 KB Output is correct
57 Correct 1012 ms 208052 KB Output is correct
58 Correct 1093 ms 206400 KB Output is correct
59 Correct 1098 ms 207116 KB Output is correct
60 Correct 1077 ms 206940 KB Output is correct
61 Correct 1154 ms 208172 KB Output is correct
62 Correct 1206 ms 207224 KB Output is correct
63 Correct 1133 ms 206180 KB Output is correct
64 Correct 1054 ms 206756 KB Output is correct
65 Correct 1091 ms 206456 KB Output is correct
66 Correct 443 ms 176504 KB Output is correct
67 Correct 542 ms 178088 KB Output is correct
68 Correct 652 ms 181168 KB Output is correct
69 Correct 590 ms 179124 KB Output is correct
70 Correct 953 ms 210640 KB Output is correct
71 Correct 996 ms 209848 KB Output is correct
72 Correct 928 ms 210804 KB Output is correct
73 Correct 1024 ms 209884 KB Output is correct
74 Correct 1082 ms 205056 KB Output is correct
75 Correct 1086 ms 210396 KB Output is correct
76 Correct 813 ms 181900 KB Output is correct
77 Correct 743 ms 176236 KB Output is correct
78 Correct 772 ms 176308 KB Output is correct
79 Correct 1000 ms 209248 KB Output is correct
80 Correct 781 ms 176676 KB Output is correct
81 Correct 1020 ms 210976 KB Output is correct
82 Correct 780 ms 176176 KB Output is correct
83 Correct 1119 ms 204064 KB Output is correct
84 Correct 794 ms 170504 KB Output is correct
85 Correct 1147 ms 204076 KB Output is correct
86 Correct 800 ms 170596 KB Output is correct
87 Correct 1151 ms 205752 KB Output is correct
88 Correct 759 ms 170460 KB Output is correct
89 Correct 988 ms 204324 KB Output is correct