제출 #225230

#제출 시각아이디문제언어결과실행 시간메모리
225230PedroBigManMountains (NOI20_mountains)C++14
100 / 100
784 ms71740 KiB
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define INF 100000000000000000LL
ll insig;
#define In(vecBRO, LENBRO) REP(IBRO,0,LENBRO) {cin>>insig; vecBRO.pb(insig);}
void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}

class ST
{
    public:
    ll N; 
    
    class SV //segment values
    {
        public:
        ll a;
        SV() {a=0LL;}
        SV(ll x) {a=x;}
    };
    
    SV op(SV A, SV B)
    {
        SV X(A.a+B.a);
        return X;
    }
    
    SV neut;
    
    vector<SV> ar; vector<SV> p;
    
    ST(vector<ll> arr)
    {
        N = (ll) 1<<(ll) ceil(log2(arr.size()));
        REP(i,0,arr.size()) {SV X(arr[i]); ar.pb(X);} 
        REP(i,arr.size(),N) {ar.pb(neut);}
        REP(i,0,N) {p.pb(neut);}
        REP(i,0,N) {p.pb(ar[i]);}
        ll cur = N-1;
        while(cur>0)
        {
            p[cur]=op(p[2*cur],p[2*cur+1]);
            cur--;
        }
    }
    
    SV query(ll a,ll b, ll c, ll x, ll y) //c=current node, starting in 1, a,b=range of query, x,y=range of node c in the array down, x,y from 0 to N-1. query(a,b)->query(a,b,1,0,N-1)
    {
        if(y<a || x>b) {return neut;}
        if(x>=a && y<=b) {return p[c];}
        ll mid=(x+y)/2;
        return op(query(a,b,2*c,x,mid),query(a,b,2*c+1,mid+1,y));
    }
    
    void update(SV s, ll a, ll c, ll x, ll y) //position a in 0,N-1 gets +s
    {
        if(y<a || x>a) {return ;}
        p[c]=op(s,p[c]);
        if(c==a+N) {ar[a]=op(ar[a],s); return;}
        ll mid=(x+y)/2;
        update(s,a,2*c,x,mid); update(s,a,2*c+1,mid+1,y);
    }
};

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll N; cin>>N; vector<ll> h; In(h,N); 
    vector<ll> a=h; sort(a.begin(),a.end()); map<ll,ll> m; ll cnt=0LL;
    REP(i,0,N) 
    {
        if(i>0 && a[i]==a[i-1]) {continue;}
        m[a[i]]=cnt; cnt++;
    }
    REP(i,0,N) {h[i]=m[h[i]];}
    vector<ll> xx; REP(i,0,N) {xx.pb(0LL);}
    vector<ll> v1,v2; REP(i,0,N) {v1.pb(0LL); v2.pb(0LL);}
    ST S1(xx); 
    REP(i,0,N)
    {
        ST::SV X(1LL);
        S1.update(X,h[i],1,0,S1.N-1);
        if(h[i]>=1LL) {v1[i]=S1.query(0,h[i]-1,1,0,S1.N-1).a;}
    }
    ST S2(xx);
    for(ll i=N-1;i>=0;i--)
    {
        ST::SV X(1LL);
        S2.update(X,h[i],1,0,S2.N-1);
        if(h[i]>=1) {v2[i]=S2.query(0,h[i]-1,1,0,S2.N-1).a;}
    }
    ll ans=0LL;
    REP(i,0,N) {ans+=v1[i]*v2[i];}
    cout<<ans<<endl;
    return 0;
}

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

Mountains.cpp: In function 'void Out(std::vector<long long int>)':
Mountains.cpp:14:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define REP(i,a,b) for(ll i=a; i<b; i++)
Mountains.cpp:23:29:
 void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}
                             ~~~~~~~~~~~~
Mountains.cpp:23:25: note: in expansion of macro 'REP'
 void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}
                         ^~~
Mountains.cpp: In constructor 'ST::ST(std::vector<long long int>)':
Mountains.cpp:14:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define REP(i,a,b) for(ll i=a; i<b; i++)
Mountains.cpp:51:13:
         REP(i,0,arr.size()) {SV X(arr[i]); ar.pb(X);} 
             ~~~~~~~~~~~~~~       
Mountains.cpp:51:9: note: in expansion of macro 'REP'
         REP(i,0,arr.size()) {SV X(arr[i]); ar.pb(X);} 
         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...