제출 #1114615

#제출 시각UTC-0아이디문제언어결과실행 시간메모리
11146152024-11-19 08:59:41lftroqArranging Shoes (IOI19_shoes)C++14
100 / 100
239 ms273736 KiB
#include<bits/stdc++.h>
#include "shoes.h"
typedef long long ll;
using namespace std;
const int N=200005;
int n;
queue<int> ql[N],qr[N];
int bit[N];
void update(int x,int v){for(;x<=n;x+=(x&(-x))) bit[x]+=v;}
int get(int x){int ans=0;for(;x;x-=(x&(-x))) ans+=bit[x];return ans;}
long long count_swaps(std::vector<int> s) {
ll ans=0;
n=(int)s.size();
for(int i=0;i<(int)s.size();i++)
{
if(s[i]<0)
{
s[i]*=-1;
if(qr[s[i]].empty()) ql[s[i]].push(i+1);
else
{
int x=qr[s[i]].front();
int temp=get(x);
ans+=i-x+1-temp;
update(x,1);
update(i+2,-1);
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...