답안 #152658

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
152658 2019-09-09T05:37:29 Z balbit Vudu (COCI15_vudu) C++14
56 / 140
742 ms 65540 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define bug(x) cerr<<#x<<" is "<<x<<endl
using namespace std;

#define int ll

const int iinf = 1<<29;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;


void GG(){cout<<"No\n"; exit(0);}

ll mpow(ll a, ll n){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mod;
        a = a*a %mod;
        n>>=1;
    }
    return re;
}

ll inv (ll b){
    if (b==1) return b;
    return (mod-mod/b) * inv(mod%b) % mod;
}   

const int maxn = 1e5+5;

map<int, int> mp;

struct BIT{
    vector<int> s;
    int mx;
    ll QU(int e){
        e++; ll re = 0; 
        while(e>0) re+=s[e], e-=e&(-e);
        return re;
    }
    void MO(int e, int v){
        e++; 
        while (e<mx) s[e] += v, e+=e&(-e);
    }
    BIT(int mm){
        mx = mm; s.resize(mm,0);
    }
};

main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n; cin>>n;
    vector<int> a(n); int pp;
    vector<int> ps(n+1);
    REP(i,n) cin>>a[i];
    cin>>pp;
    REP(i,n) a[i] -= pp;
    REP(i,n){
        ps[i+1] = ps[i] + a[i];
    }
    vector<int> p = ps;
    SORT_UNIQUE(p);
    REP(i,SZ(p)){
        mp[p[i]] = i;
    }
    BIT bb(n+2);
    ll re = 0;
    REP(i,n+1){
        re += bb.QU(mp[ps[i]]);
        bb.MO(mp[ps[i]], 1);
    }
    cout<<re<<endl;
}

Compilation message

vudu.cpp:66:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
vudu.cpp: In function 'int main()':
vudu.cpp:9:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define REP(i,n) for (int i=0; i<(n); i++)
                                 ^
vudu.cpp:79:5: note: in expansion of macro 'REP'
     REP(i,SZ(p)){
     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1216 KB Output is correct
2 Correct 6 ms 888 KB Output is correct
3 Correct 5 ms 888 KB Output is correct
4 Runtime error 505 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Correct 742 ms 57068 KB Output is correct
6 Runtime error 500 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 489 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 492 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 495 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 490 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)