답안 #670910

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
670910 2022-12-11T10:12:16 Z ParsaS 푸드 코트 (JOI21_foodcourt) C++17
14 / 100
1000 ms 524288 KB
// In the name of God
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
#define int ll
const int N = 25e4 + 5;
int n, m, q;
vector<pair<int, int> > A[N], B[N];
vector<pair<int, int> > vec[N];
int INX[N];
vector<pair<pair<int, int>, int> > Q[N];
int col[N], ans[N];
int seg[N << 2], lz[N << 2], fen[N];

void updFen(int inx, int val) {
    for (inx; inx <= m; inx += inx & -inx)
        fen[inx] += val;
}
int queryFen(int inx) {
    int res = 0;
    for (inx; inx > 0; inx -= inx & -inx)
        res += fen[inx];
    return res;
}

void shift(int v, int tl, int tr) {
    seg[v] += lz[v];
    if (tl < tr) {
        lz[v << 1] += lz[v];
        lz[v << 1 | 1] += lz[v];
    }
    lz[v] = 0;
}

void upd(int l, int r, int val, int v = 1, int tl = 0, int tr = q) {
    shift(v, tl, tr);
    if (tl > r || tr < l)
        return;
    if (tl >= l && tr <= r) {
        lz[v] += val;
        shift(v, tl, tr);
        return;
    }
    int mid = (tl + tr) >> 1;
    upd(l, r, val, v << 1, tl, mid);
    upd(l, r, val, v << 1 | 1, mid + 1, tr);
    seg[v] = min(seg[v << 1], seg[v << 1 | 1]);
}
int query(int l, int r, int v = 1, int tl = 0, int tr = q) {
    shift(v, tl, tr);
    if (l > tr || r < tl)
        return 1e9 + 10;
    if (tl >= l && tr <= r)
        return seg[v];
    int mid = (tl + tr) >> 1;
    return min(query(l, r, v << 1, tl, mid), query(l, r, v << 1 | 1, mid + 1, tr));
}

void solve() {
    cin >> n >> m >> q;
    int inx = 0;
    for (int i = 0; i < q; i++) {
        int t; cin >> t;
        if (t == 1) {
            int l, r, c, k; cin >> l >> r >> c >> k;

            for (int j = l; j <= r; j++) {
                vec[j].pb(mp(k, c));
            }

        }
        else if (t == 2) {
            int l, r, k; cin >> l >> r >> k;
            int kp = k;
            for (int j = l; j <= r; j++) {
                k = kp;
                while (INX[j] < vec[j].size() && k) {
                    int tmp = min(k, vec[j][INX[j]].fi);
                    k -= tmp;
                    vec[j][INX[j]].fi -= tmp;
                    if (!vec[j][INX[j]].fi)
                        INX[j]++;
                }
            }

        }
        else {
            int a, b; cin >> a >> b;
			if (n <= 2000 && q <= 2000) {
				int sum = 0, j;
				for (j = 0; j < vec[a].size() && sum < b; j++) {
					sum += vec[a][j].fi;
				}
				if (sum >= b)
					cout << vec[a][--j].se << '\n';
				else
					cout << 0 << '\n';
			}
			else {
				if (vec[a].size() - INX[a] < b) {
					cout << 0 << '\n';
				}
				else {
					cout << vec[a][INX[a] + b - 1].se << '\n';
				}
			}
            continue;
            int sum = 0, j;
            for (j = 0; j < vec[a].size() && sum < b; j++) {
                sum += vec[a][j].fi;
            }
            if (sum >= b)
                cout << vec[a][--j].se << '\n';
            else
                cout << 0 << '\n';
            ans[i] = 0;
            Q[a].pb(mp(mp(inx, i), b));
        }
    }

    /*for (int i = 1; i <= n; i++) {
        for (auto [l, k] : A[i]) {
            upd(l, q, k);
        }
        for (auto tmp : Q[i]) {
            int j = tmp.fi.fi, qi = tmp.fi.se, b = tmp.se;
            int l = -1, r = j + 1;
            while (r - l > 1) {
                int mid = (l + r) >> 1;
                if (query(mid, j) < b)
                    l = mid;
                else
                    r = mid;
            }
            if (query(j + 1, j + 1) >= b) {
                ans[qi] = col[l];
            }
        }
    }
    for (int i = 0; i < q; i++)
        if (ans[i] != -1)
            cout << ans[i] << '\n';*/
}

int32_t main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    solve();
    return 0;
}

Compilation message

foodcourt.cpp: In function 'void updFen(ll, ll)':
foodcourt.cpp:20:10: warning: statement has no effect [-Wunused-value]
   20 |     for (inx; inx <= m; inx += inx & -inx)
      |          ^~~
foodcourt.cpp: In function 'll queryFen(ll)':
foodcourt.cpp:25:10: warning: statement has no effect [-Wunused-value]
   25 |     for (inx; inx > 0; inx -= inx & -inx)
      |          ^~~
foodcourt.cpp: In function 'void solve()':
foodcourt.cpp:81:31: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |                 while (INX[j] < vec[j].size() && k) {
      |                        ~~~~~~~^~~~~~~~~~~~~~~
foodcourt.cpp:95:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |     for (j = 0; j < vec[a].size() && sum < b; j++) {
      |                 ~~^~~~~~~~~~~~~~~
foodcourt.cpp:104:32: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'll' {aka 'long long int'} [-Wsign-compare]
  104 |     if (vec[a].size() - INX[a] < b) {
      |         ~~~~~~~~~~~~~~~~~~~~~~~^~~
foodcourt.cpp:113:27: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |             for (j = 0; j < vec[a].size() && sum < b; j++) {
      |                         ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 29524 KB Output is correct
2 Correct 27 ms 35300 KB Output is correct
3 Correct 28 ms 37076 KB Output is correct
4 Correct 39 ms 47800 KB Output is correct
5 Correct 14 ms 23952 KB Output is correct
6 Correct 14 ms 23764 KB Output is correct
7 Correct 38 ms 41292 KB Output is correct
8 Correct 36 ms 40652 KB Output is correct
9 Correct 34 ms 40724 KB Output is correct
10 Correct 36 ms 41752 KB Output is correct
11 Correct 37 ms 42240 KB Output is correct
12 Correct 35 ms 41300 KB Output is correct
13 Correct 45 ms 49608 KB Output is correct
14 Correct 55 ms 54728 KB Output is correct
15 Correct 42 ms 39312 KB Output is correct
16 Correct 59 ms 54452 KB Output is correct
17 Correct 27 ms 32780 KB Output is correct
18 Correct 31 ms 37528 KB Output is correct
19 Correct 14 ms 24020 KB Output is correct
20 Correct 14 ms 24088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 29524 KB Output is correct
2 Correct 27 ms 35300 KB Output is correct
3 Correct 28 ms 37076 KB Output is correct
4 Correct 39 ms 47800 KB Output is correct
5 Correct 14 ms 23952 KB Output is correct
6 Correct 14 ms 23764 KB Output is correct
7 Correct 38 ms 41292 KB Output is correct
8 Correct 36 ms 40652 KB Output is correct
9 Correct 34 ms 40724 KB Output is correct
10 Correct 36 ms 41752 KB Output is correct
11 Correct 37 ms 42240 KB Output is correct
12 Correct 35 ms 41300 KB Output is correct
13 Correct 45 ms 49608 KB Output is correct
14 Correct 55 ms 54728 KB Output is correct
15 Correct 42 ms 39312 KB Output is correct
16 Correct 59 ms 54452 KB Output is correct
17 Correct 27 ms 32780 KB Output is correct
18 Correct 31 ms 37528 KB Output is correct
19 Correct 14 ms 24020 KB Output is correct
20 Correct 14 ms 24088 KB Output is correct
21 Correct 27 ms 34232 KB Output is correct
22 Correct 29 ms 35284 KB Output is correct
23 Correct 31 ms 39420 KB Output is correct
24 Correct 41 ms 47808 KB Output is correct
25 Correct 13 ms 23764 KB Output is correct
26 Correct 13 ms 23764 KB Output is correct
27 Correct 39 ms 38588 KB Output is correct
28 Correct 51 ms 41832 KB Output is correct
29 Correct 39 ms 41504 KB Output is correct
30 Correct 45 ms 41100 KB Output is correct
31 Correct 38 ms 38152 KB Output is correct
32 Correct 36 ms 37908 KB Output is correct
33 Correct 46 ms 48100 KB Output is correct
34 Correct 59 ms 54548 KB Output is correct
35 Correct 44 ms 46560 KB Output is correct
36 Correct 60 ms 54152 KB Output is correct
37 Correct 13 ms 24020 KB Output is correct
38 Correct 14 ms 24148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 410 ms 28856 KB Output is correct
2 Correct 361 ms 30572 KB Output is correct
3 Correct 455 ms 31556 KB Output is correct
4 Correct 446 ms 31516 KB Output is correct
5 Correct 396 ms 34604 KB Output is correct
6 Correct 381 ms 34552 KB Output is correct
7 Correct 28 ms 25208 KB Output is correct
8 Correct 29 ms 25464 KB Output is correct
9 Correct 699 ms 29324 KB Output is correct
10 Correct 672 ms 29288 KB Output is correct
11 Correct 657 ms 29368 KB Output is correct
12 Correct 659 ms 29344 KB Output is correct
13 Correct 153 ms 30616 KB Output is correct
14 Correct 223 ms 31716 KB Output is correct
15 Correct 80 ms 34276 KB Output is correct
16 Correct 84 ms 34400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1091 ms 386172 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 29524 KB Output is correct
2 Correct 27 ms 35300 KB Output is correct
3 Correct 28 ms 37076 KB Output is correct
4 Correct 39 ms 47800 KB Output is correct
5 Correct 14 ms 23952 KB Output is correct
6 Correct 14 ms 23764 KB Output is correct
7 Correct 38 ms 41292 KB Output is correct
8 Correct 36 ms 40652 KB Output is correct
9 Correct 34 ms 40724 KB Output is correct
10 Correct 36 ms 41752 KB Output is correct
11 Correct 37 ms 42240 KB Output is correct
12 Correct 35 ms 41300 KB Output is correct
13 Correct 45 ms 49608 KB Output is correct
14 Correct 55 ms 54728 KB Output is correct
15 Correct 42 ms 39312 KB Output is correct
16 Correct 59 ms 54452 KB Output is correct
17 Correct 27 ms 32780 KB Output is correct
18 Correct 31 ms 37528 KB Output is correct
19 Correct 14 ms 24020 KB Output is correct
20 Correct 14 ms 24088 KB Output is correct
21 Correct 410 ms 28856 KB Output is correct
22 Correct 361 ms 30572 KB Output is correct
23 Correct 455 ms 31556 KB Output is correct
24 Correct 446 ms 31516 KB Output is correct
25 Correct 396 ms 34604 KB Output is correct
26 Correct 381 ms 34552 KB Output is correct
27 Correct 28 ms 25208 KB Output is correct
28 Correct 29 ms 25464 KB Output is correct
29 Correct 699 ms 29324 KB Output is correct
30 Correct 672 ms 29288 KB Output is correct
31 Correct 657 ms 29368 KB Output is correct
32 Correct 659 ms 29344 KB Output is correct
33 Correct 153 ms 30616 KB Output is correct
34 Correct 223 ms 31716 KB Output is correct
35 Correct 80 ms 34276 KB Output is correct
36 Correct 84 ms 34400 KB Output is correct
37 Execution timed out 1099 ms 480732 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 676 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 29524 KB Output is correct
2 Correct 27 ms 35300 KB Output is correct
3 Correct 28 ms 37076 KB Output is correct
4 Correct 39 ms 47800 KB Output is correct
5 Correct 14 ms 23952 KB Output is correct
6 Correct 14 ms 23764 KB Output is correct
7 Correct 38 ms 41292 KB Output is correct
8 Correct 36 ms 40652 KB Output is correct
9 Correct 34 ms 40724 KB Output is correct
10 Correct 36 ms 41752 KB Output is correct
11 Correct 37 ms 42240 KB Output is correct
12 Correct 35 ms 41300 KB Output is correct
13 Correct 45 ms 49608 KB Output is correct
14 Correct 55 ms 54728 KB Output is correct
15 Correct 42 ms 39312 KB Output is correct
16 Correct 59 ms 54452 KB Output is correct
17 Correct 27 ms 32780 KB Output is correct
18 Correct 31 ms 37528 KB Output is correct
19 Correct 14 ms 24020 KB Output is correct
20 Correct 14 ms 24088 KB Output is correct
21 Correct 27 ms 34232 KB Output is correct
22 Correct 29 ms 35284 KB Output is correct
23 Correct 31 ms 39420 KB Output is correct
24 Correct 41 ms 47808 KB Output is correct
25 Correct 13 ms 23764 KB Output is correct
26 Correct 13 ms 23764 KB Output is correct
27 Correct 39 ms 38588 KB Output is correct
28 Correct 51 ms 41832 KB Output is correct
29 Correct 39 ms 41504 KB Output is correct
30 Correct 45 ms 41100 KB Output is correct
31 Correct 38 ms 38152 KB Output is correct
32 Correct 36 ms 37908 KB Output is correct
33 Correct 46 ms 48100 KB Output is correct
34 Correct 59 ms 54548 KB Output is correct
35 Correct 44 ms 46560 KB Output is correct
36 Correct 60 ms 54152 KB Output is correct
37 Correct 13 ms 24020 KB Output is correct
38 Correct 14 ms 24148 KB Output is correct
39 Correct 410 ms 28856 KB Output is correct
40 Correct 361 ms 30572 KB Output is correct
41 Correct 455 ms 31556 KB Output is correct
42 Correct 446 ms 31516 KB Output is correct
43 Correct 396 ms 34604 KB Output is correct
44 Correct 381 ms 34552 KB Output is correct
45 Correct 28 ms 25208 KB Output is correct
46 Correct 29 ms 25464 KB Output is correct
47 Correct 699 ms 29324 KB Output is correct
48 Correct 672 ms 29288 KB Output is correct
49 Correct 657 ms 29368 KB Output is correct
50 Correct 659 ms 29344 KB Output is correct
51 Correct 153 ms 30616 KB Output is correct
52 Correct 223 ms 31716 KB Output is correct
53 Correct 80 ms 34276 KB Output is correct
54 Correct 84 ms 34400 KB Output is correct
55 Execution timed out 1099 ms 480732 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 29524 KB Output is correct
2 Correct 27 ms 35300 KB Output is correct
3 Correct 28 ms 37076 KB Output is correct
4 Correct 39 ms 47800 KB Output is correct
5 Correct 14 ms 23952 KB Output is correct
6 Correct 14 ms 23764 KB Output is correct
7 Correct 38 ms 41292 KB Output is correct
8 Correct 36 ms 40652 KB Output is correct
9 Correct 34 ms 40724 KB Output is correct
10 Correct 36 ms 41752 KB Output is correct
11 Correct 37 ms 42240 KB Output is correct
12 Correct 35 ms 41300 KB Output is correct
13 Correct 45 ms 49608 KB Output is correct
14 Correct 55 ms 54728 KB Output is correct
15 Correct 42 ms 39312 KB Output is correct
16 Correct 59 ms 54452 KB Output is correct
17 Correct 27 ms 32780 KB Output is correct
18 Correct 31 ms 37528 KB Output is correct
19 Correct 14 ms 24020 KB Output is correct
20 Correct 14 ms 24088 KB Output is correct
21 Correct 27 ms 34232 KB Output is correct
22 Correct 29 ms 35284 KB Output is correct
23 Correct 31 ms 39420 KB Output is correct
24 Correct 41 ms 47808 KB Output is correct
25 Correct 13 ms 23764 KB Output is correct
26 Correct 13 ms 23764 KB Output is correct
27 Correct 39 ms 38588 KB Output is correct
28 Correct 51 ms 41832 KB Output is correct
29 Correct 39 ms 41504 KB Output is correct
30 Correct 45 ms 41100 KB Output is correct
31 Correct 38 ms 38152 KB Output is correct
32 Correct 36 ms 37908 KB Output is correct
33 Correct 46 ms 48100 KB Output is correct
34 Correct 59 ms 54548 KB Output is correct
35 Correct 44 ms 46560 KB Output is correct
36 Correct 60 ms 54152 KB Output is correct
37 Correct 13 ms 24020 KB Output is correct
38 Correct 14 ms 24148 KB Output is correct
39 Correct 410 ms 28856 KB Output is correct
40 Correct 361 ms 30572 KB Output is correct
41 Correct 455 ms 31556 KB Output is correct
42 Correct 446 ms 31516 KB Output is correct
43 Correct 396 ms 34604 KB Output is correct
44 Correct 381 ms 34552 KB Output is correct
45 Correct 28 ms 25208 KB Output is correct
46 Correct 29 ms 25464 KB Output is correct
47 Correct 699 ms 29324 KB Output is correct
48 Correct 672 ms 29288 KB Output is correct
49 Correct 657 ms 29368 KB Output is correct
50 Correct 659 ms 29344 KB Output is correct
51 Correct 153 ms 30616 KB Output is correct
52 Correct 223 ms 31716 KB Output is correct
53 Correct 80 ms 34276 KB Output is correct
54 Correct 84 ms 34400 KB Output is correct
55 Execution timed out 1091 ms 386172 KB Time limit exceeded
56 Halted 0 ms 0 KB -