제출 #390122

#제출 시각아이디문제언어결과실행 시간메모리
390122ioiArranging Shoes (IOI19_shoes)C++14
50 / 100
224 ms206952 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std ; const int N = 3e5 ; int add = 1e5 + 5 ; queue<int> pos[N]; int done[N] ; struct BIT{ int sz ; vector<long long> v; explicit BIT(int n){ sz = n ; v.resize(n); } long long get(int i){ long long ret = 0 ; for(i ++ ; i ; i -=(i & -i)) ret += v[i - 1]; return ret ; } void update(int i , long long val){ for(i ++ ; i <= sz ; i += (i & -i)) v[i - 1] += val ; } long long query(int l , int r){ return get(r) - get(l - 1); } }; long long count_swaps(vector<int> s) { for(int i = 0 ; i < s.size() ; i ++){ pos[s[i] + add].push(i); } BIT bit(s.size()); int ans = 0 ; for(int i = 0 ; i < s.size() ; i ++){ if(done[i])continue ; int p = pos[-s[i] + add].front(); pos[-s[i] + add].pop(); done[p] ++; pos[s[i] + add].pop(); // cout << i << " " << p << endl ; ans += p - i - 1 - bit.query( i, p) + (s[i] > 0 ? 1 : 0); bit.update(p , 1); } return ans; }

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

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