QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#734383#4894. 学姐买瓜NineSuns0 0ms7692kbC++142.1kb2024-11-11 09:35:542024-11-11 09:35:55

Judging History

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

  • [2024-11-11 09:35:55]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:7692kb
  • [2024-11-11 09:35:54]
  • 提交

answer

#include <bits/stdc++.h>
#define pii pair <int, int>
#define fi first
#define se second

using namespace std;
const int N = 3e5+5, B = 3e5+5, b = 255, inf = 0x3f3f3f3f;
int n, m, nxt[N], nb[N], d[N], rk[N], lb[B], rb[B], o[B], od[B]; 
set <pii> st; 

void reset (int bi, int l, int r, int k) {
	if (o[bi]) {
		for (int j = rb[bi];j >= lb[bi];j--) nxt[j] = od[bi], d[j] = 1; 
		o[bi] = 0;
	}
	for (int j = l;j <= r;j++) nxt[j] = k; 
	for (int j = r;j >= lb[bi];j--) {
		if (nxt[j] > rb[bi]) nb[j] = nxt[j], d[j] = 1; 
		else nb[j] = nb[nxt[j]], d[j] = d[nxt[j]]+1; 
	}
}

void upd (int l, int r, int k) {
//	cout << "MODIFY:" << l << " " << r << " " << k << endl; 
	int bl = rk[l], br = rk[r]; 
	if (bl == br) {
		return reset(bl, l, r, k);
	} 
	reset(bl, l, rb[bl], k); reset(br, lb[br], r, k);
	for (int j = bl+1;j < br;j++) o[j] = 1, od[j] = k; 
}

int getd (int l, int r) {
	int k = 0; 
	while (1) {
		if (o[rk[l]]) {
			if (od[rk[l]] > r+1) break;
			k++; l = od[rk[l]]; 
		}
		else {
			if (nb[l] > r+1) break; 
			k += d[l]; l = nb[l]; 
		}
	}
	while (1) {
		if (o[rk[l]]) {
			if (od[rk[l]] > r+1) break; 
			k++; l = od[rk[l]]; 
		}
		else {
			if (nxt[l] > r+1) break; 
			k++; l = nxt[l]; 
		}
	}
	return k; 
}

int main () {
	ios::sync_with_stdio(0); 
	cin.tie(0); cout.tie(0); 
	cin >> m >> n; 
	for (int i = 1; ;i++) {
		lb[i] = rb[i-1]+1; rb[i] = min(n, rb[i-1]+b);
		for (int j = lb[i];j <= rb[i];j++) rk[j] = i; 
		if (rb[i] == n) break;  
	}
	for (int i = 1;i <= n+1;i++) nxt[i] = nb[i] = inf; 
	while (m--) {
		int o, l, r; cin >> o >> l >> r; 
		if (o == 1) {
			auto it = st.upper_bound({r+1, 0}); 
			if (it != st.begin()) {
				--it; 
				if ((*it).se >= l) continue; 
			}
			while (1) {
				auto it = st.upper_bound({r, 0}); 
				if (it == st.end()) break; 
				if ((*it).se <= l) st.erase(it); else break; 
			}
			st.insert({r, l});
			it = st.lower_bound({r, l}); auto nx = st.upper_bound({r, l}); 
			upd(it == st.begin() ? 1 : (*--it).se+1, l, r+1);  
		}
		else {
			cout << getd(l, r) << '\n'; 
		}
	}
	return 0; 
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 20
Accepted
time: 0ms
memory: 7692kb

input:

11 13
2 4 4
1 11 12
1 1 5
1 2 3
1 2 10
2 2 8
1 6 6
2 2 10
1 6 11
2 2 3
2 2 13

output:

0
1
2
1
3

result:

ok 5 lines

Test #2:

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

input:

2000 2000
2 66 273
1 475 1570
2 51 958
2 731 1771
1 1286 1627
1 37 892
1 529 890
2 155 1486
1 87 1815
1 576 1872
2 1269 1515
2 1521 1794
2 634 1887
2 204 1668
1 351 1679
2 1571 1599
1 243 681
2 1 2000
2 1 2000
2 564 648
2 1215 1807
2 466 1617
1 1119 1348
1 497 886
2 1358 1487
2 173 1974
1 401 1294
2...

output:

0
0
0
1
0
0
1
2
0
2
2
0
1
1
0
2
1
1
0
1
0
1
0
0
1
2
1
1
1
2
1
1
0
0
2
2
0
2
2
0
1
3
0
0
4
0
0
2
2
5
2
0
4
0
2
0
2
3
3
0
0
1
3
2
0
3
6
1
0
1
1
4
0
8
0
8
1
3
1
8
1
4
9
2
2
0
4
5
2
9
3
0
9
1
3
8
9
1
0
7
0
7
4
6
0
1
0
6
9
2
5
0
1
0
5
3
5
5
4
3
4
0
9
0
5
2
7
8
1
9
5
7
7
9
1
9
7
4
2
6
1
5
9
7
9
4
3
3
4
2
...

result:

wrong answer 102nd lines differ - expected: '8', found: '7'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%