답안 #878062

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878062 2023-11-24T04:05:21 Z abcvuitunggio Ants and Sugar (JOI22_sugar) C++17
100 / 100
1006 ms 147256 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
int st[4000001][2][2],lazy[4000001],lazy2[4000001],cnt[4000001];
int q,l,t[500001],x[500001],a[500001],s;
vector <int> ve;
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][i][j]+=lazy[node];
            st[node<<1|1][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][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);
    for (int i=0;i<2;i++)
        for (int j=0;j<2;j++)
            st[node][i][j]=max(st[node<<1][i][0]+st[node<<1|1][0][j],st[node<<1][i][1]+st[node<<1|1][1][j]-cnt[node]);
    for (int i=0;i<2;i++){
        st[node][i][0]=max(st[node][i][0],st[node<<1][i][0]);
        st[node][0][i]=max(st[node][0][i],st[node<<1|1][0][i]);
    }
}
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][0][0],0LL) << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8672 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 12636 KB Output is correct
6 Correct 3 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 3 ms 9052 KB Output is correct
11 Correct 3 ms 9052 KB Output is correct
12 Correct 4 ms 9052 KB Output is correct
13 Correct 4 ms 9052 KB Output is correct
14 Correct 4 ms 9052 KB Output is correct
15 Correct 4 ms 9052 KB Output is correct
16 Correct 3 ms 8796 KB Output is correct
17 Correct 3 ms 8796 KB Output is correct
18 Correct 3 ms 8796 KB Output is correct
19 Correct 4 ms 9052 KB Output is correct
20 Correct 3 ms 8796 KB Output is correct
21 Correct 3 ms 9052 KB Output is correct
22 Correct 3 ms 8796 KB Output is correct
23 Correct 4 ms 9052 KB Output is correct
24 Correct 3 ms 8796 KB Output is correct
25 Correct 4 ms 9052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 2 ms 12636 KB Output is correct
4 Correct 412 ms 55972 KB Output is correct
5 Correct 172 ms 38272 KB Output is correct
6 Correct 502 ms 57928 KB Output is correct
7 Correct 173 ms 38076 KB Output is correct
8 Correct 600 ms 60552 KB Output is correct
9 Correct 381 ms 60928 KB Output is correct
10 Correct 603 ms 59812 KB Output is correct
11 Correct 372 ms 59692 KB Output is correct
12 Correct 165 ms 35892 KB Output is correct
13 Correct 226 ms 51876 KB Output is correct
14 Correct 363 ms 56736 KB Output is correct
15 Correct 372 ms 56504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 169 ms 37168 KB Output is correct
3 Correct 224 ms 51904 KB Output is correct
4 Correct 369 ms 56504 KB Output is correct
5 Correct 369 ms 57268 KB Output is correct
6 Correct 550 ms 82464 KB Output is correct
7 Correct 30 ms 20952 KB Output is correct
8 Correct 260 ms 50408 KB Output is correct
9 Correct 399 ms 80524 KB Output is correct
10 Correct 826 ms 143544 KB Output is correct
11 Correct 816 ms 143120 KB Output is correct
12 Correct 816 ms 143248 KB Output is correct
13 Correct 807 ms 143924 KB Output is correct
14 Correct 808 ms 143288 KB Output is correct
15 Correct 785 ms 143288 KB Output is correct
16 Correct 803 ms 142768 KB Output is correct
17 Correct 908 ms 143864 KB Output is correct
18 Correct 976 ms 142580 KB Output is correct
19 Correct 961 ms 143240 KB Output is correct
20 Correct 945 ms 142840 KB Output is correct
21 Correct 988 ms 143444 KB Output is correct
22 Correct 987 ms 142576 KB Output is correct
23 Correct 1000 ms 143852 KB Output is correct
24 Correct 956 ms 142172 KB Output is correct
25 Correct 987 ms 143796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8672 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 12636 KB Output is correct
6 Correct 3 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 3 ms 9052 KB Output is correct
11 Correct 3 ms 9052 KB Output is correct
12 Correct 4 ms 9052 KB Output is correct
13 Correct 4 ms 9052 KB Output is correct
14 Correct 4 ms 9052 KB Output is correct
15 Correct 4 ms 9052 KB Output is correct
16 Correct 3 ms 8796 KB Output is correct
17 Correct 3 ms 8796 KB Output is correct
18 Correct 3 ms 8796 KB Output is correct
19 Correct 4 ms 9052 KB Output is correct
20 Correct 3 ms 8796 KB Output is correct
21 Correct 3 ms 9052 KB Output is correct
22 Correct 3 ms 8796 KB Output is correct
23 Correct 4 ms 9052 KB Output is correct
24 Correct 3 ms 8796 KB Output is correct
25 Correct 4 ms 9052 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 2 ms 12636 KB Output is correct
29 Correct 412 ms 55972 KB Output is correct
30 Correct 172 ms 38272 KB Output is correct
31 Correct 502 ms 57928 KB Output is correct
32 Correct 173 ms 38076 KB Output is correct
33 Correct 600 ms 60552 KB Output is correct
34 Correct 381 ms 60928 KB Output is correct
35 Correct 603 ms 59812 KB Output is correct
36 Correct 372 ms 59692 KB Output is correct
37 Correct 165 ms 35892 KB Output is correct
38 Correct 226 ms 51876 KB Output is correct
39 Correct 363 ms 56736 KB Output is correct
40 Correct 372 ms 56504 KB Output is correct
41 Correct 1 ms 8536 KB Output is correct
42 Correct 169 ms 37168 KB Output is correct
43 Correct 224 ms 51904 KB Output is correct
44 Correct 369 ms 56504 KB Output is correct
45 Correct 369 ms 57268 KB Output is correct
46 Correct 550 ms 82464 KB Output is correct
47 Correct 30 ms 20952 KB Output is correct
48 Correct 260 ms 50408 KB Output is correct
49 Correct 399 ms 80524 KB Output is correct
50 Correct 826 ms 143544 KB Output is correct
51 Correct 816 ms 143120 KB Output is correct
52 Correct 816 ms 143248 KB Output is correct
53 Correct 807 ms 143924 KB Output is correct
54 Correct 808 ms 143288 KB Output is correct
55 Correct 785 ms 143288 KB Output is correct
56 Correct 803 ms 142768 KB Output is correct
57 Correct 908 ms 143864 KB Output is correct
58 Correct 976 ms 142580 KB Output is correct
59 Correct 961 ms 143240 KB Output is correct
60 Correct 945 ms 142840 KB Output is correct
61 Correct 988 ms 143444 KB Output is correct
62 Correct 987 ms 142576 KB Output is correct
63 Correct 1000 ms 143852 KB Output is correct
64 Correct 956 ms 142172 KB Output is correct
65 Correct 987 ms 143796 KB Output is correct
66 Correct 373 ms 81860 KB Output is correct
67 Correct 460 ms 83868 KB Output is correct
68 Correct 563 ms 86672 KB Output is correct
69 Correct 495 ms 86148 KB Output is correct
70 Correct 801 ms 145296 KB Output is correct
71 Correct 828 ms 146360 KB Output is correct
72 Correct 856 ms 146820 KB Output is correct
73 Correct 861 ms 147256 KB Output is correct
74 Correct 975 ms 141008 KB Output is correct
75 Correct 934 ms 146412 KB Output is correct
76 Correct 688 ms 85008 KB Output is correct
77 Correct 691 ms 79476 KB Output is correct
78 Correct 664 ms 79548 KB Output is correct
79 Correct 853 ms 146720 KB Output is correct
80 Correct 677 ms 79660 KB Output is correct
81 Correct 835 ms 146156 KB Output is correct
82 Correct 679 ms 79420 KB Output is correct
83 Correct 989 ms 145392 KB Output is correct
84 Correct 670 ms 79812 KB Output is correct
85 Correct 1006 ms 146704 KB Output is correct
86 Correct 683 ms 79624 KB Output is correct
87 Correct 975 ms 146544 KB Output is correct
88 Correct 649 ms 79292 KB Output is correct
89 Correct 859 ms 145232 KB Output is correct