Submission #878629

# Submission time Handle Problem Language Result Execution time Memory
878629 2023-11-25T02:44:05 Z thangdz2k7 Food Court (JOI21_foodcourt) C++17
24 / 100
70 ms 32120 KB
#include <bits/stdc++.h>
#define ll pair <long long, long long>
#define ii pair <int, int>
#define F first
#define S second
#define pb push_back

using namespace std;

const int N = 2e5 + 5e4 + 5;

int n, m, q, group[N], ans[N];
vector <ii> event[N], numadd[N], query[N];

long long cur[4 * N], Min[4 * N];

void update_cur(int s, int l, int r, int u, int val){
    if (l == r){
        cur[s] += val;
        Min[s] = min(0ll, cur[s]);
        return;
    }

    int mid = l + r >> 1;
    if (mid >= u) update_cur(2 * s, l, mid, u, val);
    else update_cur(2 * s + 1, mid + 1, r, u, val);

    cur[s] = cur[2 * s] + cur[2 * s + 1];
    Min[s] = min(Min[2 * s], cur[2 * s] + Min[2 * s + 1]);
}

ll get_cur(int s, int l, int r, int u){
    if (l > u) return ll(0, 0);
    if (r <= u) return ll(cur[s], Min[s]);

    int mid = l + r >> 1;
    ll A = get_cur(2 * s, l, mid, u);
    ll B = get_cur(2 * s + 1, mid + 1, r, u);

    return ll(A.F + B.F, min(A.S, A.F + B.S));
}

long long sumadd[4 * N];

void update_sumadd(int s, int l, int r, int u, int val){
    if (l == r){
        sumadd[s] += val;
        return;
    }

    int mid = l + r >> 1;
    if (mid >= u) update_sumadd(2 * s, l, mid, u, val);
    else update_sumadd(2 * s + 1, mid + 1, r, u, val);
    sumadd[s] = sumadd[2 * s] + sumadd[2 * s + 1];
}

long long get_sumadd(int s, int l, int r, int u){
    if (l > u) return 0;
    if (r <= u) return sumadd[s];

    int mid = l + r >> 1;
    return get_sumadd(2 * s, l, mid, u) + get_sumadd(2 * s + 1, mid + 1, r, u);
}

int get_pos(int s, int l, int r, long long val){
    if (l == r) return l;
    int mid = l + r >> 1;
    if (sumadd[2 * s] < val) return get_pos(2 * s + 1, mid + 1, r, val - sumadd[2 * s]);
    return get_pos(2 * s, l, mid, val);
}

void solve(){
    cin >> n >> m >> q;
    for (int i = 1; i <= q; ++ i){
        ans[i] = -1;
        int t; cin >> t;
        if (t == 1){
            int l, r, k; cin >> l >> r >> group[i] >> k;
            event[l].pb(ii(i, k));
            event[r + 1].pb(ii(i, -k));
            numadd[l].pb(ii(i, k));
            numadd[r + 1].pb(ii(i, -k));
        }
        if (t == 2){
            int l, r, k; cin >> l >> r >> k;
            event[l].pb(ii(i, -k));
            event[r + 1].pb(ii(i, k));
        }
        if (t == 3){
            int a, b; cin >> a >> b;
            query[a].pb(ii(i, b));
        }
    }

    for (int i = 1; i <= n; ++ i){
        for (ii v : event[i]) {
            update_cur(1, 1, q, v.F, v.S);
            //cout << i << ' ' << v.F << ' ' << v.S << endl;
        }
        for (ii v : numadd[i]) update_sumadd(1, 1, q, v.F, v.S);
        for (ii v : query[i]){
            ll gnum_cur = get_cur(1, 1, q, v.F);
            long long num_cur = gnum_cur.F - gnum_cur.S;
            //cout << gnum_cur.F << ' ' << gnum_cur.S << endl;
            long long num_add = get_sumadd(1, 1, q, v.F);
            if (num_cur < v.S) ans[v.F] = 0;
            else ans[v.F] = group[get_pos(1, 1, q, num_add - num_cur + v.S)];
        }
    }

    for (int i = 1; i <= q; ++ i) if (ans[i] >= 0) cout << ans[i] << '\n';
}

signed main(){
    //freopen("foodcourt.inp", "r", stdin);
    //freopen("foodcourt.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();

    return 0;
}

Compilation message

foodcourt.cpp: In function 'void update_cur(int, int, int, int, int)':
foodcourt.cpp:24:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   24 |     int mid = l + r >> 1;
      |               ~~^~~
foodcourt.cpp: In function 'std::pair<long long int, long long int> get_cur(int, int, int, int)':
foodcourt.cpp:36:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |     int mid = l + r >> 1;
      |               ~~^~~
foodcourt.cpp: In function 'void update_sumadd(int, int, int, int, int)':
foodcourt.cpp:51:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |     int mid = l + r >> 1;
      |               ~~^~~
foodcourt.cpp: In function 'long long int get_sumadd(int, int, int, int)':
foodcourt.cpp:61:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   61 |     int mid = l + r >> 1;
      |               ~~^~~
foodcourt.cpp: In function 'int get_pos(int, int, int, long long int)':
foodcourt.cpp:67:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   67 |     int mid = l + r >> 1;
      |               ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21084 KB Output is correct
2 Correct 5 ms 21084 KB Output is correct
3 Correct 5 ms 21084 KB Output is correct
4 Correct 5 ms 21080 KB Output is correct
5 Correct 5 ms 21084 KB Output is correct
6 Correct 6 ms 21336 KB Output is correct
7 Correct 6 ms 21084 KB Output is correct
8 Correct 5 ms 21196 KB Output is correct
9 Correct 5 ms 21084 KB Output is correct
10 Correct 5 ms 21084 KB Output is correct
11 Correct 6 ms 21144 KB Output is correct
12 Correct 6 ms 21084 KB Output is correct
13 Correct 5 ms 21084 KB Output is correct
14 Correct 5 ms 21128 KB Output is correct
15 Correct 5 ms 21084 KB Output is correct
16 Correct 5 ms 21180 KB Output is correct
17 Correct 6 ms 21084 KB Output is correct
18 Correct 5 ms 21084 KB Output is correct
19 Correct 7 ms 21084 KB Output is correct
20 Correct 6 ms 21080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21084 KB Output is correct
2 Correct 5 ms 21084 KB Output is correct
3 Correct 5 ms 21084 KB Output is correct
4 Correct 5 ms 21080 KB Output is correct
5 Correct 5 ms 21084 KB Output is correct
6 Correct 6 ms 21336 KB Output is correct
7 Correct 6 ms 21084 KB Output is correct
8 Correct 5 ms 21196 KB Output is correct
9 Correct 5 ms 21084 KB Output is correct
10 Correct 5 ms 21084 KB Output is correct
11 Correct 6 ms 21144 KB Output is correct
12 Correct 6 ms 21084 KB Output is correct
13 Correct 5 ms 21084 KB Output is correct
14 Correct 5 ms 21128 KB Output is correct
15 Correct 5 ms 21084 KB Output is correct
16 Correct 5 ms 21180 KB Output is correct
17 Correct 6 ms 21084 KB Output is correct
18 Correct 5 ms 21084 KB Output is correct
19 Correct 7 ms 21084 KB Output is correct
20 Correct 6 ms 21080 KB Output is correct
21 Incorrect 5 ms 21084 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 55 ms 31060 KB Output is correct
2 Correct 67 ms 31568 KB Output is correct
3 Correct 53 ms 31044 KB Output is correct
4 Correct 57 ms 31132 KB Output is correct
5 Correct 60 ms 31580 KB Output is correct
6 Correct 59 ms 31568 KB Output is correct
7 Correct 28 ms 28596 KB Output is correct
8 Correct 29 ms 29212 KB Output is correct
9 Correct 54 ms 31204 KB Output is correct
10 Correct 55 ms 31312 KB Output is correct
11 Correct 56 ms 31268 KB Output is correct
12 Correct 70 ms 31312 KB Output is correct
13 Correct 49 ms 31580 KB Output is correct
14 Correct 61 ms 31316 KB Output is correct
15 Correct 64 ms 31572 KB Output is correct
16 Correct 67 ms 32084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 60 ms 30148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21084 KB Output is correct
2 Correct 5 ms 21084 KB Output is correct
3 Correct 5 ms 21084 KB Output is correct
4 Correct 5 ms 21080 KB Output is correct
5 Correct 5 ms 21084 KB Output is correct
6 Correct 6 ms 21336 KB Output is correct
7 Correct 6 ms 21084 KB Output is correct
8 Correct 5 ms 21196 KB Output is correct
9 Correct 5 ms 21084 KB Output is correct
10 Correct 5 ms 21084 KB Output is correct
11 Correct 6 ms 21144 KB Output is correct
12 Correct 6 ms 21084 KB Output is correct
13 Correct 5 ms 21084 KB Output is correct
14 Correct 5 ms 21128 KB Output is correct
15 Correct 5 ms 21084 KB Output is correct
16 Correct 5 ms 21180 KB Output is correct
17 Correct 6 ms 21084 KB Output is correct
18 Correct 5 ms 21084 KB Output is correct
19 Correct 7 ms 21084 KB Output is correct
20 Correct 6 ms 21080 KB Output is correct
21 Correct 55 ms 31060 KB Output is correct
22 Correct 67 ms 31568 KB Output is correct
23 Correct 53 ms 31044 KB Output is correct
24 Correct 57 ms 31132 KB Output is correct
25 Correct 60 ms 31580 KB Output is correct
26 Correct 59 ms 31568 KB Output is correct
27 Correct 28 ms 28596 KB Output is correct
28 Correct 29 ms 29212 KB Output is correct
29 Correct 54 ms 31204 KB Output is correct
30 Correct 55 ms 31312 KB Output is correct
31 Correct 56 ms 31268 KB Output is correct
32 Correct 70 ms 31312 KB Output is correct
33 Correct 49 ms 31580 KB Output is correct
34 Correct 61 ms 31316 KB Output is correct
35 Correct 64 ms 31572 KB Output is correct
36 Correct 67 ms 32084 KB Output is correct
37 Correct 55 ms 31604 KB Output is correct
38 Correct 52 ms 30300 KB Output is correct
39 Correct 25 ms 28204 KB Output is correct
40 Correct 30 ms 28780 KB Output is correct
41 Correct 56 ms 30804 KB Output is correct
42 Correct 56 ms 31064 KB Output is correct
43 Correct 57 ms 31036 KB Output is correct
44 Correct 56 ms 31008 KB Output is correct
45 Correct 57 ms 31056 KB Output is correct
46 Correct 56 ms 31056 KB Output is correct
47 Correct 37 ms 30052 KB Output is correct
48 Correct 47 ms 29952 KB Output is correct
49 Correct 40 ms 29524 KB Output is correct
50 Correct 49 ms 30532 KB Output is correct
51 Correct 56 ms 31060 KB Output is correct
52 Correct 57 ms 31064 KB Output is correct
53 Correct 56 ms 30924 KB Output is correct
54 Correct 67 ms 32120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 24024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21084 KB Output is correct
2 Correct 5 ms 21084 KB Output is correct
3 Correct 5 ms 21084 KB Output is correct
4 Correct 5 ms 21080 KB Output is correct
5 Correct 5 ms 21084 KB Output is correct
6 Correct 6 ms 21336 KB Output is correct
7 Correct 6 ms 21084 KB Output is correct
8 Correct 5 ms 21196 KB Output is correct
9 Correct 5 ms 21084 KB Output is correct
10 Correct 5 ms 21084 KB Output is correct
11 Correct 6 ms 21144 KB Output is correct
12 Correct 6 ms 21084 KB Output is correct
13 Correct 5 ms 21084 KB Output is correct
14 Correct 5 ms 21128 KB Output is correct
15 Correct 5 ms 21084 KB Output is correct
16 Correct 5 ms 21180 KB Output is correct
17 Correct 6 ms 21084 KB Output is correct
18 Correct 5 ms 21084 KB Output is correct
19 Correct 7 ms 21084 KB Output is correct
20 Correct 6 ms 21080 KB Output is correct
21 Incorrect 5 ms 21084 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21084 KB Output is correct
2 Correct 5 ms 21084 KB Output is correct
3 Correct 5 ms 21084 KB Output is correct
4 Correct 5 ms 21080 KB Output is correct
5 Correct 5 ms 21084 KB Output is correct
6 Correct 6 ms 21336 KB Output is correct
7 Correct 6 ms 21084 KB Output is correct
8 Correct 5 ms 21196 KB Output is correct
9 Correct 5 ms 21084 KB Output is correct
10 Correct 5 ms 21084 KB Output is correct
11 Correct 6 ms 21144 KB Output is correct
12 Correct 6 ms 21084 KB Output is correct
13 Correct 5 ms 21084 KB Output is correct
14 Correct 5 ms 21128 KB Output is correct
15 Correct 5 ms 21084 KB Output is correct
16 Correct 5 ms 21180 KB Output is correct
17 Correct 6 ms 21084 KB Output is correct
18 Correct 5 ms 21084 KB Output is correct
19 Correct 7 ms 21084 KB Output is correct
20 Correct 6 ms 21080 KB Output is correct
21 Incorrect 5 ms 21084 KB Output isn't correct
22 Halted 0 ms 0 KB -