답안 #313881

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
313881 2020-10-17T08:22:44 Z BeanZ Vudu (COCI15_vudu) C++14
140 / 140
380 ms 24024 KB
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 1e6 + 5;
ll a[N], st[N];
ll n;
void add(ll x){
    for (; x <= (n + 1); x += (x & -x)){
        st[x]++;
    }
}
ll get(ll x){
    ll res = 0;
    for (; x > 0; x -= (x & -x)){
        res = res + st[x];
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    if (fopen("A.inp", "r")){
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    ll p;
    cin >> p;
    for (int i = 1; i <= n; i++) a[i] -= p;
    vector<ll> val;
    ll sum = 0;
    val.push_back(sum);
    for (int i = 1; i <= n; i++){
        sum = sum + a[i];
        val.push_back(sum);
    }
    sort(val.begin(), val.end());
    val.resize(unique(val.begin(), val.end()) - val.begin());
    add(lower_bound(val.begin(), val.end(), 0) - val.begin() + 1);
    sum = 0;
    ll ans = 0;
    for (int i = 1; i <= n; i++){
        sum = sum + a[i];
        ll id = lower_bound(val.begin(), val.end(), sum) - val.begin() + 1;
        ans = ans + get(id);
        add(id);
    }
    cout << ans;
}
/*
*/

Compilation message

vudu.cpp: In function 'int main()':
vudu.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   25 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
vudu.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   26 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 380 ms 23104 KB Output is correct
5 Correct 198 ms 13372 KB Output is correct
6 Correct 311 ms 20568 KB Output is correct
7 Correct 316 ms 21460 KB Output is correct
8 Correct 283 ms 18776 KB Output is correct
9 Correct 369 ms 24024 KB Output is correct
10 Correct 313 ms 20824 KB Output is correct