QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#374903#8313. Nim CheaterPetroTarnavskyiCompile Error//C++202.0kb2024-04-02 19:24:542024-04-02 19:24:54

Judging History

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

  • [2024-04-02 19:24:54]
  • 评测
  • [2024-04-02 19:24:54]
  • 提交

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 double db;

const int LEN = 1 << 14;
const int LOG = 16;
int dp[LEN * LOG];

const int N = 20'001;
const int INF = 1e9 + 47;
VI g[N];
int q[2 * N];
int ans[N];
int c[N];
int val[N];
int idx[N];
int cnt[N];
set<int> ind;
int sz = 1;

void recalc(int i, int j, int v)
{
	FOR (k, 0, LEN)
	{
		dp[i * LEN + k] = min(dp[j * LEN + k], dp[j * LEN + (k ^ c[v])] + val[v]);
	}
}

void dfsSZ(int v)
{
	cnt[v] = 1;
	for (auto to : g[v])
	{
		dfsSZ(to);
		cnt[v] += cnt[to];
	}
}

void dfsSolve(int v, int xr = 0)
{
	ans[v] = dp[idx[v] * LEN + xr];
	if (g[v].empty())
		return;
	sort(ALL(g[v]), [&](int i, int j)
	{
		return cnt[i] < cnt[j];
	});
	int id = idx[v];
	FOR (i, 0, SZ(g[v]) - 1)
	{
		int to = g[v][i];
		idx[to] = *ind.begin();
		ind.erase(idx[to]);
		recalc(idx[to], id, to);
		dfsSolve(to, xr ^ c[to]);
		ind.insert(idx[to]);
	}
	int to = g[v].back();
	idx[to] = *ind.begin();
	ind.erase(idx[to]);
	recalc(idx[to], id, to);
	ind.insert(id);
	dfsSolve(to, xr ^ c[to]);
	ind.insert(idx[to]);
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	cerr << sizeof(cnt) * 8 + sizeof(dp)  << '\n';
	int n;
	cin >> n;
	{
		stack<int> s;
		s.push(0);
		FOR (i, 0, n)
		{
			string t;
			cin >> t;
			if (t == "ADD")
			{
				cin >> c[sz] >> val[sz];
				g[s.top()].PB(sz);
				s.push(sz);
				sz++;			
			}
			else
			{
				s.pop();
			}
			q[i] = s.top();
		}
	}
	idx[0] = 0;
	fill(dp[0] + 1, dp[0] + LEN, INF);
	FOR (i, 1, LOG)
		ind.insert(i);
	dfsSZ(0);
	dfsSolve(0);
	FOR (i, 0, n)
	{
		cout << ans[q[i]] << '\n';
	}
	
	return 0;
}

Details

In file included from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from answer.code:1:
/usr/include/c++/13/bits/stl_algobase.h: In instantiation of ‘constexpr typename __gnu_cxx::__enable_if<std::__is_scalar<_Tp>::__value, void>::__type std::__fill_a1(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = int; _Tp = int; typename __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type = void]’:
/usr/include/c++/13/bits/stl_algobase.h:977:21:   required from ‘constexpr void std::__fill_a(_FIte, _FIte, const _Tp&) [with _FIte = int; _Tp = int]’
/usr/include/c++/13/bits/stl_algobase.h:1007:20:   required from ‘constexpr void std::fill(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = int; _Tp = int]’
answer.code:111:6:   required from here
/usr/include/c++/13/bits/stl_algobase.h:931:9: error: invalid type argument of unary ‘*’ (have ‘int’)
  931 |         *__first = __tmp;
      |         ^~~~~~~~