Submission #65269823


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct N {
int v, p, sz;
ll so, se;
N *l, *r;
N(int _v) : v(_v), p(rand()), sz(1), so(_v), se(0), l(nullptr), r(nullptr) {}
};
int gsz(N* t) { return t ? t->sz : 0; }
ll gso(N* t) { return t ? t->so : 0; }
ll gse(N* t) { return t ? t->se : 0; }
void upd(N* t) {
if (!t) return;
int ls = gsz(t->l);
ll lso = gso(t->l), lse = gse(t->l);
bool rootOdd = ((ls + 1) & 1);
bool flip = ((ls & 1) == 0);
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct N {
    int v, p, sz;
    ll so, se;
    N *l, *r;
    N(int _v) : v(_v), p(rand()), sz(1), so(_v), se(0), l(nullptr), r(nullptr) {}
};

int gsz(N* t) { return t ? t->sz : 0; }
ll gso(N* t) { return t ? t->so : 0; }
ll gse(N* t) { return t ? t->se : 0; }

void upd(N* t) {
    if (!t) return;
    int ls = gsz(t->l);
    ll lso = gso(t->l), lse = gse(t->l);
    bool rootOdd = ((ls + 1) & 1);
    bool flip = ((ls & 1) == 0);
    ll rso = gso(t->r), rse = gse(t->r);
    ll nso = flip ? rse : rso;
    ll nse = flip ? rso : rse;
    t->sz = 1 + ls + gsz(t->r);
    t->so = lso + (rootOdd ? t->v : 0) + nso;
    t->se = lse + (rootOdd ? 0 : t->v) + nse;
}

void split(N* t, int x, N*& a, N*& b) {
    if (!t) { a = b = nullptr; return; }
    if (t->v < x) {
        split(t->r, x, t->r, b);
        a = t;
    } else {
        split(t->l, x, a, t->l);
        b = t;
    }
    upd(t);
}

N* merge(N* a, N* b) {
    if (!a || !b) return a ? a : b;
    if (a->p > b->p) {
        a->r = merge(a->r, b);
        upd(a);
        return a;
    } else {
        b->l = merge(a, b->l);
        upd(b);
        return b;
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    srand(0);

    int Q;
    cin >> Q;
    N* root = nullptr;
    ll z = 0;

    while (Q--) {
        ll y;
        cin >> y;
        int x = int((y + z) % 1000000000 + 1);

        N *a, *b;
        split(root, x, a, b);
        N* nd = new N(x);
        root = merge(merge(a, nd), b);
        z = root->so;
        cout << z << endl;
    }
    return 0;
}

Submission Info

Submission Time
Task G - Odd Position Sum Query
User bal4u
Language C++ 20 (gcc 12.2)
Score 600
Code Size 1693 Byte
Status AC
Exec Time 721 ms
Memory 23824 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 2
AC × 47
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt, 01_test_33.txt, 01_test_34.txt, 01_test_35.txt, 01_test_36.txt, 01_test_37.txt, 01_test_38.txt, 01_test_39.txt, 01_test_40.txt, 01_test_41.txt, 01_test_42.txt, 01_test_43.txt, 01_test_44.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3400 KB
00_sample_01.txt AC 1 ms 3520 KB
01_test_00.txt AC 1 ms 3416 KB
01_test_01.txt AC 1 ms 3412 KB
01_test_02.txt AC 1 ms 3328 KB
01_test_03.txt AC 1 ms 3460 KB
01_test_04.txt AC 1 ms 3552 KB
01_test_05.txt AC 2 ms 3548 KB
01_test_06.txt AC 11 ms 3856 KB
01_test_07.txt AC 3 ms 3636 KB
01_test_08.txt AC 33 ms 4628 KB
01_test_09.txt AC 204 ms 9744 KB
01_test_10.txt AC 416 ms 15196 KB
01_test_11.txt AC 356 ms 13884 KB
01_test_12.txt AC 706 ms 23604 KB
01_test_13.txt AC 702 ms 23624 KB
01_test_14.txt AC 253 ms 15420 KB
01_test_15.txt AC 391 ms 23640 KB
01_test_16.txt AC 349 ms 17160 KB
01_test_17.txt AC 498 ms 23716 KB
01_test_18.txt AC 508 ms 21464 KB
01_test_19.txt AC 576 ms 23736 KB
01_test_20.txt AC 359 ms 14848 KB
01_test_21.txt AC 614 ms 23688 KB
01_test_22.txt AC 600 ms 20768 KB
01_test_23.txt AC 694 ms 23688 KB
01_test_24.txt AC 534 ms 18260 KB
01_test_25.txt AC 720 ms 23632 KB
01_test_26.txt AC 715 ms 23724 KB
01_test_27.txt AC 716 ms 23640 KB
01_test_28.txt AC 713 ms 23700 KB
01_test_29.txt AC 710 ms 23656 KB
01_test_30.txt AC 703 ms 23600 KB
01_test_31.txt AC 704 ms 23652 KB
01_test_32.txt AC 721 ms 23824 KB
01_test_33.txt AC 711 ms 23100 KB
01_test_34.txt AC 407 ms 23560 KB
01_test_35.txt AC 392 ms 23648 KB
01_test_36.txt AC 397 ms 23544 KB
01_test_37.txt AC 395 ms 23716 KB
01_test_38.txt AC 429 ms 23616 KB
01_test_39.txt AC 421 ms 23660 KB
01_test_40.txt AC 462 ms 23544 KB
01_test_41.txt AC 451 ms 23720 KB
01_test_42.txt AC 2 ms 3396 KB
01_test_43.txt AC 385 ms 22212 KB
01_test_44.txt AC 391 ms 23792 KB


2025-05-10 (Sat)
11:59:53 +09:00