답안 #947997

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
947997 2024-03-17T11:36:33 Z vjudge306 Vudu (COCI15_vudu) C++14
42 / 140
567 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define nn "\n"
#define x_x ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define intt int _; cin >> _; while (_--)
#define emp push_back
#define mod 1000000007
#define all(v) v.begin(), v.end()
#define ld long double
#define A first
#define B second
//#define int long long
typedef long long ll;
const ld eps = 1e-27;
// diff between decimals 0.000000001 mt19937 mt(time(nullptr));

int main() {

    x_x
int n; cin>>n; ll p, sm=0, ar[n];
for(auto&i:ar)cin>>i;
cin>>p; ordered_set s;
ll ans=0; vector<ll>v; v.emp(0);

for (ll i=1; i<=n; i++) {
    sm+=ar[i-1]; ll x=-p*i;  x+=sm;
    v.emp(x);
}
sort(all(v));  map<ll,int>mp; int id=0;
for (auto i : v) {
    if(mp.find(i)==mp.end()) mp[i]=id, ++id;
}
sm=0; s.insert(mp[0]);
for (ll i=1; i<=n; i++) {
    sm+=ar[i-1]; ll x=p*i; x=sm-x; int j=upper_bound(all(v),x)-v.begin();
    if(j==v.size())
        x=id;
    else x=mp[v[j]];
    ans+=s.order_of_key(x); x=-p*i; x+=sm; s.insert(mp[x]);
}

cout<<ans;
    return 0;
}

Compilation message

vudu.cpp: In function 'int main()':
vudu.cpp:40:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     if(j==v.size())
      |        ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1372 KB Output is correct
2 Correct 4 ms 1116 KB Output is correct
3 Correct 4 ms 1116 KB Output is correct
4 Runtime error 418 ms 65536 KB Execution killed with signal 9
5 Runtime error 567 ms 65536 KB Execution killed with signal 9
6 Runtime error 373 ms 65536 KB Execution killed with signal 9
7 Runtime error 370 ms 65536 KB Execution killed with signal 9
8 Runtime error 415 ms 65536 KB Execution killed with signal 9
9 Runtime error 408 ms 65536 KB Execution killed with signal 9
10 Runtime error 409 ms 65536 KB Execution killed with signal 9