답안 #75550

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
75550 2018-09-10T09:15:28 Z noclever Vudu (COCI15_vudu) C++14
42 / 140
764 ms 66560 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
 
using namespace std;
 
template<typename T>
class fenwick {
  private:
    int n;
    vector<T> fenw;
  public:
 
    fenwick(int _n) : n(_n) {
      fenw.resize(n);
    }
 
    void modify(int x, T v) {
      while (x < n) {
        fenw[x] += v;
        x |= (x + 1);
      }
    }
 
    T get(int x) {
      T v{};
      while (x >= 0) {
        v += fenw[x];
        x = (x & (x + 1)) - 1;
      }
      return v;
    }
};
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> a(n);
  vector<long long> b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long p;
  cin >> p;
  for (int i = 0; i < n; i++) {
    a[i] -= p;
  }
  b[0] = a[0];
  for (int i = 1; i < n; i++) {
    a[i] += a[i - 1];
    b[i] = a[i];
  } 
  sort(b.begin(), b.end());
  b.erase( unique( b.begin(), b.end() ), b.end() );
  map<long long, int> mp;
  for (int i = 0; i < n; i++) {
    mp[a[i]] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
  }
  fenwick<long long> fenw(n+1);
  long long ans = 0ll;
  for (int i = 0; i < n; i++) {
    if (a[i] >= 0) {
      ans++;
    }
    int tmp = mp[a[i]];
    ans += (fenw.get(tmp));
    fenw.modify(tmp, +1);
  }
  cout << ans << endl;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 888 KB Output is correct
2 Correct 5 ms 888 KB Output is correct
3 Correct 5 ms 888 KB Output is correct
4 Runtime error 764 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 678 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 697 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 641 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 624 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 660 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 642 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)