# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
228164 | blacktulip | 콤보 (IOI18_combo) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "shoes.h"
using namespace std;
typedef long long lo;
typedef pair< lo,lo > PII;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(lo i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;
lo a[li],cev,hak[li],hak1[li],butun,butun1,farkli,farkli1,vis1[li],yer,tree[li*4],lazy[4*li];
vector<int> vv;
map<lo ,lo > vis;
vector<lo> sag[li];
vector<lo> sol[li];
vector<lo> vec;
inline void push(int node,int start,int end){
if(lazy[node]==0)return ;
tree[node]+=lazy[node];
if(start!=end){
lazy[node*2]+=lazy[node];
lazy[node*2+1]+=lazy[node];
}
lazy[node]=0;
}
inline void update(int node,int start,int end,int l,int r){
push(node,start,end);
if(start>end || start>r || end<l)return ;
if(start>=l && end<=r){
lazy[node]+=1;
push(node,start,end);
return ;
}
update(node*2,start,mid,l,r),update(node*2+1,mid+1,end,l,r);
tree[node]=tree[node*2]+tree[node*2+1];
}
inline int query(int node,int start,int end,int l,int r){
if(start>end || start>r || end<l)return 0;
push(node,start,end);
if(start>=l && end<=r){
return tree[node];
}
return query(node*2,start,mid,l,r)+query(node*2+1,mid+1,end,l,r);
}
long long count_swaps(vector<int> v) {
for(int i=0;i<(int)v.size();i++){
vec.pb(v[i]);
}
v.clear();
v.pb(0);
for(int i=0;i<(int)vec.size();i++){
v.pb(vec[i]);
}
for(lo i=1;i<=(lo)v.size();i++){
//~ vis[i]=vis[i-1]+vis[i];
if(v[i]<0){
if((lo)sag[-v[i]].size()-hak[-v[i]]>0){
cev+=i-sag[-v[i]][hak[-v[i]]]-query(1,1,v.size(),sag[-v[i]][hak[-v[i]]],sag[-v[i]][hak[-v[i]]])+query(1,1,v.size(),i,i);;
//~ cout<<cev<<" "<<query(0,0,v.size(),0,0)<<endl;
update(1,1,v.size(),sag[-v[i]][hak[-v[i]]],i);
//~ cout<<cev<<" "<<query(0,0,v.size(),0,0)<<endl;
hak[-v[i]]++;
}
else{sol[-v[i]].pb(i);}
}
else{
if((lo)sol[v[i]].size()-hak1[v[i]]>0){
cev+=i-sol[v[i]][hak1[v[i]]]-1-query(1,1,v.size(),sol[v[i]][hak1[v[i]]],sol[v[i]][hak1[v[i]]])+query(1,1,v.size(),i,i);
update(1,1,v.size(),sol[v[i]][hak1[v[i]]]+1,i);
hak1[v[i]]++;
}
else{sag[v[i]].pb(i);}
}
}
return cev;
}