답안 #51634

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51634 2018-06-19T11:18:38 Z Diuven 단층 (JOI16_ho_t5) C++11
100 / 100
227 ms 9124 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const int MX=200010, inf=2e9;

int n, q;

struct {
    int x, d, l;
} L[MX];

struct BIT {
    int n;
    ll tree[MX];
    void init(int sz){
        n=sz;
        for(int i=1; i<=n; i++) tree[i]=0;
    }
    void upt(int pos, ll d){
        for(; pos>0; pos-=pos&(-pos))
            tree[pos]+=d;
    }
    void upt(int l, int r, ll d){
        if(r<l) return;
        upt(r,d); upt(l-1,-d);
    }
    ll val(int x){
        ll res=0;
        for(; 0<x && x<=n; x+=x&(-x))
            res+=tree[x];
        return res;
    }
} UT, VT;

void process(int idx){
    if(L[idx].d==1){
        if(VT.val(1)<L[idx].x) return;
        int l=1, r;
        {
            int s=1, e=n;
            while(s<e){
                int m=(s+e+1)/2;
                if(VT.val(m)>=L[idx].x) s=m;
                else e=m-1;
            }
            r=s;
        }
        UT.upt(l,r,-L[idx].l);
    }
    else{
        if(UT.val(n)<L[idx].x) return;
        int l, r=n;
        {
            int s=1, e=n;
            while(s<e){
                int m=(s+e)/2;
                if(UT.val(m)>=L[idx].x) e=m;
                else s=m+1;
            }
            l=s;
        }
        VT.upt(l,r,-L[idx].l);
    }

}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n>>q;
    UT.init(n); VT.init(n);
    for(int i=1; i<=q; i++){
        int x, d, l;
        cin>>x>>d>>l;
        // v>=x, u+=l
        if(d==1) L[i]={-x,d,2*l};
        // u>=x, v+=l
        else L[i]={x+1,d,2*l};
    }
    for(int i=1; i<=n; i++){
        UT.upt(i,i,i);
        VT.upt(i,i,-i);
    }
    for(int i=q; i>=1; i--){
        process(i);
    }
    for(int i=1; i<=n; i++)
        cout<<-((UT.val(i)+VT.val(i))/2)<<'\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 408 KB Output is correct
5 Correct 3 ms 408 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 3 ms 592 KB Output is correct
8 Correct 3 ms 592 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 3 ms 720 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 3 ms 744 KB Output is correct
21 Correct 2 ms 744 KB Output is correct
22 Correct 3 ms 744 KB Output is correct
23 Correct 3 ms 744 KB Output is correct
24 Correct 3 ms 744 KB Output is correct
25 Correct 2 ms 744 KB Output is correct
26 Correct 2 ms 744 KB Output is correct
27 Correct 3 ms 744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 408 KB Output is correct
5 Correct 3 ms 408 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 3 ms 592 KB Output is correct
8 Correct 3 ms 592 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 3 ms 720 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 3 ms 744 KB Output is correct
21 Correct 2 ms 744 KB Output is correct
22 Correct 3 ms 744 KB Output is correct
23 Correct 3 ms 744 KB Output is correct
24 Correct 3 ms 744 KB Output is correct
25 Correct 2 ms 744 KB Output is correct
26 Correct 2 ms 744 KB Output is correct
27 Correct 3 ms 744 KB Output is correct
28 Correct 5 ms 744 KB Output is correct
29 Correct 5 ms 764 KB Output is correct
30 Correct 3 ms 780 KB Output is correct
31 Correct 4 ms 796 KB Output is correct
32 Correct 4 ms 812 KB Output is correct
33 Correct 5 ms 812 KB Output is correct
34 Correct 5 ms 812 KB Output is correct
35 Correct 5 ms 824 KB Output is correct
36 Correct 4 ms 824 KB Output is correct
37 Correct 4 ms 824 KB Output is correct
38 Correct 4 ms 828 KB Output is correct
39 Correct 4 ms 828 KB Output is correct
40 Correct 4 ms 828 KB Output is correct
41 Correct 4 ms 828 KB Output is correct
42 Correct 5 ms 828 KB Output is correct
43 Correct 4 ms 828 KB Output is correct
44 Correct 5 ms 828 KB Output is correct
45 Correct 5 ms 828 KB Output is correct
46 Correct 4 ms 828 KB Output is correct
47 Correct 4 ms 828 KB Output is correct
48 Correct 4 ms 828 KB Output is correct
49 Correct 4 ms 944 KB Output is correct
50 Correct 5 ms 944 KB Output is correct
51 Correct 4 ms 944 KB Output is correct
52 Correct 4 ms 944 KB Output is correct
53 Correct 4 ms 944 KB Output is correct
54 Correct 4 ms 944 KB Output is correct
55 Correct 5 ms 944 KB Output is correct
56 Correct 5 ms 944 KB Output is correct
57 Correct 4 ms 944 KB Output is correct
58 Correct 4 ms 944 KB Output is correct
59 Correct 4 ms 944 KB Output is correct
60 Correct 4 ms 944 KB Output is correct
61 Correct 4 ms 944 KB Output is correct
62 Correct 4 ms 944 KB Output is correct
63 Correct 4 ms 944 KB Output is correct
64 Correct 5 ms 944 KB Output is correct
65 Correct 7 ms 944 KB Output is correct
66 Correct 6 ms 944 KB Output is correct
67 Correct 5 ms 944 KB Output is correct
68 Correct 5 ms 944 KB Output is correct
69 Correct 4 ms 944 KB Output is correct
70 Correct 3 ms 944 KB Output is correct
71 Correct 2 ms 944 KB Output is correct
72 Correct 3 ms 944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 408 KB Output is correct
5 Correct 3 ms 408 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 3 ms 592 KB Output is correct
8 Correct 3 ms 592 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 3 ms 720 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 3 ms 744 KB Output is correct
21 Correct 2 ms 744 KB Output is correct
22 Correct 3 ms 744 KB Output is correct
23 Correct 3 ms 744 KB Output is correct
24 Correct 3 ms 744 KB Output is correct
25 Correct 2 ms 744 KB Output is correct
26 Correct 2 ms 744 KB Output is correct
27 Correct 3 ms 744 KB Output is correct
28 Correct 5 ms 744 KB Output is correct
29 Correct 5 ms 764 KB Output is correct
30 Correct 3 ms 780 KB Output is correct
31 Correct 4 ms 796 KB Output is correct
32 Correct 4 ms 812 KB Output is correct
33 Correct 5 ms 812 KB Output is correct
34 Correct 5 ms 812 KB Output is correct
35 Correct 5 ms 824 KB Output is correct
36 Correct 4 ms 824 KB Output is correct
37 Correct 4 ms 824 KB Output is correct
38 Correct 4 ms 828 KB Output is correct
39 Correct 4 ms 828 KB Output is correct
40 Correct 4 ms 828 KB Output is correct
41 Correct 4 ms 828 KB Output is correct
42 Correct 5 ms 828 KB Output is correct
43 Correct 4 ms 828 KB Output is correct
44 Correct 5 ms 828 KB Output is correct
45 Correct 5 ms 828 KB Output is correct
46 Correct 4 ms 828 KB Output is correct
47 Correct 4 ms 828 KB Output is correct
48 Correct 4 ms 828 KB Output is correct
49 Correct 4 ms 944 KB Output is correct
50 Correct 5 ms 944 KB Output is correct
51 Correct 4 ms 944 KB Output is correct
52 Correct 4 ms 944 KB Output is correct
53 Correct 4 ms 944 KB Output is correct
54 Correct 4 ms 944 KB Output is correct
55 Correct 5 ms 944 KB Output is correct
56 Correct 5 ms 944 KB Output is correct
57 Correct 4 ms 944 KB Output is correct
58 Correct 4 ms 944 KB Output is correct
59 Correct 4 ms 944 KB Output is correct
60 Correct 4 ms 944 KB Output is correct
61 Correct 4 ms 944 KB Output is correct
62 Correct 4 ms 944 KB Output is correct
63 Correct 4 ms 944 KB Output is correct
64 Correct 5 ms 944 KB Output is correct
65 Correct 7 ms 944 KB Output is correct
66 Correct 6 ms 944 KB Output is correct
67 Correct 5 ms 944 KB Output is correct
68 Correct 5 ms 944 KB Output is correct
69 Correct 4 ms 944 KB Output is correct
70 Correct 3 ms 944 KB Output is correct
71 Correct 2 ms 944 KB Output is correct
72 Correct 3 ms 944 KB Output is correct
73 Correct 186 ms 7340 KB Output is correct
74 Correct 211 ms 7340 KB Output is correct
75 Correct 227 ms 7488 KB Output is correct
76 Correct 181 ms 7488 KB Output is correct
77 Correct 174 ms 7488 KB Output is correct
78 Correct 180 ms 7488 KB Output is correct
79 Correct 204 ms 7612 KB Output is correct
80 Correct 150 ms 7616 KB Output is correct
81 Correct 136 ms 7840 KB Output is correct
82 Correct 135 ms 7840 KB Output is correct
83 Correct 138 ms 7904 KB Output is correct
84 Correct 157 ms 7904 KB Output is correct
85 Correct 132 ms 7916 KB Output is correct
86 Correct 135 ms 8036 KB Output is correct
87 Correct 117 ms 8656 KB Output is correct
88 Correct 147 ms 9020 KB Output is correct
89 Correct 125 ms 9020 KB Output is correct
90 Correct 175 ms 9124 KB Output is correct
91 Correct 147 ms 9124 KB Output is correct
92 Correct 143 ms 9124 KB Output is correct
93 Correct 162 ms 9124 KB Output is correct
94 Correct 150 ms 9124 KB Output is correct
95 Correct 163 ms 9124 KB Output is correct
96 Correct 177 ms 9124 KB Output is correct
97 Correct 176 ms 9124 KB Output is correct
98 Correct 157 ms 9124 KB Output is correct
99 Correct 172 ms 9124 KB Output is correct
100 Correct 155 ms 9124 KB Output is correct
101 Correct 172 ms 9124 KB Output is correct
102 Correct 158 ms 9124 KB Output is correct
103 Correct 171 ms 9124 KB Output is correct
104 Correct 147 ms 9124 KB Output is correct
105 Correct 168 ms 9124 KB Output is correct
106 Correct 144 ms 9124 KB Output is correct
107 Correct 130 ms 9124 KB Output is correct
108 Correct 169 ms 9124 KB Output is correct
109 Correct 168 ms 9124 KB Output is correct
110 Correct 140 ms 9124 KB Output is correct
111 Correct 164 ms 9124 KB Output is correct
112 Correct 155 ms 9124 KB Output is correct
113 Correct 173 ms 9124 KB Output is correct
114 Correct 153 ms 9124 KB Output is correct
115 Correct 154 ms 9124 KB Output is correct
116 Correct 146 ms 9124 KB Output is correct
117 Correct 168 ms 9124 KB Output is correct
118 Correct 147 ms 9124 KB Output is correct
119 Correct 40 ms 9124 KB Output is correct
120 Correct 34 ms 9124 KB Output is correct