QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#770054#9742. 优秀的拆分SymmetreeCompile Error//C++202.3kb2024-11-21 20:26:532024-11-21 20:26:54

Judging History

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

  • [2024-11-21 20:26:54]
  • 评测
  • [2024-11-21 20:26:53]
  • 提交

answer

#include<bits/stdc++.h>
// f[i] = max(f[j]) + 1
const int N = 2e5+5;
using i64 = long long;
using i128 = __int128;
int n, c[N], p[N], f[2][N], g[2][N]; i64 d[N], cntf[2][N], cntg[2][N];
void add(int x, int k, i64 cnt) {
	for(; x <= n; x += x&-x) {
		if(c[x] < k) c[x] = k, d[x] = cnt;
		else if(c[x] == k) d[x] += cnt;
	}
}
int ask1(int x) {
	int ans = 0;
	for(; x; x -= x&-x) ans = std::max(ans, c[x]);
	return ans;
}
i64 ask2(int x) {
	i64 ans = 1; int now = 0;
	for(; x; x -= x&-x) {
		if(now < c[x]) ans = d[x], now = c[x];
		else if(now == c[x]) ans += d[x];
	}
	return ans;
}
void calc(int f[], i64 cntf[]) {
	for(int i = 1; i <= n; ++i) c[i] = d[i] = 0;
	for(int i = 1; i <= n; ++i) {
		f[i] = ask1(p[i]) + 1;
		cntf[i] = ask2(p[i]);
		add(p[i], f[i], cntf[i]);
	}
}
void solve() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%d", &p[i]);
	
	// for(int i = 1; i <= n; ++i) printf("%d %lld\n", c[i], d[i]);
	// for(int i = 1 ; i <= n; ++i) printf("%d %lld\n", f[0][i], cntf[0][i]);
	calc(f[0], cntf[0]);
	std::reverse(p + 1, p + n + 1);
	calc(g[1], cntg[1]);
	std::reverse(g[1] + 1, g[1] + n + 1);
	std::reverse(cntg[1] + 1, cntg[1] + n + 1);
	for(int i = 1; i <= n; ++i) p[i] = n + 1 - p[i];
	calc(f[1], cntf[1]);
	std::reverse(f[1] + 1, f[1] + n + 1);
	std::reverse(cntf[1] + 1, cntf[1] + n + 1);
	std::reverse(p + 1, p + n + 1);
	calc(g[0], cntg[0]);
	// for(int i = 1; i <= n; ++i) printf("%d %lld %d %lld\n", f[0][i], cntf[0][i], f[1][i], cntf[1][i]);
	// puts("");
	// for(int i = 1; i <= n; ++i) printf("%d %lld %d %lld\n", g[0][i], cntg[0][i], g[1][i], cntg[1][i]);
	int LIS = 0, LDS = 0;
	for(int i = 1; i <= n; ++i) {
		LIS = std::max(LIS, f[0][i]);
		LDS = std::max(LDS, g[0][i]);
	}
	i64 numi = 0, numd = 0, num = 0;
	for(int i = 1; i <= n; ++i) {
		if(f[0][i] == LIS) numi += cntf[0][i];
		if(g[0][i] == LDS) numd += cntg[0][i];
		if(f[0][i] + f[1][i] - 1 == LIS && g[0][i] + g[1][i] - 1 == LDS) {
			num += cntf[0][i] * cntf[1][i] * cntg[0][i] * cntg[1][i];
		}
	}
	assert(numi >= 0), assert(numd >= 0), assert(num >= 0);
	std::cerr << numi << " " << numd << " " << num << endl;
	if(numi * numd == num) printf("%d\n", LIS + LDS - 1);
	else printf("%d\n", LIS + LDS);
}
signed main() {
	int t;
	scanf("%d", &t);
	while(t--) solve();
	return 0;
}

详细

answer.code: In function ‘void solve()’:
answer.code:68:59: error: ‘endl’ was not declared in this scope; did you mean ‘std::endl’?
   68 |         std::cerr << numi << " " << numd << " " << num << endl;
      |                                                           ^~~~
      |                                                           std::endl
In file included from /usr/include/c++/13/bits/unique_ptr.h:42,
                 from /usr/include/c++/13/memory:78,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:56,
                 from answer.code:1:
/usr/include/c++/13/ostream:735:5: note: ‘std::endl’ declared here
  735 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
answer.code:35:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
answer.code:36:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |         for(int i = 1; i <= n; ++i) scanf("%d", &p[i]);
      |                                     ~~~~~^~~~~~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:74:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   74 |         scanf("%d", &t);
      |         ~~~~~^~~~~~~~~~