QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#374777#8316. Random PermutationPetroTarnavskyi#Compile Error//C++202.8kb2024-04-02 18:01:392024-04-02 18:01:40

Judging History

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

  • [2024-04-02 18:01:40]
  • 评测
  • [2024-04-02 18:01:39]
  • 提交

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 INF = 1e9 + 47;

struct Segtree
{
	int n;
	vector<PII> t;
	
	void init(int _n)
	{
		n = 1;
		while (n < _n) n*= 2;
		t.assign(2 * n - 1, MP(-1, -1));
	}
	
	void upd(int v, int tl, int tr, int pos, int val)
	{
		if (tl + 1 == tr)
		{
			t[v] = {val, pos};
			return;
		}
		int tm = (tl + tr) / 2;
		if (pos < tm)
			upd(v * 2 + 1, tl, tm, pos, val);
		else
			upd(v * 2 + 2, tm, tr, pos, val);
		t[v] = max(t[v * 2 + 1], t[v * 2 + 2]);
	}
	
	void upd(int pos, int val)
	{
		upd(0, 0, n, pos, val);
	}
	
	int query(int v, int tl, int tr, int l, int r, int k)
	{
		if (tl + 1 == tr)
			return t[v].S;
		int tm = (tl + tr) / 2;
		int left = t[v * 2 + 1].F;
		if (left >= k)
			return query(v * 2 + 1, tl, tm, l, r, k);
		else
			return query(v * 2 + 2, tm, tr, l, r, k);
	}
	
	int query(int l, int r, int k)
	{
		return query(0, 0, n, l, r, k);
	}
	
} st;

struct Fenwick
{
	int n;
	vector<LL> t;
	
	void init(int _n)
	{
		n = _n;
		t.clear();
		t.assign(n, 0);
	}
	
	void upd(int i, int x)
	{
		for (; i < n; i |= i + 1)
			t[i] += x;
	}
	
	LL query(int i)
	{
		LL ans = 0;
		for (; i >= 0; i = (i & (i + 1)) - 1)
			ans += t[i];
		return ans;
	}
} fn;

const int N = 400'447;

map<int, int> idxInSet;
set<int> s[N];
int c[N];
int v[N];

void add(int pos)
{
	if (!idxInSet.count(c[pos]))
		idxInSet[c[pos]] = SZ(idxInSet);
	int idx = idxInSet[c[pos]];
	auto it = s[idx].lower_bound(pos);
	if (it != s[idx].end())
		st.upd(*it, pos);
	int prev = -1;
	if (it != s[idx].begin())
	{
		it--;
		prev = *it;
	}
	st.upd(pos, prev);
	s[idx].insert(pos);
	fn.upd(pos, v[pos]);
}

void erase(int pos)
{
	int idx = idxInSet[c[pos]];
	auto it = s[idx].erase(pos);
	int pr = -1;
	if (it != s[idx].begin())
		pr = *prev(it);
	if (it != s[idx].end())
		st.upd(*it, pr);
	fn.upd(pos, -v[pos]);
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	st.init(n + 1);
	st.upd(n, INF);
	fn.init(n);
	FOR (i, 0, n)
	{
		cin >> c[i] >> v[i];
		add(i);
	}
	FOR (i, 0, m)
	{
		int t;
		cin >> t;
		if (t == 1)
		{
			int x, C, V;
			cin >> x >> C >> V;
			x--;
			erase(x);
			c[x] = C;
			v[x] = V;
			add(x);
		}
		else
		{
			int s, k;
			cin >> s >> k;
			s--;
			LL ans = 0;
			int idx = s;
			FOR (i, 0, k)
			{
				if (idx == n)
					break;
				int j = st.query(idx, n, s);
				
			}
		}
	}
	
	return 0;
}

详细

answer.code: In function ‘void erase(int)’:
answer.code:130:16: error: no match for ‘operator!=’ (operand types are ‘long unsigned int’ and ‘std::set<int>::iterator’ {aka ‘std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator’})
  130 |         if (it != s[idx].begin())
      |             ~~ ^~ ~~~~~~~~~~~~~~
      |             |                 |
      |             long unsigned int std::set<int>::iterator {aka std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator}
In file included from /usr/include/c++/13/regex:68,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:181,
                 from answer.code:1:
/usr/include/c++/13/bits/regex.h:1274:5: note: candidate: ‘template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator==(const sub_match<_BiIter>&, __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)’ (reversed)
 1274 |     operator==(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/13/bits/regex.h:1274:5: note:   template argument deduction/substitution failed:
answer.code:130:32: note:   ‘std::set<int>::iterator’ {aka ‘std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator’} is not derived from ‘const std::__cxx11::sub_match<_BiIter>’
  130 |         if (it != s[idx].begin())
      |                                ^
/usr/include/c++/13/bits/regex.h:1441:5: note: candidate: ‘template<class _Bi_iter> bool std::__cxx11::operator==(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type*)’ (reversed)
 1441 |     operator==(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/13/bits/regex.h:1441:5: note:   template argument deduction/substitution failed:
answer.code:130:32: note:   ‘std::set<int>::iterator’ {aka ‘std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator’} is not derived from ‘const std::__cxx11::sub_match<_BiIter>’
  130 |         if (it != s[idx].begin())
      |                                ^
/usr/include/c++/13/bits/regex.h:1613:5: note: candidate: ‘template<class _Bi_iter> bool std::__cxx11::operator==(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type&)’ (reversed)
 1613 |     operator==(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/13/bits/regex.h:1613:5: note:   template argument deduction/substitution failed:
answer.code:130:32: note:   ‘std::set<int>::iterator’ {aka ‘std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator’} is not derived from ‘const std::__cxx11::sub_match<_BiIter>’
  130 |         if (it != s[idx].begin())
      |                                ^
In file included from /usr/include/c++/13/bits/stl_algobase.h:67,
                 from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51:
/usr/include/c++/13/bits/stl_iterator.h:534:5: note: candidate: ‘template<class _IteratorL, class _IteratorR> constexpr bool std::operator==(const reverse_iterator<_IteratorL>&, const reverse_iterator<_IteratorR>&) requires requires{{std::operator==::__x->base() == std::operator==::__y->base()} -> decltype(auto) [requires std::convertible_to<<placeholder>, bool>];}’ (reversed)
  534 |     operator==(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/13/bits/stl_iterator.h:534:5: note:   template argument deduction/substitution failed:
answer.code:130:32: note:   ‘std::set<int>::iterator’ {aka ‘std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator’} is not derived from ‘const std::reverse_iterator<_IteratorL>’
  130 |         if (it != s[idx].begin())
      |                                ^
/usr/include/c++/13/bits/stl_iterator.h:1678:5: note: candidate: ‘template<class _IteratorL, class _IteratorR> constexpr bool std::operator==(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&) requires requires{{std::operator==::__x->base() == std::operator==::__y->base()} -> decltype(auto) [requires std::convertible_to<<placeholder>, bool>];}’ (reversed)
 1678 |     operator==(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/13/bits/stl_iterator.h:1678:5: note:   template argument deduction/substitution failed:
answer.code:130:32: note:   ‘std::set<int>::iterator’ {aka ‘std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator’} is not derived from ‘const std::move_iterator<_IteratorL>’
  130 |         if (it != s[idx].begin())
      |                                ^
In file included from /usr/include/c++/13/string:43,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52:
/usr/include/c++/13/bits/allocator.h:237:5...