제출 #1036894

#제출 시각아이디문제언어결과실행 시간메모리
1036894DeathIsAweArranging Shoes (IOI19_shoes)C++14
100 / 100
116 ms141976 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; #define ll long long ll segment[524288]; void update(ll a, ll b) { a += 262144; b += 262144; while (a <= b) { if (a % 2 == 1) {segment[a++]++;} if (b % 2 == 0) {segment[b--]++;} a /= 2; b /= 2; } } ll give(ll a) { ll total = a; a += 262144; while (a > 0) { total += segment[a]; a /= 2; } return total; } long long count_swaps(vector<int> s) { for (int i=0;i<524288;i++) { segment[i] = 0; } ll n = s.size(), shift = *max_element(s.begin(), s.end()), ans = 0; vector<deque<ll>> positions(2 * shift + 1); for (int i=0;i<n;i++) { if (shift - s[i] < 0) { return 1/0; } if (shift + s[i] >= positions.size()) { return 1/0; } if (positions[shift - s[i]].empty()) { positions[shift + s[i]].push_back(i); } else { ans += i - give(positions[shift - s[i]][0]); update(positions[shift - s[i]][0], i); if (s[i] > 0) { ans--; } positions[shift - s[i]].pop_front(); } } return ans; }

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:35:12: warning: division by zero [-Wdiv-by-zero]
   35 |    return 1/0;
      |           ~^~
shoes.cpp:37:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::deque<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   if (shift + s[i] >= positions.size()) {
      |       ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
shoes.cpp:38:12: warning: division by zero [-Wdiv-by-zero]
   38 |    return 1/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...