Submission #501614

#TimeUsernameProblemLanguageResultExecution timeMemory
501614mansurMoney (IZhO17_money)C++17
100 / 100
1189 ms101048 KiB
#include<bits/stdc++.h> #pragma optimize ("g",on) #pragma GCC optimize ("inline") #pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC optimize ("03") #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native") #pragma comment(linker, "/stack:200000000") //01001101 01100001 01101011 01101000 01100001 01100111 01100001 01111001 using namespace std; #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define ll long long #define pb push_back #define sz(a) a.size() #define nl '\n' #define popb pop_back() #define ld double #define ull unsigned long long #define ff first #define ss second #define fix fixed << setprecision #define pii pair<int, int> #define E exit (0) #define int long long const int inf = 1e18, N = 1e6 + 1, mod = 998244353; vector<pii> dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; vector<int> t(4 * N, inf); void update(int u, int tl, int tr, int l, int r, int val) { if (tl > r || tr < l) return; if (tl >= l && tr <= r) { t[u] = min(t[u], val); return; } int mid = (tl + tr) / 2; update(u * 2, tl, mid, l, r, val); update(u * 2 + 1, mid + 1, tr, l, r, val); } int get(int u, int tl, int tr, int pos) { if (tl == tr) return t[u]; int mid = (tl + tr) / 2; if (pos <= mid) { return min(get(u * 2, tl, mid, pos), t[u]); } return min(get(u * 2 + 1, mid + 1, tr, pos), t[u]); } main() { //freopen("cowrect.in", "r", stdin); //freopen("cowrect.out", "w", stdout); ios_base::sync_with_stdio(NULL); cin.tie(NULL); int n; cin >> n; int a[n + 1], r[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; int l = 1; for (int i = 2; i <= n; i++) { if (a[i] < a[i - 1]) { while (l < i) { r[l++] = i - 1; } } } while (l <= n) { r[l++] = n; } set<int> s; update(1, 0, n, 0, 0, 0); for (int i = 1; i <= n; i++) { auto it = s.upper_bound(a[i]); int val; if (it == s.end()) val = inf; else val = *it; int tl = i, tr = r[i], pos; while (tl <= tr) { int mid = (tl + tr) / 2; if (a[mid] <= val) { tl = mid + 1; pos = mid; }else tr = mid - 1; } update(1, 0, n, i, pos, get(1, 0, n, i - 1) + 1); s.insert(a[i]); } cout << get(1, 0, n, n); }

Compilation message (stderr)

money.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    3 | #pragma optimize ("g",on)
      | 
money.cpp:9: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
    9 | #pragma comment(linker, "/stack:200000000")
      | 
money.cpp:57:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   57 | main() {
      | ^~~~
money.cpp: In function 'int main()':
money.cpp:45:8: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   45 |  update(u * 2 + 1, mid + 1, tr, l, r, val);
      |  ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
money.cpp:84:26: note: 'pos' was declared here
   84 |   int tl = i, tr = r[i], pos;
      |                          ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...