QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#371508#8301. Hold the Lineucup-team052#WA 739ms97484kbC++142.1kb2024-03-30 13:28:162024-03-30 13:28:16

Judging History

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

  • [2024-03-30 13:28:16]
  • 评测
  • 测评结果:WA
  • 用时:739ms
  • 内存:97484kb
  • [2024-03-30 13:28:16]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while (c < '0' || c > '9') { if (c == '-') { fu = -1; } c = getchar(); }
    while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if (x < 0) putchar('-'), x = -x;
    if (x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

const int N = 5e5 + 5, INF = 1e9;

set <int> p[N << 2];
int T, n, m;

void ins(int u, int l, int r, int x, int y) {
    p[u].insert(y);
    if (l == r) return;
    int mid = (l + r) >> 1;
    if (mid >= x) ins(u << 1, l, mid, x, y);
    else ins(u << 1 | 1, mid + 1, r, x, y);
}

int ans;
void query(int u, int L, int R, int l, int r, int x) {
    if (!p[u].size()) return;
    auto it = p[u].lower_bound(x);
    if (it != p[u].end()) ans = min(ans, *it - x);
    if (it != p[u].begin()) {
        --it;
        ans = min(ans, x - *it);
    }
    int mid = (L + R) >> 1;
    if (mid >= l) query(u << 1, L, mid, l, r, x);
    if (mid + 1 <= r) query(u << 1 | 1, mid + 1, R, l, r, x);
}

int main() {
    read(T);
    while (T--) {
        read(n); read(m);
        for (int i = 1; i <= n * 4; i++) p[i].clear();
        for (int i = 1; i <= m; i++) {
            int opt; read(opt);
            if (opt == 0) {
                int x, y;
                read(x); read(y);
                ins(1, 1, n, x, y);
            }
            if (opt == 1) {
                ans = INF;
                int l, r, x;
                read(l); read(r); read(x);
                query(1, 1, n, l, r, x);
                if (ans == INF) ans = -1;
                print(ans, '\n');
            }
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 16ms
memory: 97408kb

input:

1
3 5
1 1 3 2
0 1 1
0 3 3
1 1 2 2
1 2 3 2

output:

-1
1
1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 739ms
memory: 97484kb

input:

3000
100 200
0 59 64091111
1 10 94 45205032
0 41 67249140
1 15 93 79570187
0 51 83215051
1 3 22 20062363
0 21 5188814
1 43 94 79642299
0 73 39313603
1 43 67 17001771
0 65 10784990
1 51 69 73368509
0 42 57377517
1 36 49 17483147
0 40 67280095
1 3 41 25139505
0 56 22833553
1 26 65 15640242
0 22 189761...

output:

18886079
12321047
44028748
3572752
11812957
6119369
6698157
14174098
4855252
2221206
1596905
1243665
3120922
6997364
2017635
494034
2499997
90484
977838
1193064
1144184
734969
3527915
4159424
2354329
774042
3211890
1785837
283130
3493739
1751056
1759085
845742
3218058
1098857
2028531
379947
2455095
...

result:

wrong answer 3rd lines differ - expected: '-1', found: '44028748'