提交记录 3642


用户 题目 状态 得分 用时 内存 语言 代码长度
larryzhong noi17a. 【NOI2017】整数 Accepted 100 1.154 s 37308 KB C++ 3.18 KB
提交时间 评测时间
2018-07-17 13:09:57 2020-07-31 21:21:15
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn = 500010, S = 60;
ll a, b, INF = (1LL << S) - 1, f[maxn];
int n, m, t1, t2, t3;
struct segment_tree {
    int l, r, pos;
    ll lazy;
    bool all[2];
} tree[maxn << 2];

void maintain(int k) {
    tree[k].all[0] = tree[k << 1].all[0] & tree[k << 1 | 1].all[0];
    tree[k].all[1] = tree[k << 1].all[1] & tree[k << 1 | 1].all[1];
}

void modify(int k, ll x) {
    if (tree[k].pos != -1) f[tree[k].pos] = x; tree[k].lazy = x;
    if (x == 0) tree[k].all[0] = 1, tree[k].all[1] = 0;
    else if (x == INF) tree[k].all[0] = 0, tree[k].all[1] = 1;
    else tree[k].all[0] = tree[k].all[1] = 0;
}

void pushdown(int k) {
    if (tree[k].lazy == -1) return;
    modify(k << 1, tree[k].lazy), modify(k << 1 | 1, tree[k].lazy);
    tree[k].lazy = -1;
}

void build(int k, int l, int r) {
    tree[k].l = l, tree[k].r = r, tree[k].all[0] = 1, tree[k].lazy = tree[k].pos = -1;
    if (l == r) { tree[k].pos = l; return; }
    int mid = (l + r) >> 1;
    build(k << 1, l, mid), build(k << 1 | 1, mid + 1, r);
}

void change(int k, int l, int r, ll x) {
    if (tree[k].l == l && tree[k].r == r) { modify(k, x); return; }
    pushdown(k);
    int mid = (tree[k].l + tree[k].r) >> 1;
    if (mid >= r) {
        change(k << 1, l, r, x);
    } else if (mid < l) {
        change(k << 1 | 1, l, r, x);
    } else {
        change(k << 1, l, mid, x), change(k << 1 | 1, mid + 1, r, x);
    }
    maintain(k);
}

int find_nxt(int k, int p, int v) {
    if (tree[k].all[!v]) return -1;
    if (tree[k].l == tree[k].r) return tree[k].l;
    int mid = (tree[k].l + tree[k].r) >> 1, t;
    if (mid >= p && (t = find_nxt(k << 1, p, v)) != -1) return t;
    return find_nxt(k << 1 | 1, p, v);
}

ll query(int k, int p) {
    if (tree[k].l == tree[k].r) return f[tree[k].l];
    pushdown(k);
    int mid = (tree[k].l + tree[k].r) >> 1;
    if (mid >= p) {
        return query(k << 1, p);
    } else {
        return query(k << 1 | 1, p);
    }
}

void add(int p, ll x) {
    ll t = query(1, p); change(1, p, p, (t + x) & INF);
    if (t + x > INF) {
        t = find_nxt(1, p + 1, 0);
        change(1, t, t, f[t] + 1);
        if (p + 1 < t) change(1, p + 1, t - 1, 0);
    }
}

void sub(int p, ll x) {
    ll t = query(1, p); change(1, p, p, (t - x) & INF);
    if (t - x < 0) {
        t = find_nxt(1, p + 1, 1);
        change(1, t, t, f[t] - 1);
        if (p + 1 < t) change(1, p + 1, t - 1, INF);
    }
}

int main() {
    scanf("%d %d %d %d", &m, &t1, &t2, &t3), n = (m + 2) >> 1;
    build(1, 0, n);
    for (int i = 1, op; i <= m; i++) {
        scanf("%d %lld", &op, &a);
        if (op == 1) {
            scanf("%lld", &b);
            if (a > 0) {
                int p = b / S, r = b % S;
                ll x = a << r & INF;
                if (x) add(p, x);
                p++, a >>= (S - r);
                if (b) add(p, a);
            } else {
                a = -a;
                int p = b / S, r = b % S;
                ll x = a << r & INF;
                if (x) sub(p, x);
                p++, a >>= (S - r);
                if (b) sub(p, a);
            }
        } else {
            printf("%d\n", query(1, a / S) >> (a % S) & 1);
        }
    }
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #139.66 us44 KBAcceptedScore: 4

Testcase #273.98 us48 KBAcceptedScore: 4

Testcase #3714.56 us108 KBAcceptedScore: 4

Testcase #41.411 ms172 KBAcceptedScore: 4

Testcase #53.263 ms300 KBAcceptedScore: 4

Testcase #63.09 ms304 KBAcceptedScore: 4

Testcase #76.167 ms596 KBAcceptedScore: 4

Testcase #85.524 ms560 KBAcceptedScore: 4

Testcase #922.405 ms1 MB + 176 KBAcceptedScore: 4

Testcase #1041.158 ms2 MB + 264 KBAcceptedScore: 4

Testcase #1140.915 ms2 MB + 88 KBAcceptedScore: 4

Testcase #1239.425 ms2 MB + 336 KBAcceptedScore: 4

Testcase #1357.939 ms4 MB + 356 KBAcceptedScore: 4

Testcase #14188.937 ms8 MB + 940 KBAcceptedScore: 4

Testcase #15225.482 ms17 MB + 368 KBAcceptedScore: 4

Testcase #16412.321 ms17 MB + 820 KBAcceptedScore: 4

Testcase #17431.337 ms16 MB + 404 KBAcceptedScore: 4

Testcase #18653.274 ms34 MB + 696 KBAcceptedScore: 4

Testcase #19785.199 ms35 MB + 124 KBAcceptedScore: 4

Testcase #20763.007 ms35 MB + 876 KBAcceptedScore: 4

Testcase #21789.607 ms36 MBAcceptedScore: 4

Testcase #22839.296 ms32 MB + 716 KBAcceptedScore: 4

Testcase #231.083 s36 MB + 168 KBAcceptedScore: 4

Testcase #24905.36 ms32 MB + 760 KBAcceptedScore: 4

Testcase #251.154 s36 MB + 444 KBAcceptedScore: 4


Judge Duck Online | 评测鸭在线
Server Time: 2024-11-22 13:05:19 | Loaded in 2 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠