QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#344714 | #8301. Hold the Line | hos_lyric | WA | 434ms | 3852kb | C++14 | 2.6kb | 2024-03-05 00:21:51 | 2024-03-05 00:21:51 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
/*
problem
query
0 x h: add h to position x (which was empty)
1 L R H: find distance from values in [L, R] to H
*/
constexpr int INF = 1001001001;
int main() {
for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
int N, Q;
scanf("%d%d", &N, &Q);
int segN;
for (segN = 1; segN < N; segN <<= 1) {}
vector<set<int>> seg(segN << 1);
for (; Q--; ) {
int O;
scanf("%d", &O);
if (O == 0) {
int X, H;
scanf("%d%d", &X, &H);
--X;
for (int a = segN + X; a; a >>= 1) {
seg[a].insert(H);
}
} else if (O == 1) {
int L, R, H;
scanf("%d%d%d", &L, &R, &H);
++R;
int ans = INF;
auto check = [&](int a) -> void {
auto it = seg[a].lower_bound(H);
if (it != seg[a].end()) {
chmin(ans, *it - H);
}
if (it != seg[a].begin()) {
--it;
chmin(ans, H - *it);
}
};
for (int a = segN + L, b = segN + R; a < b; a >>= 1, b >>= 1) {
if (a & 1) check(a++);
if (b & 1) check(--b);
}
printf("%d\n", (ans < INF) ? ans : -1);
} else {
assert(false);
}
}
}
#ifndef LOCAL
break;
#endif
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3824kb
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: 434ms
memory: 3852kb
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 -1 3572752 47089340 9277398 39894370 19950691 4855252 2221206 1596905 -1 3120922 -1 3353597 -1 2499997 -1 15114024 1193064 3773839 734969 3981124 4159424 5836824 61155540 5163746 -1 283130 3982548 28549348 65997993 33685312 5047211 2356693 -1 379947 75097044 2637615 7856589 153976 ...
result:
wrong answer 14th lines differ - expected: '34260194', found: '-1'