# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
691781 | tolbi | Money (IZhO17_money) | C++17 | 1439 ms | 61888 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma optimize("Bismillahirrahmanirrahim")
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█■█
//█─█─█▄─█▄─█─█─█─█
//Allahuekber
//ahmet23 orz...
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//YavuzSultanSelimHan
//AbdulhamidHan
#define author tolbi
#include <bits/stdc++.h>
#ifdef LOCAL
#include "23.h"
#endif
#define endl '\n'
#define vint(x) vector<int> x
#define deci(x) int x;cin>>x;
#define decstr(x) string x;cin>>x;
#define cinarr(x) for (auto &it : x) cin>>it;
#define coutarr(x) for (auto &it : x) cout<<it<<" ";cout<<endl;
#define sortarr(x) sort(x.begin(),x.end())
#define sortrarr(x) sort(x.rbegin(),x.rend())
#define det(x) cout<<"NO\0YES"+x*3<<endl;
#define INF LONG_LONG_MAX
#define rev(x) reverse(x.begin(),x.end());
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define tol(bi) (1LL<<((int)(bi)))
const int MOD = 1e9+7;
using namespace std;
mt19937 ayahya(chrono::high_resolution_clock().now().time_since_epoch().count());
struct BIT{
vector<int> fenwik;
BIT(int n){
fenwik.resize(2*n);
}
void update(int node){
for (; node<fenwik.size(); node=node|(node+1)) fenwik[node]++;
}
int get(int node){
int rval = 0;
for (; node>=0; node=(node&(node+1))-1) rval+=fenwik[node];
return rval;
}
int query(int l, int r){
int hh = 0;
if (l) hh = get(l-1);
if (l>r) return 0ll;
return get(r)-hh;
}
};
void compress(vector<int> &arr){
vector<int> barr = arr;
map<int,int> mp;
sortarr(barr);
int ind = 1;
for (int i = 0; i < arr.size(); i++){
if (mp[barr[i]]) continue;
mp[barr[i]]=ind++;
}
for (int i = 0; i < arr.size(); ++i)
{
arr[i]=mp[arr[i]];
}
}
int32_t main(){
ios;
int t=1;
int tno = 0;
if (!t) cin>>t;
while (t-(tno++)){
deci(n);
vint(arr(n));
cinarr(arr);
compress(arr);
BIT fenwik(n);
int ans = n;
fenwik.update(arr[0]);
vector<int> barr=arr;
int ind = 1;
for (int i = 1; i < n; i++){
if (arr[i]>=barr[i-1]){
if (fenwik.query(arr[i-1]+1,arr[i]-1)==0){
ans--;
arr[i]=arr[i-1];
}
else {
while (ind<=i){
fenwik.update(barr[ind++]);
}
}
}
else {
while (ind<=i){
fenwik.update(barr[ind++]);
}
}
}
cout<<ans<<endl;
}
}
Compilation message (stderr)
# | 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... |