제출 #932948

#제출 시각아이디문제언어결과실행 시간메모리
932948velislavgarkovArranging Shoes (IOI19_shoes)C++14
100 / 100
46 ms20824 KiB
#include "shoes.h" #include <iostream> #include <vector> using namespace std; const int MAXN=2e5+10; vector <int> idx[MAXN][2]; int lef[MAXN], fen[MAXN]; bool sw[MAXN]; int n; void update(int ind, int ch) { if (ind==0) return; while (ind<n) { fen[ind]+=ch; ind+=(ind & (-ind)); } } int query(int ind) { if (ind==0) return 0; int res=0; while (ind>0) { res+=fen[ind]; ind-=(ind & (-ind)); } return res; } long long count_swaps(vector<int> s) { n=s.size(); for (int i=0;i<n;i++) { if (s[i]<0) idx[-s[i]][0].push_back(i); else idx[s[i]][1].push_back(i); lef[i]=-1; sw[i]=false; } for (int i=0;i<n;i++) { if (idx[i][0].empty()) continue; for (int j=0;j<idx[i][0].size();j++) { if (idx[i][0][j]<idx[i][1][j]) lef[idx[i][1][j]]=idx[i][0][j]; else { lef[idx[i][0][j]]=idx[i][1][j]; sw[idx[i][0][j]]=true; } } } long long ans=0; for (int i=1;i<n;i++) { if (lef[i]==-1) update(i,1); else { long long s=query(i-1)-query(lef[i]); s+=sw[i]; ans+=s; update(lef[i],1); } } return ans; }

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:36:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |   for (int j=0;j<idx[i][0].size();j++) {
      |                ~^~~~~~~~~~~~~~~~~
#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...