제출 #877074

#제출 시각아이디문제언어결과실행 시간메모리
877074raul2008487Arranging Shoes (IOI19_shoes)C++17
0 / 100
0 ms348 KiB
#include "shoes.h" #include<bits/stdc++.h> #define ll long long #define pb push_back #define all(v) v.begin(), v.end() #define fi first #define se second #define in insert using namespace std; const int sz = 2e5+5; ll Tree[sz]; void add(ll pos, ll val){ for(ll i = pos; i<sz ; i += (i & (-i))){ Tree[i] += val; } } ll get(ll pos){ ll rx = 0; for(ll i = pos; i>0; i -= (i & (-i))){ rx += Tree[i]; } return rx; } ll ask(ll l, ll r){ return get(r) - get(l-1); } long long count_swaps(vector<int> s) { ll n = s.size(), i, j, ans = 0; set<pair<int,int>> c; for(i=0;i<n;i++){ c.in({s[i], i}); add(i+1, 1); } for(i=0;i<n;i++){ if(c.find({s[i], i}) == c.end()){continue;} ll ix = (*c.lower_bound({-s[i], i})).se; if(ix >= (i+2)){ ans += ask(i+2, ix); } if(s[i] > 0){ ans++; } add(i+1, -1); add(ix+1, -1); c.erase({s[i], i}); c.erase({-s[i], i}); } return ans; }

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:28:22: warning: unused variable 'j' [-Wunused-variable]
   28 |  ll n = s.size(), i, j, ans = 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...