제출 #345190

#제출 시각아이디문제언어결과실행 시간메모리
345190RakhmandHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
2031 ms71192 KiB
// // A.cpp // torelax // // Created by Rakhman on 1/5/21. // #include <cstring> #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <queue> #include <cmath> #include <cstdlib> #include <ctime> #include <cassert> #include <iterator> #define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0); #define S second #define F first #define pb push_back #define nl '\n' #define NL cout << '\n'; #define EX exit(0) #define all(s) s.begin(), s.end() #define no_answer {cout << "NO"; exit(0);} #define FOR(i, start, finish, k) for(llong i = start; i <= finish; i += k) const long long mxn = 1e6 + 110; const long long mnn = 1e3 + 2; const long long mod = 1e9 + 7; const long long inf = 1e18; const long long OO = 1e9 + 100; typedef long long llong; typedef unsigned long long ullong; using namespace std; int n, m, b[mxn], pr[mxn], su[mxn], ans[mxn], pos[mxn]; int Q; vector<int> rightq[mxn]; struct query{ int l, r, x; }q[mxn]; void divideandconquer(int l, int r){ if(l == r) return ; int m = (l + r) / 2; for(int i = m + 1; i <= r; i++){ pr[i] = b[i]; if(i > m + 1){ ans[i] = ans[i - 1]; pr[i] = max(pr[i - 1], pr[i]); if(pr[i - 1] > b[i]){ ans[i] = max(ans[i], pr[i - 1] + b[i]); } } } vector<int> v; for(int i = m; i >= l; i--) { su[i] = b[i]; if(i < m) { ans[i] = ans[i + 1]; su[i] = max(su[i + 1], su[i]); } while(v.size() > 0 && v.back() <= b[i]){ if(b[i] > v.back()) ans[i] = max(ans[i], b[i] + v.back()); v.pop_back(); } v.push_back(b[i]); } vector<int> kek; for(int i = m + 1; i <= r; i++){ for(int j = 0; j < rightq[i].size(); i++){ if(kek.size() == 0 || kek.back() < b[i]){ kek.push_back(b[i]); } int left = q[rightq[i][j]].l, k = q[rightq[i][j]].x; if(pos[rightq[i][j]] == 0) continue; if(left <= m){ if(max(ans[r], ans[l]) > k) pos[rightq[i][j]] = 0; else{ int mx = su[l]; int x = lower_bound(kek.begin(), kek.end(), mx) - kek.begin() - 1; if(0 < x && x < kek.size()) ans[r] = max(ans[r], mx + kek[x]); } }else{ continue; } } } } int main() { cin >> n >> Q; for(int i = 1; i <= n; i++){ cin >> b[i]; } for(int i = 1; i <= Q; i++){ cin >> q[i].l >> q[i].r >> q[i].x; rightq[q[i].r].push_back(i); pos[i] = 1; } divideandconquer(1, n); for(int i = 1; i <= Q; i++){ cout << pos[i] << nl; } }

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

sortbooks.cpp: In function 'void divideandconquer(int, int)':
sortbooks.cpp:89:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |         for(int j = 0; j < rightq[i].size(); i++){
      |                        ~~^~~~~~~~~~~~~~~~~~
sortbooks.cpp:100:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |                     if(0 < x && x < kek.size()) ans[r] = max(ans[r], mx + kek[x]);
      |                                 ~~^~~~~~~~~~~~
#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...