Submission #313878

# Submission time Handle Problem Language Result Execution time Memory
313878 2020-10-17T08:16:46 Z BeanZ Vudu (COCI15_vudu) C++14
126 / 140
390 ms 27532 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; 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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 390 ms 26896 KB Output is correct
5 Correct 200 ms 16976 KB Output is correct
6 Incorrect 314 ms 24148 KB Output isn't correct
7 Correct 318 ms 24916 KB Output is correct
8 Correct 287 ms 22432 KB Output is correct
9 Correct 364 ms 27532 KB Output is correct
10 Correct 323 ms 24404 KB Output is correct