답안 #946671

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946671 2024-03-14T21:38:26 Z NourWael Vudu (COCI15_vudu) C++17
56 / 140
441 ms 65536 KB
#include <bits/extc++.h>
using namespace std; 
using namespace __gnu_pbds; 
int const mxN = 1e6;
long long a[mxN + 1];
int seg[4*mxN];
map<long long,int> val;

int get ( int node, int l, int r, int ind) {
   if(ind<l) return 0;
   if(r-1<=ind) return seg[node];
   int m = (l+r) / 2;
   return get(node*2+1, l, m, ind) + get(node*2+2, m, r, ind);
}

void update ( int node, int l, int r, int ind) {
    if(ind<l || ind>=r) return;
    if(l==r-1 && l==ind) {
      seg[node] += 1;
      return;
    }
    int m = (l+r) / 2;
    update(node*2+1, l, m, ind), update(node*2+2, m, r, ind);
    seg[node] = seg[node*2+1] + seg[node*2+2];
}

signed main() {
   ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
   
   long long n,p, ans = 0, ind = 0; cin>>n;
   for(int i=0; i<n; i++) cin>>a[i];
   cin>>p;
   vector<long long> st;
   st.push_back(p);
   for(int i=0; i<n; i++) {
      a[i] += (i? a[i-1]:0);
      long long x = a[i] - p*i;
      st.push_back(x);
   }
   sort(st.begin(),st.end());
   val[st[0]] = 0;
   for(int i=1; i<st.size(); i++) {
      if(st[i]==st[i-1]) continue;
      ind++;
      val[st[i]] = ind;
   }
   int pw = (1<<(__lg(ind-1)+1));
   update(0,0,pw, val[p]);
   for(int i=0; i<n; i++) {
      long long x = a[i] - p*i;
      x = val[x];
      ans += get(0,0,pw, x);
      update(0,0,pw,x);
   }
   cout<<ans;
   return 0;
}

Compilation message

vudu.cpp: In function 'int main()':
vudu.cpp:42:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |    for(int i=1; i<st.size(); i++) {
      |                 ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2908 KB Output is correct
2 Correct 3 ms 2908 KB Output is correct
3 Correct 3 ms 2908 KB Output is correct
4 Runtime error 290 ms 65536 KB Execution killed with signal 9
5 Correct 441 ms 51888 KB Output is correct
6 Runtime error 255 ms 65536 KB Execution killed with signal 9
7 Runtime error 261 ms 65536 KB Execution killed with signal 9
8 Runtime error 262 ms 65536 KB Execution killed with signal 9
9 Runtime error 297 ms 65536 KB Execution killed with signal 9
10 Runtime error 277 ms 65536 KB Execution killed with signal 9