/ WOJ /

记录详情

Compile Error

foo.cc: In function ‘void Main()’:
foo.cc:13:15: error: invalid use of template-name ‘std::vector’ without an argument list
   13 |         const vector v = {a, b};
      |               ^~~~~~
foo.cc:13:15: note: class template argument deduction is only available with ‘-std=c++17’ or ‘-std=gnu++17’
In file included from /nix/gcc/include/c++/15.2.0/vector:68,
                 from /nix/gcc/include/c++/15.2.0/queue:69,
                 from /nix/gcc/include/c++/15.2.0/x86_64-unknown-linux-gnu/bits/stdc++.h:160,
                 from /nix/gcc/include/c++/15.2.0/x86_64-unknown-linux-gnu/bits/extc++.h:32,
                 from foo.cc:1:
/nix/gcc/include/c++/15.2.0/bits/stl_vector.h:458:11: note: ‘template<class _Tp, class _Alloc> class std::vector’ declared here
  458 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
foo.cc:14:23: error: ‘v’ was not declared in this scope
   14 |         const int n = v.size();
      |                       ^

代码

#include <bits/extc++.h>
#define endl '\n'
typedef long long ll;
#define int ll
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

void Main()
{
	int a, b;
	cin >> a >> b;
	const vector v = {a, b};
	const int n = v.size();
	vector<int> tr(n << 2), tg(n << 2);
	auto pu = [&](const int p) { tr[p] = tr[p << 1] + tr[p << 1 | 1]; };
	auto at = [&](const int rt, const int l, const int r, const int x)
	{
		tg[rt] += x;
		tr[rt] += (r - l + 1) * x;
	};
	auto pd = [&](const int rt, const int l, const int r)
	{
		if (tg[rt])
		{
			const int mid = (l + r) >> 1;
			at(rt << 1, l, mid, tg[rt]);
			at(rt << 1 | 1, mid + 1, r, tg[rt]);
			tg[rt] = 0;
		}
	};
	function<void(int, int, int)> bld = [&](const int rt, const int l, const int r)
	{
		if (l == r)
		{
			tr[rt] = v[l - 1];
			return;
		}
		const int mid = (l + r) >> 1;
		bld(rt << 1, l, mid);
		bld(rt << 1 | 1, mid + 1, r);
		pu(rt);
	};
	function<void(int, int, int, int, int, int)> upt =
		[&](const int rt, const int l, const int r, const int s, const int t, const int x)
	{
		if (s <= l && r <= t)
		{
			at(rt, l, r, x);
			return;
		}
		pd(rt, l, r);
		const int mid = (l + r) >> 1;
		if (s <= mid)
		{
			upt(rt << 1, l, mid, s, t, x);
		}
		if (t > mid)
		{
			upt(rt << 1 | 1, mid + 1, r, s, t, x);
		}
		pu(rt);
	};
	function<int(int, int, int, int, int)> query = [&](const int rt, const int l, const int r, const int s, const int t)
	{
		if (s <= l && r <= t)
		{
			return tr[rt];
		}
		pd(rt, l, r);
		const int mid = (l + r) >> 1;
		int res = 0;
		if (s <= mid)
		{
			res += query(rt << 1, l, mid, s, t);
		}
		if (t > mid)
		{
			res += query(rt << 1 | 1, mid + 1, r, s, t);
		}
		return res;
	};
	bld(1, 1, n);
	cout << query(1, 1, n, 1, n) << endl;
}

// #define CP_MULTI_TEST_CASES

signed main()
{
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	int t = 1;
#ifdef CP_MULTI_TEST_CASES
	cin >> t;
#endif
	while (t--)
	{
		Main();
	}
	return cout << flush, fflush(stdout), 0;
}

信息

递交者
类型
递交
题目
P1004 A+B Problem 非常规解法
题目数据
下载
语言
C++
递交时间
2026-05-05 15:40:44
评测时间
2026-05-07 17:45:38
评测机
分数
0
总耗时
0ms
峰值内存
0 Bytes