답안 #973675

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973675 2024-05-02T09:29:56 Z RaresFelix 푸드 코트 (JOI21_foodcourt) C++17
68 / 100
1000 ms 25912 KB
#include <bits/stdc++.h>

using namespace std;

#define int ll
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<ll, ll>;

struct ura1 {
    int n;
    vll V;
    ura1(int N) : n(N), V(N, 0) {}
    void update(int p, int v) {
        ///update pe pozitie
        V[p] = v;
    }

    int query(int p) {
        if(p == -1) return 0;
        /// va returna suma maxima pt (i...p)
        int re = V[p], s = V[p];
        for(int i = p - 1; i >= 0; --i) {
            s += V[i];
            re = max(re, s);
        }
        return re;
    }
};

struct ura2 {
    ll n, sumtot = 0;
    vll V;
    ura2(int N) : n(N), V(N) {}
    void update(int p, int v) {
        ///update pe pozitie
        sumtot -= V[p];
        V[p] = v;
        sumtot += V[p];
    }
    int sum(int p) {
        int re = 0;
        for(int i = 0; i <= p; ++i)
            re += V[i];
        return re;
    }
    int query(int nr) {
        /// va returna pozitia celul a al nr-lea element
        ll s = 0;
        for(int i = 0; i < n; ++i) {
            s += V[i];
            if(s >= nr) return i;
        }
        assert(0);
    }
};

signed main() {
    int n, m, q;
    cin >> n >> m >> q;
    vi V1, V2, C2;
    vector<ii> UpV1, UpV2; /// toggle-uri pe timp
    struct query {
        int poz, id, ultV1, ultV2;
    };
    vector<vector<query> > Q(n);
    int nr3 = 0;
    for (int i = 0; i < q; ++i) {
        int tip;
        cin >> tip;
        if (tip == 1) {
            int l, r, c, k;
            cin >> l >> r >> c >> k;
            --l; --r;
            UpV1.push_back({l, V1.size()});
            UpV1.push_back({r + 1, V1.size()});
            UpV2.push_back({l, V2.size()});
            UpV2.push_back({r + 1, V2.size()});

            V1.push_back(k);
            V2.push_back(k);
            C2.push_back(c);
        } else if (tip == 2) {
            int l, r, k;
            cin >> l >> r >> k; 
            --l; --r;
            UpV1.push_back({l, V1.size()});
            UpV1.push_back({r + 1, V1.size()});
            V1.push_back(-k);
        } else {
            int a, b;
            cin >> a >> b;
            --a;
            Q[a].push_back({b, nr3, int(V1.size()) - 1, int(V2.size()) - 1});
            ++nr3;
        }
    }
    sort(UpV1.begin(), UpV1.end());
    sort(UpV2.begin(), UpV2.end());

    int p1 = 0, p2 = 0;
    vi Re(nr3);

    ura1 Sol1(V1.size());
    vi on1(V1.size(), 0);
    ura2 Sol2(V2.size());
    vi on2(V2.size(), 0);

    for(int i = 0; i < n; ++i) {
        while(p1 < UpV1.size() && UpV1[p1].first <= i) {
            //toggle it
            int v = UpV1[p1].second;
            if(!on1[v]) Sol1.update(v, V1[v]);
            else Sol1.update(v, 0);
            on1[v] ^= 1;
            ++p1;
        }

        while(p2 < UpV2.size() && UpV2[p2].first <= i) {
            //toggle it
            int v = UpV2[p2].second;
            if(!on2[v]) Sol2.update(v, V2[v]);
            else Sol2.update(v, 0);
            on2[v] ^= 1;
            ++p2;
        }

        for(auto q : Q[i]) {
            ll nrsuf = Sol1.query(q.ultV1), nrtot = Sol2.sum(q.ultV2);
            ll b = q.poz + nrtot - nrsuf;
            if(b > nrtot) {
                Re[q.id] = 0;
            } else {
                Re[q.id] = C2[Sol2.query(b)];
            }
        }
    }
    for(auto it : Re) cout << it << "\n";
    return 0;
}

Compilation message

foodcourt.cpp: In function 'int main()':
foodcourt.cpp:111:18: 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]
  111 |         while(p1 < UpV1.size() && UpV1[p1].first <= i) {
      |               ~~~^~~~~~~~~~~~~
foodcourt.cpp:120:18: 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]
  120 |         while(p2 < UpV2.size() && UpV2[p2].first <= i) {
      |               ~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 3 ms 600 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 3 ms 856 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 4 ms 600 KB Output is correct
9 Correct 3 ms 600 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 3 ms 600 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 3 ms 600 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 3 ms 856 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 4 ms 600 KB Output is correct
9 Correct 3 ms 600 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 3 ms 600 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
21 Correct 3 ms 600 KB Output is correct
22 Correct 3 ms 600 KB Output is correct
23 Correct 4 ms 600 KB Output is correct
24 Correct 3 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 600 KB Output is correct
27 Correct 4 ms 860 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 3 ms 572 KB Output is correct
30 Correct 4 ms 608 KB Output is correct
31 Correct 3 ms 700 KB Output is correct
32 Correct 3 ms 600 KB Output is correct
33 Correct 3 ms 604 KB Output is correct
34 Correct 3 ms 604 KB Output is correct
35 Correct 3 ms 860 KB Output is correct
36 Correct 4 ms 604 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 3 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 627 ms 7100 KB Output is correct
2 Correct 554 ms 8912 KB Output is correct
3 Correct 621 ms 8416 KB Output is correct
4 Correct 612 ms 8300 KB Output is correct
5 Correct 559 ms 8828 KB Output is correct
6 Correct 569 ms 8828 KB Output is correct
7 Correct 570 ms 5916 KB Output is correct
8 Correct 596 ms 6100 KB Output is correct
9 Correct 535 ms 8420 KB Output is correct
10 Correct 537 ms 8424 KB Output is correct
11 Correct 526 ms 8456 KB Output is correct
12 Correct 538 ms 8596 KB Output is correct
13 Correct 605 ms 7608 KB Output is correct
14 Correct 738 ms 8764 KB Output is correct
15 Correct 455 ms 9836 KB Output is correct
16 Correct 456 ms 10564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1033 ms 25912 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 3 ms 600 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 3 ms 856 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 4 ms 600 KB Output is correct
9 Correct 3 ms 600 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 3 ms 600 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
21 Correct 627 ms 7100 KB Output is correct
22 Correct 554 ms 8912 KB Output is correct
23 Correct 621 ms 8416 KB Output is correct
24 Correct 612 ms 8300 KB Output is correct
25 Correct 559 ms 8828 KB Output is correct
26 Correct 569 ms 8828 KB Output is correct
27 Correct 570 ms 5916 KB Output is correct
28 Correct 596 ms 6100 KB Output is correct
29 Correct 535 ms 8420 KB Output is correct
30 Correct 537 ms 8424 KB Output is correct
31 Correct 526 ms 8456 KB Output is correct
32 Correct 538 ms 8596 KB Output is correct
33 Correct 605 ms 7608 KB Output is correct
34 Correct 738 ms 8764 KB Output is correct
35 Correct 455 ms 9836 KB Output is correct
36 Correct 456 ms 10564 KB Output is correct
37 Correct 570 ms 7620 KB Output is correct
38 Correct 400 ms 7184 KB Output is correct
39 Correct 393 ms 5300 KB Output is correct
40 Correct 514 ms 5788 KB Output is correct
41 Correct 655 ms 8208 KB Output is correct
42 Correct 638 ms 8172 KB Output is correct
43 Correct 595 ms 8260 KB Output is correct
44 Correct 637 ms 8320 KB Output is correct
45 Correct 624 ms 8148 KB Output is correct
46 Correct 607 ms 8380 KB Output is correct
47 Correct 687 ms 8012 KB Output is correct
48 Correct 704 ms 8096 KB Output is correct
49 Correct 278 ms 6072 KB Output is correct
50 Correct 402 ms 7588 KB Output is correct
51 Correct 548 ms 8324 KB Output is correct
52 Correct 543 ms 8404 KB Output is correct
53 Correct 286 ms 8504 KB Output is correct
54 Correct 449 ms 10296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 755 ms 6972 KB Output is correct
2 Correct 924 ms 8772 KB Output is correct
3 Correct 940 ms 9272 KB Output is correct
4 Correct 482 ms 7016 KB Output is correct
5 Correct 704 ms 7992 KB Output is correct
6 Correct 947 ms 9104 KB Output is correct
7 Correct 738 ms 6396 KB Output is correct
8 Correct 656 ms 5820 KB Output is correct
9 Correct 935 ms 9020 KB Output is correct
10 Correct 484 ms 6772 KB Output is correct
11 Correct 972 ms 9080 KB Output is correct
12 Correct 957 ms 9072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 3 ms 600 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 3 ms 856 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 4 ms 600 KB Output is correct
9 Correct 3 ms 600 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 3 ms 600 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
21 Correct 3 ms 600 KB Output is correct
22 Correct 3 ms 600 KB Output is correct
23 Correct 4 ms 600 KB Output is correct
24 Correct 3 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 600 KB Output is correct
27 Correct 4 ms 860 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 3 ms 572 KB Output is correct
30 Correct 4 ms 608 KB Output is correct
31 Correct 3 ms 700 KB Output is correct
32 Correct 3 ms 600 KB Output is correct
33 Correct 3 ms 604 KB Output is correct
34 Correct 3 ms 604 KB Output is correct
35 Correct 3 ms 860 KB Output is correct
36 Correct 4 ms 604 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 3 ms 604 KB Output is correct
39 Correct 627 ms 7100 KB Output is correct
40 Correct 554 ms 8912 KB Output is correct
41 Correct 621 ms 8416 KB Output is correct
42 Correct 612 ms 8300 KB Output is correct
43 Correct 559 ms 8828 KB Output is correct
44 Correct 569 ms 8828 KB Output is correct
45 Correct 570 ms 5916 KB Output is correct
46 Correct 596 ms 6100 KB Output is correct
47 Correct 535 ms 8420 KB Output is correct
48 Correct 537 ms 8424 KB Output is correct
49 Correct 526 ms 8456 KB Output is correct
50 Correct 538 ms 8596 KB Output is correct
51 Correct 605 ms 7608 KB Output is correct
52 Correct 738 ms 8764 KB Output is correct
53 Correct 455 ms 9836 KB Output is correct
54 Correct 456 ms 10564 KB Output is correct
55 Correct 570 ms 7620 KB Output is correct
56 Correct 400 ms 7184 KB Output is correct
57 Correct 393 ms 5300 KB Output is correct
58 Correct 514 ms 5788 KB Output is correct
59 Correct 655 ms 8208 KB Output is correct
60 Correct 638 ms 8172 KB Output is correct
61 Correct 595 ms 8260 KB Output is correct
62 Correct 637 ms 8320 KB Output is correct
63 Correct 624 ms 8148 KB Output is correct
64 Correct 607 ms 8380 KB Output is correct
65 Correct 687 ms 8012 KB Output is correct
66 Correct 704 ms 8096 KB Output is correct
67 Correct 278 ms 6072 KB Output is correct
68 Correct 402 ms 7588 KB Output is correct
69 Correct 548 ms 8324 KB Output is correct
70 Correct 543 ms 8404 KB Output is correct
71 Correct 286 ms 8504 KB Output is correct
72 Correct 449 ms 10296 KB Output is correct
73 Correct 755 ms 6972 KB Output is correct
74 Correct 924 ms 8772 KB Output is correct
75 Correct 940 ms 9272 KB Output is correct
76 Correct 482 ms 7016 KB Output is correct
77 Correct 704 ms 7992 KB Output is correct
78 Correct 947 ms 9104 KB Output is correct
79 Correct 738 ms 6396 KB Output is correct
80 Correct 656 ms 5820 KB Output is correct
81 Correct 935 ms 9020 KB Output is correct
82 Correct 484 ms 6772 KB Output is correct
83 Correct 972 ms 9080 KB Output is correct
84 Correct 957 ms 9072 KB Output is correct
85 Correct 609 ms 7556 KB Output is correct
86 Correct 732 ms 8756 KB Output is correct
87 Correct 515 ms 8360 KB Output is correct
88 Correct 678 ms 9232 KB Output is correct
89 Correct 331 ms 6128 KB Output is correct
90 Correct 661 ms 8732 KB Output is correct
91 Correct 442 ms 7072 KB Output is correct
92 Correct 404 ms 6936 KB Output is correct
93 Correct 614 ms 8828 KB Output is correct
94 Correct 644 ms 8716 KB Output is correct
95 Correct 628 ms 8464 KB Output is correct
96 Correct 615 ms 8992 KB Output is correct
97 Correct 603 ms 8924 KB Output is correct
98 Correct 467 ms 7496 KB Output is correct
99 Correct 716 ms 8376 KB Output is correct
100 Correct 520 ms 7300 KB Output is correct
101 Correct 705 ms 8564 KB Output is correct
102 Correct 815 ms 10348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 3 ms 600 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 3 ms 856 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 4 ms 600 KB Output is correct
9 Correct 3 ms 600 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 3 ms 600 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
21 Correct 3 ms 600 KB Output is correct
22 Correct 3 ms 600 KB Output is correct
23 Correct 4 ms 600 KB Output is correct
24 Correct 3 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 600 KB Output is correct
27 Correct 4 ms 860 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 3 ms 572 KB Output is correct
30 Correct 4 ms 608 KB Output is correct
31 Correct 3 ms 700 KB Output is correct
32 Correct 3 ms 600 KB Output is correct
33 Correct 3 ms 604 KB Output is correct
34 Correct 3 ms 604 KB Output is correct
35 Correct 3 ms 860 KB Output is correct
36 Correct 4 ms 604 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 3 ms 604 KB Output is correct
39 Correct 627 ms 7100 KB Output is correct
40 Correct 554 ms 8912 KB Output is correct
41 Correct 621 ms 8416 KB Output is correct
42 Correct 612 ms 8300 KB Output is correct
43 Correct 559 ms 8828 KB Output is correct
44 Correct 569 ms 8828 KB Output is correct
45 Correct 570 ms 5916 KB Output is correct
46 Correct 596 ms 6100 KB Output is correct
47 Correct 535 ms 8420 KB Output is correct
48 Correct 537 ms 8424 KB Output is correct
49 Correct 526 ms 8456 KB Output is correct
50 Correct 538 ms 8596 KB Output is correct
51 Correct 605 ms 7608 KB Output is correct
52 Correct 738 ms 8764 KB Output is correct
53 Correct 455 ms 9836 KB Output is correct
54 Correct 456 ms 10564 KB Output is correct
55 Execution timed out 1033 ms 25912 KB Time limit exceeded
56 Halted 0 ms 0 KB -