QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#628201#6608. Descent of DragonsMoyouWA 0ms9800kbC++141.6kb2024-10-10 19:06:592024-10-10 19:06:59

Judging History

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

  • [2024-10-10 19:06:59]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:9800kb
  • [2024-10-10 19:06:59]
  • 提交

answer

#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
const int N = 5e5 + 10, M = N * 35;

int n, q;
int dat[M], ls[M], rs[M], root[N], idx;
#define mid (l + r >> 1)
int build(int l, int r) {
	int u = ++ idx;
	if(l == r) return dat[u] = 1, u;
	ls[u] = build(l, mid), rs[u] = build(mid + 1, r), dat[u] = dat[ls[u]] + dat[rs[u]];
	return u;
}
int update(int p, int q, int l, int r, int ql, int qr) {
//	if(!p) return 0;
	if(ql <= l && qr >= r) return p;
	int u = ++ idx; ls[u] = ls[q], rs[u] = rs[q];
	if(ql <= mid) ls[u] = update(ls[p], ls[u], l, mid, ql, qr);
	if(qr > mid) rs[u] = update(rs[p], rs[u], mid + 1, r, ql, qr);
	dat[u] = dat[ls[u]] + dat[rs[u]];
	return u;
}
int query(int u, int l, int r, int ql, int qr) {
	if(!dat[u]) return 0;
	if(ql <= l && qr >= r) return dat[u];
	int tmp = 0;
	if(ql <= mid) tmp = query(ls[u], l, mid, ql, qr);
	if(qr > mid) tmp += query(rs[u], mid + 1, r, ql, qr);
	return tmp;
}
#undef mid 
signed main() {
	ios::sync_with_stdio(0), cin.tie(0);
//	freopen("dat.in", "r", stdin);
//	freopen("my.out", "w", stdout);
	cin >> n >> q;
	root[0] = build(1, n);
	int cnt = 0;
	for(int i = 1; i <= q; i ++) {
		int op, l, r, x;
		cin >> op >> l >> r;
		if(op == 1) {
			cin >> x;
			root[x + 1] = update(root[x], root[x + 1], 1, n, l, r);
		}
		else {
			cnt ++;
				int ll = 0, rr = i, ans = -1, mid;
				while(ll <= rr) {
					mid = ll + rr >> 1;
					if(query(root[mid], 1, n, x, x)) ll = mid + 1, ans = mid;
					else rr = mid - 1;
				}
				cout << ans << '\n';
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 9800kb

input:

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

output:

0
0

result:

wrong answer 2nd numbers differ - expected: '3', found: '0'