제출 #92838

#제출 시각아이디문제언어결과실행 시간메모리
92838SamAndMoney (IZhO17_money)C++17
100 / 100
254 ms14460 KiB
#include <bits/stdc++.h>
using namespace std;
const int N = 1000006;

int n;
int a[N];

int t[N];

void ubd(int x)
{
    while (x < N)
    {
        t[x]++;
        x += (x & (-x));
    }
}

int qry(int l, int r)
{
    if (l > r)
        return 0;
    int ans = 0;
    while (r > 0)
    {
        ans += t[r];
        r -= (r & (-r));
    }
    --l;
    while (l > 0)
    {
        ans -= t[l];
        l -= (l & (-l));
    }
    return ans;
}

int main()
{
    //freopen("input2.txt", "r", stdin);
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    int ans = 1;
    ubd(a[1]);
    int s = a[1];
    map<int, int> mp;
    for (int i = 2; i <= n; ++i)
    {
        ubd(a[i]);
        if (a[i] >= a[i - 1] && qry(a[i - 1] + 1, a[i] - 1) == 0)
        {
            mp[a[i]]++;
            if (a[i] == a[i - 1])
                continue;
            else
            {
                if (mp[a[i - 1]] == qry(a[i - 1], a[i - 1]))
                    continue;
                else
                {
                    if (a[i - 1] == s)
                        continue;
                    else
                    {
                        ++ans;
                        s = a[i];
                        mp.clear();
                        mp[s]++;
                    }
                }
            }
        }
        else
        {
            ++ans;
            s = a[i];
            mp.clear();
            mp[s]++;
        }
    }
    cout << ans << endl;
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

money.cpp: In function 'int main()':
money.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
money.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...