Submission #224586

# Submission time Handle Problem Language Result Execution time Memory
224586 2020-04-18T13:03:34 Z inwbear Mountains (NOI20_mountains) C++14
0 / 100
2000 ms 131944 KB
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
using namespace std;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define MEM(x,a) memset((x),a,sizeof((x)))
#define F first
#define S second
#define imx INT_MAX
const long long MOD = (long long)(1e9+7);
const long long MMX = (long long)(1e18);
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,int>PQ;
int n,x,ls=-1,fen[300005];
LL ans,a,rr,b;
priority_queue<PQ,vector<PQ>,greater<PQ> >pq;
queue<int>q;
void up(int idx)
{
    while(idx<=300004)
    {
        fen[idx]++;
        idx+=idx&(-idx);
    }
    return;
}
int ss(int idx)
{
    LL re=0;
    while(idx>0)
    {
        re+=fen[idx];
        idx-=idx&(-idx);
    }
    return re;
}
int main()
{
    pq.push({1e18+1,-1});
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&x);
        pq.push({x,i});
    }
    while(pq.top().S!=-1)
    {
        if(pq.top().F!=ls)
        {
            //while(!q.empty())up(q.front()),q.pop(),rr++;
        }
        ls=pq.top().F;
        q.push(pq.top().S);
        a=ss(pq.top().S);
        pq.pop();
        ans+=(a*(rr-a));
    }
    printf("%lld",ans);
}

Compilation message

Mountains.cpp: In function 'int main()':
Mountains.cpp:45:24: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
         scanf("%lld",&x);
                      ~~^
Mountains.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
Mountains.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&x);
         ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Execution timed out 2095 ms 131828 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2086 ms 131944 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2086 ms 131944 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Execution timed out 2095 ms 131828 KB Time limit exceeded
3 Halted 0 ms 0 KB -