QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#108702#4429. Gebyte's GrindymjdRE 0ms0kbC++142.3kb2023-05-26 13:14:482023-05-26 13:14:49

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-26 13:14:49]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-05-26 13:14:48]
  • 提交

answer

#include<bits/stdc++.h>
#define miu 1000007
using namespace std;
const long long inf = 1e18;
int n, m;
long long H;
struct node {
    long long a, b, c;
} tr[miu << 2];
struct Snode {
    int p;  
    node t; 
};
inline node merge(node x, node y) {
    if(x.c <= y.a) {
        return (node){min(x.b + y.a - x.c, inf), min(x.b + y.b - x.c, inf), y.c}; 
    } else if(x.c <= y.b) {
        return (node){x.a, min(x.b + y.b - x.c, inf), y.c};
    } else {
        return (node){x.a, x.b, min(x.c + y.c - y.b, inf)};
    }
}
inline void pushup(int id) {
    tr[id] = merge(tr[id << 1], tr[id << 1 | 1]);
}
void modify(int id, int l, int r, int x, node v) {
    if(l == r) {
        tr[id] = v; return;
    }
    int mid = l + r >> 1;
    if(x <= mid) modify(id << 1, l, mid, x, v);
    else modify(id << 1 | 1, mid + 1, r, x, v);
    pushup(id);
}
Snode query(int id, int l, int r, int x, node cur) {
    if(l == r) {
        if(merge(cur, tr[id]).a >= H) return (Snode){l - 1, cur};
        else return (Snode){l, merge(cur, tr[id])};
    }
    int mid = l + r >> 1;
    if(x > mid) return query(id << 1 | 1, mid + 1, r, x, cur);
    Snode lt = query(id << 1, l, mid, x, cur);
    if(lt.p < mid) return lt;
    if(merge(lt.t, tr[id << 1 | 1]).a >= H) return query(id << 1 | 1, mid + 1, r, x, lt.t);
    return (Snode){r, merge(lt.t, tr[id << 1 | 1])};
}
inline node init(int op, long long x) {
    switch(op) {
        case 1:
            return (node){x, x, 0};
            break;
        case 2:
            return (node){x - 1, inf, x};
            break;
        case 3:
            return (node){0, x, x};
            break;
    }
}
signed main() {
    freopen("bad.in", "r", stdin);
    freopen("bad.out", "w", stdout);
    scanf("%d %d %lld", &n, &m, &H);
    for(int i = 1; i <= n; ++i) {
        int op; long long x; scanf("%d %lld", &op, &x);
        modify(1, 1, n, i, init(op, x));
    }
    for(int i = 1; i <= m; ++i) {
        int tp, op, x;
        long long v; scanf("%d %d", &tp, &x);
        if(tp == 1) {
            scanf("%d %lld", &op, &v);
            modify(1, 1, n, x, init(op, v));
        } else {
            int ans = query(1, 1, n, x, (node){0, 0, 0}).p;
            printf("%d\n", ans < x ? -1 : ans);
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

1
2000000 4000000 1000000000000
B 2982992025
B 1226542907
B 2299259203
B 1223702056
B 1407121251
B 340783317
B 1259091208
B 2101980047
B 2611543443
B 2010658889
B 4233714406
B 3112120167
B 2311876255
B 2789960428
B 3008572010
B 1
B 2464951378
B 1364240867
B 2829584762
B 2511437438
B 692948679
B 1113...

output:


result: