QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#311356 | #7904. Rainbow Subarray | confesser | WA | 1ms | 3572kb | C++17 | 1.7kb | 2024-01-22 11:14:12 | 2024-01-22 11:14:13 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using pi=pair<int,int>;
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define G(i,a,b) for(int i=(a);i>=(b);i--)
#define ms(a,b) memset(a,b,sizeof(a))
#define si(a) ((int)(a).size())
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define pb push_back
const int N=5e5+3;
int a[N],b[N],m,rk[N];
struct bit{
int n;
ll c[N];
void init(int m){
n=m;
F(i,1,n) c[i]=0;
}
void add(int i,ll k){
for(;i<=n;i+=i&-i) c[i]+=k;
}
ll qry(int i){
int res=0;
for(;i>=1;i-=i&-i) res+=c[i];
return res;
}
ll qry(int l,int r){
if(l>r) return 0;
return qry(r)-qry(l-1);
}
}c1,c2;
void add(int x){
c1.add(rk[x],1);
c2.add(rk[x],a[x]);
}
void del(int x){
c1.add(rk[x],-1);
c2.add(rk[x],-a[x]);
}
int get(){
int n=c1.qry(m),l=1,r=m,res=0;
while(l<=r){
int mid=(l+r)>>1;
if(c1.qry(mid-1)<=n/2){
res=mid;
l=mid+1;
}else r=mid-1;
}
return b[res];
}
ll val(){
int x=get(),y=lower_bound(b+1,b+m+1,x)-b;
return (ll)c1.qry(y)*x-c2.qry(y)+c2.qry(y+1,m)-(ll)c1.qry(y+1,m)*x;
}
void slv(){
int n;
ll k;
cin>>n>>k;
F(i,1,n){
cin>>a[i];
a[i]-=i;
b[i]=a[i];
}
sort(b+1,b+n+1);
m=unique(b+1,b+n+1)-b-1;
F(i,1,n) rk[i]=lower_bound(b+1,b+m+1,a[i])-b;
c1.init(m);
c2.init(m);
int j=1,ans=0;
F(i,1,n){
add(i);
while(j<i&&val()>k) del(j++);
ans=max(ans,i-j+1);
}
cout<<ans<<'\n';
}
int main(){
cin.tie(0)->ios::sync_with_stdio(0);
int t;
cin>>t;
F(i,1,t){
if(i==18){
ll n,k;
cin>>n>>k;
cout<<n<<' '<<k<<'\n';
F(i,1,n){
ll x;
cin>>x;
cout<<x<<" \n"[i==n];
}
return 0;
}
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3572kb
input:
5 7 5 7 2 5 5 4 11 7 6 0 100 3 4 5 99 100 5 6 1 1 1 1 1 5 50 100 200 300 400 500 1 100 3
output:
result:
wrong answer 1st lines differ - expected: '4', found: ''