萌新求助代码细节
查看原帖
萌新求助代码细节
532268
ayzhr435619楼主2024/10/15 23:30
#include<bits/stdc++.h>
#define AC 0
#define D(x) cout<<#x<<": "<<x<<'\n'
#define De(x) cout<<#x<<": "<<x<<' '
#define IOS ios::sync_with_stdio(false), cin.tie(), cout.tie()
#define RE register
#define ll long long
#define fst first
#define scd second
#define mkp make_pair
#define pii pair<int,int>
#define inl inline
#define up(l,r,i) for(RE int i=l,END##i=r;i<=END##i;i=-~i)
#define dn(r,l,i) for(RE int i=r,END##i=l;i>=END##i;i=~-i)
#define mems(a, x) memset((a), (x), sizeof(a))
#define eb emplace_back
#define Open(s) freopen(s".in","r",stdin);freopen(s".out","w",stdout);
#define enter putchar('\n')
#define space putchar(' ')
#define ctn continue
#define brk break
using namespace std;
inline int min(int a, int b){return a < b ? a : b;}
inline int max(int a, int b){return a > b ? a : b;}
inline int gcd(int a, int b){return b == 0 ? a : gcd(b, a % b);}
inline int lcm(int a, int b){return a / gcd(a, b) * b;}
inline int ksm(int a, int m){int ans = 1;while(m) {if (m & 1) ans *= a;a *= a;m >>= 1;}return ans;}
inline int ksm(int a, int m, int p){int ans = 1;while(m) { if(m & 1) ans = (ans * a) % p;a = (a * a) % p;m >>= 1;}return ans;}
inline bool Isprime(int x){if(x <= 1) return false;for(RE int i = 2; i * i <= x; i = -~i) if(x % i == 0) return false;return true;}
const int MAXSIZE = 1 << 20;
char buf[MAXSIZE], *p1, *p2;
#define gc() getchar()
//#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? EOF : *p1++)
inline void read(double& rdx) {double t = 0;int x = 0, s = 0, f = 1;char c;do c = gc();while (!isdigit(c) && c != '-' && c != '.');if (c == '-')f = -1, c = gc();while (isdigit(c) && c != '.') x = (c ^ 48) + (x << 1) + (x << 3), c = gc();if (c == '.') c = gc();else {rdx =  x * f;return;}while (c >= '0' && c <= '9') t = t * 10 + (c ^ 48), s = -~s, c = gc();while (s--) t /= 10;rdx = (x + t) * f;}
inline void read(char& ch) {ch = gc();while (ch == ' ' || ch == '\n') ch = gc();}
inline int read() {int x = 0;bool f = 1;char ch = gc();while (!isdigit(ch)) f = ch == '-' ? 0 : 1, ch = gc();while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc();return f ? x : -x;}
inline void write(int x) {if(x < 0){putchar('-'), x = -x;}static int sta[50];int top = 0;do {sta[top++] = x % 10, x /= 10;} while (x);while (top) putchar(sta[--top] + 48);}
const int N = 5e5 + 7, inf = 0x3fffffff, mod = 1e9 + 7;
int n;
int a[N];
int dp[N][2];
int maxx, mixx;
int l[N][2];
int ans = 0;
signed main() {
	n = read();
	up(1, n, i) a[i] = read();
	dp[0][1] = -1;
	up(1, n, i){
		dp[i][1] = 1;
		if(dp[l[a[i]][1]][1] & 1) dp[i][0] = dp[l[a[i]][1]][1] + 1;
		if(maxx != a[i]){
			dp[i][1] = max(dp[i][1], dp[l[maxx][0]][0] + 1);
		}
		else{
			dp[i][1] = max(dp[i][1], dp[l[mixx][0]][0] + 1);
		}
		if(dp[l[a[i]][0]][0] < dp[i][0]) l[a[i]][0] = i;
		if(dp[l[a[i]][1]][1] < dp[i][1]) l[a[i]][1] = i;
		if(dp[l[maxx][0]][0] <= dp[i][0]){//这里
			if(maxx != a[i]) mixx = maxx;
			maxx = a[i];
		}
		else{
			if(dp[l[mixx][0]][0] <= dp[i][0]){//这里
				mixx = a[i];
			}
		}
		ans = max(ans, dp[i][0]);
	}
	cout << ans;
	return AC;
}

为什么标“这里”的地方 "<="是100分,改成“<”是25分?

2024/10/15 23:30
加载中...