제출 #380977

#제출 시각아이디문제언어결과실행 시간메모리
380977PedroBigManCryptography (NOI20_crypto)C++14
100 / 100
828 ms59932 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, c is current node, is 1 in beginning, x, y is range, is 0,S.N-1 in beginning
    {
        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 mod=1000000007LL;
    ll N; cin>>N; vector<ll> a; In(a,N);
    set<ll> x; REP(i,0,N) {x.insert(a[i]);}
    map<ll,ll> m; set<ll>::iterator it=x.begin();
    ll cnt=0LL;
    while(it!=x.end()) 
    {
        m[*it]=cnt; cnt++; it++;
    }
    REP(i,0,N) {a[i]=m[a[i]];}
    vector<ll> xx; REP(i,0,N) {xx.pb(0LL);}
    ST S(xx); ll ans=0LL; ll val;
    vector<ll> fat; ll curfat=1LL; REP(i,1,N) {fat.pb(curfat); curfat*=i; curfat%=mod;}
    fat.pb(curfat);
    REP(i,0,N)
    {
        ST::SV X(1LL); 
        S.update(X,a[i],1,0,S.N-1);
        val=S.query(0,a[i]-1LL,1,0,S.N-1).a;
        val=a[i]-val;
        ans+=val*fat[N-1-i]; ans%=mod;
    }
    ans++; ans%=mod; ans+=mod; ans%=mod;
    cout<<ans<<endl;
    return 0;
}

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

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