Submission #169156

#TimeUsernameProblemLanguageResultExecution timeMemory
169156tselmegkhMoney (IZhO17_money)C++14
0 / 100
2 ms376 KiB
#include<bits/stdc++.h> using namespace std; vector<int> mergesort(vector<int> a, vector<int> b){ int i = 0, j = 0; vector<int> res; while(i < a.size() && j < b.size()){ if(a[i] < b[j]){ res.push_back(a[i]); i++; }else{ res.push_back(b[j]); j++; } } while(i < a.size()){ res.push_back(a[i]); i++; } while(j < b.size()){ res.push_back(b[j]); j++; } return res; } int main(){ int n; cin >> n; vector<int> a(n); int ans = 1; for(int i = 0; i < n; i++){ cin >> a[i]; } int j = 1; vector<int> b; b.push_back(a[0]); while(a[j] >= a[j - 1] && j < n){ b.push_back(a[j]); j++; } int cnt = 0, bound = 0; vector<int> cursegment; while(j < n){ int l = 0, r = b.size() - 1; if(cnt == 0){ ans++; while(l != r){ int mid = (l + r + 1) / 2; if(b[mid] <= a[j]){ l = mid; }else{ r = mid - 1; } } if(b[l] > a[j]){ l = -1; } if(l < b.size() - 1){ bound = b[l + 1]; }else{ bound = 1e9; } //cout << j << ' ' << l << '\n'; cnt++; cursegment.push_back(a[j]); j++; }else{ if(a[j] < a[j - 1]){ cnt = 0; b = mergesort(b, cursegment); cursegment.clear(); //ans++; continue; }else{ if(a[j] <= bound){ cursegment.push_back(a[j]); cnt++; j++; }else{ cnt = 0; b = mergesort(b, cursegment); cursegment.clear(); //ans++; } } } } cout << ans << '\n'; }

Compilation message (stderr)

money.cpp: In function 'std::vector<int> mergesort(std::vector<int>, std::vector<int>)':
money.cpp:7:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(i < a.size() && j < b.size()){
        ~~^~~~~~~~~~
money.cpp:7:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(i < a.size() && j < b.size()){
                        ~~^~~~~~~~~~
money.cpp:16:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(i < a.size()){
        ~~^~~~~~~~~~
money.cpp:20:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(j < b.size()){
        ~~^~~~~~~~~~
money.cpp: In function 'int main()':
money.cpp:59:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(l < b.size() - 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...