QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#226870#5159. Justice ServedFyind#WA 138ms7944kbC++231.2kb2023-10-26 17:33:012023-10-26 17:33:01

Judging History

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

  • [2023-10-26 17:33:01]
  • 评测
  • 测评结果:WA
  • 用时:138ms
  • 内存:7944kb
  • [2023-10-26 17:33:01]
  • 提交

answer

#include <bits/stdc++.h>
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
typedef long long ll;
using namespace std;



int main() {
	int n;
	cin >> n;
	vector<pair<pair<int, int>, int>> a(n + 1);
	for (int i = 1; i <= n; ++i) {
		int s, t;
		cin >> s >> t;
		a[i] = mp(mp(s, t), i);
	}
	sort(a.begin() + 1, a.end(), [](pair<pair<int, int>, int> x, pair<pair<int, int>, int> y) {
		return x.fi.fi == y.fi.fi ? x.fi.se > y.fi.se : x.fi.fi < y.fi.fi;
	});

	vector<int> c;
	for (int i = 1; i <= n; ++i) 
		c.push_back(a[i].fi.se);
	sort(c.begin(), c.end());
	c.erase(unique(c.begin(), c.end()), c.end());
	int m = c.size();
	vector<int> d(m + 1);

	auto ask = [&](int pos) {
		pos = m - pos + 1;
		int ret = 0;
		for (; pos; pos -= (pos & -pos))
			ret = max(ret, d[pos]);
		return ret;
	};
	auto mod = [&](int pos, int val) {
		pos = m - pos + 1;
		for (; pos <= m; pos += (pos & -pos))
			d[pos] = max(d[pos], val);
	};

	vector<int> ans(n + 1);
	for (int i = 1; i <= n; ++i) {
		int r = lower_bound(c.begin(), c.end(), a[i].fi.se) - c.begin() + 1;
		ans[a[i].se] = ask(r) + 1;
		mod(r, ans[a[i].se]);
	}
	for (int i = 1; i <= n; ++i)
		cout << ans[i] - 1 << ' ';
	cout << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
2 8
1 7
4 5
5 2

output:

0 0 1 2 

result:

ok single line: '0 0 1 2 '

Test #2:

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

input:

5
2 4
3 3
2 2
4 2
4 1

output:

0 1 1 2 3 

result:

ok single line: '0 1 1 2 3 '

Test #3:

score: -100
Wrong Answer
time: 138ms
memory: 7944kb

input:

200000
75760147 173015388
62879760 211229046
6728658 106668560
29476341 129401393
30531505 130450085
39792769 139780734
59486082 221617335
12447225 112582555
94207716 117434450
68962063 193352291
13519090 113644734
60611935 218232526
77901558 166662816
40316254 140281744
39094390 138994435
49921965 ...

output:

51067 25775 6 14 12 14 19015 9 88306 37703 9 21158 55423 15 13 16 12 24879 15 7 8 45768 24224 14 11 55424 9 7 12683 15 65167 14 1 33107 19 20827 81112 10 1963 98792 89739 13 95821 44266 89326 16 8 16 4 8131 16033 8 9 90497 70197 36711 14 15 46836 39837 38641 13 53674 7 16 4 15 18 12 83782 15935 9 4 ...

result:

wrong answer 1st lines differ - expected: '51062 25770 5 10 10 12 19010 7...59 9 12 84254 91909 88054 9 7 7', found: '51067 25775 6 14 12 14 19015 9...4 14 84259 91914 88059 14 12 8 '