답안 #950243

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
950243 2024-03-20T07:14:49 Z vjudge1 Vudu (COCI15_vudu) C++17
56 / 140
625 ms 65536 KB
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=1e6+5;
ll t[N*4];
ll get(int v,int tl,int tr,int l,int r){
    if(r<tl or tr<l)return 0;
    if(l<=tl && tr<=r)return t[v];
    int tm=(tl+tr)/2;
    return get(v*2,tl,tm,l,r)+get(v*2+1,tm+1,tr,l,r);
}
void update(int v,int tl,int tr,int pos){
    if(tl==tr)t[v]++;
    else{
        int tm=(tl+tr)/2;
        if(pos<=tm)update(v*2,tl,tm,pos);
        else update(v*2+1,tm+1,tr,pos);
        t[v]=t[v*2]+t[v*2+1];
    }
}
signed main(){
    ios_base::sync_with_stdio();
    cin.tie(0);cout.tie(0);
    int n,p;
    cin>>n;
    vector <int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    cin>>p;
    ll sum=0,x=0,y=0;
    vector <ll> v;
    for(int i=0;i<n;i++){
        x=i;y=p;
        x*=y;
        v.pb(sum-x);
        x=a[i];
        sum+=x;
        x=i;y=p;
        x*=y;
        v.pb(sum-x-p);
    }
    sort(all(v));
    int id=1;
    map <ll,int> ind;
    ind[v[0]]=id;
    for(int i=1;i<v.size();i++){
        if(v[i]!=v[i-1]){
            id++;
            ind[v[i]]=id;
        }
        
    }
    sum=0;
    ll ans=0;
    for(int i=0;i<n;i++){
        x=i;y=p;
        x*=y;
        update(1,1,id,ind[sum-x]);
        x=a[i];
        sum+=x;
        x=i;y=p;
        x*=y;
        ans+=get(1,1,id,1,ind[sum-x-p]);
    }
    cout<<ans<<"\n";
}


/*
 
 */

Compilation message

vudu.cpp: In function 'int main()':
vudu.cpp:49:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for(int i=1;i<v.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1116 KB Output is correct
2 Correct 5 ms 1000 KB Output is correct
3 Correct 4 ms 860 KB Output is correct
4 Runtime error 560 ms 65536 KB Execution killed with signal 9
5 Correct 625 ms 65536 KB Output is correct
6 Runtime error 471 ms 65536 KB Execution killed with signal 9
7 Runtime error 452 ms 65536 KB Execution killed with signal 9
8 Runtime error 419 ms 65536 KB Execution killed with signal 9
9 Runtime error 501 ms 65536 KB Execution killed with signal 9
10 Runtime error 456 ms 65536 KB Execution killed with signal 9