QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#693935#7904. Rainbow SubarrayczrqCompile Error//C++171.4kb2024-10-31 16:59:122024-10-31 16:59:25

Judging History

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

  • [2024-10-31 16:59:25]
  • 评测
  • [2024-10-31 16:59:12]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
const int M = 5e5 + 10;
long long t,n,k;
long long a[M];
multiset<long long> s1,s2;
long long sum1=0,sum2=0;
void adjust(){
	while(s1.size()>s2.size()+1){
		multiset<int>::iterator it=(--s1.end());
		sum2+=*it; sum1-=*it;
		s2.insert(*it);
		s1.erase(it);
	}
	while(s1.size()<s2.size()){
		multiset<int>::iterator it=s2.begin();
		sum1+=*it; sum2-=*it;
		s1.insert(*it); s2.erase(it);
	}
}
void add(int tmp){
	if(tmp>*s2.begin()){
		s2.insert(tmp);
		sum2+=tmp;
	}
	else {
		s1.insert(tmp); sum1+=tmp;
	}
	adjust();
}
void del(int tmp){
	multiset<int>::iterator it=s1.lower_bound(tmp);
	if(it!=s1.end()){
		s1.erase(it);
		sum1-=tmp;
	}
	else{
		it=s2.lower_bound(tmp); s2.erase(it);
		sum2-=tmp;
	}
	adjust();
}
void solve(){
	cin>>n>>k;
	s1.clear(); s2.clear(); sum1=sum2=0;
	for(int i=1;i<=n;i++){
		cin>>a[i]; a[i]-=i;
	}
	if(n==1) {
		cout<<1<<endl; return;
	}
	long long mid=a[1],sum=0,res=1;
	add(a[1]);
	for(int i=1,j=2;i<=j&&j<=n&&i<=n;i++){
		while(j<=n){
			add(a[j]); int tmp=*(s1.rbegin());
			sum=tmp*s1.size()-sum1+sum2-tmp*s2.size();
			//cout<<tmp<<" ";
			if(sum<=k&&j<=n) {
				res=max(res,j-i+1); j++;
			}
			else {
				del[a[j]];	break;
			}
			
			
		}
		del(a[i]);
	}
	cout<<res<<endl;
}
int main(){
	cin>>t;
	while(t--){
		solve();
	}
} 


 

详细

answer.code: In function ‘void adjust()’:
answer.code:11:45: error: conversion from ‘_Rb_tree_const_iterator<long long int>’ to non-scalar type ‘_Rb_tree_const_iterator<int>’ requested
   11 |                 multiset<int>::iterator it=(--s1.end());
      |                                            ~^~~~~~~~~~~
answer.code:14:25: error: no matching function for call to ‘std::multiset<long long int>::erase(std::multiset<int>::iterator&)’
   14 |                 s1.erase(it);
      |                 ~~~~~~~~^~~~
In file included from /usr/include/c++/13/set:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:158,
                 from answer.code:1:
/usr/include/c++/13/bits/stl_multiset.h:641:7: note: candidate: ‘std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::erase(const_iterator) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; iterator = std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator; const_iterator = std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator]’
  641 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/13/bits/stl_multiset.h:641:28: note:   no known conversion for argument 1 from ‘_Rb_tree_const_iterator<int>’ to ‘_Rb_tree_const_iterator<long long int>’
  641 |       erase(const_iterator __position)
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_multiset.h:671:7: note: candidate: ‘std::multiset<_Key, _Compare, _Alloc>::size_type std::multiset<_Key, _Compare, _Alloc>::erase(const key_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; size_type = long unsigned int; key_type = long long int]’
  671 |       erase(const key_type& __x)
      |       ^~~~~
/usr/include/c++/13/bits/stl_multiset.h:671:29: note:   no known conversion for argument 1 from ‘std::multiset<int>::iterator’ {aka ‘std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator’} to ‘const std::multiset<long long int>::key_type&’ {aka ‘const long long int&’}
  671 |       erase(const key_type& __x)
      |             ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_multiset.h:693:7: note: candidate: ‘std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::erase(const_iterator, const_iterator) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; iterator = std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator; const_iterator = std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator]’
  693 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/13/bits/stl_multiset.h:693:7: note:   candidate expects 2 arguments, 1 provided
answer.code:17:52: error: conversion from ‘_Rb_tree_const_iterator<long long int>’ to non-scalar type ‘_Rb_tree_const_iterator<int>’ requested
   17 |                 multiset<int>::iterator it=s2.begin();
      |                                            ~~~~~~~~^~
answer.code:19:41: error: no matching function for call to ‘std::multiset<long long int>::erase(std::multiset<int>::iterator&)’
   19 |                 s1.insert(*it); s2.erase(it);
      |                                 ~~~~~~~~^~~~
/usr/include/c++/13/bits/stl_multiset.h:641:7: note: candidate: ‘std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::erase(const_iterator) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; iterator = std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator; const_iterator = std::_Rb_tree<long long int, long long int, std::_Identity<long long int>, std::less<long long int>, std::allocator<long long int> >::const_iterator]’
  641 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/13/bits/stl_multiset.h:641:28: note:   no known conversion for argument 1 from ‘_Rb_tree_const_iterator<int>’ to ‘_Rb_tree_const_iterator<long long int>’
  641 |       erase(const_iterator __position)
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/13/bits/stl_multiset.h:671:7: note: candidate: ‘std::multiset<_Key, _Compare, _Alloc>::size_type std::multiset<_Key, _Compare, _Alloc>::erase(const key_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; size_type = long unsigned int; key_type = long long i...