제출 #599219

#제출 시각아이디문제언어결과실행 시간메모리
599219SummersArranging Shoes (IOI19_shoes)C++14
100 / 100
89 ms34664 KiB
#include "shoes.h" #include<iostream> #include<vector> using namespace std; vector<long long>v[1000000]; long long fen[1000000]; void update(long long pos,long long val) { for(int i=pos;i<=1000000;i+=(i&-i)) { fen[i]+=val; } } long long sum(long long val) { long long ss=0; for(int i=val;i>0;i-=(i&-i)) { ss+=fen[i]; } return ss; } bool is[1000000]; long long count_swaps(std::vector<int> s) { long long i,j,n,res=0; n=s.size()/2; for(i=s.size()-1;i>=0;i--) { v[s[i]+n].push_back(i); update(i+1,1); } for(i=0;i<s.size();i++) { if(is[i])continue; is[i]=1; v[s[i]+n].pop_back(); long long pos=v[-s[i]+n][v[-s[i]+n].size()-1]; v[-s[i]+n].pop_back(); is[pos]=1; res+=sum(pos)-sum(i+1); update(pos+1,-1); if(s[i]>0)res++; } return res; }

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:34:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(i=0;i<s.size();i++)
      |             ~^~~~~~~~~
shoes.cpp:26:14: warning: unused variable 'j' [-Wunused-variable]
   26 |  long long i,j,n,res=0;
      |              ^
#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...