QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#316422 | #7904. Rainbow Subarray | gingoo | Compile Error | / | / | C++20 | 7.4kb | 2024-01-27 20:42:29 | 2024-01-27 20:42:29 |
Judging History
你现在查看的是最新测评结果
- [2024-06-09 00:00:26]
- hack成功,自动添加数据
- (/hack/652)
- [2024-01-27 20:42:29]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2024-01-27 20:42:29]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
typedef int ld;
const int mod=1e9+7;
// struct point
// {
// ld x, y;
// point operator + (const point &a) const
// {
// return {x + a.x, y + a.y};
// }
// point operator - (const point &a) const
// {
// return {x - a.x, y - a.y};
// }
// point operator * (const ld &a) const
// {
// return {x * a, y * a};
// }
// };
// struct line
// {
// point s, t;
// };
// ld sqr(ld x) { return x * x; }
// // // const ld eps = 1e-9;
// // int sgn(ld x) { return x > eps ? 1 : -eps ? -1
// // : 0; }
// ld dot(const point &a, const point &b)
// {
// return a.x * b.x + a.y * b.y;
// }
// ld det(const point &a, const point &b)
// {
// return a.x * b.y - a.y * b.x;
// }
// bool point_on_line(const point &a, const line &l){
// return (det(l.s - a, a - l.t)) == 0;
// }
// bool pol(const point &a,const point &b,const point &c){
// return (a.y-b.y)*(b.x-c.x)==(b.y-c.y)*(a.x-b.x);
// }
// vector<point> v;
// map<point,int> mp;
// int n;
// bool dfs(vector<point> &v1,int now){
// if(v1.size()<=now)return 1;
// for(int i=0;i<=now;i++){
// for(int j=i+1;j<=now;j++){
// vector<point> v2;
// for(auto p:v1){
// if(!point_on_line(p,(line){v1[i],v1[j]})){
// v2.push_back(p);
// }
// }
// if(dfs(v2,now-1))return 1;
// }
// }
// return 0;
// }
typedef long long ll;
set<ll> s1,s2;
ll a[500500];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--){
ll n,k;
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>a[i-1];
}
s1.clear();s2.clear();
int l=0,r=0;
ll sum1=0,sum2=0;
int ans=0;
ll now=a[0];
while(l<=r){
if(l==a.size())break;
while(sum1-now*s1.size()+now*s2.size()-sum2<=k){
ll now1,now2;
if(r==a.size()-1)break;
// int flag1=0,,flag2=0;
r++;
if(s1.empty() and s2.empty()){
if(a[r]>=now)s1.insert(a[r]),sum1+=a[r];
else s2.insert(a[r]),sum2+=a[r];
continue;
}
else if(s1.empty()){
if(a[r]>=now)s1.insert(a[r]),sum1+=a[r];
else s1.insert(now),sum1+=now,now=a[r];
continue;
}
else if(s2.empty()){
if(a[r]<=now)s2.insert(a[r]),sum2+=a[r];
else s2.insert(now),sum2+=now,now=a[r];
continue;
}
now1=*s1.begin(),s1.erase(s1.find(now1)),sum1-=now1;
now2=*s2.rbegin(),s2.erase(s2.find(now2)),sum2-=now2;
int cnt=r-l+1;
if(a[r]>=now1){
s1.insert(a[r]),sum1+=a[r];
if(cnt%2){
//s1.insert(now1),sum1+=now1;
//s2.insert(now2),sum2+=now2;
if(s1.size()>s2.size()){
s2.insert(now2),sum2+=now2;
s2.insert(now),sum2+=now;
now=now1;
}
else{
s1.insert(now1),sum1+=now1;
s2.insert(now2),sum2+=now2;
}
}
else{
s1.insert(now1),sum1+=now1;
s2.insert(now2),sum2+=now2;
}
}
else if(a[r]<=now2){
s2.insert(a[r]),sum2+=a[r];
if(cnt%2){
//s1.insert(now1),sum1+=now1;
//s2.insert(now2),sum2+=now2;
if(s1.size()<s2.size()){
s1.insert(now1),sum1+=now1;
s1.insert(now),sum1+=now;
now=now2;
}
else{
s1.insert(now1),sum1+=now1;
s2.insert(now2),sum2+=now2;
}
}
else{
s1.insert(now1),sum1+=now1;
s2.insert(now2),sum2+=now2;
}
}
else if(a[r]<=now and a[r]>=now2){
s2.insert(now2),sum2+=now2;
if(cnt%2){
//s1.insert(now1),sum1+=now1;
//s2.insert(now2),sum2+=now2;
if(s1.size()<s2.size()){
s1.insert(now1),sum1+=now1;
s1.insert(now),sum1+=now;
now=a[r];
}
else{
s1.insert(now1),sum1+=now1;
s2.insert(a[r]),sum2+=a[r];
}
}
else{
s1.insert(now1),sum1+=now1;
s2.insert(a[r]),sum2+=a[r];
}
}
else if(a[r]>=now and a[r]<=now1){
s1.insert(now1),sum1+=now1;
if(cnt%2){
//s1.insert(now1),sum1+=now1;
//s2.insert(now2),sum2+=now2;
if(s1.size()>s2.size()){
s2.insert(now2),sum2+=now2;
s2.insert(now),sum2+=now;
now=a[r];
}
else{
s1.insert(now1),sum1+=now1;
s2.insert(a[r]),sum2+=a[r];
}
}
else{
s1.insert(now1),sum1+=now1;
s2.insert(a[r]),sum2+=a[r];
}
}
}
//r--;
//ans=max(r-l+1,ans)
if(sum1-now*s1.size()+now*s2.size()-sum2<=k)ans=max(r-l+1,ans);
else ans=max(r-l,ans);
int l1=l;
if(a[l]>now){
if(!s1.empty()){
auto p=s1.find(a[l]);
s1.erase(p);sum1-=a[l];
}
else now=a[l+1],l1++;
}
else if(a[l]<now){
if(!s2.empty()){
auto p=s2.find(a[l]);
s2.erase(p);sum2-=a[l];
}
else now=a[l+1],l1++;
}
else{
if(!s2.empty()){
now=*s2.rbegin();
s2.erase(s2.find(now));
sum2-=now;
}
else if(!s1.empty()){
now=*s1.begin();
s1.erase(s1.find(now));
sum1-=now;
}
else now=a[l+1];
}
l++;
}
cout<<ans<<'\n';
}
return 0;
}
详细
answer.code: In function ‘int main()’: answer.code:83:21: error: request for member ‘size’ in ‘a’, which is of non-class type ‘ll [500500]’ {aka ‘long long int [500500]’} 83 | if(l==a.size())break; | ^~~~ answer.code:86:25: error: request for member ‘size’ in ‘a’, which is of non-class type ‘ll [500500]’ {aka ‘long long int [500500]’} 86 | if(r==a.size()-1)break; | ^~~~