이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fst first
#define snd second
#define pb push_back
#define forn(i,a,b) for(int i = a; i < b; i++)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define dbg(v) cout<<"Line("<<__LINE__<<"): "<<#v<<" = "<<v<<'\n';
#define pi pair<int,int>
#define pll pair<ll,ll>
#define oper(a,b) (a+b)
#define NEUT 0
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_multiset;
ll n;
vector<ll> a;
struct STree { // segment tree for min over integers
vector<int> st;int n;
STree(int n): st(4*n+5,NEUT), n(n) {}
void upd(int k, int s, int e, int p, int v){
if(s+1==e){st[k]=v;return;}
int m=(s+e)/2;
if(p<m)upd(2*k,s,m,p,v);
else upd(2*k+1,m,e,p,v);
st[k]=oper(st[2*k],st[2*k+1]);
}
int query(int k, int s, int e, int a, int b){
if(s>=b||e<=a)return NEUT;
if(s>=a&&e<=b)return st[k];
int m=(s+e)/2;
return oper(query(2*k,s,m,a,b),query(2*k+1,m,e,a,b));
}
void upd(int p, int v){upd(1,0,n,p,v);}
int query(int a, int b){return query(1,0,n,a,b);}
};
int sequence(int N, std::vector<int> A) {
n=N;
a.clear();
a.resize(n);
forn(i,0,n) a[i]=A[i];
ll res = 0;
STree stree(n);
vector<vector<ll>> p;
set<ll> vals;
map<ll,ll> cI;
forn(i,0,n) vals.insert(a[i]);
ll ind = 0;
for(auto i:vals) cI[i]=ind,ind++;
p.resize(SZ(cI));
forn(i,0,n) p[cI[a[i]]].pb(i);
ll men = 0;
ll may = 0;
ll igu = 0;
ll ini = 0;
forn(i,0,SZ(p)){
men=0; may = 0; igu = 0;
ini = 0;
//cout<<"-> "<<i<<":\n";
forn(j,0,SZ(p[i])){
stree.upd(p[i][j],1);
}
forn(j,0,n){
if(cI[a[j]]==i) igu++;
men=stree.query(ini,j+1);
may=((j+1)-ini)-men;
while(may>men){
/*cout<<" "<<p[i][ini]<<" "<<p[i][j]<<": "<<'\n';
cout<<" "<<men<<" "<<igu<<" "<<may<<'\n'; */
if(cI[a[ini]]==i)igu--;
ini++;
men=stree.query(ini,j+1);
may=((j+1)-ini)-men;
}
/*cout<<" "<<p[i][ini]<<" "<<p[i][j]<<": "<<'\n';
cout<<" "<<men<<" "<<igu<<" "<<may<<'\n'; */
/*cout<<" "<<ini<<" "<<j<<": "<<'\n';
cout<<" "<<men<<" "<<igu<<" "<<may<<'\n';*/
res = max(res,igu);
}
}
return res;
}
# | 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... |