제출 #158389

#제출 시각아이디문제언어결과실행 시간메모리
158389nickmet2004Arranging Shoes (IOI19_shoes)C++14
0 / 100
157 ms136696 KiB
#include<bits/stdc++.h> //#include<shoes.h> using namespace std; const int NAX = 1e5 + 5; const int l = 1e5 + 5; int N; // fenwick tree to count range sums (+0 , +1 , +2) int f[2 * NAX + 1]; void update(int idx , int u){ ++idx; while(idx <= N){ f[idx] += u; idx += idx & (-idx); } } long long sum(int idx){ long long sum = 0; ++idx; while(idx){ sum += f[idx]; idx -= idx & (-idx); } return sum; } queue<int> q[NAX]; long long count_swaps(vector<int> S){ N = S.size(); long long ans = 0; // update BIT for(int i = 0; i < N; ++i){ update(i , 1); } for(int i = 0; i < N; ++i){ int x = abs(S[i]); int k = S[i]; if(!q[i + l].empty()){ ans += (sum(i) - (q[i + l].front() - 1) - 1); if(k > 0){ --ans; } update(i , -1); update(q[i + l].front() , 1); } else { // q[i * -1 + l] because its opposite is the same as the next x // i * -1 + l == next_x(i + l) q[i * -1 + l].push(i); } } return ans; }

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:40:13: warning: unused variable 'x' [-Wunused-variable]
         int x = abs(S[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...