답안 #472665

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
472665 2021-09-14T06:03:21 Z balbit 푸드 코트 (JOI21_foodcourt) C++14
68 / 100
560 ms 94908 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define f first
#define s second

#define REP(i,n) for(int i = 0; i<n; ++i)
#define pb push_back
#define SZ(x) (int)((x).size())

#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<"- "<<#__VA_ARGS__<<": ", _do(__VA_ARGS__)
template<typename T> void _do(T &&x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S&& ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#define endl '\n'
#endif

const int N = 250005;
const ll inf = 3e18;

ll bs[N];

void mo(int e, ll v) {
    for(++e; e<N; e+=e&-e) bs[e] += v;
}
ll qu(int e) {
    ll re = 0;
    for(++e; e>0; e-=e&-e) re += bs[e];
    return re;
}

int findfirst(ll cap) {
    int r = 0;
    for (int ty = 1<<__lg(N); ty >= 1; ty >>= 1) {
        if (cap >= bs[r + ty]) {
            r += ty; cap -= bs[r];
        }
    }
    return r;
}

ll s[N*4], mn[N*4], tg[N*4];
ll who[N]; // which group is added at this time

void push(int o, int l, int r) {
    if(tg[o]) {
        s[o] += tg[o];
        mn[o] += tg[o];
        if(l!=r) {
            tg[o*2] += tg[o];
            tg[o*2+1] += tg[o];
        }
        tg[o] = 0;
    }
}

ll QU(int L, int R, int o=1, int l=0, int r=N-1) {
    if(l > R || r<L) return inf;
    push(o,l,r);
    if(l>=L && r <=R) {
        return mn[o];
    }
    int mid = (l+r)/2;
    return min(
               QU(L,R,o*2,l,mid),
               QU(L,R,o*2+1,mid+1,r)
               );
}

ll GET(int p, int o=1, int l=0, int r=N-1) {
    if (l > p || r < p) return -1;
    push(o,l,r);
    if(l==r) return s[o];
    int mid = (l+r)/2;
    return p<=mid?GET(p,o*2,l,mid) : GET(p,o*2+1,mid+1,r);
}

void MO(int L, int R, ll v, int o=1, int l=0, int r = N-1) {
    push(o,l,r);
    if(l > R ||r < L) return;
    if(l>=L && r <=R) {
        tg[o] += v;
        push(o,l,r);
        return;
    }
    int mid = l+r>>1;
    MO(L,R,v,o*2,l,mid);
    MO(L,R,v,o*2+1,mid+1,r);
    s[o] = s[o*2]+s[o*2+1];
    mn[o] = min(mn[o*2], mn[o*2+1]);
}

vector<pii>ev[N]; // {position, value}
vector<pii>ev2[N]; // {position, value}
vector<pii> que[N]; // {position, number};

ll ans[N];

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n,m,q; cin>>n>>m>>q;
    memset(ans, -1, sizeof ans);
    REP(i,q) {
        int tp ;cin>>tp;
        if(tp == 1) {
            ll l,r,c,k; cin>>l>>r>>c>>k;
            who[i] = c;// group set
            ev[l].pb({i,k});
            ev[r+1].pb({i,-k});
        }else if (tp == 2) {
            ll l,r,k; cin>>l>>r>>k;
            ev2[l].pb({i,-k});
            ev2[r+1].pb({i,+k});
        }else if (tp == 3) {
            ll a,b; cin>>a>>b;
            que[a].pb({i, b});
        }
    }

    for(int i=1; i<=n; ++i) {
//        bug("position ", i);
        for(pii p : ev[i]) {
            int at = p.f;
            ll val = p.s;
            MO(at, N-1, val);
            bug(at, val);
            mo(at, val);
        }
        for(pii p : ev2[i]) {
            int at = p.f;
            ll val = p.s;
            MO(at, N-1, val);
            bug(at, val);
        }
        for(pii p : que[i]) {
            int at = p.f;
            ll num = p.s;
            ll low = min(0ll,QU(0, at));
            ll val = GET(at);
            bug(val, low);
            if (val - low >= num) {
                // continue here
                bug(num, val-low-num);
                num = val - low + 1 - num;

                int pp = findfirst(qu(at) - num);

                bug(pp);
                ans[at] = who[pp];
            }else{
                ans[at] = 0;
            }
        }
    }
    REP(i, q) {
        if (ans[i] != -1) cout<<ans[i]<<endl;
    }
}

Compilation message

foodcourt.cpp: In function 'void MO(int, int, long long int, int, int, int)':
foodcourt.cpp:90:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   90 |     int mid = l+r>>1;
      |               ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 20300 KB Output is correct
2 Correct 14 ms 20264 KB Output is correct
3 Correct 13 ms 20280 KB Output is correct
4 Correct 15 ms 20300 KB Output is correct
5 Correct 13 ms 20300 KB Output is correct
6 Correct 13 ms 20260 KB Output is correct
7 Correct 14 ms 20300 KB Output is correct
8 Correct 16 ms 20292 KB Output is correct
9 Correct 14 ms 20260 KB Output is correct
10 Correct 14 ms 20260 KB Output is correct
11 Correct 14 ms 20300 KB Output is correct
12 Correct 14 ms 20300 KB Output is correct
13 Correct 12 ms 20260 KB Output is correct
14 Correct 13 ms 20264 KB Output is correct
15 Correct 13 ms 20244 KB Output is correct
16 Correct 13 ms 20276 KB Output is correct
17 Correct 13 ms 20300 KB Output is correct
18 Correct 14 ms 20348 KB Output is correct
19 Correct 14 ms 20320 KB Output is correct
20 Correct 15 ms 20300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 20300 KB Output is correct
2 Correct 14 ms 20264 KB Output is correct
3 Correct 13 ms 20280 KB Output is correct
4 Correct 15 ms 20300 KB Output is correct
5 Correct 13 ms 20300 KB Output is correct
6 Correct 13 ms 20260 KB Output is correct
7 Correct 14 ms 20300 KB Output is correct
8 Correct 16 ms 20292 KB Output is correct
9 Correct 14 ms 20260 KB Output is correct
10 Correct 14 ms 20260 KB Output is correct
11 Correct 14 ms 20300 KB Output is correct
12 Correct 14 ms 20300 KB Output is correct
13 Correct 12 ms 20260 KB Output is correct
14 Correct 13 ms 20264 KB Output is correct
15 Correct 13 ms 20244 KB Output is correct
16 Correct 13 ms 20276 KB Output is correct
17 Correct 13 ms 20300 KB Output is correct
18 Correct 14 ms 20348 KB Output is correct
19 Correct 14 ms 20320 KB Output is correct
20 Correct 15 ms 20300 KB Output is correct
21 Correct 14 ms 20348 KB Output is correct
22 Correct 15 ms 20300 KB Output is correct
23 Correct 14 ms 20300 KB Output is correct
24 Correct 14 ms 20356 KB Output is correct
25 Correct 14 ms 20256 KB Output is correct
26 Correct 14 ms 20300 KB Output is correct
27 Correct 15 ms 20256 KB Output is correct
28 Correct 14 ms 20260 KB Output is correct
29 Correct 14 ms 20256 KB Output is correct
30 Correct 14 ms 20260 KB Output is correct
31 Correct 14 ms 20300 KB Output is correct
32 Correct 15 ms 20296 KB Output is correct
33 Correct 13 ms 20300 KB Output is correct
34 Correct 13 ms 20376 KB Output is correct
35 Correct 14 ms 20264 KB Output is correct
36 Correct 14 ms 20260 KB Output is correct
37 Correct 13 ms 20216 KB Output is correct
38 Correct 14 ms 20352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 129 ms 27460 KB Output is correct
2 Correct 129 ms 27544 KB Output is correct
3 Correct 125 ms 27384 KB Output is correct
4 Correct 120 ms 27460 KB Output is correct
5 Correct 124 ms 27672 KB Output is correct
6 Correct 126 ms 27488 KB Output is correct
7 Correct 59 ms 25884 KB Output is correct
8 Correct 61 ms 26108 KB Output is correct
9 Correct 124 ms 27224 KB Output is correct
10 Correct 130 ms 27556 KB Output is correct
11 Correct 123 ms 27444 KB Output is correct
12 Correct 122 ms 27508 KB Output is correct
13 Correct 112 ms 26564 KB Output is correct
14 Correct 116 ms 27444 KB Output is correct
15 Correct 131 ms 27280 KB Output is correct
16 Correct 131 ms 27460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 560 ms 45844 KB Output is correct
2 Correct 427 ms 40772 KB Output is correct
3 Runtime error 254 ms 94908 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 20300 KB Output is correct
2 Correct 14 ms 20264 KB Output is correct
3 Correct 13 ms 20280 KB Output is correct
4 Correct 15 ms 20300 KB Output is correct
5 Correct 13 ms 20300 KB Output is correct
6 Correct 13 ms 20260 KB Output is correct
7 Correct 14 ms 20300 KB Output is correct
8 Correct 16 ms 20292 KB Output is correct
9 Correct 14 ms 20260 KB Output is correct
10 Correct 14 ms 20260 KB Output is correct
11 Correct 14 ms 20300 KB Output is correct
12 Correct 14 ms 20300 KB Output is correct
13 Correct 12 ms 20260 KB Output is correct
14 Correct 13 ms 20264 KB Output is correct
15 Correct 13 ms 20244 KB Output is correct
16 Correct 13 ms 20276 KB Output is correct
17 Correct 13 ms 20300 KB Output is correct
18 Correct 14 ms 20348 KB Output is correct
19 Correct 14 ms 20320 KB Output is correct
20 Correct 15 ms 20300 KB Output is correct
21 Correct 129 ms 27460 KB Output is correct
22 Correct 129 ms 27544 KB Output is correct
23 Correct 125 ms 27384 KB Output is correct
24 Correct 120 ms 27460 KB Output is correct
25 Correct 124 ms 27672 KB Output is correct
26 Correct 126 ms 27488 KB Output is correct
27 Correct 59 ms 25884 KB Output is correct
28 Correct 61 ms 26108 KB Output is correct
29 Correct 124 ms 27224 KB Output is correct
30 Correct 130 ms 27556 KB Output is correct
31 Correct 123 ms 27444 KB Output is correct
32 Correct 122 ms 27508 KB Output is correct
33 Correct 112 ms 26564 KB Output is correct
34 Correct 116 ms 27444 KB Output is correct
35 Correct 131 ms 27280 KB Output is correct
36 Correct 131 ms 27460 KB Output is correct
37 Correct 115 ms 26764 KB Output is correct
38 Correct 104 ms 26040 KB Output is correct
39 Correct 53 ms 25464 KB Output is correct
40 Correct 63 ms 25872 KB Output is correct
41 Correct 127 ms 27076 KB Output is correct
42 Correct 126 ms 27588 KB Output is correct
43 Correct 130 ms 27548 KB Output is correct
44 Correct 126 ms 27444 KB Output is correct
45 Correct 141 ms 27720 KB Output is correct
46 Correct 127 ms 27548 KB Output is correct
47 Correct 73 ms 26460 KB Output is correct
48 Correct 104 ms 27468 KB Output is correct
49 Correct 91 ms 25544 KB Output is correct
50 Correct 110 ms 26564 KB Output is correct
51 Correct 132 ms 27652 KB Output is correct
52 Correct 140 ms 27628 KB Output is correct
53 Correct 98 ms 25960 KB Output is correct
54 Correct 121 ms 27500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 26392 KB Output is correct
2 Correct 120 ms 27076 KB Output is correct
3 Correct 124 ms 27112 KB Output is correct
4 Correct 85 ms 25080 KB Output is correct
5 Correct 112 ms 26308 KB Output is correct
6 Correct 126 ms 27160 KB Output is correct
7 Correct 62 ms 25600 KB Output is correct
8 Correct 63 ms 25224 KB Output is correct
9 Correct 85 ms 26520 KB Output is correct
10 Correct 84 ms 24972 KB Output is correct
11 Correct 112 ms 26948 KB Output is correct
12 Correct 113 ms 26820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 20300 KB Output is correct
2 Correct 14 ms 20264 KB Output is correct
3 Correct 13 ms 20280 KB Output is correct
4 Correct 15 ms 20300 KB Output is correct
5 Correct 13 ms 20300 KB Output is correct
6 Correct 13 ms 20260 KB Output is correct
7 Correct 14 ms 20300 KB Output is correct
8 Correct 16 ms 20292 KB Output is correct
9 Correct 14 ms 20260 KB Output is correct
10 Correct 14 ms 20260 KB Output is correct
11 Correct 14 ms 20300 KB Output is correct
12 Correct 14 ms 20300 KB Output is correct
13 Correct 12 ms 20260 KB Output is correct
14 Correct 13 ms 20264 KB Output is correct
15 Correct 13 ms 20244 KB Output is correct
16 Correct 13 ms 20276 KB Output is correct
17 Correct 13 ms 20300 KB Output is correct
18 Correct 14 ms 20348 KB Output is correct
19 Correct 14 ms 20320 KB Output is correct
20 Correct 15 ms 20300 KB Output is correct
21 Correct 14 ms 20348 KB Output is correct
22 Correct 15 ms 20300 KB Output is correct
23 Correct 14 ms 20300 KB Output is correct
24 Correct 14 ms 20356 KB Output is correct
25 Correct 14 ms 20256 KB Output is correct
26 Correct 14 ms 20300 KB Output is correct
27 Correct 15 ms 20256 KB Output is correct
28 Correct 14 ms 20260 KB Output is correct
29 Correct 14 ms 20256 KB Output is correct
30 Correct 14 ms 20260 KB Output is correct
31 Correct 14 ms 20300 KB Output is correct
32 Correct 15 ms 20296 KB Output is correct
33 Correct 13 ms 20300 KB Output is correct
34 Correct 13 ms 20376 KB Output is correct
35 Correct 14 ms 20264 KB Output is correct
36 Correct 14 ms 20260 KB Output is correct
37 Correct 13 ms 20216 KB Output is correct
38 Correct 14 ms 20352 KB Output is correct
39 Correct 129 ms 27460 KB Output is correct
40 Correct 129 ms 27544 KB Output is correct
41 Correct 125 ms 27384 KB Output is correct
42 Correct 120 ms 27460 KB Output is correct
43 Correct 124 ms 27672 KB Output is correct
44 Correct 126 ms 27488 KB Output is correct
45 Correct 59 ms 25884 KB Output is correct
46 Correct 61 ms 26108 KB Output is correct
47 Correct 124 ms 27224 KB Output is correct
48 Correct 130 ms 27556 KB Output is correct
49 Correct 123 ms 27444 KB Output is correct
50 Correct 122 ms 27508 KB Output is correct
51 Correct 112 ms 26564 KB Output is correct
52 Correct 116 ms 27444 KB Output is correct
53 Correct 131 ms 27280 KB Output is correct
54 Correct 131 ms 27460 KB Output is correct
55 Correct 115 ms 26764 KB Output is correct
56 Correct 104 ms 26040 KB Output is correct
57 Correct 53 ms 25464 KB Output is correct
58 Correct 63 ms 25872 KB Output is correct
59 Correct 127 ms 27076 KB Output is correct
60 Correct 126 ms 27588 KB Output is correct
61 Correct 130 ms 27548 KB Output is correct
62 Correct 126 ms 27444 KB Output is correct
63 Correct 141 ms 27720 KB Output is correct
64 Correct 127 ms 27548 KB Output is correct
65 Correct 73 ms 26460 KB Output is correct
66 Correct 104 ms 27468 KB Output is correct
67 Correct 91 ms 25544 KB Output is correct
68 Correct 110 ms 26564 KB Output is correct
69 Correct 132 ms 27652 KB Output is correct
70 Correct 140 ms 27628 KB Output is correct
71 Correct 98 ms 25960 KB Output is correct
72 Correct 121 ms 27500 KB Output is correct
73 Correct 111 ms 26392 KB Output is correct
74 Correct 120 ms 27076 KB Output is correct
75 Correct 124 ms 27112 KB Output is correct
76 Correct 85 ms 25080 KB Output is correct
77 Correct 112 ms 26308 KB Output is correct
78 Correct 126 ms 27160 KB Output is correct
79 Correct 62 ms 25600 KB Output is correct
80 Correct 63 ms 25224 KB Output is correct
81 Correct 85 ms 26520 KB Output is correct
82 Correct 84 ms 24972 KB Output is correct
83 Correct 112 ms 26948 KB Output is correct
84 Correct 113 ms 26820 KB Output is correct
85 Correct 117 ms 26784 KB Output is correct
86 Correct 133 ms 27464 KB Output is correct
87 Correct 120 ms 26580 KB Output is correct
88 Correct 132 ms 27496 KB Output is correct
89 Correct 96 ms 24840 KB Output is correct
90 Correct 134 ms 27560 KB Output is correct
91 Correct 112 ms 26256 KB Output is correct
92 Correct 101 ms 25924 KB Output is correct
93 Correct 131 ms 27572 KB Output is correct
94 Correct 132 ms 27376 KB Output is correct
95 Correct 133 ms 27320 KB Output is correct
96 Correct 132 ms 27560 KB Output is correct
97 Correct 141 ms 27624 KB Output is correct
98 Correct 115 ms 26436 KB Output is correct
99 Correct 80 ms 26508 KB Output is correct
100 Correct 96 ms 26124 KB Output is correct
101 Correct 109 ms 27460 KB Output is correct
102 Correct 116 ms 27636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 20300 KB Output is correct
2 Correct 14 ms 20264 KB Output is correct
3 Correct 13 ms 20280 KB Output is correct
4 Correct 15 ms 20300 KB Output is correct
5 Correct 13 ms 20300 KB Output is correct
6 Correct 13 ms 20260 KB Output is correct
7 Correct 14 ms 20300 KB Output is correct
8 Correct 16 ms 20292 KB Output is correct
9 Correct 14 ms 20260 KB Output is correct
10 Correct 14 ms 20260 KB Output is correct
11 Correct 14 ms 20300 KB Output is correct
12 Correct 14 ms 20300 KB Output is correct
13 Correct 12 ms 20260 KB Output is correct
14 Correct 13 ms 20264 KB Output is correct
15 Correct 13 ms 20244 KB Output is correct
16 Correct 13 ms 20276 KB Output is correct
17 Correct 13 ms 20300 KB Output is correct
18 Correct 14 ms 20348 KB Output is correct
19 Correct 14 ms 20320 KB Output is correct
20 Correct 15 ms 20300 KB Output is correct
21 Correct 14 ms 20348 KB Output is correct
22 Correct 15 ms 20300 KB Output is correct
23 Correct 14 ms 20300 KB Output is correct
24 Correct 14 ms 20356 KB Output is correct
25 Correct 14 ms 20256 KB Output is correct
26 Correct 14 ms 20300 KB Output is correct
27 Correct 15 ms 20256 KB Output is correct
28 Correct 14 ms 20260 KB Output is correct
29 Correct 14 ms 20256 KB Output is correct
30 Correct 14 ms 20260 KB Output is correct
31 Correct 14 ms 20300 KB Output is correct
32 Correct 15 ms 20296 KB Output is correct
33 Correct 13 ms 20300 KB Output is correct
34 Correct 13 ms 20376 KB Output is correct
35 Correct 14 ms 20264 KB Output is correct
36 Correct 14 ms 20260 KB Output is correct
37 Correct 13 ms 20216 KB Output is correct
38 Correct 14 ms 20352 KB Output is correct
39 Correct 129 ms 27460 KB Output is correct
40 Correct 129 ms 27544 KB Output is correct
41 Correct 125 ms 27384 KB Output is correct
42 Correct 120 ms 27460 KB Output is correct
43 Correct 124 ms 27672 KB Output is correct
44 Correct 126 ms 27488 KB Output is correct
45 Correct 59 ms 25884 KB Output is correct
46 Correct 61 ms 26108 KB Output is correct
47 Correct 124 ms 27224 KB Output is correct
48 Correct 130 ms 27556 KB Output is correct
49 Correct 123 ms 27444 KB Output is correct
50 Correct 122 ms 27508 KB Output is correct
51 Correct 112 ms 26564 KB Output is correct
52 Correct 116 ms 27444 KB Output is correct
53 Correct 131 ms 27280 KB Output is correct
54 Correct 131 ms 27460 KB Output is correct
55 Correct 560 ms 45844 KB Output is correct
56 Correct 427 ms 40772 KB Output is correct
57 Runtime error 254 ms 94908 KB Execution killed with signal 11
58 Halted 0 ms 0 KB -