Submission #472662

# Submission time Handle Problem Language Result Execution time Memory
472662 2021-09-14T05:54:15 Z balbit Food Court (JOI21_foodcourt) C++14
68 / 100
675 ms 53896 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 = 250000;
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;
}

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 l = 0, r = at;
                while (l!=r) {
                    int mid = (l+r)/2;
                    if (qu(at) - qu(mid-1) >= num) {
                        l = mid+1;
                    }else{
                        r = mid;
                    }
                }
                --l;
                bug(l);
                ans[at] = who[l];
            }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:80:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   80 |     int mid = l+r>>1;
      |               ~^~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 20200 KB Output is correct
2 Correct 14 ms 20324 KB Output is correct
3 Correct 14 ms 20256 KB Output is correct
4 Correct 14 ms 20236 KB Output is correct
5 Correct 13 ms 20256 KB Output is correct
6 Correct 14 ms 20216 KB Output is correct
7 Correct 14 ms 20324 KB Output is correct
8 Correct 14 ms 20304 KB Output is correct
9 Correct 14 ms 20340 KB Output is correct
10 Correct 15 ms 20256 KB Output is correct
11 Correct 16 ms 20248 KB Output is correct
12 Correct 16 ms 20256 KB Output is correct
13 Correct 13 ms 20256 KB Output is correct
14 Correct 13 ms 20256 KB Output is correct
15 Correct 12 ms 20244 KB Output is correct
16 Correct 14 ms 20300 KB Output is correct
17 Correct 14 ms 20256 KB Output is correct
18 Correct 15 ms 20300 KB Output is correct
19 Correct 14 ms 20264 KB Output is correct
20 Correct 14 ms 20328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 20200 KB Output is correct
2 Correct 14 ms 20324 KB Output is correct
3 Correct 14 ms 20256 KB Output is correct
4 Correct 14 ms 20236 KB Output is correct
5 Correct 13 ms 20256 KB Output is correct
6 Correct 14 ms 20216 KB Output is correct
7 Correct 14 ms 20324 KB Output is correct
8 Correct 14 ms 20304 KB Output is correct
9 Correct 14 ms 20340 KB Output is correct
10 Correct 15 ms 20256 KB Output is correct
11 Correct 16 ms 20248 KB Output is correct
12 Correct 16 ms 20256 KB Output is correct
13 Correct 13 ms 20256 KB Output is correct
14 Correct 13 ms 20256 KB Output is correct
15 Correct 12 ms 20244 KB Output is correct
16 Correct 14 ms 20300 KB Output is correct
17 Correct 14 ms 20256 KB Output is correct
18 Correct 15 ms 20300 KB Output is correct
19 Correct 14 ms 20264 KB Output is correct
20 Correct 14 ms 20328 KB Output is correct
21 Correct 16 ms 20392 KB Output is correct
22 Correct 14 ms 20300 KB Output is correct
23 Correct 14 ms 20328 KB Output is correct
24 Correct 15 ms 20356 KB Output is correct
25 Correct 13 ms 20212 KB Output is correct
26 Correct 14 ms 20252 KB Output is correct
27 Correct 14 ms 20260 KB Output is correct
28 Correct 14 ms 20352 KB Output is correct
29 Correct 16 ms 20256 KB Output is correct
30 Correct 15 ms 20348 KB Output is correct
31 Correct 15 ms 20352 KB Output is correct
32 Correct 15 ms 20320 KB Output is correct
33 Correct 13 ms 20260 KB Output is correct
34 Correct 13 ms 20300 KB Output is correct
35 Correct 13 ms 20300 KB Output is correct
36 Correct 14 ms 20260 KB Output is correct
37 Correct 13 ms 20268 KB Output is correct
38 Correct 14 ms 20232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 28476 KB Output is correct
2 Correct 151 ms 28640 KB Output is correct
3 Correct 122 ms 28520 KB Output is correct
4 Correct 123 ms 28468 KB Output is correct
5 Correct 131 ms 28580 KB Output is correct
6 Correct 133 ms 28720 KB Output is correct
7 Correct 63 ms 26496 KB Output is correct
8 Correct 66 ms 26704 KB Output is correct
9 Correct 125 ms 28236 KB Output is correct
10 Correct 127 ms 28572 KB Output is correct
11 Correct 129 ms 28588 KB Output is correct
12 Correct 127 ms 28636 KB Output is correct
13 Correct 120 ms 27492 KB Output is correct
14 Correct 122 ms 28284 KB Output is correct
15 Correct 121 ms 28496 KB Output is correct
16 Correct 138 ms 28672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 612 ms 51140 KB Output is correct
2 Correct 495 ms 44836 KB Output is correct
3 Incorrect 675 ms 53896 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 20200 KB Output is correct
2 Correct 14 ms 20324 KB Output is correct
3 Correct 14 ms 20256 KB Output is correct
4 Correct 14 ms 20236 KB Output is correct
5 Correct 13 ms 20256 KB Output is correct
6 Correct 14 ms 20216 KB Output is correct
7 Correct 14 ms 20324 KB Output is correct
8 Correct 14 ms 20304 KB Output is correct
9 Correct 14 ms 20340 KB Output is correct
10 Correct 15 ms 20256 KB Output is correct
11 Correct 16 ms 20248 KB Output is correct
12 Correct 16 ms 20256 KB Output is correct
13 Correct 13 ms 20256 KB Output is correct
14 Correct 13 ms 20256 KB Output is correct
15 Correct 12 ms 20244 KB Output is correct
16 Correct 14 ms 20300 KB Output is correct
17 Correct 14 ms 20256 KB Output is correct
18 Correct 15 ms 20300 KB Output is correct
19 Correct 14 ms 20264 KB Output is correct
20 Correct 14 ms 20328 KB Output is correct
21 Correct 123 ms 28476 KB Output is correct
22 Correct 151 ms 28640 KB Output is correct
23 Correct 122 ms 28520 KB Output is correct
24 Correct 123 ms 28468 KB Output is correct
25 Correct 131 ms 28580 KB Output is correct
26 Correct 133 ms 28720 KB Output is correct
27 Correct 63 ms 26496 KB Output is correct
28 Correct 66 ms 26704 KB Output is correct
29 Correct 125 ms 28236 KB Output is correct
30 Correct 127 ms 28572 KB Output is correct
31 Correct 129 ms 28588 KB Output is correct
32 Correct 127 ms 28636 KB Output is correct
33 Correct 120 ms 27492 KB Output is correct
34 Correct 122 ms 28284 KB Output is correct
35 Correct 121 ms 28496 KB Output is correct
36 Correct 138 ms 28672 KB Output is correct
37 Correct 132 ms 27592 KB Output is correct
38 Correct 105 ms 26820 KB Output is correct
39 Correct 56 ms 25816 KB Output is correct
40 Correct 73 ms 26476 KB Output is correct
41 Correct 133 ms 28000 KB Output is correct
42 Correct 171 ms 28496 KB Output is correct
43 Correct 147 ms 28452 KB Output is correct
44 Correct 143 ms 28308 KB Output is correct
45 Correct 135 ms 28452 KB Output is correct
46 Correct 139 ms 28484 KB Output is correct
47 Correct 77 ms 27200 KB Output is correct
48 Correct 117 ms 28180 KB Output is correct
49 Correct 102 ms 26112 KB Output is correct
50 Correct 114 ms 27280 KB Output is correct
51 Correct 134 ms 28596 KB Output is correct
52 Correct 164 ms 28532 KB Output is correct
53 Correct 113 ms 26716 KB Output is correct
54 Correct 148 ms 28656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 27796 KB Output is correct
2 Correct 135 ms 28532 KB Output is correct
3 Correct 139 ms 28616 KB Output is correct
4 Correct 118 ms 26180 KB Output is correct
5 Correct 118 ms 27420 KB Output is correct
6 Correct 134 ms 28628 KB Output is correct
7 Correct 78 ms 26720 KB Output is correct
8 Correct 72 ms 26088 KB Output is correct
9 Correct 95 ms 27912 KB Output is correct
10 Correct 86 ms 26008 KB Output is correct
11 Correct 119 ms 28228 KB Output is correct
12 Correct 124 ms 28220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 20200 KB Output is correct
2 Correct 14 ms 20324 KB Output is correct
3 Correct 14 ms 20256 KB Output is correct
4 Correct 14 ms 20236 KB Output is correct
5 Correct 13 ms 20256 KB Output is correct
6 Correct 14 ms 20216 KB Output is correct
7 Correct 14 ms 20324 KB Output is correct
8 Correct 14 ms 20304 KB Output is correct
9 Correct 14 ms 20340 KB Output is correct
10 Correct 15 ms 20256 KB Output is correct
11 Correct 16 ms 20248 KB Output is correct
12 Correct 16 ms 20256 KB Output is correct
13 Correct 13 ms 20256 KB Output is correct
14 Correct 13 ms 20256 KB Output is correct
15 Correct 12 ms 20244 KB Output is correct
16 Correct 14 ms 20300 KB Output is correct
17 Correct 14 ms 20256 KB Output is correct
18 Correct 15 ms 20300 KB Output is correct
19 Correct 14 ms 20264 KB Output is correct
20 Correct 14 ms 20328 KB Output is correct
21 Correct 16 ms 20392 KB Output is correct
22 Correct 14 ms 20300 KB Output is correct
23 Correct 14 ms 20328 KB Output is correct
24 Correct 15 ms 20356 KB Output is correct
25 Correct 13 ms 20212 KB Output is correct
26 Correct 14 ms 20252 KB Output is correct
27 Correct 14 ms 20260 KB Output is correct
28 Correct 14 ms 20352 KB Output is correct
29 Correct 16 ms 20256 KB Output is correct
30 Correct 15 ms 20348 KB Output is correct
31 Correct 15 ms 20352 KB Output is correct
32 Correct 15 ms 20320 KB Output is correct
33 Correct 13 ms 20260 KB Output is correct
34 Correct 13 ms 20300 KB Output is correct
35 Correct 13 ms 20300 KB Output is correct
36 Correct 14 ms 20260 KB Output is correct
37 Correct 13 ms 20268 KB Output is correct
38 Correct 14 ms 20232 KB Output is correct
39 Correct 123 ms 28476 KB Output is correct
40 Correct 151 ms 28640 KB Output is correct
41 Correct 122 ms 28520 KB Output is correct
42 Correct 123 ms 28468 KB Output is correct
43 Correct 131 ms 28580 KB Output is correct
44 Correct 133 ms 28720 KB Output is correct
45 Correct 63 ms 26496 KB Output is correct
46 Correct 66 ms 26704 KB Output is correct
47 Correct 125 ms 28236 KB Output is correct
48 Correct 127 ms 28572 KB Output is correct
49 Correct 129 ms 28588 KB Output is correct
50 Correct 127 ms 28636 KB Output is correct
51 Correct 120 ms 27492 KB Output is correct
52 Correct 122 ms 28284 KB Output is correct
53 Correct 121 ms 28496 KB Output is correct
54 Correct 138 ms 28672 KB Output is correct
55 Correct 132 ms 27592 KB Output is correct
56 Correct 105 ms 26820 KB Output is correct
57 Correct 56 ms 25816 KB Output is correct
58 Correct 73 ms 26476 KB Output is correct
59 Correct 133 ms 28000 KB Output is correct
60 Correct 171 ms 28496 KB Output is correct
61 Correct 147 ms 28452 KB Output is correct
62 Correct 143 ms 28308 KB Output is correct
63 Correct 135 ms 28452 KB Output is correct
64 Correct 139 ms 28484 KB Output is correct
65 Correct 77 ms 27200 KB Output is correct
66 Correct 117 ms 28180 KB Output is correct
67 Correct 102 ms 26112 KB Output is correct
68 Correct 114 ms 27280 KB Output is correct
69 Correct 134 ms 28596 KB Output is correct
70 Correct 164 ms 28532 KB Output is correct
71 Correct 113 ms 26716 KB Output is correct
72 Correct 148 ms 28656 KB Output is correct
73 Correct 119 ms 27796 KB Output is correct
74 Correct 135 ms 28532 KB Output is correct
75 Correct 139 ms 28616 KB Output is correct
76 Correct 118 ms 26180 KB Output is correct
77 Correct 118 ms 27420 KB Output is correct
78 Correct 134 ms 28628 KB Output is correct
79 Correct 78 ms 26720 KB Output is correct
80 Correct 72 ms 26088 KB Output is correct
81 Correct 95 ms 27912 KB Output is correct
82 Correct 86 ms 26008 KB Output is correct
83 Correct 119 ms 28228 KB Output is correct
84 Correct 124 ms 28220 KB Output is correct
85 Correct 128 ms 28032 KB Output is correct
86 Correct 150 ms 28848 KB Output is correct
87 Correct 136 ms 27932 KB Output is correct
88 Correct 152 ms 29048 KB Output is correct
89 Correct 91 ms 25772 KB Output is correct
90 Correct 141 ms 28996 KB Output is correct
91 Correct 122 ms 27460 KB Output is correct
92 Correct 120 ms 27000 KB Output is correct
93 Correct 151 ms 28972 KB Output is correct
94 Correct 149 ms 28856 KB Output is correct
95 Correct 136 ms 28772 KB Output is correct
96 Correct 164 ms 28980 KB Output is correct
97 Correct 137 ms 28996 KB Output is correct
98 Correct 125 ms 27684 KB Output is correct
99 Correct 86 ms 27672 KB Output is correct
100 Correct 101 ms 27204 KB Output is correct
101 Correct 117 ms 28804 KB Output is correct
102 Correct 127 ms 29024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 20200 KB Output is correct
2 Correct 14 ms 20324 KB Output is correct
3 Correct 14 ms 20256 KB Output is correct
4 Correct 14 ms 20236 KB Output is correct
5 Correct 13 ms 20256 KB Output is correct
6 Correct 14 ms 20216 KB Output is correct
7 Correct 14 ms 20324 KB Output is correct
8 Correct 14 ms 20304 KB Output is correct
9 Correct 14 ms 20340 KB Output is correct
10 Correct 15 ms 20256 KB Output is correct
11 Correct 16 ms 20248 KB Output is correct
12 Correct 16 ms 20256 KB Output is correct
13 Correct 13 ms 20256 KB Output is correct
14 Correct 13 ms 20256 KB Output is correct
15 Correct 12 ms 20244 KB Output is correct
16 Correct 14 ms 20300 KB Output is correct
17 Correct 14 ms 20256 KB Output is correct
18 Correct 15 ms 20300 KB Output is correct
19 Correct 14 ms 20264 KB Output is correct
20 Correct 14 ms 20328 KB Output is correct
21 Correct 16 ms 20392 KB Output is correct
22 Correct 14 ms 20300 KB Output is correct
23 Correct 14 ms 20328 KB Output is correct
24 Correct 15 ms 20356 KB Output is correct
25 Correct 13 ms 20212 KB Output is correct
26 Correct 14 ms 20252 KB Output is correct
27 Correct 14 ms 20260 KB Output is correct
28 Correct 14 ms 20352 KB Output is correct
29 Correct 16 ms 20256 KB Output is correct
30 Correct 15 ms 20348 KB Output is correct
31 Correct 15 ms 20352 KB Output is correct
32 Correct 15 ms 20320 KB Output is correct
33 Correct 13 ms 20260 KB Output is correct
34 Correct 13 ms 20300 KB Output is correct
35 Correct 13 ms 20300 KB Output is correct
36 Correct 14 ms 20260 KB Output is correct
37 Correct 13 ms 20268 KB Output is correct
38 Correct 14 ms 20232 KB Output is correct
39 Correct 123 ms 28476 KB Output is correct
40 Correct 151 ms 28640 KB Output is correct
41 Correct 122 ms 28520 KB Output is correct
42 Correct 123 ms 28468 KB Output is correct
43 Correct 131 ms 28580 KB Output is correct
44 Correct 133 ms 28720 KB Output is correct
45 Correct 63 ms 26496 KB Output is correct
46 Correct 66 ms 26704 KB Output is correct
47 Correct 125 ms 28236 KB Output is correct
48 Correct 127 ms 28572 KB Output is correct
49 Correct 129 ms 28588 KB Output is correct
50 Correct 127 ms 28636 KB Output is correct
51 Correct 120 ms 27492 KB Output is correct
52 Correct 122 ms 28284 KB Output is correct
53 Correct 121 ms 28496 KB Output is correct
54 Correct 138 ms 28672 KB Output is correct
55 Correct 612 ms 51140 KB Output is correct
56 Correct 495 ms 44836 KB Output is correct
57 Incorrect 675 ms 53896 KB Output isn't correct
58 Halted 0 ms 0 KB -