제출 #306405

#제출 시각아이디문제언어결과실행 시간메모리
306405amunduzbaevArranging Shoes (IOI19_shoes)C++14
100 / 100
184 ms28536 KiB
#include "shoes.h" #include <bits/stdc++.h> //#include "grader.cpp" using namespace std; long long res[200010]; long long vis[200011], dp[200010]; vector <long long> a1[100002], b[100002]; const long long maxn=2e5+7; vector<long long> a; vector<long long> t(4*maxn); vector<long long> add(4*maxn,0); void push(long long v) { if(add[v]) { add[v*2]+=add[v]; add[v*2+1]+=add[v]; add[v]=0; } } void build(long long v,long long tl,long long tr) { if(tl==tr) { t[v]=a[tl]; } else { long long tm=(tl+tr)/2; build(v*2,tl,tm); build(v*2+1,tm+1,tr); } } long long get(long long v,long long tl,long long tr,long long pos) { if(tl==tr) { t[v]+=add[v]; add[v]=0; return t[v]; } else { long long tm=(tl+tr)/2; push(v); if(pos<=tm) { return get(v*2,tl,tm,pos); } else { return get(v*2+1,tm+1,tr,pos); } } } void Add(long long v,long long tl,long long tr,long long l,long long r,long long val) { if(l>r) { return; } if(tl==l && tr==r) { add[v]+=val; return; } else { long long tm=(tl+tr)/2; Add(v*2,tl,tm,l,min(r,tm),val); Add(v*2+1,tm+1,tr,max(tm+1,l),r,val); } } long long count_swaps(std::vector<int> s) { long long sum = 0; for(long long i = 0 ; i < s.size(); i++){ if(s[i]>0) a1[s[i]].push_back(i); else b[abs(s[i])].push_back(i); } for(long long i = 0 ; i <100001;i++){ for(long long j = 0 ; j < a1[i].size();j++){ dp[a1[i][j]]=b[i][j]; dp[b[i][j]]=a1[i][j]; } } long long n = s.size()+1; for(long long i = 0 ; i < s.size(); i++){ if(vis[i]==1) continue; long long j=i+1; sum += dp[i] - i - 1 + get(1,0,n-1,dp[i]) - get(1,0,n-1,i); Add(1,0,n,i,dp[i],1); if(s[i] > 0) sum++; vis[dp[i]]=1; } return sum; }

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:82:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for(long long i = 0 ; i < s.size(); i++){
      |                           ~~^~~~~~~~~~
shoes.cpp:89:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |         for(long long j = 0 ; j < a1[i].size();j++){
      |                               ~~^~~~~~~~~~~~~~
shoes.cpp:95:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |     for(long long i = 0 ; i < s.size(); i++){
      |                           ~~^~~~~~~~~~
shoes.cpp:99:19: warning: unused variable 'j' [-Wunused-variable]
   99 |         long long j=i+1;
      |                   ^
#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...