This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//
// ROIGold.cpp
// Main calisma
//
// Created by Rakhman on 05/02/2019.
// Copyright © 2019 Rakhman. All rights reserved.
//
#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 return cout << 0, 0;
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)
const int MXN = 1e6 + 200;
const long long MNN = 4e2 + 200;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int OO = 1e9 + 500;
typedef long long llong;
typedef unsigned long long ullong;
using namespace std;
int n, b[MXN], ans, t[4 * MXN];
int get(int v, int tl, int tr, int L, int R){
if(L <= tl && tr <= R){
return t[v];
}
if(tl > R || tr < L || L > R){
return 0;
}
int tm = (tl + tr) / 2;
return get(v * 2, tl, tm, L, R) + get(v * 2 + 1, tm + 1, tr, L, R);
}
void upd(int v, int tl, int tr, int ind, int x){
if(tl == tr){
t[v] = x;
return ;
}
int tm = (tl + tr) / 2;
if(ind <= tm){
upd(v * 2, tl, tm, ind, x);
}else{
upd(v * 2 + 1, tm + 1, tr, ind, x);
}
t[v] = t[v * 2] + t[v * 2 + 1];
}
int main () {
ios;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> b[i];
}
int l = 1, r = 1;
while(l <= n){
while(b[r] <= b[r + 1] && get(1, 1, n, l + 1, r - 1) == 0 && r + 1 <= n){
r++;
}
ans ++;
for(int i = l; i <= r; i++){
upd(1, 1, 1000000, b[i], 1);
}
l = r + 1;
r = r + 1;
}
cout << ans;
}
/*
6
3 6 4 5 1 2
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |