Submission #35769

#TimeUsernameProblemLanguageResultExecution timeMemory
35769funcsrMoney (IZhO17_money)C++14
100 / 100
899 ms18020 KiB
#include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <cstring> #include <vector> #include <queue> #include <set> #include <map> #include <cmath> #include <iomanip> #include <cassert> #include <bitset> using namespace std; typedef pair<int, int> P; #define rep(i, n) for (int i=0; i<(n); i++) #define all(c) (c).begin(), (c).end() #define uniq(c) c.erase(unique(all(c)), (c).end()) #define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin()) #define _1 first #define _2 second #define pb push_back #define INF 1145141919 #define MOD 1000000007 #define MAX_N (1<<20) int seg[MAX_N*2-1]; int query(int a, int b, int k=0, int l=0, int r=MAX_N) { if (b <= l || r <= a) return 0; if (a <= l && r <= b) return seg[k]; return query(a, b, k*2+1, l, (l+r)/2) + query(a, b, k*2+2, (l+r)/2, r); } void add(int k) { k += MAX_N-1; if (seg[k]) return; seg[k]++; while (k > 0) { k = (k-1) / 2; seg[k]++; } } int kth(int x, int k=0, int l=0, int r=MAX_N) { if (r-l == 1) return l; if (x <= seg[k*2+1]) return kth(x, k*2+1, l, (l+r)/2); else return kth(x-seg[k*2+1], k*2+2, (l+r)/2, r); } int N; int A[1000000]; int L[1000000]; signed main() { scanf("%d", &N); rep(i, N) scanf("%d", &A[i]); L[N-1] = N-1; for (int i=N-2; i>=0; i--) { if (A[i] <= A[i+1]) L[i] = L[i+1]; else L[i] = i; } add(1000001); rep(i, N) { int s = query(0, A[i]+1); int lim = kth(s+1); L[i] = upper_bound(A+i, A+L[i]+1, lim) - A - 1; add(A[i]); } //rep(i, N) cout<<L[i] << ",";cout<<"\n"; assert(is_sorted(L, L+N)); rep(i, N) assert(L[i] >= i); int lo = 0, ctr = 0; while (lo < N) { lo = L[lo]+1; ctr++; } printf("%d\n", ctr); return 0; }

Compilation message (stderr)

money.cpp: In function 'int main()':
money.cpp:54:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &N);
                  ^
money.cpp:55:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   rep(i, N) scanf("%d", &A[i]);
                               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...