QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#356682#8301. Hold the LineFOY#WA 815ms3704kbC++141.8kb2024-03-18 09:01:112024-03-18 09:01:11

Judging History

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

  • [2024-03-18 09:01:11]
  • 评测
  • 测评结果:WA
  • 用时:815ms
  • 内存:3704kb
  • [2024-03-18 09:01:11]
  • 提交

answer

#include <vector>
#include <set>
#include <iostream>

using namespace std;
using ll = long long;
struct X {
	set<int> vals;

	X operator+(X rhs) {
		set<int> out = {vals.begin(), vals.end()};
		for (int j : rhs.vals) out.insert(j);
		return { out };
	}
};

int closest(int x, set<int> &a) {
	auto u = a.upper_bound(x);
	auto l = a.lower_bound(x);
	int ans = -1e9;
	if (u != a.end()) 
		ans = *u;
	if (l != a.end()) 
		if (abs(ans-x) > abs(*l-x)) ans = *l;
	return ans;
}

int closest(int x, int y, int z) {
	if (abs(x-y) < abs(x-z)) return y;
	else return z;
}

struct Segtree {
    int n;
    vector<X> tree;
    Segtree(int n): n(n), tree(4*n) {
    }

    void insert(int idx, int val, int cl = 0, int cr = -1, int k = 1) {
        if (cr == -1) cr = n;
				tree[k].vals.insert(val);
				if (cl == cr-1) return;
        int mid = (cl+cr)/2;
        if (idx < mid) insert(idx, val, cl, mid, k*2);
        else insert(idx, val, mid, cr, k*2+1);
    }

    int act(int l, int r, int targ, int cl = 0, int cr = -1, int k = 1) {
        if (cr == -1) cr = n;
        if (cr <= l || r <= cl) return -1e9;
        if (l <= cl && r >= cr) {
            return closest(targ, tree[k].vals);
        }
        int mid = (cl+cr)/2;
				int a = act(l, r, cl, mid, k*2);
				int b = act(l, r, mid, cr, k*2+1);
        return closest(targ, a, b);
    }
};

void solve() {
	int n, m; cin >> n >> m;
	Segtree s(n);
	for (int i = 0; i < m; i++) {
		int type; cin >> type;
		if (type == 0) {
			int x, h; cin >> x>> h;
			s.insert(x-1, h);
		}
		else {
			int l, r, h; cin >> l >> r >> h;
			l--;
			int ans = s.act(l, r, h);
			if (ans == -1e9) cout << -1 << endl;
			else cout << ans << endl;
		}
	}

}

int main() {
	int t; cin >> t;
	while (t--) solve();

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 815ms
memory: 3704kb

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:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
453818
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
453818
-1
-1
-1
-1
-1
-1
453818
-1
-1
-1
-1
453818
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1...

result:

wrong answer 1st lines differ - expected: '18886079', found: '-1'