QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#86613#4236. Triangular Logscardinal_cityML 69ms25116kbC++203.8kb2023-03-10 13:20:242023-03-10 13:20:25

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-10 13:20:25]
  • 评测
  • 测评结果:ML
  • 用时:69ms
  • 内存:25116kb
  • [2023-03-10 13:20:24]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define smn(a, b) a = min(a, b)
#define all(x) x.begin(), x.end()


const int SZ = 1e9 + 5;
template <class T, T (*op)(T, T), T (*e)()> struct seg1d {
    T val = e(); seg1d<T, op, e>* c[2];
    seg1d() { c[0] = c[1] = NULL; }
    void update(int pos, T v, int L = 0, int R = SZ-1) {
        if (L == pos && R == pos) { val = v; return; }
        int M = (L + R) / 2;
        if (pos <= M) {
            if (!c[0]) {
                c[0] = new seg1d();
            }
            c[0]->update(pos, v, L, M);
        } else {
            if (!c[1]) {
                c[1] = new seg1d();
            }
            c[1]->update(pos, v, M + 1, R);
        }
        val = e();
        if (c[0]) val = op(val, c[0]->val);
        if (c[1]) val = op(val, c[1]->val);
    }

    T query(int lo, int hi, int L = 0, int R = SZ-1) {
        if (hi < L || R < lo) return e();
        if (lo <= L && R <= hi) return val;
        int M = (L + R) / 2;
        T res = e();
        if (c[0]) {
            res = op(res, c[0]->query(lo, hi, L, M));
        }
        if (c[1]) {
            res = op(res, c[1]->query(lo, hi, M + 1, R));
        }
        return res;
    }
};

template <class T, T (*op)(T, T), T (*e)()> struct seg2d {
    seg1d<T, op, e> val; seg2d<T, op, e>* c[2]; 
    seg2d() { c[0] = c[1] = NULL; }
    void update(int posX, int posY, T v, int L = 0, int R = SZ - 1) {
        if (L == posX && R == posX) {
            val.update(posY, v);
            return;
        }
        int M = (L + R) / 2;
        if (posX <= M) {
            if (!c[0]) c[0] = new seg2d();
            c[0]->update(posX, posY, v, L, M);
        } else {
            if (!c[1]) c[1] = new seg2d();
            c[1]->update(posX, posY, v, M + 1, R);
        }
        T res = e();
        if (c[0]) res = op(res, c[0]->val.query(posY, posY + 1));
        if (c[1]) res = op(res, c[1]->val.query(posY, posY + 1));
        val.update(posY, res);
    }

    T query(int loX, int hiX, int loY, int hiY, int L = 0, int R = SZ - 1) {
        if (hiX < L || R < loX) { return e(); }
        if (loX <= L && R <= hiX) { return val.query(loY, hiY); }
        int M = (L + R) / 2;
        T res = e();
        if (c[0]) res = op(res, c[0]->query(loX, hiX, loY, hiY, L, M));
        if (c[1]) res = op(res, c[1]->query(loX, hiX, loY, hiY, M + 1, R));
        return res;
    } 
};

int op1(int a, int b) {
    return a + b;
}

int e1() {
    return 0;
}

vector<int> op2(vector<int> a, vector<int> b) {
    if (a.size() + b.size() >= 100) {
        return {}; // destruct it when large enough, not needed
    }
    if (a.size() > b.size()) {
        swap(a, b);
    }
    for (auto& c : a) {
        b.push_back(c);
    }
    return b;
}

vector<int> e2() {
    return {};
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n, q; cin >> n >> q;

    seg2d<int, op1, e1> trees;
    seg2d<vector<int>, op2, e2> heights;
    for (int i = 0; i < n; i++) {
        int x, y, w;
        cin >> x >> y >> w;
        trees.update(x, y, w);
        heights.update(x, y, {w});
    }

    for (int i = 0; i < q; i++) {
        int loX, loY, hiX, hiY;
        cin >> loX >> loY >> hiX >> hiY;
        if (trees.query(loX, hiX, loY, hiY) >= 50) {
            cout << "1\n";
            continue;
        }
        vector<int> qq = heights.query(loX, hiX, loY, hiY);
        sort(all(qq));
        if (qq.size() < 3) {
            cout << "0\n";
            continue;
        }
        for (int i = 0; i < (int)qq.size() - 2; i++) {
            if (qq[i] + qq[i + 1] > qq[i + 2]) {
                cout << "1\n";
                goto win;
            }
        }
        cout << "0\n";

        win:
        int y = 1;
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 3920kb

input:

9 5
1 3 3
2 3 1
3 3 4
1 2 1
2 2 5
3 2 9
1 1 2
2 1 6
3 1 5
1 1 1 2
1 1 2 2
1 1 1 3
1 2 3 2
1 1 3 3

output:

0
1
0
0
1

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 57ms
memory: 22252kb

input:

481 1
8 6788 8975
24 6552 2668
26 7948 4730
40 531 9805
110 1914 1916
164 7073 3371
165 6293 7756
170 9946 2003
179 9654 1700
215 6447 2229
221 3149 3030
242 1999 6843
242 5764 3163
249 3716 8634
250 6801 9317
260 2741 4273
282 5436 4836
284 3951 6483
288 4812 76
375 9004 5492
380 5627 5929
391 6385...

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 69ms
memory: 25116kb

input:

378 1
62730 50925 80731
92666 77280 61521
29236 67032 7889
35986 96802 8763
13313 49918 83582
51842 66775 47834
2286 12925 41106
39790 6698 15243
65145 56379 68496
35570 809 525
39834 16723 48002
77230 16273 16032
52615 7621 77300
92267 82517 39917
13170 89084 77751
45638 23868 49631
7758 71381 5191...

output:

1

result:

ok single line: '1'

Test #4:

score: -100
Memory Limit Exceeded

input:

100000 100000
299999993 206450345 26023928
334281171 300000008 18107965
318653732 299999990 82338399
299999997 393028366 37212808
299999992 208114125 82126189
300000002 303613195 34463905
270033576 299999993 49200970
300000003 249755524 5829381
300000003 367329175 12867359
300000009 337452692 131045...

output:


result: