제출 #951488

#제출 시각아이디문제언어결과실행 시간메모리
951488SmuggingSpun서열 (APIO23_sequence)C++17
28 / 100
2097 ms9556 KiB
#include<bits/stdc++.h> using namespace std; int sequence(int n, vector<int>a){ vector<int>bit(n + 1); function<void(int)>update = [&] (int p){ for(; p <= n; p += p & -p){ bit[p]++; } }; function<int(int)>get = [&] (int p){ int ans = 0; for(; p > 0; p -= p & -p){ ans += bit[p]; } return ans; }; function<void(int&, int)>maximize = [&] (int& a, int b){ if(a < b){ a = b; } }; int ans = 0; for(int i = 0; i < n; i++){ fill(bit.begin(), bit.end(), 0); for(int j = i; j < n; j++){ update(a[j]); int low = 1, high = n, x = j - i + 1, median; while(low <= high){ int mid = (low + high) >> 1; if(get(mid) >= (x >> 1) + (x & 1)){ high = (median = mid) - 1; } else{ low = mid + 1; } } maximize(ans, get(median) - get(median - 1)); if((~x & 1) && get(median) == (x >> 1)){ low = median + 1; high = n; while(low <= high){ int mid = (low + high) >> 1; if(get(mid) > (x >> 1)){ high = (median = mid) - 1; } else{ low = mid + 1; } } maximize(ans, get(median) - get(median - 1)); } } } return ans; }

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

sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:39:9: warning: 'median' may be used uninitialized in this function [-Wmaybe-uninitialized]
   39 |     low = median + 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...
#Verdict Execution timeMemoryGrader output
Fetching results...