QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#861948#9982. Staircase Museumucup-team191#WA 13ms5736kbC++232.2kb2025-01-18 20:47:562025-01-18 20:49:30

Judging History

This is the latest submission verdict.

  • [2025-01-18 20:49:30]
  • Judged
  • Verdict: WA
  • Time: 13ms
  • Memory: 5736kb
  • [2025-01-18 20:47:56]
  • Submitted

answer

#include <bits/stdc++.h>
#define X first
#define Y second
#define PB push_back
#define x first
#define y second
#define pb push_back
#define all(a) begin(a),end(a)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
using pii=pair<int,int>;

const int N = 5e5 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
const char en='\n';
const ll LLINF=1ll<<60;

int t,n,l[N],r[N];

int an1()
{
	set<pii> sr,sl;
	sr.insert({0,l[0]});
	for (int i=1;i<n;++i) if (r[i]!=r[i-1]) sr.insert({i,r[i-1]});
	sl.insert({0,l[0]});
	for (int i=1;i<n;++i) if (l[i]!=l[i-1]) sl.insert({i,l[i]});
	int odg=sl.size()+sr.size();
	for (auto x: sr)
	{
		while (sl.size() && sl.begin()->x<x.x) sl.erase(sl.begin());
		if (sl.size() && sl.begin()->y<=x.y) --odg,sl.erase(sl.begin());
	}
	return odg;
}

int an2()
{
	set<pii> sr,sl;
	sr.insert({0,l[0]});
	for (int i=1;i<n;++i) if (r[i]!=r[i-1]) sr.insert({i,r[i-1]});
	sl.insert({n,l[n-1]});
	for (int i=1;i<n;++i) if (l[i]!=l[i-1]) sl.insert({i,l[i-1]});
	int odg=sl.size()+sr.size();
	for (auto x: sr)
	{
		while (sl.size() && sl.begin()->x<x.x) sl.erase(sl.begin());
		if (sl.size() && sl.begin()->y<=x.y) --odg,sl.erase(sl.begin());
	}
	return odg;
}

int an3()
{
	set<pii> sr,sl;
	sr.insert({0,r[0]});
	for (int i=1;i<n;++i) if (r[i]!=r[i-1]) sr.insert({i,r[i]});
	sl.insert({0,l[0]});
	for (int i=1;i<n;++i) if (l[i]!=l[i-1]) sl.insert({i,l[i]});
	int odg=sl.size()+sr.size();
	for (auto x: sr)
	{
		while (sl.size() && sl.begin()->x<x.x) sl.erase(sl.begin());
		if (sl.size() && sl.begin()->y<=x.y) --odg,sl.erase(sl.begin());
	}
	return odg;
}

int an4()
{
	set<pii> sr,sl;
	sr.insert({0,r[0]});
	for (int i=1;i<n;++i) if (r[i]!=r[i-1]) sr.insert({i,r[i]});
	sl.insert({n,l[n-1]});
	for (int i=1;i<n;++i) if (l[i]!=l[i-1]) sl.insert({i,l[i-1]});
	int odg=sl.size()+sr.size();
	for (auto x: sr)
	{
		while (sl.size() && sl.begin()->x<x.x) sl.erase(sl.begin());
		if (sl.size() && sl.begin()->y<=x.y) --odg,sl.erase(sl.begin());
	}
	return odg;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>t;
	while (t--)
	{
		cin>>n;
		for (int i=0;i<n;++i) cin>>l[i]>>r[i];
		cout<<max(max(an1(),an2()),max(an3(),an4()))<<en;
	}
}

詳細信息

Test #1:

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

input:

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

output:

2
3
3
4

result:

ok 4 number(s): "2 3 3 4"

Test #2:

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

input:

1
1
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: -100
Wrong Answer
time: 13ms
memory: 5736kb

input:

9653
1
1 1
2
1 1
1 1
3
1 1
1 1
1 1
4
1 1
1 1
1 1
1 1
5
1 1
1 1
1 1
1 1
1 1
6
1 1
1 1
1 1
1 1
1 1
1 1
6
1 2
1 2
1 2
1 2
1 2
2 2
6
1 1
1 1
1 1
1 1
1 1
1 2
6
1 2
1 2
1 2
1 2
1 2
2 3
5
1 2
1 2
1 2
1 2
2 2
6
1 2
1 2
1 2
1 2
2 2
2 2
6
1 3
1 3
1 3
1 3
2 3
3 3
6
1 2
1 2
1 2
1 2
2 2
2 3
6
1 3
1 3
1 3
1 3
2 3...

output:

1
1
1
1
1
1
2
2
2
2
2
3
3
3
2
2
2
3
3
3
3
2
2
3
3
3
3
3
2
2
2
3
3
3
3
3
4
4
4
3
3
3
4
4
4
4
3
3
4
4
4
4
4
2
2
2
2
3
3
3
3
3
3
2
2
3
3
3
3
3
3
3
3
3
3
4
4
3
3
4
4
4
4
3
3
3
4
4
3
3
4
4
4
4
3
3
4
4
4
3
3
4
4
4
4
4
2
2
2
3
3
3
3
3
3
3
3
3
4
4
4
4
4
4
4
3
3
3
4
4
3
3
4
4
4
4
3
3
4
4
4
4
4
4
4
4
4
3
3
4
...

result:

wrong answer 20th numbers differ - expected: '2', found: '3'