QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#859171#9742. 优秀的拆分bamboo123WA 63ms13900kbC++142.8kb2025-01-17 16:06:032025-01-17 16:06:04

Judging History

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

  • [2025-01-17 16:06:04]
  • 评测
  • 测评结果:WA
  • 用时:63ms
  • 内存:13900kb
  • [2025-01-17 16:06:03]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e6 + 5, mod = 1e9 + 7;
struct node {
	int mx, cnt;
	friend node operator+(node x, node y) {
		if(x.mx != y.mx)
			return (x.mx < y.mx ? y : x);
		return node{x.mx, (x.cnt + y.cnt) % mod};
	}
};
struct Segtree {
	node tr[maxn << 2];
	void pushup(int t) {
		tr[t] = tr[t << 1] + tr[t << 1 | 1];
	}
	void build(int l, int r, int t) {
		tr[t] = {0, 0};
		if(l == r)	
			return ;
		int mid = l + r >> 1;
		build(l, mid, t << 1), build(mid + 1, r, t << 1 | 1);
	}
	void modify(int l, int r, int pos, int t, node val) {
		if(l == r) {
			tr[t] = val;
			return ;
		}
		int mid = l + r >> 1;
		if(pos <= mid)
			modify(l, mid, pos, t << 1, val);
		else
			modify(mid + 1, r, pos, t << 1 | 1, val);
		pushup(t);
	}
	node query(int l, int r, int x, int y, int t) {
		if(x <= l && r <= y)
			return tr[t];
		int mid = l + r >> 1;
		if(y <= mid)
			return query(l, mid, x, y, t << 1);
		if(mid < x)
			return query(mid + 1, r, x, y, t << 1 | 1);
		return query(l, mid, x, y, t << 1) + query(mid + 1, r, x, y, t << 1 | 1);
	}
} tree;
node prelis[maxn], prelds[maxn], suflis[maxn], suflds[maxn];
int n, a[maxn];
void solve() {
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	tree.build(1, n, 1);
	tree.modify(1, n, 1, 1, node{0, 1});
	for (int i = 1; i <= n; i++) {
		prelis[i] = tree.query(1, n, 1, a[i], 1); prelis[i].mx++;
		tree.modify(1, n, a[i], 1, prelis[i]);
	}
	tree.build(1, n, 1);
	tree.modify(1, n, n, 1, node{0, 1});
	for (int i = 1; i <= n; i++) {
		prelds[i] = tree.query(1, n, a[i], n, 1); prelds[i].mx++;
		tree.modify(1, n, a[i], 1, prelds[i]);
	}
	tree.build(1, n, 1);
	tree.modify(1, n, 1, 1, node{0, 1});
	for (int i = n; i >= 1; i--) {
		suflis[i] = tree.query(1, n, 1, a[i], 1); suflis[i].mx++;
		tree.modify(1, n, a[i], 1, suflis[i]);
	}
	tree.build(1, n, 1);
	tree.modify(1, n, n, 1, node{0, 1});
	for (int i = n; i >= 1; i--) {
		suflds[i] = tree.query(1, n, a[i], n, 1); suflds[i].mx++;
		tree.modify(1, n, a[i], 1, suflds[i]);
	}
	node lis = {0, 0}, lds = {0, 0};
	for (int i = 1; i <= n; i++)
		lis = lis + prelis[i];
	for (int i = 1; i <= n; i++)
		lds = lds + prelds[i];
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if((prelis[i].mx + suflds[i].mx - 1 != lis.mx) || (prelds[i].mx + suflis[i].mx - 1 != lds.mx))
			continue;
	//	cout << i << " " << "Asd" << " " << prelis[i].mx << " " << suflds[i].mx << " " << prelds[i].mx << " " << suflis[i].mx << endl;
		ans += prelis[i].cnt * prelds[i].cnt % mod * suflis[i].cnt % mod * suflds[i].cnt % mod;
	}
	cout << (ans == lis.cnt * lds.cnt % mod ? lis.mx + lds.mx - 1 : lis.mx + lds.mx) << endl;
}
signed main() {
	int T; cin >> T;
	while(T--)
		solve();
	return 0;
}
/*
10 10
1 2 3 4 5 6 7 8 9 10
9 6
9 7
5 4
10 9
6 4
7 4
6 6
4 2
7 6
4 1
*/

详细

Test #1:

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

input:

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

output:

4
4
5

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 33ms
memory: 13900kb

input:

20000
2
2 1
10
6 10 2 7 9 3 8 4 1 5
9
3 6 4 5 8 9 2 7 1
7
3 7 6 4 1 5 2
7
7 2 3 6 5 1 4
5
4 1 3 2 5
9
6 7 5 3 8 1 9 2 4
3
1 2 3
8
7 2 4 6 1 8 3 5
7
4 2 6 3 1 7 5
8
1 7 3 4 2 5 6 8
2
1 2
10
10 2 3 8 6 9 1 4 7 5
4
3 2 1 4
9
7 5 3 4 1 2 9 6 8
7
2 4 5 1 6 7 3
10
3 1 10 4 9 5 6 8 2 7
5
1 2 5 3 4
6
2 6 5 ...

output:

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

result:

ok 20000 lines

Test #3:

score: -100
Wrong Answer
time: 63ms
memory: 13900kb

input:

20
895
97 29 511 535 178 149 710 846 37 191 684 504 309 528 524 189 659 42 337 688 213 343 859 433 606 445 693 608 232 585 577 313 759 746 612 341 480 875 610 222 28 637 11 91 796 261 296 333 377 871 275 552 788 371 763 862 522 322 447 126 492 694 799 620 842 394 434 706 460 479 240 241 676 502 749 ...

output:

115
165
332
171
112
204
247
227
239
114
231
242
57
229
371
243
347
121
62
352

result:

wrong answer 3rd lines differ - expected: '331', found: '332'