답안 #973693

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973693 2024-05-02T09:41:22 Z RaresFelix 푸드 코트 (JOI21_foodcourt) C++17
68 / 100
1000 ms 27592 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;
    vll S;
    ura2(int N) : n(N), S(4 * N) {}

    void update(int p, int v, int u, int s, int d) {
        if(d < p || p < s) return;
        if(s == d) {
            S[u] = v;
            return;
        }
        update(p, v, u << 1, s, (s + d) >> 1);
        update(p, v, u << 1 | 1, ((s + d) >> 1) + 1, d);
        S[u] = S[u << 1] + S[u << 1 | 1];
    }

    int querys(int l, int r, int u, int s, int d) {
        if(d < l || r < s) {
            return 0;
        }
        if(l <= s && d <= r) return S[u];
        return querys(l, r, u << 1, s, (s + d) >> 1)
            + querys(l, r, u << 1 | 1, ((s + d) >> 1) + 1, d);
    }

    int queryp(int nr, int u, int s, int d) {
        if(s == d) return s;
        if(nr > S[u << 1]) return queryp(nr - S[u << 1], u << 1 | 1, ((s + d) >> 1) + 1, d);
        return queryp(nr, u << 1, s, (s + d) >> 1);
    }

    void update(int p, int v) { ///update pe pozitie
        update(p, v, 1, 0, n - 1);
    }
    int sum(int p) { return querys(0, p, 1, 0, n - 1); }
    int query(int nr) { /// va returna pozitia celul a al nr-lea element
        return queryp(nr, 1, 0, n - 1);
    }
};

signed main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    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:126: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]
  126 |         while(p1 < UpV1.size() && UpV1[p1].first <= i) {
      |               ~~~^~~~~~~~~~~~~
foodcourt.cpp:135: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]
  135 |         while(p2 < UpV2.size() && UpV2[p2].first <= i) {
      |               ~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 856 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 520 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
19 Correct 3 ms 604 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 856 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 520 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
19 Correct 3 ms 604 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 2 ms 600 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 720 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 856 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 3 ms 600 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 480 ms 7500 KB Output is correct
2 Correct 410 ms 8452 KB Output is correct
3 Correct 469 ms 7620 KB Output is correct
4 Correct 477 ms 7644 KB Output is correct
5 Correct 415 ms 8572 KB Output is correct
6 Correct 411 ms 8248 KB Output is correct
7 Correct 401 ms 5556 KB Output is correct
8 Correct 410 ms 6080 KB Output is correct
9 Correct 410 ms 7780 KB Output is correct
10 Correct 402 ms 7796 KB Output is correct
11 Correct 404 ms 7800 KB Output is correct
12 Correct 407 ms 7800 KB Output is correct
13 Correct 393 ms 7304 KB Output is correct
14 Correct 478 ms 8628 KB Output is correct
15 Correct 303 ms 9724 KB Output is correct
16 Correct 313 ms 10780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1037 ms 27592 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 856 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 520 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
19 Correct 3 ms 604 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 480 ms 7500 KB Output is correct
22 Correct 410 ms 8452 KB Output is correct
23 Correct 469 ms 7620 KB Output is correct
24 Correct 477 ms 7644 KB Output is correct
25 Correct 415 ms 8572 KB Output is correct
26 Correct 411 ms 8248 KB Output is correct
27 Correct 401 ms 5556 KB Output is correct
28 Correct 410 ms 6080 KB Output is correct
29 Correct 410 ms 7780 KB Output is correct
30 Correct 402 ms 7796 KB Output is correct
31 Correct 404 ms 7800 KB Output is correct
32 Correct 407 ms 7800 KB Output is correct
33 Correct 393 ms 7304 KB Output is correct
34 Correct 478 ms 8628 KB Output is correct
35 Correct 303 ms 9724 KB Output is correct
36 Correct 313 ms 10780 KB Output is correct
37 Correct 391 ms 7116 KB Output is correct
38 Correct 268 ms 6752 KB Output is correct
39 Correct 261 ms 5248 KB Output is correct
40 Correct 347 ms 6056 KB Output is correct
41 Correct 407 ms 7708 KB Output is correct
42 Correct 409 ms 7680 KB Output is correct
43 Correct 405 ms 7800 KB Output is correct
44 Correct 411 ms 7808 KB Output is correct
45 Correct 409 ms 7652 KB Output is correct
46 Correct 414 ms 7908 KB Output is correct
47 Correct 461 ms 7672 KB Output is correct
48 Correct 473 ms 7644 KB Output is correct
49 Correct 187 ms 5824 KB Output is correct
50 Correct 262 ms 7220 KB Output is correct
51 Correct 379 ms 7856 KB Output is correct
52 Correct 375 ms 7944 KB Output is correct
53 Correct 211 ms 8520 KB Output is correct
54 Correct 319 ms 10300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 443 ms 7576 KB Output is correct
2 Correct 537 ms 7936 KB Output is correct
3 Correct 548 ms 8292 KB Output is correct
4 Correct 283 ms 6416 KB Output is correct
5 Correct 405 ms 7372 KB Output is correct
6 Correct 546 ms 8256 KB Output is correct
7 Correct 412 ms 6000 KB Output is correct
8 Correct 365 ms 5408 KB Output is correct
9 Correct 541 ms 8288 KB Output is correct
10 Correct 277 ms 6304 KB Output is correct
11 Correct 539 ms 8252 KB Output is correct
12 Correct 544 ms 8508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 856 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 520 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
19 Correct 3 ms 604 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 2 ms 600 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 720 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 856 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 3 ms 600 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 480 ms 7500 KB Output is correct
40 Correct 410 ms 8452 KB Output is correct
41 Correct 469 ms 7620 KB Output is correct
42 Correct 477 ms 7644 KB Output is correct
43 Correct 415 ms 8572 KB Output is correct
44 Correct 411 ms 8248 KB Output is correct
45 Correct 401 ms 5556 KB Output is correct
46 Correct 410 ms 6080 KB Output is correct
47 Correct 410 ms 7780 KB Output is correct
48 Correct 402 ms 7796 KB Output is correct
49 Correct 404 ms 7800 KB Output is correct
50 Correct 407 ms 7800 KB Output is correct
51 Correct 393 ms 7304 KB Output is correct
52 Correct 478 ms 8628 KB Output is correct
53 Correct 303 ms 9724 KB Output is correct
54 Correct 313 ms 10780 KB Output is correct
55 Correct 391 ms 7116 KB Output is correct
56 Correct 268 ms 6752 KB Output is correct
57 Correct 261 ms 5248 KB Output is correct
58 Correct 347 ms 6056 KB Output is correct
59 Correct 407 ms 7708 KB Output is correct
60 Correct 409 ms 7680 KB Output is correct
61 Correct 405 ms 7800 KB Output is correct
62 Correct 411 ms 7808 KB Output is correct
63 Correct 409 ms 7652 KB Output is correct
64 Correct 414 ms 7908 KB Output is correct
65 Correct 461 ms 7672 KB Output is correct
66 Correct 473 ms 7644 KB Output is correct
67 Correct 187 ms 5824 KB Output is correct
68 Correct 262 ms 7220 KB Output is correct
69 Correct 379 ms 7856 KB Output is correct
70 Correct 375 ms 7944 KB Output is correct
71 Correct 211 ms 8520 KB Output is correct
72 Correct 319 ms 10300 KB Output is correct
73 Correct 443 ms 7576 KB Output is correct
74 Correct 537 ms 7936 KB Output is correct
75 Correct 548 ms 8292 KB Output is correct
76 Correct 283 ms 6416 KB Output is correct
77 Correct 405 ms 7372 KB Output is correct
78 Correct 546 ms 8256 KB Output is correct
79 Correct 412 ms 6000 KB Output is correct
80 Correct 365 ms 5408 KB Output is correct
81 Correct 541 ms 8288 KB Output is correct
82 Correct 277 ms 6304 KB Output is correct
83 Correct 539 ms 8252 KB Output is correct
84 Correct 544 ms 8508 KB Output is correct
85 Correct 402 ms 6636 KB Output is correct
86 Correct 481 ms 7548 KB Output is correct
87 Correct 323 ms 7548 KB Output is correct
88 Correct 416 ms 8456 KB Output is correct
89 Correct 198 ms 5480 KB Output is correct
90 Correct 409 ms 7788 KB Output is correct
91 Correct 287 ms 6300 KB Output is correct
92 Correct 259 ms 6092 KB Output is correct
93 Correct 412 ms 7784 KB Output is correct
94 Correct 408 ms 7612 KB Output is correct
95 Correct 398 ms 7496 KB Output is correct
96 Correct 410 ms 7812 KB Output is correct
97 Correct 405 ms 7924 KB Output is correct
98 Correct 312 ms 6600 KB Output is correct
99 Correct 468 ms 7496 KB Output is correct
100 Correct 346 ms 6716 KB Output is correct
101 Correct 473 ms 7652 KB Output is correct
102 Correct 479 ms 9724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 856 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 520 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
19 Correct 3 ms 604 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 2 ms 600 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 720 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 856 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 3 ms 600 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 480 ms 7500 KB Output is correct
40 Correct 410 ms 8452 KB Output is correct
41 Correct 469 ms 7620 KB Output is correct
42 Correct 477 ms 7644 KB Output is correct
43 Correct 415 ms 8572 KB Output is correct
44 Correct 411 ms 8248 KB Output is correct
45 Correct 401 ms 5556 KB Output is correct
46 Correct 410 ms 6080 KB Output is correct
47 Correct 410 ms 7780 KB Output is correct
48 Correct 402 ms 7796 KB Output is correct
49 Correct 404 ms 7800 KB Output is correct
50 Correct 407 ms 7800 KB Output is correct
51 Correct 393 ms 7304 KB Output is correct
52 Correct 478 ms 8628 KB Output is correct
53 Correct 303 ms 9724 KB Output is correct
54 Correct 313 ms 10780 KB Output is correct
55 Execution timed out 1037 ms 27592 KB Time limit exceeded
56 Halted 0 ms 0 KB -