QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#398687#1872. GameieeAC ✓1496ms37568kbC++141.3kb2024-04-25 16:27:342024-04-25 16:27:44

Judging History

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

  • [2024-04-25 16:27:44]
  • 评测
  • 测评结果:AC
  • 用时:1496ms
  • 内存:37568kb
  • [2024-04-25 16:27:34]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

int T, n, q;
map<pair<int, int>, int> mp, crit;
vector<pair<int, int>> cand;

int main() {
    scanf("%d", &T);
    function<int(int, int)> solve = [&](int l, int r) {
        auto it = lower_bound(cand.begin(), cand.end(), make_pair(l + r, l));
        if (it == cand.end() || it->first != l + r) return (r - l) & 1;
        l = it->second, r = it->first - l;
        if (crit.count({l, r})) return crit[{l, r}];
        if (l == r) return 0;
        if (mp.count({l, r})) return mp[{l, r}];
        return mp[{l, r}] = !solve(l + 1, r) | !solve(l, r - 1);
    };
    while (T--) {
        scanf("%d %d", &n, &q);
        mp.clear(), crit.clear(), cand.clear();
        while (n--) {
            int l, r, z;
            scanf("%d %d %d", &l, &r, &z);
            crit[{l, r}] = z;
            for (int i = l - 2; i <= l; i++) {
                for (int j = r; j <= r + 2; j++) {
                    if (j - i <= r - l + 2) cand.emplace_back(i + j, i);
                }
            }
        }
        sort(cand.begin(), cand.end());
        while (q--) {
            int l, r;
            scanf("%d %d", &l, &r);
            putchar(solve(l, r) ? '1' : '0');
        }
        putchar('\n');
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3644kb

input:

1
5 10
1 2 0
3 3 1
3 4 1
2 4 1
1 3 0
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5

output:

0010111101

result:

ok single line: '0010111101'

Test #2:

score: 0
Accepted
time: 1496ms
memory: 37568kb

input:

1004
100000 100000
500000000 500000000 1
500000000 500000002 1
500000000 500000004 1
500000000 500000006 0
500000000 500000008 1
500000000 500000010 0
500000000 500000012 0
500000000 500000014 1
500000000 500000016 0
500000000 500000018 1
500000000 500000020 0
500000000 500000022 1
500000000 5000000...

output:

000001100000000111001010000111001111110010000101100101101000101010101010000100100100101010011011110110001100000000100101000000000000000101000000000010100110110101000001000111110000100010110000100111110101101010011000000100000000001001011011101000100000011000111111100010001111010001000010001110001110...

result:

ok 1004 lines