제출 #352356

#제출 시각아이디문제언어결과실행 시간메모리
352356David_MArranging Shoes (IOI19_shoes)C++14
컴파일 에러
0 ms0 KiB
//#include "shoes.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll f[300005],b[300005],c[300005],o=1,N;
void upd(int x){for(;x<=2*N;x+=x&(-x))f[x]+=o;}
ll get(int x, int Ans=0){for(;x;x-=x&(-x))Ans+=f[x];return Ans;}
long long count_swaps(vector<int> s){
	ll x,ans=0;
	map<ll, ll> a;
	N=(int)s.size()/2;
	for (int i=0; i<2*N; i++){
		c[s[i]+2*N]++;
		if(s[i]<0)s[i]=-(c[s[i]+2*N]<<20)+s[i];
		else s[i]=(c[s[i]+2*N]<<20)+s[i];
	}
	for (int i=0; i<2*N; i++)a[abs(s[i])]=i,upd(i+1); o=-1;
//	for (int i=0; i<2*N; i++)cout<<s[i]<<" ";
	for (int i=0; i<2*N; i++)if(!b[i+1])x=a[abs(s[i])]+1,b[x]=1,ans+=get(x-1)-get(i)-(s[i]<0),upd(x);
	return ans;
}
int main(){
	int n;
//	assert(1==scanf("%d", &n));
//	for (int i=0; i<2*n; i++)
//		assert(1 == scanf("%d", &S[i]));
	cin>>n;
	vector<int> S(2*n);
	for (int i=0; i<2*n; i++)
		cin>>S[i];
//	fclose(stdin);
	long long result = count_swaps(S);
	printf("%lld\n", result);
//	fclose(stdout);
	return 0;
}
/*
3
-2 2 2 -2 -2 2
*/

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:17:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   17 |  for (int i=0; i<2*N; i++)a[abs(s[i])]=i,upd(i+1); o=-1;
      |  ^~~
shoes.cpp:17:52: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   17 |  for (int i=0; i<2*N; i++)a[abs(s[i])]=i,upd(i+1); o=-1;
      |                                                    ^
/tmp/ccATH1wV.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccM85Z1U.o:shoes.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status