답안 #260173

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
260173 2020-08-09T13:51:13 Z sckmd Vudu (COCI15_vudu) C++14
42 / 140
1000 ms 65540 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define MAXN 1000005
ll a[MAXN];
ll bit[MAXN];
map <ll,int> mp;

void update(int idx,int val)
{
  while(idx < MAXN)
  {
    bit[idx] += val;
    idx += idx&(-idx);
  }
}
ll get(int idx)
{
  ll ret = 0LL;
  while(idx > 0)
  {
    ret += bit[idx];
    idx -= idx&(-idx);
  }
  return ret;
}
ll get(int l,int r)
{
  ll ret = get(r);
  if(l > 0)ret -= get(l-1);
  return ret;
}

int main()
{
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for(int i = 1; i <= n; i++)cin >> a[i];
  int p;
  cin >> p;
  for(int i = 1; i <= n; i++)a[i]-=p,a[i]+=a[i-1];
  vector <int> all;
  all.push_back(0);
  for(int i = 1; i <= n; i++)all.push_back(a[i]);
  sort(all.begin(),all.end());
  all.erase(unique(all.begin(),all.end()),all.end());
  for(int j = 0; j < all.size(); j++)
  {
    mp[all[j]]=j+1;
  }
  update(mp[0],1);
  ll ans = 0LL;
  for(int i = 1; i <= n; i++)
  {
    ans += get(mp[a[i]]);
    update(mp[a[i]],1);
  }
  cout << ans;
  return 0;
}

Compilation message

vudu.cpp: In function 'int main()':
vudu.cpp:49:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0; j < all.size(); j++)
                  ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1024 KB Output is correct
2 Correct 4 ms 896 KB Output is correct
3 Correct 4 ms 768 KB Output is correct
4 Runtime error 473 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Execution timed out 1099 ms 47072 KB Time limit exceeded
6 Execution timed out 1088 ms 65536 KB Time limit exceeded
7 Runtime error 452 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Execution timed out 1053 ms 65536 KB Time limit exceeded
9 Runtime error 478 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Execution timed out 1098 ms 65536 KB Time limit exceeded