QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#784162#9787. Shrek's Song of the Swamporz_zWA 2ms7732kbC++143.3kb2024-11-26 13:52:472024-11-26 13:52:57

Judging History

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

  • [2024-11-26 13:52:57]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:7732kb
  • [2024-11-26 13:52:47]
  • 提交

answer

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
//#pragma GCC optimize("Ofast,fast-math")
//#pragma GCC target("avx,avx2")
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
//#define int long long
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double db;
#define F(i, a, b) for(int i = a; i <= (b); ++i)
#define F2(i, a, b) for(int i = a; i < (b); ++i)
#define dF(i, a, b) for(int i = a; i >= (b); --i)
template<typename T> void debug(string s, T x) {
	cerr << "[" << s << "] = [" << x << "]\n";
}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {
	for (int i = 0, b = 0; i < (int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++;
	else if (s[i] == ')' || s[i] == '}') b--;
	else if (s[i] == ',' && b == 0) {
		cerr << "[" << s.substr(0, i) << "] = [" << x << "] | ";
		debug(s.substr(s.find_first_not_of(' ', i + 1)), args...);
		break;
	}
}
#ifdef orzz
#define Debug(...) debug(#__VA_ARGS__, __VA_ARGS__)
#else
#define Debug(...)
#endif
#define pb push_back
#define fi first
#define se second
#define Mry fprintf(stderr, "%.3lf MB\n", (&Med - &Mbe) / 1048576.0)
#define Try cerr << 1e3 * clock() / CLOCKS_PER_SEC << " ms\n";
typedef long long ll;
// namespace Fread {const int SIZE = 1 << 17; char buf[SIZE], *S, *T; inline char getchar() {if (S == T) {T = (S = buf) + fread(buf, 1, SIZE, stdin); if (S == T) return '\n';} return *S++;}}
// namespace Fwrite {const int SIZE = 1 << 17; char buf[SIZE], *S = buf, *T = buf + SIZE; inline void flush() {fwrite(buf, 1, S - buf, stdout), S = buf;} inline void putchar(char c) {*S++ = c;if (S == T) flush();} struct NTR {~NTR() {flush();}} ztr;}
// #ifdef ONLINE_JUDGE
// #define getchar Fread::getchar
// #define putchar Fwrite::putchar
// #endif
inline int ri() {
	int x = 0;
	bool t = 0;
	char c = getchar();
	while (c < '0' || c > '9') t |= c == '-', c = getchar();
	while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
	return t ? -x : x;
}
inline void wi(int x) {
	if (x < 0) {
		putchar('-'), x = -x;
	}
	if (x > 9) wi(x / 10);
	putchar(x % 10 + 48);
}
inline void wi(int x, char s) {
	wi(x), putchar(s);
}
bool Mbe;
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3f;
const int _ = 2e5 + 5;

int n, a[_], b[_], f[_][2], lst[_], w[_];

bool Med;
signed main() {
	// Mry;
	n = ri();
	F(i, 1, n) a[i] = ri();
	F(i, 1, n) b[i] = a[i];
	sort(b + 1, b + n + 1);
	int t = unique(b + 1, b + n + 1) - b- 1;
	F(i, 1, n) a[i] = lower_bound(b + 1, b + t + 1, a[i]) - b;
	memset(f, -0x3f, sizeof f);
	f[0][0] = 0;
	int ans = 0;
	F(i, 1, n) {
		f[i][1] = ans + 1;
		if(lst[a[i]])
			f[i][0] = max(f[i][0], w[a[i]] + 1);
//		F(j, 0, i - 1) if(a[j] != a[i]) {
//			f[i][1] = max(f[i][1], f[j][0] + 1);
//		} else {
//			f[i][0] = max(f[i][0], max(f[j][0], f[j][1]) + 1);
//		}
		lst[a[i]] = i;
		w[a[i]] = max(w[a[i]], max(f[i][0], f[i][1]));
		ans = max(ans, f[i][0]);
	}
	cout << ans << '\n';
	// Try;
	return 0;
}

/*
9
1 2 3 1 3 1 2 3 2

6
3 4 10 1 -3 5

4
1 2 1 1
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5924kb

input:

9
1 2 3 1 3 1 2 3 2

output:

5

result:

ok 1 number(s): "5"

Test #2:

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

input:

6
3 4 10 1 -3 5

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 1ms
memory: 7720kb

input:

4
1 2 1 1

output:

3

result:

ok 1 number(s): "3"

Test #4:

score: 0
Accepted
time: 1ms
memory: 5616kb

input:

9
1 2 3 1 3 1 2 3 2

output:

5

result:

ok 1 number(s): "5"

Test #5:

score: 0
Accepted
time: 1ms
memory: 7728kb

input:

6
3 4 10 1 -3 5

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 0
Accepted
time: 1ms
memory: 5684kb

input:

4
1 2 1 1

output:

3

result:

ok 1 number(s): "3"

Test #7:

score: -100
Wrong Answer
time: 2ms
memory: 6476kb

input:

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

output:

0

result:

wrong answer 1st numbers differ - expected: '463867', found: '0'