QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#377872#8281. Pangu and StonesPetroTarnavskyi#WA 0ms3480kbC++202.6kb2024-04-05 19:05:042024-04-05 19:05:05

Judging History

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

  • [2024-04-05 19:05:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3480kb
  • [2024-04-05 19:05:04]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef double db;

const LL LINF = 1e18;
vector<LL> a;

pair<PLL, set<LL>> f(int i)
{
	LL l = -LINF;
	LL r = LINF;
	set<LL> bad;
	FOR (j, 0, 3)
		FOR (k, j + 1, 3)
			if (a[i + j] == a[i + k])
				bad.insert(a[i + j]);
	if ((a[i] <= a[i + 1] && a[i + 1] <= a[i + 2]) && 
		(a[i] >= a[i + 1] && a[i + 1] >= a[i + 2]))
	{
			return {{l, r}, bad};
	}
	if (a[i] >= a[i + 1] && a[i] >= a[i + 2] && a[i + 1] <= a[i + 2])
	{
		LL mid = (a[i] + a[i + 1]) / 2;
		LL L = -LINF;
		LL R = mid;
		bad.insert(mid);
		r = min(r, R);
		l = max(l, L);
	}
	if (a[i] >= a[i + 1] && a[i] <= a[i + 2] && a[i + 1] <= a[i + 2])
	{
		LL m1 = (a[i] + a[i + 1]) / 2;
		LL m2 = (a[i + 2] + a[i + 1]) / 2;
		bad.insert(m1);
		bad.insert(m2);
		LL L = -LINF;
		LL R = m2;
		r = min(r, R);
		l = max(l, L);
	}
	if (a[i] <= a[i + 1] && a[i] <= a[i + 2] && a[i + 1] >= a[i + 2])
	{
		LL m1 = (a[i] + a[i + 1]) / 2;
		LL m2 = (a[i + 2] + a[i + 1]) / 2;
		bad.insert(m1);
		bad.insert(m2);
		LL L = m1;
		LL R = LINF;
		r = min(r, R);
		l = max(l, L);
	}
	if (a[i] <= a[i + 1] && a[i] >= a[i + 2] && a[i + 1] >= a[i + 2])
	{
		LL mid = (a[i + 1] + a[i + 2]) / 2;
		LL L = mid;
		LL R = LINF;
		bad.insert(mid);
		r = min(r, R);
		l = max(l, L);
	}
	return MP(MP(l, r), bad);
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	a.resize(n);
	FOR (i, 0, n)
	{
		cin >> a[i];
		a[i] *= 2;
	}
		
	multiset<LL> L, R, off;
	L.insert(-LINF);
	R.insert(LINF);
	LL ans = 0;
	int j = 2;
	map<LL, int> m;
	m[a[0]]++;
	m[a[1]]++;
	FOR (i, 0, n - 2)
	{
		while(j < i + 2 && j < n)
		{
			m[a[j]]++;
			j++;
		}
		while (j < n)
		{
			auto [p, bad] = f(j - 2);
			LL l = max(p.F, *L.rbegin());
			LL r = min(p.S, *R.begin());
			if (m[a[j]] >= 2 || r < l || (r == l && (off.find(l) != off.end() || bad.count(l))))
				break;
			L.insert(p.F);
			R.insert(p.S);
			off.insert(ALL(bad));
			m[a[j]]++;
			j++;
		}
		ans += j - i - 1;
		if(j > i + 2)
		{
			auto [p, bad] = f(i);
			L.erase(L.find(p.F));
			R.erase(R.find(p.S));
			m[a[i]]--;
			for (auto b : bad)
				off.erase(off.find(b));
		}
	}
	cout << ans + 1 << '\n';
	
	return 0;	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3480kb

input:

3 2 2
1 2 3

output:

3

result:

wrong answer 1st numbers differ - expected: '9', found: '3'