QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#379535#8567. Cheap Constructionucup-team027#WA 180ms3792kbC++231.6kb2024-04-06 17:48:062024-04-06 17:48:07

Judging History

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

  • [2024-04-06 17:48:07]
  • 评测
  • 测评结果:WA
  • 用时:180ms
  • 内存:3792kb
  • [2024-04-06 17:48:06]
  • 提交

answer

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;

void solve() {
	int n; cin >> n;
	vector<int> p(n);
	Tree<int> pos;
	for (int i = 0; i < n; i++) {
		pos.insert(i);
	}

	vector<pair<int, int>> inp(n);
	for (int i = 0; i < n; i++) {
		cin >> inp[i].first >> inp[i].second;
		inp[i].first--;
	}
	reverse(inp.begin(), inp.end());

	for (auto [pp, h]: inp) {
		int ps = *pos.find_by_order(pp);
		pos.erase(pos.find_by_order(pp));
		p[ps] = h;

		//cout << ps << '\n';
	}

	//for (int i: p) cout << i << ' ';
	//cout << '\n';

	vector<int> dp;
	vector<vector<int>> lis;
	for (int i = n-1; i >= 0; i--) {
		auto it = upper_bound(dp.begin(), dp.end(), p[i]);
		int id = it - dp.begin();
		if (it == dp.end()) {
			dp.push_back(p[i]);
			lis.push_back(vector<int>(0));
		}
		dp[id] = p[i];
		lis[id].push_back(p[i]);
	}

	/*
	for (auto v: lis) {
		for (int i: v) cout << i << ' ';
		cout << '\n';
	}
	*/

	int cursz = 0;
	while (lis[0].size()) {
		int sz = cursz + 1;
		for (int i = 0; i < lis.size(); i++) {
			if (lis[i].empty()) break;
			cout << sz << ' ' << lis[i].back() << '\n';
			lis[i].pop_back();
			cursz++;
		}
	}
}

signed main() {
	ios::sync_with_stdio(0); cin.tie(0);
	
	int t; cin >> t;
	while (t--) {
		solve();
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
3
1 1
2 2
1 3

output:

1 1
1 3
3 2

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

2
3
1 1
1 2
3 1
3
1 3
2 1
3 3

output:

1 1
1 1
1 2
1 1
1 3
3 3

result:

ok 6 lines

Test #3:

score: -100
Wrong Answer
time: 180ms
memory: 3648kb

input:

1000
500
1 25
2 115
2 356
4 396
5 417
3 416
1 376
8 302
5 475
8 134
5 470
2 191
9 443
9 483
7 311
6 415
14 422
6 288
9 411
9 318
18 406
20 213
16 292
8 351
8 150
20 199
3 311
22 321
22 221
16 364
7 316
17 79
23 160
23 369
6 209
36 9
35 490
2 498
30 391
31 175
10 322
16 484
4 63
44 304
39 300
13 309
...

output:

1 2
1 2
1 6
1 6
1 6
1 15
1 15
1 25
1 31
1 40
1 40
1 55
1 57
1 63
1 65
1 68
1 68
1 102
1 144
1 149
1 150
1 161
1 167
1 168
1 180
1 197
1 224
1 227
1 229
1 252
1 258
1 267
1 301
1 362
1 367
1 368
1 375
1 376
1 393
1 459
1 474
1 498
43 9
43 6
43 8
43 13
43 9
43 23
43 23
43 27
43 45
43 50
43 48
43 60
43...

result:

wrong answer 3rd lines differ - expected: '1 40', found: '1 6'