답안 #797081

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
797081 2023-07-29T06:14:00 Z vjudge1 푸드 코트 (JOI21_foodcourt) C++17
24 / 100
316 ms 49992 KB
#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 250500;
const int mod = 1e9 + 7;

using namespace std;

struct fenwick {
        vector<long long> t;
        fenwick(int _N) : t(_N, 0) {}

        void upd(int x, long long g) {
                while(x < t.size()) {
                        t[x] += g;
                        x += x & -x;
                }
        }

        long long get(int x) {
                long long res = 0;
                while(x > 0) {
                        res += t[x];
                        x -= x & -x;
                }
                return res;
        }

        int get_f(long long k) {
                int res = 0;
                for (int i = 20; i >= 0; i--) {
                        if (res + (1 << i) >= t.size()) {
                                continue;
                        } else if (t[res + (1 << i)] < k) {
                                res += (1 << i);
                                k -= t[res];
                        }
                }
                return res + 1;
        }
};

long long t[4 * N];
long long lz[4 * N];

void upd(int x, int l, int r, int tl, int tr, long long y)
{
        if (tl > tr) {
                return;
        } else if (l == tl && r == tr) {
                t[x] += y;
                lz[x] += y;
                return;
        }
        int m = (l + r) / 2;
        upd(x * 2, l, m, tl, min(m, tr), y);
        upd(x * 2 + 1, m + 1, r, max(m + 1, tl), tr, y);
        t[x] = min(t[x * 2], t[x * 2 + 1]) + lz[x];
}

long long inf = 1e18;
long long get(int x, int l, int r, int tl, int tr)
{
        if (tl > tr) {
                return inf;
        } else if (l == tl && r == tr) {
                return t[x];
        }
        int m = (l + r) / 2;
        return min(get(x * 2, l, m, tl, min(m, tr)), get(x * 2 + 1, m + 1, r, max(m + 1, tl), tr)) + lz[x];
}

fenwick A(N), B(N);

int n, m, q;
long long res[N];
long long c[N];
vector<pair<long long, int>> ad[N];
vector<pair<long long, int>> del[N];
vector<pair<long long, int>> qu[N];


int main() {
        #ifdef zxc
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        #endif
        ios_base::sync_with_stdio(0);

        cin >> n >> m >> q;
        for (int i = 1; i <= q; i++) {
                int t;
                cin >> t;
                res[i] = -1;
                if (t == 1) {
                        long long l, r, k;
                        cin >> l >> r >> c[i] >> k;
                        ad[l].push_back({i, k});
                        ad[r + 1].push_back({i, -k});
                } else if (t == 2) {
                        long long l, r, k;
                        cin >> l >> r >> k;
                        del[l].push_back({i, -k});
                        del[r + 1].push_back({i, k});
                } else {
                        long long l, b;
                        cin >> l >> b;
                        qu[l].push_back({i, b});
                }
        }

        for (int i = 1; i <= n; i++) {
                for (auto p: ad[i]) {
                        A.upd(p.fi, p.se);
                        B.upd(p.fi, p.se);
                        upd(1, 0, q, p.fi, q, p.se);
                }
                for (auto p: del[i]) {
                        B.upd(p.fi, p.se);
                        upd(1, 0, q, p.fi, q, p.se);
                }
                for (auto p: qu[i]) {
                        long long all = A.get(p.fi);
                        long long cur = B.get(p.fi) - get(1, 0, q, 0, p.fi);

                        p.se += all - cur;

                        if (p.se <= all) {
                                res[p.fi] = c[A.get_f(p.se)];
                        } else {
                                res[p.fi] = 0;
                        }
                }
        }

        for (int i = 1; i <= q; i++) {
                if (res[i] != -1) {
                        cout << res[i] << "\n";
                }
        }
}

Compilation message

foodcourt.cpp: In member function 'void fenwick::upd(int, long long int)':
foodcourt.cpp:16:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |                 while(x < t.size()) {
      |                       ~~^~~~~~~~~~
foodcourt.cpp: In member function 'int fenwick::get_f(long long int)':
foodcourt.cpp:34:44: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |                         if (res + (1 << i) >= t.size()) {
      |                             ~~~~~~~~~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 21972 KB Output is correct
2 Correct 12 ms 22100 KB Output is correct
3 Correct 13 ms 22064 KB Output is correct
4 Correct 12 ms 22100 KB Output is correct
5 Correct 11 ms 22156 KB Output is correct
6 Correct 12 ms 22100 KB Output is correct
7 Correct 12 ms 22108 KB Output is correct
8 Correct 12 ms 22060 KB Output is correct
9 Correct 12 ms 22064 KB Output is correct
10 Correct 12 ms 22100 KB Output is correct
11 Correct 13 ms 22160 KB Output is correct
12 Correct 12 ms 22100 KB Output is correct
13 Correct 11 ms 22064 KB Output is correct
14 Correct 12 ms 22100 KB Output is correct
15 Correct 11 ms 22028 KB Output is correct
16 Correct 12 ms 22060 KB Output is correct
17 Correct 12 ms 22064 KB Output is correct
18 Correct 12 ms 22068 KB Output is correct
19 Correct 12 ms 22100 KB Output is correct
20 Correct 12 ms 22132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 21972 KB Output is correct
2 Correct 12 ms 22100 KB Output is correct
3 Correct 13 ms 22064 KB Output is correct
4 Correct 12 ms 22100 KB Output is correct
5 Correct 11 ms 22156 KB Output is correct
6 Correct 12 ms 22100 KB Output is correct
7 Correct 12 ms 22108 KB Output is correct
8 Correct 12 ms 22060 KB Output is correct
9 Correct 12 ms 22064 KB Output is correct
10 Correct 12 ms 22100 KB Output is correct
11 Correct 13 ms 22160 KB Output is correct
12 Correct 12 ms 22100 KB Output is correct
13 Correct 11 ms 22064 KB Output is correct
14 Correct 12 ms 22100 KB Output is correct
15 Correct 11 ms 22028 KB Output is correct
16 Correct 12 ms 22060 KB Output is correct
17 Correct 12 ms 22064 KB Output is correct
18 Correct 12 ms 22068 KB Output is correct
19 Correct 12 ms 22100 KB Output is correct
20 Correct 12 ms 22132 KB Output is correct
21 Incorrect 12 ms 22100 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 29160 KB Output is correct
2 Correct 64 ms 29324 KB Output is correct
3 Correct 62 ms 29208 KB Output is correct
4 Correct 64 ms 29176 KB Output is correct
5 Correct 65 ms 29388 KB Output is correct
6 Correct 66 ms 29388 KB Output is correct
7 Correct 38 ms 27492 KB Output is correct
8 Correct 38 ms 27616 KB Output is correct
9 Correct 62 ms 29084 KB Output is correct
10 Correct 66 ms 29380 KB Output is correct
11 Correct 64 ms 29260 KB Output is correct
12 Correct 66 ms 29328 KB Output is correct
13 Correct 58 ms 28424 KB Output is correct
14 Correct 68 ms 29204 KB Output is correct
15 Correct 64 ms 29200 KB Output is correct
16 Correct 67 ms 29400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 316 ms 49992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 21972 KB Output is correct
2 Correct 12 ms 22100 KB Output is correct
3 Correct 13 ms 22064 KB Output is correct
4 Correct 12 ms 22100 KB Output is correct
5 Correct 11 ms 22156 KB Output is correct
6 Correct 12 ms 22100 KB Output is correct
7 Correct 12 ms 22108 KB Output is correct
8 Correct 12 ms 22060 KB Output is correct
9 Correct 12 ms 22064 KB Output is correct
10 Correct 12 ms 22100 KB Output is correct
11 Correct 13 ms 22160 KB Output is correct
12 Correct 12 ms 22100 KB Output is correct
13 Correct 11 ms 22064 KB Output is correct
14 Correct 12 ms 22100 KB Output is correct
15 Correct 11 ms 22028 KB Output is correct
16 Correct 12 ms 22060 KB Output is correct
17 Correct 12 ms 22064 KB Output is correct
18 Correct 12 ms 22068 KB Output is correct
19 Correct 12 ms 22100 KB Output is correct
20 Correct 12 ms 22132 KB Output is correct
21 Correct 63 ms 29160 KB Output is correct
22 Correct 64 ms 29324 KB Output is correct
23 Correct 62 ms 29208 KB Output is correct
24 Correct 64 ms 29176 KB Output is correct
25 Correct 65 ms 29388 KB Output is correct
26 Correct 66 ms 29388 KB Output is correct
27 Correct 38 ms 27492 KB Output is correct
28 Correct 38 ms 27616 KB Output is correct
29 Correct 62 ms 29084 KB Output is correct
30 Correct 66 ms 29380 KB Output is correct
31 Correct 64 ms 29260 KB Output is correct
32 Correct 66 ms 29328 KB Output is correct
33 Correct 58 ms 28424 KB Output is correct
34 Correct 68 ms 29204 KB Output is correct
35 Correct 64 ms 29200 KB Output is correct
36 Correct 67 ms 29400 KB Output is correct
37 Correct 60 ms 28508 KB Output is correct
38 Correct 56 ms 28220 KB Output is correct
39 Correct 34 ms 27076 KB Output is correct
40 Correct 38 ms 27384 KB Output is correct
41 Correct 65 ms 29008 KB Output is correct
42 Correct 70 ms 29180 KB Output is correct
43 Correct 67 ms 29256 KB Output is correct
44 Correct 68 ms 29104 KB Output is correct
45 Correct 66 ms 29292 KB Output is correct
46 Correct 69 ms 29224 KB Output is correct
47 Correct 43 ms 27972 KB Output is correct
48 Correct 57 ms 28916 KB Output is correct
49 Correct 49 ms 27708 KB Output is correct
50 Correct 59 ms 28500 KB Output is correct
51 Correct 68 ms 29248 KB Output is correct
52 Correct 67 ms 29332 KB Output is correct
53 Correct 53 ms 28176 KB Output is correct
54 Correct 66 ms 29372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 58 ms 28748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 21972 KB Output is correct
2 Correct 12 ms 22100 KB Output is correct
3 Correct 13 ms 22064 KB Output is correct
4 Correct 12 ms 22100 KB Output is correct
5 Correct 11 ms 22156 KB Output is correct
6 Correct 12 ms 22100 KB Output is correct
7 Correct 12 ms 22108 KB Output is correct
8 Correct 12 ms 22060 KB Output is correct
9 Correct 12 ms 22064 KB Output is correct
10 Correct 12 ms 22100 KB Output is correct
11 Correct 13 ms 22160 KB Output is correct
12 Correct 12 ms 22100 KB Output is correct
13 Correct 11 ms 22064 KB Output is correct
14 Correct 12 ms 22100 KB Output is correct
15 Correct 11 ms 22028 KB Output is correct
16 Correct 12 ms 22060 KB Output is correct
17 Correct 12 ms 22064 KB Output is correct
18 Correct 12 ms 22068 KB Output is correct
19 Correct 12 ms 22100 KB Output is correct
20 Correct 12 ms 22132 KB Output is correct
21 Incorrect 12 ms 22100 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 21972 KB Output is correct
2 Correct 12 ms 22100 KB Output is correct
3 Correct 13 ms 22064 KB Output is correct
4 Correct 12 ms 22100 KB Output is correct
5 Correct 11 ms 22156 KB Output is correct
6 Correct 12 ms 22100 KB Output is correct
7 Correct 12 ms 22108 KB Output is correct
8 Correct 12 ms 22060 KB Output is correct
9 Correct 12 ms 22064 KB Output is correct
10 Correct 12 ms 22100 KB Output is correct
11 Correct 13 ms 22160 KB Output is correct
12 Correct 12 ms 22100 KB Output is correct
13 Correct 11 ms 22064 KB Output is correct
14 Correct 12 ms 22100 KB Output is correct
15 Correct 11 ms 22028 KB Output is correct
16 Correct 12 ms 22060 KB Output is correct
17 Correct 12 ms 22064 KB Output is correct
18 Correct 12 ms 22068 KB Output is correct
19 Correct 12 ms 22100 KB Output is correct
20 Correct 12 ms 22132 KB Output is correct
21 Incorrect 12 ms 22100 KB Output isn't correct
22 Halted 0 ms 0 KB -