Submission #35275

# Submission time Handle Problem Language Result Execution time Memory
35275 2017-11-19T15:22:02 Z dqhungdl Money (IZhO17_money) C++14
0 / 100
0 ms 9988 KB
#include <bits/stdc++.h>
using namespace std;

int n,a[1000005],tree[1000005];

void Update(int idx,int data)
{
    while(idx<=1e6)
    {
        tree[idx]+=data;
        idx+=idx&-idx;
    }
}

int Query(int idx)
{
    int rs=0;
    while(idx>0)
    {
        rs+=tree[idx];
        idx-=idx&-idx;
    }
    return rs;
}

int main()
{
    ios_base::sync_with_stdio(false);
    //freopen("TEST.INP","r",stdin);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        Update(a[i],1);
    }
    int res=1,Count=0;
    for(int i=2;i<=n;i++)
    {
        Update(a[i],-1);
        if(a[i]<a[i-1]||(Query(a[i])-Query(a[i-1])>0&&Count==1))
        {
            res++;
            Count=0;
        }
        else
        if(Query(a[i])-Query(a[i-1])>0)
            Count++;
    }
    cout<<res;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 9988 KB Output is correct
2 Incorrect 0 ms 9988 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 9988 KB Output is correct
2 Incorrect 0 ms 9988 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 9988 KB Output is correct
2 Incorrect 0 ms 9988 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 9988 KB Output is correct
2 Incorrect 0 ms 9988 KB Output isn't correct
3 Halted 0 ms 0 KB -