QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#478966#6509. Not Another Range Query ProblempavementTL 19ms5684kbC++172.0kb2024-07-15 13:19:222024-07-15 13:19:22

Judging History

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

  • [2024-07-15 13:19:22]
  • 评测
  • 测评结果:TL
  • 用时:19ms
  • 内存:5684kb
  • [2024-07-15 13:19:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")

#define pb push_back

int n, q, del_time[500005];
char s[500005];
set<int> rem;

struct dat {
	int a{-1}, b{-1}, diff{(int)1e9};
};

dat combine(dat lhs, dat rhs) {
	dat ret;
	ret.diff = min(lhs.diff, rhs.diff);
	if (lhs.b != -1 && rhs.a != -1 && s[lhs.b] != s[rhs.a]) {
		ret.diff = min(ret.diff, rhs.a);
	}
	if (lhs.a == -1) {
		ret.a = rhs.a;
	} else {
		ret.a = lhs.a;
	}
	if (rhs.b == -1) {
		ret.b = lhs.b;
	} else {
		ret.b = rhs.b;
	}
	return ret;
}

struct node {
	node *left, *right;
	int S, E;
	dat val;
	node(int _s, int _e) : S(_s), E(_e) {
		if (S == E) {
			val.a = val.b = S;
			return;
		}
		int M = (S + E) / 2;
		left = new node(S, M);
		right = new node(M + 1, E);
		val = combine(left->val, right->val);
	}
	dat qry(int l, int r) {
		if (l > E || r < S) {
			dat dummy;
			return dummy;
		}
		if (l <= S && E <= r) {
			return val;
		}
		return combine(left->qry(l, r), right->qry(l, r));
	}
	void del(int p) {
		if (S == E) {
			val.a = val.b = -1;
			val.diff = (int)1e9;
			return;
		}
		int M = (S + E) / 2;
		if (p <= M) {
			left->del(p);
		} else {
			right->del(p);
		}
		val = combine(left->val, right->val);
	}
} *root;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> q;
	for (int i = 1; i <= n; i++) {
		cin >> s[i];
	}
	root = new node(1, n);
	for (int i = 1; i <= n; i++) {
		rem.insert(i);
	}
	for (int t = 1; !rem.empty(); t++) {
		vector<int> to_erase;
		for (int st = *rem.begin(); st <= n; st = root->qry(st, n).diff) {
			to_erase.pb(st);
		}
		for (auto i : to_erase) {
			rem.erase(i);
			root->del(i);
			del_time[i] = t;
		}
	}
	for (int i = 1, l, r, k; i <= q; i++) {
		cin >> l >> r >> k;
		int cur = 0;
		for (int j = l, prv = 0; j <= r; j++) {
			if (prv >= k && del_time[j] > k) {
				cur++;
			}
			if (del_time[j] >= prv + 1) {
				prv++;
			}
		}
		cout << cur << '\n';
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5684kb

input:

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

output:

2
1
1
3
4
9
0

result:

ok 7 numbers

Test #2:

score: 0
Accepted
time: 19ms
memory: 3848kb

input:

100 100000
0000011010101000111011110110000111110101101010111111101011011010111001111010111000001000011000001010
76 99 3
25 84 7
45 83 11
10 12 10
69 86 4
27 28 1
22 42 42
4 86 25
26 91 22
20 81 17
50 78 0
77 93 50
31 50 34
7 46 13
78 89 0
79 98 0
2 84 33
58 93 11
56 75 2
55 77 68
7 9 41
44 46 11
47 ...

output:

8
13
4
0
3
0
0
0
0
4
29
0
0
0
12
20
0
0
5
0
0
0
0
0
0
0
0
10
18
1
0
57
0
0
11
0
3
0
0
3
0
0
0
0
0
0
0
0
0
0
0
0
0
0
19
0
0
0
12
5
0
0
2
0
0
0
0
10
12
0
0
0
5
0
8
0
1
16
0
19
29
40
21
12
26
0
21
6
0
10
18
0
3
0
2
5
0
0
5
0
0
0
51
0
0
0
18
11
0
20
5
9
10
0
16
22
0
20
0
26
0
0
0
0
0
0
11
46
59
2
9
43
1...

result:

ok 100000 numbers

Test #3:

score: -100
Time Limit Exceeded

input:

100000 100000
0000000000000100001000000010000000010100000100000000000000100000010000000000000000000001100010000000100000000000000000000000000000000000010000000000001000000100000010000000000000000000000100001010000000000000100000101000001000010000000110000000001001100001001000001000000000000000000000...

output:

22471
25961
5992
28726
71306
32974
19300
27865
4043
18931
20250
10170
0
6468
23117
30898
0
35198
39326
23429
1392
1912
5358
0
0
37098
20809
19360
36450
38461
58630
10729
7118
1080
1791
16314
15830
33873
11823
37496
47846
12635
3677
27787
0
50176
38497
13639
34736
14197
28295
25390
0
12080
0
17512
15...

result: