답안 #87413

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
87413 2018-11-30T18:28:03 Z nikolapesic2802 Vudu (COCI15_vudu) C++14
42 / 140
1000 ms 66560 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
	os << '{';
	for(int i=0;i<sz(a);i++)
	{
		if(i>0&&i<sz(a)-1)
			os << ", ";
		os << a[i];
	}
	os << '}';
    return os;
}
const int N=1e6+5;
vector<ll> pre(N);
int main()
{
    int n,p;
    scanf("%i",&n);
    for(int i=1;i<=n;i++)
        scanf("%lld",&pre[i]);
    scanf("%i",&p);
    for(int i=1;i<=n;i++){
        pre[i]+=pre[i-1]-p;
        //printf("%lld ",pre[i]);
    }
    //printf("\n");
    ordered_set<pair<ll,int> > o;
    o.insert({0,0});
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        ordered_set<pair<ll,int> >::iterator it=o.lower_bound({pre[i]+1,0});
        //cout << *it;
        if(it==o.end())
        {
            //printf("%i\n",o.size());
            ans+=o.size();
            o.insert({pre[i],i});
            continue;
        }
        ans+=o.order_of_key({pre[i]+1,0});
        o.insert({pre[i],i});
    }
    printf("%lld\n",ans);
    return 0;
}

Compilation message

vudu.cpp: In function 'int main()':
vudu.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i",&n);
     ~~~~~^~~~~~~~~
vudu.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&pre[i]);
         ~~~~~^~~~~~~~~~~~~~~~
vudu.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i",&p);
     ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 8696 KB Output is correct
2 Correct 13 ms 8776 KB Output is correct
3 Correct 12 ms 8776 KB Output is correct
4 Execution timed out 1062 ms 66560 KB Time limit exceeded
5 Runtime error 587 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
6 Runtime error 977 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
7 Runtime error 965 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
8 Runtime error 791 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
9 Runtime error 878 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 867 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.