Submission #142945

# Submission time Handle Problem Language Result Execution time Memory
142945 2019-08-12T09:08:46 Z vardan__02 Simple game (IZhO17_game) C++14
0 / 100
2 ms 376 KB
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
ll n,m,i,j,k,p,ans[1000005],q,a[100005],hanel[1000005],plyus[1000005],h,u,v;
struct anun
{
    ll tiv,kod;
};
bool operator<(const anun &a, const anun &b)
{
    return a.tiv<b.tiv;
}
anun b[100005];
set<ll> s;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        s.insert(a[i]);
        b[i].tiv=a[i];
        b[i].kod=i;
    }
    sort(b+1,b+1+n);
    if(b[n].kod!=n)
    {
        if(a[b[n].kod+1]<b[n].tiv)
        {
            plyus[b[n].tiv]++;
            hanel[a[b[n].kod+1]]++;
        }
    }
    if(b[n].kod!=1)
    {
        if(a[b[n].kod-1]<b[n].tiv)
        {
            plyus[b[n].tiv]++;
            hanel[a[b[n].kod-1]]++;
        }
    }
    for(i=n-1;i>=1;i--)
    {
        if(b[i].tiv!=b[i+1].tiv)
            ans[b[i].tiv]=ans[b[i+1].tiv]+plyus[b[i+1].tiv]-hanel[b[i+1].tiv];
        /*if(b[i].kod!=1)
        {
            if(a[b[i].kod-1]>b[i].tiv)
            {
                hanel[b[i].tiv]++;
                ans[b[i].tiv]++;
            }
        }
        if(b[i].kod!=n)
        {
            if(a[b[i].kod+1]>b[i].tiv)
            {
                hanel[b[i].tiv]++;
                ans[b[i].tiv]++;
            }
        }*/
        if(b[i].kod!=n)
        {
            if(a[b[i].kod+1]<b[i].tiv)
            {
                plyus[b[i].tiv]++;
                hanel[a[b[i].kod+1]]++;
            }
        }
        if(b[i].kod!=1)
        {
            if(a[b[i].kod-1]<b[i].tiv)
            {
                plyus[b[i].tiv]++;
                hanel[a[b[i].kod-1]]++;
            }
        }
    }
    for(i=1;i<=m;i++)
    {
        ll w;
        cin>>w;
        if(w==2)
        {
            cin>>h;
            if(h<b[1].tiv || h>b[n].tiv)
                cout<<0<<endl;
            else
            {
                set<ll>::iterator it=s.lower_bound(h);
                it--;
                cout<<ans[*it]<<endl;
            }
        }
    }
    return 0;
}
/*
10 5
20 2 8 4 10 12 14 6 16 18
*/
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -