제출 #537309

#제출 시각아이디문제언어결과실행 시간메모리
537309ERHArranging Shoes (IOI19_shoes)C++14
컴파일 에러
0 ms0 KiB
#include <iostream>
#include <vector>
using namespace std;
vector<int> lista[100001][2];
int temp[100001];
long long count_swaps(vector<int> v){
  long long int total=0;
  for(int i=0; i<v.size(); ++i){
    int a=v[i];
    if(a<0){
      a=-a;
      if(!lista[a][0].empty()){
        int temp1=i+1, temp2=lista[a][0].front();
        for(int j=i+1; j>0; j-=j&-j){
          temp1+=temp[j];
        }
        temp1+=temp[0];
        for(int j=lista[a][0].front(); j>0; j-=j&-j){
          temp2+=temp[j];
        }
        temp2+=temp[0];
        total+=temp1-temp2;
        for(int j=lista[a][0].front(); j<100001; j+=j&-j){
          temp[j]++;
        }
        for(int j=i+1; j<100001; j+=j&-j){
          temp[j]--;
        }
        lista[a][0].erase(lista[a][0].begin());
      } else {
        lista[a][1].push_back(i+1);
      }
    } else {
      if(!lista[a][1].empty()){
        int temp1=i+1, temp2=lista[a][1].front();
        for(int j=i+1; j>0; j-=j&-j){
          temp1+=temp[j];
        }
        temp1+=temp[0];
        for(int j=lista[a][1].front(); j>0; j-=j&-j){
          temp2+=temp[j];
        }
        temp2+=temp[0];
        total+=temp1-temp2;
        total--;
        for(int j=lista[a][1].front(); j<100001; j+=j&-j){
          temp[j]++;
        }
        for(int j=i+1; j<100001; j+=j&-j){
          temp[j]--;
        }
        lista[a][1].erase(lista[a][1].begin());
      } else {
        lista[a][0].push_back(i+1);
      }
    }
  }
  return total;
}
int main(){
  cout<<count_swaps({2, 2, -2, -2});
}

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:8:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |   for(int i=0; i<v.size(); ++i){
      |                ~^~~~~~~~~
/usr/bin/ld: /tmp/cc4OxEDX.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cczq0MHX.o:shoes.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status