이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sequence.h"
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include <cassert>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
#include <cstdlib>
#include <cstdint>
using namespace std;
#define ll long long
#define f first
//#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
const int mxn=5e5,lg=24;
int mx=0;
struct fen{
//using fenwick cus i dont wanna write slding median
int fwk[mxn+10];
vector<pii>keep;
void update(int pos,int val){
keep.pb({pos,val});
for(int i=pos;i<=mx;i+=(i&-i))fwk[i]+=val;
}
int qry(int pos){
if(pos==0)return 0;
int sum=0;
for(int i=pos;i>0;i-=(i&-i))sum+=fwk[i];
return sum;
}
void re(){
for(auto i:keep)for(int j=i.f;j<=mx;j+=(j&-j))fwk[j]+=-i.s;
keep.clear();
}
int get(int x){
x++;
int pos=0,sum=0;
for(int i=lg;i>=0;i--){
if(pos+(1LL<<i)<=mx&&fwk[pos+(1LL<<i)]+sum<x){
pos+=(1LL<<i);
sum+=fwk[pos];
}
}
return pos+1;
}
}t;
int sequence(int n, vector<int>v){
for(auto i:v)mx=max(mx,i);
int ans=0;
for(int i=0;i<n;i++){
t.re();
for(int j=i;j<n;j++){
t.update(v[j],1);
int x=t.get((j-i)/2);
ans=max(ans,t.qry(x)-t.qry(x-1));
if((j-i)%2){
x++;
ans=max(ans,t.qry(x)-t.qry(x-1));
}
}
}
return ans;
}
/*
int32_t main(){
int n;cin>>n;
vector<int>v(n);
for(int i=0;i<n;i++)cin>>v[i];
cout<<sequence(n,v);
}*/
/*
7
1 2 3 1 2 1 3
*/
/*
constraint of being a medain
A number of number <x,B number of number >x,C number of number ==x
if C>=A+B
if A+C>=B && C<=A+B
if A+B>=c && B<=A+C
i might be wrong
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |