제출 #339407

#제출 시각아이디문제언어결과실행 시간메모리
339407KerimArranging Shoes (IOI19_shoes)C++17
10 / 100
4 ms5100 KiB
#include "bits/stdc++.h"
#include "shoes.h"
#define MAXN 100009
#define pb(x) push_back(x)
#define ppb() pop_back()
using namespace std;

int vis[MAXN],F[MAXN];
vector<int>a[MAXN],b[MAXN];
int get(int x){x++;int res=0;
	for(;x;x-=x&(-x))res+=F[x];
	return res;
}
void upd(int x){x++;
	for(;x<MAXN;x+=x&(-x))F[x]++;	
}
long long count_swaps(std::vector<int> s) {
	int n=s.size();long long ans=0;
	for(int i=n-1;i>=0;i--){
		if(s[i]>0)a[s[i]].pb(i);
		else b[-s[i]].pb(i);	
	}
	for(int i=0,j;i<n;i++){
		if(vis[i])continue;
		if(s[i]>0)j=b[s[i]].back();
		else j=a[-s[i]].back();vis[j]=1;
		a[abs(s[i])].ppb();b[abs(s[i])].ppb();
		ans+=(s[i]>s[j])+j-i-1;vis[j]=1;
		ans+=get(j)-get(i);upd(j);
		//for(int k=i+1;k<j;k++)ans-=vis[k];
	}return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:26:3: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
   26 |   else j=a[-s[i]].back();vis[j]=1;
      |   ^~~~
shoes.cpp:26:26: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
   26 |   else j=a[-s[i]].back();vis[j]=1;
      |                          ^~~
#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...