제출 #952754

#제출 시각아이디문제언어결과실행 시간메모리
952754batsukh2006Arranging Shoes (IOI19_shoes)C++17
25 / 100
237 ms277372 KiB
#include<iostream> #include<stdio.h> #include<math.h> #include<map> #include<string> #include<algorithm> #include<vector> #include<string.h> #include<utility> #include<set> #include<cmath> #include<queue> #include<deque> #include<functional> #include<stack> #include<limits.h> #include<iomanip> #include<unordered_map> #include "shoes.h" using namespace std; const int mxN=2e5; vector<int> tree(4*mxN); int cal(int node, int L, int R, int l, int r){ if(L>r||R<l) return 0; if(L>=l&&R<=r) return tree[node]; return cal(node*2,L,(L+R)/2,l,r)+cal(node*2+1,(L+R)/2+1,R,l,r); } void up(int node, int L, int R, int l, int r){ if(L>r||R<l) return; if(L==R){ tree[node]=1; return; } up(node*2,L,(L+R)/2,l,r); up(node*2+1,(L+R)/2+1,R,l,r); tree[node]=tree[node*2]+tree[node*2+1]; } long long count_swaps(vector<int> s){ vector<int> p(s.size()); vector<stack<int> > v(s.size()+s.size()+1); for(int i=s.size()-1; i>=0; i--){ v[s[i]+s.size()].push(i); } for(int i=0,j=0; i<s.size(); i++){ if(!v[s[i]+s.size()].empty()){ if(s[i]<0){ p[j]=i; j++; p[j++]=v[-s[i]+s.size()].top(); v[s[i]+s.size()].pop(); v[-s[i]+s.size()].pop(); }else{ p[j++]=v[-s[i]+s.size()].top(); p[j]=i; v[s[i]+s.size()].pop(); v[-s[i]+s.size()].pop(); j++; } } } long long ans=0; for(int i=0; i<p.size(); i++){ ans+=cal(1,0,s.size(),p[i],s.size()); up(1,0,s.size(),p[i],p[i]); } return ans; } // signed main(){ // // freopen("hps.in", "r", stdin); // // freopen("hps.out", "w", stdout); // ios::sync_with_stdio(0); // cin.tie(0); // cout.tie(0); // int t=1; // // cin>>t; // while(t--){ // cout<<endl; // } // return 0; // }

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

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