답안 #878633

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878633 2023-11-25T02:45:49 Z thangdz2k7 푸드 코트 (JOI21_foodcourt) C++17
24 / 100
338 ms 52920 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
#define ill long long

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, ill 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, ill 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;
            ill 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, long long int)':
foodcourt.cpp:25:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   25 |     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:37:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |     int mid = l + r >> 1;
      |               ~~^~~
foodcourt.cpp: In function 'void update_sumadd(int, int, int, int, long long int)':
foodcourt.cpp:52:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   52 |     int mid = l + r >> 1;
      |               ~~^~~
foodcourt.cpp: In function 'long long int get_sumadd(int, int, int, int)':
foodcourt.cpp:62:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   62 |     int mid = l + r >> 1;
      |               ~~^~~
foodcourt.cpp: In function 'int get_pos(int, int, int, long long int)':
foodcourt.cpp:68:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   68 |     int mid = l + r >> 1;
      |               ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21084 KB Output is correct
2 Correct 5 ms 21104 KB Output is correct
3 Correct 5 ms 20920 KB Output is correct
4 Correct 5 ms 21336 KB Output is correct
5 Correct 5 ms 20920 KB Output is correct
6 Correct 6 ms 21084 KB Output is correct
7 Correct 5 ms 21084 KB Output is correct
8 Correct 6 ms 21084 KB Output is correct
9 Correct 6 ms 20948 KB Output is correct
10 Correct 7 ms 21084 KB Output is correct
11 Correct 5 ms 21084 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 21084 KB Output is correct
15 Correct 5 ms 21060 KB Output is correct
16 Correct 6 ms 21084 KB Output is correct
17 Correct 5 ms 21084 KB Output is correct
18 Correct 5 ms 21084 KB Output is correct
19 Correct 5 ms 21080 KB Output is correct
20 Correct 6 ms 21084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21084 KB Output is correct
2 Correct 5 ms 21104 KB Output is correct
3 Correct 5 ms 20920 KB Output is correct
4 Correct 5 ms 21336 KB Output is correct
5 Correct 5 ms 20920 KB Output is correct
6 Correct 6 ms 21084 KB Output is correct
7 Correct 5 ms 21084 KB Output is correct
8 Correct 6 ms 21084 KB Output is correct
9 Correct 6 ms 20948 KB Output is correct
10 Correct 7 ms 21084 KB Output is correct
11 Correct 5 ms 21084 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 21084 KB Output is correct
15 Correct 5 ms 21060 KB Output is correct
16 Correct 6 ms 21084 KB Output is correct
17 Correct 5 ms 21084 KB Output is correct
18 Correct 5 ms 21084 KB Output is correct
19 Correct 5 ms 21080 KB Output is correct
20 Correct 6 ms 21084 KB Output is correct
21 Incorrect 6 ms 21084 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 29964 KB Output is correct
2 Correct 61 ms 30288 KB Output is correct
3 Correct 58 ms 29872 KB Output is correct
4 Correct 55 ms 29956 KB Output is correct
5 Correct 70 ms 30320 KB Output is correct
6 Correct 57 ms 30292 KB Output is correct
7 Correct 28 ms 27832 KB Output is correct
8 Correct 30 ms 28400 KB Output is correct
9 Correct 76 ms 29948 KB Output is correct
10 Correct 53 ms 30032 KB Output is correct
11 Correct 53 ms 30028 KB Output is correct
12 Correct 56 ms 30032 KB Output is correct
13 Correct 48 ms 30804 KB Output is correct
14 Correct 62 ms 30292 KB Output is correct
15 Correct 61 ms 30288 KB Output is correct
16 Correct 69 ms 30804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 338 ms 52920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21084 KB Output is correct
2 Correct 5 ms 21104 KB Output is correct
3 Correct 5 ms 20920 KB Output is correct
4 Correct 5 ms 21336 KB Output is correct
5 Correct 5 ms 20920 KB Output is correct
6 Correct 6 ms 21084 KB Output is correct
7 Correct 5 ms 21084 KB Output is correct
8 Correct 6 ms 21084 KB Output is correct
9 Correct 6 ms 20948 KB Output is correct
10 Correct 7 ms 21084 KB Output is correct
11 Correct 5 ms 21084 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 21084 KB Output is correct
15 Correct 5 ms 21060 KB Output is correct
16 Correct 6 ms 21084 KB Output is correct
17 Correct 5 ms 21084 KB Output is correct
18 Correct 5 ms 21084 KB Output is correct
19 Correct 5 ms 21080 KB Output is correct
20 Correct 6 ms 21084 KB Output is correct
21 Correct 55 ms 29964 KB Output is correct
22 Correct 61 ms 30288 KB Output is correct
23 Correct 58 ms 29872 KB Output is correct
24 Correct 55 ms 29956 KB Output is correct
25 Correct 70 ms 30320 KB Output is correct
26 Correct 57 ms 30292 KB Output is correct
27 Correct 28 ms 27832 KB Output is correct
28 Correct 30 ms 28400 KB Output is correct
29 Correct 76 ms 29948 KB Output is correct
30 Correct 53 ms 30032 KB Output is correct
31 Correct 53 ms 30028 KB Output is correct
32 Correct 56 ms 30032 KB Output is correct
33 Correct 48 ms 30804 KB Output is correct
34 Correct 62 ms 30292 KB Output is correct
35 Correct 61 ms 30288 KB Output is correct
36 Correct 69 ms 30804 KB Output is correct
37 Correct 57 ms 30552 KB Output is correct
38 Correct 51 ms 29532 KB Output is correct
39 Correct 25 ms 27692 KB Output is correct
40 Correct 30 ms 28260 KB Output is correct
41 Correct 58 ms 29832 KB Output is correct
42 Correct 58 ms 30032 KB Output is correct
43 Correct 62 ms 30032 KB Output is correct
44 Correct 69 ms 29948 KB Output is correct
45 Correct 63 ms 30004 KB Output is correct
46 Correct 55 ms 29872 KB Output is correct
47 Correct 35 ms 28568 KB Output is correct
48 Correct 46 ms 28992 KB Output is correct
49 Correct 39 ms 28764 KB Output is correct
50 Correct 49 ms 29608 KB Output is correct
51 Correct 60 ms 30036 KB Output is correct
52 Correct 62 ms 30068 KB Output is correct
53 Correct 49 ms 29768 KB Output is correct
54 Correct 72 ms 30804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 79 ms 27180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21084 KB Output is correct
2 Correct 5 ms 21104 KB Output is correct
3 Correct 5 ms 20920 KB Output is correct
4 Correct 5 ms 21336 KB Output is correct
5 Correct 5 ms 20920 KB Output is correct
6 Correct 6 ms 21084 KB Output is correct
7 Correct 5 ms 21084 KB Output is correct
8 Correct 6 ms 21084 KB Output is correct
9 Correct 6 ms 20948 KB Output is correct
10 Correct 7 ms 21084 KB Output is correct
11 Correct 5 ms 21084 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 21084 KB Output is correct
15 Correct 5 ms 21060 KB Output is correct
16 Correct 6 ms 21084 KB Output is correct
17 Correct 5 ms 21084 KB Output is correct
18 Correct 5 ms 21084 KB Output is correct
19 Correct 5 ms 21080 KB Output is correct
20 Correct 6 ms 21084 KB Output is correct
21 Incorrect 6 ms 21084 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21084 KB Output is correct
2 Correct 5 ms 21104 KB Output is correct
3 Correct 5 ms 20920 KB Output is correct
4 Correct 5 ms 21336 KB Output is correct
5 Correct 5 ms 20920 KB Output is correct
6 Correct 6 ms 21084 KB Output is correct
7 Correct 5 ms 21084 KB Output is correct
8 Correct 6 ms 21084 KB Output is correct
9 Correct 6 ms 20948 KB Output is correct
10 Correct 7 ms 21084 KB Output is correct
11 Correct 5 ms 21084 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 21084 KB Output is correct
15 Correct 5 ms 21060 KB Output is correct
16 Correct 6 ms 21084 KB Output is correct
17 Correct 5 ms 21084 KB Output is correct
18 Correct 5 ms 21084 KB Output is correct
19 Correct 5 ms 21080 KB Output is correct
20 Correct 6 ms 21084 KB Output is correct
21 Incorrect 6 ms 21084 KB Output isn't correct
22 Halted 0 ms 0 KB -