Submission #143688

#TimeUsernameProblemLanguageResultExecution timeMemory
143688MladenPMoney (IZhO17_money)C++17
0 / 100
2 ms376 KiB
#include <bits/stdc++.h> #define MAXN 1000010 #define PRINT(x) cerr<<#x<<'='<<x<<endl; #define pii pair<int,int> #define pb push_back #define fi first #define se second using namespace std; int a[MAXN], inv[MAXN], N, l, r; pii b[MAXN]; int bit[MAXN]; int query(int idx) { int rez = 0; while(idx) { rez += bit[idx]; idx -= idx&-idx; } return rez; } void update(int idx, int val) { while(idx < MAXN) { bit[idx] += val; idx += idx&-idx; } } int main() { cin >> N; for(int i = 1; i <= N; i++) cin >> a[i]; for(int i = 1; i <= N; i++) b[i-1] = {a[i], i}; sort(b, b+N); for(int i = 0; i < N; i++) a[b[i].se] = i+1; for(int i = 1; i <= N; i++) update(i, +1); int rez = 1; for(int i = 2; i <= N; i++) { if(a[i] < a[i-1] || query(a[i])-query(a[i-1]) != a[i]-a[i-1]) { rez++; } update(a[i-1], -1); } cout << rez; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...